+ Antworten
Seite 119 von 132 ErsteErste ... 19 69 109 117 118 119 120 121 129 ... LetzteLetzte
Ergebnis 1.181 bis 1.190 von 1311
  1. #1181
    Team BroFist Avatar von Panjab
    Registriert seit
    28.04.2012
    Beiträge
    1.480
    Minecraft
    Panjab
    @Johannes_C25

    Habe echt keine Ahnung, warum es in der Klasse nicht funktioniert. Im Listener funktioniert es doch auch <.<

  2. #1182
    @Panjab

    Weil in deinem Listener wahrscheinlich etwas in dieser Art steht:
    Code:
    Main plugin;
    public Listener (Main plugin) {
        this.plugin = plugin;
    }
    Aber genau das fehlt in der Command Klasse.

    Und ich würde dir wirklich vorschlagen eine Klasse einmal zu erstellen, die du dann öfters benutzt. Weil momentan ist das (meiner Meinung nach) ziemlich Resourcen verschwenderisch...

  3. #1183
    Team BroFist Avatar von Panjab
    Registriert seit
    28.04.2012
    Beiträge
    1.480
    Minecraft
    Panjab
    @Johannes_C25

    Selbst wenn ich das einbaue, bringt es leider auch nix

  4. #1184
    Creeper-Jäger Avatar von dainless
    Registriert seit
    18.07.2011
    Beiträge
    489
    Minecraft
    dainless
    Sollte man das
    Code:
    int seconds = Integer.parseInt(st);
    bei Handyhackers Problem nicht in einen TryCatch-Block schreiben, weil wegen Fehler?

  5. #1185
    @dainless

    Jup... sollte man.

    @Panjab

    Wie sieht die Klasse dann aus? Wie rufst du sie auf? Ist es dann vielleicht eine andere Fehlermeldung?

  6. #1186
    Team BroFist Avatar von Panjab
    Registriert seit
    28.04.2012
    Beiträge
    1.480
    Minecraft
    Panjab
    @Johannes_C25

    loadConfig() ist ne Methode

    Code:
        public boolean loadConfig() {
            
            this.config = getConfig();
            
            this.config.options().copyDefaults(true);
            saveConfig();
            
            if (!new File(getDataFolder() + "src/config.yml").exists());
            saveDefaultConfig();
            
            return true;
        }
    Listener:
    Code:
        Main plugin;
        
        public ZoneListener(Main instance) {
            
            plugin = instance;
            
        }
        
        static int zone_ID;
    
        
        @Event Handler
        public void onPlayerInteract(PlayerInteractEvent event) {
            
            final Player player = event.getPlayer();
            
            if (ModSettings.createOn.contains(player) && ModSettings.step1.contains(player)) {
                
                if (event.getAction() == Action.LEFT_CLICK_BLOCK && player.getItemInHand().getType() == Material.STICK) {
                    
                    try {
                        
                        plugin.l1 = event.getClickedBlock().getLocation();
                        player.sendMessage("");
                        player.sendMessage(ChatColor.DARK_GREEN + "Position 1: " + Throws.showBlockCoords(plugin.l1));
                        
                        event.setCancelled(true);
                        int loc1_x = plugin.l1.getBlockX();
                        int loc1_y = plugin.l1.getBlockY();
                        int loc1_z = plugin.l1.getBlockZ();
                        
                        plugin.loadArenas();
                        plugin.saveFile.load(plugin.f);
                        plugin.saveFile.set(ModSettings.zoneName + ".L1.X", loc1_x);
                        plugin.saveFile.set(ModSettings.zoneName + ".L1.Y", loc1_y);
                        plugin.saveFile.set(ModSettings.zoneName + ".L1.Z", loc1_z);
                        plugin.saveFile.save(plugin.f);
                        
                        ModSettings.step1.remove(player);
                        ModSettings.step2.add(player);
                        
                    } catch (Exception e) {
                        
                        Throws.errorOccuredWhileCreatePoint(player);
                        e.printStackTrace();
                        
                    }
                }
                
            }
            
            if (ModSettings.createOn.contains(player) && ModSettings.step2.contains(player)) {
                
                if (event.getAction() == Action.RIGHT_CLICK_BLOCK && player.getItemInHand().getType() == Material.STICK) {
                    
                    try {
                        
                        plugin.l2 = event.getClickedBlock().getLocation();
                        player.sendMessage(ChatColor.DARK_GREEN + "Position 2: " + Throws.showBlockCoords(plugin.l2));
                        
                        event.setCancelled(true);
                        int loc2_x = plugin.l2.getBlockX();
                        int loc2_y = plugin.l2.getBlockY();
                        int loc2_z = plugin.l2.getBlockZ();
                        
                        plugin.loadArenas();
                        plugin.saveFile.load(plugin.f);
                        plugin.saveFile.set(ModSettings.zoneName + ".L2.X", loc2_x);
                        plugin.saveFile.set(ModSettings.zoneName + ".L2.Y", loc2_y);
                        plugin.saveFile.set(ModSettings.zoneName + ".L2.Z", loc2_z);
                        plugin.saveFile.save(plugin.f);
                        
                        plugin.pz.createZone(player, plugin.l1, plugin.l2);
                        
                        ModSettings.step2.remove(player);
                        ModSettings.step3.add(player);
                        
                    } catch (Exception e) {
                        
                        Throws.errorOccuredWhileCreatePoint(player);
                        e.printStackTrace();
                        
                    }
                }
                
            }
            
            if (ModSettings.createOn.contains(player) && ModSettings.step3.contains(player)) {
                
                if (event.getAction() == Action.LEFT_CLICK_BLOCK && player.getItemInHand().getType() == Material.STICK) {
                
                    try {
                        
                        plugin.l3 = event.getClickedBlock().getLocation();
                        player.sendMessage(ChatColor.DARK_GREEN + "Spawnpoint 1: " + Throws.showBlockCoords(plugin.l3));
                        
                        event.setCancelled(true);
                        int spawn1_x = plugin.l2.getBlockX();
                        int spawn1_y = plugin.l2.getBlockY();
                        int spawn1_z = plugin.l2.getBlockZ();
                        
                        plugin.loadArenas();
                        plugin.saveFile.load(plugin.f);
                        plugin.saveFile.set(ModSettings.zoneName + ".Spawn1.X", spawn1_x);
                        plugin.saveFile.set(ModSettings.zoneName + ".Spawn1.Y", spawn1_y);
                        plugin.saveFile.set(ModSettings.zoneName + ".Spawn1.Z", spawn1_z);
                        plugin.saveFile.save(plugin.f);
                        
                        ModSettings.step3.remove(player);
                        ModSettings.step4.add(player);
                        
                    } catch(Exception e) {
                        
                        Throws.errorOccuredWhileCreatePoint(player);
                        
                    }
                    
                }
                
            }
            
            if (ModSettings.createOn.contains(player) && ModSettings.step4.contains(player)) {
                
                if (event.getAction() == Action.RIGHT_CLICK_BLOCK && player.getItemInHand().getType() == Material.STICK) {
                    
                    try {
                        
                        plugin.l4 = event.getClickedBlock().getLocation();
                        player.sendMessage(ChatColor.DARK_GREEN + "Spawnpoint 2: " + Throws.showBlockCoords(plugin.l4));
    
                        event.setCancelled(true);
                        int spawn2_x = plugin.l2.getBlockX();
                        int spawn2_y = plugin.l2.getBlockY();
                        int spawn2_z = plugin.l2.getBlockZ();
                        
                        plugin.loadArenas();
                        plugin.saveFile.load(plugin.f);
                        plugin.saveFile.set(ModSettings.zoneName + ".Spawn2.X", spawn2_x);
                        plugin.saveFile.set(ModSettings.zoneName + ".Spawn2.Y", spawn2_y);
                        plugin.saveFile.set(ModSettings.zoneName + ".Spawn2.Z", spawn2_z);
                        plugin.saveFile.save(plugin.f);
                        
                        ModSettings.step4.remove(player);
                        ModSettings.step5.add(player);
                        
                    } catch (Exception e) {
                        
                        Throws.errorOccuredWhileCreateZone(player);
                        
                    }
                }
            }
            
            if (ModSettings.createOn.contains(player) && ModSettings.step5.contains(player)) {
                
                if (event.getAction() == Action.LEFT_CLICK_BLOCK && player.getItemInHand().getType() == Material.STICK) {
                    
                    try {
                        
                        plugin.l5 = event.getClickedBlock().getLocation();
                        player.sendMessage(ChatColor.DARK_GREEN + "Deathposition: " + Throws.showBlockCoords(plugin.l5));
                        player.sendMessage("");
                        
                        int death_x = plugin.l2.getBlockX();
                        int death_y = plugin.l2.getBlockY();
                        int death_z = plugin.l2.getBlockZ();
                        
                        zone_ID = player.getTicksLived() + 500 / 2;
                        
                        plugin.loadArenas();
                        plugin.saveFile.load(plugin.f);
                        plugin.saveFile.set(ModSettings.zoneName + ".Death.X", death_x);
                        plugin.saveFile.set(ModSettings.zoneName + ".Death.Y", death_y);
                        plugin.saveFile.set(ModSettings.zoneName + ".Death.Z", death_z);
                        plugin.saveFile.set(ModSettings.zoneName + ".Zone_ID", zone_ID);
                        plugin.saveFile.save(plugin.f);
                        
                        player.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() {  player.sendMessage(ChatColor.GREEN + "Congratulation! You successfully created the arena " + ChatColor.GOLD + ModSettings.zoneName); }}, 60L);
                        
                        event.setCancelled(true);
                        
                        ModSettings.switchStatus(player);
                        ModSettings.step5.remove(player);
                        
                    } catch (Exception e) {
                        
                        Throws.errorOccuredWhileCreateZone(player);
                        
                    }
                }
            }
            
        }
    Commandklasse:
    Code:
        Main plugin;
        Command cmd;
        Player player;
        Player ask;
        String[] args;
        
        ChatColor gray = ChatColor.GRAY;
        ChatColor blue = ChatColor.BLUE;
        ChatColor gold = ChatColor.GOLD;
        ChatColor aqua = ChatColor.AQUA;
        ChatColor green = ChatColor.GREEN;
        ChatColor darkgreen = ChatColor.DARK_GREEN;
        ChatColor red = ChatColor.RED;
        
        
        public CommandPvP(Command cmd, Player player, String[] args) {
            
            this.cmd = cmd;
            this.player = player;
            this.args = args;
            
        }
    
        public boolean run() {
                if (args[0].equalsIgnoreCase("join")) {
                    if (args.length == 2) {
                        
                        ModSettings.zoneName = args[1];
    
                        try {
                            
                            plugin.loadArenas();
                            plugin.saveFile.load(plugin.f);
                            
                        } catch (IOException | InvalidConfigurationException | NullPointerException e) {
                            
                            e.printStackTrace();
                            
                        }
                        
    //                     if (!plugin.saveFile.contains(ModSettings.zoneName)) {
    //                        
    //                        player.sendMessage(red + "This arena doesn't exists!");
    //                        
    //                        return false;
    //                    }
                        
    //                    World world = player.getWorld();
    //                    int x = plugin.saveFile.getInt(ModSettings.zoneName + ".Spawn1.X");
    //                    int y = plugin.saveFile.getInt(ModSettings.zoneName + ".Spawn1.Y");
    //                    int z = plugin.saveFile.getInt(ModSettings.zoneName + ".Spawn1.Z");
    //                    
    //                    Location spawnLoc = new Location(world, x, y, z);
    //                    
    //                    player.teleport(spawnLoc);
                        player.sendMessage(green + "You have been ported to the arena " + gold + args[1]);
                        
                        return true;
                        
                    } else {
                        
                        Throws.ArgumentsException(player);
                        
                    }
                }
    Und alle Exceptions sind NullPointerException's welche auftreten, sobald irgendwas mit der Datei gemacht wird.

  7. #1187
    @Panjab

    Code:
    public ZoneListener(Main instance) {
            
            plugin = instance;
            
        }
    Das hast du im Listener, aber nicht im Command Klasse.

  8. #1188
    Team BroFist Avatar von Panjab
    Registriert seit
    28.04.2012
    Beiträge
    1.480
    Minecraft
    Panjab
    @Johannes_C25 Wie gesagt, selbst wenn ich das nutze, funktioniert es nicht :/

  9. #1189
    @Panjab

    Bau es ein und zeig mir dann mal deinen Code... und schau, ob es vielleicht eine andere Fehlermeldung gibt.

  10. #1190
    Team BroFist Avatar von Panjab
    Registriert seit
    28.04.2012
    Beiträge
    1.480
    Minecraft
    Panjab
    @Johannes_C25

    Mit dieser Methode wirft es eine NullPointerException für die Zeile if (args.length == 2) <.<

    Code:
                if (args[0].equalsIgnoreCase("delzone")) {
                    if (args.length == 2) {
                        
                        ModSettings.zoneName = args[1];
                        
                        try {
    
                            plugin.loadArenas();
                            plugin.saveFile.load(plugin.f);
                            plugin.saveFile.set(ModSettings.zoneName, null);
                            plugin.saveFile.save(plugin.f);
                        
                        } catch (Exception e) {
                            
                            e.printStackTrace();
    
                        }
                        
                        Throws.deletedZone(player);
                        
                        return true;
                        
                    }
                }

+ Antworten