Solved i want a plugin... Its like a chest plugin

Discussion in 'Plugin Help/Development/Requests' started by ArtHD, Dec 5, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    ArtHD

    i want a plugin that you have a chest in your inventory then if you put it in your hand then right click it will give the item inside of it ahm.. example the chest name is Christmas Box and that chest is in your inventory when you right click it it will give a sword ChristmasSword or any item inside of it please help me
     
  2. Offline

    timtower Moderator Moderator

    @ArtHD So you want a random item plugin? Predefined of course.
     
  3. Offline

    ArtHD

    ahhm i dont think so ? but its just like this
     

    Attached Files:

  4. Offline

    timtower Moderator Moderator

    @ArtHD That still doesn't explain it.
    Not for me at least, a gift chest?
     
  5. Offline

    ArtHD

    no its random look at the picture i get a chest name CaixaDaSorte then when i right click it in my hand then it will open then give random Caixadasorte item
     
  6. Offline

    timtower Moderator Moderator

    @ArtHD The picture isn't very clear either.
    Please explain everything in text, maybe an example config?
     
  7. Offline

    ArtHD

    i dont have example of config i see that in other server its a like a loot chest but your holding it then when you right clicked while holding them it gives the loot inside of it but when i search loot chest plugins its not like the plugin i want please help...
     
  8. Offline

    TheMrJezza

    @timtower Just a guess, but I think he wants a GUI with a chest. When you click that chest it will give you a chest with a random item inside.
     
  9. Offline

    Scorpionvssub

    Sooo... You hold a chest and you right click holding it, the chest becomes an item from a config item list?
     
  10. Offline

    TheMrJezza

    If I'm right...
    Step 1: You click a chest in an inventory GUI, it's like a button, that gives you a PRESENT CHEST (chest).
    Step 2: Once you have the PRESENT CHEST in your inventory, you place it like a normal chest.
    Step 3: You open the PRESENT CHEST and take out the RANDOM ITEM inside.
    Step 4: That's it. Once the RANDOM ITEM is gone, the PRESENT CHEST will disappear.

    Notes: The RANDOM ITEM can only be tools, weapons or armour with or without enchantments. The name of the RANDOM ITEM in the PRESENT CHEST is made up of 2 Strings. Example: "Present" + RANDOM ITEM.getType.name();

    PRESENT CHEST and RANDOM ITEM are in caps so I'm sure you understand that the item in the chest has to be random and present chest is in caps so you know which chest I'm talking about.

    This is how I see the request, I'm not 100% sure this is what is @ArtHD wants. Anyone confused?

    Edit: I re-read the request, you don't place the PRESENT CHEST, you just right click it in your hand and it opens.

    Edit Again: I had a really basic try at this. It's not tested so sorry if there's an error. Download

    Commands /pchest /pchestgui

    Here is the code so anyone else can edit it and probably make it better. I'm gonna go offline. Bye guys.
    Code:
    package me.TheMrJezza.PresentChest;
    
    import java.util.Random;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class PresentChestMain extends JavaPlugin implements Listener {
    
        @Override
        public void onEnable() {
            this.getServer().getPluginManager().registerEvents(this, this);
        }
    
        public static Inventory GameMenu = Bukkit.createInventory(null, 54,
                "Present Chest GUI");
    
        public static String chestName = ChatColor.RESET + ""
                + ChatColor.DARK_GREEN + "Present";
        public String itemName = ChatColor.RESET + "" + ChatColor.DARK_GREEN
                + "Present " + ChatColor.DARK_RED + "Chest";
    
        static {
            ItemStack chest = new ItemStack(Material.CHEST);
            ItemMeta meta = chest.getItemMeta();
            meta.setDisplayName(chestName);
            chest.setItemMeta(meta);
            GameMenu.setItem(0, chest);
        }
    
        String error = ChatColor.DARK_RED + "Error: ";
    
        public boolean onCommand(CommandSender cs, Command cmd, String aliases,
                String[] args) {
    
            if (cmd.getName().equalsIgnoreCase("pchest")) {
                if (!(cs instanceof Player)) {
                    cs.sendMessage(error + ChatColor.RED
                            + "Only in-game players can do that!");
                    return true;
                } else if (cs instanceof Player) {
                    Player player = (Player) cs;
                    ItemStack chest = new ItemStack(Material.CHEST);
                    ItemMeta meta = chest.getItemMeta();
                    meta.setDisplayName(itemName);
                    chest.setItemMeta(meta);
                    if (!player.getInventory().contains(chest)) {
                        player.getInventory().addItem(chest);
                        player.sendMessage(ChatColor.GREEN + "Enjoy your present!");
                        return true;
                    } else
                        player.sendMessage(ChatColor.RED
                                + "You already have a present");
                    return true;
                }
            } else if (cmd.getName().equalsIgnoreCase("pchestgui")) {
                if (!(cs instanceof Player)) {
                    cs.sendMessage(error + ChatColor.RED
                            + "Only in-game players can do that!");
                    return true;
                } else if (cs instanceof Player) {
                    Player player = (Player) cs;
                    player.openInventory(GameMenu);
                    return true;
                }
            }
            return false;
        }
    
        @EventHandler
        public void onInvClick(InventoryClickEvent evt) {
            Player player = (Player) evt.getWhoClicked();
            ItemStack clicked = evt.getCurrentItem();
            if (clicked.hasItemMeta()) {
                if (clicked.getItemMeta().getDisplayName().equals(chestName)) {
                    evt.setCancelled(true);
                    ItemStack chest = new ItemStack(Material.CHEST);
                    ItemMeta meta = chest.getItemMeta();
                    meta.setDisplayName(ChatColor.RESET + "" + ChatColor.DARK_GREEN
                            + "Present " + ChatColor.DARK_RED + "Chest");
                    chest.setItemMeta(meta);
                    if (!player.getInventory().contains(chest)) {
                        player.getInventory().addItem(chest);
                        player.sendMessage(ChatColor.GREEN + "Enjoy your present!");
                    } else
                        player.sendMessage(ChatColor.RED
                                + "You already have a present");
                }
            }
        }
    
        @EventHandler
        public void onItemClick(PlayerInteractEvent evt) {
            Player player = evt.getPlayer();
            Action action = evt.getAction();
            ItemStack hand = player.getItemInHand();
            if ((action == Action.RIGHT_CLICK_AIR)
                    || (action == Action.RIGHT_CLICK_BLOCK)) {
                if (hand.hasItemMeta()) {
                    String handName = hand.getItemMeta().getDisplayName();
                    if (handName.equals(itemName)) {
                        player.getInventory().remove(hand);
                        if (player.getInventory().firstEmpty() == -1) {
                            Location loc = player.getLocation();
                            loc.getWorld().dropItemNaturally(loc, getRandomItem());
                            player.sendMessage(ChatColor.GREEN
                                    + "Merry Christmas! We dropped your present at your feet.");
                        } else {
                            player.getInventory().addItem(getRandomItem());
                            player.sendMessage(ChatColor.GREEN + "Merry Christmas!");
                        }
                    }
                }
            }
        }
    
        @EventHandler
        public void onBlockPlace(BlockPlaceEvent evt) {
            Player player = evt.getPlayer();
            ItemStack hand = player.getItemInHand();
            if (hand.hasItemMeta()) {
                if (hand.getItemMeta().getDisplayName().equals(itemName)) {
                    evt.setCancelled(true);
                }
            }
        }
    
        public ItemStack getRandomItem() {
            ItemStack sword = new ItemStack(Material.DIAMOND_SWORD);
            ItemStack axe = new ItemStack(Material.DIAMOND_AXE);
            ItemStack pickaxe = new ItemStack(Material.DIAMOND_PICKAXE);
            ItemStack hoe = new ItemStack(Material.DIAMOND_HOE);
            ItemStack spade = new ItemStack(Material.DIAMOND_SPADE);
    
            ItemMeta swordMeta = sword.getItemMeta();
            ItemMeta axeMeta = axe.getItemMeta();
            ItemMeta pickaxeMeta = pickaxe.getItemMeta();
            ItemMeta hoeMeta = hoe.getItemMeta();
            ItemMeta spadeMeta = spade.getItemMeta();
    
            swordMeta.setDisplayName(ChatColor.RESET + "" + ChatColor.GREEN
                    + "Christmas " + ChatColor.RED + "Sword");
            axeMeta.setDisplayName(ChatColor.RESET + "" + ChatColor.GREEN
                    + "Christmas " + ChatColor.RED + "Axe");
            pickaxeMeta.setDisplayName(ChatColor.RESET + "" + ChatColor.GREEN
                    + "Christmas " + ChatColor.RED + "Pickaxe");
            hoeMeta.setDisplayName(ChatColor.RESET + "" + ChatColor.GREEN
                    + "Christmas " + ChatColor.RED + "Hoe");
            spadeMeta.setDisplayName(ChatColor.RESET + "" + ChatColor.GREEN
                    + "Christmas " + ChatColor.RED + "Spade");
    
            sword.setItemMeta(swordMeta);
            axe.setItemMeta(axeMeta);
            pickaxe.setItemMeta(pickaxeMeta);
            hoe.setItemMeta(hoeMeta);
            spade.setItemMeta(spadeMeta);
    
            Random random = new Random();
            int chance = random.nextInt(4);
            if (chance == 0) {
                return sword;
            } else if (chance == 1) {
                return axe;
            } else if (chance == 2) {
                return pickaxe;
            } else if (chance == 3) {
                return hoe;
            } else if (chance == 4) {
                return spade;
            } else
                return sword;
        }
    }
     
    Last edited: Dec 10, 2015
  11. Offline

    ArtHD

    no if you open the Chest as in Chest Block inside of it there is a Chest too inside of it. example name is [Lord's Chest] then when you claim it, it will goes to your inventory then put it in your hand then right click and then it will open then the "Lord's Chest" Chest will give you example name Lord's Chest diamond sword enchantment 50 or any item inside of it. :( Hoping to help me guys
     
  12. Offline

    danielporsh9

    That is exactly what @TheMrJezza just gave you..... Just take that code copy it change it up how ever you want to and complie it.
     
  13. Offline

    Scorpionvssub

    @danielporsh9 The topic says "plugin request" so i dont think pieces of code will help him X)
     
  14. Offline

    TheMrJezza

    @Scorpionvssub I gave a download of the plugin along with the code. I left the code so someone else could edit the plugin for this guy if I wasn't online. I set the plugin up as simple as I could. if you want to add more items, or add a config or anything to do with the items, all one would have to do is edit the getRandomItem() method to their liking. I've done all the hard work.
     
  15. Offline

    pie_flavor

    @ArtHD So, you open a chest, and take another chest out. You right click the another chest as if you were going to place it, but it disappears, and you get an item instead. Is this right?
     
  16. Offline

    ArtHD

    guys no need i found what plugin is it okay ? so thanks for you comments here thanks @TheMrJezza for plugin you gave to me i found what i need its LootBox. ^_^
     
Thread Status:
Not open for further replies.

Share This Page