Skip to content

Commit

Permalink
Repeated combat-logging now doubles temporary ban duration.
Browse files Browse the repository at this point in the history
Ban duration is reset to the default after player has not combat-logged for 24 hours.
  • Loading branch information
shiinee committed Apr 25, 2012
1 parent 2f68cac commit d6d0ea9
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions CombatTag/com/trc202/CombatTagListeners/NoPvpPlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,27 @@

public class NoPvpPlayerListener implements Listener{

private class Ban {
public long duration;
public long resetTime;

public Ban(long _duration, long _resetTime) {
duration = _duration;
resetTime = _resetTime;
}
}

private final CombatTag plugin;
public static int explosionDamage = -1;
public NPCManager npcm;
public NoPvpEntityListener entityListener;
private HashMap<String, Long> bannedPlayers;
private HashMap<String, Ban> banData;

public NoPvpPlayerListener(CombatTag instance) {
plugin = instance;
bannedPlayers = new HashMap<String, Long>();
banData = new HashMap<String, Ban>();
}

@EventHandler(ignoreCancelled = true)
Expand Down Expand Up @@ -106,8 +118,15 @@ public void tempBanIfPvP(Player player){
PlayerDataContainer dataContainer = plugin.getPlayerData(player.getName());
if (dataContainer.hasPVPtagExpired()) { return; }
long tempBanSeconds = plugin.settings.getTempBanSeconds();
if (banData.containsKey(player.getName())) {
// If the player has recently received a temporary ban for combat-logging,
// the new ban should be twice as long as the previous one.
tempBanSeconds = banData.get(player.getName()).duration * 2;
}
long deadline = (tempBanSeconds * 1000) + System.currentTimeMillis();
long resetTime = 86000 * System.currentTimeMillis();
plugin.log.info("[CombatTag] Combat-logging by " + player.getName() + " detected. Banning for " + tempBanSeconds + " seconds.");
banData.put(player.getName(), new Ban(tempBanSeconds, resetTime));
bannedPlayers.put(player.getName(), deadline);
player.setBanned(true);
}
Expand All @@ -126,6 +145,14 @@ public void tryUnbanIfTempBanned(PlayerLoginEvent event){
event.allow();
}
}
// If the player hasn't been banned by CombatTag recently,
// reset his combat ban duration to the default.
if (banData.containsKey(player.getName())) {
long resetTime = banData.get(player.getName()).resetTime;
if (resetTime > System.currentTimeMillis()) {
banData.remove(player.getName());
}
}
}

private void onPlayerQuitNPCMode(Player quitPlr){
Expand Down

0 comments on commit d6d0ea9

Please sign in to comment.