I can't find my mistakes

Discussion in 'Plugin Development' started by Scrapnix, Mar 16, 2017.

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

    Scrapnix

    Hey there,
    I made plugin, but something went wrong. I can't find my mistakes.
    It says, that the onEnable - part is wrong and something in my Event - Class is wrong.
    I hope someone can help me :D

    onEnable part:
    Code:
    public static Plugin that;
        Logger log;
    
        public static String prefix = that.getConfig().getString("prefix");
        @Override
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(new Scrap.Jump.Events.Handler(), this);
            log = this.getLogger();
            log.info("Plugin TryJump was enabled!");
            that = this;
            new Stage(this);
            new Status(this);
            if (this.getConfig().getBoolean("reload") == true || this.getConfig() == null) {
                Status.data();
            }
            this.getCommand("tryjump").setExecutor(new CMDHandler());
            this.getCommand("tj").setExecutor(new CMDHandler());
    Events part:
    Code:
    public class Handler implements Listener{
      
        public static HashMap<Player, Integer> stage = new HashMap<Player, Integer>();
        public static HashMap<String, Integer> ps = new HashMap<String, Integer>();
         @EventHandler
            public void JoinSign(SignChangeEvent e) {
            File data = new File("plugins/TryJump/Data/data.yml");
            YamlConfiguration dataconfig = null;
            dataconfig = YamlConfiguration.loadConfiguration(data);
            Player p = e.getPlayer();
            Location loc = e.getBlock().getLocation();
            if (e.getLine(0).toLowerCase().contains("[tj]")) {
                if (dataconfig.getString(e.getLine(1) + ".world").equalsIgnoreCase(p.getWorld().getName())){
                    e.setLine(0, "- TryJump -");
                    e.setLine(1, "[§aLobby§0]");
                    if (e.getLine(2).equalsIgnoreCase("team")) {
                    e.setLine(2, "Team");
                    }else if (e.getLine(2).equalsIgnoreCase("solo")) {
                        e.setLine(2, "Solo");
                    }else {
                        p.sendMessage(Scrap.Jump.Handler.prefix + "Please type into the 3rd line team or solo!");
                    }
                    e.setLine(3, e.getLine(1));
                }else {
                    p.sendMessage(Scrap.Jump.Handler.prefix + "You forgot to set the Level or you set a wrong level!");
                }
            }
         }
         @EventHandler
         public void SignTeleport(PlayerInteractEvent e) {
         File data = new File("plugins/TryJump/Data/data.yml");
         YamlConfiguration dataconfig = null;
         dataconfig = YamlConfiguration.loadConfiguration(data);
         Sign s = (Sign) e.getClickedBlock().getState();
         if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK) {
                if (e.getClickedBlock().getType() == Material.WALL_SIGN || e.getClickedBlock().getType() == Material.SIGN_POST) {
                    if (e.getClickedBlock().getState() instanceof Sign) {
                        World w = Bukkit.getWorld(dataconfig.getString(s.getLine(0) + ".lobby.world"));
                        int x = dataconfig.getInt(s.getLine(0) + ".lobby.x");
                        int y = dataconfig.getInt(s.getLine(0) + ".lobby.y");
                        int z = dataconfig.getInt(s.getLine(0) + ".lobby.z");
                        int yaw = dataconfig.getInt(s.getLine(0) + ".lobby.yaw");
                        int pitch = dataconfig.getInt(s.getLine(0) + ".lobby.pitch");
                        Location loc = new Location(w, x, y, z, yaw, pitch);
                        e.getPlayer().teleport(loc);
                        ps.put(s.getLine(0) + "count", ps.get(s.getLine(0) + "count") + 1);
                        for (Player players : w.getPlayers()) {
                            players.sendMessage(Scrap.Jump.Handler.prefix + "§7" + e.getPlayer().getName() + " §7ist dem Spiel beigetreten!");
                        }
                        }
                    }
                }
         }
    }
    Command part:
    (The commands aren't work too.)
    Code:
    public ArrayList<String> levels = new ArrayList<String>();
      
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    
            File data = new File("plugins/TryJump/Data/data.yml");
            YamlConfiguration dataconfig = null;
            dataconfig = YamlConfiguration.loadConfiguration(data);
                Player p = (Player)sender;
                if (cmd.getName().equalsIgnoreCase("tj") || cmd.getName().equalsIgnoreCase("tryjump")) {
                    if (args[0].length() == 0) {
                        p.sendMessage(Scrap.Jump.Handler.prefix + "§aHelp:");
                        p.sendMessage(Scrap.Jump.Handler.prefix + "§7/tj create <Level>");
                        p.sendMessage(Scrap.Jump.Handler.prefix + "§7/tj setspawn <Level>");
                        p.sendMessage(Scrap.Jump.Handler.prefix + "§7/tj setlobby <Level>");
                        p.sendMessage(Scrap.Jump.Handler.prefix + "§7/tj sethub <Level>");
                        p.sendMessage(Scrap.Jump.Handler.prefix + "§7/tj allow <Level>");
                    }
                    if (args[0].equalsIgnoreCase("create")) {
                        if (args[1].length() == 0) {
                            p.sendMessage(Scrap.Jump.Handler.prefix + "§7please use /tj create Level");
                        }else {
                            levels.add(args[1]);
                            dataconfig.set("levels", levels);
                            p.sendMessage(Scrap.Jump.Handler.prefix + "Arena " + args[1] + " created!");
                        }
                    }
                    if (args[0].equalsIgnoreCase("sethub")) {
                        if (args[1].length() == 0) {
                            p.sendMessage(Scrap.Jump.Handler.prefix + "§7please use /tj sethub Level");
                        }else {
                            if (dataconfig.getList("levels").contains(args[1])){
                                dataconfig.set(args[1] + ".hub.x", p.getLocation().getX());
                                dataconfig.set(args[1] + ".hub.y", p.getLocation().getY());
                                dataconfig.set(args[1] + ".hub.z", p.getLocation().getZ());
                                dataconfig.set(args[1] + ".hub.yaw", p.getLocation().getYaw());
                                dataconfig.set(args[1] + ".hub.pitch", p.getLocation().getPitch());
                                dataconfig.set(args[1] + ".hub.world", p.getLocation().getWorld().getName());
                                try {
                                    dataconfig.save(data);
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }
                    if (args[0].equalsIgnoreCase("setlobby")) {
                        if (args[1].length() == 0) {
                            p.sendMessage(Scrap.Jump.Handler.prefix + "§7please use /tj setlobby Level");
                        }else {
                            if (dataconfig.getList("levels").contains(args[1])){
                            dataconfig.set(args[1] + ".lobby.x", p.getLocation().getX());
                            dataconfig.set(args[1] + ".lobby.y", p.getLocation().getY());
                            dataconfig.set(args[1] + ".lobby.z", p.getLocation().getZ());
                            dataconfig.set(args[1] + ".lobby.yaw", p.getLocation().getYaw());
                            dataconfig.set(args[1] + ".lobby.pitch", p.getLocation().getPitch());
                            dataconfig.set(args[1] + ".lobby.world", p.getLocation().getWorld().getName());
                            try {
                                dataconfig.save(data);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            }
                        }
                    }        
                    if (args[0].equalsIgnoreCase("setspawn")) {
                        if (args[1].length() == 0) {
                            p.sendMessage(Scrap.Jump.Handler.prefix + "§7please use /tj setspawn Level");
                        }else {
                            if (dataconfig.getList("levels").contains(args[1])){
                                dataconfig.set(args[1] + ".x", p.getLocation().getX());
                                dataconfig.set(args[1] + ".y", p.getLocation().getY());
                                dataconfig.set(args[1] + ".z", p.getLocation().getZ());
                                dataconfig.set(args[1] + ".yaw", p.getLocation().getYaw());
                                dataconfig.set(args[1] + ".pitch", p.getLocation().getPitch());
                                dataconfig.set(args[1] + ".world", p.getLocation().getWorld().getName());
                                try {
                                    dataconfig.save(data);
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                p.sendMessage(Scrap.Jump.Handler.prefix + "§7Arena " + args[1] + " §7created!");
                            }else {
                                p.sendMessage(Scrap.Jump.Handler.prefix + "§7The Arena " + args[1] + " §7doesn't exist!");
                            }
                        }
                    }
                    if (args[0].equalsIgnoreCase("allow")) {
                        if (args[1].length() == 0) {
                            p.sendMessage(Scrap.Jump.Handler.prefix + "§7please use /tj allow Level");
                        }else {
                        if (dataconfig.getList("levels").contains(args[1])){
                      
                        Scrap.Jump.Events.Handler.ps.put("count", 0);
                        Scrap.Jump.Methods.Status.allowed.put(args[1], true);
                        for (String b : Status.allowed.keySet()) {
                            dataconfig.set("allowed." + args[1], Status.allowed.get(b));
                        }
                        try {
                            dataconfig.save(data);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        }
                    }
                }
            }
            return false;
        }
    EDIT:
    I know, there are some mistakes with saving my dataconfig. Please ignore that.
    The whole commands aren't registered!
     
    Last edited: Mar 16, 2017
  2. Offline

    Irantwomiles

    Can you put console error in as well? I can't read everything and tell you what's wrong.
     
  3. Offline

    timtower Administrator Administrator Moderator

    @Scrapnix You are making multiple command handlers. Try using the same instance instead.
     
  4. Offline

    Caderape2

    @Scrapnix
    you are creating a separate class for each command. the arraylist 'levels' will not be the same for the two commands.
    anyway, did you register the command name in the plugin.yml ?
     
Thread Status:
Not open for further replies.

Share This Page