Search in sources :

Example 1 with ItemCommand

use of me.RockinChaos.itemjoin.item.ItemCommand in project ItemJoin by RockinChaos.

the class Menu method headerStack.

/**
 * Gets the Header ItemStack.
 *
 * @param player - The player getting the Header Stack.
 * @param itemMap - The ItemMap to be formatted.
 * @return The formatted Header ItemStack.
 */
private static ItemStack headerStack(final Player player, final ItemMap itemMap) {
    String slotList = "";
    String slotString = "";
    ItemStack item = new ItemStack(Material.STONE);
    if (StringUtils.nullCheck(itemMap.getMultipleSlots().toString()) != "NONE") {
        for (String slot : itemMap.getMultipleSlots()) {
            slotString += slot + ", ";
        }
        if (slotString.length() >= 2) {
            for (String split : StringUtils.softSplit(StringUtils.nullCheck(slotString.substring(0, slotString.length() - 2)))) {
                slotList += "&a" + split + " /n ";
            }
        }
    }
    String itemflagsList = "";
    if (StringUtils.nullCheck(itemMap.getItemFlags()) != "NONE") {
        for (String split : StringUtils.softSplit(itemMap.getItemFlags())) {
            itemflagsList += "&a" + split + " /n ";
        }
    }
    String triggersList = "";
    if (StringUtils.nullCheck(itemMap.getTriggers()) != "NONE") {
        for (String split : StringUtils.softSplit(itemMap.getTriggers())) {
            triggersList += "&a" + split + " /n ";
        }
    }
    String disabledList = "";
    if (StringUtils.nullCheck(itemMap.getDisabledWorlds().toString()) != "NONE") {
        for (String split : StringUtils.softSplit(StringUtils.nullCheck(itemMap.getDisabledWorlds().toString()))) {
            disabledList += "&a" + split + " /n ";
        }
    }
    String enabledList = "";
    if (StringUtils.nullCheck(itemMap.getEnabledWorlds().toString()) != "NONE") {
        for (String split : StringUtils.softSplit(StringUtils.nullCheck(itemMap.getEnabledWorlds().toString()))) {
            enabledList += "&a" + split + " /n ";
        }
    }
    String regionList = "";
    if (StringUtils.nullCheck(itemMap.getEnabledRegions().toString()) != "NONE") {
        for (String split : StringUtils.softSplit(StringUtils.nullCheck(itemMap.getEnabledRegions().toString()))) {
            regionList += "&a" + split + " /n ";
        }
    }
    String enchantList = "";
    if (StringUtils.nullCheck(itemMap.getEnchantments().toString()) != "NONE") {
        for (String split : StringUtils.softSplit(StringUtils.nullCheck(itemMap.getEnchantments().toString()))) {
            enchantList += "&a" + split + " /n ";
        }
    }
    String potionList = "";
    String potionString = "";
    if (StringUtils.nullCheck(itemMap.getPotionEffect().toString()) != "NONE") {
        for (PotionEffect potions : itemMap.getPotionEffect()) {
            potionString += potions.getType().getName().toUpperCase() + ":" + potions.getAmplifier() + ":" + potions.getDuration() + ", ";
        }
        if (potionString.length() >= 2) {
            for (String split : StringUtils.softSplit(StringUtils.nullCheck(potionString.substring(0, potionString.length() - 2)))) {
                potionList += "&a" + split + " /n ";
            }
        }
    }
    String attributeList = "";
    String attributeString = "";
    if (StringUtils.nullCheck(itemMap.getAttributes().toString()) != "NONE") {
        for (String attribute : itemMap.getAttributes().keySet()) {
            attributeString += attribute + ":" + itemMap.getAttributes().get(attribute) + ", ";
        }
        for (String split : StringUtils.softSplit(StringUtils.nullCheck(attributeString.substring(0, attributeString.length())))) {
            attributeList += "&a" + split + " /n ";
        }
    }
    String patternList = "";
    String patternString = "";
    if (ServerUtils.hasSpecificUpdate("1_8") && StringUtils.nullCheck(itemMap.getBannerPatterns().toString()) != "NONE") {
        for (Pattern patterns : itemMap.getBannerPatterns()) {
            patternString += patterns.getColor() + ":" + patterns.getPattern().name().toUpperCase() + ", ";
        }
        if (patternString.length() >= 2) {
            for (String split : StringUtils.softSplit(StringUtils.nullCheck(patternString.substring(0, patternString.length() - 2)))) {
                patternList += "&a" + split + " /n ";
            }
        }
    }
    String colorList = "";
    if (StringUtils.nullCheck(itemMap.getFireworkColor().toString()) != "NONE") {
        for (String split : StringUtils.softSplit(StringUtils.nullCheck(itemMap.getFireworkColor().toString()))) {
            colorList += "&a" + split + " /n ";
        }
    }
    boolean useCommands = true;
    if (itemMap.getCommands().length == 1) {
        for (ItemCommand command : itemMap.getCommands()) {
            if (command.getRawCommand().equalsIgnoreCase("default: ")) {
                useCommands = false;
            }
        }
    } else if (itemMap.getCommands().length == 0) {
        useCommands = false;
    }
    boolean useToggle = itemMap.getToggleCommands() != null && !itemMap.getToggleCommands().isEmpty();
    String mobs = "";
    for (EntityType entity : itemMap.getMobsDrop().keySet()) {
        mobs += entity.name() + ", ";
    }
    String blocks = "";
    for (Material material : itemMap.getBlocksDrop().keySet()) {
        blocks += material.name() + ", ";
    }
    try {
        item = ItemHandler.getItem(itemMap.getMaterial().toString() + ((itemMap.getDataValue() != null && itemMap.getDataValue() != 0) ? ":" + itemMap.getDataValue() : ""), 1, false, "&7*&6&l&nItem Information", "&7", "&9&lNode: &a" + itemMap.getConfigName(), "&9&lMaterial: &a" + itemMap.getMaterial().toString() + ((itemMap.getDataValue() != null && itemMap.getDataValue() != 0) ? ":" + itemMap.getDataValue() : ""), (itemMap.getMultipleSlots() != null && !itemMap.getMultipleSlots().isEmpty() ? "&9&lSlot(s): &a" + slotList : "&9&lSlot: &a" + itemMap.getSlot().toUpperCase()), (itemMap.getCount(player) != 1 && itemMap.getCount(player) != 0) ? "&9&lCount: &a" + itemMap.getCount(player) : "", ((StringUtils.nullCheck(itemMap.getCustomName()) != "NONE" && !ItemHandler.getMaterialName(itemMap.getTempItem()).equalsIgnoreCase(itemMap.getCustomName())) ? "&9&lName: &a" + itemMap.getCustomName() : ""), (StringUtils.nullCheck(itemMap.getCustomLore().toString()) != "NONE" ? "&9&lLore: &a" + (StringUtils.nullCheck(itemMap.getCustomLore().toString()).replace(",,", ",").replace(", ,", ",").length() > 40 ? StringUtils.nullCheck(itemMap.getCustomLore().toString()).replace(",,", ",").replace(", ,", ",").substring(0, 40) : StringUtils.nullCheck(itemMap.getCustomLore().toString()).replace(",,", ",").replace(", ,", ",")) : ""), (StringUtils.nullCheck(itemMap.getDurability() + "&7") != "NONE" ? "&9&lDurability: &a" + itemMap.getDurability() : ""), (StringUtils.nullCheck(itemMap.getData() + "&7") != "NONE" ? "&9&lTexture Data: &a" + itemMap.getData() : ""), (useCommands ? "&9&lCommands: &aYES" : ""), (useToggle ? "&9&lTogglable: &aYES" : ""), (StringUtils.nullCheck(itemMap.getItemCost() + "") != "NONE" ? "&9&lCommands-Item: &a" + itemMap.getItemCost() : ""), (StringUtils.nullCheck(itemMap.getCommandCost() + "&7") != "NONE" ? "&9&lCommands-Cost: &a" + itemMap.getCommandCost() : ""), (StringUtils.nullCheck(itemMap.getCommandReceive() + "&7") != "NONE" ? "&9&lCommands-Receive: &a" + itemMap.getCommandReceive() : ""), (StringUtils.nullCheck(itemMap.getCommandSequence() + "") != "NONE" ? "&9&lCommands-Sequence: &a" + itemMap.getCommandSequence() : ""), (StringUtils.nullCheck(itemMap.getCommandCooldown() + "&7") != "NONE" ? "&9&lCommands-Cooldown: &a" + itemMap.getCommandCooldown() + " second(s)" : ""), (StringUtils.nullCheck(itemMap.getCooldownMessage()) != "NONE" ? "&9&lCooldown-Message: &a" + itemMap.getCooldownMessage() : ""), (StringUtils.nullCheck(itemMap.getCommandSound() + "") != "NONE" ? "&9&lCommands-Sound: &a" + itemMap.getCommandSound() : ""), (StringUtils.nullCheck(itemMap.getCommandParticle() + "") != "NONE" ? "&9&lCommands-Particle: &a" + itemMap.getCommandParticle() : ""), (StringUtils.nullCheck(itemMap.getEnchantments().toString()) != "NONE" ? "&9&lEnchantments: &a" + enchantList : ""), (StringUtils.nullCheck(itemMap.getItemFlags()) != "NONE" ? "&9&lItemflags: &a" + itemflagsList : ""), (StringUtils.nullCheck(itemMap.getTriggers()) != "NONE" ? "&9&lTriggers: &a" + triggersList : ""), (StringUtils.nullCheck(itemMap.getPermissionNode()) != "NONE" ? "&9&lPermission Node: &a" + itemMap.getPermissionNode() : ""), (StringUtils.nullCheck(itemMap.getDisabledWorlds().toString()) != "NONE" ? "&9&lDisabled Worlds: &a" + disabledList : ""), (StringUtils.nullCheck(itemMap.getEnabledWorlds().toString()) != "NONE" ? "&9&lEnabled Worlds: &a" + enabledList : ""), (StringUtils.nullCheck(itemMap.getEnabledRegions().toString()) != "NONE" ? "&9&lEnabled Regions: &a" + regionList : ""), (!itemMap.getDynamicMaterials().isEmpty() ? "&9&lMaterial Animations: &aYES" : ""), (!itemMap.getDynamicNames().isEmpty() ? "&9&lName Animations: &aYES" : ""), (!itemMap.getDynamicLores().isEmpty() ? "&9&lLore Animations: &aYES" : ""), (!itemMap.getDynamicOwners().isEmpty() || !itemMap.getDynamicTextures().isEmpty() ? "&9&lSkull Animations: &aYES" : ""), (StringUtils.nullCheck(itemMap.getLimitModes()) != "NONE" ? "&9&lLimit-Modes: &a" + itemMap.getLimitModes() : ""), (StringUtils.nullCheck(itemMap.getProbability() + "&a%") != "NONE" ? "&9&lProbability: &a" + itemMap.getProbability() + "%" : ""), (StringUtils.nullCheck(itemMap.getInteractCooldown() + "&7") != "NONE" ? "&9&lUse-Cooldown: &a" + itemMap.getInteractCooldown() : ""), (StringUtils.nullCheck(itemMap.getLeatherColor()) != "NONE" ? "&9&lLeather Color: &a" + itemMap.getLeatherColor() : ""), (StringUtils.nullCheck(itemMap.getLeatherHex()) != "NONE" ? "&9&lLeather Color: &a" + itemMap.getLeatherHex() : ""), (StringUtils.nullCheck(itemMap.getMapImage()) != "NONE" ? "&9&lMap-Image: &a" + itemMap.getMapImage() : ""), (StringUtils.nullCheck(itemMap.getChargeColor() + "") != "NONE" ? "&9&lCharge Color: &a" + itemMap.getChargeColor() : ""), (StringUtils.nullCheck(patternList) != "NONE" ? "&9&lBanner Meta: &a" + patternList : ""), (StringUtils.nullCheck(potionList) != "NONE" ? "&9&lPotion-Effects: &a" + potionList : ""), (itemMap.getIngredients() != null && !itemMap.getIngredients().isEmpty() ? "&9&lRecipe: &aYES" : ""), (!mobs.isEmpty() ? "&9&lMobs Drop: &a" + mobs.substring(0, mobs.length() - 2) : ""), (!blocks.isEmpty() ? "&9&lBlocks Drop: &a" + blocks.substring(0, blocks.length() - 2) : ""), (StringUtils.nullCheck(itemMap.getCommandConditions() + "") != "NONE" ? "&9&lCommand Conditions: &aYES" : ""), (StringUtils.nullCheck(itemMap.getDisposableConditions() + "") != "NONE" ? "&9&lDisposable Conditions: &aYES" : ""), (StringUtils.nullCheck(itemMap.getTriggerConditions() + "") != "NONE" ? "&9&lTrigger Conditions: &aYES" : ""), (StringUtils.nullCheck(itemMap.getNBTValues() + "") != "NONE" ? "&9&lNBT Properties: &aYES" : ""), (StringUtils.nullCheck(itemMap.getContents() + "") != "NONE" ? "&9&lContents: &aYES" : ""), (StringUtils.nullCheck(attributeList) != "NONE" ? "&9&lAttributes: &a" + attributeList : ""), (StringUtils.nullCheck(itemMap.getPages() + "") != "NONE" ? "&9&lBook Pages: &aYES" : ""), (StringUtils.nullCheck(itemMap.getAuthor()) != "NONE" ? "&9&lBook Author: &a" + itemMap.getAuthor() : ""), (StringUtils.nullCheck(itemMap.getSkull()) != "NONE" ? "&9&lSkull-Owner: &a" + itemMap.getSkull() : ""), (StringUtils.nullCheck(itemMap.getSkullTexture()) != "NONE" ? "&9&lSkull-Texture: &a" + (itemMap.getSkullTexture().length() > 40 ? itemMap.getSkullTexture().substring(0, 40) : itemMap.getSkullTexture()) : ""), (StringUtils.nullCheck(itemMap.getFireworkType() + "") != "NONE" ? "&9&lFirework Type: &a" + itemMap.getFireworkType().name() : ""), (StringUtils.nullCheck(itemMap.getFireworkPower() + "&7") != "NONE" ? "&9&lFirework Power: &a" + itemMap.getFireworkPower() : ""), (StringUtils.nullCheck(colorList) != "NONE" ? "&9&lFirework Color(s): &a" + colorList : ""), (itemMap.getFireworkTrail() ? "&9&lFirework Trail: &aENABLED" : ""), (itemMap.getFireworkFlicker() ? "&9&lFirework Flicker: &aENABLED" : ""));
    } catch (Exception e) {
        ServerUtils.sendDebugTrace(e);
    }
    if (ItemHandler.isSkull(itemMap.getMaterial())) {
        ItemMeta itemMeta = item.getItemMeta();
        if (itemMap.getSkull() != null) {
            itemMeta = ItemHandler.setSkullOwner(itemMeta, StringUtils.translateLayout(itemMap.getSkull(), player));
        } else if (itemMap.getSkullTexture() != null && !itemMap.isHeadDatabase()) {
            try {
                if (ServerUtils.hasSpecificUpdate("1_8")) {
                    GameProfile gameProfile = new GameProfile(UUID.randomUUID(), null);
                    gameProfile.getProperties().put("textures", new Property("textures", new String(itemMap.getSkullTexture())));
                    Field declaredField = itemMeta.getClass().getDeclaredField("profile");
                    declaredField.setAccessible(true);
                    declaredField.set(itemMeta, gameProfile);
                }
            } catch (Exception e) {
                ServerUtils.sendDebugTrace(e);
            }
        } else if (itemMap.isHeadDatabase() && itemMap.getSkullTexture() != null) {
            HeadDatabaseAPI api = new HeadDatabaseAPI();
            ItemStack sk = api.getItemHead(itemMap.getSkullTexture());
            item = (sk != null ? sk : item.clone());
        }
        item.setItemMeta(itemMeta);
    }
    return item;
}
Also used : Pattern(org.bukkit.block.banner.Pattern) ItemCommand(me.RockinChaos.itemjoin.item.ItemCommand) PotionEffect(org.bukkit.potion.PotionEffect) Material(org.bukkit.Material) HeadDatabaseAPI(me.arcaniax.hdb.api.HeadDatabaseAPI) EntityType(org.bukkit.entity.EntityType) Field(java.lang.reflect.Field) GameProfile(com.mojang.authlib.GameProfile) ItemStack(org.bukkit.inventory.ItemStack) Property(com.mojang.authlib.properties.Property) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 2 with ItemCommand

