Solved SMALL bug/error ,dont see it/cant find it... help!

Discussion in 'Plugin Development' started by PeterXonwiiXx, Nov 23, 2015.

Thread Status:
Not open for further replies.
  1. i make a doublejump plugin with particle efffects and lot more but when a player does NOT have permission and is NOT op then he gets fly Enabled :/ wich isnt allowed to..

    this is my code where the bug has to be
    Code:
     
    
        ArrayList<Player> cooldown = new ArrayList<Player>();
        HashMap<String, Integer> cooldownTime = new HashMap<String, Integer>();
        HashMap<String, BukkitTask> cooldownTask = new HashMap<String, BukkitTask>();
    
        @EventHandler
        public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
            final Player player = event.getPlayer();
            if (player.getGameMode().equals(GameMode.CREATIVE)) {
                return;
            }
            if (!(player.hasPermission("dj.doublejump"))) {
                return;
            }
            if (this.cooldownTime.containsKey(player.getName())) {
                event.setCancelled(true);
                return;
            }
    
            event.setCancelled(true);
            player.setAllowFlight(true);
            player.setFlying(false);
            player.setVelocity(player.getLocation().getDirection().multiply(1.5D).setY(1));
            event.getPlayer().setNoDamageTicks(100);
    
            this.cooldownTime.put(player.getName(), Integer.valueOf(getConfig().getInt("cooldown") * 20));
            if (getConfig().getBoolean("messageadd")) {
                player.sendMessage(format(getConfig().getString("cooldownadd")));
            }
            player.setAllowFlight(false);
    
            this.cooldownTask.put(player.getName(), Bukkit.getScheduler().runTaskTimer(this, new Runnable() {
                public void run() {
                    int time = ((Integer) main.this.cooldownTime.get(player.getName())).intValue();
                    time--;
                    if (time <= 0) {
                        main.this.cooldownTime.remove(player.getName());
                        if (main.this.getConfig().getBoolean("messageremove")) {
                            player.sendMessage(main.format(main.this.getConfig().getString("cooldownremove")));
                        }
                        BukkitTask task = (BukkitTask) main.this.cooldownTask.get(player.getName());
                        main.this.cooldownTask.remove(player.getName());
                        task.cancel();
                    } else {
                        main.this.cooldownTime.put(player.getName(), Integer.valueOf(time));
                    }
                }
            }, 1L, 1L));
            if (getConfig().getBoolean("fireworkonlaunch")) {
                Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                    public void run() {
                        Firework f = (Firework) event.getPlayer().getWorld().spawn(event.getPlayer().getLocation(),
                                Firework.class);
    
                        FireworkMeta fm = f.getFireworkMeta();
                        Color color = Color.fromBGR(main.this.getConfig().getInt("fireworkcolor.r"),
                                main.this.getConfig().getInt("fireworkcolor.g"),
                                main.this.getConfig().getInt("fireworkcolor.b"));
                        Color fade = Color.fromBGR(main.this.getConfig().getInt("fireworkfadecolor.r"),
                                main.this.getConfig().getInt("fireworkfadecolor.g"),
                                main.this.getConfig().getInt("fireworkfadecolor.b"));
                        fm.addEffect(FireworkEffect.builder().flicker(main.this.getConfig().getBoolean("flicker"))
                                .trail(main.this.getConfig().getBoolean("trial"))
                                .with(FireworkEffect.Type.valueOf(main.this.getConfig().getString("fireworktype")))
                                .withColor(color).withFade(fade).build());
                        fm.setPower(1);
                        f.setFireworkMeta(fm);
                    }
                }, 20L);
            }
            if (getConfig().getBoolean("1.soundeffect")) {
                player.playSound(event.getPlayer().getLocation(), Sound.valueOf(getConfig().getString("1.soundname")), 1.0F,
                        getConfig().getInt("1.pitch"));
            }
            if (getConfig().getBoolean("2.soundeffect")) {
                player.playSound(event.getPlayer().getLocation(), Sound.valueOf(getConfig().getString("2.soundname")), 1.0F,
                        getConfig().getInt("2.pitch"));
            }
            if (getConfig().getBoolean("3.soundeffect")) {
                player.playSound(event.getPlayer().getLocation(), Sound.valueOf(getConfig().getString("3.soundname")), 1.0F,
                        getConfig().getInt("3.pitch"));
            }
            if (getConfig().getBoolean("4.soundeffect")) {
                player.playSound(event.getPlayer().getLocation(), Sound.valueOf(getConfig().getString("4.soundname")), 1.0F,
                        getConfig().getInt("4.pitch"));
            }
            if (getConfig().getBoolean("5.soundeffect")) {
                player.playSound(event.getPlayer().getLocation(), Sound.valueOf(getConfig().getString("5.soundname")), 1.0F,
                        getConfig().getInt("5.pitch"));
            }
            if (getConfig().getBoolean("1.ParticleEffects")) {
                Location loc = event.getPlayer().getLocation();
                ParticleEffect.valueOf(getConfig().getString("1.ParticleEffect")).display(
                        getConfig().getInt("1.float offsetX"), getConfig().getInt("1.float offsetY"),
                        getConfig().getInt("1.float offsetZ"), getConfig().getInt("1.float speed"),
                        getConfig().getInt("1.amount"), loc, getConfig().getInt("1.double range"));
            }
            if (getConfig().getBoolean("2.ParticleEffects")) {
                Location loc = event.getPlayer().getLocation();
                ParticleEffect.valueOf(getConfig().getString("2.ParticleEffect")).display(
                        getConfig().getInt("2.float offsetX"), getConfig().getInt("2.float offsetY"),
                        getConfig().getInt("2.float offsetZ"), getConfig().getInt("2.float speed"),
                        getConfig().getInt("2.amount"), loc, getConfig().getInt("2.double range"));
            }
            if (getConfig().getBoolean("3.ParticleEffects")) {
                Location loc = event.getPlayer().getLocation();
                ParticleEffect.valueOf(getConfig().getString("3.ParticleEffect")).display(
                        getConfig().getInt("3.float offsetX"), getConfig().getInt("3.float offsetY"),
                        getConfig().getInt("3.float offsetZ"), getConfig().getInt("3.float speed"),
                        getConfig().getInt("3.amount"), loc, getConfig().getInt("3.double range"));
            }
            if (getConfig().getBoolean("4.ParticleEffects")) {
                Location loc = event.getPlayer().getLocation();
                ParticleEffect.valueOf(getConfig().getString("4.ParticleEffect")).display(
                        getConfig().getInt("4.float offsetX"), getConfig().getInt("4.float offsetY"),
                        getConfig().getInt("4.float offsetZ"), getConfig().getInt("4.float speed"),
                        getConfig().getInt("4.amount"), loc, getConfig().getInt("4.double range"));
            }
            if (getConfig().getBoolean("5.ParticleEffects")) {
                Location loc = event.getPlayer().getLocation();
                ParticleEffect.valueOf(getConfig().getString("5.ParticleEffect")).display(
                        getConfig().getInt("5.float offsetX"), getConfig().getInt("5.float offsetY"),
                        getConfig().getInt("5.float offsetZ"), getConfig().getInt("5.float speed"),
                        getConfig().getInt("5.amount"), loc, getConfig().getInt("5.double range"));
            }
        }
    
        @EventHandler
        public void onPlayerQuit(PlayerQuitEvent event) {
            BukkitTask task = (BukkitTask) this.cooldownTask.get(event.getPlayer().getName());
            if (task != null) {
                task.cancel();
                this.cooldownTask.remove(event.getPlayer().getName());
                this.cooldownTime.remove(event.getPlayer().getName());
            }
        }
    
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event) {
            Player player = event.getPlayer();
            if (player.getLocation().subtract(0.0D, 1.0D, 0.0D).getBlock().getType().equals(Material.AIR)) {
                return;
            }
            if (player.isFlying()) {
                return;
            }
            if ((this.cooldownTask.containsKey(player.getName())) || (this.cooldownTime.containsKey(player.getName()))) {
                player.setAllowFlight(false);
            } else {
                player.setAllowFlight(true);
            }
        }
    
    
    Thanks in advance!!
     
  2. Offline

    Lordloss

    Code:
            if ((this.cooldownTask.containsKey(player.getName())) || (this.cooldownTime.containsKey(player.getName()))) {
                player.setAllowFlight(false);
            } else {
                player.setAllowFlight(true);
            }
    This will allow every player who is not in your list to fly with /fly command if not denied or mods. But theres no section in your code where fly gets turned on for a player..
     
  3. its double jump,, op and permission works fine but the problem is that normal player with NO permission can also use it
     
  4. Offline

    Lordloss

    Code:
            if (!(player.hasPermission("dj.doublejump"))) {
                return;
            }
    What about cancelling the event here?
     
  5. i will try that right now,,my friend said that that isnt need/able because on end of that part it already has.... will message you in a minute how it goes ;)
    thank anyway
     
  6. Offline

    Lordloss

    it is needed because of the "return;" the end of this will never be reached. Let me talk to your friend xD
     
  7. hahaha my friend didnt see it then i think,you can talk to him but he is really smart pc guy,,he made website /apps for his Dad's company and he is just 15 so.... but either way

    this is what i have done and EVERYTTHING works so far as i want/tested

    Code:
        @EventHandler
        public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
            final Player player = event.getPlayer();
            if (player.getGameMode().equals(GameMode.CREATIVE)) {
                return;
            }
            if (!(player.hasPermission("dj.doublejump"))) {
                player.setAllowFlight(false);
                player.setFlying(false);
                this.cooldownTime.put(player.getName(), Integer.valueOf(getConfig().getInt("cooldown") * 20));
                event.setCancelled(true);
                return;
            }
            if (this.cooldownTime.containsKey(player.getName())) {
                event.setCancelled(true);
                return;
            }
    
    thats the code i now have,
    thanks anyway and i will SOLVE this thread for now,until i found my next error(Hope i dont) :p
     
Thread Status:
Not open for further replies.

Share This Page