New setting "handleExploitInteractionSpam" (defaults to true). If enabled, players will begin to take injury if they rapidly try interacting with anything in another faction's territory. This is to prevent people from spam-clicking on doors and chests and such in the hopes that they'll get one through. After 10 rapid interaction attempts in a row, every click will cause them damage; the damage amount is a half heart of damage for every 10 clicks (up to 1 heart at 20 clicks, 1.5 hearts at 30, etc.). After the player has stopped trying for 2 seconds, their failed interaction counter will reset.

Also removed our old workaround fix code for the bug where half-step placement wasn't detected, since the Bukkit team fixed that in 1.1-R4.
This commit is contained in:
Brettflan 2012-03-19 07:59:41 -05:00
parent 8f2e587eb9
commit 8333354926
2 changed files with 43 additions and 20 deletions

View File

@ -105,6 +105,7 @@ public class Conf
// prevent some potential exploits // prevent some potential exploits
public static boolean handleExploitObsidianGenerators = true; public static boolean handleExploitObsidianGenerators = true;
public static boolean handleExploitEnderPearlClipping = true; public static boolean handleExploitEnderPearlClipping = true;
public static boolean handleExploitInteractionSpam = true;
public static boolean homesEnabled = true; public static boolean homesEnabled = true;
public static boolean homesMustBeInClaimedTerritory = true; public static boolean homesMustBeInClaimedTerritory = true;

View File

@ -1,11 +1,12 @@
package com.massivecraft.factions.listeners; package com.massivecraft.factions.listeners;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -20,6 +21,7 @@ import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPreLoginEvent; import org.bukkit.event.player.PlayerPreLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.util.NumberConversions;
import com.massivecraft.factions.Board; import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
@ -129,6 +131,23 @@ public class FactionsPlayerListener implements Listener
if ( ! canPlayerUseBlock(player, block, false)) if ( ! canPlayerUseBlock(player, block, false))
{ {
event.setCancelled(true); event.setCancelled(true);
if (Conf.handleExploitInteractionSpam)
{
String name = player.getName();
InteractAttemptSpam attempt = interactSpammers.get(name);
if (attempt == null)
{
attempt = new InteractAttemptSpam();
interactSpammers.put(name, attempt);
}
int count = attempt.increment();
if (count >= 10)
{
FPlayer me = FPlayers.i.get(name);
me.msg("<b>Ouch, that is starting to hurt. You should give it a rest.");
player.damage(NumberConversions.floor((double)count / 10));
}
}
return; return;
} }
@ -137,25 +156,6 @@ public class FactionsPlayerListener implements Listener
return; // only interested on right-clicks for below return; // only interested on right-clicks for below
} }
// workaround fix for new CraftBukkit 1.1-R1 bug where half-step on half-step placement doesn't trigger BlockPlaceEvent
if (
event.hasItem()
&&
event.getItem().getType() == Material.STEP
&&
block.getType() == Material.STEP
&&
event.getBlockFace() == BlockFace.UP
&&
event.getItem().getData().getData() == block.getData()
&&
! FactionsBlockListener.playerCanBuildDestroyBlock(player, block, "build", false)
)
{
event.setCancelled(true);
return;
}
if ( ! playerCanUseItemHere(player, block.getLocation(), event.getMaterial(), false)) if ( ! playerCanUseItemHere(player, block.getLocation(), event.getMaterial(), false))
{ {
event.setCancelled(true); event.setCancelled(true);
@ -163,6 +163,28 @@ public class FactionsPlayerListener implements Listener
} }
} }
// for handling people who repeatedly spam attempts to open a door (or similar) in another faction's territory
private Map<String, InteractAttemptSpam> interactSpammers = new HashMap<String, InteractAttemptSpam>();
private static class InteractAttemptSpam
{
private int attempts = 0;
private long lastAttempt = System.currentTimeMillis();
// returns the current attempt count
public int increment()
{
long Now = System.currentTimeMillis();
if (Now > lastAttempt + 2000)
attempts = 1;
else
attempts++;
lastAttempt = Now;
return attempts;
}
}
// TODO: Refactor ! justCheck -> to informIfNot // TODO: Refactor ! justCheck -> to informIfNot
// TODO: Possibly incorporate pain build... // TODO: Possibly incorporate pain build...
public static boolean playerCanUseItemHere(Player player, Location loc, Material material, boolean justCheck) public static boolean playerCanUseItemHere(Player player, Location loc, Material material, boolean justCheck)