use of me.RockinChaos.itemjoin.item.ItemCommand in project ItemJoin by RockinChaos.

the class Menu method modifyCommandsPane.

/**
 * Opens the Pane for the Player.
 * This Pane is for creating a new command for an item.
 *
 * @param player - The Player to have the Pane opened.
 * @param itemMap - The ItemMap currently being modified.
 * @param action - The action to be matched.
 * @param command - The ItemCommand instance being modified.
 * @param orderNumber - The current number that dictates the ItemCommands "place in line".
 */
private static void modifyCommandsPane(final Player player, final ItemMap itemMap, final Action action, final ItemCommand command, final int orderNumber) {
    Interface modPane = new Interface(false, 3, GUIName, player);
    SchedulerUtils.runAsync(() -> {
        modPane.addButton(new Button(fillerPaneGItem), 4);
        modPane.addButton(new Button(ItemHandler.getItem("FEATHER", 1, true, "&f" + command.getRawCommand(), "&7", "&7*You are modifying this command.", "&9&lOrder Number: &a" + orderNumber)));
        modPane.addButton(new Button(fillerPaneGItem), 4);
        modPane.addButton(new Button(fillerPaneGItem));
        modPane.addButton(new Button(ItemHandler.getItem((ServerUtils.hasSpecificUpdate("1_13") ? "REPEATER" : "356"), 1, false, "&fIdentifier", "&7", "&7*Set a custom identifier", "&7for this command line.", "&7", "&cNOTE: &7This is in order to set", "&7a random command list sequence.", "&7Only use this if", "&7the commands sequence is", "&7set to &aRANDOM_LIST&7.", "&7", "&9&lIDENTIFIER: &a" + StringUtils.nullCheck(command.getSection())), event -> {
            if (StringUtils.nullCheck(command.getSection()) != "NONE") {
                ItemCommand[] commands = itemMap.getCommands();
                for (ItemCommand Command : commands) {
                    if (Command.equals(command)) {
                        Command.setSection(null);
                    }
                }
                itemMap.setCommands(commands);
                command.setSection(null);
                modifyCommandsPane(player, itemMap, action, command, orderNumber);
            } else {
                player.closeInventory();
                String[] placeHolders = LanguageAPI.getLang(false).newString();
                placeHolders[16] = "COMMAND IDENTIFIER";
                placeHolders[15] = "winner";
                LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputType", player, placeHolders);
                LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputExample", player, placeHolders);
            }
        }, event -> {
            ItemCommand[] commands = itemMap.getCommands();
            for (ItemCommand Command : commands) {
                if (Command.equals(command)) {
                    Command.setSection(ChatColor.stripColor(event.getMessage()));
                }
            }
            itemMap.setCommands(commands);
            String[] placeHolders = LanguageAPI.getLang(false).newString();
            placeHolders[16] = "COMMAND IDENTIFIER";
            LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputSet", player, placeHolders);
            commandListPane(event.getPlayer(), itemMap, action);
        }));
        modPane.addButton(new Button(fillerPaneGItem));
        modPane.addButton(new Button(ItemHandler.getItem("PAPER", 1, false, "&fModify", "&7", "&7*Sets the command to", "&7another text entry."), event -> {
            player.closeInventory();
            String[] placeHolders = LanguageAPI.getLang(false).newString();
            placeHolders[16] = "MODIFIED COMMAND";
            placeHolders[15] = "gamemode creative";
            LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputType", player, placeHolders);
            LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputExample", player, placeHolders);
        }, event -> {
            ItemCommand[] commands = itemMap.getCommands();
            for (ItemCommand Command : commands) {
                if (Command.equals(command)) {
                    Command.setCommand(ChatColor.stripColor(event.getMessage()));
                }
            }
            itemMap.setCommands(commands);
            String[] placeHolders = LanguageAPI.getLang(false).newString();
            placeHolders[16] = "MODIFIED COMMAND";
            LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputSet", player, placeHolders);
            commandListPane(event.getPlayer(), itemMap, action);
        }));
        modPane.addButton(new Button(fillerPaneGItem));
        modPane.addButton(new Button(ItemHandler.getItem("STICK", 1, false, "&fOrder", "&7", "&7*Changes the order of execution", "&7for this command line.", "&7", "&7This will simply set the order", "&7number and push the", "&7other commands down by one."), event -> {
            orderPane(player, itemMap, action, command, orderNumber);
        }));
        modPane.addButton(new Button(fillerPaneGItem));
        modPane.addButton(new Button(ItemHandler.getItem("REDSTONE", 1, false, "&fDelete", "&7", "&7*Click to &cdelete &7this command."), event -> {
            modifyCommands(itemMap, command, false);
            commandListPane(player, itemMap, action);
        }));
        modPane.addButton(new Button(fillerPaneGItem));
        modPane.addButton(new Button(ItemHandler.getItem("BARRIER", 1, false, "&c&l&nReturn", "&7", "&7*Returns you to the command lines menu."), event -> commandListPane(player, itemMap, action)));
        modPane.addButton(new Button(fillerPaneBItem), 7);
        modPane.addButton(new Button(ItemHandler.getItem("BARRIER", 1, false, "&c&l&nReturn", "&7", "&7*Returns you to the command lines menu."), event -> commandListPane(player, itemMap, action)));
    });
    modPane.open(player);
}
Also used : ItemHandler(me.RockinChaos.itemjoin.handlers.ItemHandler) PatternType(org.bukkit.block.banner.PatternType) Enchantment(org.bukkit.enchantments.Enchantment) GameProfile(com.mojang.authlib.GameProfile) Player(org.bukkit.entity.Player) LanguageAPI(me.RockinChaos.itemjoin.utils.api.LanguageAPI) Inventory(org.bukkit.inventory.Inventory) DependAPI(me.RockinChaos.itemjoin.utils.api.DependAPI) World(org.bukkit.World) Map(java.util.Map) PlayerInventory(org.bukkit.inventory.PlayerInventory) Material(org.bukkit.Material) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) Bukkit(org.bukkit.Bukkit) Action(me.RockinChaos.itemjoin.item.ItemCommand.Action) CommandSender(org.bukkit.command.CommandSender) UUID(java.util.UUID) Sound(org.bukkit.Sound) ItemMap(me.RockinChaos.itemjoin.item.ItemMap) EntityType(org.bukkit.entity.EntityType) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) ItemUtilities(me.RockinChaos.itemjoin.item.ItemUtilities) ItemStack(org.bukkit.inventory.ItemStack) List(java.util.List) SchedulerUtils(me.RockinChaos.itemjoin.utils.SchedulerUtils) StringUtils(me.RockinChaos.itemjoin.utils.StringUtils) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) ItemJoin(me.RockinChaos.itemjoin.ItemJoin) PotionEffectType(org.bukkit.potion.PotionEffectType) Button(me.RockinChaos.itemjoin.utils.interfaces.Button) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Pattern(org.bukkit.block.banner.Pattern) BookMeta(org.bukkit.inventory.meta.BookMeta) Interface(me.RockinChaos.itemjoin.utils.interfaces.Interface) HashMap(java.util.HashMap) HeadDatabaseAPI(me.arcaniax.hdb.api.HeadDatabaseAPI) BannerMeta(org.bukkit.inventory.meta.BannerMeta) ServerUtils(me.RockinChaos.itemjoin.utils.ServerUtils) ArrayList(java.util.ArrayList) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) Environment(org.bukkit.World.Environment) Property(com.mojang.authlib.properties.Property) ConfigHandler(me.RockinChaos.itemjoin.handlers.ConfigHandler) Color(org.bukkit.Color) Attribute(org.bukkit.attribute.Attribute) Type(org.bukkit.FireworkEffect.Type) PlayerHandler(me.RockinChaos.itemjoin.handlers.PlayerHandler) LegacyAPI(me.RockinChaos.itemjoin.utils.api.LegacyAPI) DecimalFormat(java.text.DecimalFormat) Field(java.lang.reflect.Field) File(java.io.File) PotionEffect(org.bukkit.potion.PotionEffect) CommandSequence(me.RockinChaos.itemjoin.item.ItemCommand.CommandSequence) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ItemCommand(me.RockinChaos.itemjoin.item.ItemCommand) ChatColor(org.bukkit.ChatColor) DyeColor(org.bukkit.DyeColor) ItemCommand(me.RockinChaos.itemjoin.item.ItemCommand) Button(me.RockinChaos.itemjoin.utils.interfaces.Button) Interface(me.RockinChaos.itemjoin.utils.interfaces.Interface)

