Skip to content

Commit

Permalink
Add minimum players to auto search, optional check if player is in PV…
Browse files Browse the repository at this point in the history
…P world for auto checker
  • Loading branch information
Dmck2b committed Sep 8, 2014
1 parent 4ec8853 commit c05b16a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
42 changes: 39 additions & 3 deletions src/main/java/tk/maciekmm/antiaura/AntiAura.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@


public class AntiAura extends JavaPlugin implements Listener {

private HashMap<UUID, AuraCheck> running = new HashMap<>();
public static int total;
private static int autoBanCount;
Expand All @@ -55,6 +56,11 @@ public class AntiAura extends JavaPlugin implements Listener {
private boolean visOrInvisible;
private boolean visCmd;
public static final Random RANDOM = new Random();
private int minToAutoRun;
private boolean worldPvpCheck;
private boolean iCanHasPVP = false;
private int count = 0;
private int maxToCheck;

public void onEnable() {
this.saveDefaultConfig();
Expand All @@ -68,6 +74,9 @@ public void onEnable() {
customCommandToggle = this.getConfig().getBoolean("customBanCommand.enable", false);
customCommand = this.getConfig().getString("customBanCommand.command", "ban %player");
visOrInvisible = this.getConfig().getBoolean("settings.invisibility", false);
minToAutoRun = this.getConfig().getInt("settings.min-players-to-autorun", 5);
worldPvpCheck = this.getConfig().getBoolean("player-checks.world", true);
maxToCheck = this.getConfig().getInt("player-checks.max-to-check", 10);
this.getServer().getPluginManager().registerEvents(this, this);

if(type.equalsIgnoreCase("running") || type.equalsIgnoreCase("standing")) {
Expand All @@ -78,14 +87,41 @@ public void onEnable() {
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
@Override
public void run() {
if(Bukkit.getOnlinePlayers().length > 0) {
String player = org.bukkit.Bukkit.getOnlinePlayers()[RANDOM.nextInt(Bukkit.getOnlinePlayers().length)].getName();
org.bukkit.Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "auracheck " + player);
if(Bukkit.getOnlinePlayers().length > minToAutoRun) {
if(worldPvpCheck) {
findPlayerWorld();
} else {
autoCheckExecute(getRandomPlayer().getName());
}
}
}
}, 800L, runEvery);
}
}

public Player getRandomPlayer() {
return org.bukkit.Bukkit.getOnlinePlayers()[RANDOM.nextInt(Bukkit.getOnlinePlayers().length)];
}

public void findPlayerWorld() {
while(!iCanHasPVP) {
if(count > maxToCheck) {
count = 0;
break;
}
Player player = getRandomPlayer();
count++;
if(player.getWorld().getPVP()) {
iCanHasPVP = true;
autoCheckExecute(player.getName());
}
}
iCanHasPVP = false;
}

public void autoCheckExecute(String player) {
org.bukkit.Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "auracheck " + player);
}

public void register() {
ProtocolLibrary.getProtocolManager().addPacketListener(
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ settings:
autoBanOnXPlayers: 3 # If someone kills this many, they will be autobanned
silentBan: true # If false, user will be kicked on ban, always enabled if using a custom command
randomlyRun: true # Randomly select a player
min-players-to-autorun: 5 # Minimum players to to the auto check
runEvery: 2400 # If above is true, how many ticks between each check
defaultType: "running" # Running or standing style
messages:
banMessage: "ANTI-AURA: Passed threshold" # Ban message
kickMessage: "ANTI-AURA: Passed threshold" # Kick message
customBanCommand:
enable: false
command: ban %player
command: ban %player
player-checks:
world: true
max-to-check: 10

0 comments on commit c05b16a

Please sign in to comment.