Using the AAC API properly

Discussion in 'Spigot Plugin Development' started by ItzSomebody, May 10, 2017.

  1. Hey there! I just recently picked up Java and experimenting with APIs at the moment. So say I wanted to make a plugin that does
    Code (Text):
    /aaccheck <player> <HackType>
    and by default the HackType is off so when
    Code (Text):
    /aaccheck ItzSomebody Derp
    is run, it enables the check for about 5 minutes and sees if ItzSomebody's VLs raise above a certain level.


    Lol, how do I do that xD
     
  2. I don't know, but I just wanted to say, that this is similar to how Hypixel's system works.

    If a user is reported multiple (3) times, or a staff activates a similar command, they'll be checked for a certain hack.

    KillAura:
    This will summon invisible and visible fake players, around the player

    AntiKnockback:
    This will give the player small amounts of knockback, from side to side, almost unnoticeable, and if they don't take knockback, and their ping is average with no lag issues, they'll be autobanned
     
    • Agree Agree x 2
  3. The idea is the same, but I also want to learn how to code better. :)
     
  4. Awesome, good luck to you, I would hope you'd make this an open-source project possibly? You could get helpful criticism on your coding, support, and you'd be helping other developers and server owners.
    (I still have yet to get an API working... I'm still a complete noob at coding ;))
     
    • Friendly Friendly x 1
  5. After looking at AAC's current API, they have no methods to do this for you. You could 1. use reflection and access the player's data object (would require you to study code) and manually modify what you want. Or you could just have your server (console) run the command.

    EDIT: Actually, this is what you want:
    int getViolationLevel(Player player, HackType check)
    Returns the internal violation level for a specific check, for a specific player. This is shown in the log files, after "VL:"

    Store that int, check 5 minutes later in a scheduler if that number has increased by so much you want it to increase.

    EDIT: Example:
    Code (Text):
    int nowViolation = AACAPIProvider.getAPI().getViolationLevel(Bukkit.getPlayer("ExpDev"), HackType.AIMBOT);
    //scheduler to schedule 5 minutes later >
    int newViolation = AACAPIProvider.getAPI().getViolationLevel(Bukkit.getPlayer("ExpDev"), HackType.AIMBOT);

    if ((newViolation - nowViolation) > 5) {
      // increased by 5
    }
     
    #5 ExpDev, May 10, 2017
    Last edited: May 10, 2017
    • Useful Useful x 1
  6. Ahh thanks! I will report back when I fail again xD
     
  7. Ok, I (sorta) got some code put together... and got errors in the console. (Prepare your eyes for a headache)
    Code (Text):
    package me.itzsomebody.aacreport;

    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitRunnable;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.Bukkit;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;

    import me.konsolas.aac.api.AACAPIProvider;
    import me.konsolas.aac.api.HackType;

    public abstract class AACReport extends JavaPlugin {

        private AACReport plugin;

        @Override
        public void onEnable() {
            System.out.println("[AACReport] AACR has been enabled.");
        }

        class delayListener implements Listener {
             
            private final AACReport plugin;
         
           public delayListener(AACReport plugin) {
               this.plugin = plugin;
               this.plugin.getServer().getPluginManager().registerEvents(this, plugin);
           }
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("aacr") || cmd.getName().equalsIgnoreCase("aacreport")) {
                String reportedPlayer = args[0];
                if (args[0] == null) {
                    sender.sendMessage("&cUsage: /aacreport <player> <reason>");
                    return false;
                }
                if (args[1].equalsIgnoreCase("aimbot") || args[1].equalsIgnoreCase("killaura")) {
                    int nowViolation = AACAPIProvider.getAPI().getViolationLevel(Bukkit.getPlayer(reportedPlayer), HackType.FORCEFIELD);
                   
                    int newViolation = AACAPIProvider.getAPI().getViolationLevel(Bukkit.getPlayer(reportedPlayer), HackType.FORCEFIELD);

                    runDelayEvent(nowViolation, newViolation);
                   
                    if ((newViolation - nowViolation) > 10) { // If increased by 5
                        getServer().dispatchCommand(getServer().getConsoleSender(), "ban " + reportedPlayer + " AACR Test");
                    } else {
                        sender.sendMessage("[AACR] I was unable to find out if " + reportedPlayer + "was hacking!");
                    }
                }
                return true;
            } //If this has happened the function will return true.
               // If this hasn't happened the value of false will be returned.
            return false;
        }

        public void ExampleListener(AACReport plugin) {
            this.plugin = plugin;
            this.plugin.getServer().getPluginManager().registerEvents((Listener) this, plugin);
        }
       
        @EventHandler
        public void runDelayEvent(int firstArg, int secondArg) {
            new BukkitRunnable() {
           
                @Override
                public void run() {
                   
                }
               
            }.runTaskLater(this.plugin, 6000);
        }
       
        public void onDisable() {
            System.out.println("[AACReport] AACR has been disabled.");
        }
    }
    Here is the stack trace (btw, I tried googling first but no luck)
    Code (Text):
    [01:18:38] [Server thread/ERROR]: Could not load 'plugins\AACReport.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: Abnormal plugin type
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:80) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugins(CraftServer.java:292) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:198) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]
    Caused by: java.lang.InstantiationException
        at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_131]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_131]
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_131]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        ... 7 more
    K, a little help? XD
     
  8. Code (Text):
    public abstract class AACReport extends JavaPlugin {
    Change to
    Code (Text):
    public class AACReport extends JavaPlugin {
     
  9. To begin with, you can't do this:
    Code (Text):
    int nowViolation = AACAPIProvider.getAPI().getViolationLevel(Bukkit.getPlayer(reportedPlayer), HackType.FORCEFIELD);
                   
    int newViolation = AACAPIProvider.getAPI().getViolationLevel(Bukkit.getPlayer(reportedPlayer), HackType.FORCEFIELD);

    runDelayEvent(nowViolation, newViolation);
    Here, nowViolation would = newViolation.

    See something I made just now quickly. Read the comments. You would do this inside your command.
    Code (Text):
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class ExecTest extends JavaPlugin {

        public static void main(String[] strings) {
            // I need an instance of my class extending JavaPlugin
            // You would just refer to your main class which has loaded
            // onEnable
            ExecTest test = new ExecTest();
           
            // Player we will check. Make final because schedulers.
            final Player toCheck = Bukkit.getPlayer("ExpDev");
           
            // Check if they are online
            if (toCheck == null) {
                System.out.println("Player is offline. How can their VL increase then?");
                return;
            }

            // Their current VL when command was ran. Also final
            final int currentVL = 5; // you would get the AAC VL of toCheck, but I don't have AAC.
           
            // Announcing that we are indeed gonna start the scheduler
            System.out.println("Starting a scheduler which will check for player's VL in 5 mins and compare");
           
            // Our scheduler. You might wanna consider saving this int, as you can use it
            // to idendify which scheduler is related to which player
            int scheduler = Bukkit.getScheduler().scheduleSyncDelayedTask(test, new Runnable() {
                @Override
                public void run() {
                    // time to compare. Might want to perform a null check
                    // on the player. They might have logged off
                    int newVL = 10;
                   
                    // If their VL increased by five or more
                    // they shall be banned
                    if ((newVL - currentVL) >= 5) {
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ban " + toCheck.getName() + " Your VL increased by 5");
                    }
                }
            }, 20*60*5); // 20 ticks = 1 second * 60 * 5 = 5 minutes
           
        }

    }