Example 3 with ItemCommand

use of me.RockinChaos.itemjoin.item.ItemCommand in project ItemJoin by RockinChaos.

the class Menu method modifyCommands.

/**
 * Modifies an existing ItemCommand or adds the new ItemCommand to the ItemMap.
 *
 * @param itemMap - The ItemMap currently being modified.
 * @param itemCommand - The itemCommand to be modified or added.
 * @param newCommand - If this is a new command being added.
 */
private static void modifyCommands(final ItemMap itemMap, final ItemCommand itemCommand, final boolean newCommand) {
    List<ItemCommand> arrayCommands = new ArrayList<ItemCommand>();
    for (ItemCommand command : itemMap.getCommands()) {
        arrayCommands.add(command);
    }
    if (newCommand) {
        arrayCommands.add(itemCommand);
    } else {
        arrayCommands.remove(itemCommand);
    }
    final ItemCommand[] commands = new ItemCommand[arrayCommands.size()];
    for (int i = 0; i < arrayCommands.size(); ++i) {
        commands[i] = arrayCommands.get(i);
    }
    itemMap.setCommands(commands);
}
Also used : ItemCommand(me.RockinChaos.itemjoin.item.ItemCommand) ArrayList(java.util.ArrayList)

Example 4 with ItemCommand

