use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.
the class Menu method usePane.
/**
* Opens the Pane for the Player.
* This Pane is for setting the use-cooldown.
*
* @param player - The Player to have the Pane opened.
* @param itemMap - The ItemMap currently being modified.
*/
private static void usePane(final Player player, final ItemMap itemMap) {
Interface usePane = new Interface(true, 6, GUIName, player);
SchedulerUtils.runAsync(() -> {
usePane.setReturnButton(new Button(ItemHandler.getItem("BARRIER", 1, false, "&c&l&nReturn", "&7", "&7*Returns you to the item definition menu."), event -> {
creatingPane(player, itemMap);
}));
usePane.addButton(new Button(ItemHandler.getItem((ServerUtils.hasSpecificUpdate("1_13") ? "YELLOW_STAINED_GLASS_PANE" : "STAINED_GLASS_PANE:4"), 1, false, "&e&lCustom Usage", "&7", "&7*Click to set a custom usage cooldown", "&7value for the item."), event -> {
player.closeInventory();
String[] placeHolders = LanguageAPI.getLang(false).newString();
placeHolders[16] = "USAGE COOLDOWN";
placeHolders[15] = "120";
LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputType", player, placeHolders);
LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputExample", player, placeHolders);
}, event -> {
if (StringUtils.isInt(ChatColor.stripColor(event.getMessage()))) {
itemMap.setInteractCooldown(Integer.parseInt(ChatColor.stripColor(event.getMessage())));
String[] placeHolders = LanguageAPI.getLang(false).newString();
placeHolders[16] = "USAGE COOLDOWN";
LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputSet", player, placeHolders);
} else {
String[] placeHolders = LanguageAPI.getLang(false).newString();
placeHolders[16] = ChatColor.stripColor(event.getMessage());
LanguageAPI.getLang(false).sendLangMessage("commands.menu.noInteger", player, placeHolders);
}
creatingPane(event.getPlayer(), itemMap);
}));
for (int i = 1; i <= 64; i++) {
final int k = i;
usePane.addButton(new Button(ItemHandler.getItem((ServerUtils.hasSpecificUpdate("1_13") ? "BLUE_STAINED_GLASS_PANE" : "STAINED_GLASS_PANE:11"), k, false, "&9&lDuration: &a&l" + k + " Second(s)", "&7", "&7*Click to set the", "&7use-cooldown of the item."), event -> {
itemMap.setInteractCooldown(k);
creatingPane(player, itemMap);
}));
}
});
usePane.open(player);
}
use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.
the class Menu method blocksPane.
/**
* Opens the Pane for the Player.
* This Pane is for setting the blocks drop chances.
*
* @param player - The Player to have the Pane opened.
* @param itemMap - The ItemMap currently being modified.
*/
private static void blocksPane(final Player player, final ItemMap itemMap) {
Interface blockPane = new Interface(true, 6, GUIName, player);
SchedulerUtils.runAsync(() -> {
blockPane.setReturnButton(new Button(ItemHandler.getItem("BARRIER", 1, false, "&c&l&nReturn", "&7", "&7*Returns you to the drop chances menu."), event -> {
dropsPane(player, itemMap);
}));
blockPane.addButton(new Button(ItemHandler.getItem("STICK", 1, true, "&b&lBukkit Material", "&7", "&7*If you know the name", "&7of the BUKKIT material type", "&7simply click and type it."), event -> {
player.closeInventory();
String[] placeHolders = LanguageAPI.getLang(false).newString();
placeHolders[16] = "BUKKIT MATERIAL";
placeHolders[15] = "IRON_SWORD";
LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputType", player, placeHolders);
LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputExample", player, placeHolders);
}, event -> {
if (ItemHandler.getMaterial(ChatColor.stripColor(event.getMessage()), null) != null) {
String[] placeHolders = LanguageAPI.getLang(false).newString();
placeHolders[16] = "BUKKIT MATERIAL";
LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputSet", player, placeHolders);
chancePane(player, itemMap, null, ItemHandler.getMaterial(ChatColor.stripColor(event.getMessage()), null));
} else {
String[] placeHolders = LanguageAPI.getLang(false).newString();
placeHolders[16] = ChatColor.stripColor(event.getMessage());
LanguageAPI.getLang(false).sendLangMessage("commands.menu.noMaterial", player, placeHolders);
blocksPane(player, itemMap);
}
}));
Inventory inventoryCheck = Bukkit.getServer().createInventory(null, 9, GUIName);
for (Material material : Material.values()) {
if (material.isBlock() && itemMap.getBlocksDrop().containsKey(material)) {
if (!material.name().contains("LEGACY") && material.name() != "AIR" && safeMaterial(ItemHandler.getItem(material.toString(), 1, false, "", ""), inventoryCheck)) {
if (!ServerUtils.hasSpecificUpdate("1_13") && LegacyAPI.getDataValue(material) != 0) {
for (int i = 0; i <= LegacyAPI.getDataValue(material); i++) {
if (!material.toString().equalsIgnoreCase("STEP") || material.toString().equalsIgnoreCase("STEP") && i != 2) {
final int dataValue = i;
blockPane.addButton(new Button(ItemHandler.getItem(material.toString() + ":" + dataValue, 1, (itemMap.getBlocksDrop().containsKey(material)), "", "&7", "&7*Click to set the material.", (itemMap.getBlocksDrop().containsKey(material) ? "&9&lChance: &a" + itemMap.getBlocksDrop().get(material) : "")), event -> {
if (itemMap.getBlocksDrop().containsKey(material)) {
Map<Material, Double> blocksDrop = itemMap.getBlocksDrop();
blocksDrop.remove(material);
itemMap.setBlocksDrop(blocksDrop);
blocksPane(player, itemMap);
} else {
chancePane(player, itemMap, null, material);
}
}));
}
}
} else {
blockPane.addButton(new Button(ItemHandler.getItem(material.toString(), 1, (itemMap.getBlocksDrop().containsKey(material)), "", "&7", "&7*Click to set the material.", (itemMap.getBlocksDrop().containsKey(material) ? "&9&lChance: &a" + itemMap.getBlocksDrop().get(material) : "")), event -> {
if (itemMap.getBlocksDrop().containsKey(material)) {
Map<Material, Double> blocksDrop = itemMap.getBlocksDrop();
blocksDrop.remove(material);
itemMap.setBlocksDrop(blocksDrop);
blocksPane(player, itemMap);
} else {
chancePane(player, itemMap, null, material);
}
}));
}
}
}
}
for (Material material : Material.values()) {
if (material.isBlock() && !itemMap.getBlocksDrop().containsKey(material)) {
if (!material.name().contains("LEGACY") && material.name() != "AIR" && safeMaterial(ItemHandler.getItem(material.toString(), 1, false, "", ""), inventoryCheck)) {
if (!ServerUtils.hasSpecificUpdate("1_13") && LegacyAPI.getDataValue(material) != 0) {
for (int i = 0; i <= LegacyAPI.getDataValue(material); i++) {
if (!material.toString().equalsIgnoreCase("STEP") || material.toString().equalsIgnoreCase("STEP") && i != 2) {
final int dataValue = i;
blockPane.addButton(new Button(ItemHandler.getItem(material.toString() + ":" + dataValue, 1, (itemMap.getBlocksDrop().containsKey(material)), "", "&7", "&7*Click to set the material.", (itemMap.getBlocksDrop().containsKey(material) ? "&9&lChance: &a" + itemMap.getBlocksDrop().get(material) : "")), event -> {
if (itemMap.getBlocksDrop().containsKey(material)) {
Map<Material, Double> blocksDrop = itemMap.getBlocksDrop();
blocksDrop.remove(material);
itemMap.setBlocksDrop(blocksDrop);
blocksPane(player, itemMap);
} else {
chancePane(player, itemMap, null, material);
}
}));
}
}
} else {
blockPane.addButton(new Button(ItemHandler.getItem(material.toString(), 1, (itemMap.getBlocksDrop().containsKey(material)), "", "&7", "&7*Click to set the material.", (itemMap.getBlocksDrop().containsKey(material) ? "&9&lChance: &a" + itemMap.getBlocksDrop().get(material) : "")), event -> {
if (itemMap.getBlocksDrop().containsKey(material)) {
Map<Material, Double> blocksDrop = itemMap.getBlocksDrop();
blocksDrop.remove(material);
itemMap.setBlocksDrop(blocksDrop);
blocksPane(player, itemMap);
} else {
chancePane(player, itemMap, null, material);
}
}));
}
}
}
}
inventoryCheck.clear();
});
blockPane.open(player);
}
use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.
the class Commands method onInteract.
/**
* Runs the commands upon physically interacting with the custom item.
*
* @param event - PlayerInteractEvent
*/
@EventHandler(ignoreCancelled = false)
private void onInteract(PlayerInteractEvent event) {
final Player player = event.getPlayer();
final ItemStack item = (event.getItem() != null ? event.getItem().clone() : (event.getAction() == Action.PHYSICAL ? PlayerHandler.getMainHandItem(player) : event.getItem()));
final String action = event.getAction().name();
if (((PlayerHandler.isAdventureMode(player) && !action.contains("LEFT") || !PlayerHandler.isAdventureMode(player))) && !this.isDropEvent(event.getPlayer())) {
final ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(PlayerHandler.getHandItem(player), null, player.getWorld());
if (!PlayerHandler.isMenuClick(player.getOpenInventory(), event.getAction()) && itemMap != null && itemMap.isSimilar(item)) {
long dupeDuration = (this.interactDupe != null && !this.interactDupe.isEmpty() && this.interactDupe.get(item) != null ? (((System.currentTimeMillis()) - this.interactDupe.get(item))) : -1);
if (dupeDuration == -1 || dupeDuration > 30) {
this.interactDupe.put(item, System.currentTimeMillis());
this.runCommands(player, null, item, action, (event.getAction() == Action.PHYSICAL ? "INTERACTED" : action.split("_")[0]), String.valueOf(player.getInventory().getHeldItemSlot()));
}
}
}
}
use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.
the class Consumes method onConsumeSkullEffects.
/**
* Gives the players the defined custom items potion effects upon consuming a skull.
*
* @param event - PlayerInteractEvent.
*/
@EventHandler(ignoreCancelled = false)
private void onConsumeSkullEffects(PlayerInteractEvent event) {
final ItemStack item = event.getItem();
final Player player = event.getPlayer();
final ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(item, null, player.getWorld());
if (itemMap != null && ItemHandler.isSkull(itemMap.getMaterial()) && itemMap.isCustomConsumable()) {
if (itemMap.getPotionEffect() != null && !itemMap.getPotionEffect().isEmpty()) {
for (PotionEffect potion : itemMap.getPotionEffect()) {
player.addPotionEffect(potion);
}
}
event.setCancelled(true);
if (item.getAmount() > 1) {
item.setAmount(item.getAmount() - 1);
} else 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));
}
}
}
use of me.RockinChaos.itemjoin.item.ItemMap in project ItemJoin by RockinChaos.
the class Crafting method returnCrafting.
/**
* Returns the custom crafting item to the player after the specified delay.
*
* @param player - the Player having their item returned.
* @param contents - the crafting contents to be returned.
* @param delay - the delay to wait before returning the item.
*/
private void returnCrafting(final Player player, final ItemStack[] contents, final long delay, final boolean slotZero) {
SchedulerUtils.runLater(delay, () -> {
if (!player.isOnline()) {
return;
} else if (!PlayerHandler.isCraftingInv(player.getOpenInventory())) {
this.returnCrafting(player, contents, 10L, slotZero);
return;
}
if (!slotZero) {
for (int i = 4; i >= 0; i--) {
final ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(contents[i], null, player.getWorld());
if (contents != null && contents[i] != null && itemMap != null) {
player.getOpenInventory().getTopInventory().setItem(i, contents[i]);
PlayerHandler.updateInventory(player, itemMap, 1L);
}
}
} else {
final ItemMap itemMap = ItemUtilities.getUtilities().getItemMap(contents[0], null, player.getWorld());
if (contents != null && contents[0] != null && itemMap != null) {
player.getOpenInventory().getTopInventory().setItem(0, contents[0]);
PlayerHandler.updateInventory(player, ItemUtilities.getUtilities().getItemMap(contents[0], null, player.getWorld()), 1L);
}
}
});
}
Aggregations