mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-01 13:27:44 +01:00
Removed no longer needed workarounds + lots of code formatting
This commit is contained in:
parent
33e9c46716
commit
7e0721da98
@ -3,7 +3,7 @@ name: NoCheat
|
|||||||
author: Evenprime
|
author: Evenprime
|
||||||
|
|
||||||
main: cc.co.evenprime.bukkit.nocheat.NoCheat
|
main: cc.co.evenprime.bukkit.nocheat.NoCheat
|
||||||
version: 1.12
|
version: 1.12a
|
||||||
|
|
||||||
softdepend: [ Permissions, CraftIRC ]
|
softdepend: [ Permissions, CraftIRC ]
|
||||||
|
|
||||||
|
@ -42,8 +42,7 @@ public class CustomCommandSender implements CommandSender {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PermissionAttachment addAttachment(Plugin plugin, String name,
|
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
|
||||||
boolean value) {
|
|
||||||
// Whatever it is, I don't care
|
// Whatever it is, I don't care
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -55,8 +54,7 @@ public class CustomCommandSender implements CommandSender {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PermissionAttachment addAttachment(Plugin plugin, String name,
|
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
|
||||||
boolean value, int ticks) {
|
|
||||||
// Whatever it is, I don't care
|
// Whatever it is, I don't care
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -14,24 +14,25 @@ import cc.co.evenprime.bukkit.nocheat.data.NukeData;
|
|||||||
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
|
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
|
||||||
import cc.co.evenprime.bukkit.nocheat.data.SpeedhackData;
|
import cc.co.evenprime.bukkit.nocheat.data.SpeedhackData;
|
||||||
|
|
||||||
|
|
||||||
public class DataManager {
|
public class DataManager {
|
||||||
|
|
||||||
// Store data between Events
|
// Store data between Events
|
||||||
private final Map<Player, NoCheatData> playerData = new HashMap<Player, NoCheatData>();
|
private final Map<Player, NoCheatData> playerData = new HashMap<Player, NoCheatData>();
|
||||||
|
|
||||||
public DataManager() { }
|
public DataManager() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Go through the playerData HashMap and remove players that are no longer online
|
* Go through the playerData HashMap and remove players that are no longer
|
||||||
* from the map. This should be called in long, regular intervals (e.g. every 10 minutes)
|
* online
|
||||||
|
* from the map. This should be called in long, regular intervals (e.g.
|
||||||
|
* every 10 minutes)
|
||||||
* to keep the memory footprint of the plugin low
|
* to keep the memory footprint of the plugin low
|
||||||
*/
|
*/
|
||||||
public void cleanPlayerDataCollection() {
|
public void cleanPlayerDataCollection() {
|
||||||
synchronized(playerData) {
|
synchronized(playerData) {
|
||||||
Iterator<Map.Entry<Player, NoCheatData>> it = playerData.entrySet().iterator();
|
Iterator<Map.Entry<Player, NoCheatData>> it = playerData.entrySet().iterator();
|
||||||
while (it.hasNext()) {
|
while(it.hasNext()) {
|
||||||
Map.Entry<Player, NoCheatData> pairs = (Map.Entry<Player, NoCheatData>)it.next();
|
Map.Entry<Player, NoCheatData> pairs = (Map.Entry<Player, NoCheatData>) it.next();
|
||||||
if(!pairs.getKey().isOnline()) {
|
if(!pairs.getKey().isOnline()) {
|
||||||
// Cancel all referenced tasks before removing the entry
|
// Cancel all referenced tasks before removing the entry
|
||||||
cancelTasks(pairs.getValue());
|
cancelTasks(pairs.getValue());
|
||||||
@ -42,7 +43,6 @@ public class DataManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main access to data that needs to be stored between different events.
|
* Main access to data that needs to be stored between different events.
|
||||||
* Always returns a NoCheatData object, because if there isn't one
|
* Always returns a NoCheatData object, because if there isn't one
|
||||||
@ -51,7 +51,7 @@ public class DataManager {
|
|||||||
* @param p
|
* @param p
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public NoCheatData getPlayerData(Player p) {
|
private NoCheatData getPlayerData(final Player p) {
|
||||||
NoCheatData data = playerData.get(p);
|
NoCheatData data = playerData.get(p);
|
||||||
|
|
||||||
if(data == null) {
|
if(data == null) {
|
||||||
@ -82,7 +82,6 @@ public class DataManager {
|
|||||||
|
|
||||||
if(data.moving == null) {
|
if(data.moving == null) {
|
||||||
data.moving = new MovingData();
|
data.moving = new MovingData();
|
||||||
data.moving.teleportedTo = p.getLocation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return data.moving;
|
return data.moving;
|
||||||
@ -121,16 +120,17 @@ public class DataManager {
|
|||||||
return data.speedhack;
|
return data.speedhack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Go through the playerData HashMap and remove players that are no longer online
|
* Go through the playerData HashMap and remove players that are no longer
|
||||||
* from the map. This should be called in long, regular intervals (e.g. every 10 minutes)
|
* online
|
||||||
|
* from the map. This should be called in long, regular intervals (e.g.
|
||||||
|
* every 10 minutes)
|
||||||
* to keep the memory footprint of the plugin low
|
* to keep the memory footprint of the plugin low
|
||||||
*/
|
*/
|
||||||
public void cancelPlayerDataTasks() {
|
public void cancelPlayerDataTasks() {
|
||||||
synchronized(playerData) {
|
synchronized(playerData) {
|
||||||
Iterator<Map.Entry<Player, NoCheatData>> it = playerData.entrySet().iterator();
|
Iterator<Map.Entry<Player, NoCheatData>> it = playerData.entrySet().iterator();
|
||||||
while (it.hasNext()) {
|
while(it.hasNext()) {
|
||||||
cancelTasks(it.next().getValue());
|
cancelTasks(it.next().getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,8 +145,7 @@ public class DataManager {
|
|||||||
|
|
||||||
if(id != -1) {
|
if(id != -1) {
|
||||||
Bukkit.getServer().getScheduler().cancelTask(id);
|
Bukkit.getServer().getScheduler().cancelTask(id);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// To prevent accidentially creating a new one while cleaning up
|
// To prevent accidentially creating a new one while cleaning up
|
||||||
d.summaryTask = 1;
|
d.summaryTask = 1;
|
||||||
}
|
}
|
||||||
@ -159,8 +158,7 @@ public class DataManager {
|
|||||||
|
|
||||||
if(id != -1) {
|
if(id != -1) {
|
||||||
Bukkit.getServer().getScheduler().cancelTask(id);
|
Bukkit.getServer().getScheduler().cancelTask(id);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// To prevent accidentially creating a new one while cleaning up
|
// To prevent accidentially creating a new one while cleaning up
|
||||||
d2.summaryTask = 1;
|
d2.summaryTask = 1;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import java.util.logging.Formatter;
|
|||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
|
|
||||||
public class LogFileFormatter extends Formatter {
|
public class LogFileFormatter extends Formatter {
|
||||||
|
|
||||||
private final SimpleDateFormat date;
|
private final SimpleDateFormat date;
|
||||||
|
|
||||||
public LogFileFormatter() {
|
public LogFileFormatter() {
|
||||||
@ -25,7 +26,7 @@ public class LogFileFormatter extends Formatter {
|
|||||||
builder.append(record.getMessage());
|
builder.append(record.getMessage());
|
||||||
builder.append('\n');
|
builder.append('\n');
|
||||||
|
|
||||||
if (ex != null) {
|
if(ex != null) {
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
ex.printStackTrace(new PrintWriter(writer));
|
ex.printStackTrace(new PrintWriter(writer));
|
||||||
builder.append(writer);
|
builder.append(writer);
|
||||||
|
@ -323,7 +323,9 @@ public class NoCheat extends JavaPlugin {
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(useNewPermissionSystem) {
|
if(useNewPermissionSystem) {
|
||||||
//System.out.println("New permissions system asked for " + PermissionData.permissionNames[permission] + " got " + player.hasPermission(PermissionData.permissionNames[permission]));
|
// System.out.println("New permissions system asked for " +
|
||||||
|
// PermissionData.permissionNames[permission] + " got " +
|
||||||
|
// player.hasPermission(PermissionData.permissionNames[permission]));
|
||||||
return player.hasPermission(PermissionData.permissionNames[permission]);
|
return player.hasPermission(PermissionData.permissionNames[permission]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,9 @@ public class CancelAction extends Action {
|
|||||||
|
|
||||||
public final static CancelAction cancel = new CancelAction();
|
public final static CancelAction cancel = new CancelAction();
|
||||||
|
|
||||||
private CancelAction() { super(1, true); }
|
private CancelAction() {
|
||||||
|
super(1, true);
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "cancel";
|
return "cancel";
|
||||||
|
@ -22,12 +22,10 @@ public class CustomAction extends Action {
|
|||||||
public String getValue() {
|
public String getValue() {
|
||||||
if(firstAfter <= 1 && repeat) {
|
if(firstAfter <= 1 && repeat) {
|
||||||
return command;
|
return command;
|
||||||
}
|
} else if(repeat) {
|
||||||
else if(repeat) {
|
return "[" + firstAfter + "] " + command;
|
||||||
return "["+firstAfter+"] "+ command;
|
} else {
|
||||||
}
|
return "[" + firstAfter + "," + repeat + "] " + command;
|
||||||
else {
|
|
||||||
return "["+firstAfter+","+repeat+"] "+ command;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ public class LogAction extends Action {
|
|||||||
public final static LogAction logmed = new LogAction(1, false, Level.WARNING);
|
public final static LogAction logmed = new LogAction(1, false, Level.WARNING);
|
||||||
public final static LogAction loghigh = new LogAction(1, false, Level.SEVERE);
|
public final static LogAction loghigh = new LogAction(1, false, Level.SEVERE);
|
||||||
|
|
||||||
public final static LogAction[] log = { loglow, logmed, loghigh };
|
public final static LogAction[] log = {loglow, logmed, loghigh};
|
||||||
|
|
||||||
private LogAction(int firstAfter, boolean repeat, Level level) {
|
private LogAction(int firstAfter, boolean repeat, Level level) {
|
||||||
super(firstAfter, repeat);
|
super(firstAfter, repeat);
|
||||||
|
@ -20,9 +20,9 @@ import cc.co.evenprime.bukkit.nocheat.data.AirbuildData;
|
|||||||
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
|
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
|
||||||
import cc.co.evenprime.bukkit.nocheat.listeners.AirbuildBlockListener;
|
import cc.co.evenprime.bukkit.nocheat.listeners.AirbuildBlockListener;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the player tries to place blocks in midair (which shouldn't be possible)
|
* Check if the player tries to place blocks in midair (which shouldn't be
|
||||||
|
* possible)
|
||||||
*
|
*
|
||||||
* @author Evenprime
|
* @author Evenprime
|
||||||
*
|
*
|
||||||
@ -41,10 +41,11 @@ public class AirbuildCheck extends Check {
|
|||||||
public void check(BlockPlaceEvent event) {
|
public void check(BlockPlaceEvent event) {
|
||||||
|
|
||||||
// Should we check at all?
|
// Should we check at all?
|
||||||
if(skipCheck(event.getPlayer())) return;
|
if(skipCheck(event.getPlayer()))
|
||||||
|
return;
|
||||||
|
|
||||||
// Are all 6 sides "air-blocks" -> cancel the event
|
// Are all 6 sides "air-blocks" -> cancel the event
|
||||||
if( event.getBlockAgainst().getType() == Material.AIR && event.getBlockPlaced().getType() != Material.AIR ) {
|
if(event.getBlockAgainst().getType() == Material.AIR && event.getBlockPlaced().getType() != Material.AIR) {
|
||||||
final AirbuildData data = plugin.getDataManager().getAirbuildData(event.getPlayer());
|
final AirbuildData data = plugin.getDataManager().getAirbuildData(event.getPlayer());
|
||||||
final Player p = event.getPlayer();
|
final Player p = event.getPlayer();
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ public class AirbuildCheck extends Check {
|
|||||||
summary(p, data);
|
summary(p, data);
|
||||||
// deleting its own reference
|
// deleting its own reference
|
||||||
data.summaryTask = -1;
|
data.summaryTask = -1;
|
||||||
}catch(Exception e) {}
|
} catch(Exception e) {}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -68,9 +69,9 @@ public class AirbuildCheck extends Check {
|
|||||||
data.perFiveSeconds++;
|
data.perFiveSeconds++;
|
||||||
|
|
||||||
// which limit has been reached
|
// which limit has been reached
|
||||||
for(int i = limits.length-1; i >= 0; i--) {
|
for(int i = limits.length - 1; i >= 0; i--) {
|
||||||
if(data.perFiveSeconds >= limits[i]) {
|
if(data.perFiveSeconds >= limits[i]) {
|
||||||
action(actions[i], event, data.perFiveSeconds - limits[i]+1);
|
action(actions[i], event, data.perFiveSeconds - limits[i] + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,7 +80,8 @@ public class AirbuildCheck extends Check {
|
|||||||
|
|
||||||
private void action(Action actions[], BlockPlaceEvent event, int violations) {
|
private void action(Action actions[], BlockPlaceEvent event, int violations) {
|
||||||
|
|
||||||
if(actions == null) return;
|
if(actions == null)
|
||||||
|
return;
|
||||||
|
|
||||||
// Execute actions in order
|
// Execute actions in order
|
||||||
for(Action a : actions) {
|
for(Action a : actions) {
|
||||||
@ -87,14 +89,12 @@ public class AirbuildCheck extends Check {
|
|||||||
if(a.firstAfter == violations || a.repeat) {
|
if(a.firstAfter == violations || a.repeat) {
|
||||||
if(a instanceof LogAction) {
|
if(a instanceof LogAction) {
|
||||||
final Location l = event.getBlockPlaced().getLocation();
|
final Location l = event.getBlockPlaced().getLocation();
|
||||||
String logMessage = "Airbuild: "+event.getPlayer().getName()+" tried to place block " + event.getBlockPlaced().getType() + " in the air at " + l.getBlockX() + "," + l.getBlockY() +"," + l.getBlockZ();
|
String logMessage = "Airbuild: " + event.getPlayer().getName() + " tried to place block " + event.getBlockPlaced().getType() + " in the air at " + l.getBlockX() + "," + l.getBlockY() + "," + l.getBlockZ();
|
||||||
plugin.log(((LogAction)a).level, logMessage);
|
plugin.log(((LogAction) a).level, logMessage);
|
||||||
}
|
} else if(a instanceof CancelAction) {
|
||||||
else if(a instanceof CancelAction) {
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
} else if(a instanceof CustomAction) {
|
||||||
else if(a instanceof CustomAction) {
|
plugin.handleCustomAction((CustomAction) a, event.getPlayer());
|
||||||
plugin.handleCustomAction((CustomAction)a, event.getPlayer());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,10 +103,11 @@ public class AirbuildCheck extends Check {
|
|||||||
|
|
||||||
private void summary(Player player, AirbuildData data) {
|
private void summary(Player player, AirbuildData data) {
|
||||||
|
|
||||||
// Give a summary according to the highest violation level we encountered in that second
|
// Give a summary according to the highest violation level we
|
||||||
for(int i = limits.length-1; i >= 0; i--) {
|
// encountered in that second
|
||||||
|
for(int i = limits.length - 1; i >= 0; i--) {
|
||||||
if(data.perFiveSeconds >= limits[i]) {
|
if(data.perFiveSeconds >= limits[i]) {
|
||||||
plugin.log(LogAction.log[i].level, "Airbuild summary: " +player.getName() + " total violations per 5 seconds: " + data.perFiveSeconds);
|
plugin.log(LogAction.log[i].level, "Airbuild summary: " + player.getName() + " total violations per 5 seconds: " + data.perFiveSeconds);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,7 +133,7 @@ public class AirbuildCheck extends Check {
|
|||||||
|
|
||||||
setActive(config.getBooleanValue("active.airbuild"));
|
setActive(config.getBooleanValue("active.airbuild"));
|
||||||
|
|
||||||
} catch (ConfigurationException e) {
|
} catch(ConfigurationException e) {
|
||||||
setActive(false);
|
setActive(false);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -23,14 +23,15 @@ import cc.co.evenprime.bukkit.nocheat.listeners.BogusitemsPlayerListener;
|
|||||||
|
|
||||||
public class BogusitemsCheck extends Check {
|
public class BogusitemsCheck extends Check {
|
||||||
|
|
||||||
public BogusitemsCheck(NoCheat plugin, NoCheatConfiguration config){
|
public BogusitemsCheck(NoCheat plugin, NoCheatConfiguration config) {
|
||||||
super(plugin, "bogusitems", PermissionData.PERMISSION_BOGUSITEMS, config);
|
super(plugin, "bogusitems", PermissionData.PERMISSION_BOGUSITEMS, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void check(PlayerPickupItemEvent event) {
|
public void check(PlayerPickupItemEvent event) {
|
||||||
|
|
||||||
// Should we check at all?
|
// Should we check at all?
|
||||||
if(skipCheck(event.getPlayer())) return;
|
if(skipCheck(event.getPlayer()))
|
||||||
|
return;
|
||||||
|
|
||||||
Item i = event.getItem();
|
Item i = event.getItem();
|
||||||
if(i != null) {
|
if(i != null) {
|
||||||
@ -49,7 +50,8 @@ public class BogusitemsCheck extends Check {
|
|||||||
|
|
||||||
public void check(PlayerInteractEvent event) {
|
public void check(PlayerInteractEvent event) {
|
||||||
|
|
||||||
if(skipCheck(event.getPlayer())) return;
|
if(skipCheck(event.getPlayer()))
|
||||||
|
return;
|
||||||
|
|
||||||
if(event.hasItem() && event.getItem().getAmount() <= 0) {// buggy item
|
if(event.hasItem() && event.getItem().getAmount() <= 0) {// buggy item
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@ -62,7 +64,8 @@ public class BogusitemsCheck extends Check {
|
|||||||
|
|
||||||
public void check(PlayerDropItemEvent event) {
|
public void check(PlayerDropItemEvent event) {
|
||||||
|
|
||||||
if(skipCheck(event.getPlayer())) return;
|
if(skipCheck(event.getPlayer()))
|
||||||
|
return;
|
||||||
|
|
||||||
Item item = event.getItemDrop();
|
Item item = event.getItemDrop();
|
||||||
|
|
||||||
@ -98,7 +101,7 @@ public class BogusitemsCheck extends Check {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
setActive(config.getBooleanValue("active.bogusitems"));
|
setActive(config.getBooleanValue("active.bogusitems"));
|
||||||
} catch (ConfigurationException e) {
|
} catch(ConfigurationException e) {
|
||||||
setActive(false);
|
setActive(false);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package cc.co.evenprime.bukkit.nocheat.checks;
|
package cc.co.evenprime.bukkit.nocheat.checks;
|
||||||
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import cc.co.evenprime.bukkit.nocheat.ConfigurationException;
|
import cc.co.evenprime.bukkit.nocheat.ConfigurationException;
|
||||||
@ -29,12 +28,11 @@ public abstract class Check {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
checkOPs= config.getBooleanValue(name + ".checkops");
|
checkOPs = config.getBooleanValue(name + ".checkops");
|
||||||
} catch (ConfigurationException e) {
|
} catch(ConfigurationException e) {
|
||||||
checkOPs = false;
|
checkOPs = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
configure(config);
|
configure(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,5 +65,4 @@ public abstract class Check {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,27 @@
|
|||||||
package cc.co.evenprime.bukkit.nocheat.checks;
|
package cc.co.evenprime.bukkit.nocheat.checks;
|
||||||
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
|
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the player should be allowed to make that move, e.g. is he allowed to jump here or move that far in one step
|
* Check if the player should be allowed to make that move, e.g. is he allowed
|
||||||
|
* to jump here or move that far in one step
|
||||||
*
|
*
|
||||||
* @author Evenprime
|
* @author Evenprime
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class FlyingCheck {
|
public class FlyingCheck {
|
||||||
|
|
||||||
public FlyingCheck() { }
|
public FlyingCheck() {}
|
||||||
|
|
||||||
// How many move events can a player have in air before he is expected to lose altitude (or eventually land somewhere)
|
// How many move events can a player have in air before he is expected to
|
||||||
|
// lose altitude (or eventually land somewhere)
|
||||||
private final static int jumpingLimit = 5;
|
private final static int jumpingLimit = 5;
|
||||||
|
|
||||||
// How high may a player get compared to his last location with ground contact
|
// How high may a player get compared to his last location with ground
|
||||||
|
// contact
|
||||||
private final static double jumpHeight = 1.31D;
|
private final static double jumpHeight = 1.31D;
|
||||||
|
|
||||||
// How much points should hovering attempts cause?
|
// How much points should hovering attempts cause?
|
||||||
@ -28,9 +30,9 @@ public class FlyingCheck {
|
|||||||
// How high may a player move in one event on ground
|
// How high may a player move in one event on ground
|
||||||
private final static double stepHeight = 0.501D;
|
private final static double stepHeight = 0.501D;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate if and how much the player "failed" this check. The check should not
|
* Calculate if and how much the player "failed" this check. The check
|
||||||
|
* should not
|
||||||
* modify any data
|
* modify any data
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -45,13 +47,11 @@ public class FlyingCheck {
|
|||||||
double limit = calculateVerticalLimit(data, fromOnGround) + jumpHeight;
|
double limit = calculateVerticalLimit(data, fromOnGround) + jumpHeight;
|
||||||
|
|
||||||
// Walk or start Jump
|
// Walk or start Jump
|
||||||
if(fromOnGround)
|
if(fromOnGround) {
|
||||||
{
|
|
||||||
distanceAboveLimit = toY - Math.floor(fromY) - limit;
|
distanceAboveLimit = toY - Math.floor(fromY) - limit;
|
||||||
}
|
}
|
||||||
// Land or Fly/Fall
|
// Land or Fly/Fall
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
final Location l;
|
final Location l;
|
||||||
|
|
||||||
if(data.setBackPoint == null)
|
if(data.setBackPoint == null)
|
||||||
@ -60,16 +60,18 @@ public class FlyingCheck {
|
|||||||
l = data.setBackPoint;
|
l = data.setBackPoint;
|
||||||
|
|
||||||
if(data.jumpPhase > jumpingLimit) {
|
if(data.jumpPhase > jumpingLimit) {
|
||||||
limit -= (data.jumpPhase-jumpingLimit) * 0.2D;
|
limit -= (data.jumpPhase - jumpingLimit) * 0.2D;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(toOnGround) limit += stepHeight;
|
if(toOnGround)
|
||||||
|
limit += stepHeight;
|
||||||
|
|
||||||
distanceAboveLimit = toY - Math.floor(l.getY()) - limit;
|
distanceAboveLimit = toY - Math.floor(l.getY()) - limit;
|
||||||
|
|
||||||
// Always give some bonus points in case of identical Y values in midair (hovering player)
|
// Always give some bonus points in case of identical Y values in
|
||||||
|
// midair (hovering player)
|
||||||
if(fromY == toY && !toOnGround) {
|
if(fromY == toY && !toOnGround) {
|
||||||
distanceAboveLimit = Math.max(hoveringPunishment, distanceAboveLimit+hoveringPunishment);
|
distanceAboveLimit = Math.max(hoveringPunishment, distanceAboveLimit + hoveringPunishment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,27 +80,34 @@ public class FlyingCheck {
|
|||||||
|
|
||||||
private double calculateVerticalLimit(final MovingData data, final boolean onGroundFrom) {
|
private double calculateVerticalLimit(final MovingData data, final boolean onGroundFrom) {
|
||||||
|
|
||||||
// A halfway lag-resistant method of allowing vertical acceleration without allowing blatant cheating
|
// A halfway lag-resistant method of allowing vertical acceleration
|
||||||
|
// without allowing blatant cheating
|
||||||
|
|
||||||
// FACT: Minecraft server sends player "velocity" to the client and lets the client calculate the movement
|
// FACT: Minecraft server sends player "velocity" to the client and lets
|
||||||
// PROBLEM: There may be an arbitrary amount of other move events between the server sending the data
|
// the client calculate the movement
|
||||||
// and the client accepting it/reacting to it. The server can't know when the client starts to
|
// PROBLEM: There may be an arbitrary amount of other move events
|
||||||
|
// between the server sending the data
|
||||||
|
// and the client accepting it/reacting to it. The server can't know
|
||||||
|
// when the client starts to
|
||||||
// consider the sent "velocity" in its movement.
|
// consider the sent "velocity" in its movement.
|
||||||
// SOLUTION: Give the client at least 10 events after sending "velocity" to actually use the velocity for
|
// SOLUTION: Give the client at least 10 events after sending "velocity"
|
||||||
// its movement, plus additional events if the "velocity" was big and can cause longer flights
|
// to actually use the velocity for
|
||||||
|
// its movement, plus additional events if the "velocity" was big and
|
||||||
|
// can cause longer flights
|
||||||
|
|
||||||
// The server sent the player a "velocity" packet a short time ago
|
// The server sent the player a "velocity" packet a short time ago
|
||||||
|
|
||||||
// consume a counter for this client
|
// consume a counter for this client
|
||||||
if(data.vertFreedomCounter > 0) {
|
if(data.vertFreedomCounter > 0) {
|
||||||
data.vertFreedomCounter--;
|
data.vertFreedomCounter--;
|
||||||
data.vertFreedom += data.maxYVelocity*2D;
|
data.vertFreedom += data.maxYVelocity * 2D;
|
||||||
data.maxYVelocity *= 0.90D;
|
data.maxYVelocity *= 0.90D;
|
||||||
}
|
}
|
||||||
|
|
||||||
final double limit = data.vertFreedom;
|
final double limit = data.vertFreedom;
|
||||||
|
|
||||||
// If the event counter has been consumed, remove the vertical movement limit increase when landing the next time
|
// If the event counter has been consumed, remove the vertical movement
|
||||||
|
// limit increase when landing the next time
|
||||||
if(onGroundFrom && data.vertFreedomCounter <= 0) {
|
if(onGroundFrom && data.vertFreedomCounter <= 0) {
|
||||||
data.vertFreedom = 0.0D;
|
data.vertFreedom = 0.0D;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
package cc.co.evenprime.bukkit.nocheat.checks;
|
package cc.co.evenprime.bukkit.nocheat.checks;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -27,7 +26,8 @@ import cc.co.evenprime.bukkit.nocheat.listeners.MovingPlayerListener;
|
|||||||
import cc.co.evenprime.bukkit.nocheat.listeners.MovingPlayerMonitor;
|
import cc.co.evenprime.bukkit.nocheat.listeners.MovingPlayerMonitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the player should be allowed to make that move, e.g. is he allowed to jump here or move that far in one step
|
* Check if the player should be allowed to make that move, e.g. is he allowed
|
||||||
|
* to jump here or move that far in one step
|
||||||
*
|
*
|
||||||
* @author Evenprime
|
* @author Evenprime
|
||||||
*
|
*
|
||||||
@ -62,7 +62,11 @@ public class MovingCheck extends Check {
|
|||||||
// How should moving violations be treated?
|
// How should moving violations be treated?
|
||||||
private Action actions[][];
|
private Action actions[][];
|
||||||
|
|
||||||
public long statisticTotalEvents = 1; // Prevent accidental division by 0 at some point
|
public long statisticTotalEvents = 1; // Prevent
|
||||||
|
// accidental
|
||||||
|
// division by
|
||||||
|
// 0 at some
|
||||||
|
// point
|
||||||
|
|
||||||
private boolean enforceTeleport;
|
private boolean enforceTeleport;
|
||||||
|
|
||||||
@ -76,11 +80,11 @@ public class MovingCheck extends Check {
|
|||||||
* Second check if the player moved too far horizontally
|
* Second check if the player moved too far horizontally
|
||||||
* Third check if the player moved too high vertically
|
* Third check if the player moved too high vertically
|
||||||
* Fourth treat any occured violations as configured
|
* Fourth treat any occured violations as configured
|
||||||
|
*
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public Location check(Player player, Location from, Location to,
|
public Location check(Player player, Location from, Location to, MovingData data) {
|
||||||
MovingData data) {
|
|
||||||
|
|
||||||
Location newToLocation = null;
|
Location newToLocation = null;
|
||||||
|
|
||||||
@ -94,10 +98,11 @@ public class MovingCheck extends Check {
|
|||||||
|
|
||||||
if(flyCheck || runCheck) {
|
if(flyCheck || runCheck) {
|
||||||
|
|
||||||
// In both cases it will be interesting to know the type of underground the player
|
// In both cases it will be interesting to know the type of
|
||||||
|
// underground the player
|
||||||
// is in or goes to
|
// is in or goes to
|
||||||
final int fromType = helper.isLocationOnGround(from.getWorld(), from.getX(), from.getY(), from.getZ(), waterElevators);
|
final int fromType = helper.isLocationOnGround(from.getWorld(), from.getX(), from.getY(), from.getZ(), waterElevators);
|
||||||
final int toType = helper.isLocationOnGround(to.getWorld(), to.getX(), to.getY(),to.getZ(), waterElevators);
|
final int toType = helper.isLocationOnGround(to.getWorld(), to.getX(), to.getY(), to.getZ(), waterElevators);
|
||||||
|
|
||||||
final boolean fromOnGround = fromType != MovingEventHelper.NONSOLID;
|
final boolean fromOnGround = fromType != MovingEventHelper.NONSOLID;
|
||||||
final boolean toOnGround = toType != MovingEventHelper.NONSOLID;
|
final boolean toOnGround = toType != MovingEventHelper.NONSOLID;
|
||||||
@ -109,16 +114,14 @@ public class MovingCheck extends Check {
|
|||||||
|
|
||||||
if(flyCheck) {
|
if(flyCheck) {
|
||||||
result += Math.max(0D, flyingCheck.check(player, from, fromOnGround, to, toOnGround, data));
|
result += Math.max(0D, flyingCheck.check(player, from, fromOnGround, to, toOnGround, data));
|
||||||
}
|
} else {
|
||||||
else
|
// If players are allowed to fly, there's no need to remember
|
||||||
{
|
// the last location on ground
|
||||||
// If players are allowed to fly, there's no need to remember the last location on ground
|
|
||||||
data.setBackPoint = from;
|
data.setBackPoint = from;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(runCheck) {
|
if(runCheck) {
|
||||||
result += Math.max(0D, runningCheck.check(from, to,
|
result += Math.max(0D, runningCheck.check(from, to, !allowFakeSneak && player.isSneaking(), !allowFastSwim && (fromType & toType & MovingEventHelper.LIQUID) > 0, data, this));
|
||||||
!allowFakeSneak && player.isSneaking(), !allowFastSwim && (fromType & toType & MovingEventHelper.LIQUID) > 0, data, this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/********* HANDLE/COMBINE THE RESULTS OF THE CHECKS ***********/
|
/********* HANDLE/COMBINE THE RESULTS OF THE CHECKS ***********/
|
||||||
@ -128,22 +131,22 @@ public class MovingCheck extends Check {
|
|||||||
if(fromOnGround) {
|
if(fromOnGround) {
|
||||||
data.setBackPoint = from;
|
data.setBackPoint = from;
|
||||||
data.jumpPhase = 0;
|
data.jumpPhase = 0;
|
||||||
}
|
} else if(result <= 0 && toOnGround) {
|
||||||
else if(result <= 0 && toOnGround) {
|
|
||||||
data.jumpPhase = 0;
|
data.jumpPhase = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(result > 0) {
|
if(result > 0) {
|
||||||
// Increment violation counter
|
// Increment violation counter
|
||||||
data.violationLevel += result;
|
data.violationLevel += result;
|
||||||
if(data.setBackPoint == null) data.setBackPoint = from;
|
if(data.setBackPoint == null)
|
||||||
|
data.setBackPoint = from;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(result > 0 && data.violationLevel > 1) {
|
if(result > 0 && data.violationLevel > 1) {
|
||||||
|
|
||||||
setupSummaryTask(player, data);
|
setupSummaryTask(player, data);
|
||||||
|
|
||||||
int level = limitCheck(data.violationLevel-1);
|
int level = limitCheck(data.violationLevel - 1);
|
||||||
|
|
||||||
data.violationsInARow[level]++;
|
data.violationsInARow[level]++;
|
||||||
|
|
||||||
@ -158,12 +161,13 @@ public class MovingCheck extends Check {
|
|||||||
statisticElapsedTimeNano += System.nanoTime() - startTime;
|
statisticElapsedTimeNano += System.nanoTime() - startTime;
|
||||||
statisticTotalEvents++;
|
statisticTotalEvents++;
|
||||||
|
|
||||||
|
|
||||||
return newToLocation;
|
return newToLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Various corner cases that would cause this check to fail or require special treatment
|
* Various corner cases that would cause this check to fail or require
|
||||||
|
* special treatment
|
||||||
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param data
|
* @param data
|
||||||
* @param from
|
* @param from
|
||||||
@ -172,34 +176,14 @@ public class MovingCheck extends Check {
|
|||||||
*/
|
*/
|
||||||
public boolean shouldBeApplied(final Player player, final MovingData data, final Location from, final Location to) {
|
public boolean shouldBeApplied(final Player player, final MovingData data, final Location from, final Location to) {
|
||||||
|
|
||||||
if(player.isDead() || player.isInsideVehicle()) return false;
|
|
||||||
|
|
||||||
if(data.wasTeleported) {
|
|
||||||
// Remember this location
|
|
||||||
data.teleportedTo = from.clone();
|
|
||||||
data.wasTeleported = false;
|
|
||||||
data.jumpPhase = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(data.teleportedTo != null && data.teleportedTo.getWorld().equals(from.getWorld())) {
|
|
||||||
// As long as the from-Location doesn't change, the player didn't accept the teleport
|
|
||||||
if(data.teleportedTo.distanceSquared(from) < 0.01D) {
|
|
||||||
// Event after Teleport ignored
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// The player finally accepted the teleport with the previous event
|
|
||||||
data.teleportedTo = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a task with bukkit that will be run a short time from now, displaying how many
|
* Register a task with bukkit that will be run a short time from now,
|
||||||
|
* displaying how many
|
||||||
* violations happened in that timeframe
|
* violations happened in that timeframe
|
||||||
|
*
|
||||||
* @param p
|
* @param p
|
||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
@ -213,7 +197,7 @@ public class MovingCheck extends Check {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if(data.highestLogLevel != null) {
|
if(data.highestLogLevel != null) {
|
||||||
String logString = String.format(summaryMessage, p.getName(), ticksBeforeSummary/20, data.violationsInARow[0], data.violationsInARow[1],data.violationsInARow[2]);
|
String logString = String.format(summaryMessage, p.getName(), ticksBeforeSummary / 20, data.violationsInARow[0], data.violationsInARow[1], data.violationsInARow[2]);
|
||||||
plugin.log(data.highestLogLevel, logString);
|
plugin.log(data.highestLogLevel, logString);
|
||||||
|
|
||||||
data.highestLogLevel = Level.ALL;
|
data.highestLogLevel = Level.ALL;
|
||||||
@ -224,8 +208,7 @@ public class MovingCheck extends Check {
|
|||||||
data.violationsInARow[0] = 0;
|
data.violationsInARow[0] = 0;
|
||||||
data.violationsInARow[1] = 0;
|
data.violationsInARow[1] = 0;
|
||||||
data.violationsInARow[2] = 0;
|
data.violationsInARow[2] = 0;
|
||||||
}
|
} catch(Exception e) {}
|
||||||
catch(Exception e) { }
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -235,7 +218,8 @@ public class MovingCheck extends Check {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this when a player got successfully teleported with the corresponding event to adjust stored
|
* Call this when a player got successfully teleported with the
|
||||||
|
* corresponding event to adjust stored
|
||||||
* data to the new situation
|
* data to the new situation
|
||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
@ -244,7 +228,8 @@ public class MovingCheck extends Check {
|
|||||||
|
|
||||||
MovingData data = plugin.getDataManager().getMovingData(event.getPlayer());
|
MovingData data = plugin.getDataManager().getMovingData(event.getPlayer());
|
||||||
|
|
||||||
// We can enforce a teleport, if that flag is explicitly set (but I'd rather have other plugins
|
// We can enforce a teleport, if that flag is explicitly set (but I'd
|
||||||
|
// rather have other plugins
|
||||||
// not arbitrarily cancel teleport events in the first place...
|
// not arbitrarily cancel teleport events in the first place...
|
||||||
if(data.teleportInitializedByMe != null && event.isCancelled() && enforceTeleport && event.getTo().equals(data.teleportInitializedByMe)) {
|
if(data.teleportInitializedByMe != null && event.isCancelled() && enforceTeleport && event.getTo().equals(data.teleportInitializedByMe)) {
|
||||||
event.setCancelled(false);
|
event.setCancelled(false);
|
||||||
@ -252,24 +237,25 @@ public class MovingCheck extends Check {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!event.isCancelled()) {
|
if(!event.isCancelled()) {
|
||||||
data.wasTeleported = true;
|
data.setBackPoint = null;
|
||||||
data.setBackPoint = event.getTo().clone();
|
|
||||||
//data.lastLocation = event.getTo().clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset anyway - if another plugin cancelled our teleport it's no use to try and be precise
|
// reset anyway - if another plugin cancelled our teleport it's no use
|
||||||
|
// to try and be precise
|
||||||
data.jumpPhase = 0;
|
data.jumpPhase = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the cached values for players velocity to be prepared to
|
* Update the cached values for players velocity to be prepared to
|
||||||
* give them additional movement freedom in their next move events
|
* give them additional movement freedom in their next move events
|
||||||
|
*
|
||||||
* @param v
|
* @param v
|
||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
public void updateVelocity(Vector v, MovingData data) {
|
public void updateVelocity(Vector v, MovingData data) {
|
||||||
|
|
||||||
// Compare the velocity vector to the existing movement freedom that we've from previous events
|
// Compare the velocity vector to the existing movement freedom that
|
||||||
|
// we've from previous events
|
||||||
double tmp = (Math.abs(v.getX()) + Math.abs(v.getZ())) * 3D;
|
double tmp = (Math.abs(v.getX()) + Math.abs(v.getZ())) * 3D;
|
||||||
if(tmp > data.horizFreedom)
|
if(tmp > data.horizFreedom)
|
||||||
data.horizFreedom = tmp;
|
data.horizFreedom = tmp;
|
||||||
@ -282,16 +268,17 @@ public class MovingCheck extends Check {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform actions that were specified in the config file
|
* Perform actions that were specified in the config file
|
||||||
|
*
|
||||||
* @param event
|
* @param event
|
||||||
* @param action
|
* @param action
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Location action( Player player, Location from, Location to, Action[] actions, int violations, MovingData data, MovingEventHelper helper) {
|
private Location action(Player player, Location from, Location to, Action[] actions, int violations, MovingData data, MovingEventHelper helper) {
|
||||||
|
|
||||||
|
|
||||||
Location newToLocation = null;
|
Location newToLocation = null;
|
||||||
|
|
||||||
if(actions == null) return newToLocation;
|
if(actions == null)
|
||||||
|
return newToLocation;
|
||||||
boolean cancelled = false;
|
boolean cancelled = false;
|
||||||
|
|
||||||
for(Action a : actions) {
|
for(Action a : actions) {
|
||||||
@ -299,41 +286,49 @@ public class MovingCheck extends Check {
|
|||||||
if(a.firstAfter == violations || a.repeat) {
|
if(a.firstAfter == violations || a.repeat) {
|
||||||
if(a instanceof LogAction) {
|
if(a instanceof LogAction) {
|
||||||
// prepare log message if necessary
|
// prepare log message if necessary
|
||||||
String log = String.format(Locale.US, logMessage, player.getName(), from.getWorld().getName(), to.getWorld().getName(), from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ(), Math.abs(from.getX()-to.getX()),to.getY()-from.getY(), Math.abs(from.getZ()-to.getZ()));
|
String log = String.format(Locale.US, logMessage, player.getName(), from.getWorld().getName(), to.getWorld().getName(), from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ(), Math.abs(from.getX() - to.getX()), to.getY() - from.getY(), Math.abs(from.getZ() - to.getZ()));
|
||||||
|
|
||||||
plugin.log(((LogAction)a).level, log);
|
plugin.log(((LogAction) a).level, log);
|
||||||
|
|
||||||
// Remember the highest log level we encountered to determine what level the summary log message should have
|
// Remember the highest log level we encountered to
|
||||||
if(data.highestLogLevel == null) data.highestLogLevel = Level.ALL;
|
// determine what level the summary log message should
|
||||||
if(data.highestLogLevel.intValue() < ((LogAction)a).level.intValue()) data.highestLogLevel = ((LogAction)a).level;
|
// have
|
||||||
}
|
if(data.highestLogLevel == null)
|
||||||
else if(!cancelled && a instanceof CancelAction) {
|
data.highestLogLevel = Level.ALL;
|
||||||
// Make a modified copy of the setBackPoint to prevent other plugins from accidentally modifying it
|
if(data.highestLogLevel.intValue() < ((LogAction) a).level.intValue())
|
||||||
// and keep the current pitch and yaw (setbacks "feel" better that way). Plus try to adapt the Y-coord
|
data.highestLogLevel = ((LogAction) a).level;
|
||||||
|
} else if(!cancelled && a instanceof CancelAction) {
|
||||||
|
// Make a modified copy of the setBackPoint to prevent
|
||||||
|
// other plugins from accidentally modifying it
|
||||||
|
// and keep the current pitch and yaw (setbacks "feel"
|
||||||
|
// better that way). Plus try to adapt the Y-coord
|
||||||
// to place the player close to ground
|
// to place the player close to ground
|
||||||
|
|
||||||
double y = data.setBackPoint.getY();
|
double y = data.setBackPoint.getY();
|
||||||
|
|
||||||
// search for the first solid block up to 5 blocks below the setbackpoint and teleport the player there
|
// search for the first solid block up to 5 blocks below
|
||||||
|
// the setbackpoint and teleport the player there
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(; i < 20; i++) {
|
for(; i < 20; i++) {
|
||||||
if(helper.isLocationOnGround(data.setBackPoint.getWorld(), data.setBackPoint.getX(), data.setBackPoint.getY() - 0.5*i, data.setBackPoint.getZ(), waterElevators) != MovingData.NONSOLID) {
|
if(helper.isLocationOnGround(data.setBackPoint.getWorld(), data.setBackPoint.getX(), data.setBackPoint.getY() - 0.5 * i, data.setBackPoint.getZ(), waterElevators) != MovingData.NONSOLID) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
y -= 0.5*i;
|
y -= 0.5 * i;
|
||||||
|
|
||||||
data.setBackPoint.setY(y);
|
data.setBackPoint.setY(y);
|
||||||
|
|
||||||
// Remember the location we send the player to, to identify teleports that were started by us
|
// Remember the location we send the player to, to
|
||||||
|
// identify teleports that were started by us
|
||||||
data.teleportInitializedByMe = new Location(data.setBackPoint.getWorld(), data.setBackPoint.getX(), y, data.setBackPoint.getZ(), to.getYaw(), to.getPitch());
|
data.teleportInitializedByMe = new Location(data.setBackPoint.getWorld(), data.setBackPoint.getX(), y, data.setBackPoint.getZ(), to.getYaw(), to.getPitch());
|
||||||
|
|
||||||
newToLocation = data.teleportInitializedByMe;
|
newToLocation = data.teleportInitializedByMe;
|
||||||
|
|
||||||
cancelled = true; // just prevent us from treating more than one "cancel" action, which would make no sense
|
cancelled = true; // just prevent us from treating more
|
||||||
}
|
// than one "cancel" action, which
|
||||||
else if(a instanceof CustomAction)
|
// would make no sense
|
||||||
plugin.handleCustomAction((CustomAction)a, player);
|
} else if(a instanceof CustomAction)
|
||||||
|
plugin.handleCustomAction((CustomAction) a, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -344,6 +339,7 @@ public class MovingCheck extends Check {
|
|||||||
/**
|
/**
|
||||||
* Check a value against an array of sorted values to find out
|
* Check a value against an array of sorted values to find out
|
||||||
* where it fits in
|
* where it fits in
|
||||||
|
*
|
||||||
* @param value
|
* @param value
|
||||||
* @param limits
|
* @param limits
|
||||||
* @return
|
* @return
|
||||||
@ -354,8 +350,10 @@ public class MovingCheck extends Check {
|
|||||||
if(value > 0.5D) {
|
if(value > 0.5D) {
|
||||||
if(value > 2.0D)
|
if(value > 2.0D)
|
||||||
return 2;
|
return 2;
|
||||||
return 1; }
|
return 1;
|
||||||
return 0; }
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,19 +369,11 @@ public class MovingCheck extends Check {
|
|||||||
|
|
||||||
checkOPs = config.getBooleanValue("moving.checkops");
|
checkOPs = config.getBooleanValue("moving.checkops");
|
||||||
|
|
||||||
logMessage = config.getStringValue("moving.logmessage").
|
logMessage = config.getStringValue("moving.logmessage").replace("[player]", "%1$s").replace("[world]", "%2$s").replace("[from]", "(%4$.1f, %5$.1f, %6$.1f)").replace("[to]", "(%7$.1f, %8$.1f, %9$.1f)").replace("[distance]", "(%10$.1f, %11$.1f, %12$.1f)");
|
||||||
replace("[player]", "%1$s").
|
|
||||||
replace("[world]", "%2$s").
|
|
||||||
replace("[from]", "(%4$.1f, %5$.1f, %6$.1f)").
|
|
||||||
replace("[to]", "(%7$.1f, %8$.1f, %9$.1f)").
|
|
||||||
replace("[distance]", "(%10$.1f, %11$.1f, %12$.1f)");
|
|
||||||
|
|
||||||
summaryMessage = config.getStringValue("moving.summarymessage").
|
summaryMessage = config.getStringValue("moving.summarymessage").replace("[timeframe]", "%2$d").replace("[player]", "%1$s").replace("[violations]", "(%3$d,%4$d,%5$d)");
|
||||||
replace("[timeframe]", "%2$d").
|
|
||||||
replace("[player]", "%1$s").
|
|
||||||
replace("[violations]", "(%3$d,%4$d,%5$d)");
|
|
||||||
|
|
||||||
ticksBeforeSummary = config.getIntegerValue("moving.summaryafter")*20;
|
ticksBeforeSummary = config.getIntegerValue("moving.summaryafter") * 20;
|
||||||
|
|
||||||
actions = new Action[3][];
|
actions = new Action[3][];
|
||||||
|
|
||||||
@ -395,11 +385,11 @@ public class MovingCheck extends Check {
|
|||||||
|
|
||||||
enforceTeleport = config.getBooleanValue("moving.enforceteleport");
|
enforceTeleport = config.getBooleanValue("moving.enforceteleport");
|
||||||
|
|
||||||
stepWidth = ((double)config.getIntegerValue("moving.limits.walking")) /100D;
|
stepWidth = ((double) config.getIntegerValue("moving.limits.walking")) / 100D;
|
||||||
sneakWidth = ((double)config.getIntegerValue("moving.limits.sneaking"))/100D;
|
sneakWidth = ((double) config.getIntegerValue("moving.limits.sneaking")) / 100D;
|
||||||
swimWidth = ((double)config.getIntegerValue("moving.limits.swimming"))/100D;
|
swimWidth = ((double) config.getIntegerValue("moving.limits.swimming")) / 100D;
|
||||||
|
|
||||||
} catch (ConfigurationException e) {
|
} catch(ConfigurationException e) {
|
||||||
setActive(false);
|
setActive(false);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import org.bukkit.World;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A collection of stuff to process data of move events
|
* A collection of stuff to process data of move events
|
||||||
|
*
|
||||||
* @author Evenprime
|
* @author Evenprime
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -22,7 +23,8 @@ public class MovingEventHelper {
|
|||||||
public static final int LADDER = 4; // 0x00000100
|
public static final int LADDER = 4; // 0x00000100
|
||||||
public static final int FENCE = 8; // 0x00001000
|
public static final int FENCE = 8; // 0x00001000
|
||||||
|
|
||||||
// Until I can think of a better way to determine if a block is solid or not, this is what I'll do
|
// Until I can think of a better way to determine if a block is solid or
|
||||||
|
// not, this is what I'll do
|
||||||
private final int types[] = new int[256];
|
private final int types[] = new int[256];
|
||||||
|
|
||||||
public MovingEventHelper() {
|
public MovingEventHelper() {
|
||||||
@ -36,8 +38,7 @@ public class MovingEventHelper {
|
|||||||
if(Block.byId[i].material.isSolid()) {
|
if(Block.byId[i].material.isSolid()) {
|
||||||
// solid blocks like STONE, CAKE, TRAPDOORS
|
// solid blocks like STONE, CAKE, TRAPDOORS
|
||||||
types[i] = SOLID;
|
types[i] = SOLID;
|
||||||
}
|
} else if(Block.byId[i].material.isLiquid()) {
|
||||||
else if(Block.byId[i].material.isLiquid()){
|
|
||||||
// WATER, LAVA
|
// WATER, LAVA
|
||||||
types[i] = LIQUID;
|
types[i] = LIQUID;
|
||||||
}
|
}
|
||||||
@ -45,68 +46,65 @@ public class MovingEventHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Special types just for me
|
// Special types just for me
|
||||||
types[Material.LADDER.getId()]= LADDER | SOLID;
|
types[Material.LADDER.getId()] = LADDER | SOLID;
|
||||||
types[Material.FENCE.getId()]= FENCE | SOLID;
|
types[Material.FENCE.getId()] = FENCE | SOLID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if certain coordinates are considered "on ground"
|
* Check if certain coordinates are considered "on ground"
|
||||||
*
|
*
|
||||||
* @param w The world the coordinates belong to
|
* @param w
|
||||||
* @param values The coordinates [lowerX, higherX, Y, lowerZ, higherZ] to be checked
|
* The world the coordinates belong to
|
||||||
* @param l The precise location that was used for calculation of "values"
|
* @param values
|
||||||
|
* The coordinates [lowerX, higherX, Y, lowerZ, higherZ] to be
|
||||||
|
* checked
|
||||||
|
* @param l
|
||||||
|
* The precise location that was used for calculation of "values"
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public int isLocationOnGround(final World world, final double x, final double y, final double z, boolean waterElevatorsAllowed) {
|
public int isLocationOnGround(final World world, final double x, final double y, final double z, boolean waterElevatorsAllowed) {
|
||||||
|
|
||||||
final int lowerX = lowerBorder(x);
|
final int lowerX = lowerBorder(x);
|
||||||
final int upperX = upperBorder(x);
|
final int upperX = upperBorder(x);
|
||||||
final int Y = (int)Math.floor(y);
|
final int Y = (int) Math.floor(y);
|
||||||
final int lowerZ = lowerBorder(z);
|
final int lowerZ = lowerBorder(z);
|
||||||
final int higherZ = upperBorder(z);
|
final int higherZ = upperBorder(z);
|
||||||
|
|
||||||
|
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
// check in what kind of block the player is standing "in"
|
// check in what kind of block the player is standing "in"
|
||||||
result = types[world.getBlockTypeIdAt(lowerX, Y, lowerZ)] | types[world.getBlockTypeIdAt(upperX, Y, lowerZ)] |
|
result = types[world.getBlockTypeIdAt(lowerX, Y, lowerZ)] | types[world.getBlockTypeIdAt(upperX, Y, lowerZ)] | types[world.getBlockTypeIdAt(lowerX, Y, higherZ)] | types[world.getBlockTypeIdAt(upperX, Y, higherZ)];
|
||||||
types[world.getBlockTypeIdAt(lowerX, Y, higherZ)] | types[world.getBlockTypeIdAt(upperX, Y, higherZ)];
|
|
||||||
|
|
||||||
if((result & SOLID) != 0) {
|
if((result & SOLID) != 0) {
|
||||||
// return standing
|
// return standing
|
||||||
return SOLID;
|
return SOLID;
|
||||||
}
|
} else if((result & LIQUID) != 0) {
|
||||||
else if((result & LIQUID) != 0) {
|
|
||||||
// return swimming
|
// return swimming
|
||||||
return LIQUID;
|
return LIQUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the four borders of the players hitbox for something he could be standing on
|
// Check the four borders of the players hitbox for something he could
|
||||||
result = types[world.getBlockTypeIdAt(lowerX, Y-1, lowerZ)] | types[world.getBlockTypeIdAt(upperX, Y-1, lowerZ)] |
|
// be standing on
|
||||||
types[world.getBlockTypeIdAt(lowerX, Y-1, higherZ)] | types[world.getBlockTypeIdAt(upperX, Y-1, higherZ)];
|
result = types[world.getBlockTypeIdAt(lowerX, Y - 1, lowerZ)] | types[world.getBlockTypeIdAt(upperX, Y - 1, lowerZ)] | types[world.getBlockTypeIdAt(lowerX, Y - 1, higherZ)] | types[world.getBlockTypeIdAt(upperX, Y - 1, higherZ)];
|
||||||
|
|
||||||
if((result & SOLID) != 0) {
|
if((result & SOLID) != 0) {
|
||||||
// return standing
|
// return standing
|
||||||
return SOLID;
|
return SOLID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// check if his head is "stuck" in an block
|
// check if his head is "stuck" in an block
|
||||||
result = types[world.getBlockTypeIdAt(lowerX, Y+1, lowerZ)] | types[world.getBlockTypeIdAt(upperX, Y+1, lowerZ)] |
|
result = types[world.getBlockTypeIdAt(lowerX, Y + 1, lowerZ)] | types[world.getBlockTypeIdAt(upperX, Y + 1, lowerZ)] | types[world.getBlockTypeIdAt(lowerX, Y + 1, higherZ)] | types[world.getBlockTypeIdAt(upperX, Y + 1, higherZ)];
|
||||||
types[world.getBlockTypeIdAt(lowerX, Y+1, higherZ)] | types[world.getBlockTypeIdAt(upperX, Y+1, higherZ)];
|
|
||||||
|
|
||||||
if((result & SOLID) != 0) {
|
if((result & SOLID) != 0) {
|
||||||
// return standing
|
// return standing
|
||||||
return SOLID;
|
return SOLID;
|
||||||
}
|
} else if((result & LIQUID) != 0) {
|
||||||
else if((result & LIQUID) != 0) {
|
|
||||||
// return swimming
|
// return swimming
|
||||||
return LIQUID;
|
return LIQUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Running on fences causes problems if not treated specially
|
// Running on fences causes problems if not treated specially
|
||||||
result = types[world.getBlockTypeIdAt(lowerX, Y-2, lowerZ)] | types[world.getBlockTypeIdAt(upperX, Y-2, lowerZ)] |
|
result = types[world.getBlockTypeIdAt(lowerX, Y - 2, lowerZ)] | types[world.getBlockTypeIdAt(upperX, Y - 2, lowerZ)] | types[world.getBlockTypeIdAt(lowerX, Y - 2, higherZ)] | types[world.getBlockTypeIdAt(upperX, Y - 2, higherZ)];
|
||||||
types[world.getBlockTypeIdAt(lowerX, Y-2, higherZ)] | types[world.getBlockTypeIdAt(upperX, Y-2, higherZ)];
|
|
||||||
|
|
||||||
if((result & FENCE) != 0) {
|
if((result & FENCE) != 0) {
|
||||||
// return standing
|
// return standing
|
||||||
@ -115,25 +113,21 @@ public class MovingEventHelper {
|
|||||||
|
|
||||||
// Water elevators - optional "feature"
|
// Water elevators - optional "feature"
|
||||||
if(waterElevatorsAllowed) {
|
if(waterElevatorsAllowed) {
|
||||||
result = types[world.getBlockTypeIdAt(lowerX+1, Y+1, lowerZ+1)] |
|
result = types[world.getBlockTypeIdAt(lowerX + 1, Y + 1, lowerZ + 1)] | types[world.getBlockTypeIdAt(lowerX + 1, Y, lowerZ + 1)] | types[world.getBlockTypeIdAt(lowerX, Y + 1, lowerZ + 1)] | types[world.getBlockTypeIdAt(lowerX, Y, lowerZ + 1)] | types[world.getBlockTypeIdAt(lowerX + 1, Y + 1, lowerZ)] | types[world.getBlockTypeIdAt(lowerX + 1, Y, lowerZ)];
|
||||||
types[world.getBlockTypeIdAt(lowerX+1, Y , lowerZ+1)] |
|
|
||||||
types[world.getBlockTypeIdAt(lowerX, Y+1, lowerZ+1)] |
|
|
||||||
types[world.getBlockTypeIdAt(lowerX , Y , lowerZ+1)] |
|
|
||||||
types[world.getBlockTypeIdAt(lowerX+1, Y+1, lowerZ )] |
|
|
||||||
types[world.getBlockTypeIdAt(lowerX+1, Y , lowerZ )] ;
|
|
||||||
|
|
||||||
if((result & LIQUID) != 0) {
|
if((result & LIQUID) != 0) {
|
||||||
return SOLID; // Solid? Why that? Because that's closer to what the bug actually does than liquid
|
return SOLID; // Solid? Why that? Because that's closer to what
|
||||||
|
// the bug actually does than liquid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If nothing matches, he is somewhere in the air
|
// If nothing matches, he is somewhere in the air
|
||||||
return NONSOLID;
|
return NONSOLID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Personal Rounding function to determine if a player is still touching a block or not
|
* Personal Rounding function to determine if a player is still touching a
|
||||||
|
* block or not
|
||||||
|
*
|
||||||
* @param d1
|
* @param d1
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -151,7 +145,9 @@ public class MovingEventHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Personal Rounding function to determine if a player is still touching a block or not
|
* Personal Rounding function to determine if a player is still touching a
|
||||||
|
* block or not
|
||||||
|
*
|
||||||
* @param d1
|
* @param d1
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -20,7 +20,6 @@ import cc.co.evenprime.bukkit.nocheat.data.NukeData;
|
|||||||
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
|
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
|
||||||
import cc.co.evenprime.bukkit.nocheat.listeners.NukeBlockListener;
|
import cc.co.evenprime.bukkit.nocheat.listeners.NukeBlockListener;
|
||||||
|
|
||||||
|
|
||||||
public class NukeCheck extends Check {
|
public class NukeCheck extends Check {
|
||||||
|
|
||||||
private String kickMessage;
|
private String kickMessage;
|
||||||
@ -37,17 +36,14 @@ public class NukeCheck extends Check {
|
|||||||
@Override
|
@Override
|
||||||
protected void configure(NoCheatConfiguration config) {
|
protected void configure(NoCheatConfiguration config) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
kickMessage = config.getStringValue("nuke.kickmessage");
|
kickMessage = config.getStringValue("nuke.kickmessage");
|
||||||
logMessage = config.getStringValue("nuke.logmessage").
|
logMessage = config.getStringValue("nuke.logmessage").replace("[player]", "%1$s");
|
||||||
replace("[player]", "%1$s");
|
|
||||||
|
|
||||||
limitReach = config.getBooleanValue("nuke.limitreach");
|
limitReach = config.getBooleanValue("nuke.limitreach");
|
||||||
|
|
||||||
setActive(config.getBooleanValue("active.nuke"));
|
setActive(config.getBooleanValue("active.nuke"));
|
||||||
} catch (ConfigurationException e) {
|
} catch(ConfigurationException e) {
|
||||||
setActive(false);
|
setActive(false);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -68,9 +64,9 @@ public class NukeCheck extends Check {
|
|||||||
|
|
||||||
// Because it's not very precise on very short distances,
|
// Because it's not very precise on very short distances,
|
||||||
// consider the length of the side of a block to be 2.0 instead of 1.0
|
// consider the length of the side of a block to be 2.0 instead of 1.0
|
||||||
final double x1 = ((double)block.getX()) - eyes.getX() - 0.5;
|
final double x1 = ((double) block.getX()) - eyes.getX() - 0.5;
|
||||||
final double y1 = ((double)block.getY()) - eyes.getY() - 0.5;
|
final double y1 = ((double) block.getY()) - eyes.getY() - 0.5;
|
||||||
final double z1 = ((double)block.getZ()) - eyes.getZ() - 0.5;
|
final double z1 = ((double) block.getZ()) - eyes.getZ() - 0.5;
|
||||||
|
|
||||||
final double x2 = x1 + 2;
|
final double x2 = x1 + 2;
|
||||||
final double y2 = y1 + 2;
|
final double y2 = y1 + 2;
|
||||||
@ -80,13 +76,11 @@ public class NukeCheck extends Check {
|
|||||||
|
|
||||||
boolean tooFarAway = limitReach && factor > 4.85D;
|
boolean tooFarAway = limitReach && factor > 4.85D;
|
||||||
|
|
||||||
if(!tooFarAway && factor * direction.getX() >= x1 && factor * direction.getY() >= y1 && factor * direction.getZ() >= z1 &&
|
if(!tooFarAway && factor * direction.getX() >= x1 && factor * direction.getY() >= y1 && factor * direction.getZ() >= z1 && factor * direction.getX() <= x2 && factor * direction.getY() <= y2 && factor * direction.getZ() <= z2) {
|
||||||
factor * direction.getX() <= x2 && factor * direction.getY() <= y2 && factor * direction.getZ() <= z2) {
|
|
||||||
if(data.counter > 0) {
|
if(data.counter > 0) {
|
||||||
data.counter--;
|
data.counter--;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
data.counter++;
|
data.counter++;
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
@ -101,10 +95,8 @@ public class NukeCheck extends Check {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerListeners() {
|
protected void registerListeners() {
|
||||||
PluginManager pm = Bukkit.getServer().getPluginManager();
|
PluginManager pm = Bukkit.getServer().getPluginManager();
|
||||||
@ -115,7 +107,6 @@ public class NukeCheck extends Check {
|
|||||||
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Lowest, plugin);
|
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Lowest, plugin);
|
||||||
pm.registerEvent(Event.Type.BLOCK_DAMAGE, blockListener, Priority.Monitor, plugin);
|
pm.registerEvent(Event.Type.BLOCK_DAMAGE, blockListener, Priority.Monitor, plugin);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,7 @@ import cc.co.evenprime.bukkit.nocheat.data.MovingData;
|
|||||||
|
|
||||||
public class RunningCheck {
|
public class RunningCheck {
|
||||||
|
|
||||||
|
public RunningCheck() {}
|
||||||
public RunningCheck() { }
|
|
||||||
|
|
||||||
public double check(final Location from, final Location to, final boolean isSneaking, final boolean isSwimming, final MovingData data, MovingCheck check) {
|
public double check(final Location from, final Location to, final boolean isSneaking, final boolean isSwimming, final MovingData data, MovingCheck check) {
|
||||||
|
|
||||||
@ -15,18 +14,16 @@ public class RunningCheck {
|
|||||||
double distanceAboveLimit = 0.0D;
|
double distanceAboveLimit = 0.0D;
|
||||||
|
|
||||||
// First calculate the distance the player has moved horizontally
|
// First calculate the distance the player has moved horizontally
|
||||||
final double xDistance = from.getX()-to.getX();
|
final double xDistance = from.getX() - to.getX();
|
||||||
final double zDistance = from.getZ()-to.getZ();
|
final double zDistance = from.getZ() - to.getZ();
|
||||||
|
|
||||||
final double totalDistance = Math.sqrt((xDistance*xDistance + zDistance*zDistance));
|
final double totalDistance = Math.sqrt((xDistance * xDistance + zDistance * zDistance));
|
||||||
|
|
||||||
if(isSneaking) {
|
if(isSneaking) {
|
||||||
distanceAboveLimit = totalDistance - check.sneakWidth;
|
distanceAboveLimit = totalDistance - check.sneakWidth;
|
||||||
}
|
} else if(isSwimming) {
|
||||||
else if(isSwimming) {
|
|
||||||
distanceAboveLimit = totalDistance - check.swimWidth;
|
distanceAboveLimit = totalDistance - check.swimWidth;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
distanceAboveLimit = totalDistance - check.stepWidth;
|
distanceAboveLimit = totalDistance - check.stepWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,8 @@ import cc.co.evenprime.bukkit.nocheat.data.SpeedhackData;
|
|||||||
import cc.co.evenprime.bukkit.nocheat.listeners.SpeedhackPlayerListener;
|
import cc.co.evenprime.bukkit.nocheat.listeners.SpeedhackPlayerListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log if a player sends to many move events in a specific time frame, usually the result of tinkering with the system clock
|
* Log if a player sends to many move events in a specific time frame, usually
|
||||||
|
* the result of tinkering with the system clock
|
||||||
*
|
*
|
||||||
* @author Evenprime
|
* @author Evenprime
|
||||||
*
|
*
|
||||||
@ -47,15 +48,19 @@ public class SpeedhackCheck extends Check {
|
|||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
// Should we check at all?
|
// Should we check at all?
|
||||||
if(skipCheck(player)) return;
|
if(skipCheck(player))
|
||||||
|
return;
|
||||||
|
|
||||||
// Ignore events of players in vehicles (these can be the cause of event spam between server and client)
|
// Ignore events of players in vehicles (these can be the cause of event
|
||||||
// Ignore events if the player has positive y-Velocity (these can be the cause of event spam between server and client)
|
// spam between server and client)
|
||||||
|
// Ignore events if the player has positive y-Velocity (these can be the
|
||||||
|
// cause of event spam between server and client)
|
||||||
if(player.isInsideVehicle() || player.getVelocity().getY() > 0.0D) {
|
if(player.isInsideVehicle() || player.getVelocity().getY() > 0.0D) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// During world transfers many events of same location get sent, ignore them all
|
// During world transfers many events of same location get sent, ignore
|
||||||
|
// them all
|
||||||
if(event.getFrom().equals(event.getTo())) {
|
if(event.getFrom().equals(event.getTo())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -80,14 +85,16 @@ public class SpeedhackCheck extends Check {
|
|||||||
if(plugin.getServerLag() > 150) {
|
if(plugin.getServerLag() > 150) {
|
||||||
// Any data would likely be unreliable with that lag
|
// Any data would likely be unreliable with that lag
|
||||||
resetData(data, event.getFrom());
|
resetData(data, event.getFrom());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
|
|
||||||
int level = -1;
|
int level = -1;
|
||||||
|
|
||||||
if(data.eventsSinceLastCheck > limits[2]) level = 2;
|
if(data.eventsSinceLastCheck > limits[2])
|
||||||
else if(data.eventsSinceLastCheck > limits[1]) level = 1;
|
level = 2;
|
||||||
else if(data.eventsSinceLastCheck > limits[0]) level = 0;
|
else if(data.eventsSinceLastCheck > limits[1])
|
||||||
|
level = 1;
|
||||||
|
else if(data.eventsSinceLastCheck > limits[0])
|
||||||
|
level = 0;
|
||||||
else {
|
else {
|
||||||
resetData(data, event.getFrom());
|
resetData(data, event.getFrom());
|
||||||
}
|
}
|
||||||
@ -106,9 +113,7 @@ public class SpeedhackCheck extends Check {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data.lastCheckTicks = ticks;
|
data.lastCheckTicks = ticks;
|
||||||
}
|
} else if(data.lastCheckTicks + 10 < ticks) {
|
||||||
else if(data.lastCheckTicks + 10 < ticks)
|
|
||||||
{
|
|
||||||
// The player didn't move for the last 10 ticks
|
// The player didn't move for the last 10 ticks
|
||||||
resetData(data, event.getFrom());
|
resetData(data, event.getFrom());
|
||||||
data.lastCheckTicks = ticks;
|
data.lastCheckTicks = ticks;
|
||||||
@ -126,20 +131,19 @@ public class SpeedhackCheck extends Check {
|
|||||||
|
|
||||||
private void action(Action actions[], PlayerMoveEvent event, int violations, SpeedhackData data) {
|
private void action(Action actions[], PlayerMoveEvent event, int violations, SpeedhackData data) {
|
||||||
|
|
||||||
if(actions == null) return;
|
if(actions == null)
|
||||||
|
return;
|
||||||
|
|
||||||
for(Action a : actions) {
|
for(Action a : actions) {
|
||||||
if(a.firstAfter <= violations) {
|
if(a.firstAfter <= violations) {
|
||||||
if(a instanceof LogAction) {
|
if(a instanceof LogAction) {
|
||||||
String log = String.format(logMessage, event.getPlayer().getName(), data.eventsSinceLastCheck*2, limits[0]);
|
String log = String.format(logMessage, event.getPlayer().getName(), data.eventsSinceLastCheck * 2, limits[0]);
|
||||||
plugin.log(((LogAction)a).level, log);
|
plugin.log(((LogAction) a).level, log);
|
||||||
}
|
} else if(a.firstAfter == violations || a.repeat) {
|
||||||
else if(a.firstAfter == violations || a.repeat) {
|
|
||||||
if(a instanceof CancelAction) {
|
if(a instanceof CancelAction) {
|
||||||
resetPlayer(event, data);
|
resetPlayer(event, data);
|
||||||
}
|
} else if(a instanceof CustomAction) {
|
||||||
else if(a instanceof CustomAction) {
|
plugin.handleCustomAction((CustomAction) a, event.getPlayer());
|
||||||
plugin.handleCustomAction((CustomAction)a, event.getPlayer());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,7 +152,8 @@ public class SpeedhackCheck extends Check {
|
|||||||
|
|
||||||
private static void resetPlayer(PlayerMoveEvent event, SpeedhackData data) {
|
private static void resetPlayer(PlayerMoveEvent event, SpeedhackData data) {
|
||||||
|
|
||||||
if(data.setBackPoint == null) data.setBackPoint = event.getFrom();
|
if(data.setBackPoint == null)
|
||||||
|
data.setBackPoint = event.getFrom();
|
||||||
|
|
||||||
// If we have stored a location for the player, we put him back there
|
// If we have stored a location for the player, we put him back there
|
||||||
event.setTo(data.setBackPoint);
|
event.setTo(data.setBackPoint);
|
||||||
@ -165,8 +170,7 @@ public class SpeedhackCheck extends Check {
|
|||||||
limits[1] = config.getIntegerValue("speedhack.limits.med");
|
limits[1] = config.getIntegerValue("speedhack.limits.med");
|
||||||
limits[2] = config.getIntegerValue("speedhack.limits.high");
|
limits[2] = config.getIntegerValue("speedhack.limits.high");
|
||||||
|
|
||||||
logMessage = config.getStringValue("speedhack.logmessage").
|
logMessage = config.getStringValue("speedhack.logmessage").replace("[player]", "%1$s").replace("[events]", "%2$d").replace("[limit]", "%3$d");
|
||||||
replace("[player]", "%1$s").replace("[events]", "%2$d").replace("[limit]", "%3$d");
|
|
||||||
|
|
||||||
actions = new Action[3][];
|
actions = new Action[3][];
|
||||||
|
|
||||||
@ -175,14 +179,12 @@ public class SpeedhackCheck extends Check {
|
|||||||
actions[2] = config.getActionValue("speedhack.action.high");
|
actions[2] = config.getActionValue("speedhack.action.high");
|
||||||
|
|
||||||
setActive(config.getBooleanValue("active.speedhack"));
|
setActive(config.getBooleanValue("active.speedhack"));
|
||||||
} catch (ConfigurationException e) {
|
} catch(ConfigurationException e) {
|
||||||
setActive(false);
|
setActive(false);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void registerListeners() {
|
protected void registerListeners() {
|
||||||
PluginManager pm = Bukkit.getServer().getPluginManager();
|
PluginManager pm = Bukkit.getServer().getPluginManager();
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package cc.co.evenprime.bukkit.nocheat.config;
|
package cc.co.evenprime.bukkit.nocheat.config;
|
||||||
|
|
||||||
|
|
||||||
public class BooleanOption extends ChildOption {
|
public class BooleanOption extends ChildOption {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,7 +2,6 @@ package cc.co.evenprime.bukkit.nocheat.config;
|
|||||||
|
|
||||||
import cc.co.evenprime.bukkit.nocheat.wizard.gui.Explainations;
|
import cc.co.evenprime.bukkit.nocheat.wizard.gui.Explainations;
|
||||||
|
|
||||||
|
|
||||||
public abstract class ChildOption extends Option {
|
public abstract class ChildOption extends Option {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -14,7 +13,6 @@ public abstract class ChildOption extends Option {
|
|||||||
super(identifier);
|
super(identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public abstract String getValue();
|
public abstract String getValue();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -8,7 +8,6 @@ public class CustomActionOption extends ChildOption {
|
|||||||
private boolean repeat;
|
private boolean repeat;
|
||||||
private String command;
|
private String command;
|
||||||
|
|
||||||
|
|
||||||
public CustomActionOption(String identifier, String command) {
|
public CustomActionOption(String identifier, String command) {
|
||||||
|
|
||||||
super(identifier);
|
super(identifier);
|
||||||
@ -24,15 +23,12 @@ public class CustomActionOption extends ChildOption {
|
|||||||
firstAfter = Integer.parseInt(s2[0]);
|
firstAfter = Integer.parseInt(s2[0]);
|
||||||
repeat = Boolean.parseBoolean(s2[1]);
|
repeat = Boolean.parseBoolean(s2[1]);
|
||||||
command = s[1];
|
command = s[1];
|
||||||
}
|
} else if(com.matches("\\[[0-9]*\\] .*")) {
|
||||||
else if(com.matches("\\[[0-9]*\\] .*")) {
|
|
||||||
String s[] = com.split(" ", 2);
|
String s[] = com.split(" ", 2);
|
||||||
firstAfter = Integer.parseInt(s[0].replace("[", "").replace("]", ""));
|
firstAfter = Integer.parseInt(s[0].replace("[", "").replace("]", ""));
|
||||||
repeat = true;
|
repeat = true;
|
||||||
command = s[1];
|
command = s[1];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
firstAfter = 1;
|
firstAfter = 1;
|
||||||
repeat = true;
|
repeat = true;
|
||||||
command = com;
|
command = com;
|
||||||
@ -43,16 +39,13 @@ public class CustomActionOption extends ChildOption {
|
|||||||
public String getValue() {
|
public String getValue() {
|
||||||
if(firstAfter <= 1 && repeat) {
|
if(firstAfter <= 1 && repeat) {
|
||||||
return command;
|
return command;
|
||||||
}
|
} else if(repeat) {
|
||||||
else if(repeat) {
|
return "[" + firstAfter + "] " + command;
|
||||||
return "["+firstAfter+"] "+ command;
|
} else {
|
||||||
}
|
return "[" + firstAfter + "," + repeat + "] " + command;
|
||||||
else {
|
|
||||||
return "["+firstAfter+","+repeat+"] "+ command;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public CustomAction getCustomActionValue() {
|
public CustomAction getCustomActionValue() {
|
||||||
return new CustomAction(firstAfter, repeat, command);
|
return new CustomAction(firstAfter, repeat, command);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package cc.co.evenprime.bukkit.nocheat.config;
|
package cc.co.evenprime.bukkit.nocheat.config;
|
||||||
|
|
||||||
|
|
||||||
public class IntegerOption extends TextFieldOption {
|
public class IntegerOption extends TextFieldOption {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,13 +15,13 @@ public class IntegerOption extends TextFieldOption {
|
|||||||
@Override
|
@Override
|
||||||
public boolean isValid(String value) {
|
public boolean isValid(String value) {
|
||||||
|
|
||||||
if(!super.isValid(value)) return false;
|
if(!super.isValid(value))
|
||||||
|
return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Integer.parseInt(value);
|
Integer.parseInt(value);
|
||||||
return true;
|
return true;
|
||||||
}
|
} catch(Exception e) {
|
||||||
catch(Exception e) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package cc.co.evenprime.bukkit.nocheat.config;
|
|||||||
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
|
||||||
public class LevelOption extends ChildOption {
|
public class LevelOption extends ChildOption {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -14,11 +13,7 @@ public class LevelOption extends ChildOption {
|
|||||||
|
|
||||||
public enum LogLevel {
|
public enum LogLevel {
|
||||||
|
|
||||||
|
OFF("off", "never", Level.OFF), LOW("low", "all messages", Level.INFO), MED("med", "important messages", Level.WARNING), HIGH("high", "very important messages", Level.SEVERE);
|
||||||
OFF("off", "never", Level.OFF),
|
|
||||||
LOW("low", "all messages", Level.INFO),
|
|
||||||
MED("med", "important messages", Level.WARNING),
|
|
||||||
HIGH("high", "very important messages", Level.SEVERE);
|
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
private final String description;
|
private final String description;
|
||||||
@ -30,10 +25,13 @@ public class LevelOption extends ChildOption {
|
|||||||
this.level = level;
|
this.level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String asString() { return this.value; }
|
public String asString() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
public static LogLevel getLogLevelFromString(String s) {
|
public static LogLevel getLogLevelFromString(String s) {
|
||||||
if(s == null) return OFF;
|
if(s == null)
|
||||||
|
return OFF;
|
||||||
if("off".equals(s))
|
if("off".equals(s))
|
||||||
return OFF;
|
return OFF;
|
||||||
else if("low".equals(s))
|
else if("low".equals(s))
|
||||||
@ -46,7 +44,6 @@ public class LevelOption extends ChildOption {
|
|||||||
return OFF;
|
return OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.name() + ": " + description;
|
return this.name() + ": " + description;
|
||||||
}
|
}
|
||||||
@ -62,7 +59,6 @@ public class LevelOption extends ChildOption {
|
|||||||
this.option = initialValue;
|
this.option = initialValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return option.asString();
|
return option.asString();
|
||||||
|
@ -29,13 +29,12 @@ import cc.co.evenprime.bukkit.nocheat.yaml.SimpleYaml;
|
|||||||
*/
|
*/
|
||||||
public class NoCheatConfiguration {
|
public class NoCheatConfiguration {
|
||||||
|
|
||||||
|
|
||||||
public final static String configFile = "plugins/NoCheat/nocheat.yml";
|
public final static String configFile = "plugins/NoCheat/nocheat.yml";
|
||||||
public final static String descriptionsFile = "plugins/NoCheat/descriptions.txt";
|
public final static String descriptionsFile = "plugins/NoCheat/descriptions.txt";
|
||||||
|
|
||||||
private ParentOption root;
|
private ParentOption root;
|
||||||
|
|
||||||
private final Map<String, Action> actionMap = new HashMap<String,Action>();
|
private final Map<String, Action> actionMap = new HashMap<String, Action>();
|
||||||
|
|
||||||
private Map<String, Object> yamlContent = new HashMap<String, Object>();
|
private Map<String, Object> yamlContent = new HashMap<String, Object>();
|
||||||
|
|
||||||
@ -54,42 +53,35 @@ public class NoCheatConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the configuration file and assign either standard values or whatever is declared in the file
|
* Read the configuration file and assign either standard values or whatever
|
||||||
|
* is declared in the file
|
||||||
|
*
|
||||||
* @param configurationFile
|
* @param configurationFile
|
||||||
*/
|
*/
|
||||||
public void config(File configurationFile, File descriptionsFile) {
|
public void config(File configurationFile, File descriptionsFile) {
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
yamlContent = (Map<String, Object>) SimpleYaml.read(configurationFile);
|
yamlContent = (Map<String, Object>) SimpleYaml.read(configurationFile);
|
||||||
} catch (Exception e) {
|
} catch(Exception e) {
|
||||||
System.out.println("Couldn't use existing nocheat.yml, creating a new file.");
|
System.out.println("Couldn't use existing nocheat.yml, creating a new file.");
|
||||||
yamlContent = new HashMap<String, Object>();
|
yamlContent = new HashMap<String, Object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
root = new ParentOption("", false);
|
root = new ParentOption("", false);
|
||||||
|
|
||||||
|
|
||||||
/*** LOGGING section ***/
|
/*** LOGGING section ***/
|
||||||
{
|
{
|
||||||
ParentOption loggingNode = new ParentOption("logging", false);
|
ParentOption loggingNode = new ParentOption("logging", false);
|
||||||
root.add(loggingNode);
|
root.add(loggingNode);
|
||||||
|
|
||||||
loggingNode.add(new MediumStringOption("filename",
|
loggingNode.add(new MediumStringOption("filename", SimpleYaml.getString("logging.filename", "plugins/NoCheat/nocheat.log", yamlContent)));
|
||||||
SimpleYaml.getString("logging.filename", "plugins/NoCheat/nocheat.log", yamlContent)));
|
|
||||||
|
|
||||||
loggingNode.add(new LevelOption("logtofile",
|
loggingNode.add(new LevelOption("logtofile", LogLevel.getLogLevelFromString(SimpleYaml.getString("logging.logtofile", LogLevel.LOW.asString(), yamlContent))));
|
||||||
LogLevel.getLogLevelFromString(SimpleYaml.getString("logging.logtofile", LogLevel.LOW.asString(), yamlContent))));
|
loggingNode.add(new LevelOption("logtoconsole", LogLevel.getLogLevelFromString(SimpleYaml.getString("logging.logtoconsole", LogLevel.HIGH.asString(), yamlContent))));
|
||||||
loggingNode.add(new LevelOption("logtoconsole",
|
loggingNode.add(new LevelOption("logtochat", LogLevel.getLogLevelFromString(SimpleYaml.getString("logging.logtochat", LogLevel.MED.asString(), yamlContent))));
|
||||||
LogLevel.getLogLevelFromString(SimpleYaml.getString("logging.logtoconsole", LogLevel.HIGH.asString(), yamlContent))));
|
loggingNode.add(new LevelOption("logtoirc", LogLevel.getLogLevelFromString(SimpleYaml.getString("logging.logtoirc", LogLevel.MED.asString(), yamlContent))));
|
||||||
loggingNode.add(new LevelOption("logtochat",
|
|
||||||
LogLevel.getLogLevelFromString(SimpleYaml.getString("logging.logtochat", LogLevel.MED.asString(), yamlContent))));
|
|
||||||
loggingNode.add(new LevelOption("logtoirc",
|
|
||||||
LogLevel.getLogLevelFromString(SimpleYaml.getString("logging.logtoirc", LogLevel.MED.asString(), yamlContent))));
|
|
||||||
|
|
||||||
loggingNode.add(new ShortStringOption("logtoirctag",
|
loggingNode.add(new ShortStringOption("logtoirctag", SimpleYaml.getString("logging.logtoirctag", "nocheat", yamlContent)));
|
||||||
SimpleYaml.getString("logging.logtoirctag", "nocheat", yamlContent)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
root.add(new BooleanOption("newpermsystem", SimpleYaml.getBoolean("newpermsystem", false, yamlContent)));
|
root.add(new BooleanOption("newpermsystem", SimpleYaml.getBoolean("newpermsystem", false, yamlContent)));
|
||||||
@ -100,16 +92,11 @@ public class NoCheatConfiguration {
|
|||||||
ParentOption activeNode = new ParentOption("active", false);
|
ParentOption activeNode = new ParentOption("active", false);
|
||||||
root.add(activeNode);
|
root.add(activeNode);
|
||||||
|
|
||||||
activeNode.add(new BooleanOption("speedhack",
|
activeNode.add(new BooleanOption("speedhack", SimpleYaml.getBoolean("active.speedhack", true, yamlContent)));
|
||||||
SimpleYaml.getBoolean("active.speedhack", true, yamlContent)));
|
activeNode.add(new BooleanOption("moving", SimpleYaml.getBoolean("active.moving", true, yamlContent)));
|
||||||
activeNode.add(new BooleanOption("moving",
|
activeNode.add(new BooleanOption("airbuild", SimpleYaml.getBoolean("active.airbuild", false, yamlContent)));
|
||||||
SimpleYaml.getBoolean("active.moving", true, yamlContent)));
|
activeNode.add(new BooleanOption("bogusitems", SimpleYaml.getBoolean("active.bogusitems", false, yamlContent)));
|
||||||
activeNode.add(new BooleanOption("airbuild",
|
activeNode.add(new BooleanOption("nuke", SimpleYaml.getBoolean("active.nuke", false, yamlContent)));
|
||||||
SimpleYaml.getBoolean("active.airbuild", false, yamlContent)));
|
|
||||||
activeNode.add(new BooleanOption("bogusitems",
|
|
||||||
SimpleYaml.getBoolean("active.bogusitems", false, yamlContent)));
|
|
||||||
activeNode.add(new BooleanOption("nuke",
|
|
||||||
SimpleYaml.getBoolean("active.nuke", false, yamlContent)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** SPEEDHACK section ***/
|
/*** SPEEDHACK section ***/
|
||||||
@ -117,23 +104,18 @@ public class NoCheatConfiguration {
|
|||||||
ParentOption speedhackNode = new ParentOption("speedhack", false);
|
ParentOption speedhackNode = new ParentOption("speedhack", false);
|
||||||
root.add(speedhackNode);
|
root.add(speedhackNode);
|
||||||
|
|
||||||
speedhackNode.add(new LongStringOption("logmessage",
|
speedhackNode.add(new LongStringOption("logmessage", SimpleYaml.getString("speedhack.logmessage", "[player] sent [events] move events, but only [limit] were allowed. Speedhack?", yamlContent)));
|
||||||
SimpleYaml.getString("speedhack.logmessage", "[player] sent [events] move events, but only [limit] were allowed. Speedhack?", yamlContent)));
|
|
||||||
|
|
||||||
speedhackNode.add(new BooleanOption("checkops",
|
speedhackNode.add(new BooleanOption("checkops", SimpleYaml.getBoolean("speedhack.checkops", false, yamlContent)));
|
||||||
SimpleYaml.getBoolean("speedhack.checkops", false, yamlContent)));
|
|
||||||
|
|
||||||
/*** SPEEDHACK LIMITS section ***/
|
/*** SPEEDHACK LIMITS section ***/
|
||||||
{
|
{
|
||||||
ParentOption speedhackLimitsNode = new ParentOption("limits", false);
|
ParentOption speedhackLimitsNode = new ParentOption("limits", false);
|
||||||
speedhackNode.add(speedhackLimitsNode);
|
speedhackNode.add(speedhackLimitsNode);
|
||||||
|
|
||||||
speedhackLimitsNode.add(new IntegerOption("low",
|
speedhackLimitsNode.add(new IntegerOption("low", SimpleYaml.getInt("speedhack.limits.low", 22, yamlContent)));
|
||||||
SimpleYaml.getInt("speedhack.limits.low", 22, yamlContent)));
|
speedhackLimitsNode.add(new IntegerOption("med", SimpleYaml.getInt("speedhack.limits.med", 33, yamlContent)));
|
||||||
speedhackLimitsNode.add(new IntegerOption("med",
|
speedhackLimitsNode.add(new IntegerOption("high", SimpleYaml.getInt("speedhack.limits.high", 44, yamlContent)));
|
||||||
SimpleYaml.getInt("speedhack.limits.med", 33, yamlContent)));
|
|
||||||
speedhackLimitsNode.add(new IntegerOption("high",
|
|
||||||
SimpleYaml.getInt("speedhack.limits.high", 44, yamlContent)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** SPEEDHACK ACTIONS section ***/
|
/*** SPEEDHACK ACTIONS section ***/
|
||||||
@ -141,12 +123,9 @@ public class NoCheatConfiguration {
|
|||||||
ParentOption speedhackActionNode = new ParentOption("action", false);
|
ParentOption speedhackActionNode = new ParentOption("action", false);
|
||||||
speedhackNode.add(speedhackActionNode);
|
speedhackNode.add(speedhackActionNode);
|
||||||
|
|
||||||
speedhackActionNode.add(new MediumStringOption("low",
|
speedhackActionNode.add(new MediumStringOption("low", SimpleYaml.getString("speedhack.action.low", "loglow cancel", yamlContent)));
|
||||||
SimpleYaml.getString("speedhack.action.low", "loglow cancel", yamlContent)));
|
speedhackActionNode.add(new MediumStringOption("med", SimpleYaml.getString("speedhack.action.med", "logmed cancel", yamlContent)));
|
||||||
speedhackActionNode.add(new MediumStringOption("med",
|
speedhackActionNode.add(new MediumStringOption("high", SimpleYaml.getString("speedhack.action.high", "loghigh cancel", yamlContent)));
|
||||||
SimpleYaml.getString("speedhack.action.med", "logmed cancel", yamlContent)));
|
|
||||||
speedhackActionNode.add(new MediumStringOption("high",
|
|
||||||
SimpleYaml.getString("speedhack.action.high", "loghigh cancel", yamlContent)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,42 +134,29 @@ public class NoCheatConfiguration {
|
|||||||
ParentOption movingNode = new ParentOption("moving", false);
|
ParentOption movingNode = new ParentOption("moving", false);
|
||||||
root.add(movingNode);
|
root.add(movingNode);
|
||||||
|
|
||||||
movingNode.add(new LongStringOption("logmessage",
|
movingNode.add(new LongStringOption("logmessage", SimpleYaml.getString("moving.logmessage", "Moving violation: [player] from [world] [from] to [to] distance [distance]", yamlContent)));
|
||||||
SimpleYaml.getString("moving.logmessage", "Moving violation: [player] from [world] [from] to [to] distance [distance]", yamlContent)));
|
|
||||||
|
|
||||||
movingNode.add(new LongStringOption("summarymessage",
|
movingNode.add(new LongStringOption("summarymessage", SimpleYaml.getString("moving.summarymessage", "Moving summary of last ~[timeframe] seconds: [player] total Violations: [violations]", yamlContent)));
|
||||||
SimpleYaml.getString("moving.summarymessage", "Moving summary of last ~[timeframe] seconds: [player] total Violations: [violations]", yamlContent)));
|
|
||||||
|
|
||||||
movingNode.add(new IntegerOption("summaryafter",
|
movingNode.add(new IntegerOption("summaryafter", SimpleYaml.getInt("moving.summaryafter", 15, yamlContent)));
|
||||||
SimpleYaml.getInt("moving.summaryafter", 15, yamlContent)));
|
|
||||||
|
|
||||||
movingNode.add(new BooleanOption("allowflying",
|
movingNode.add(new BooleanOption("allowflying", SimpleYaml.getBoolean("moving.allowflying", false, yamlContent)));
|
||||||
SimpleYaml.getBoolean("moving.allowflying", false, yamlContent)));
|
movingNode.add(new BooleanOption("allowfakesneak", SimpleYaml.getBoolean("moving.allowfakesneak", true, yamlContent)));
|
||||||
movingNode.add(new BooleanOption("allowfakesneak",
|
movingNode.add(new BooleanOption("allowfastswim", SimpleYaml.getBoolean("moving.allowfastswim", false, yamlContent)));
|
||||||
SimpleYaml.getBoolean("moving.allowfakesneak", true, yamlContent)));
|
movingNode.add(new BooleanOption("waterelevators", SimpleYaml.getBoolean("moving.waterelevators", false, yamlContent)));
|
||||||
movingNode.add(new BooleanOption("allowfastswim",
|
|
||||||
SimpleYaml.getBoolean("moving.allowfastswim", false, yamlContent)));
|
|
||||||
movingNode.add(new BooleanOption("waterelevators",
|
|
||||||
SimpleYaml.getBoolean("moving.waterelevators", false, yamlContent)));
|
|
||||||
|
|
||||||
movingNode.add(new BooleanOption("checkops",
|
movingNode.add(new BooleanOption("checkops", SimpleYaml.getBoolean("moving.checkops", false, yamlContent)));
|
||||||
SimpleYaml.getBoolean("moving.checkops", false, yamlContent)));
|
|
||||||
|
|
||||||
movingNode.add(new BooleanOption("enforceteleport",
|
|
||||||
SimpleYaml.getBoolean("moving.enforceteleport", false, yamlContent)));
|
|
||||||
|
|
||||||
|
movingNode.add(new BooleanOption("enforceteleport", SimpleYaml.getBoolean("moving.enforceteleport", false, yamlContent)));
|
||||||
|
|
||||||
/*** MOVING LIMITS section ***/
|
/*** MOVING LIMITS section ***/
|
||||||
{
|
{
|
||||||
ParentOption movingLimitsNode = new ParentOption("limits", false);
|
ParentOption movingLimitsNode = new ParentOption("limits", false);
|
||||||
movingNode.add(movingLimitsNode);
|
movingNode.add(movingLimitsNode);
|
||||||
|
|
||||||
movingLimitsNode.add(new IntegerOption("walking",
|
movingLimitsNode.add(new IntegerOption("walking", SimpleYaml.getInt("moving.limits.walking", 22, yamlContent)));
|
||||||
SimpleYaml.getInt("moving.limits.walking", 22, yamlContent)));
|
movingLimitsNode.add(new IntegerOption("sneaking", SimpleYaml.getInt("moving.limits.sneaking", 14, yamlContent)));
|
||||||
movingLimitsNode.add(new IntegerOption("sneaking",
|
movingLimitsNode.add(new IntegerOption("swimming", SimpleYaml.getInt("moving.limits.swimming", 18, yamlContent)));
|
||||||
SimpleYaml.getInt("moving.limits.sneaking", 14, yamlContent)));
|
|
||||||
movingLimitsNode.add(new IntegerOption("swimming",
|
|
||||||
SimpleYaml.getInt("moving.limits.swimming", 18, yamlContent)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** MOVING ACTION section ***/
|
/*** MOVING ACTION section ***/
|
||||||
@ -198,12 +164,9 @@ public class NoCheatConfiguration {
|
|||||||
ParentOption movingActionNode = new ParentOption("action", false);
|
ParentOption movingActionNode = new ParentOption("action", false);
|
||||||
movingNode.add(movingActionNode);
|
movingNode.add(movingActionNode);
|
||||||
|
|
||||||
movingActionNode.add(new MediumStringOption("low",
|
movingActionNode.add(new MediumStringOption("low", SimpleYaml.getString("moving.action.low", "loglow cancel", yamlContent)));
|
||||||
SimpleYaml.getString("moving.action.low", "loglow cancel", yamlContent)));
|
movingActionNode.add(new MediumStringOption("med", SimpleYaml.getString("moving.action.med", "logmed cancel", yamlContent)));
|
||||||
movingActionNode.add(new MediumStringOption("med",
|
movingActionNode.add(new MediumStringOption("high", SimpleYaml.getString("moving.action.high", "loghigh cancel", yamlContent)));
|
||||||
SimpleYaml.getString("moving.action.med", "logmed cancel", yamlContent)));
|
|
||||||
movingActionNode.add(new MediumStringOption("high",
|
|
||||||
SimpleYaml.getString("moving.action.high", "loghigh cancel", yamlContent)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,20 +175,16 @@ public class NoCheatConfiguration {
|
|||||||
ParentOption airbuildNode = new ParentOption("airbuild", false);
|
ParentOption airbuildNode = new ParentOption("airbuild", false);
|
||||||
root.add(airbuildNode);
|
root.add(airbuildNode);
|
||||||
|
|
||||||
airbuildNode.add(new BooleanOption("checkops",
|
airbuildNode.add(new BooleanOption("checkops", SimpleYaml.getBoolean("airbuild.checkops", false, yamlContent)));
|
||||||
SimpleYaml.getBoolean("airbuild.checkops", false, yamlContent)));
|
|
||||||
|
|
||||||
/*** AIRBUILD LIMITS section ***/
|
/*** AIRBUILD LIMITS section ***/
|
||||||
{
|
{
|
||||||
ParentOption airbuildLimitsNode = new ParentOption("limits", false);
|
ParentOption airbuildLimitsNode = new ParentOption("limits", false);
|
||||||
airbuildNode.add(airbuildLimitsNode);
|
airbuildNode.add(airbuildLimitsNode);
|
||||||
|
|
||||||
airbuildLimitsNode.add(new IntegerOption("low",
|
airbuildLimitsNode.add(new IntegerOption("low", SimpleYaml.getInt("airbuild.limits.low", 1, yamlContent)));
|
||||||
SimpleYaml.getInt("airbuild.limits.low", 1, yamlContent)));
|
airbuildLimitsNode.add(new IntegerOption("med", SimpleYaml.getInt("airbuild.limits.med", 3, yamlContent)));
|
||||||
airbuildLimitsNode.add(new IntegerOption("med",
|
airbuildLimitsNode.add(new IntegerOption("high", SimpleYaml.getInt("airbuild.limits.high", 10, yamlContent)));
|
||||||
SimpleYaml.getInt("airbuild.limits.med", 3, yamlContent)));
|
|
||||||
airbuildLimitsNode.add(new IntegerOption("high",
|
|
||||||
SimpleYaml.getInt("airbuild.limits.high", 10, yamlContent)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** AIRBUILD ACTION section ***/
|
/*** AIRBUILD ACTION section ***/
|
||||||
@ -233,15 +192,11 @@ public class NoCheatConfiguration {
|
|||||||
ParentOption airbuildActionNode = new ParentOption("action", false);
|
ParentOption airbuildActionNode = new ParentOption("action", false);
|
||||||
airbuildNode.add(airbuildActionNode);
|
airbuildNode.add(airbuildActionNode);
|
||||||
|
|
||||||
airbuildActionNode.add(new MediumStringOption("low",
|
airbuildActionNode.add(new MediumStringOption("low", SimpleYaml.getString("airbuild.action.low", "loglow cancel", yamlContent)));
|
||||||
SimpleYaml.getString("airbuild.action.low", "loglow cancel", yamlContent)));
|
airbuildActionNode.add(new MediumStringOption("med", SimpleYaml.getString("airbuild.action.med", "logmed cancel", yamlContent)));
|
||||||
airbuildActionNode.add(new MediumStringOption("med",
|
airbuildActionNode.add(new MediumStringOption("high", SimpleYaml.getString("airbuild.action.high", "loghigh cancel", yamlContent)));
|
||||||
SimpleYaml.getString("airbuild.action.med", "logmed cancel", yamlContent)));
|
|
||||||
airbuildActionNode.add(new MediumStringOption("high",
|
|
||||||
SimpleYaml.getString("airbuild.action.high", "loghigh cancel", yamlContent)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** BOGUSITEMS section ***/
|
/*** BOGUSITEMS section ***/
|
||||||
@ -249,24 +204,18 @@ public class NoCheatConfiguration {
|
|||||||
ParentOption bogusitemsNode = new ParentOption("bogusitems", false);
|
ParentOption bogusitemsNode = new ParentOption("bogusitems", false);
|
||||||
root.add(bogusitemsNode);
|
root.add(bogusitemsNode);
|
||||||
|
|
||||||
bogusitemsNode.add(new BooleanOption("checkops",
|
bogusitemsNode.add(new BooleanOption("checkops", SimpleYaml.getBoolean("bogusitems.checkops", false, yamlContent)));
|
||||||
SimpleYaml.getBoolean("bogusitems.checkops", false, yamlContent)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*** NUKE section ***/
|
/*** NUKE section ***/
|
||||||
{
|
{
|
||||||
ParentOption nukeNode = new ParentOption("nuke", false);
|
ParentOption nukeNode = new ParentOption("nuke", false);
|
||||||
root.add(nukeNode);
|
root.add(nukeNode);
|
||||||
|
|
||||||
nukeNode.add(new BooleanOption("checkops",
|
nukeNode.add(new BooleanOption("checkops", SimpleYaml.getBoolean("nuke.checkops", false, yamlContent)));
|
||||||
SimpleYaml.getBoolean("nuke.checkops", false, yamlContent)));
|
nukeNode.add(new LongStringOption("logmessage", SimpleYaml.getString("nuke.logmessage", "Nuke: [player] tried to nuke the world", yamlContent)));
|
||||||
nukeNode.add(new LongStringOption("logmessage",
|
nukeNode.add(new LongStringOption("kickmessage", SimpleYaml.getString("nuke.kickmessage", "No nuking allowed", yamlContent)));
|
||||||
SimpleYaml.getString("nuke.logmessage", "Nuke: [player] tried to nuke the world", yamlContent)));
|
nukeNode.add(new BooleanOption("limitreach", SimpleYaml.getBoolean("nuke.limitreach", true, yamlContent)));
|
||||||
nukeNode.add(new LongStringOption("kickmessage",
|
|
||||||
SimpleYaml.getString("nuke.kickmessage", "No nuking allowed", yamlContent)));
|
|
||||||
nukeNode.add(new BooleanOption("limitreach",
|
|
||||||
SimpleYaml.getBoolean("nuke.limitreach", true, yamlContent)));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,7 +228,7 @@ public class NoCheatConfiguration {
|
|||||||
|
|
||||||
for(String s : customs) {
|
for(String s : customs) {
|
||||||
|
|
||||||
CustomActionOption o = new CustomActionOption(s, SimpleYaml.getString("customactions."+s, "unknown", yamlContent));
|
CustomActionOption o = new CustomActionOption(s, SimpleYaml.getString("customactions." + s, "unknown", yamlContent));
|
||||||
|
|
||||||
customActionsNode.add(o);
|
customActionsNode.add(o);
|
||||||
actionMap.put(s, o.getCustomActionValue());
|
actionMap.put(s, o.getCustomActionValue());
|
||||||
@ -302,7 +251,7 @@ public class NoCheatConfiguration {
|
|||||||
fh.setFormatter(new LogFileFormatter());
|
fh.setFormatter(new LogFileFormatter());
|
||||||
logger.addHandler(fh);
|
logger.addHandler(fh);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch(Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -316,7 +265,7 @@ public class NoCheatConfiguration {
|
|||||||
fh.flush();
|
fh.flush();
|
||||||
fh.close();
|
fh.close();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch(Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -338,8 +287,7 @@ public class NoCheatConfiguration {
|
|||||||
as.add(CancelAction.cancel);
|
as.add(CancelAction.cancel);
|
||||||
else if(actionMap.get(s) != null)
|
else if(actionMap.get(s) != null)
|
||||||
as.add(actionMap.get(s));
|
as.add(actionMap.get(s));
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
System.out.println("NC: Couldn't parse custom action '" + s + "'");
|
System.out.println("NC: Couldn't parse custom action '" + s + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -349,6 +297,7 @@ public class NoCheatConfiguration {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Write configuration file to specific filename
|
* Write configuration file to specific filename
|
||||||
|
*
|
||||||
* @param f
|
* @param f
|
||||||
*/
|
*/
|
||||||
public static void writeConfigFile(File f, NoCheatConfiguration configuration) {
|
public static void writeConfigFile(File f, NoCheatConfiguration configuration) {
|
||||||
@ -361,14 +310,16 @@ public class NoCheatConfiguration {
|
|||||||
|
|
||||||
w.write(configuration.getRoot().toYAMLString(""));
|
w.write(configuration.getRoot().toYAMLString(""));
|
||||||
|
|
||||||
w.flush(); w.close();
|
w.flush();
|
||||||
} catch (IOException e) {
|
w.close();
|
||||||
|
} catch(IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a file with the descriptions of all options
|
* Write a file with the descriptions of all options
|
||||||
|
*
|
||||||
* @param f
|
* @param f
|
||||||
*/
|
*/
|
||||||
private static void writeDescriptionFile(File f, NoCheatConfiguration configuration) {
|
private static void writeDescriptionFile(File f, NoCheatConfiguration configuration) {
|
||||||
@ -381,8 +332,9 @@ public class NoCheatConfiguration {
|
|||||||
|
|
||||||
w.write(configuration.getRoot().toDescriptionString(""));
|
w.write(configuration.getRoot().toDescriptionString(""));
|
||||||
|
|
||||||
w.flush(); w.close();
|
w.flush();
|
||||||
} catch (IOException e) {
|
w.close();
|
||||||
|
} catch(IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -391,15 +343,15 @@ public class NoCheatConfiguration {
|
|||||||
return stringToActions(getStringOption(optionName).getValue());
|
return stringToActions(getStringOption(optionName).getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getIntegerValue(String optionName) throws ConfigurationException {
|
public int getIntegerValue(String optionName) throws ConfigurationException {
|
||||||
return getIntegerOption(optionName).getIntegerValue();
|
return getIntegerOption(optionName).getIntegerValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private IntegerOption getIntegerOption(String optionName) throws ConfigurationException {
|
private IntegerOption getIntegerOption(String optionName) throws ConfigurationException {
|
||||||
|
|
||||||
Option o = getOption(optionName) ;
|
Option o = getOption(optionName);
|
||||||
if(o instanceof IntegerOption) {
|
if(o instanceof IntegerOption) {
|
||||||
return (IntegerOption)o;
|
return (IntegerOption) o;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ConfigurationException("Config Node " + optionName + " is not an integer");
|
throw new ConfigurationException("Config Node " + optionName + " is not an integer");
|
||||||
@ -408,11 +360,12 @@ public class NoCheatConfiguration {
|
|||||||
public String getStringValue(String optionName) throws ConfigurationException {
|
public String getStringValue(String optionName) throws ConfigurationException {
|
||||||
return getStringOption(optionName).getValue();
|
return getStringOption(optionName).getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private TextFieldOption getStringOption(String optionName) throws ConfigurationException {
|
private TextFieldOption getStringOption(String optionName) throws ConfigurationException {
|
||||||
|
|
||||||
Option o = getOption(optionName);
|
Option o = getOption(optionName);
|
||||||
if(o instanceof TextFieldOption) {
|
if(o instanceof TextFieldOption) {
|
||||||
return (TextFieldOption)o;
|
return (TextFieldOption) o;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ConfigurationException("Config Node " + optionName + " is not a string");
|
throw new ConfigurationException("Config Node " + optionName + " is not a string");
|
||||||
@ -421,17 +374,17 @@ public class NoCheatConfiguration {
|
|||||||
public Level getLogLevelValue(String optionName) throws ConfigurationException {
|
public Level getLogLevelValue(String optionName) throws ConfigurationException {
|
||||||
return getLogLevelOption(optionName).getLevelValue();
|
return getLogLevelOption(optionName).getLevelValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private LevelOption getLogLevelOption(String optionName) throws ConfigurationException {
|
private LevelOption getLogLevelOption(String optionName) throws ConfigurationException {
|
||||||
|
|
||||||
Option o = getOption(optionName);
|
Option o = getOption(optionName);
|
||||||
if(o instanceof LevelOption) {
|
if(o instanceof LevelOption) {
|
||||||
return (LevelOption)o;
|
return (LevelOption) o;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ConfigurationException("Config Node " + optionName + " is not a loglevel");
|
throw new ConfigurationException("Config Node " + optionName + " is not a loglevel");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean getBooleanValue(String optionName) throws ConfigurationException {
|
public boolean getBooleanValue(String optionName) throws ConfigurationException {
|
||||||
return getBooleanOption(optionName).getBooleanValue();
|
return getBooleanOption(optionName).getBooleanValue();
|
||||||
}
|
}
|
||||||
@ -440,13 +393,12 @@ public class NoCheatConfiguration {
|
|||||||
|
|
||||||
Option o = getOption(optionName);
|
Option o = getOption(optionName);
|
||||||
if(o instanceof BooleanOption) {
|
if(o instanceof BooleanOption) {
|
||||||
return (BooleanOption)o;
|
return (BooleanOption) o;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ConfigurationException("Config Node " + optionName + " is not a boolean");
|
throw new ConfigurationException("Config Node " + optionName + " is not a boolean");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Option getOption(String optionName) throws ConfigurationException {
|
private Option getOption(String optionName) throws ConfigurationException {
|
||||||
LinkedList<String> l = new LinkedList<String>();
|
LinkedList<String> l = new LinkedList<String>();
|
||||||
for(String s : optionName.split("\\.")) {
|
for(String s : optionName.split("\\.")) {
|
||||||
@ -459,9 +411,8 @@ public class NoCheatConfiguration {
|
|||||||
|
|
||||||
if(names.size() == 0) {
|
if(names.size() == 0) {
|
||||||
return parent;
|
return parent;
|
||||||
}
|
} else if(parent instanceof ParentOption) {
|
||||||
else if(parent instanceof ParentOption) {
|
for(Option o2 : ((ParentOption) parent).getChildOptions()) {
|
||||||
for(Option o2 : ((ParentOption)parent).getChildOptions()) {
|
|
||||||
if(o2.getIdentifier().equals(names.getFirst())) {
|
if(o2.getIdentifier().equals(names.getFirst())) {
|
||||||
|
|
||||||
names.removeFirst();
|
names.removeFirst();
|
||||||
|
@ -4,7 +4,6 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
|
||||||
public class ParentOption extends Option {
|
public class ParentOption extends Option {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,9 +47,7 @@ public class ParentOption extends Option {
|
|||||||
for(Option o : getChildOptions()) {
|
for(Option o : getChildOptions()) {
|
||||||
s += o.toYAMLString(prefix + " ");
|
s += o.toYAMLString(prefix + " ");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
for(Option o : getChildOptions()) {
|
for(Option o : getChildOptions()) {
|
||||||
s += o.toYAMLString(prefix);
|
s += o.toYAMLString(prefix);
|
||||||
}
|
}
|
||||||
@ -69,9 +66,7 @@ public class ParentOption extends Option {
|
|||||||
for(Option o : getChildOptions()) {
|
for(Option o : getChildOptions()) {
|
||||||
s += o.toDescriptionString(prefix + " ");
|
s += o.toDescriptionString(prefix + " ");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
for(Option o : getChildOptions()) {
|
for(Option o : getChildOptions()) {
|
||||||
s += o.toDescriptionString(prefix);
|
s += o.toDescriptionString(prefix);
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,7 @@ public abstract class TextFieldOption extends ChildOption {
|
|||||||
if(isValid(value)) {
|
if(isValid(value)) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
return true;
|
return true;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
package cc.co.evenprime.bukkit.nocheat.data;
|
package cc.co.evenprime.bukkit.nocheat.data;
|
||||||
|
|
||||||
|
|
||||||
public class AirbuildData {
|
public class AirbuildData {
|
||||||
|
|
||||||
public int perFiveSeconds = 0;
|
public int perFiveSeconds = 0;
|
||||||
public int summaryTask = -1;
|
public int summaryTask = -1;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,15 +7,16 @@ import net.minecraft.server.Block;
|
|||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
|
||||||
public class MovingData {
|
public class MovingData {
|
||||||
|
|
||||||
public int jumpPhase = 0;
|
public int jumpPhase = 0;
|
||||||
public final int violationsInARow[] = { 0, 0, 0 };
|
public final int violationsInARow[] = {0, 0, 0};
|
||||||
public double horizFreedom = 0.0D;
|
public double horizFreedom = 0.0D;
|
||||||
public double vertFreedom = 0.0D;
|
public double vertFreedom = 0.0D;
|
||||||
public int vertFreedomCounter = 0;
|
public int vertFreedomCounter = 0;
|
||||||
|
|
||||||
// setbackpoint is a recommendation - try to teleport to first solid block below it
|
// setbackpoint is a recommendation - try to teleport to first solid block
|
||||||
|
// below it
|
||||||
// for better effect
|
// for better effect
|
||||||
public Location setBackPoint = null;
|
public Location setBackPoint = null;
|
||||||
|
|
||||||
@ -25,8 +26,6 @@ public class MovingData {
|
|||||||
public double violationLevel = 0.0D;
|
public double violationLevel = 0.0D;
|
||||||
|
|
||||||
public Location teleportInitializedByMe = null;
|
public Location teleportInitializedByMe = null;
|
||||||
public boolean wasTeleported = true;
|
|
||||||
public Location teleportedTo;
|
|
||||||
|
|
||||||
// Block types that may need to be treated specially
|
// Block types that may need to be treated specially
|
||||||
public static final int NONSOLID = 0; // 0x00000000
|
public static final int NONSOLID = 0; // 0x00000000
|
||||||
@ -35,8 +34,8 @@ public class MovingData {
|
|||||||
public static final int LADDER = 4; // 0x00000100
|
public static final int LADDER = 4; // 0x00000100
|
||||||
public static final int FENCE = 8; // 0x00001000
|
public static final int FENCE = 8; // 0x00001000
|
||||||
|
|
||||||
|
// Until I can think of a better way to determine if a block is solid or
|
||||||
// Until I can think of a better way to determine if a block is solid or not, this is what I'll do
|
// not, this is what I'll do
|
||||||
public static final int types[] = new int[256];
|
public static final int types[] = new int[256];
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -51,19 +50,17 @@ public class MovingData {
|
|||||||
if(Block.byId[i].material.isSolid()) {
|
if(Block.byId[i].material.isSolid()) {
|
||||||
// solid blocks like STONE, CAKE, TRAPDOORS
|
// solid blocks like STONE, CAKE, TRAPDOORS
|
||||||
types[i] = SOLID;
|
types[i] = SOLID;
|
||||||
}
|
} else if(Block.byId[i].material.isLiquid()) {
|
||||||
else if(Block.byId[i].material.isLiquid()){
|
|
||||||
// WATER, LAVA
|
// WATER, LAVA
|
||||||
types[i] = LIQUID;
|
types[i] = LIQUID;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
types[i] = NONSOLID;
|
types[i] = NONSOLID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special types just for me
|
// Special types just for me
|
||||||
types[Material.LADDER.getId()]= LADDER | SOLID;
|
types[Material.LADDER.getId()] = LADDER | SOLID;
|
||||||
types[Material.FENCE.getId()]= FENCE | SOLID;
|
types[Material.FENCE.getId()] = FENCE | SOLID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package cc.co.evenprime.bukkit.nocheat.data;
|
package cc.co.evenprime.bukkit.nocheat.data;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* per player storage for data persistence between events
|
* per player storage for data persistence between events
|
||||||
*
|
*
|
||||||
@ -10,7 +9,8 @@ package cc.co.evenprime.bukkit.nocheat.data;
|
|||||||
public class NoCheatData {
|
public class NoCheatData {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Don't rely on any of these yet, they are likely going to change their name/functionality
|
* Don't rely on any of these yet, they are likely going to change their
|
||||||
|
* name/functionality
|
||||||
*/
|
*/
|
||||||
public MovingData moving;
|
public MovingData moving;
|
||||||
public SpeedhackData speedhack;
|
public SpeedhackData speedhack;
|
||||||
@ -19,5 +19,5 @@ public class NoCheatData {
|
|||||||
public PermissionData permission;
|
public PermissionData permission;
|
||||||
public NukeData nuke;
|
public NukeData nuke;
|
||||||
|
|
||||||
public NoCheatData() { }
|
public NoCheatData() {}
|
||||||
}
|
}
|
@ -4,5 +4,4 @@ public class NukeData {
|
|||||||
|
|
||||||
public int counter = 0;
|
public int counter = 0;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,10 @@ public class PermissionData {
|
|||||||
public static final int PERMISSION_FLYING = 1;
|
public static final int PERMISSION_FLYING = 1;
|
||||||
public static final int PERMISSION_SPEEDHACK = 2;
|
public static final int PERMISSION_SPEEDHACK = 2;
|
||||||
public static final int PERMISSION_AIRBUILD = 3;
|
public static final int PERMISSION_AIRBUILD = 3;
|
||||||
public static final int PERMISSION_BEDTELEPORT = 4; // No longer used
|
public static final int PERMISSION_BEDTELEPORT = 4; // unused
|
||||||
public static final int PERMISSION_BOGUSITEMS = 5;
|
public static final int PERMISSION_BOGUSITEMS = 5;
|
||||||
public static final int PERMISSION_NOTIFY = 6;
|
public static final int PERMISSION_NOTIFY = 6;
|
||||||
public static final int PERMISSION_ITEMDUPE = 7; // No longer used
|
public static final int PERMISSION_ITEMDUPE = 7; // unused
|
||||||
public static final int PERMISSION_FAKESNEAK = 8;
|
public static final int PERMISSION_FAKESNEAK = 8;
|
||||||
public static final int PERMISSION_FASTSWIM = 9;
|
public static final int PERMISSION_FASTSWIM = 9;
|
||||||
public static final int PERMISSION_NUKE = 10;
|
public static final int PERMISSION_NUKE = 10;
|
||||||
|
@ -4,10 +4,12 @@ import org.bukkit.Location;
|
|||||||
|
|
||||||
public class SpeedhackData {
|
public class SpeedhackData {
|
||||||
|
|
||||||
public int lastCheckTicks = 0; // timestamp of last check for speedhacks
|
public int lastCheckTicks = 0; // timestamp of last
|
||||||
|
// check for speedhacks
|
||||||
public Location setBackPoint = null;
|
public Location setBackPoint = null;
|
||||||
public int eventsSinceLastCheck = 0; // used to identify speedhacks
|
public int eventsSinceLastCheck = 0; // used to identify
|
||||||
public final int violationsInARow[] = { 0, 0, 0 };
|
// speedhacks
|
||||||
|
public final int violationsInARow[] = {0, 0, 0};
|
||||||
public int violationsInARowTotal = 0;
|
public int violationsInARowTotal = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ public class AirbuildBlockListener extends BlockListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
|
|
||||||
if(!event.isCancelled()) check.check(event);
|
if(!event.isCancelled())
|
||||||
|
check.check(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,8 @@ public class BogusitemsPlayerListener extends PlayerListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||||
|
|
||||||
if(!event.isCancelled()) check.check(event);
|
if(!event.isCancelled())
|
||||||
|
check.check(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -30,8 +31,8 @@ public class BogusitemsPlayerListener extends PlayerListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
|
|
||||||
if(!event.isCancelled()) check.check(event);
|
if(!event.isCancelled())
|
||||||
|
check.check(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package cc.co.evenprime.bukkit.nocheat.listeners;
|
package cc.co.evenprime.bukkit.nocheat.listeners;
|
||||||
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerListener;
|
import org.bukkit.event.player.PlayerListener;
|
||||||
@ -29,7 +28,8 @@ public class MovingPlayerListener extends PlayerListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
|
|
||||||
if(event.isCancelled()) return;
|
if(event.isCancelled())
|
||||||
|
return;
|
||||||
|
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ public class MovingPlayerListener extends PlayerListener {
|
|||||||
|
|
||||||
Location newTo = null;
|
Location newTo = null;
|
||||||
|
|
||||||
if(check.shouldBeApplied(player, data, from, to)) {
|
if(!player.isInsideVehicle()) {
|
||||||
// Check it
|
// Check it
|
||||||
newTo = check.check(player, from, to, data);
|
newTo = check.check(player, from, to, data);
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ public class MovingPlayerMonitor extends PlayerListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||||
MovingData data = dataManager.getMovingData(event.getPlayer());
|
MovingData data = dataManager.getMovingData(event.getPlayer());
|
||||||
data.wasTeleported = true;
|
|
||||||
data.setBackPoint = null;
|
data.setBackPoint = null;
|
||||||
data.jumpPhase = 0;
|
data.jumpPhase = 0;
|
||||||
}
|
}
|
||||||
@ -53,9 +52,9 @@ public class MovingPlayerMonitor extends PlayerListener {
|
|||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
|
|
||||||
if(!event.isCancelled()) {
|
if(!event.isCancelled()) {
|
||||||
if( event.getPlayer().isInsideVehicle()) {
|
if(event.getPlayer().isInsideVehicle()) {
|
||||||
MovingData data = dataManager.getMovingData(event.getPlayer());
|
MovingData data = dataManager.getMovingData(event.getPlayer());
|
||||||
data.setBackPoint = event.getTo();
|
data.setBackPoint = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,8 @@ public class NukeBlockListener extends BlockListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
//System.out.println("Break "+ event.getPlayer() + " " + event.getBlock());
|
// System.out.println("Break "+ event.getPlayer() + " " +
|
||||||
|
// event.getBlock());
|
||||||
check.check(event);
|
check.check(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,12 +22,14 @@ public class SpeedhackPlayerListener extends PlayerListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
|
|
||||||
if(!event.isCancelled()) check.check(event);
|
if(!event.isCancelled())
|
||||||
|
check.check(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||||
|
|
||||||
if(!event.isCancelled()) check.teleported(event);
|
if(!event.isCancelled())
|
||||||
|
check.teleported(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ public class Wizard extends JFrame {
|
|||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 8798111079958779207L;
|
private static final long serialVersionUID = 8798111079958779207L;
|
||||||
|
|
||||||
|
|
||||||
public Wizard() {
|
public Wizard() {
|
||||||
|
|
||||||
JScrollPane scrollable = new JScrollPane();
|
JScrollPane scrollable = new JScrollPane();
|
||||||
@ -33,7 +32,7 @@ public class Wizard extends JFrame {
|
|||||||
JPanel inside = new JPanel();
|
JPanel inside = new JPanel();
|
||||||
scrollable.setViewportView(inside);
|
scrollable.setViewportView(inside);
|
||||||
|
|
||||||
inside.setLayout(new BoxLayout(inside,BoxLayout.Y_AXIS));
|
inside.setLayout(new BoxLayout(inside, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
final NoCheatConfiguration config = new NoCheatConfiguration(new File("NoCheat/nocheat.yml"), new File("NoCheat/descriptions.txt"));
|
final NoCheatConfiguration config = new NoCheatConfiguration(new File("NoCheat/nocheat.yml"), new File("NoCheat/descriptions.txt"));
|
||||||
|
|
||||||
@ -51,7 +50,8 @@ public class Wizard extends JFrame {
|
|||||||
NoCheatConfiguration.writeConfigFile(new File("NoCheat/nocheat.yml"), config);
|
NoCheatConfiguration.writeConfigFile(new File("NoCheat/nocheat.yml"), config);
|
||||||
|
|
||||||
JOptionPane.showMessageDialog(null, "Saved");
|
JOptionPane.showMessageDialog(null, "Saved");
|
||||||
} });
|
}
|
||||||
|
});
|
||||||
|
|
||||||
b.setAlignmentY(0.0F);
|
b.setAlignmentY(0.0F);
|
||||||
inside.add(b);
|
inside.add(b);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package cc.co.evenprime.bukkit.nocheat.wizard.gui;
|
package cc.co.evenprime.bukkit.nocheat.wizard.gui;
|
||||||
|
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
@ -24,16 +23,13 @@ public class ChildOptionGuiFactory {
|
|||||||
public static JComponent create(ChildOption option) {
|
public static JComponent create(ChildOption option) {
|
||||||
|
|
||||||
if(option instanceof BooleanOption) {
|
if(option instanceof BooleanOption) {
|
||||||
return createBoolean((BooleanOption)option);
|
return createBoolean((BooleanOption) option);
|
||||||
}
|
} else if(option instanceof TextFieldOption) {
|
||||||
else if(option instanceof TextFieldOption) {
|
return createTextField((TextFieldOption) option);
|
||||||
return createTextField((TextFieldOption)option);
|
} else if(option instanceof LevelOption) {
|
||||||
}
|
return createLogLevel((LevelOption) option);
|
||||||
else if(option instanceof LevelOption) {
|
} else if(option instanceof CustomActionOption) {
|
||||||
return createLogLevel((LevelOption)option);
|
return createCustomAction((CustomActionOption) option);
|
||||||
}
|
|
||||||
else if(option instanceof CustomActionOption) {
|
|
||||||
return createCustomAction((CustomActionOption)option);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new RuntimeException("Unknown ChildOption " + option);
|
throw new RuntimeException("Unknown ChildOption " + option);
|
||||||
@ -52,7 +48,7 @@ public class ChildOptionGuiFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
option.setValue((LevelOption.LogLevel)comboBox.getSelectedItem());
|
option.setValue((LevelOption.LogLevel) comboBox.getSelectedItem());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,8 +100,7 @@ public class ChildOptionGuiFactory {
|
|||||||
value = Integer.parseInt(firstAfter.getText());
|
value = Integer.parseInt(firstAfter.getText());
|
||||||
option.setFirsttAfterValue(value);
|
option.setFirsttAfterValue(value);
|
||||||
return true;
|
return true;
|
||||||
}
|
} catch(Exception e) {
|
||||||
catch(Exception e) {
|
|
||||||
JOptionPane.showMessageDialog(firstAfter, "Illegal value for this field");
|
JOptionPane.showMessageDialog(firstAfter, "Illegal value for this field");
|
||||||
firstAfter.setText(String.valueOf(option.getFirstAfterValue()));
|
firstAfter.setText(String.valueOf(option.getFirstAfterValue()));
|
||||||
return false;
|
return false;
|
||||||
@ -149,10 +144,9 @@ public class ChildOptionGuiFactory {
|
|||||||
@Override
|
@Override
|
||||||
public boolean verify(JComponent arg0) {
|
public boolean verify(JComponent arg0) {
|
||||||
|
|
||||||
if(option.setValue(textField.getText())){
|
if(option.setValue(textField.getText())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
JOptionPane.showMessageDialog(textField, "Illegal value for this field");
|
JOptionPane.showMessageDialog(textField, "Illegal value for this field");
|
||||||
textField.setText(option.getValue());
|
textField.setText(option.getValue());
|
||||||
return false;
|
return false;
|
||||||
|
@ -36,10 +36,7 @@ public class ParentOptionGui extends JPanel {
|
|||||||
this.option = option;
|
this.option = option;
|
||||||
|
|
||||||
if(option.getIdentifier().length() > 0) {
|
if(option.getIdentifier().length() > 0) {
|
||||||
this.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createCompoundBorder(
|
this.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5), BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.BLACK), " " + option.getIdentifier() + ": "), BorderFactory.createEmptyBorder(5, 5, 5, 5))));
|
||||||
BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(2, 2,
|
|
||||||
2, 2, Color.BLACK), " " + option.getIdentifier() + ": "),
|
|
||||||
BorderFactory.createEmptyBorder(5,5,5,5))));
|
|
||||||
}
|
}
|
||||||
this.setLayout(new GridBagLayout());
|
this.setLayout(new GridBagLayout());
|
||||||
|
|
||||||
@ -77,8 +74,6 @@ public class ParentOptionGui extends JPanel {
|
|||||||
|
|
||||||
GridBagConstraints c = new GridBagConstraints();
|
GridBagConstraints c = new GridBagConstraints();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
c.gridx = 0;
|
c.gridx = 0;
|
||||||
c.gridy = line;
|
c.gridy = line;
|
||||||
c.gridwidth = 1;
|
c.gridwidth = 1;
|
||||||
@ -97,9 +92,6 @@ public class ParentOptionGui extends JPanel {
|
|||||||
c.ipady = 15;
|
c.ipady = 15;
|
||||||
c.weightx = 1;
|
c.weightx = 1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.add(p2, c);
|
this.add(p2, c);
|
||||||
line++;
|
line++;
|
||||||
}
|
}
|
||||||
@ -110,7 +102,6 @@ public class ParentOptionGui extends JPanel {
|
|||||||
line++;
|
line++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.revalidate();
|
this.revalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,17 +113,16 @@ public class ParentOptionGui extends JPanel {
|
|||||||
c.gridy = line;
|
c.gridy = line;
|
||||||
|
|
||||||
c.gridwidth = 4; // Spans over three columns
|
c.gridwidth = 4; // Spans over three columns
|
||||||
if(this.option.isEditable()) c.gridwidth = 5; // Spans over four columns
|
if(this.option.isEditable())
|
||||||
|
c.gridwidth = 5; // Spans over four columns
|
||||||
c.anchor = GridBagConstraints.WEST;
|
c.anchor = GridBagConstraints.WEST;
|
||||||
c.ipadx = 5;
|
c.ipadx = 5;
|
||||||
c.ipady = 15;
|
c.ipady = 15;
|
||||||
c.weightx = 1;
|
c.weightx = 1;
|
||||||
c.fill = GridBagConstraints.HORIZONTAL;
|
c.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
|
||||||
this.add(new ParentOptionGui((ParentOption)child), c);
|
this.add(new ParentOptionGui((ParentOption) child), c);
|
||||||
}
|
} else if(child instanceof ChildOption) {
|
||||||
else if(child instanceof ChildOption)
|
|
||||||
{
|
|
||||||
GridBagConstraints c = new GridBagConstraints();
|
GridBagConstraints c = new GridBagConstraints();
|
||||||
|
|
||||||
c.gridx = 0;
|
c.gridx = 0;
|
||||||
@ -152,7 +142,7 @@ public class ParentOptionGui extends JPanel {
|
|||||||
c.weightx = 0;
|
c.weightx = 0;
|
||||||
c.fill = GridBagConstraints.HORIZONTAL;
|
c.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
|
||||||
JComponent tmp = ChildOptionGuiFactory.create((ChildOption)child);
|
JComponent tmp = ChildOptionGuiFactory.create((ChildOption) child);
|
||||||
|
|
||||||
this.add(tmp, c);
|
this.add(tmp, c);
|
||||||
|
|
||||||
@ -171,7 +161,7 @@ public class ParentOptionGui extends JPanel {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
|
|
||||||
JOptionPane.showMessageDialog(null, Explainations.get(((ChildOption)child).getFullIdentifier()), "Description of "+ ((ChildOption)child).getFullIdentifier(), JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, Explainations.get(((ChildOption) child).getFullIdentifier()), "Description of " + ((ChildOption) child).getFullIdentifier(), JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@ public class SimpleYaml {
|
|||||||
|
|
||||||
private SimpleYaml() {}
|
private SimpleYaml() {}
|
||||||
|
|
||||||
|
|
||||||
public static Map<String, Object> read(File file) throws IOException {
|
public static Map<String, Object> read(File file) throws IOException {
|
||||||
|
|
||||||
Map<String, Object> root = new HashMap<String, Object>();
|
Map<String, Object> root = new HashMap<String, Object>();
|
||||||
@ -34,7 +33,7 @@ public class SimpleYaml {
|
|||||||
|
|
||||||
String line = null;
|
String line = null;
|
||||||
|
|
||||||
while(( line = r.readLine()) != null) {
|
while((line = r.readLine()) != null) {
|
||||||
lines.add(line);
|
lines.add(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,23 +49,23 @@ public class SimpleYaml {
|
|||||||
|
|
||||||
while(!lines.isEmpty()) {
|
while(!lines.isEmpty()) {
|
||||||
line = lines.getFirst();
|
line = lines.getFirst();
|
||||||
if(line.trim().startsWith("#")) { lines.removeFirst(); }
|
if(line.trim().startsWith("#")) {
|
||||||
else if(line.trim().isEmpty()) { lines.removeFirst(); }
|
lines.removeFirst();
|
||||||
else if(line.startsWith(prefix)) {
|
} else if(line.trim().isEmpty()) {
|
||||||
|
lines.removeFirst();
|
||||||
|
} else if(line.startsWith(prefix)) {
|
||||||
lines.removeFirst();
|
lines.removeFirst();
|
||||||
if(line.contains(":")) {
|
if(line.contains(":")) {
|
||||||
String pair[] = line.split(":", 2);
|
String pair[] = line.split(":", 2);
|
||||||
if(pair[1].trim().isEmpty()) {
|
if(pair[1].trim().isEmpty()) {
|
||||||
Map<String, Object> m = new HashMap<String, Object>();
|
Map<String, Object> m = new HashMap<String, Object>();
|
||||||
root.put(pair[0].trim(), parse(m, lines, prefix + SimpleYaml.prefix));
|
root.put(pair[0].trim(), parse(m, lines, prefix + SimpleYaml.prefix));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
root.put(pair[0].trim(), removeQuotationMarks(pair[1].trim()));
|
root.put(pair[0].trim(), removeQuotationMarks(pair[1].trim()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
@ -74,10 +73,9 @@ public class SimpleYaml {
|
|||||||
|
|
||||||
private static String removeQuotationMarks(String s) {
|
private static String removeQuotationMarks(String s) {
|
||||||
if(s.startsWith("\"") && s.endsWith("\"")) {
|
if(s.startsWith("\"") && s.endsWith("\"")) {
|
||||||
return s.substring(1, s.length() -1);
|
return s.substring(1, s.length() - 1);
|
||||||
}
|
} else if(s.startsWith("\'") && s.endsWith("\'")) {
|
||||||
else if(s.startsWith("\'") && s.endsWith("\'")) {
|
return s.substring(1, s.length() - 1);
|
||||||
return s.substring(1, s.length() -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
@ -88,11 +86,9 @@ public class SimpleYaml {
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private final static Object getProperty(String path, Map<String, Object> node) {
|
private final static Object getProperty(String path, Map<String, Object> node) {
|
||||||
if (!path.contains(".")) {
|
if(!path.contains(".")) {
|
||||||
return node.get(path);
|
return node.get(path);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
String[] parts = path.split("\\.", 2);
|
String[] parts = path.split("\\.", 2);
|
||||||
return getProperty(parts[1], (Map<String, Object>) node.get(parts[0]));
|
return getProperty(parts[1], (Map<String, Object>) node.get(parts[0]));
|
||||||
}
|
}
|
||||||
@ -101,37 +97,33 @@ public class SimpleYaml {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static Set<String> getKeys(String path, Map<String, Object> node) {
|
public static Set<String> getKeys(String path, Map<String, Object> node) {
|
||||||
try {
|
try {
|
||||||
return ((Map<String, Object>)getProperty(path, node)).keySet();
|
return ((Map<String, Object>) getProperty(path, node)).keySet();
|
||||||
}
|
} catch(Exception e) {
|
||||||
catch(Exception e) {
|
// e.printStackTrace();
|
||||||
//e.printStackTrace();
|
|
||||||
return new HashSet<String>();
|
return new HashSet<String>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getInt(String path, int defaultValue, Map<String, Object> node) {
|
public static int getInt(String path, int defaultValue, Map<String, Object> node) {
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt((String)getProperty(path, node));
|
return Integer.parseInt((String) getProperty(path, node));
|
||||||
}
|
} catch(Exception e) {
|
||||||
catch(Exception e) {
|
// e.printStackTrace();
|
||||||
//e.printStackTrace();
|
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getBoolean(String path, boolean defaultValue, Map<String, Object> node) {
|
public static boolean getBoolean(String path, boolean defaultValue, Map<String, Object> node) {
|
||||||
try {
|
try {
|
||||||
if(((String)getProperty(path, node)).equals("true")) {
|
if(((String) getProperty(path, node)).equals("true")) {
|
||||||
return true;
|
return true;
|
||||||
} else if(((String)getProperty(path, node)).equals("false")) {
|
} else if(((String) getProperty(path, node)).equals("false")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
} catch(Exception e) {
|
||||||
catch(Exception e) {
|
// e.printStackTrace();
|
||||||
//e.printStackTrace();
|
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,10 +131,10 @@ public class SimpleYaml {
|
|||||||
public static String getString(String path, String defaultValue, Map<String, Object> node) {
|
public static String getString(String path, String defaultValue, Map<String, Object> node) {
|
||||||
try {
|
try {
|
||||||
String result = (String) getProperty(path, node);
|
String result = (String) getProperty(path, node);
|
||||||
if(result == null) return defaultValue;
|
if(result == null)
|
||||||
|
return defaultValue;
|
||||||
return result;
|
return result;
|
||||||
}
|
} catch(Exception e) {
|
||||||
catch(Exception e) {
|
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user