Solved Strange Error

Discussion in 'Plugin Development' started by Letroy11, Oct 8, 2016.

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

    Letroy11

    I have created a personal loot plugin that stops a boss mob from dropping loot and instead drops it into the inventory of every player who attacked the boss. When I ran the plugin on the test server it worked fine, but after running it on the actual server it crashes constantly. Any help would be great.

    Code:
    package com.letroy11.Events;
    
    import com.letroy11.personalLoot.PersonalLoot;
    import java.util.ArrayList;
    import java.util.List;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.entity.EntityDeathEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    
    public class PlayerListener
      implements Listener
    {
      private PersonalLoot plugin;
      public ArrayList<Player> PlayersHitBoss = new ArrayList();
    
      public PlayerListener(PersonalLoot pl)
      {
        this.plugin = pl;
      }
    
      @EventHandler
      public void bossDeath(EntityDeathEvent event)
      {
        for (String name : this.plugin.getConfig().getStringList("Bosses")) {
          if (event.getEntity().getName().equalsIgnoreCase(ChatColor.stripColor(name)))
          {
            while (this.PlayersHitBoss.size() > 0)
            {
              Location entLoc = event.getEntity().getLocation();
              Location playLoc = ((Player)this.PlayersHitBoss.get(0)).getLocation();
              if (entLoc.getWorld().getName().equalsIgnoreCase(playLoc.getWorld().getName()))
              {
                int locDifX = entLoc.getBlockX() - playLoc.getBlockX();
                int locDifY = entLoc.getBlockY() - playLoc.getBlockY();
                int locDifZ = entLoc.getBlockZ() - playLoc.getBlockZ();
                if (locDifX < 0) {
                  locDifX *= -1;
                }
                if (locDifY < 0) {
                  locDifY *= 1;
                }
                if (locDifZ < 0) {
                  locDifZ *= -1;
                }
                if ((locDifX < 20) && (locDifY < 20) && (locDifZ < 20))
                {
                  Player player = (Player)this.PlayersHitBoss.get(0);
                  List<ItemStack> eventDrops = event.getDrops();
                  for (int j = 0; j < eventDrops.size(); j++) {
                    player.getInventory().addItem(new ItemStack[] { (ItemStack)eventDrops.get(j) });
                  }
                }
                this.PlayersHitBoss.remove(0);
              }
            }
            event.getDrops().clear();
          }
        }
      }
    
      @EventHandler
      public void attackBoss(EntityDamageByEntityEvent event)
      {
        if ((event.getDamager() instanceof Player))
        {
          Player player = (Player)event.getDamager();
          for (String name : this.plugin.getConfig().getStringList("Bosses")) {
            if (event.getEntity().getName().equalsIgnoreCase(name))
            {
              boolean found = false;
              for (int i = 0; i < this.PlayersHitBoss.size(); i++) {
                if (this.PlayersHitBoss.get(i) == player) {
                  found = true;
                }
              }
              if (!found)
              {
                this.PlayersHitBoss.add(player);
                player.sendMessage("You have attacked the boss!");
              }
            }
          }
        }
      }
    }
    
     
    Last edited: Oct 8, 2016
  2. Offline

    Zombie_Striker

    @Letroy11
    The reason you are getting this "error" is because the server is taking too long to respond (i.e. something is lagging the server for too long).

    To fix this, check your code. Try adding debug messages to see what is lagging the server so much.
    This most likely is what is causing the problem. Figure out when the size will be 0.
     
Thread Status:
Not open for further replies.

Share This Page