mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-12-27 19:07:45 +01:00
Permissions support + fix regression at half blocks and stairs
This commit is contained in:
parent
bf07aa16d7
commit
c223358e7d
@ -3,5 +3,5 @@ name: NoCheatPlugin
|
||||
author: Evenprime
|
||||
|
||||
main: cc.co.evenprime.bukkit.nocheat.NoCheatPlugin
|
||||
version: 0.3.5
|
||||
version: 0.4
|
||||
|
||||
|
@ -11,6 +11,10 @@ import org.bukkit.plugin.PluginLoader;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import com.nijikokun.bukkit.Permissions.Permissions;
|
||||
import com.nijiko.permissions.PermissionHandler;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
*
|
||||
* NoCheatPlugin
|
||||
@ -23,6 +27,7 @@ public class NoCheatPlugin extends JavaPlugin {
|
||||
private final NoCheatPluginPlayerListener playerListener = new NoCheatPluginPlayerListener(this);
|
||||
|
||||
public static final Logger log = Logger.getLogger("Minecraft");
|
||||
public static PermissionHandler Permissions = null;
|
||||
|
||||
public NoCheatPlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
|
||||
super(pluginLoader, instance, desc, folder, plugin, cLoader);
|
||||
@ -37,7 +42,24 @@ public class NoCheatPlugin extends JavaPlugin {
|
||||
pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Lowest, this);
|
||||
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Monitor, this);
|
||||
|
||||
|
||||
PluginDescriptionFile pdfFile = this.getDescription();
|
||||
System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
|
||||
log.info( "NoCheat version " + pdfFile.getVersion() + " is enabled!" );
|
||||
|
||||
setupPermissions();
|
||||
}
|
||||
|
||||
public void setupPermissions() {
|
||||
Plugin test = this.getServer().getPluginManager().getPlugin("Permissions");
|
||||
|
||||
|
||||
if(Permissions == null) {
|
||||
if(test != null) {
|
||||
Permissions = ((Permissions)test).getHandler();
|
||||
} else {
|
||||
log.info("Nocheat couldn't find Permissions plugin. Fallback to OP -> all allowed.");
|
||||
this.getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -118,7 +118,7 @@ public class NoCheatPluginPlayerListener extends PlayerListener {
|
||||
types[Material.COBBLESTONE_STAIRS.getId()]= BlockType.UNKNOWN;
|
||||
types[Material.WALL_SIGN.getId()]= BlockType.NONSOLID;
|
||||
types[Material.LEVER.getId()]= BlockType.NONSOLID;
|
||||
types[Material.STONE_PLATE.getId()]= BlockType.NONSOLID;
|
||||
types[Material.STONE_PLATE.getId()]= BlockType.UNKNOWN;
|
||||
types[Material.IRON_DOOR_BLOCK.getId()]= BlockType.NONSOLID;
|
||||
types[Material.WOOD_PLATE.getId()]= BlockType.NONSOLID;
|
||||
types[Material.REDSTONE_ORE.getId()]= BlockType.SOLID;
|
||||
@ -178,8 +178,7 @@ public class NoCheatPluginPlayerListener extends PlayerListener {
|
||||
|
||||
// If someone cancelled the event already, ignore it
|
||||
// If the player is inside a vehicle, ignore it for now
|
||||
// If the player is OP, ignore it for now
|
||||
if(event.isCancelled() || event.getPlayer().isInsideVehicle() || event.getPlayer().isOp()) {
|
||||
if(event.isCancelled() || event.getPlayer().isInsideVehicle()) {
|
||||
data.phase = 0;
|
||||
return;
|
||||
}
|
||||
@ -192,6 +191,16 @@ public class NoCheatPluginPlayerListener extends PlayerListener {
|
||||
// Get the time of the server
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
boolean allowSpeedhack = false;
|
||||
if(NoCheatPlugin.Permissions != null && !NoCheatPlugin.Permissions.has(event.getPlayer(), "nocheat.speedhack")) {
|
||||
allowSpeedhack = true;
|
||||
}
|
||||
else if(NoCheatPlugin.Permissions == null && event.getPlayer().isOp() ) {
|
||||
allowSpeedhack = true;
|
||||
}
|
||||
|
||||
if(!allowSpeedhack){
|
||||
|
||||
// Is it time for a speedhack check now?
|
||||
if(time > timeFrameForSpeedHackCheck + data.lastSpeedHackCheck ) {
|
||||
// Yes
|
||||
@ -209,8 +218,17 @@ public class NoCheatPluginPlayerListener extends PlayerListener {
|
||||
}
|
||||
|
||||
data.eventsSinceLastSpeedHackCheck++;
|
||||
}
|
||||
|
||||
boolean allowMoving = false;
|
||||
if(NoCheatPlugin.Permissions != null && !NoCheatPlugin.Permissions.has(event.getPlayer(), "nocheat.moving")) {
|
||||
allowMoving = true;
|
||||
}
|
||||
else if(NoCheatPlugin.Permissions == null && event.getPlayer().isOp() ) {
|
||||
allowMoving = true;
|
||||
}
|
||||
|
||||
if(!allowMoving){
|
||||
// First check the distance the player has moved horizontally
|
||||
// TODO: Make this check much more precise
|
||||
if(!event.isCancelled()) {
|
||||
@ -291,9 +309,6 @@ public class NoCheatPluginPlayerListener extends PlayerListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Teleport the player back to the last valid position
|
||||
*/
|
||||
if(event.isCancelled() && !data.lastWasInvalid) {
|
||||
// Keep count of violations
|
||||
data.violations++;
|
||||
@ -310,7 +325,9 @@ public class NoCheatPluginPlayerListener extends PlayerListener {
|
||||
|
||||
// To prevent players from getting stuck in an infinite loop, needs probably more testing
|
||||
// TODO: Find a better solution
|
||||
if(data.phase > 6) data.phase = 6;
|
||||
if(data.phase > 4) {
|
||||
data.phase = 4;
|
||||
}
|
||||
}
|
||||
else if(event.isCancelled() && data.lastWasInvalid) {
|
||||
data.violations++;
|
||||
@ -324,6 +341,7 @@ public class NoCheatPluginPlayerListener extends PlayerListener {
|
||||
NoCheatPlugin.log.info("NoCheatPlugin: "+event.getPlayer().getDisplayName()+" stopped violating constraints. Total Violations: "+data.violations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the four edges of the player's approximated Bounding Box for blocks or ladders,
|
||||
@ -346,19 +364,25 @@ public class NoCheatPluginPlayerListener extends PlayerListener {
|
||||
// Check the blocks below the player. If they aren't not solid (sic!) and the blocks directly above
|
||||
// them aren't solid, The player is considered to be standing on the lower block
|
||||
// Plus the player can hang onto a ladder that is one field above him
|
||||
if( (types[w.getBlockTypeIdAt(values[0], values[2]-1, values[3])] != BlockType.NONSOLID &&
|
||||
if( ((types[w.getBlockTypeIdAt(values[0], values[2]-1, values[3])] != BlockType.NONSOLID &&
|
||||
types[w.getBlockTypeIdAt(values[0], values[2], values[3])] != BlockType.SOLID) ||
|
||||
(types[w.getBlockTypeIdAt(values[1], values[2]-1, values[3])] != BlockType.NONSOLID &&
|
||||
types[w.getBlockTypeIdAt(values[0], values[2], values[3])] == BlockType.UNKNOWN) ||
|
||||
((types[w.getBlockTypeIdAt(values[1], values[2]-1, values[3])] != BlockType.NONSOLID &&
|
||||
types[w.getBlockTypeIdAt(values[1], values[2], values[3])] != BlockType.SOLID) ||
|
||||
(types[w.getBlockTypeIdAt(values[0], values[2]-1, values[4])] != BlockType.NONSOLID &&
|
||||
types[w.getBlockTypeIdAt(values[1], values[2], values[3])] == BlockType.UNKNOWN) ||
|
||||
((types[w.getBlockTypeIdAt(values[0], values[2]-1, values[4])] != BlockType.NONSOLID &&
|
||||
types[w.getBlockTypeIdAt(values[0], values[2], values[4])] != BlockType.SOLID) ||
|
||||
(types[w.getBlockTypeIdAt(values[1], values[2]-1, values[4])] != BlockType.NONSOLID &&
|
||||
types[w.getBlockTypeIdAt(values[0], values[2], values[4])] == BlockType.UNKNOWN) ||
|
||||
((types[w.getBlockTypeIdAt(values[1], values[2]-1, values[4])] != BlockType.NONSOLID &&
|
||||
types[w.getBlockTypeIdAt(values[1], values[2], values[4])] != BlockType.SOLID) ||
|
||||
types[w.getBlockTypeIdAt(values[1], values[2], values[4])] == BlockType.UNKNOWN) ||
|
||||
(types[w.getBlockTypeIdAt(values[0], values[2]+1, values[3])] == BlockType.LADDER ||
|
||||
types[w.getBlockTypeIdAt(values[0], values[2]+1, values[4])] == BlockType.LADDER ||
|
||||
types[w.getBlockTypeIdAt(values[1], values[2]+1, values[3])] == BlockType.LADDER ||
|
||||
types[w.getBlockTypeIdAt(values[1], values[2]+1, values[4])] == BlockType.LADDER))
|
||||
types[w.getBlockTypeIdAt(values[1], values[2]+1, values[4])] == BlockType.LADDER)) {
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user