From fc56e461d79ec9bdcf3f2dfd43ea825b500e3a8d Mon Sep 17 00:00:00 2001 From: ryanhamshire Date: Mon, 13 Oct 2014 13:35:53 -0700 Subject: [PATCH] Login cooldown to seconds. Default to 60 seconds instead of 2 minutes. Now configurable in seconds. --- .../GriefPrevention/GriefPrevention.java | 6 ++--- .../GriefPrevention/PlayerEventHandler.java | 26 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java index a6fd6b2..005ea5f 100644 --- a/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -102,7 +102,7 @@ public class GriefPrevention extends JavaPlugin public ArrayList config_siege_blocks; //which blocks will be breakable in siege mode public boolean config_spam_enabled; //whether or not to monitor for spam - public int config_spam_loginCooldownMinutes; //how long players must wait between logins. combats login spam. + public int config_spam_loginCooldownSeconds; //how long players must wait between logins. combats login spam. public ArrayList config_spam_monitorSlashCommands; //the list of slash commands monitored for spam public boolean config_spam_banOffenders; //whether or not to ban spammers automatically public String config_spam_banMessage; //message to show an automatically banned player @@ -329,7 +329,7 @@ public class GriefPrevention extends JavaPlugin outConfig.set("GriefPrevention.Claims.Expiration.AutomaticNatureRestoration.CreativeWorlds", this.config_claims_creativeAutoNatureRestoration); this.config_spam_enabled = config.getBoolean("GriefPrevention.Spam.Enabled", true); - this.config_spam_loginCooldownMinutes = config.getInt("GriefPrevention.Spam.LoginCooldownMinutes", 2); + this.config_spam_loginCooldownSeconds = config.getInt("GriefPrevention.Spam.LoginCooldownSeconds", 60); this.config_spam_warningMessage = config.getString("GriefPrevention.Spam.WarningMessage", "Please reduce your noise level. Spammers will be banned."); this.config_spam_allowedIpAddresses = config.getString("GriefPrevention.Spam.AllowedIpAddresses", "1.2.3.4; 5.6.7.8"); this.config_spam_banOffenders = config.getBoolean("GriefPrevention.Spam.BanOffenders", true); @@ -573,7 +573,7 @@ public class GriefPrevention extends JavaPlugin outConfig.set("GriefPrevention.Claims.AutoRestoreUnclaimedCreativeLand", this.config_claims_autoRestoreUnclaimedCreativeLand); outConfig.set("GriefPrevention.Spam.Enabled", this.config_spam_enabled); - outConfig.set("GriefPrevention.Spam.LoginCooldownMinutes", this.config_spam_loginCooldownMinutes); + outConfig.set("GriefPrevention.Spam.LoginCooldownSeconds", this.config_spam_loginCooldownSeconds); outConfig.set("GriefPrevention.Spam.MonitorSlashCommands", slashCommandsToMonitor); outConfig.set("GriefPrevention.Spam.WarningMessage", this.config_spam_warningMessage); outConfig.set("GriefPrevention.Spam.BanOffenders", this.config_spam_banOffenders); diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java index 8f419d7..2d263d2 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java @@ -428,20 +428,20 @@ class PlayerEventHandler implements Listener //FEATURE: login cooldown to prevent login/logout spam with custom clients //if allowed to join and login cooldown enabled - if(GriefPrevention.instance.config_spam_loginCooldownMinutes > 0 && event.getResult() == Result.ALLOWED) + if(GriefPrevention.instance.config_spam_loginCooldownSeconds > 0 && event.getResult() == Result.ALLOWED) { //determine how long since last login and cooldown remaining PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId()); long millisecondsSinceLastLogin = (new Date()).getTime() - playerData.lastLogin.getTime(); - long minutesSinceLastLogin = millisecondsSinceLastLogin / 1000 / 60; - long cooldownRemaining = GriefPrevention.instance.config_spam_loginCooldownMinutes - minutesSinceLastLogin; + long secondsSinceLastLogin = millisecondsSinceLastLogin / 1000; + long cooldownRemaining = GriefPrevention.instance.config_spam_loginCooldownSeconds - secondsSinceLastLogin; //if cooldown remaining and player doesn't have permission to spam if(cooldownRemaining > 0 && !player.hasPermission("griefprevention.spam")) { //DAS BOOT! event.setResult(Result.KICK_OTHER); - event.setKickMessage("You must wait " + cooldownRemaining + " more minutes before logging-in again."); + event.setKickMessage("You must wait " + cooldownRemaining + " seconds before logging-in again."); event.disallow(event.getResult(), event.getKickMessage()); return; } @@ -460,15 +460,6 @@ class PlayerEventHandler implements Listener playerData.ipAddress = event.getAddress(); } - //when a player spawns, conditionally apply temporary pvp protection - @EventHandler(ignoreCancelled = true) - void onPlayerRespawn (PlayerRespawnEvent event) - { - PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(event.getPlayer().getUniqueId()); - playerData.lastSpawn = Calendar.getInstance().getTimeInMillis(); - GriefPrevention.instance.checkPvpProtectionNeeded(event.getPlayer()); - } - //when a player successfully joins the server... @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) void onPlayerJoin(PlayerJoinEvent event) @@ -562,6 +553,15 @@ class PlayerEventHandler implements Listener GriefPrevention.cacheUUIDNamePair(player.getUniqueId(), player.getName()); } + //when a player spawns, conditionally apply temporary pvp protection + @EventHandler(ignoreCancelled = true) + void onPlayerRespawn (PlayerRespawnEvent event) + { + PlayerData playerData = GriefPrevention.instance.dataStore.getPlayerData(event.getPlayer().getUniqueId()); + playerData.lastSpawn = Calendar.getInstance().getTimeInMillis(); + GriefPrevention.instance.checkPvpProtectionNeeded(event.getPlayer()); + } + //when a player dies... @EventHandler(priority = EventPriority.LOWEST) void onPlayerDeath(PlayerDeathEvent event)