Treasure Chest

Discussion in 'Plugin Development' started by DeadlyDeath001, Apr 19, 2015.

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

    DeadlyDeath001

    How would I make this work. I want a chest to spawn with a warning 3, 2, 1, GOOO!!! for an example. Then Chest has spawned at warp pvp. With the loot warp pvp. Then repeat the whole process every 2 hours. But It is not working for me. This is what is happening.
    [​IMG]
    Source:
    Code:
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Chest;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitScheduler;
    
    public class TeasureChest extends JavaPlugin {
        public final Logger logger = Logger.getLogger("Minecraft");
        public static TeasureChest plugin;
        public int number = 3;
    
        @Override
        public void onDisable() {
            this.logger.info("DISABLED!");
        }
        @Override
        public void onEnable() {
            this.logger.info("ENABLED!");
    
            BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
            scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
                public void run() {
                    if (number != -1) {
                        if (number !=0) {
                            Bukkit.broadcastMessage("" + number);
                            number--;
                        } else {
                            Bukkit.broadcastMessage("GO!!!!!!");
                            number--;
                        }
                    }
                    getServer().broadcastMessage("Chest Has Spawned! At Warp PvP!");
                    int x = 10;
                    int y = 10;
                    int z = 10;
                    World w = Bukkit.getWorld("world");
                    Location chestLoc = new Location(w, x, y, z);
                    chestLoc.getBlock().setType(Material.CHEST);
                    Chest chest = (Chest) chestLoc.getBlock().getState();
                    Inventory inv = chest.getInventory();
                    ItemStack ds = new ItemStack(Material.DIAMOND_SWORD, 1);
                    ItemMeta dm = ds.getItemMeta();
                    dm.setDisplayName("Example");
                    ds.setItemMeta(dm);
                    inv.addItem(ds);
                }
            }, 0L, 20L);
        }
    }
    
    plugin.yml:
    Code:
    name: TreasureChest
    version: 1.0
    main: me.DeadlyDeath001.Chest.TeasureChest
    author: DeadlyDeath001
    description: A TreasureChest plugin!
     
  2. Offline

    Koobaczech

    Where are you reseting your counter?
     
    DeadlyDeath001 likes this.
  3. Offline

    sethrem

    Code:
            @Override
            public void onEnable() {
                this.logger.info("ENABLED!");
       
                BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
                scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
                    public void run() {
                        if (number != -1) {
                            if (number !=0) {
                                Bukkit.broadcastMessage("" + number);
                                number--;
                            } else {
                                getServer().broadcastMessage("Chest Has Spawned! At Warp PvP!");
                                int x = 10;
                                int y = 10;
                                int z = 10;
                                World w = Bukkit.getWorld("world");
                                Location chestLoc = new Location(w, x, y, z);
                                chestLoc.getBlock().setType(Material.CHEST);
                                Chest chest = (Chest) chestLoc.getBlock().getState();
                                Inventory inv = chest.getInventory();
                                ItemStack ds = new ItemStack(Material.DIAMOND_SWORD, 1);
                                ItemMeta dm = ds.getItemMeta();
                                dm.setDisplayName("Example");
                                ds.setItemMeta(dm);
                                inv.addItem(ds);
                                Bukkit.broadcastMessage("GO!!!!!!");
                                number--;
                              
                            }
                        }
                    }
                }, 0L, 20L);
            }
    This only fixes it to where it drops only on 0 seconds the reset do yourself
     
    DeadlyDeath001 likes this.
  4. Offline

    DeadlyDeath001

    Thank you but I have no idea how to reset it now
     
  5. Offline

    Koobaczech

    Simply do number=3; after everything is finished! So when it starts again its on 3 :)
     
  6. Offline

    SuperOriginal

    Few tips:
    • Don't steal Minecraft's logger, use getLogger()
    • This line is completely useless because you never assign it to anything. You should understand what something does before copying a youtuber.
    • You don't need to log enable and disable messages, Bukkit already does this for you.
     
  7. Offline

    KeybladePaladin



    I'm ok with your 1st statement.

    As for the other two:
    Maybe he kept it as a... (how do I explain this?) "safety" of sorts.
    Whenever I make Plugins, I tend to leave things that have no use just incase I need them later on (I am quite forgetful)

    Also, I personally hate Bukkits Console Enable/Disable messages and always use custom ones, with COLOR!
    Bukkit default messages don't have color, or I would have been ok with them. :p
     
  8. Offline

    SuperOriginal

    That makes no sense. Again, maybe you don't know how to explain it because you don't know what it does or how to use it? I would suggest not following that youtuber anymore (or any youtuber for that matter) as many people have their own habits/imperfections and it's best to not learn them. As for this line in particular, I would suggest learning about singletons or just stick to OOP.

    1. Since you were using Minecraft's logger, nobody would be able to figure out what plugin these messages were coming from.
    2. There's no color in this example :p

    Not trying to be rude, just trying to help.
     
  9. Offline

    CraftCreeper6

    @SuperOriginal
    getLogger() is a habit obtained from some terrible Youtuber, not mentioning any names. I'm sure we all know. (TheBCBroz). In addition, @KeybladePaladin colour is only for aesthetics and, to be honest, unless you are fixing errors within a plugin, no one will see...
     
  10. Invisible

    nverdier

    It's completely fine to use #getLogger(), however it's not to use #getLogger("Minecraft")
     
    CraftCreeper6 likes this.
  11. Offline

    CraftCreeper6

  12. Offline

    KeybladePaladin

    @SuperOriginal
    @CraftCreeper6

    You didn't sound rude, just a bit disrespectful to a fellow human. (Referring to @SuperOriginal )
    • I learn from JavaDocs (I tried tutorials once, but I would only recommend kennethbgoodin for beginners)
    • So what if there isn't color? That was just my opinion :p
     
    CraftCreeper6 likes this.
Thread Status:
Not open for further replies.

Share This Page