use of me.RockinChaos.itemjoin.item.ItemCommand in project ItemJoin by RockinChaos.

the class Menu method commandPane.

// ============================================== //
// ItemCommand Menus        	       //
// ============================================== //
/**
 * Opens the Pane for the Player.
 * This Pane is for modifying an items commands.
 *
 * @param player - The Player to have the Pane opened.
 * @param itemMap - The ItemMap currently being modified.
 */
private static void commandPane(final Player player, final ItemMap itemMap) {
    Interface commandPane = new Interface(false, 3, GUIName, player);
    SchedulerUtils.runAsync(() -> {
        commandPane.addButton(new Button(fillerPaneGItem), 4);
        commandPane.addButton(new Button(ItemHandler.getItem((ServerUtils.hasSpecificUpdate("1_13") ? "WRITABLE_BOOK" : "386"), 1, false, "&e&lCommands", "&7", "&7*Click to define the custom command lines", "&7for the item and click type.", "&7", "&9&lCommands: &a" + (itemMap.getCommands().length != 0 ? "YES" : "NONE")), event -> actionPane(player, itemMap)));
        commandPane.addButton(new Button(fillerPaneGItem), 4);
        commandPane.addButton(new Button(ItemHandler.getItem("REDSTONE", 1, false, "&a&lParticle", "&7", "&7*Custom particle(s) that will be", "&7displayed when the commands", "&7are successfully executed.", "&9&lCOMMANDS-PARTICLE: &a" + StringUtils.nullCheck(itemMap.getCommandParticle() + "")), event -> {
            if (StringUtils.nullCheck(itemMap.getCommandParticle() + "") != "NONE") {
                itemMap.setCommandParticle(null);
                commandPane(player, itemMap);
            } else {
                particlePane(player, itemMap, 3);
            }
        }));
        commandPane.addButton(new Button(ItemHandler.getItem("EMERALD", 1, false, "&a&lItem Cost", "&7", "&7*Material that will", "&7be charged upon successfully", "&7executing the commands.", "&9&lCOMMANDS-ITEM: &a" + (StringUtils.nullCheck(itemMap.getItemCost()))), event -> {
            if (StringUtils.nullCheck(itemMap.getItemCost()) != "NONE") {
                itemMap.setItemCost(null);
                commandPane(player, itemMap);
            } else {
                materialPane(player, itemMap, 2, 0);
            }
        }));
        commandPane.addButton(new Button(ItemHandler.getItem("DIAMOND", 1, false, "&a&lCost", "&7", "&7*Amount that the player will", "&7be charged upon successfully", "&7executing the commands.", "&9&lCOMMANDS-COST: &a" + (StringUtils.nullCheck(itemMap.getCommandCost() + "&7"))), event -> {
            if (StringUtils.nullCheck(itemMap.getCommandCost() + "&7") != "NONE") {
                itemMap.setCommandCost(0);
                commandPane(player, itemMap);
            } else {
                costPane(player, itemMap);
            }
        }));
        commandPane.addButton(new Button(ItemHandler.getItem("STONE_BUTTON", 1, false, "&a&lReceive", "&7", "&7*The number of times the", "&7commands will execute when", "&7receiving the custom item.", "&cNOTE: &7Only functions with", "&7the on-receive command action.", "&9&lCOMMANDS-RECEIVE: &a" + (StringUtils.nullCheck(itemMap.getCommandReceive() + "&7"))), event -> {
            if (StringUtils.nullCheck(itemMap.getCommandReceive() + "&7") != "NONE") {
                itemMap.setCommandReceive(0);
                commandPane(player, itemMap);
            } else {
                receivePane(player, itemMap);
            }
        }));
        commandPane.addButton(new Button(ItemHandler.getItem("ICE", 1, false, "&a&lCooldown", "&7", "&7*The time that the commands will", "&7be on cooldown for.", "&7", "&9&lCOMMANDS-COOLDOWN: &a" + StringUtils.nullCheck(itemMap.getCommandCooldown() + "&7") + (StringUtils.nullCheck(itemMap.getCommandCooldown() + "&7") != "NONE" ? "&a second(s)" : "")), event -> {
            if (StringUtils.nullCheck(itemMap.getCommandCooldown() + "&7") != "NONE") {
                itemMap.setCommandCooldown(0);
                commandPane(player, itemMap);
            } else {
                cooldownPane(player, itemMap);
            }
        }));
        commandPane.addButton(new Button(ItemHandler.getItem((ServerUtils.hasSpecificUpdate("1_13") ? "OAK_SIGN" : "323"), 1, false, "&a&lCooldown Message", "&7", "&7*Optional cooldown message", "&7to be displayed when", "&7the items commands are", "&7on cooldown.", "&9&lCOOLDOWN-MESSAGE: &a" + StringUtils.nullCheck(itemMap.getCooldownMessage())), event -> {
            if (StringUtils.nullCheck(itemMap.getCooldownMessage()) != "NONE") {
                itemMap.setCooldownMessage(null);
                commandPane(player, itemMap);
            } else {
                player.closeInventory();
                String[] placeHolders = LanguageAPI.getLang(false).newString();
                placeHolders[16] = "COOLDOWN MESSAGE";
                placeHolders[15] = "&cThis item is on cooldown for &a%timeleft% &cseconds..";
                LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputType", player, placeHolders);
                LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputExample", player, placeHolders);
            }
        }, event -> {
            itemMap.setCooldownMessage(ChatColor.stripColor(event.getMessage()));
            String[] placeHolders = LanguageAPI.getLang(false).newString();
            placeHolders[16] = "COOLDOWN MESSAGE";
            LanguageAPI.getLang(false).sendLangMessage("commands.menu.inputSet", player, placeHolders);
            commandPane(event.getPlayer(), itemMap);
        }));
        commandPane.addButton(new Button(ItemHandler.getItem("JUKEBOX", 1, false, "&a&lSound", "&7", "&7*The sound that will be", "&7played after a successful", "&7command execution.", "&9&lCOMMANDS-SOUND: &a" + StringUtils.nullCheck(itemMap.getCommandSound() + ""), "&9&lVOLUME: &a" + ((StringUtils.nullCheck(itemMap.getCommandSound() + "") != "NONE") ? itemMap.getCommandVolume() : "0"), "&9&lPITCH: &a" + ((StringUtils.nullCheck(itemMap.getCommandSound() + "") != "NONE") ? itemMap.getCommandPitch() : "0")), event -> {
            if (StringUtils.nullCheck(itemMap.getCommandSound() + "") != "NONE") {
                itemMap.setCommandSound(null);
                commandPane(player, itemMap);
            } else {
                soundPane(player, itemMap, 3);
            }
        }));
        commandPane.addButton(new Button(ItemHandler.getItem((ServerUtils.hasSpecificUpdate("1_13") ? "REPEATER" : "356"), 1, false, "&a&lSequence", "&7", "&7*The order that the command lines", "&7will be executed in.", "&9&lCOMMANDS-SEQUENCE: &a" + StringUtils.nullCheck(itemMap.getCommandSequence() + "")), event -> {
            if (StringUtils.nullCheck(itemMap.getCommandSequence() + "") != "NONE") {
                itemMap.setCommandSequence(null);
                commandPane(player, itemMap);
            } else {
                sequencePane(player, itemMap, 0);
            }
        }));
        commandPane.addButton(new Button(ItemHandler.getItem((ServerUtils.hasSpecificUpdate("1_13") ? "LAVA_BUCKET" : "327"), 1, false, "&a&lWarmup", "&7", "&7*The time it will take before", "&7the commands are executed.", "&7Player movement will cancel the", "&7pending commands execution.", "&7", "&9&lCOMMANDS-WARMUP: &a" + StringUtils.nullCheck(itemMap.getWarmDelay() + "&7") + (StringUtils.nullCheck(itemMap.getWarmDelay() + "&7") != "NONE" ? "&a second(s)" : "")), event -> {
            if (StringUtils.nullCheck(itemMap.getWarmDelay() + "&7") != "NONE") {
                itemMap.setWarmDelay(0);
                commandPane(player, itemMap);
            } else {
                warmPane(player, itemMap);
            }
        }));
        commandPane.addButton(new Button(ItemHandler.getItem("BARRIER", 1, false, "&c&l&nReturn", "&7", "&7*Returns you to the item definition menu."), event -> creatingPane(player, itemMap)));
        commandPane.addButton(new Button(fillerPaneBItem), 7);
        commandPane.addButton(new Button(ItemHandler.getItem("BARRIER", 1, false, "&c&l&nReturn", "&7", "&7*Returns you to the item definition menu."), event -> creatingPane(player, itemMap)));
    });
    commandPane.open(player);
}
Also used : ItemHandler(me.RockinChaos.itemjoin.handlers.ItemHandler) PatternType(org.bukkit.block.banner.PatternType) Enchantment(org.bukkit.enchantments.Enchantment) GameProfile(com.mojang.authlib.GameProfile) Player(org.bukkit.entity.Player) LanguageAPI(me.RockinChaos.itemjoin.utils.api.LanguageAPI) Inventory(org.bukkit.inventory.Inventory) DependAPI(me.RockinChaos.itemjoin.utils.api.DependAPI) World(org.bukkit.World) Map(java.util.Map) PlayerInventory(org.bukkit.inventory.PlayerInventory) Material(org.bukkit.Material) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) Bukkit(org.bukkit.Bukkit) Action(me.RockinChaos.itemjoin.item.ItemCommand.Action) CommandSender(org.bukkit.command.CommandSender) UUID(java.util.UUID) Sound(org.bukkit.Sound) ItemMap(me.RockinChaos.itemjoin.item.ItemMap) EntityType(org.bukkit.entity.EntityType) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) ItemUtilities(me.RockinChaos.itemjoin.item.ItemUtilities) ItemStack(org.bukkit.inventory.ItemStack) List(java.util.List) SchedulerUtils(me.RockinChaos.itemjoin.utils.SchedulerUtils) StringUtils(me.RockinChaos.itemjoin.utils.StringUtils) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) ItemJoin(me.RockinChaos.itemjoin.ItemJoin) PotionEffectType(org.bukkit.potion.PotionEffectType) Button(me.RockinChaos.itemjoin.utils.interfaces.Button) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Pattern(org.bukkit.block.banner.Pattern) BookMeta(org.bukkit.inventory.meta.BookMeta) Interface(me.RockinChaos.itemjoin.utils.interfaces.Interface) HashMap(java.util.HashMap) HeadDatabaseAPI(me.arcaniax.hdb.api.HeadDatabaseAPI) BannerMeta(org.bukkit.inventory.meta.BannerMeta) ServerUtils(me.RockinChaos.itemjoin.utils.ServerUtils) ArrayList(java.util.ArrayList) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) Environment(org.bukkit.World.Environment) Property(com.mojang.authlib.properties.Property) ConfigHandler(me.RockinChaos.itemjoin.handlers.ConfigHandler) Color(org.bukkit.Color) Attribute(org.bukkit.attribute.Attribute) Type(org.bukkit.FireworkEffect.Type) PlayerHandler(me.RockinChaos.itemjoin.handlers.PlayerHandler) LegacyAPI(me.RockinChaos.itemjoin.utils.api.LegacyAPI) DecimalFormat(java.text.DecimalFormat) Field(java.lang.reflect.Field) File(java.io.File) PotionEffect(org.bukkit.potion.PotionEffect) CommandSequence(me.RockinChaos.itemjoin.item.ItemCommand.CommandSequence) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) ItemCommand(me.RockinChaos.itemjoin.item.ItemCommand) ChatColor(org.bukkit.ChatColor) DyeColor(org.bukkit.DyeColor) Button(me.RockinChaos.itemjoin.utils.interfaces.Button) Interface(me.RockinChaos.itemjoin.utils.interfaces.Interface)

