Solved Violations Help (AntiCheat Coding)

Discussion in 'Spigot Plugin Development' started by Lookups, May 25, 2018.

  1. Hello,
    I've been coding a anticheat lately for my server.
    I've tried to make violations to autoban / flag people.
    I've made a int for it but as i can't give a player a private violation with a int i'll need to find another solution
    What i have atm:

    Code (Java):
    public int vl = 1;

    // code //

    e.setCancelled(true);
    vl++;

    }

    if(vl >= 25) {
    // code //
    How could i make private violations for players?

    EDIT:
    Dont trash my thread, just comment helpfull comments.
     
  2. bump, am i allowed to?​
     
  3. Use a Map with the Player UUID as the key and the int as the value.
     
  4. I've tried looking at other threads on bukkit during waiting for a solution and i've came past this thread:
    https://bukkit.org/threads/violation-levels-for-clicksperseconds.425276/

    I tried using their solution but the ++'s on :
    vl.put(p.getName(), vl.get(pl.getName())++);
    do not work
    and it can't see vl.put
    (HashMap)

    How could i fix this?
    Also:

    could you give me a example?
     
  5. Based on your first post, vl is an integer, not a map. Show me what you have so I can look at it.

    I don’t exactly know what the vl is supposed to represent.
     
  6. Old code:
    HTML:

    public class GlideListener implements Listener{
       
        public int vl = 0;
       
    // code
                    e.setCancelled(true);
     // code //
                        vl++;
                    }
                    if(vl == 15) {
     // code //
                       
                    }
            }
        }

    }
    }
     
    New Code:

    HTML:

           HashMap<Player, Integer> vl = new HashMap<Player, Integer>();
       
    // code
                    e.setCancelled(true);
     // code //
                           vl.put(p.getName(), vl.get(p.getName())++);
                    }
                       if (vl.get(p.getName()) >= 5) {
     // code //
                       
                    }
            }
        }

    }
    }
     
    Having issues at:
    vl.put(p.getName(), vl.get(p.getName())++);
    (The method put(Player, Integer) in the type HashMap<Player,Integer> is not applicable for the arguments (String, Integer))
    and (Invalid argument to operation ++/--)
     
  7. Use + 1 not ++
     
    • Agree Agree x 1
  8. Thats pretty self-explanatory. You are putting a String key into a map that takes a Player object key.

    And about the ++, @xPlumpOrange answered it.
     
  9. Syntax error on token "+", ++ expected
    U sure mate?
    And you also shouldn't have helped my other problem.
     
  10. Let me see your current code, I have a feeling you did it wrong
     
  11. Yeah he is doing something wrong. The Map has a Player as a key, but he is trying to put a String key.
     
  12. I posted it above.

    Code (Text):
    package wac.checks.movement;

    import java.util.HashMap;

    import org.bukkit.Bukkit;
    import org.bukkit.GameMode;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.BlockFace;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.util.Vector;


    public class FlyListener implements Listener{
       
        HashMap<Player, Integer> vl = new HashMap<Player, Integer>();
       
    // code //
                            vl.put(p.getName(), vl.get(p.getName())++);
                        }
                        if (vl.get(p.getName()) >= 5) {
                          // code //
                           
                        }
                    }
                }
               
            }
           
        }

    }
     
     
  13. You have to remove the value from the hashmap before readding it

    Edit:
    You have to use String as a value in the Hashmap
     
  14. You don’t have to remove. Map#put replaces an entry if the keys are the same.
     
  15. I've fixed the "vl.put" issue,
    Still remaining the invalid characters issue (++ / --)
     
  16. Change ++ to +1
     
  17. Thank you, Sorry for misunderstanding
    This thread is now solved.
    (Yes, i'm kind of new to java)
     
  18. Thread reopened
    I'm getting an error when setting of alerts:
    Caused by: java.lang.NullPointerException at wac.checks.movement.MoveListener.onMove(MoveListener.java:41) ~[?:?]
    ( vl.put(p.getName(), vl.get(p.getName())+1); )
    It does set of alerts but it doesnt autoban
    Also:
    https://gyazo.com/6b3f54940db7d3c62b2dcbcca70c53f3
    Should be saying ( amount of violations ) instead of ({})

    EDIT:
    Changed the alert "vl" to "vl.values().size" , right now just shows (0)
     
    #18 Lookups, May 25, 2018
    Last edited: May 25, 2018
  19. If it's throwing a NPE that probably means that the player isn't in the map yet. Make a check first.
     
  20. Your map is null.