Warn plugin mutes and kicks them on first warn

Discussion in 'Plugin Development' started by Fhbgsdhkfbl, Aug 6, 2016.

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

    Fhbgsdhkfbl

    So I made a /warn command, and when I run on it on player, it'll loop through everything, mute and kick them right away,

    Command:
    Code:
    package me.fhbgsdhkfbll.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.fhbgsdhkfbll.warns.Warns;
    
    public class WarnCommand implements CommandExecutor {
    
        private Warns pl;
        public WarnCommand(Warns pl) {
            this.pl = pl;
        }
        @Override
        public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("warn")) {
                if(cs.hasPermission("warns.warn")) {
                    if(args.length > 0) {
                        Player p = Bukkit.getPlayer(args[0]);
                        if(p != null) {
                            pl.getConfig().set("players." + p.getUniqueId() + ".warns", pl.getConfig().getInt("players." + p.getUniqueId() + ".warns") + 1);
                            pl.saveConfig();
                           
                            String reason = "Rule Breaking";
                            for(int i = 0; i < args.length; i++) {
                                reason = reason + " " + args[i];
                            }
                           
                            p.sendMessage("§You were warned by " + cs.getName() + " for: " + reason);
                            if(pl.getConfig().getInt("player." + p.getUniqueId() + ".warns") == pl.getConfig().getInt("warns.tokick")) {
                                pl.getConfig().set("players." + p.getUniqueId() + ".kicks", pl.getConfig().getInt("players." + p.getUniqueId() + ".kicks") + 1);
                                pl.getConfig().set("players." + p.getUniqueId() + ".warns", 0);
                                pl.saveConfig();
                                Bukkit.broadcastMessage("§4" + p.getName() + " §cwas kicked for being warned to much for " + reason);
                                p.kickPlayer("§cYou were warned to many times so it resulted in a kick, further warns will be result in worse punishment.");
                            }
                           
                            if(pl.getConfig().getInt("players." + p.getUniqueId() + "kicks") == pl.getConfig().getInt("kicks.tomute")) {
                                Bukkit.broadcastMessage("§4" + p.getName() + " was muted for being warned to many times by a staff member.");
                                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "mute " + p.getName() + " 5m");
                            }
                        }
                        cs.sendMessage("§c" + args[0] + " is not online!");
                        return true;
                    }
                    return false;
                }
                cs.sendMessage("§You don't have permission to warn players!");
                return true;
            }
            return false;
        }
    
    }
    
     
  2. Offline

    N00BHUN73R

    @Fhbgsdhkfbl
    This might be why?
    Code:
    "players." + p.getUniqueId() + "kicks"
    As you can see, there is no . after p.getUniqueId()

    Also, don't use §. You should use ChatColor
     
    bwfcwalshy likes this.
  3. "§You" -> you should use ChatColor like @N00BHUN73R said or use any correct color code e.g. : "§cYou .."
    Are you sure you set "pl.getConfig().getInt("players." + p.getUniqueId() + ".warns")" to 0 or something? It might returns null and.. well you know
     
Thread Status:
Not open for further replies.

Share This Page