Solved VL System doesn't work

Discussion in 'Plugin Development' started by aweewee, Jan 12, 2020.

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

    aweewee

    I am making an anticheat right now. I am trying to make a violation system so instead of saying
    "username failed Speed", it'll say "username failed Speed[VL 1] and the vl will go up by one every time.
    I am trying to make the vl separate for each check. So even if speed vl gets to 20, noslow vl will still be at 1. I tried putting getVL and VL in CheckResult class, but it can't be used in another class unless I define it somehow?(i'm not really sure)
    Main class:
    Code:
    package com.bika.PAC;
    
    import static org.bukkit.ChatColor.BOLD;
    import static org.bukkit.ChatColor.DARK_PURPLE;
    import static org.bukkit.ChatColor.GRAY;
    import static org.bukkit.ChatColor.RED;
    import static org.bukkit.ChatColor.RESET;
    
    import java.util.HashMap;
    import java.util.UUID;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.bika.PAC.checks.CheckResult;
    import com.bika.PAC.events.JoinLeaveListener;
    import com.bika.PAC.events.MoveListener;
    import com.bika.PAC.events.PlayerListener;
    import com.bika.PAC.util.Settings;
    import com.bika.PAC.util.User;
    
    
    public class Main extends JavaPlugin{
    
        public static HashMap<UUID, User> USERS = new HashMap<>();
        static int VL;
        @Override
        public void onEnable() {
            PluginManager pm = Bukkit.getPluginManager();
            pm.registerEvents(new JoinLeaveListener(), this);
            pm.registerEvents(new MoveListener(), this);
            pm.registerEvents(new PlayerListener(), this);
           
            for (Player p : Bukkit.getOnlinePlayers())
                USERS.put(p.getUniqueId(), new User(p));
        }
       
        public static void log(CheckResult cr, User u) { 
            String message = DARK_PURPLE.toString() + BOLD + "[PAC] " + RESET.toString() + RED + u.getPlayer().getName() + GRAY + " " + cr.getLevel().toString().toLowerCase() + " " + DARK_PURPLE + cr.getType().getName() + " [VL " + VL + "]";
            for(Player p : Bukkit.getOnlinePlayers())
                if (p.hasPermission(Settings.NOTIFY))
                    p.sendMessage(message);
                Bukkit.getConsoleSender().sendMessage(message);
                Bukkit.getServer().broadcastMessage(message);
                VL++;
            }
       
        public static User getUser(Player p) {
            return USERS.get(p.getUniqueId());
        }
        }
    
    CheckResult Class
    Code:
    package com.bika.PAC.checks;
    
    public class CheckResult {
    
        private Level level;
        private String message;
        private CheckType type;
       
        public CheckResult(Level level, String message, CheckType type) {
            this.level = level;
            this.message = message;
            this.type = type;
        }
       
        public Level getLevel() {
            return level;
        }
        public String getMessage() {
            return message;
        }
       
        public CheckType getType() {
            return type;
        }
       
        public boolean failed() {
            return level != Level.PASSED;
        }
    }
    
     
  2. Offline

    Niv-Mizzet

    @aweewee Could you explain what you're asking?
    If you're just trying to run a function, then you can use Checkresult cr=new CheckResult(Level, message, type)
     
  3. Offline

    KarimAKL

    @aweewee If i understood your problem correctly, you want to make one "VL" for every cause.
    To do this you could make all the causes static constants (an enum would work), then make an instance variable of type Map<UUID, Integer> named "vl", then increase that cause's "vl" for that player when it's detected. (Remember to save and load the "vl" if you want it to persist through restarts)
     
  4. Offline

    aweewee

    @KarimAKL Oh, I figured out how to do it with a warning system, by putting MAX_WARNINGS in a settings class and returning it so I could use it in the main class. Thanks for your help though!
     
Thread Status:
Not open for further replies.

Share This Page