Solved Violation levels for ClicksPerSeconds

Discussion in 'Plugin Development' started by Sehq, Jul 14, 2016.

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

    Sehq

    Hey guys, I'm having a bit of an issue.

    I know that this code I'm about to post is very-not-right and needs to be fixed, but I'll fix it on my own.
    What I want to know is HOW to add these violations levels + autoban. Please do not give me the code, just help/explain to me how to add violations then make it autoban.

    Code:
    public class CPSBan extends JavaPlugin implements Listener {
        int vl = 0;
        @EventHandler
        public void onCPSWarn(ClickWarningEvent e) {
            Player p = e.getPlayer();
            if (vl >= 5) {
                Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "ipban " + p.getName() + " You have been banned for cheating - Autoclicking");                
       
        int clicks = e.getClickAmount();   
       
        if (clicks > 35) {
            p.getName();
            vl++
            }
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
        }
        public void onDisable() {       
        }
    
    }
    
    I'm using this plugin with another plugin's API (which is where I get int clicks from and ClickWarningEvent.)
    The coding will be in messed up spots, so I'll work on that, but I'm initially not sure of what to do.

    I attempted to create an int that has the value of 0, and each time a player has over 35 CPS, add a vl level to their name. On the event that the violation level is 5 or above, I'd like it to ban them.

    Any idea on how to do this? All help would be amazing. Thanks!
     
  2. Offline

    ipodtouch0218

    Use a Map or HashMap to store the player's VL, not an internal variable as they change for every player.

    Code:
        public void onDisable() {     
        }
    onDisable doesn't do anything, you can remove it.

    Your missing a closing bracket, you never close "if (vl >= 5)"

    Code:
        int clicks = e.getClickAmount(); 
      
        if (clicks > 35) {
            p.getName();
            vl++
            }
    p.getName() doesn't do anything.
     
  3. Offline

    Sehq

    Ok, so I've been reading into Head First Java (about 200 pages in) so I haven't come across using HashMaps yet.

    Code:
    HashMap<Player, Integer> vl = new HashMap<Player, Integer>();
       
        @EventHandler
        public void onCPSWarn(ClickWarningEvent e) {
            Player p = e.getPlayer();
            vl.put(p.getName(), vl++);
    
    I have no idea if that's correct, seeing as there's an issue with vl++. Once again I don't want the actual code, but if possible, an explanation of what should be done so I can translate it myself.

    I still have to complete that section, I just want to figure out giving violation levels first.

    Thanks for the help anyways, and if you don't want to give any more info, that's fine. I'll attempt to look around and experiment a bit more.
     
  4. Offline

    ipodtouch0218

    @Sehq You want to add to the player's vl.. so use
    Code:
    vl.put(p.getName(), vl.get(pl.getName())++);
    Or you can just assign a variable and get it done neater
    Code:
    int vlBefore = vl.get(p.getName())
    vl.put(p.getName(), vlBefore++);
     
  5. Offline

    Sehq

    Thank you! The only issue I have with the code is the
    Code:
    if (vl = 5) {
                Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "ipban " + p.getName() + " You have been banned for cheating - Autoclicking");                
            }
    
    statement, but I'm sure I can figure that out. Thanks for the help :D
     
  6. Offline

    ipodtouch0218

    @Sehq Quite simple:
    Code:
    if (vl.get(p.getName()) == 5) { //Checks if player's VL is 5
    Wish you luck on future coding!
     
  7. Offline

    Sehq

    Oh my god I am actually so stupid.
    Thank you!
     
Thread Status:
Not open for further replies.

Share This Page