How to ditch this?

Discussion in 'Spigot Plugin Development' started by Kyllian, Apr 23, 2017.

  1. Hello, When I ban a player with my own plugin and they join, I get this:

    Code (Text):
    [19:54:18 INFO]: UUID of player InstantlyMoist is 3cfa3047-782d-3cdd-9ee9-74fc60d93cd8
    [19:54:18 INFO]: Disconnecting [email protected][id=3cfa3047-782d-3cdd-9ee9-74fc60d93cd8,name=InstantlyMoist,properties={},legacy=false] (/127.0.0.1:64754): º7You have been banned!
    Reason:fuck you
    Expiration: NEVER
    [19:54:18 INFO]: [email protected][id=3cfa3047-782d-3cdd-9ee9-74fc60d93cd8,name=InstantlyMoist,properties={},legacy=false] (/127.0.0.1:64754) lost connection: º7You have been banned!
    Reason:fuck you
    Expiration: NEVER
    This is VERY annoying, So what can I do to fix this.
    Code:

    Code (Text):
    @EventHandler(priority = EventPriority.HIGHEST)
        public void onLogin(PlayerLoginEvent e) {
            Player p = e.getPlayer();
            if (fc.getData().getBoolean(p.getUniqueId().toString() + ".banned")) {
                e.disallow(null, ct.cc("&7You have been banned!" + "\nReason:"
                        + fc.getData().getString(p.getUniqueId().toString() + ".banReason") + "\nExpiration: "
                        + fc.getData().getString(p.getUniqueId().toString() + ".unbanTime")));
                return;
            }
        }
    Ban class:

    Code (Text):
    package me.kyllian.system32.commands;

    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    import me.kyllian.system32.utils.ColorTranslate;
    import me.kyllian.system32.utils.FileCreator;
    import me.kyllian.system32.utils.Messages;

    public class Ban implements CommandExecutor {

        private Messages mes = new Messages();
        private FileCreator fc = FileCreator.getInstance();
        private ColorTranslate ct = new ColorTranslate();

        public boolean onCommand(CommandSender s, Command cmd, String commandLabel, String[] args) {
            if (cmd.getName().equalsIgnoreCase("ban")) {
                if (args.length == 0) {
                    mes.specifyArguments(s);
                    return true;
                }
                if (args.length == 1) {
                    if (!(s.hasPermission("system32.ban"))) {
                        mes.noPermissions(s);
                        return true;
                    }
                    Player t = Bukkit.getPlayer(args[0]);
                    if (t == null) {
                        mes.notAPlayer(s, args[0]);
                        return true;
                    }
                    if (t == s) {
                        mes.cantBanSelf(s);
                        return true;
                    }
                    fc.getData().set(t.getUniqueId().toString() + ".banned", true);
                    fc.getData().set(t.getUniqueId().toString() + ".unbanTime", "NEVER");
                    fc.getData().set(t.getUniqueId().toString() + ".banReason", "NONE");
                    t.kickPlayer(ct.cc("&7You have been banned!\nReason: NONE\nExpiration: Never"));
                }
                if (args.length > 1) {
                    if (!(s.hasPermission("system32.ban"))) {
                        mes.noPermissions(s);
                        return true;
                    }
                    Player t = Bukkit.getPlayer(args[0]);
                    if (t == null) {
                        mes.notAPlayer(s, args[0]);
                        return true;
                    }
                    if (t == s) {
                        mes.cantBanSelf(s);
                        return true;
                    }
                    fc.getData().set(t.getUniqueId().toString() + ".banned", true);
                    fc.getData().set(t.getUniqueId().toString() + ".unbanTime", "NEVER");
                   
                    StringBuilder sb = new StringBuilder();
                    for (int i = 1; i < args.length; i++) {
                        sb.append(args[i]).append(" ");
                    }
                    String str = sb.toString();
                    fc.getData().set(t.getUniqueId().toString() + ".banReason", str);
                    t.kickPlayer(ct.cc("&7You have been banned!" + "\nReason:" + str + "\nExpiration: Never"));
                }
            }
            return true;
        }
    }
     
     
  2. Try to disable debug in your spigot.yml
     
  3. But there is no way to do it plugin sided?
     
  4. I think not. This is the disconnect message from spigot. You may edit the spigot server to disable this.
     
  5. Try this

    Code (Java):
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onLogin(PlayerLoginEvent e) {
            Player p = e.getPlayer();
            if (fc.getData().getBoolean(p.getUniqueId().toString() + ".banned")) {
                // save the old setting and then set debug to false
                boolean oldDebug = SpigotConfig.debug;
                SpigotConfig.debug = false;

                // do your stuff
                e.disallow(null, ct.cc("&7You have been banned!" + "\nReason:"
                        + fc.getData().getString(p.getUniqueId().toString() + ".banReason") + "\nExpiration: "
                        + fc.getData().getString(p.getUniqueId().toString() + ".unbanTime")));

                // restore the old setting
                SpigotConfig.debug = oldDebug;
                return;
            }
        }
     
    • Useful Useful x 1
  6. This wouldn't work! You change the debug mode before the action the event asks for is performed. If you want to try something like this, you can add a scheduler which resets the debug mode to the old one. The simplest way is to change this in spigot.yml.
     
  7. I want it included in my plugin. Why? Easy, it looks better. I think it works fine. I'll try the code tomorrow
     
  8. Yeah, I said that you may include it in your plugin but you've to add a scheduler because without it it wouldn't work.
     
  9. Why not?
     
  10. He is right.

    The code which produces the output runs after the event passed all listeners and was not canceled. At that point the debug setting is back to true.

    To fix this you will have to set the setting back to true after a short delay (after the code ran which produces the output).
     
    • Agree Agree x 2
  11. Yeah and this should be about 2/3 ticks.
     
  12. So, why not 1 tick (just wondering I always use 1 tick)
     
  13. "fuck you" lmao
     
    • Agree Agree x 1
    • Funny Funny x 1
  14. Yeah, you can try this. Usually it's performed instantly. But if I look back to to the past, I got issues with 1 tick.
     
  15. So, I tried this:

    Code (Text):
    @EventHandler(priority = EventPriority.HIGHEST)
        public void onLogin(PlayerLoginEvent e) {
            Player p = e.getPlayer();
            if (fc.getData().getBoolean(p.getUniqueId().toString() + ".banned")) {
                boolean oldDebug = SpigotConfig.debug;
                SpigotConfig.debug = false;
                e.disallow(null,
                        ct.cc("&7You have been banned!" + "\nReason:"
                                + fc.getData().getString(p.getUniqueId().toString() + ".banReason") + "\nExpiration: "
                                + fc.getData().getString(p.getUniqueId().toString() + ".unbanTime")));
                Bukkit.getScheduler().scheduleSyncDelayedTask(sys32, new Runnable() {
                    @Override
                    public void run() {
                        SpigotConfig.debug = oldDebug;
                    }
                }, 10);
                return;
            }
        }
    But it still puts this out:

    Code (Text):
    [15:28:20 INFO]: Disconnecting [email protected][id=3cfa3047-782d-3cdd-9ee9-74fc60d93cd8,name=InstantlyMoist,properties={},legacy=false] (/127.0.0.1:54265): º7You have been banned!
    Reason:NONE
    Expiration: NEVER
    [15:28:20 INFO]: [email protected][id=3cfa3047-782d-3cdd-9ee9-74fc60d93cd8,name=InstantlyMoist,properties={},legacy=false] (/127.0.0.1:54265) lost connection: º7You have been banned!
    Reason:NONE
    Expiration: NEVER
     
  16. My dude you need to use a log4j filter. I had to use it in my Stardust AntiBot plugin for the same reason. I gotchya covered on this :D
    This should help, its the filter class that I used in my Antibot plugin. Just change the condition to have your required ones.
    Code (Text):

    import org.apache.logging.log4j.message.Message;
    import org.apache.logging.log4j.Marker;
    import org.apache.logging.log4j.Level;
    import org.bukkit.ChatColor;
    import org.apache.logging.log4j.core.LogEvent;
    import org.apache.logging.log4j.core.Filter;
    import org.apache.logging.log4j.LogManager;
    import org.apache.logging.log4j.core.Logger;

    public class filter
    {
       
       
        public void hideMessages() {
            ((Logger)LogManager.getRootLogger()).addFilter((Filter)new Filter() {
                public Filter.Result filter(final LogEvent event) {
                    if (ChatColor.stripColor(event.getMessage().toString()).contains("Please log back in after some time") || ChatColor.stripColor(event.getMessage().toString()).contains("To verify that you are a player") || ChatColor.stripColor(event.getMessage().toString()).contains("UUID of player") || ChatColor.stripColor(event.getMessage().toString()).contains("You have been kicked due to suspicious login activity") || ChatColor.stripColor(event.getMessage().toString()).contains("com.mojang.authlib.GameProfile") || ChatColor.stripColor(event.getMessage().toString()).contains("Please refresh your server list")) {
                        return Filter.Result.DENY;
                    }
                    return null;
                }
               
                public Filter.Result filter(final Logger arg0, final Level arg1, final Marker arg2, final String arg3, final Object... arg4) {
                    return null;
                }
               
                public Filter.Result filter(final Logger arg0, final Level arg1, final Marker arg2, final Object arg3, final Throwable arg4) {
                    return null;
                }
               
                public Filter.Result filter(final Logger arg0, final Level arg1, final Marker arg2, final Message arg3, final Throwable arg4) {
                    return null;
                }
               
                public Filter.Result getOnMatch() {
                    return null;
                }
               
                public Filter.Result getOnMismatch() {
                    return null;
                }
            });
        }
    }
    After making such a class , Create an instance of it in your own enable method and then use the INSTANCE#hideMessages()
    Hopefully I was helpfull
     
    • Useful Useful x 1