Development Assistance iN The server not work -.-

Discussion in 'Plugin Help/Development/Requests' started by ratg97, Mar 25, 2015.

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

    ratg97

    Hi i have this own plugin of trails and i dont know why dont work for 1.8 minecraft version

    My code:

    Code:
    package me.Weaver.Effects;
    
    import java.lang.reflect.Field;
    import java.lang.reflect.Method;
    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.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    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.BukkitRunnable;
    
    public class Main extends JavaPlugin
      implements Listener
    {
      public static Inventory aura = Bukkit.createInventory(null, 9, "Auras");
    
      public void onEnable()
      {
        Bukkit.getPluginManager().registerEvents(this, this);
    
        saveDefaultConfig();
      
    
        ItemStack i1 = new ItemStack(Material.RECORD_3, 1);
        ItemMeta id1 = i1.getItemMeta();
        id1.setDisplayName(ChatColor.RED + "Saiyan");
        i1.setItemMeta(id1);
    
        ItemStack i2 = new ItemStack(Material.RECORD_5, 1);
        ItemMeta id2 = i2.getItemMeta();
        id2.setDisplayName(ChatColor.AQUA + "Majin");
        i2.setItemMeta(id2);
    
        ItemStack i3 = new ItemStack(Material.RECORD_4, 1);
        ItemMeta id3 = i3.getItemMeta();
        id3.setDisplayName(ChatColor.GREEN + "Namekiano");
        i3.setItemMeta(id3);
    
        ItemStack i4 = new ItemStack(Material.RECORD_7, 1);
        ItemMeta id4 = i4.getItemMeta();
        id4.setDisplayName(ChatColor.LIGHT_PURPLE + "Dios");
        i4.setItemMeta(id4);
      
        ItemStack i5 = new ItemStack(Material.PAPER, 1);
        ItemMeta id5 = i5.getItemMeta();
        id5.setDisplayName(ChatColor.WHITE + "Nada");
        i5.setItemMeta(id5);
    
        aura.setItem(0, i1);
        aura.setItem(1, i2);
        aura.setItem(2, i3);
        aura.setItem(3, i4);
        aura.setItem(4, i4);
    
    
        BukkitRunnable b = new BukkitRunnable()
        {
          public void run()
          {
            for (Player b1 : Bukkit.getOnlinePlayers())
            {
                //apariencias
              if (Main.this.getConfig().getInt("Players." + b1.toString()) == 1)
                  Main.ParticleEffect.sendParticleToAll(Main.ParticleEffect.FIREWORKS_SPARK, b1.getLocation().add(0.0D, 0.5D, 0.0D), 0.0F, 0.0F, 0.0F, (float)Main.this.getConfig().getDouble("Spark.Speed"), Main.this.getConfig().getInt("Spark.Amount"));
              if (Main.this.getConfig().getInt("Players." + b1.toString()) == 2)
                  Main.ParticleEffect.sendParticleToAll(Main.ParticleEffect.HAPPY_VILLAGER, b1.getLocation().add(0.0D, 0.5D, 0.0D), 0.0F, 0.0F, 0.0F, 0.1F, Main.this.getConfig().getInt("Green.Amount"));
              if (Main.this.getConfig().getInt("Players." + b1.toString()) == 3) {
                Main.ParticleEffect.sendParticleToAll(Main.ParticleEffect.MAGIC_CRIT, b1.getLocation().add(1.0D, 1.0D, 0.0D), 0.0F, 0.0F, 0.0F, 0.0F, Main.this.getConfig().getInt("Magic.Amount"));
                Main.ParticleEffect.sendParticleToAll(Main.ParticleEffect.MAGIC_CRIT, b1.getLocation().add(-1.0D, 1.0D, 0.0D), 0.0F, 0.0F, 0.0F, 0.0F, Main.this.getConfig().getInt("Magic.Amount"));
                Main.ParticleEffect.sendParticleToAll(Main.ParticleEffect.MAGIC_CRIT, b1.getLocation().add(0.0D, 1.0D, 1.0D), 0.0F, 0.0F, 0.0F, 0.0F, Main.this.getConfig().getInt("Magic.Amount"));
                Main.ParticleEffect.sendParticleToAll(Main.ParticleEffect.MAGIC_CRIT, b1.getLocation().add(0.0D, 1.0D, -1.0D), 0.0F, 0.0F, 0.0F, 0.0F, Main.this.getConfig().getInt("Magic.Amount"));
              }
              if (Main.this.getConfig().getInt("Players." + b1.toString()) == 4) {
                  Main.ParticleEffect.sendParticleToAll(Main.ParticleEffect.INSTANT_SPELL, b1.getLocation().add(0.0D, 0.5D, 0.0D), 0.0F, 0.0F, 0.0F, (float)Main.this.getConfig().getDouble("WhiteMagic.Speed"), Main.this.getConfig().getInt("WhiteMagic.Amount"));
              }
            }
          }
        };
        b.runTaskTimer(this, 1L, 2L);
      }
    
      public void onDisable()
      {
      }
    
      @EventHandler
      public void onJoin(PlayerJoinEvent e)
      {
      }
    
      @EventHandler
      public void onCLick(InventoryClickEvent e)
      {
        Player p = (Player)e.getWhoClicked();
        if (e.getInventory().getName().equals(aura.getName()))
        {       
          if (e.getCurrentItem().getType() == Material.RECORD_3) {
            if ((p.hasPermission("aura.saiyan")) || (p.hasPermission("aura.all"))) {
              p.sendMessage(ChatColor.YELLOW + "Has seleccionado la aura " + ChatColor.RED + "Saiyan");
              getConfig().set("Players." + p.toString(), Integer.valueOf(1));
              p.closeInventory();
            } else {
              p.sendMessage(ChatColor.YELLOW + "Solo VIPs Saiyan tienen permiso");
              p.closeInventory();
            }
          }
    
          if (e.getCurrentItem().getType() == Material.RECORD_4) {
            if ((p.hasPermission("aura.namekiano")) || (p.hasPermission("aura.all"))) {
              p.sendMessage(ChatColor.YELLOW + "Has seleccionado la aura " + ChatColor.GREEN + "Namekiano");
              getConfig().set("Players." + p.toString(), Integer.valueOf(2));
              p.closeInventory();
            } else {
              p.sendMessage(ChatColor.YELLOW + "Solo Usuarios tienen permiso");
              p.closeInventory();
            }
          }
    
          if (e.getCurrentItem().getType() == Material.RECORD_7) {
            if ((p.hasPermission("aura.dios")) || (p.hasPermission("aura.all"))) {
              p.sendMessage(ChatColor.YELLOW + "Has seleccionado la aura " + ChatColor.GREEN + "Dios");
              getConfig().set("Players." + p.toString(), Integer.valueOf(3));
              p.closeInventory();
            } else {
              p.sendMessage(ChatColor.YELLOW + "Solo Admins tienen permiso");
              p.closeInventory();
            }
          }
        
          if (e.getCurrentItem().getType() == Material.RECORD_5) {
              if ((p.hasPermission("aura.majin")) || (p.hasPermission("aura.all"))) {
                  p.sendMessage(ChatColor.YELLOW + "Has seleccionado la aura " + ChatColor.BLUE + "Majin");
                  getConfig().set("Players." + p.toString(), Integer.valueOf(4));
                  p.closeInventory();
                } else {
                  p.sendMessage(ChatColor.YELLOW + "Solo VIPs Majin tienen permiso");
                  p.closeInventory();
            }
          }
        
          if (e.getCurrentItem().getType() == Material.PAPER) {
              if ((p.hasPermission("aura.allow")) || (p.hasPermission("aura.all"))) {
                p.sendMessage(ChatColor.YELLOW + "Has quitado tu aura");
                getConfig().set("Players." + p.toString(), null);
                p.closeInventory();
              } else {
                p.sendMessage(ChatColor.YELLOW + "Solo Usuarios tienen permiso");
                p.closeInventory();
              }
            }
    }
        
      
    }
    
      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] agrs)
      {
        if ((sender instanceof Player)) {
          Player player = (Player)sender;
          if (cmd.getName().equalsIgnoreCase("auras")) {
            if (player.hasPermission("aura.allow"))
            {
              player.openInventory(aura);
            } else if (!player.hasPermission("aura.allow")) {
              player.sendMessage(ChatColor.YELLOW + "No tienes permisoss");
            }
          }
    
        }
    
        return false;
      }
    
    //AquĆ­ la libreria
    
      public static enum ParticleEffect
      {
        HUGE_EXPLOSION("hugeexplosion"),
        LARGE_EXPLODE("largeexplode"),
        FIREWORKS_SPARK("fireworksSpark"),
        BUBBLE("bubble"),
        SUSPEND("suspend"),
        DEPTH_SUSPEND("depthSuspend"),
        TOWN_AURA("townaura"),
        CRIT("crit"),
        MAGIC_CRIT("magicCrit"),
        MOB_SPELL("mobSpell"),
        MOB_SPELL_AMBIENT("mobSpellAmbient"),
        SPELL("spell"),
        INSTANT_SPELL("instantSpell"),
        WITCH_MAGIC("witchMagic"),
        NOTE("note"),
        PORTAL("portal"),
        ENCHANTMENT_TABLE("enchantmenttable"),
        EXPLODE("explode"),
        FLAME("flame"),
        LAVA("lava"),
        FOOTSTEP("footstep"),
        SPLASH("splash"),
        LARGE_SMOKE("largesmoke"),
        CLOUD("cloud"),
        RED_DUST("reddust"),
        SNOWBALL_POOF("snowballpoof"),
        DRIP_WATER("dripWater"),
        DRIP_LAVA("dripLava"),
        SNOW_SHOVEL("snowshovel"),
        SLIME("slime"),
        HEART("heart"),
        ANGRY_VILLAGER("angryVillager"),
        HAPPY_VILLAGER("happyVillager"),
        ICONCRACK("iconcrack_"),
        TILECRACK("tilecrack_"),
        BLOCKDUST("blockdust_");
    
        private String particleName;
        private static Random random;
    
        static { random = new Random(); }
    
        private ParticleEffect(String particleName) {
          this.particleName = particleName;
        }
    
        public String getName() {
          return this.particleName;
        }
    
        private static Object getEntityPlayer(Player p) throws Exception {
          return p.getClass().getMethod("getHandle", new Class[0]).invoke(p, new Object[0]);
        }
    
        private static String getPackageName() {
          return "net.minecraft.server." + Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
        }
    
        private static Object getParticlePacket() throws Exception {
          Class packet = Class.forName(getPackageName() + ".PacketPlayOutWorldParticles");
          return packet.getConstructors()[0].newInstance(new Object[0]);
        }
    
        private static Class<?> getPacketClass() throws Exception {
          return Class.forName(getPackageName() + ".Packet");
        }
    
        public static Object getPacket(String particleName, Location location, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
          try {
            Object packet = getParticlePacket();
            setField(packet, "a", particleName);
            setField(packet, "b", Float.valueOf((float)location.getX()));
            setField(packet, "c", Float.valueOf((float)location.getY()));
            setField(packet, "d", Float.valueOf((float)location.getZ()));
            setField(packet, "e", Float.valueOf(offsetX));
            setField(packet, "f", Float.valueOf(offsetY));
            setField(packet, "g", Float.valueOf(offsetZ));
            setField(packet, "h", Float.valueOf(speed));
            setField(packet, "i", Integer.valueOf(amount));
            return packet; } catch (Exception e) {
          }
          return null;
        }
    
        public static void sendParticle(Player player, String particleName, Location location, float offsetX, float offsetY, float offsetZ, float speed, int amount)
        {
          try {
            Object packet = getPacket(particleName, location, offsetX, offsetY, offsetZ, speed, amount);
    
            Object eplayer = getEntityPlayer(player);
            Field playerConnectionField = eplayer.getClass().getField("playerConnection");
            Object playerConnection = playerConnectionField.get(eplayer);
            playerConnection.getClass().getMethod("sendPacket", new Class[0]).invoke(playerConnection, new Object[] { packet });
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
    
        public static void sendParticle(Player player, ParticleEffect particle, Location location, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
          sendParticle(player, particle.particleName, location, offsetX, offsetY, offsetZ, speed, amount);
        }
    
        public static void sendIconCrack(Player player, String iconName, Location location, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
          sendParticle(player, "iconcrack_" + iconName, location, offsetX, offsetY, offsetZ, speed, amount);
        }
    
        public static void sendTileCrack(Player player, String tileName, Location location, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
          sendParticle(player, "tilecrack_" + tileName, location, offsetX, offsetY, offsetZ, speed, amount);
        }
    
        public static void sendParticleToAll(ParticleEffect particle, Location location, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
          sendParticleToAll(particle.getName(), location, offsetX, offsetY, offsetZ, speed, amount);
        }
    
        public static void sendParticleNearby(String particleName, Location location, float offsetX, float offsetY, float offsetZ, float speed, int amount)
        {
          double f = (random.nextDouble() - 0.5D) * 2.0D;
          double d3 = f > 1.0D ? 16.0D * f : 16.0D;
          try
          {
            Object ws = location.getWorld().getClass().getMethod("getHandle", new Class[0]).invoke(location.getWorld(), new Object[0]);
            Object mcs = ws.getClass().getMethod("getMinecraftServer", new Class[0]).invoke(ws, new Object[0]);
            Object plist = mcs.getClass().getMethod("getPlayerList", new Class[0]).invoke(mcs, new Object[0]);
            int dimension = ((Integer)getField(ws, "dimension")).intValue();
    
            Method m = plist.getClass().getMethod("sendPacketNearby", new Class[] { getPacketClass() });
            m.invoke(plist, new Object[] { Double.valueOf(location.getX()), Double.valueOf(location.getY()),
              Double.valueOf(location.getZ()), Double.valueOf(d3), Integer.valueOf(dimension),
              getPacket(particleName, location, offsetX, offsetY, offsetZ,
              speed, amount) });
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
    
        public static void sendParticleToAll(String particleName, Location location, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
          try {
            Object ws = location.getWorld().getClass().getMethod("getHandle", new Class[0]).invoke(location.getWorld(), new Object[0]);
            Object mcs = ws.getClass().getMethod("getMinecraftServer", new Class[0]).invoke(ws, new Object[0]);
            Object plist = mcs.getClass().getMethod("getPlayerList", new Class[0]).invoke(mcs, new Object[0]);
    
            Method m = plist.getClass().getMethod("sendAll", new Class[] { getPacketClass() });
    
            m.invoke(plist, new Object[] { getPacket(particleName, location, offsetX, offsetY, offsetZ,
              speed, amount) });
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
    
        public static void sendIconCrackToAll(int id, Integer data, Location location, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
          String s = "iconcrack_" + id + "_" + data;
          sendParticleToAll(s, location, offsetX, offsetY, offsetZ, speed, amount);
        }
    
        public static void sendTileCrackToAll(int id, Integer data, Location location, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
          String s = "tilecrack_" + id + "_" + data;
          sendParticleToAll(s, location, offsetX, offsetY, offsetZ, speed, amount);
        }
    
        public static void sendBlockDustToAll(int id, Integer data, Location location, float offsetX, float offsetY, float offsetZ, float speed, int amount) {
          String s = "blockdust_" + id + "_" + data;
          sendParticleToAll(s, location, offsetX, offsetY, offsetZ, speed, amount);
        }
    
        public static ParticleEffect get(String name) {
          for (ParticleEffect e : values()) {
            if (e.getName().equalsIgnoreCase(name)) {
              return e;
            }
          }
          return null;
        }
    
        public static void setField(Object instance, String fieldName, Object value)
          throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException
        {
          Field field = instance.getClass().getDeclaredField(fieldName);
          field.setAccessible(true);
          field.set(instance, value);
        }
    
        public static Object getField(Object instance, String fieldName)
          throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException
        {
          Field field = instance.getClass().getDeclaredField(fieldName);
          field.setAccessible(true);
          return field.get(instance);
        }
      }
    }
    
    When i select the trail that i want... i dont see the trails
     
  2. I don't know if you have worked with packets before, but they change on almost every update. In this case, the particle packet changed the particle name field from String to EnumParticle. It isn't hard to update, just go to the getPacket method and change setField(packet, "a", particleName) to: setField(packet, "a", EnumParticle.valueOf(particleName.toUpperCase())
     
    Tyler Christensen likes this.
  3. Online

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives
     
  4. Offline

    mine-care

    Don't abuse static please.
    Don't include overwritten methods that are empty like onDisable
    Don't bump in less than 24 hours

    @megamichiel explained what is wrong and how to fix it.
     
  5. Offline

    ratg97

    but i put it and eclipse say to me its wrong
    [​IMG]
     
  6. Offline

    nverdier

    @ratg97 Please post the entire code.
     
  7. Offline

    ratg97

    i only use one java class... is on my first comment

    i use other plugins like particlemenu and too it doest work for 1.8
     
  8. Offline

    nverdier

    @ratg97 Have you imported EnumParticle?
     
  9. Offline

    ratg97

    @nverdier this plugin work for 1.7 but for 1.8

    i dont import enumparticle

    i need help because the code is right i think
     
  10. Offline

    Konato_K

    @ratg97 It's not right for 1.8 because
     
  11. Offline

    ratg97

    where
     
  12. Offline

    ratg97

  13. If it doesn't show the import request make sure you have craftbukkit 1.8(not bukkit!) in your libraries
     
  14. Offline

    ratg97

    [​IMG]
    now i have this error
     
  15. @ratg97 Because you haven't put in a ParticleEffect array
     
  16. Offline

    ratg97

    i cant see the particles in the server..
     
  17. Offline

    nverdier

    @ratg97 You have to put a ParticleEffect array after the ':'...
    I suggest you learn Java. Read about that here.
     
  18. Offline

    ratg97

    ?? with this code is right all because in 1.7 work

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  19. Offline

    ratg97

  20. Offline

    ratg97

Thread Status:
Not open for further replies.

Share This Page