From 272c35cda6601bdb24413b3ec5cc955a19f2d900 Mon Sep 17 00:00:00 2001 From: drtshock Date: Thu, 9 Oct 2014 11:04:11 -0500 Subject: [PATCH] Add cooldown for auto showing f map to players. Fixes issue #64. --- pom.xml | 10 ++++----- .../com/massivecraft/factions/FPlayer.java | 7 +++--- .../listeners/FactionsPlayerListener.java | 22 +++++++++++-------- src/main/resources/config.yml | 8 +++++++ 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index 05c805c1..d83e71a1 100644 --- a/pom.xml +++ b/pom.xml @@ -50,9 +50,9 @@ 1.7.10-R0.1-SNAPSHOT - net.daboross.vault - vault-api - 1.3.01 + net.milkbowl.vault + VaultAPI + 1.4 provided @@ -81,8 +81,8 @@ - repo-daboross-net - http://repo.daboross.net/ + vault-repo + http://nexus.theyeticave.net/content/repositories/pub_releases ess-repo diff --git a/src/main/java/com/massivecraft/factions/FPlayer.java b/src/main/java/com/massivecraft/factions/FPlayer.java index 5a360c27..a506daa1 100644 --- a/src/main/java/com/massivecraft/factions/FPlayer.java +++ b/src/main/java/com/massivecraft/factions/FPlayer.java @@ -542,10 +542,9 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator { // Shows them the scoreboard instead of sending a message in chat. Will disappear after a few seconds. new FInfoBoard(getPlayer(), toShow, true); } else { - Faction factionHere = Board.getFactionAt(this.getLastStoodAt()); - String msg = P.p.txt.parse("") + " ~ " + factionHere.getTag(this); - if (factionHere.getDescription().length() > 0) { - msg += " - " + factionHere.getDescription(); + String msg = P.p.txt.parse("") + " ~ " + toShow.getTag(this); + if (toShow.getDescription().length() > 0) { + msg += " - " + toShow.getDescription(); } this.sendMessage(msg); } diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 0b7ce8fe..0102b49f 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -16,9 +16,8 @@ import org.bukkit.event.block.Action; import org.bukkit.event.player.*; import org.bukkit.util.NumberConversions; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; +import java.util.*; +import java.util.logging.Level; public class FactionsPlayerListener implements Listener { @@ -56,6 +55,9 @@ public class FactionsPlayerListener implements Listener { } } + // Holds the next time a player can have a map shown. + private HashMap showTimes = new HashMap(); + @EventHandler(priority = EventPriority.MONITOR) public void onPlayerMove(PlayerMoveEvent event) { if (event.isCancelled()) { @@ -87,13 +89,15 @@ public class FactionsPlayerListener implements Listener { Faction factionTo = Board.getFactionAt(to); boolean changedFaction = (factionFrom != factionTo); - /* Was used for displaying on Spout but we removed Spout compatibility. - if (changedFaction) - changedFaction = false; - */ - if (me.isMapAutoUpdating()) { - me.sendMessage(Board.getMap(me.getFaction(), to, player.getLocation().getYaw())); + if(showTimes.containsKey(player.getUniqueId()) && (showTimes.get(player.getUniqueId()) > System.currentTimeMillis())) { + if(P.p.getConfig().getBoolean("findfactionsexploit.log", false)) { + P.p.log(Level.WARNING, "%s tried to show a faction map too soon and triggered exploit blocker.", player.getName()); + } + } else { + me.sendMessage(Board.getMap(me.getFaction(), to, player.getLocation().getYaw())); + showTimes.put(player.getUniqueId(), System.currentTimeMillis() + P.p.getConfig().getLong("findfactionsexploit.cooldown", 2000)); + } } else { Faction myFaction = me.getFaction(); String ownersTo = myFaction.getOwnerListString(to); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 07237a89..0cd8fae3 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -10,6 +10,14 @@ # It's suggested that you only turn this on at the direction of a developer. debug: false +# Prevent find factions exploit +# This will help limit how many times a player can be sent a map of factions. +# Set this to the cooldown you want, in miliseconds, for a map to be shown to a player. +# If you want to log when a player violates this (only happens on chunk enter so it shouldn't be too spammy), +# set log to true and it will be logged to console as "player tried to show a faction map too soon and triggered exploit blocker." +findfactionsexploit: + cooldown: 2000 # in miliseconds. 2000 = 2 seconds. + log: false # Configuration section for Scoreboards # This will allow you to completely customize how your scoreboards look.