Example 5 with ItemCommand

use of me.RockinChaos.itemjoin.item.ItemCommand in project ItemJoin by RockinChaos.

the class Menu method listCommands.

/**
 * Gets the command for the specified action.
 *
 * @param itemMap - The ItemMap currently being modified.
 * @param action - The action that the command should contain.
 * @return The raw String command.
 */
private static String listCommands(final ItemMap itemMap, final Action action) {
    String commands = "";
    String commandReturn = "NONE";
    for (ItemCommand command : itemMap.getCommands()) {
        if (command.matchAction(action)) {
            commands += command.getRawCommand() + " /n ";
        }
    }
    if (StringUtils.nullCheck(commands) != "NONE") {
        commandReturn = commands;
    }
    return commandReturn;
}
Also used : ItemCommand(me.RockinChaos.itemjoin.item.ItemCommand)

Aggregations

ItemCommand (me.RockinChaos.itemjoin.item.ItemCommand)8 ArrayList (java.util.ArrayList)6 GameProfile (com.mojang.authlib.GameProfile)5 Property (com.mojang.authlib.properties.Property)5 Field (java.lang.reflect.Field)5 ItemMap (me.RockinChaos.itemjoin.item.ItemMap)5 HeadDatabaseAPI (me.arcaniax.hdb.api.HeadDatabaseAPI)5 Material (org.bukkit.Material)5 Pattern (org.bukkit.block.banner.Pattern)5 File (java.io.File)4 DecimalFormat (java.text.DecimalFormat)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 UUID (java.util.UUID)4 ItemJoin (me.RockinChaos.itemjoin.ItemJoin)4 ConfigHandler (me.RockinChaos.itemjoin.handlers.ConfigHandler)4 ItemHandler (me.RockinChaos.itemjoin.handlers.ItemHandler)4 PlayerHandler (me.RockinChaos.itemjoin.handlers.PlayerHandler)4 Action (me.RockinChaos.itemjoin.item.ItemCommand.Action)4