Development Assistance Flickering Stained Glass in inventory

Discussion in 'Plugin Help/Development/Requests' started by norrd007, May 4, 2015.

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

    norrd007

    Hey there, I am Norrd and I am trying to make a crate key plugin for my server where when you click the crates it opens an inventory and there is colored glass that flickers different colors like in the Archon's crates. Please could you help me. Would I use a loop to make the glass change color on a timer until the timer reaches zero?
     
    Last edited: May 4, 2015
  2. @norrd007 You don't want a loop. I beleive you're looking for a Bukkit runnable.
     
  3. Offline

    norrd007

    @CodePlaysMinecraft and how would I do that to make the glass change/flicker different colors? I have never used Bukkit runnable before.
     
  4. Offline

    Konato_K

  5. Offline

    norrd007

    @Konato_K Thank you! But I have done that but where would I put the code for the runnable because I have put it in but it isn't doing anything?!
    Code:
        public void OpenInventory(InventoryOpenEvent e) {
         
            new BukkitRunnable() {
             
                @Override
                public void run() {
                     Random r = new Random();
                     int rt = r.nextInt(14) + 1;
                       a.setDurability((short) rt);
                       b.setDurability((short) rt);
                       c.setDurability((short) rt);
                       d.setDurability((short) rt);
                 
                }
            }.runTaskLater(this.plugin, 1);
        }
     
  6. Offline

    Konato_K

    @norrd007 You're doing it wrong

    You have to schedule a timer (using runTaskTimer would work fine).
     
  7. Offline

    norrd007

    @Konato_K like this?
    Code:
    public class Menu implements Listener {
    
        Player player;
        Main plugin;
        public Inventory inv;
        private ItemStack a,b,c,d;
    
        public Menu(Plugin p) {
          Random r = new Random();
          int rt = r.nextInt(14) + 1; 
                a = createItem(Material.STAINED_GLASS_PANE, ChatColor.RESET + "", rt ,(short) 1).runTaskTimer(this.plugin, 10, 20);;
                b = createItem(Material.STAINED_GLASS_PANE, ChatColor.RESET + "", rt ,(short) 1).runTaskTimer(this.plugin, 10, 20);;
                c = createItem(Material.STAINED_GLASS_PANE, ChatColor.RESET + "", rt ,(short) 1).runTaskTimer(this.plugin, 10, 20);;
                d = createItem(Material.STAINED_GLASS_PANE, ChatColor.RESET + "", rt ,(short) 1).runTaskTimer(this.plugin, 10, 20);;
                BukkitTask task = new MenuSelfCancelingTask(this.plugin, 5).runTaskTimer(this.plugin, 10, 20);
           
            inv = Bukkit.createInventory(null, 27, ChatColor.GOLD + "Vote Crate!");
            inv.setItem(0, a);
            inv.setItem(8, b);
            inv.setItem(18, c);
            inv.setItem(26, d);
            Bukkit.getPluginManager().registerEvents(this, p);
        }
    
     
  8. Use this method do fill the inventory with different colored glass:
    Code:
    public void fillInv(Inventory inv) {
    Method name with an Inventory as parameter.

    Code:
    Random r = new Random();
    Define a new Random.

    Code:
    for (int i = 0; i < inv.getSize(); i++) {
    Loop through every slot in the inventory. Starting from 0 to the max slots.

    Code:
    inv.setItem(i, new ItemStack(Material.STAINED_CLASS_PANE, 1, (byte) r.nextInt(16)));
    Set the item at the slot (index) i, to a new ItemStack with the Material stained glass pane. 1 amount. And (byte) is the datavalue (for different colors).
    r.nextInt(16) generates a random int between 0 and 15.

    Whole method (don't copy paste)
    Code:
    public void fillInv(Inventory inv) {
    Random r = new Random();
    for (int i = 0; i < inv.getSize(); i++) {
    inv.setItem(i, new ItemStack(Material.STAINED_CLASS_PANE, 1, (byte) r.nextInt(16)));
    }
    }
     
  9. Offline

    norrd007

    @FisheyLP Thanks! But where would I put the
    Code:
     BukkitTask task = new ExampleSelfCancelingTask(this.plugin, 5).runTaskTimer(this.plugin, 10, 20);
    kinda bit so that it repeats and changes color every few seconds? @CodePlaysMinecraft @Konato_K
     
    Last edited: May 4, 2015
  10. The easiest repeating task (but may not the best):
    new BukkitRunnable () {
    public void run () {
    //possible to use: cancel();
    }
    }.runTaskLater(main, 10, 20);

    (20 ticks = 1 second)
    10 is the first delay (in ticks)
    20 is the interval for the repeating task (in ticks)
     
    Last edited: May 5, 2015
  11. Offline

    norrd007

    @FisheyLP ok, but where do I put it in a new class that just runs the Menu class repeatedly or in the main class or in the actual menu class?
     
  12. Offline

    Zombie_Striker

    @norrd007 Create a class that can be called, which takes in the Inventory. Then call it whenever you want it to flicker.
     
  13. Offline

    norrd007

    @Zombie_Striker @FisheyLP like this then?
    Code:
    public class Menu implements Listener {
       
       
        public static Inventory inv;
        private static ItemStack a;
        public static int taskid;
        private static ItemStack b;
        private static ItemStack c;
        private static ItemStack d;
       
        public Menu(Plugin p) {
            inv = Bukkit.getServer().createInventory(null, 27, "Particles Plugin");
            Bukkit.getPluginManager().registerEvents(this, p);
            Menu.Menus(p);
        }
       
        public static void Menus(Plugin p) {
            Random r = new Random();
            int rt = r.nextInt(14) + 1;
            rt = r.nextInt(14) + 1;
            a = createItem(Material.STAINED_GLASS_PANE, " ", (byte) rt);
            rt = r.nextInt(14) + 1;
            b = createItem(Material.STAINED_GLASS_PANE, " ", (byte) rt);
            rt = r.nextInt(14) + 1;
            c = createItem(Material.STAINED_GLASS_PANE, " ", (byte) rt);
            rt = r.nextInt(14) + 1;
            d = createItem(Material.STAINED_GLASS_PANE, " ", (byte) rt);
            rt = r.nextInt(14) + 1;
            inv.setItem(0, a);
            inv.setItem(8, b);
            inv.setItem(18, c);
            inv.setItem(26, d);
           
        }
       
        public void invOpen(InventoryOpenEvent e) {
            if(e.getInventory().getName().contains(inv.getName())) {
                Flicker.taskID;
            }
        }
    Code:
    public class Flicker  {
       
        static MainClass plugin;
        Menu menu = new Menu(plugin);
        Flicker flick;
       
        public Flicker(MainClass p, int counter) {
            menu = new Menu(p);
            Flicker.plugin = p;
        }
    
           @SuppressWarnings("deprecation")
        public static int taskID = Bukkit.getScheduler().scheduleAsyncRepeatingTask(Bukkit.getPluginManager().getPlugin(plugin.getName()), new Runnable(){
              
                @Override
                public void run() {
                    Menu.Menus(plugin);
                }
        
            }, 10L, 5L);
    
       
       
       
       
    
    }
    
     
  14. Offline

    Zombie_Striker

    @norrd007 Move the public static Menus() and add an Inventory instance to Flicker. The reason I said to make a new class for it was comparmentilize it. Each Flicker Class should be able to focus on one (or multiple if you want) Inventory.
     
  15. Offline

    norrd007

    @Zombie_Striker Error! @Konato_K @md_5
    06.05 23:21:24 [Server] INFO at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:710) [spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at java.util.concurrent.FutureTask.run(FutureTask.java:262) [?:1.7.0_75]
    06.05 23:21:24 [Server] INFO at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [?:1.7.0_75]
    06.05 23:21:24 [Server] INFO at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at net.minecraft.server.v1_8_R2.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at net.minecraft.server.v1_8_R2.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:52) [spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:734) [spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at net.minecraft.server.v1_8_R2.PlayerInteractManager.interact(PlayerInteractManager.java:463) [spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:226) [spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) [spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) [spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_75]
    06.05 23:21:24 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_75]
    06.05 23:21:24 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_75]
    06.05 23:21:24 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_75]
    06.05 23:21:24 [Server] INFO at com.norrd.ZCRATES.MainClass.onClickEvent(MainClass.java:40) [ZCrates.jar:?]
    06.05 23:21:24 [Server] INFO at com.norrd.ZCRATES.Menu.show(Menu.java:25) [ZCrates.jar:?]
    06.05 23:21:24 [Server] INFO at org.bukkit.craftbukkit.v1_8_R2.entity.CraftHumanEntity.openInventory(CraftHumanEntity.java:184) [spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at net.minecraft.server.v1_8_R2.EntityPlayer.openContainer(EntityPlayer.java:663) [spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.callInventoryOpenEvent(CraftEventFactory.java:714) [spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot.jar:git-Spigot-dbe012b-61ef214]
    06.05 23:21:24 [Server] INFO org.bukkit.event.EventException
    06.05 23:21:24 [Server] ERROR Could not pass event InventoryOpenEvent to ZCrates v1.0
     
    Last edited: May 8, 2015
Thread Status:
Not open for further replies.

Share This Page