Solved Vanish problems

Discussion in 'Plugin Development' started by TheNokar, Nov 18, 2012.

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

    TheNokar

    I'm trying to make vanish plugin it almost works, but there is one bug when ever a new player joins or player logs out and logs in again i all vanished players looses there vanish.

    Video of the error :




    Here is my classes:


    MAIN CLASS :
    Code:
    package net.gauragangur.EasyVanish;
     
     
    import java.util.ArrayList;
    import java.util.logging.Logger;
     
     
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class EasyVanish extends JavaPlugin {
        public final Logger logger = Logger.getLogger("Minecraft");
        public final Commands cmd = new Commands(this);
        public ArrayList<String> vanish = new ArrayList<String>();
     
     
        public void onEnable(){
     
            getCommand("vanish").setExecutor(cmd);
            PluginDescriptionFile pdfFile = getDescription();
            getServer().getPluginManager().registerEvents(new LoginHandler(this), this);
            getLogger().info("[" + pdfFile.getName() + "] version: [" + pdfFile.getVersion() + "] has been enabled!");
            //.replaceAll("(&([a-f0-9]))", "\u00A7$2");
            this.getConfig().options().copyDefaults(true);
            this.saveConfig();
        }
     
        public void onDisable() {
            PluginDescriptionFile pdfFile = getDescription();
            getLogger().info("[" + pdfFile.getName() + "]" + "has been disabled!");
     
        }
     
        public boolean VanishList(Player player) {
            return vanish.contains(player.getName());
        }
        public void VanishPlayers(Player player) {
            vanish.add(player.getName());
     
            for (Player p1 : getServer().getOnlinePlayers()) {
                p1.hidePlayer(player);
         
            }
     
        }
        public void RemoveVanish(Player player) {
            vanish.remove(player.getName());
            for (Player p1 : getServer().getOnlinePlayers()) {
                p1.showPlayer(player);
         
            }
        }
     
    }
    
    LOGIN HANDLER :
    Code:
    package net.gauragangur.EasyVanish;
     
     
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
     
    public class LoginHandler implements Listener {
     
        private EasyVanish plugin;
     
        public LoginHandler(EasyVanish plugin) {
            this.plugin = plugin;
        }
     
        public void handleLogin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            for (Player p1 : plugin.getServer().getOnlinePlayers()) {
                if(plugin.vanish.contains(p1)) {
                    plugin.VanishPlayers(p1);
                }
            }
        }
     
        @EventHandler
        public void handleQuit(PlayerQuitEvent event) {
            Player player = event.getPlayer();
     
            if (plugin.VanishList(player)) {
                plugin.RemoveVanish(player);
            }
        }
    }
    
    AND COMMAND LISTENER :
    Code:
    package net.gauragangur.EasyVanish;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
     
    public class Commands implements CommandExecutor {
     
        EasyVanish plugin;
     
        public Commands(EasyVanish EasyVanish) {
     
            plugin = EasyVanish;
        }
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            if (!(sender instanceof Player)) {
                sender.sendMessage(ChatColor.RED + "You got to be a player to use this command!");
                }
     
                Player player = (Player) sender;
                    if(!plugin.VanishList(player)) {
                        plugin.VanishPlayers(player);
                        player.sendMessage(ChatColor.GRAY + "Poof, you have vanished");
                    }  else {
                        plugin.RemoveVanish(player);
                        player.sendMessage(ChatColor.GRAY + "You are visable again");
                    }
                return true;
                }
     
     
    }
    
    If you see what i can do to fix this please post it in a reply!.
     
  2. Offline

    leiger

    Could you show us the contents of your VanishPlayers and RemoveVanish methods?
     
  3. Offline

    TheNokar

    I posted a video of the bug. Hope that explains better what error i'm having.

    It's in the main class :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  4. Offline

    leiger

    Ah, I didn't notice them earlier. Both methods look fine.

    Not sure what the problem is then. I'll have another look later, and see if I can suggest a solution, if it hasn't been solved by then.
     
  5. Offline

    TheNokar

    Thanks
     
  6. Offline

    Remi1115

    I'm probably wrong, but try replacing this:
    Code:Java
    1.  
    2. public void handleLogin(PlayerJoinEvent event) {
    3. Player player = event.getPlayer();
    4. for (Player p1 : plugin.getServer().getOnlinePlayers()) {
    5. if(plugin.vanish.contains(p1)) {
    6. plugin.VanishPlayers(p1);
    7. }
    8. }
    9. }
    10.  

    With this:
    Code:Java
    1.  
    2. public void handleLogin(PlayerJoinEvent event) {
    3. Player player = event.getPlayer();
    4. for (Player p1 : plugin.getServer().getOnlinePlayers()) {
    5. if(plugin.vanish.contains(p1.getName())) {
    6. plugin.VanishPlayers(p1);
    7. }
    8. }
    9. }
    10.  


    Edit: Do you see any stacktraces in the console?
     
  7. Offline

    TheNokar

    Thanks this worked :), Thank you so much
     
  8. Offline

    Remi1115

    I'm glad it helped.
    Have fun with your plugin :) .
     
  9. Offline

    _HellHound_

    Hello, and sorry for stealing a thread but dont like to start a new for this. My problem is with the VanishNoPacket plugin, every time i start my server it shows me this (2013-01-09 09:56:06 [WARNING] Task of 'VanishNoPacket' generated an exception
    java.lang.NoSuchMethodError: org.bukkit.scheduler.BukkitScheduler.runTaskTimerAsynchronously(Lorg/bukkit/plugin/Plugin;Ljava/lang/Runnable;JJ)Lorg/bukkit/scheduler/BukkitTask;
    at org.kitteh.vanish.metrics.Metrics.start(Metrics.java:455)
    at org.kitteh.vanish.metrics.MetricsOverlord.init(MetricsOverlord.java:77)
    at org.kitteh.vanish.VanishPlugin$1.run(VanishPlugin.java:276)
    at org.bukkit.craftbukkit.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:126)
    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:533)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:457)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    can anyone shed some light on the problem?

    NinjaEdit: and in game it doesnt do absolutely anything
     
  10. Offline

    fireblast709

    1. necropost much?
    2. seems like an outdated version? Try updating VanishNoPacket, and if it still throws the error submit a ticket @ BukkitDev
     
  11. Offline

    _HellHound_

    1. perhaps did :D
    2. i noticed that i had to downgrade because tekkit server:oops:
     
Thread Status:
Not open for further replies.

Share This Page