use of pw.codehusky.huskycrates.crate.VirtualCrate in project HuskyCrates-Sponge by codeHusky.
the class HuskyCrates method crateInteract.
@Listener
public void crateInteract(InteractBlockEvent.Secondary.MainHand event) {
//pp.getInventory().offer(ItemStack.builder().fromContainer(ss.toContainer().set(DataQuery.of("UnsafeDamage"),3)).build());*/
if (!event.getTargetBlock().getLocation().isPresent())
return;
Location<World> blk = event.getTargetBlock().getLocation().get();
//System.out.println(blk.getBlock().getType());
if (validCrateBlocks.contains(blk.getBlockType())) {
Player plr = (Player) event.getCause().root();
if (crateUtilities.physicalCrates.containsKey(blk)) {
String crateType = crateUtilities.physicalCrates.get(blk).vc.id;
VirtualCrate vc = crateUtilities.getVirtualCrate(crateType);
crateUtilities.physicalCrates.get(blk).createHologram();
if (vc.crateBlockType == blk.getBlockType()) {
event.setCancelled(true);
} else {
return;
}
//crateUtilities.recognizeChest(te.getLocation());
if (plr.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
ItemStack inhand = plr.getItemInHand(HandTypes.MAIN_HAND).get();
if (inhand.getItem() == vc.getKeyType()) {
if (inhand.toContainer().get(DataQuery.of("UnsafeData", "crateID")).isPresent()) {
String id = inhand.toContainer().get(DataQuery.of("UnsafeData", "crateID")).get().toString();
if (id.equals(crateType)) {
if (!plr.hasPermission("huskycrates.tester")) {
if (inhand.getQuantity() == 1)
plr.setItemInHand(HandTypes.MAIN_HAND, null);
else {
ItemStack tobe = inhand.copy();
tobe.setQuantity(tobe.getQuantity() - 1);
plr.setItemInHand(HandTypes.MAIN_HAND, tobe);
}
}
Task.Builder upcoming = scheduler.createTaskBuilder();
upcoming.execute(() -> {
crateUtilities.launchCrateForPlayer(crateType, plr, this);
}).delayTicks(1).submit(this);
return;
}
}
}
}
plr.playSound(SoundTypes.BLOCK_ANVIL_LAND, blk.getPosition(), 0.3);
try {
plr.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(vc.langData.formatter(vc.langData.prefix + vc.langData.noKeyMessage, null, plr, vc, null)));
} catch (Exception e) {
plr.sendMessage(Text.of(TextColors.RED, "Critical crate failure, contact the administrator. (Admins, check console!)"));
e.printStackTrace();
}
}
}
}
use of pw.codehusky.huskycrates.crate.VirtualCrate in project HuskyCrates-Sponge by codeHusky.
the class Crate method getCrateKey.
public ItemStack getCrateKey(String id, int quantity) {
VirtualCrate vc = plugin.crateUtilities.getVirtualCrate(id);
if (vc != null) {
ItemStack key = ItemStack.builder().itemType(ItemTypes.NETHER_STAR).quantity(quantity).add(Keys.DISPLAY_NAME, TextSerializers.LEGACY_FORMATTING_CODE.deserialize(vc.displayName + " Key")).build();
ArrayList<Text> bb = new ArrayList<>();
bb.add(Text.of(TextColors.WHITE, "A key for a ", TextSerializers.LEGACY_FORMATTING_CODE.deserialize(vc.displayName), TextColors.WHITE, "."));
bb.add(Text.of(TextColors.WHITE, "crate_" + id));
key.offer(Keys.ITEM_LORE, bb);
return key;
}
return null;
}
Aggregations