mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-12-28 03:17:53 +01:00
More stuff for infinitedurability check: cancel using of items, choose
if to log or not. Only log once every 5 seconds.
This commit is contained in:
parent
c207f6ce94
commit
0284f5be3f
@ -3,7 +3,7 @@ name: NoCheat
|
||||
author: Evenprime
|
||||
|
||||
main: cc.co.evenprime.bukkit.nocheat.NoCheat
|
||||
version: 1.14a
|
||||
version: 1.14b
|
||||
|
||||
softdepend: [ Permissions, CraftIRC ]
|
||||
|
||||
|
@ -8,6 +8,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.data.AirbuildData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.InfinitedurabilityData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.NoCheatData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.NukeData;
|
||||
@ -119,6 +120,18 @@ public class DataManager {
|
||||
|
||||
return data.speedhack;
|
||||
}
|
||||
|
||||
|
||||
public InfinitedurabilityData getInfiniteData(Player p) {
|
||||
|
||||
NoCheatData data = getPlayerData(p);
|
||||
|
||||
if(data.infinite == null) {
|
||||
data.infinite = new InfinitedurabilityData();
|
||||
}
|
||||
|
||||
return data.infinite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Go through the playerData HashMap and remove players that are no longer
|
||||
|
@ -7,12 +7,14 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.ConfigurationException;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.NoCheatConfiguration;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.InfinitedurabilityData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
|
||||
import cc.co.evenprime.bukkit.nocheat.listeners.InfinitedurabilityListener;
|
||||
|
||||
@ -20,7 +22,9 @@ public class InfinitedurabilityCheck extends Check {
|
||||
|
||||
private String logMessage;
|
||||
private String kickMessage;
|
||||
private boolean log;
|
||||
private boolean kick;
|
||||
private boolean cancel;
|
||||
|
||||
public InfinitedurabilityCheck(NoCheat plugin, NoCheatConfiguration config) {
|
||||
super(plugin, "infinitedurability", PermissionData.PERMISSION_INFINITEDURABILITY, config);
|
||||
@ -30,21 +34,59 @@ public class InfinitedurabilityCheck extends Check {
|
||||
|
||||
if(skipCheck(event.getPlayer()))
|
||||
return;
|
||||
|
||||
|
||||
if(event.getNewSlot() == 9) {
|
||||
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
String logString = String.format(logMessage, player.getName());
|
||||
plugin.log(Level.SEVERE, logString);
|
||||
|
||||
|
||||
if(log) {
|
||||
InfinitedurabilityData data = plugin.getDataManager().getInfiniteData(player);
|
||||
long thisTime = System.currentTimeMillis();
|
||||
if(data.lastLog + 5000 < thisTime) {
|
||||
data.lastLog = thisTime;
|
||||
|
||||
String logString = String.format(logMessage, player.getName());
|
||||
plugin.log(Level.SEVERE, logString);
|
||||
}
|
||||
}
|
||||
|
||||
if(kick) {
|
||||
player.kickPlayer(kickMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void check(PlayerInteractEvent event) {
|
||||
if(skipCheck(event.getPlayer()))
|
||||
return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(player.getInventory().getHeldItemSlot() == 9) {
|
||||
|
||||
if(log) {
|
||||
InfinitedurabilityData data = plugin.getDataManager().getInfiniteData(player);
|
||||
long thisTime = System.currentTimeMillis();
|
||||
|
||||
if(data.lastLog + 5000 < thisTime) {
|
||||
data.lastLog = thisTime;
|
||||
|
||||
String logString = String.format(logMessage, player.getName());
|
||||
plugin.log(Level.SEVERE, logString);
|
||||
}
|
||||
}
|
||||
|
||||
if(kick) {
|
||||
player.kickPlayer(kickMessage);
|
||||
}
|
||||
|
||||
if(cancel) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure(NoCheatConfiguration config) {
|
||||
|
||||
@ -54,8 +96,10 @@ public class InfinitedurabilityCheck extends Check {
|
||||
logMessage = logMessage.replace("[player]", "%1$s");
|
||||
|
||||
kickMessage = config.getStringValue("infinitedurability.kickmessage");
|
||||
|
||||
|
||||
log = config.getBooleanValue("infinitedurability.log");
|
||||
kick = config.getBooleanValue("infinitedurability.kick");
|
||||
cancel = config.getBooleanValue("infinitedurability.cancel");
|
||||
} catch(ConfigurationException e) {
|
||||
setActive(false);
|
||||
e.printStackTrace();
|
||||
@ -71,5 +115,7 @@ public class InfinitedurabilityCheck extends Check {
|
||||
|
||||
// Register listeners for itemdupe check
|
||||
pm.registerEvent(Event.Type.PLAYER_ITEM_HELD, bogusitemsPlayerListener, Priority.Lowest, plugin);
|
||||
pm.registerEvent(Event.Type.PLAYER_INTERACT, bogusitemsPlayerListener, Priority.Lowest, plugin);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -228,7 +228,9 @@ public class NoCheatConfiguration {
|
||||
nukeNode.add(new BooleanOption("checkops", SimpleYaml.getBoolean("infinitedurability.checkops", false, yamlContent)));
|
||||
nukeNode.add(new LongStringOption("logmessage", SimpleYaml.getString("infinitedurability.logmessage", "InfDur: [player] tries to use an infinite durability hack", yamlContent)));
|
||||
nukeNode.add(new LongStringOption("kickmessage", SimpleYaml.getString("infinitedurability.kickmessage", "No infinite durability hacks allowed", yamlContent)));
|
||||
nukeNode.add(new BooleanOption("log", SimpleYaml.getBoolean("infinitedurability.log", true, yamlContent)));
|
||||
nukeNode.add(new BooleanOption("kick", SimpleYaml.getBoolean("infinitedurability.kick", true, yamlContent)));
|
||||
nukeNode.add(new BooleanOption("cancel", SimpleYaml.getBoolean("infinitedurability.cancel", true, yamlContent)));
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.data;
|
||||
|
||||
|
||||
public class InfinitedurabilityData {
|
||||
|
||||
public long lastLog = 0;
|
||||
}
|
@ -18,6 +18,8 @@ public class NoCheatData {
|
||||
|
||||
public PermissionData permission;
|
||||
public NukeData nuke;
|
||||
|
||||
public InfinitedurabilityData infinite;
|
||||
|
||||
public NoCheatData() {}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.listeners;
|
||||
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
|
||||
@ -18,4 +19,9 @@ public class InfinitedurabilityListener extends PlayerListener {
|
||||
public void onItemHeldChange(PlayerItemHeldEvent event) {
|
||||
check.check(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
check.check(event);
|
||||
}
|
||||
}
|
||||
|
@ -216,6 +216,8 @@ public class Explainations {
|
||||
set("infinitedurability.kick", "Kick the player if hacking. Please not that if you decide to not kick players,\n" +
|
||||
"the log message about hacking will only appear once, not every time they use the infinite durability\n" +
|
||||
"item. It is strongly recommended to kick the players!");
|
||||
set("infinitedurability.log", "Log a message in case of violations.");
|
||||
set("infinitedurability.cancel", "Prevent using of items with infinite durability.");
|
||||
}
|
||||
|
||||
private static void set(String id, String text) {
|
||||
|
Loading…
Reference in New Issue
Block a user