Solved Ban default message

Discussion in 'Plugin Development' started by GodzillaFlame42, Sep 5, 2016.

Thread Status:
Not open for further replies.
  1. So i am working on a custom ban plugin but cant figure out how to set it so when someone tries to join again when they are banned it wont put the message i set it as.

    Code:
    Code:
    package me.godzilla;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerKickEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Ban extends JavaPlugin implements Listener {
          
            @SuppressWarnings("deprecation")
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
                    if (cmd.getName().equalsIgnoreCase("ban")) {
                        Player p = (Player) sender;
                        if(p.hasPermission("Warn.Allow")) {
                            Date now = new Date();
                            SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
                            // Check for perms
                            if (args.length < 2) {
                                    sender.sendMessage(ChatColor.RED + "/ban <player> <reason>");
                                    return true;
                            }
                       
                            final Player target = Bukkit.getServer().getPlayer(args[0]);
                          
                            if (target == null) {
                                    sender.sendMessage(ChatColor.RED + "Could not find player " + args[0]);
                                    return true;
                            }
                          
                            String msg = "";
                            for (int i = 1; i < args.length; i++) {
                                    msg += args[i] + " ";
                            }
                    
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "You have been banned by " + ChatColor.YELLOW + p.getName());
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Reason: " + ChatColor.YELLOW + msg);
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Date: " + ChatColor.YELLOW + format.format(now));
                                target.setBanned(true);
                                target.kickPlayer(ChatColor.RED + "                      Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "You have been banned by " + ChatColor.YELLOW + p.getName() + ChatColor.GRAY + "                         Reason: " + ChatColor.YELLOW + msg + ChatColor.GRAY + "   Date: " + ChatColor.YELLOW + format.format(now));
                            }
                        }
                    return false;
            }
                           
    
    @EventHandler
        public void onPlayerKick(PlayerKickEvent event){
        if (event.getReason().contains("You are banned from this server!")) {
                event.setLeaveMessage("Worked");
            }
        }
    }
     
  2. Offline

    kameronn

    @GodzillaFlame42
    There are different reasons for a kick
    Where you put target.kickPlayer(MESSAGE GOES HERE);

    Then on login event, check if the kick reason was equal to kick_ban (i think its that at least) and if it was event.setkickmessage("custom check message")
     
  3. It still doesnt work when i did that, is this how it is supposed to look? @kameronn

    Code:

    Code:
    package me.godzilla;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerKickEvent;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerLoginEvent.Result;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Ban extends JavaPlugin implements Listener {
         
            @SuppressWarnings("deprecation")
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
                    if (cmd.getName().equalsIgnoreCase("ban")) {
                        Player p = (Player) sender;
                        if(p.hasPermission("Warn.Allow")) {
                            Date now = new Date();
                            SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
                            // Check for perms
                            if (args.length < 2) {
                                    sender.sendMessage(ChatColor.RED + "/ban <player> <reason>");
                                    return true;
                            }
                      
                            final Player target = Bukkit.getServer().getPlayer(args[0]);
                         
                            if (target == null) {
                                    sender.sendMessage(ChatColor.RED + "Could not find player " + args[0]);
                                    return true;
                            }
                         
                            String msg = "";
                            for (int i = 1; i < args.length; i++) {
                                    msg += args[i] + " ";
                            }
                  
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.YELLOW + target.getName() + ChatColor.GRAY + " has been banned by " + ChatColor.YELLOW + p.getName());
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Reason: " + ChatColor.YELLOW + msg);
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Date: " + ChatColor.YELLOW + format.format(now));
                                target.setBanned(true);
                                target.kickPlayer(ChatColor.RED + "                      Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "You have been banned by " + ChatColor.YELLOW + p.getName() + ChatColor.GRAY + "                         Reason: " + ChatColor.YELLOW + msg + ChatColor.GRAY + "   Date: " + ChatColor.YELLOW + format.format(now));
                            }
                        }
                    return false;
            }
                          
    
    @EventHandler
        public void onPlayerLogin(PlayerLoginEvent event){
            Result r = event.getResult();  
            if(r == Result.KICK_BANNED) {
                event.setKickMessage("hi");
            }
        }
    }
     
  4. Offline

    kameronn

    @GodzillaFlame42
    try this
    Code:
                if(player.isBanned())
                event.setResult(Result.KICK_BANNED);
    
                event.setKickMessage("cya");
     
  5. @kameronn still doesnt work

    Code:
    Code:
    package me.godzilla;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerKickEvent;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerLoginEvent.Result;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Ban extends JavaPlugin implements Listener {
          
            @SuppressWarnings("deprecation")
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
                    if (cmd.getName().equalsIgnoreCase("ban")) {
                        Player p = (Player) sender;
                        if(p.hasPermission("Warn.Allow")) {
                            Date now = new Date();
                            SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
                            // Check for perms
                            if (args.length < 2) {
                                    sender.sendMessage(ChatColor.RED + "/ban <player> <reason>");
                                    return true;
                            }
                       
                            final Player target = Bukkit.getServer().getPlayer(args[0]);
                          
                            if (target == null) {
                                    sender.sendMessage(ChatColor.RED + "Could not find player " + args[0]);
                                    return true;
                            }
                          
                            String msg = "";
                            for (int i = 1; i < args.length; i++) {
                                    msg += args[i] + " ";
                            }
                   
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.YELLOW + target.getName() + ChatColor.GRAY + " has been banned by " + ChatColor.YELLOW + p.getName());
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Reason: " + ChatColor.YELLOW + msg);
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Date: " + ChatColor.YELLOW + format.format(now));
                                target.setBanned(true);
                                target.kickPlayer(ChatColor.RED + "                      Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "You have been banned by " + ChatColor.YELLOW + p.getName() + ChatColor.GRAY + "                         Reason: " + ChatColor.YELLOW + msg + ChatColor.GRAY + "   Date: " + ChatColor.YELLOW + format.format(now));
                            }
                        }
                    return false;
            }
                           
    
    @EventHandler
        public void onPlayerLogin(PlayerLoginEvent event){
            Result r = event.getResult();   
            if(event.getPlayer().isBanned())
                event.setResult(Result.KICK_BANNED);
    
                event.setKickMessage("cya");
            }
        }
     
  6. Offline

    Jakeeeee

    That does nothing but set the result and a kick message, never really kicks the player. Use event#disallow(result, reason). Don't quote me on this but I think setBanned(true) already handles login, so what you can do is store the players name in a config. Then check to see if the player's name (that tried to join the server) and if they're in the config, then do event#disallow
     
    Mindlessmink likes this.
  7. Offline

    Zombie_Striker

    @GodzillaFlame42
    Are you sure the event is being triggered? Are you sure "isBanned" is returning true?

    @kameronn
    This is why we don't want spoonfeeding here. You forgot to encapsulate the if statement. Now, the kick message will always be set to "cya" even if the player was not banned. This may interfere with other plugins that he has or may have in the future. Please, do not spoonfeed. Make sure your code works before you post it and make sure anyone reading your code can fully understand what each line does (this is more in response to some of your other posts.).
     
  8. @GodzillaFlame42 Since no one has pointed this out yet, if console tries to ban a player it wont work and will just throw an error. You should check before casting
     
  9. Offline

    kameronn

    @Zombie_Striker
    I did think someone giving him that would be spoonfeeding lol. He most likely wouldve figured that out anyways, and its almost no different then just linking java docs but ok, even someone would little knowledge of java couldve understood that or figured it out what it meant
     
  10. It's a shame they probably don't have that.
    And neither do you, or you would have noticed that the code you have up there is wrong.
    Anyways, on to the problem.

    @GodzillaFlame42 That result variable is completely useless since you aren't using it. Get rid of it. Why is your player final? Also, if you have a reason that's more than one word, it won't take the command. This also makes your for loop completely useless since you'll only have a reason that's one argument. And again, put brackets around that if statement in your event.
     
  11. Offline

    TheFl4me

    PlayerLoginEvent

    and then you ust do:

    Code:
    event.disallow(Result.KICK_BANNED, <insert message in here>);
     
  12. Offline

    kameronn

  13. A statement could not be any more false. The Bukkit API is made entirely out of Java, and you use Java to program and make plugins with the Bukkit API.

    Just so I stay on topic,
    @GodzillaFlame42, any updates/updated code?
     
  14. Offline

    ZP18

    I'm sorry to say but @kameronn is right not you, what he/she said is that the Bukkit API is not the same as Java, which is 100% correct. What I think you are trying to say is that the Bukkit API is implemented on the Java language.

    This thread has been going on for quite a while now @GodzillaFlame42 if your issue has been solved please mark the thread as solved if not please reply with any new errors/problems so we can you help you with your problem


    Sent from my iPhone using Tapatalk
     
    Mindlessmink likes this.
  15. @CodePlaysMinecraft and everyone else here is the updated code i have but it still isnt working

    Code:
    package me.godzilla;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerLoginEvent.Result;
    public class Ban implements Listener, CommandExecutor {
          
            @SuppressWarnings("deprecation")
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
                    if (cmd.getName().equalsIgnoreCase("ban")) {
                        Player p = (Player) sender;
                        if(p.hasPermission("Warn.Allow")) {
                            Date now = new Date();
                            SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
                            // Check for perms
                            if (args.length < 2) {
                                    sender.sendMessage(ChatColor.RED + "/ban <player> <reason>");
                                    return true;
                            }
                       
                            final Player target = Bukkit.getServer().getPlayer(args[0]);
                          
                            if (target == null) {
                                    sender.sendMessage(ChatColor.RED + "Could not find player " + args[0]);
                                    return true;
                            }
                          
                            String msg = "";
                            for (int i = 1; i < args.length; i++) {
                                    msg += args[i] + " ";
                            }
                   
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.YELLOW + target.getName() + ChatColor.GRAY + " has been banned by " + ChatColor.YELLOW + p.getName());
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Reason: " + ChatColor.YELLOW + msg);
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Date: " + ChatColor.YELLOW + format.format(now));
                                target.setBanned(true);
                                target.kickPlayer(ChatColor.RED + "                      Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "You have been banned by " + ChatColor.YELLOW + p.getName() + ChatColor.GRAY + "                         Reason: " + ChatColor.YELLOW + msg + ChatColor.GRAY + "   Date: " + ChatColor.YELLOW + format.format(now));
                            }
                        }
                    return false;
            }
                           
    
    @EventHandler
        public void onPlayerLogin(PlayerLoginEvent event){
            Result r = event.getResult();   
            event.disallow(Result.KICK_BANNED, "test");
            }
        }
     
  16. @GodzillaFlame42 Do you register it? And yet again I see in your code you cast WITHOUT checking. I hope you know it's extremely annoying seeing people not fixing mistakes and continuing to make new threads. Also why do you not use a StringBuilder? Why do people not like StringBuilder :( @ArsenArsen
     
  17. Offline

    ArsenArsen

    #StringBuilderMasterRace

    But seriously the compiler itself turns every string contacting attempt into a String builder.

    Use it.

    Not every but most =p
     
    bwfcwalshy likes this.
  18. Yes i registered it but i do have a feeling i registered it wrong... Also im making an unban too but it just sends me a message in white when i either type /unban or /unban <player> <reason> @bwfcwalshy

    Main class:
    Code:
    package me.godzilla;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
        public static Main plugin;
      
        public void onEnable() {
            plugin = this;
          
            this.getCommand("ban").setExecutor(new me.godzilla.Ban());
            this.getCommand("kick").setExecutor(new me.godzilla.Kick());
          
        }
    }
    
    Unban class:
    Code:
    package me.godzilla;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import org.bukkit.Bukkit;
    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 UnBan implements CommandExecutor {
         
            @SuppressWarnings("deprecation")
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
                    if (cmd.getName().equalsIgnoreCase("unban")) {
                        Player p = (Player) sender;
                        if(p.hasPermission("Ban.Allow")) {
                            Date now = new Date();
                            SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
                            // Check for perms
                            if (args.length < 2) {
                                    sender.sendMessage(ChatColor.RED + "/unban <player> <reason>");
                                    return true;
                            }
                      
                            final Player target = Bukkit.getServer().getPlayer(args[0]);
                         
                            if (target == null) {
                                    sender.sendMessage(ChatColor.RED + "Could not find player " + args[0]);
                                    return true;
                            }
                         
                            String msg = "";
                            for (int i = 1; i < args.length; i++) {
                                    msg += args[i] + " ";
                            }
                  
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.YELLOW + target.getName() + ChatColor.GRAY + " has been un-banned by " + ChatColor.YELLOW + p.getName());
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Reason: " + ChatColor.YELLOW + msg);
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Date: " + ChatColor.YELLOW + format.format(now));
                                target.setBanned(false);
                            }
                        }
                    return false;
            }
        }
    plugin.yml:
    name: Punish
    version: 1.0
    main: me.godzilla.Main
    description: Warn players!

    commands:
    ban:
    usage: /<command> <player> <reason>
    description: Ban a player.
    kick:
    usage: /<command> <player> <reason>
    description: Kick a player.
    unban:
    usage: /<command> <player> <reason>
    description: Kick a player.
     
  19. Offline

    Zombie_Striker

    @GodzillaFlame42
    The issue is that you are not registering the command unban. You are registering a ban command and a kick command, but not the unban command. Register the Unban command and that should fix the current issue.
     
  20. @Zombie_Striker thanks for the help. the other thing i am having trouble with is getting the reason when they try to join again all i can get is the date when they try to join again.

    Ban class:
    Code:
    package me.godzilla;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerLoginEvent.Result;
    public class Ban implements Listener, CommandExecutor {
          
            @SuppressWarnings("deprecation")
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
                    if (cmd.getName().equalsIgnoreCase("ban")) {
                        Player p = (Player) sender;
                        if(p.hasPermission("Ban.Allow")) {
                            Date now = new Date();
                            SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
                            // Check for perms
                            if (args.length < 2) {
                                    sender.sendMessage(ChatColor.RED + "/ban <player> <reason>");
                                    return true;
                            }
                       
                            final Player target = Bukkit.getServer().getPlayer(args[0]);
                          
                            if (target == null) {
                                    sender.sendMessage(ChatColor.RED + "Could not find player " + args[0]);
                                    return true;
                            }
                          
                            String msg = "";
                            for (int i = 1; i < args.length; i++) {
                                    msg += args[i] + " ";
                            }
                   
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.YELLOW + target.getName() + ChatColor.GRAY + " has been banned by " + ChatColor.YELLOW + p.getName());
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Reason: " + ChatColor.YELLOW + msg);
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Date: " + ChatColor.YELLOW + format.format(now));
                                target.setBanned(true);
                                target.kickPlayer(ChatColor.RED + "                      Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "You have been banned by " + ChatColor.YELLOW + p.getName() + ChatColor.GRAY + "                         Reason: " + ChatColor.YELLOW + msg + ChatColor.GRAY + "   Date: " + ChatColor.YELLOW + format.format(now));
                            }
                        }
                    return false;
            }
            Date now = new Date();
            SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
    @EventHandler
        public void onPlayerLogin(PlayerLoginEvent event){
            Result r = event.getResult();   
            event.disallow(Result.KICK_BANNED, ChatColor.RED + "                      Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "You have been banned from the server                         Date: " + ChatColor.YELLOW + format.format(now));
            }
        }
     
  21. Offline

    Zombie_Striker

    @GodzillaFlame42
    When you ban a player, save the reason to the config. If they try to rejoin, get the reason from the config.
     
  22. How would i get the reason if i don't have @Zombie_Striker
    Code:
    String msg = "";
                        for (int i = 1; i < args.length; i++) {
                                msg += args[i] + " ";
    
    in the core file?

    Core:
    Code:
    package me.godzilla;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
        public static Main plugin;
      
        public void onEnable() {
            getConfig().options().copyDefaults(true);
            saveConfig();
            plugin = this;
            getServer().getPluginManager().registerEvents(new Ban(), this);
          
            this.getCommand("unban").setExecutor(new me.godzilla.UnBan());
            this.getCommand("ban").setExecutor(new me.godzilla.Ban());
            this.getCommand("kick").setExecutor(new me.godzilla.Kick());
          
        }
    }
    
     
  23. Offline

    Zombie_Striker

    @GodzillaFlame42
    You would save the reason to the config and load it out of the config when you need to use it.

    [edit] re-read your post. Since you have a static instance of your main class, reference that instance in the command class in order to get the config.
     
  24. @Zombie_Striker The config.yml is not showing anything when i start the server up.

    Ban class:
    Code:
    package me.godzilla;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerLoginEvent.Result;
    public class Ban implements Listener, CommandExecutor {
        public static Main plugin;
            @SuppressWarnings("deprecation")
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
                    if (cmd.getName().equalsIgnoreCase("ban")) {
                        Player p = (Player) sender;
                        if(p.hasPermission("Ban.Allow")) {
                            Date now = new Date();
                            SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
                            // Check for perms
                            if (args.length < 2) {
                                    sender.sendMessage(ChatColor.RED + "/ban <player> <reason>");
                                    return true;
                            }
                      
                            final Player target = Bukkit.getServer().getPlayer(args[0]);
                         
                            if (target == null) {
                                    sender.sendMessage(ChatColor.RED + "Could not find player " + args[0]);
                                    return true;
                            }
                         
                            String msg = "";
                            for (int i = 1; i < args.length; i++) {
                                    msg += args[i] + " ";
                                 
                            }
                  
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.YELLOW + target.getName() + ChatColor.GRAY + " has been banned by " + ChatColor.YELLOW + p.getName());
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Reason: " + ChatColor.YELLOW + msg);
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Date: " + ChatColor.YELLOW + format.format(now));
                                target.setBanned(true);
                                if(plugin.getConfig().isString("Reasons") + msg != null);
                                target.kickPlayer(ChatColor.RED + "                      Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "You have been banned by " + ChatColor.YELLOW + p.getName() + ChatColor.GRAY + "                         Reason: " + ChatColor.YELLOW + msg + ChatColor.GRAY + "   Date: " + ChatColor.YELLOW + format.format(now));
                            }
                        }
                    return false;
            }
            Date now = new Date();
            SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
    @EventHandler
        public void onPlayerLogin(PlayerLoginEvent event){
            Result r = event.getResult();  
            event.disallow(Result.KICK_BANNED, ChatColor.RED + "                      Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "You have been banned from the server                         Date: " + ChatColor.YELLOW + format.format(now));
            }
        }
    config.yml:
    #Configuration And Data Storage Files For Punish Plugin
    Reasons:
     
  25. Offline

    Zombie_Striker

    @GodzillaFlame42
    You never set plugin equal to anything. Not only that, but that is not what I meant. Inside your "Main" class, you have a static plugin that is equal to your plugin's instance. This is what you need to use to get the config.

    This also makes no sense:
    1. isString returns a boolean, not a string. You cannot add anything onto it.
    2. You are adding msg to this "String". Since msg will always be set to something, there is no way this can be null.
    3. Because you have a semi colon at the end of the if statement, this statement does nothing. It will check if the "String" is not null, and in any case, it will do nothing. Delete the semicolon, and use brackets to encapsulate what you want to do if this if statement is true.
     
  26. Offline

    Go Hard

    @GodzillaFlame42
    Change the event to PlayerLoginEvent

    Check if the player is banned

    Set the result to KICK_BANNED
    Code:
    e.setResult(Result.KICK_BANNED);
    Set the kick message
    Code:
    e.setKickMessage(ChatColor.RED + "Your message goes here");
     
  27. @Zombie_Striker ok i see what your saying so i do it like this?

    Code:
    package me.godzilla;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerLoginEvent.Result;
    public class Ban implements Listener, CommandExecutor {
        public static Main plugin;
       
            @SuppressWarnings({ "deprecation", "static-access" })
            public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
                    if (cmd.getName().equalsIgnoreCase("ban")) {
                        Player p = (Player) sender;
                        if(p.hasPermission("Ban.Allow")) {
                            Date now = new Date();
                            SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
                            // Check for perms
                            if (args.length < 2) {
                                    sender.sendMessage(ChatColor.RED + "/ban <player> <reason>");
                                    return true;
                            }
                       
                            final Player target = Bukkit.getServer().getPlayer(args[0]);
                          
                            if (target == null) {
                                    sender.sendMessage(ChatColor.RED + "Could not find player " + args[0]);
                                    return true;
                            }
                          
                            String msg = "";
                            for (int i = 1; i < args.length; i++) {
                                    msg += args[i] + " ";
                                  
                            }
                   
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.YELLOW + target.getName() + ChatColor.GRAY + " has been banned by " + ChatColor.YELLOW + p.getName());
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Reason: " + ChatColor.YELLOW + msg);
                                Bukkit.broadcastMessage(ChatColor.RED + "Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "Date: " + ChatColor.YELLOW + format.format(now));
                                target.setBanned(true);
                                if(this.plugin.getConfig().getString("Reasons") != msg) {
                                target.kickPlayer(ChatColor.RED + "                      Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "You have been banned by " + ChatColor.YELLOW + p.getName() + ChatColor.GRAY + "                         Reason: " + ChatColor.YELLOW + msg + ChatColor.GRAY + "   Date: " + ChatColor.YELLOW + format.format(now));
                            }
                        }
                    }
                    return false;
            }
            Date now = new Date();
            SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
    @EventHandler
        public void onPlayerLogin(PlayerLoginEvent event){
            Result r = event.getResult();   
            event.disallow(Result.KICK_BANNED, ChatColor.RED + "                      Punish" + ChatColor.DARK_GRAY + " » " + ChatColor.GRAY + "You have been banned from the server                         Date: " + ChatColor.YELLOW + format.format(now));
            }
        }
     
  28. Offline

    Zombie_Striker

    This is null. Just delete this line and replace all "plugin" references with "Main.plugin"

    This also will always be true. You cannot compare strings using ==, so they will never be equal. Remove this line.

    Use this line to save the ban reason.

    Use this to get the reason.
     
Thread Status:
Not open for further replies.

Share This Page