Solved What's causing this gross stacktrace? I'm having trouble deciphering it.

Discussion in 'Plugin Development' started by mrdude123, Apr 29, 2016.

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

    mrdude123

    http://pastebin.com/wdJTr6yV - Stacktrace

    Sorry about that atrocity.
    Two more classes now.
    Main:
    Code:
    package archer.kit;
    
    import java.util.ArrayList;
    
    import net.minecraft.server.v1_8_R3.PlayerConnection;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerBucketFillEvent;
    import org.bukkit.event.player.PlayerEggThrowEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    import org.bukkit.event.*;
    import org.bukkit.inventory.ItemStack;
    
    
    public class Main extends JavaPlugin implements Listener{
     
        public ArrayList<Integer> isFrozen = new ArrayList<Integer>();
     
        public void onEnable(){
            Bukkit.getPluginManager().registerEvents(this, this);
            // Not important here:  getCommand("feed").setExecutor(new Feed());
            getCommand("freezecvar").setExecutor(new Freeze());
        } 
     
        @EventHandler
        public void onMoveEvent(PlayerMoveEvent e){
            Player p = e.getPlayer();
            if(isFrozen.get(0) == 1){
                e.setCancelled(true);
                p.sendMessage(ChatColor.RED + "All players are currently frozen, you cannot move!");
            }
            }
             
         
        }
     
     
     
    
    
    Freeze class:
    Code:
    package archer.kit;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.Listener;
    
    public class Freeze extends Main implements CommandExecutor, Listener {
     
        public boolean onCommand(CommandSender sender, Command cmd, String lbl,
                String[] args) {
                if(isFrozen.get(0) == 1){
                    isFrozen.set(0, 0);
                    return true;
                }else{
                isFrozen.set(0, 1);
                sender.sendMessage(ChatColor.GREEN + "Server players have been frozen!");
         
         
         
            return false;
        }
    
    }
    }
    Keep in mind the stacktrace occurs both when the plugin is loaded and when the player move event is fired.
     
  2. Offline

    Irantwomiles

    This seems to be the error

    Code:
    Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    
    Also you could have easily just used a boolean. All you had to do was when you run the command, you set the boolean to true and on PlayerMoveEvent just check if the boolean is true and if it is just cancel the event. I also dont understand what your are doing with the arraylist.
     
  3. Offline

    mrdude123

    Thanks for your response :)

    Earlier I used a boolean and a method to do this, and it worked fine. I'm just practicing arraylists with the bukkit API, basically just trying to get better. I used a true/false 1 or 0 with the ArrayList, or at least attempted to. On the command, set the first slot in the arraylist to 1, then check if it is equal to 1 or 0 in the event. A boolean is significantly more efficient and easier, but once again I was simply experimenting.
     
  4. Offline

    Irantwomiles

    @mrdude123 ArrayLists aren't used to check if numbers match or not, it is a collection of objects. What you were trying to do is something you need to do with a integer or like I said before a boolean. To learn Arraylists you're going to want to follow actual Java tutorials to fully understand. You should have a basic understanding of Java before even starting to make Bukkit plugins.
     
    mine-care likes this.
  5. Offline

    mine-care

    Also, please removie this import, it is not used anywhere as i see. It may cause errors for all versions but 1.8.3
     
Thread Status:
Not open for further replies.

Share This Page