use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.
the class Crafting method onCraftingClick.
/**
* Allows the player to move their custom crafting item around their inventory without them dropping
* or bugging out. This creates a seamless transition between their inventory and crafting slots.
*
* @param event - InventoryClickEvent
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = false)
private void onCraftingClick(InventoryClickEvent event) {
final InventoryView view = event.getView();
final Player player = (Player) event.getWhoClicked();
final ItemStack[] craftingContents = view.getTopInventory().getContents().clone();
if (PlayerHandler.isCraftingInv(view) && event.getSlot() <= 4) {
if (event.getSlot() != 0 && event.getSlotType() == SlotType.CRAFTING) {
if (craftingContents[0] != null && craftingContents[0].getType() != Material.AIR) {
final ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(craftingContents[0], null, player.getWorld());
if (itemMap != null && itemMap.isCraftingItem()) {
ItemHandler.returnCraftingItem(player, 0, craftingContents[0], 1L);
}
}
} else if (event.getSlot() == 0 && event.getSlotType() == SlotType.RESULT) {
if (craftingContents[0] != null && craftingContents[0].getType() != Material.AIR) {
for (ItemMap itemMap : ItemUtilities.getUtilities().getCraftingItems()) {
if (!itemMap.isMovement() && itemMap.isSimilar(craftingContents[0])) {
for (int i = 1; i <= 4; i++) {
ItemHandler.returnCraftingItem(player, i, craftingContents[i].clone(), 1L);
}
SchedulerUtils.runLater(1L, () -> {
player.getOpenInventory().getTopInventory().setItem(0, new ItemStack(Material.AIR));
});
break;
}
}
} else if (event.getCursor() != null && event.getCursor().getType() != Material.AIR) {
for (ItemMap itemMap : ItemUtilities.getUtilities().getCraftingItems()) {
if (!itemMap.isMovement() && itemMap.isSimilar(event.getCursor())) {
ItemStack cursor = event.getCursor().clone();
player.setItemOnCursor(new ItemStack(Material.AIR));
ItemHandler.returnCraftingItem(player, 0, cursor, 1L);
break;
}
}
}
}
}
}
use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.
the class Placement method onFrameLock.
/**
* Refills the custom item to its original stack size when placing the item into a itemframe.
*
* @param event - PlayerInteractEntityEvent
*/
@EventHandler(ignoreCancelled = false)
private void onFrameLock(PlayerInteractEntityEvent event) {
if (event.getRightClicked() instanceof ItemFrame) {
try {
ItemStack item = null;
if (ServerUtils.hasSpecificUpdate("1_9")) {
item = PlayerHandler.getPerfectHandItem(event.getPlayer(), event.getHand().toString());
} else {
item = PlayerHandler.getPerfectHandItem(event.getPlayer(), "");
}
Player player = event.getPlayer();
if (PlayerHandler.isCreativeMode(player)) {
if (!ItemUtilities.getUtilities().isAllowed(player, item, "count-lock")) {
ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(item, null, player.getWorld());
if (itemMap != null) {
if (PlayerHandler.getHandItem(player) == null || PlayerHandler.getHandItem(player).getAmount() <= 1) {
if (ServerUtils.hasSpecificUpdate("1_9")) {
if (event.getHand().equals(EquipmentSlot.HAND)) {
PlayerHandler.setMainHandItem(player, item);
} else if (event.getHand().equals(EquipmentSlot.OFF_HAND)) {
PlayerHandler.setOffHandItem(player, item);
}
} else {
PlayerHandler.setMainHandItem(player, item);
}
} else if (itemMap.isSimilar(PlayerHandler.getHandItem(player))) {
PlayerHandler.getHandItem(player).setAmount(itemMap.getCount(player));
}
}
}
}
} catch (Exception e) {
ServerUtils.sendDebugTrace(e);
}
}
}
use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.
the class Projectile method onCrossbow.
/**
* Refills the custom arrow item to its original stack size when using a crossbow.
*
* @param event - PlayerInteractEvent
*/
@EventHandler(ignoreCancelled = false)
private void onCrossbow(PlayerInteractEvent event) {
ItemStack item = (event.getItem() != null ? event.getItem().clone() : event.getItem());
Player player = event.getPlayer();
if ((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) && item != null && item.getType().name().equalsIgnoreCase("CROSSBOW") && !PlayerHandler.isCreativeMode(player)) {
HashMap<Integer, ItemStack> map = new HashMap<Integer, ItemStack>();
for (int i = 0; i < player.getInventory().getSize(); i++) {
if (player.getInventory().getItem(i) != null && player.getInventory().getItem(i).getType() == Material.ARROW) {
ItemStack cloneStack = player.getInventory().getItem(i).clone();
ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(player.getInventory().getItem(i), null, player.getWorld());
if (itemMap != null) {
cloneStack.setAmount(itemMap.getCount(player));
}
map.put(i, cloneStack);
}
}
this.crossyAction(player, map, 10);
}
}
use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.
the class Legacy_Consumes method onConsumeEffects.
/**
* Gives the players the defined custom items potion effects upon consumption.
*
* @param event - PlayerItemConsumeEvent.
* @deprecated This is a LEGACY event, only use on Minecraft versions below 1.11.
*/
@EventHandler(ignoreCancelled = true)
private void onConsumeEffects(PlayerItemConsumeEvent event) {
ItemStack item = event.getItem();
Player player = event.getPlayer();
ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(item, null, player.getWorld());
if (itemMap != null && itemMap.getMaterial().isEdible() && itemMap.isCustomConsumable()) {
if (itemMap.getPotionEffect() != null && !itemMap.getPotionEffect().isEmpty()) {
for (PotionEffect potion : itemMap.getPotionEffect()) {
player.addPotionEffect(potion);
}
}
event.setCancelled(true);
if (ItemUtilities.getUtilities().isAllowed(player, item, "count-lock")) {
if (item.getAmount() <= 1) {
if (itemMap.isReal(PlayerHandler.getMainHandItem(player))) {
PlayerHandler.setMainHandItem(player, new ItemStack(Material.AIR));
} else if (itemMap.isReal(PlayerHandler.getOffHandItem(player))) {
PlayerHandler.setOffHandItem(player, new ItemStack(Material.AIR));
}
} else {
item.setAmount((item.getAmount() - 1));
if (itemMap.isReal(PlayerHandler.getMainHandItem(player))) {
PlayerHandler.setMainHandItem(player, item);
} else if (itemMap.isReal(PlayerHandler.getOffHandItem(player))) {
PlayerHandler.setOffHandItem(player, item);
}
}
}
}
}
use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.
the class Legacy_Consumes method onPlayerConsumesItem.
/**
* Refills the custom item to its original stack size when consuming the item.
*
* @param event - PlayerItemConsumeEvent.
* @deprecated This is a LEGACY event, only use on Minecraft versions below 1.11.
*/
@EventHandler(ignoreCancelled = true)
private void onPlayerConsumesItem(PlayerItemConsumeEvent event) {
ItemStack item = (event.getItem() != null ? event.getItem().clone() : event.getItem());
Player player = event.getPlayer();
if (!ItemUtilities.getUtilities().isAllowed(player, item, "count-lock")) {
ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(item, null, player.getWorld());
item.setAmount(itemMap.getCount(player));
SchedulerUtils.runLater(2L, () -> {
if (itemMap != null) {
if (PlayerHandler.getHandItem(player) == null || PlayerHandler.getHandItem(player).getAmount() <= 1) {
if (ServerUtils.hasSpecificUpdate("1_9")) {
if (PlayerHandler.getMainHandItem(player) != null && PlayerHandler.getMainHandItem(player).getType() != Material.AIR) {
PlayerHandler.setMainHandItem(player, item);
} else if (PlayerHandler.getOffHandItem(player) != null && PlayerHandler.getOffHandItem(player).getType() != Material.AIR) {
PlayerHandler.setOffHandItem(player, item);
} else {
itemMap.giveTo(player);
}
} else {
PlayerHandler.setMainHandItem(player, item);
}
} else if (itemMap.isSimilar(PlayerHandler.getHandItem(player))) {
PlayerHandler.getHandItem(player).setAmount(itemMap.getCount(player));
}
}
});
}
}
Aggregations