Solved AntiCheat Plugin Development Problem

Discussion in 'Plugin Development' started by NixBuildz, Aug 23, 2016.

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

    NixBuildz

    Hello,
    I am making a anticheat and I have encountered some problems. I will post the code as well as screenshots of problems I have.
    The code:
    Code:
    package me.NixBuildz.matrixanticheat;
    
    import java.util.ArrayList;
    
    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.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
      
        private ArrayList<Player> banned = new ArrayList<Player>();
      
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (cmd.getName().equalsIgnoreCase("warn")) {
                // Check for perms.
                if (args.length < 2) {
                    sender.sendMessage(ChatColor.RED + "/warn <player> <reason>");
                    return true;
                }
              
                final Player target = Bukkit.getServer().getPlayer(args[0]);   //error1
              
                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];
                }
              
                Object level = this.getConfig().get(target.getName());
              
                if (level == null) {
                    target.sendMessage(ChatColor.RED + msg);
                    this.getConfig().set(target.getName(), 1);
                    this.saveConfig();
                    return true;
                }
              
                int l = Integer.parseInt(level.toString());
              
                if (l == 1) {
                    target.kickPlayer(ChatColor.RED + msg);
                    this.getConfig().set(target.getName(), 2);
                    this.saveConfig();
                    return true;
                }
              
                if (l == 2) {
                    banned.add(target);
                    target.kickPlayer(ChatColor.RED + msg);
                    target.setBanned(true); //error2
                  
                    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                        public void run() {
                            banned.remove(target);
                        }
                    }, 1440 * 60);
                  
                    return true;
                }
            }
            return true;
        }
    
    }

    Screenshots:

    error1:

    error1.JPG

    error2:

    error2.JPG
     
    Last edited by a moderator: Aug 23, 2016
  2. Offline

    timtower Moderator Moderator

    @NixBuildz
    1. Those are warnings.
    2. The getPlayer is because of the string input, it is deprecated to get attention to the UUID change, just suppress the warning.
    3. What is the message on setBanned?
     
  3. Offline

    NixBuildz

    setBanned message is the ban message that the staff inputs
    here is the code:

    Code:
     String msg = "";
                for (int i = 1; i < args.length; i++) {
                    msg += args[i];
                }
     
  4. Offline

    timtower Moderator Moderator

    @NixBuildz Hover your mouse over the warning.
    What does it say?
     
  5. Offline

    bwfcwalshy Retired Staff

  6. Offline

    NixBuildz

  7. Offline

    timtower Moderator Moderator

  8. Offline

    NixBuildz

    tim I see but can you give me a example?
     
  9. Offline

    bwfcwalshy Retired Staff

    It takes a Date. Get the current Date with new Data(System.currentTimeMillis()): add 24 hours and use that date. Google is your friend for any examples.
     
  10. Offline

    NixBuildz

    Im sorry... Im a noob...
     
  11. Offline

    timtower Moderator Moderator

    For a single method call I won't.
    I won't spoonfeed anyways though.
     
  12. Offline

    NixBuildz

    I have edited the code a bit but it says there is a error:

    error3.JPG

    Never mind. I fixed it... hopefully.

    Oh wait no... I came across this issue. error4.JPG

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 23, 2016
  13. Offline

    N00BHUN73R

    @NixBuildz
    Oh, good ol PogoStick29Dev tutorials..

    Anyways, On-Topic:
    You have to first import BanEntry and then use the correct parameters, because what you're doing now is not correct.
    The BanEntry.addBan() is as follows:
    PHP:
    BanEntry addBan(String target,
                    
    String reason,
                    
    Date expires,
                    
    String source)
    You can go here for more info:
    https://hub.spigotmc.org/javadocs/b...ang.String, java.util.Date, java.lang.String)
     
  14. Offline

    NixBuildz

    @N00BHUN73R Thanks!

    Nope... still have the problem.
    Here is the code:

    Code:
    if (l == 2) {
                    BanEntry.addBan(target.getName(), ChatColor.GREEN + "Cheating", ChatColor.GREEN + "You have been permanently banned.", ChatColor.BLUE + "Banned by:" + ChatColor.RED + ChatColor.BOLD + "Matrix AntiCheat") //Here is the issue. addBan will not be recognized.
                
                
                    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                        public void run() {
                            banned.remove(target);
                        }
                    }, 1440 * 60);
    I have removed the ";" and added the dot between them but addBan will not work! When I hover over it, it says, "The method addBan(String, String, String, String) is unidentified"
    @Zombie_Striker Got any ideas?


    I have fixed it but when I input it into my server, it will not work. I have finished the plugin.yml but I do not believe it is fully complete. Help?
     
    Last edited: Aug 24, 2016
  15. Offline

    N00BHUN73R

    @NixBuildz
    The reason it's still not working is because addBan() doesnt take 4 strings.
    It takes a target, so target.getname
    It takes a reason, so
    PHP:
    ChatColor.GREEN "Cheating" ChatColor.GREEN "You have been permanently banned." ChatColor.BLUE "Banned by:" ChatColor.RED ChatColor.BOLD "Matrix AntiCheat"
    It takes a date, so when it expires, new Date() (This can be null to imply forever)
    and a source, which I believe can just be null

    Finished:
    PHP:
    BanEntry.addBan("usser2Ban"ChatColor.GREEN "Cheating"ChatColor.GREEN "You have been permanently banned." ChatColor.BLUE "Banned by:" ChatColor.RED ChatColor.BOLD.toString() + "Matrix AntiCheat"nullnull);
    This would ban usser2Ban forever with the reason, Cheating: Banned permanently, Banned by: Matrix Anticheat
     
  16. Offline

    NixBuildz

    @N00BHUN73R
    Okay thanks! Now I am stuck on the perms tho... I am trying to make a onCommand() line that if the player has permission to execute the command, it will execute it and otherwise it will say, "Not enough permissions to execute this command. For more information please confront a moderator."

    Here is the code:

    Perms.Java:


    Code:
    package me.NixBuildz.matrixanticheat;
    
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    
    public class Perms implements Listener {
        @EventHandler
        public void onCommand() {
       
    
       
        }
    }
    
    

    Main.Java:


    Code:
    package me.NixBuildz.matrixanticheat;
    
    import java.util.ArrayList;
    
    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.permissions.Permission;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
    
        public Permission playerPermission = new Permission("matrix.warn");
    
        @Override
        public void onEnable() {
            getLogger().info(ChatColor.BLUE + "Matrix AntiCheat is enabled.");
            PluginManager pm = getServer().getPluginManager();
            pm.addPermission(playerPermission);
       
        }
    
        @Override
        public void onDisable() {
            getLogger().info(ChatColor.BLUE + "Matrix AntiCheat is disabled.");
        }
    
        private ArrayList<Player> banned = new ArrayList<Player>();
        @SuppressWarnings("deprecation")
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (cmd.getName().equalsIgnoreCase("warn")) {
                if (args.length < 2) {
                    sender.sendMessage(ChatColor.RED + "/warn <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;
                }
           
                for (int i = 1; i < args.length; i++) {
                }
           
                Object level = this.getConfig().get(target.getName());
           
                if (level == null) {
                    target.sendMessage(ChatColor.RED + "Our AntiCheat has decected that you have been hacking. This is a warning.");
                    this.getConfig().set(target.getName(), 1);
                    this.saveConfig();
                    return true;
                }
           
                int l = Integer.parseInt(level.toString());
           
                if (l == 1) {
                    target.kickPlayer(ChatColor.RED + "You have been kicked for hacking." + "Next time you hack you will be permanently banned.");
                    this.getConfig().set(target.getName(), 2);
                    this.saveConfig();
                    return true;
                }
           
                if (l == 2) {
                    target.kickPlayer(ChatColor.RED + "You have been banned for hacking." + ChatColor.BLUE + "Banned by: Matrix AntiCheat");
                    target.setBanned(true);
               
                    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                        public void run() {
                            banned.remove(target);
                        }
                    }, 1440 * 60);
               
                    return true;
                }
            }
            return true;
        }
    
    }

    also addBan() is still a error

    also, when I do Player player = e.getPlayer(); its telling me to add a cast to 'e' and I dont really want to do that.
     
    Last edited: Aug 24, 2016
  17. Offline

    Zombie_Striker

    @NixBuildz
    1. If you want a separate class for a command, use CommandExecutor, not listener.
    2. onCommand is not an event, so remove the @EventHandler tag
    3. onCommand requires all of the other parameters in order to work.
    4. to check if a player has permission, use (Player#hasPermission(String perm))
    Can you post what you used to use "addBan"? It should be BanList.addBan().

    Also, I do not see any events in your class, or any "e" variables for that matter. Where are you trying to get the player?
     
  18. Offline

    NixBuildz

    @Zombie_Striker
    Hey sorry I was out of the house... when I use BanList.addBan() the addBan comes up as a error that has no "quick solutions" I am trying to see if the player has the permission to the command and if they do, to execute the command and if they dont to, of course, not execute it.
     
  19. Offline

    Zombie_Striker

    @NixBuildz
    That is because BanList is not an an object/class you call, you have to access it. Use Bukkit.getBanList(BanList.Type.NAME) to get the banlist of player names.
     
  20. Offline

    NixBuildz

    @Zombie_Striker
    nvm... I have solved the issue but I cant get the plugin to work! I have tried but I can export it and get it to work on my server... I will try again with the help of youtube.
     
    Last edited: Aug 24, 2016
Thread Status:
Not open for further replies.

Share This Page