mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-20 06:21:23 +01:00
Added Metrics support!
This commit is contained in:
parent
e585e918fd
commit
dde0f74003
@ -12,6 +12,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.ExecuteActionsEvent;
|
||||
import fr.neatmonster.nocheatplus.checks.Workarounds;
|
||||
import fr.neatmonster.nocheatplus.checks.blockbreak.BlockBreakListener;
|
||||
@ -23,6 +24,10 @@ import fr.neatmonster.nocheatplus.checks.inventory.InventoryListener;
|
||||
import fr.neatmonster.nocheatplus.checks.moving.MovingListener;
|
||||
import fr.neatmonster.nocheatplus.config.ConfPaths;
|
||||
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
||||
import fr.neatmonster.nocheatplus.metrics.Metrics;
|
||||
import fr.neatmonster.nocheatplus.metrics.Metrics.Graph;
|
||||
import fr.neatmonster.nocheatplus.metrics.Metrics.Plotter;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.packets.PacketsWorkaround;
|
||||
import fr.neatmonster.nocheatplus.players.Permissions;
|
||||
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
|
||||
@ -102,6 +107,47 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
|
||||
// Register the commands handler.
|
||||
getCommand("nocheatplus").setExecutor(new CommandHandler(this));
|
||||
|
||||
// Start Metrics.
|
||||
try {
|
||||
final Metrics metrics = new Metrics(this);
|
||||
final Graph eventsChecked = metrics.createGraph("Events Checked");
|
||||
final Graph checksFailed = metrics.createGraph("Checks Failed");
|
||||
final Graph violationLevels = metrics.createGraph("Violation Levels");
|
||||
for (final CheckType type : CheckType.values())
|
||||
if (type == CheckType.ALL || type.getParent() != null) {
|
||||
eventsChecked.addPlotter(new Plotter(type.name()) {
|
||||
|
||||
@Override
|
||||
public int getValue() {
|
||||
return MetricsData.getChecked(type);
|
||||
}
|
||||
});
|
||||
checksFailed.addPlotter(new Plotter(type.name()) {
|
||||
|
||||
@Override
|
||||
public int getValue() {
|
||||
return MetricsData.getFailed(type);
|
||||
}
|
||||
});
|
||||
violationLevels.addPlotter(new Plotter(type.name()) {
|
||||
|
||||
@Override
|
||||
public int getValue() {
|
||||
return (int) MetricsData.getViolationLevel(type);
|
||||
}
|
||||
});
|
||||
}
|
||||
final Graph serverTicks = metrics.createGraph("Server Ticks");
|
||||
serverTicks.addPlotter(new Plotter("" + LagMeasureTask.getAverageTicks()) {
|
||||
|
||||
@Override
|
||||
public int getValue() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
metrics.start();
|
||||
} catch (final Exception e) {}
|
||||
|
||||
// Tell the server administrator that we finished loading NoCheatPlus now.
|
||||
System.out.println("[NoCheatPlus] Version " + getDescription().getVersion() + " is enabled.");
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import fr.neatmonster.nocheatplus.actions.Action;
|
||||
import fr.neatmonster.nocheatplus.actions.ParameterName;
|
||||
import fr.neatmonster.nocheatplus.actions.types.ActionList;
|
||||
import fr.neatmonster.nocheatplus.hooks.NCPHookManager;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.players.ExecutionHistory;
|
||||
|
||||
/*
|
||||
@ -60,18 +61,17 @@ public abstract class Check {
|
||||
*
|
||||
* @param player
|
||||
* the player
|
||||
* @param VL
|
||||
* the vL
|
||||
* @param VLAdded
|
||||
* the vL added
|
||||
* @param vL
|
||||
* the violation level
|
||||
* @param addedVL
|
||||
* the violation level added
|
||||
* @param actions
|
||||
* the actions
|
||||
* @return true, if the event should be cancelled
|
||||
*/
|
||||
protected boolean executeActions(final Player player, final double VL, final double VLAdded,
|
||||
protected boolean executeActions(final Player player, final double vL, final double addedVL,
|
||||
final ActionList actions) {
|
||||
ViolationHistory.getHistory(player).log(getClass().getName(), VLAdded);
|
||||
return executeActions(new ViolationData(this, player, VL, actions));
|
||||
return executeActions(new ViolationData(this, player, vL, addedVL, actions));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,6 +82,8 @@ public abstract class Check {
|
||||
* @return true, if the event should be cancelled
|
||||
*/
|
||||
protected boolean executeActions(final ViolationData violationData) {
|
||||
MetricsData.addViolation(violationData);
|
||||
ViolationHistory.getHistory(violationData.player).log(getClass().getName(), violationData.addedVL);
|
||||
try {
|
||||
// Check a bypass permission.
|
||||
if (violationData.bypassPermission != null)
|
||||
@ -94,7 +96,6 @@ public abstract class Check {
|
||||
return false;
|
||||
|
||||
final long time = System.currentTimeMillis() / 1000L;
|
||||
|
||||
boolean cancel = false;
|
||||
for (final Action action : violationData.getActions())
|
||||
if (getHistory(violationData.player).executeAction(violationData, action, time))
|
||||
@ -114,21 +115,20 @@ public abstract class Check {
|
||||
*
|
||||
* @param player
|
||||
* the player
|
||||
* @param VL
|
||||
* the vL
|
||||
* @param VLAdded
|
||||
* the vL added
|
||||
* @param vL
|
||||
* the violation level
|
||||
* @param addedVL
|
||||
* the violation level added
|
||||
* @param actions
|
||||
* the actions
|
||||
* @param bypassPermission
|
||||
* the bypass permission
|
||||
* @return true, if the event should be cancelled
|
||||
*/
|
||||
public boolean executeActionsThreadSafe(final Player player, final double VL, final double VLAdded,
|
||||
public boolean executeActionsThreadSafe(final Player player, final double vL, final double addedVL,
|
||||
final ActionList actions, final String bypassPermission) {
|
||||
ViolationHistory.getHistory(player).log(getClass().getName(), VLAdded);
|
||||
// Sync it into the main thread by using an event.
|
||||
return executeActionsThreadSafe(new ViolationData(this, player, VL, actions, bypassPermission));
|
||||
return executeActionsThreadSafe(new ViolationData(this, player, vL, addedVL, actions, bypassPermission));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,7 +161,7 @@ public abstract class Check {
|
||||
return violationData.player.getName();
|
||||
else if (wildcard == ParameterName.VIOLATIONS) {
|
||||
try {
|
||||
return "" + Math.round(violationData.violationLevel);
|
||||
return "" + Math.round(violationData.vL);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -25,6 +25,9 @@ public class ViolationData {
|
||||
/** The actions to be executed. */
|
||||
public final ActionList actions;
|
||||
|
||||
/** The violation level added. */
|
||||
public final double addedVL;
|
||||
|
||||
/** The bypassing permission. */
|
||||
public final String bypassPermission;
|
||||
|
||||
@ -35,7 +38,7 @@ public class ViolationData {
|
||||
public final Player player;
|
||||
|
||||
/** The violation level. */
|
||||
public final double violationLevel;
|
||||
public final double vL;
|
||||
|
||||
/**
|
||||
* Instantiates a new violation data.
|
||||
@ -44,13 +47,16 @@ public class ViolationData {
|
||||
* the check
|
||||
* @param player
|
||||
* the player
|
||||
* @param violationLevel
|
||||
* @param vL
|
||||
* the violation level
|
||||
* @param addedVL
|
||||
* the violation level added
|
||||
* @param actions
|
||||
* the actions
|
||||
*/
|
||||
public ViolationData(final Check check, final Player player, final double violationLevel, final ActionList actions) {
|
||||
this(check, player, violationLevel, actions, null);
|
||||
public ViolationData(final Check check, final Player player, final double vL, final double addedVL,
|
||||
final ActionList actions) {
|
||||
this(check, player, vL, addedVL, actions, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,18 +66,21 @@ public class ViolationData {
|
||||
* the check
|
||||
* @param player
|
||||
* the player
|
||||
* @param violationLevel
|
||||
* @param vL
|
||||
* the violation level
|
||||
* @param addedVL
|
||||
* the violation level added
|
||||
* @param actions
|
||||
* the actions
|
||||
* @param bypassPermission
|
||||
* the permission to bypass the execution, if not null
|
||||
*/
|
||||
public ViolationData(final Check check, final Player player, final double violationLevel, final ActionList actions,
|
||||
final String bypassPermission) {
|
||||
public ViolationData(final Check check, final Player player, final double vL, final double addedVL,
|
||||
final ActionList actions, final String bypassPermission) {
|
||||
this.check = check;
|
||||
this.player = player;
|
||||
this.violationLevel = violationLevel;
|
||||
this.vL = vL;
|
||||
this.addedVL = addedVL;
|
||||
this.actions = actions;
|
||||
this.bypassPermission = bypassPermission;
|
||||
}
|
||||
@ -82,6 +91,6 @@ public class ViolationData {
|
||||
* @return the actions
|
||||
*/
|
||||
public Action[] getActions() {
|
||||
return actions.getActions(violationLevel);
|
||||
return actions.getActions(vL);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import org.bukkit.util.Vector;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
|
||||
|
||||
/*
|
||||
@ -39,6 +40,9 @@ public class Direction extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final Location location) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final BlockBreakData data = BlockBreakData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
|
||||
/*
|
||||
* MM""""""""`M dP M#"""""""'M dP
|
||||
@ -48,6 +49,9 @@ public class FastBreak extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final Block block) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final BlockBreakConfig cc = BlockBreakConfig.getConfig(player);
|
||||
final BlockBreakData data = BlockBreakData.getData(player);
|
||||
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
|
||||
/*
|
||||
* M"""""""`YM MP""""""`MM oo
|
||||
@ -35,6 +36,9 @@ public class NoSwing extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final BlockBreakData data = BlockBreakData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -8,6 +8,7 @@ import fr.neatmonster.nocheatplus.actions.ParameterName;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
|
||||
|
||||
/*
|
||||
@ -47,6 +48,9 @@ public class Reach extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final Location location) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final BlockBreakData data = BlockBreakData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -6,6 +6,7 @@ import org.bukkit.util.Vector;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
|
||||
|
||||
/*
|
||||
@ -39,6 +40,9 @@ public class Direction extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final Location location) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final BlockInteractData data = BlockInteractData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -8,6 +8,7 @@ import fr.neatmonster.nocheatplus.actions.ParameterName;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
|
||||
|
||||
/*
|
||||
@ -47,6 +48,9 @@ public class Reach extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final Location location) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final BlockInteractData data = BlockInteractData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -6,6 +6,7 @@ import org.bukkit.util.Vector;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
|
||||
|
||||
/*
|
||||
@ -39,6 +40,9 @@ public class Direction extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final Location placed, final Location against) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final BlockPlaceData data = BlockPlaceData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -5,6 +5,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
|
||||
|
||||
/*
|
||||
@ -38,6 +39,9 @@ public class FastPlace extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final Block block) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final BlockPlaceConfig cc = BlockPlaceConfig.getConfig(player);
|
||||
final BlockPlaceData data = BlockPlaceData.getData(player);
|
||||
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
|
||||
/*
|
||||
* M"""""""`YM MP""""""`MM oo
|
||||
@ -35,6 +36,9 @@ public class NoSwing extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final BlockPlaceData data = BlockPlaceData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -8,6 +8,7 @@ import fr.neatmonster.nocheatplus.actions.ParameterName;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
|
||||
|
||||
/*
|
||||
@ -47,6 +48,9 @@ public class Reach extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final Location location) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final BlockPlaceData data = BlockPlaceData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
|
||||
/*
|
||||
* MP""""""`MM dP
|
||||
@ -35,6 +36,9 @@ public class Speed extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final BlockPlaceConfig cc = BlockPlaceConfig.getConfig(player);
|
||||
final BlockPlaceData data = BlockPlaceData.getData(player);
|
||||
|
||||
|
@ -5,6 +5,7 @@ import org.bukkit.entity.Player;
|
||||
import fr.neatmonster.nocheatplus.actions.types.ActionList;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
|
||||
/*
|
||||
* MM'""""'YMM dP
|
||||
@ -47,6 +48,9 @@ public class Color extends Check {
|
||||
// Leave out the permission check.
|
||||
return message;
|
||||
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final ChatData data = ChatData.getData(player);
|
||||
// Keep related to ChatData/NoPwnage/Color used lock.
|
||||
synchronized (data) {
|
||||
|
@ -13,6 +13,7 @@ import fr.neatmonster.nocheatplus.actions.types.ActionList;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
|
||||
|
||||
/*
|
||||
@ -73,6 +74,9 @@ public class NoPwnage extends Check {
|
||||
if (!isMainThread && !cc.isEnabled(type))
|
||||
return false;
|
||||
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
// Keep related to ChatData/NoPwnage/Color used lock.
|
||||
synchronized (data) {
|
||||
return unsafeCheck(player, event, isMainThread, cc, data);
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
|
||||
|
||||
/*
|
||||
@ -41,6 +42,9 @@ public class Angle extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final FightConfig cc = FightConfig.getConfig(player);
|
||||
final FightData data = FightData.getData(player);
|
||||
|
||||
|
@ -5,6 +5,7 @@ import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
|
||||
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
|
||||
|
||||
@ -37,6 +38,9 @@ public class Critical extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final FightConfig cc = FightConfig.getConfig(player);
|
||||
final FightData data = FightData.getData(player);
|
||||
|
||||
|
@ -10,6 +10,7 @@ import org.bukkit.util.Vector;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
|
||||
|
||||
/*
|
||||
@ -43,6 +44,9 @@ public class Direction extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final Entity damaged) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final FightConfig cc = FightConfig.getConfig(player);
|
||||
final FightData data = FightData.getData(player);
|
||||
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
|
||||
import fr.neatmonster.nocheatplus.NoCheatPlus;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
|
||||
/*
|
||||
* MM'"""""`MM dP M"""""`'"""`YM dP
|
||||
@ -39,6 +40,9 @@ public class GodMode extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final FightData data = FightData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
|
||||
/*
|
||||
* M""M dP dP M""MMMMM""MM dP
|
||||
@ -34,6 +35,9 @@ public class InstantHeal extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final FightData data = FightData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -5,6 +5,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
|
||||
|
||||
/*
|
||||
@ -36,6 +37,9 @@ public class Knockback extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final FightConfig cc = FightConfig.getConfig(player);
|
||||
final FightData data = FightData.getData(player);
|
||||
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
|
||||
/*
|
||||
* M"""""""`YM MP""""""`MM oo
|
||||
@ -35,6 +36,9 @@ public class NoSwing extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final FightData data = FightData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
|
||||
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
|
||||
|
||||
@ -47,6 +48,9 @@ public class Reach extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final Entity damaged) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final FightConfig cc = FightConfig.getConfig(player);
|
||||
final FightData data = FightData.getData(player);
|
||||
|
||||
|
@ -6,6 +6,7 @@ import fr.neatmonster.nocheatplus.actions.ParameterName;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
|
||||
|
||||
/*
|
||||
@ -38,6 +39,9 @@ public class Speed extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final FightConfig cc = FightConfig.getConfig(player);
|
||||
final FightData data = FightData.getData(player);
|
||||
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
|
||||
/*
|
||||
* M""""""'YMM
|
||||
@ -35,6 +36,9 @@ public class Drop extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final InventoryConfig cc = InventoryConfig.getConfig(player);
|
||||
final InventoryData data = InventoryData.getData(player);
|
||||
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
|
||||
/*
|
||||
* M""M dP dP M#"""""""'M
|
||||
@ -36,6 +37,9 @@ public class InstantBow extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final float force) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final InventoryData data = InventoryData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -6,6 +6,7 @@ import fr.neatmonster.nocheatplus.actions.ParameterName;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
|
||||
/*
|
||||
* M""M dP dP MM""""""""`M dP
|
||||
@ -38,6 +39,9 @@ public class InstantEat extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final int level) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final InventoryData data = InventoryData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -13,6 +13,7 @@ import fr.neatmonster.nocheatplus.actions.ParameterName;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
|
||||
|
||||
/*
|
||||
@ -56,6 +57,9 @@ public class CreativeFly extends Check {
|
||||
* @return the location
|
||||
*/
|
||||
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final MovingConfig cc = MovingConfig.getConfig(player);
|
||||
final MovingData data = MovingData.getData(player);
|
||||
|
||||
@ -132,8 +136,7 @@ public class CreativeFly extends Check {
|
||||
data.creativeFlyVL += result;
|
||||
|
||||
// Execute whatever actions are associated with this check and the violation level and find out if we
|
||||
// should
|
||||
// cancel the event.
|
||||
// should cancel the event.
|
||||
if (executeActions(player, data.creativeFlyVL, result, cc.creativeFlyActions))
|
||||
// Compose a new location based on coordinates of "newTo" and viewing direction of "event.getTo()"
|
||||
// to allow the player to look somewhere else despite getting pulled back by NoCheatPlus.
|
||||
|
@ -7,6 +7,7 @@ import fr.neatmonster.nocheatplus.actions.ParameterName;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
|
||||
|
||||
/*
|
||||
@ -59,6 +60,9 @@ public class MorePackets extends Check {
|
||||
* @return the location
|
||||
*/
|
||||
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final MovingData data = MovingData.getData(player);
|
||||
|
||||
Location newTo = null;
|
||||
|
@ -7,6 +7,7 @@ import fr.neatmonster.nocheatplus.actions.ParameterName;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
|
||||
/*
|
||||
* M"""""`'"""`YM MM"""""""`YM dP dP
|
||||
@ -58,6 +59,9 @@ public class MorePacketsVehicle extends Check {
|
||||
* @return the location
|
||||
*/
|
||||
public Location check(final Player player, final Location from, final Location to) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final MovingData data = MovingData.getData(player);
|
||||
|
||||
Location newTo = null;
|
||||
|
@ -172,9 +172,10 @@ public class MovingListener implements Listener {
|
||||
* |___/
|
||||
*/
|
||||
final Player player = event.getPlayer();
|
||||
final MovingData data = MovingData.getData(player);
|
||||
if (survivalFly.isEnabled(player) && survivalFly.check(player))
|
||||
// To cancel the event, we simply teleport the player to his last safe location.
|
||||
player.teleport(MovingData.getData(player).lastSafeLocations[1]);
|
||||
player.teleport(data.lastSafeLocations[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -367,6 +368,7 @@ public class MovingListener implements Listener {
|
||||
if (newTo != null) {
|
||||
// Yes, so set it.
|
||||
event.setTo(newTo);
|
||||
|
||||
// Remember where we send the player to.
|
||||
data.teleported = newTo;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import fr.neatmonster.nocheatplus.actions.ParameterName;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
|
||||
|
||||
/*
|
||||
@ -45,6 +46,9 @@ public class NoFall extends Check {
|
||||
* the to
|
||||
*/
|
||||
public void check(final Player player, final PlayerLocation from, final PlayerLocation to) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final MovingConfig cc = MovingConfig.getConfig(player);
|
||||
final MovingData data = MovingData.getData(player);
|
||||
|
||||
|
@ -13,6 +13,7 @@ import fr.neatmonster.nocheatplus.actions.ParameterName;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
||||
import fr.neatmonster.nocheatplus.metrics.MetricsData;
|
||||
import fr.neatmonster.nocheatplus.players.Permissions;
|
||||
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
|
||||
|
||||
@ -48,6 +49,9 @@ public class SurvivalFly extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
// Metrics data.
|
||||
MetricsData.addChecked(type);
|
||||
|
||||
final MovingData data = MovingData.getData(player);
|
||||
|
||||
// Check if the player has entered the bed he is trying to leave.
|
||||
|
@ -87,6 +87,9 @@ public class ConfigManager {
|
||||
/** The file handler. */
|
||||
private static FileHandler fileHandler = null;
|
||||
|
||||
/** The log file. */
|
||||
public static File logFile = null;
|
||||
|
||||
/**
|
||||
* Cleanup.
|
||||
*/
|
||||
@ -166,7 +169,7 @@ public class ConfigManager {
|
||||
fileHandler = null;
|
||||
}
|
||||
|
||||
final File logFile = new File(folder, global.getString(ConfPaths.LOGGING_FILENAME));
|
||||
logFile = new File(folder, global.getString(ConfPaths.LOGGING_FILENAME));
|
||||
try {
|
||||
try {
|
||||
logFile.getParentFile().mkdirs();
|
||||
|
627
src/fr/neatmonster/nocheatplus/metrics/Metrics.java
Normal file
627
src/fr/neatmonster/nocheatplus/metrics/Metrics.java
Normal file
@ -0,0 +1,627 @@
|
||||
/*
|
||||
* Copyright 2011 Tyler Blair. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and contributors and should not be interpreted as representing official policies,
|
||||
* either expressed or implied, of anybody else.
|
||||
*/
|
||||
|
||||
package fr.neatmonster.nocheatplus.metrics;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The metrics class obtains data about a plugin and submits statistics about it to the metrics backend.
|
||||
* </p>
|
||||
* <p>
|
||||
* Public methods provided by this class:
|
||||
* </p>
|
||||
* <code>
|
||||
* Graph createGraph(String name); <br/>
|
||||
* void addCustomData(Metrics.Plotter plotter); <br/>
|
||||
* void start(); <br/>
|
||||
* </code>
|
||||
*/
|
||||
public class Metrics {
|
||||
|
||||
/**
|
||||
* Represents a custom graph on the website
|
||||
*/
|
||||
public static class Graph {
|
||||
|
||||
/**
|
||||
* The graph's name, alphanumeric and spaces only :) If it does not comply to the above when submitted, it is
|
||||
* rejected
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The set of plotters that are contained within this graph
|
||||
*/
|
||||
private final Set<Plotter> plotters = new LinkedHashSet<Plotter>();
|
||||
|
||||
private Graph(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a plotter to the graph, which will be used to plot entries
|
||||
*
|
||||
* @param plotter
|
||||
* the plotter to add to the graph
|
||||
*/
|
||||
public void addPlotter(final Plotter plotter) {
|
||||
plotters.add(plotter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object object) {
|
||||
if (!(object instanceof Graph))
|
||||
return false;
|
||||
|
||||
final Graph graph = (Graph) object;
|
||||
return graph.name.equals(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the graph's name
|
||||
*
|
||||
* @return the Graph's name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an <b>unmodifiable</b> set of the plotter objects in the graph
|
||||
*
|
||||
* @return an unmodifiable {@link Set} of the plotter objects
|
||||
*/
|
||||
public Set<Plotter> getPlotters() {
|
||||
return Collections.unmodifiableSet(plotters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return name.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the server owner decides to opt-out of Metrics while the server is running.
|
||||
*/
|
||||
protected void onOptOut() {}
|
||||
|
||||
/**
|
||||
* Remove a plotter from the graph
|
||||
*
|
||||
* @param plotter
|
||||
* the plotter to remove from the graph
|
||||
*/
|
||||
public void removePlotter(final Plotter plotter) {
|
||||
plotters.remove(plotter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface used to collect custom data for a plugin
|
||||
*/
|
||||
public static abstract class Plotter {
|
||||
|
||||
/**
|
||||
* The plot's name
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Construct a plotter with the default plot name
|
||||
*/
|
||||
public Plotter() {
|
||||
this("Default");
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a plotter with a specific plot name
|
||||
*
|
||||
* @param name
|
||||
* the name of the plotter to use, which will show up on the website
|
||||
*/
|
||||
public Plotter(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object object) {
|
||||
if (!(object instanceof Plotter))
|
||||
return false;
|
||||
|
||||
final Plotter plotter = (Plotter) object;
|
||||
return plotter.name.equals(name) && plotter.getValue() == getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the column name for the plotted point
|
||||
*
|
||||
* @return the plotted point's column name
|
||||
*/
|
||||
public String getColumnName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current value for the plotted point. Since this function defers to an external function it may or may
|
||||
* not return immediately thus cannot be guaranteed to be thread friendly or safe. This function can be called
|
||||
* from any thread so care should be taken when accessing resources that need to be synchronized.
|
||||
*
|
||||
* @return the current value for the point to be plotted.
|
||||
*/
|
||||
public abstract int getValue();
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getColumnName().hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after the website graphs have been updated
|
||||
*/
|
||||
public void reset() {}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The current revision number
|
||||
*/
|
||||
private final static int REVISION = 5;
|
||||
|
||||
/**
|
||||
* The base url of the metrics domain
|
||||
*/
|
||||
private static final String BASE_URL = "http://mcstats.org";
|
||||
|
||||
/**
|
||||
* The url used to report a server's status
|
||||
*/
|
||||
private static final String REPORT_URL = "/report/%s";
|
||||
|
||||
/**
|
||||
* The separator to use for custom data. This MUST NOT change unless you are hosting your own version of metrics and
|
||||
* want to change it.
|
||||
*/
|
||||
private static final String CUSTOM_DATA_SEPARATOR = "~~";
|
||||
|
||||
/**
|
||||
* Interval of time to ping (in minutes)
|
||||
*/
|
||||
private static final int PING_INTERVAL = 10;
|
||||
|
||||
/**
|
||||
* Encode text as UTF-8
|
||||
*
|
||||
* @param text
|
||||
* the text to encode
|
||||
* @return the encoded text, as UTF-8
|
||||
*/
|
||||
private static String encode(final String text) throws UnsupportedEncodingException {
|
||||
return URLEncoder.encode(text, "UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Encode a key/value data pair to be used in a HTTP post request. This INCLUDES a & so the first key/value pair
|
||||
* MUST be included manually, e.g:
|
||||
* </p>
|
||||
* <code>
|
||||
* StringBuffer data = new StringBuffer();
|
||||
* data.append(encode("guid")).append('=').append(encode(guid));
|
||||
* encodeDataPair(data, "version", description.getVersion());
|
||||
* </code>
|
||||
*
|
||||
* @param buffer
|
||||
* the stringbuilder to append the data pair onto
|
||||
* @param key
|
||||
* the key value
|
||||
* @param value
|
||||
* the value
|
||||
*/
|
||||
private static void encodeDataPair(final StringBuilder buffer, final String key, final String value)
|
||||
throws UnsupportedEncodingException {
|
||||
buffer.append('&').append(encode(key)).append('=').append(encode(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* The plugin this metrics submits for
|
||||
*/
|
||||
private final Plugin plugin;
|
||||
|
||||
/**
|
||||
* All of the custom graphs to submit to metrics
|
||||
*/
|
||||
private final Set<Graph> graphs = Collections.synchronizedSet(new HashSet<Graph>());
|
||||
|
||||
/**
|
||||
* The default graph, used for addCustomData when you don't want a specific graph
|
||||
*/
|
||||
private final Graph defaultGraph = new Graph("Default");
|
||||
|
||||
/**
|
||||
* The plugin configuration file
|
||||
*/
|
||||
private final YamlConfiguration configuration;
|
||||
|
||||
/**
|
||||
* The plugin configuration file
|
||||
*/
|
||||
private final File configurationFile;
|
||||
|
||||
/**
|
||||
* Unique server id
|
||||
*/
|
||||
private final String guid;
|
||||
|
||||
/**
|
||||
* Lock for synchronization
|
||||
*/
|
||||
private final Object optOutLock = new Object();
|
||||
|
||||
/**
|
||||
* Id of the scheduled task
|
||||
*/
|
||||
private volatile int taskId = -1;
|
||||
|
||||
public Metrics(final Plugin plugin) throws IOException {
|
||||
if (plugin == null)
|
||||
throw new IllegalArgumentException("Plugin cannot be null");
|
||||
|
||||
this.plugin = plugin;
|
||||
|
||||
// load the config
|
||||
configurationFile = getConfigFile();
|
||||
configuration = YamlConfiguration.loadConfiguration(configurationFile);
|
||||
|
||||
// add some defaults
|
||||
configuration.addDefault("opt-out", false);
|
||||
configuration.addDefault("guid", UUID.randomUUID().toString());
|
||||
|
||||
// Do we need to create the file?
|
||||
if (configuration.get("guid", null) == null) {
|
||||
configuration.options().header("http://mcstats.org").copyDefaults(true);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
|
||||
// Load the guid then
|
||||
guid = configuration.getString("guid");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a custom data plotter to the default graph
|
||||
*
|
||||
* @param plotter
|
||||
* The plotter to use to plot custom data
|
||||
*/
|
||||
public void addCustomData(final Plotter plotter) {
|
||||
if (plotter == null)
|
||||
throw new IllegalArgumentException("Plotter cannot be null");
|
||||
|
||||
// Add the plotter to the graph o/
|
||||
defaultGraph.addPlotter(plotter);
|
||||
|
||||
// Ensure the default graph is included in the submitted graphs
|
||||
graphs.add(defaultGraph);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Graph object to Metrics that represents data for the plugin that should be sent to the backend
|
||||
*
|
||||
* @param graph
|
||||
* The name of the graph
|
||||
*/
|
||||
public void addGraph(final Graph graph) {
|
||||
if (graph == null)
|
||||
throw new IllegalArgumentException("Graph cannot be null");
|
||||
|
||||
graphs.add(graph);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics
|
||||
* website. Plotters can be added to the graph object returned.
|
||||
*
|
||||
* @param name
|
||||
* The name of the graph
|
||||
* @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
|
||||
*/
|
||||
public Graph createGraph(final String name) {
|
||||
if (name == null)
|
||||
throw new IllegalArgumentException("Graph name cannot be null");
|
||||
|
||||
// Construct the graph object
|
||||
final Graph graph = new Graph(name);
|
||||
|
||||
// Now we can add our graph
|
||||
graphs.add(graph);
|
||||
|
||||
// and return back
|
||||
return graph;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void disable() throws IOException {
|
||||
// This has to be synchronized or it can collide with the check in the task.
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (!isOptOut()) {
|
||||
configuration.set("opt-out", true);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
|
||||
// Disable Task, if it is running
|
||||
if (taskId > 0) {
|
||||
plugin.getServer().getScheduler().cancelTask(taskId);
|
||||
taskId = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void enable() throws IOException {
|
||||
// This has to be synchronized or it can collide with the check in the task.
|
||||
synchronized (optOutLock) {
|
||||
// Check if the server owner has already set opt-out, if not, set it.
|
||||
if (isOptOut()) {
|
||||
configuration.set("opt-out", false);
|
||||
configuration.save(configurationFile);
|
||||
}
|
||||
|
||||
// Enable Task, if it is not running
|
||||
if (taskId < 0)
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the File object of the config file that should be used to store data such as the GUID and opt-out status
|
||||
*
|
||||
* @return the File object for the config file
|
||||
*/
|
||||
public File getConfigFile() {
|
||||
// I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use
|
||||
// is to abuse the plugin object we already have
|
||||
// plugin.getDataFolder() => base/plugins/PluginA/
|
||||
// pluginsFolder => base/plugins/
|
||||
// The base is not necessarily relative to the startup directory.
|
||||
final File pluginsFolder = plugin.getDataFolder().getParentFile();
|
||||
|
||||
// return => base/plugins/PluginMetrics/config.yml
|
||||
return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mineshafter is present. If it is, we need to bypass it to send POST requests
|
||||
*
|
||||
* @return true if mineshafter is installed on the server
|
||||
*/
|
||||
private boolean isMineshafterPresent() {
|
||||
try {
|
||||
Class.forName("mineshafter.MineServer");
|
||||
return true;
|
||||
} catch (final Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Has the server owner denied plugin metrics?
|
||||
*
|
||||
* @return true if metrics should be opted out of it
|
||||
*/
|
||||
public boolean isOptOut() {
|
||||
synchronized (optOutLock) {
|
||||
try {
|
||||
// Reload the metrics file
|
||||
configuration.load(getConfigFile());
|
||||
} catch (final IOException ex) {
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
||||
return true;
|
||||
} catch (final InvalidConfigurationException ex) {
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
|
||||
return true;
|
||||
}
|
||||
return configuration.getBoolean("opt-out", false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic method that posts a plugin to the metrics website
|
||||
*/
|
||||
private void postPlugin(final boolean isPing) throws IOException {
|
||||
// The plugin's description file containg all of the plugin data such as name, version, author, etc
|
||||
final PluginDescriptionFile description = plugin.getDescription();
|
||||
|
||||
// Construct the post data
|
||||
final StringBuilder data = new StringBuilder();
|
||||
data.append(encode("guid")).append('=').append(encode(guid));
|
||||
encodeDataPair(data, "version", description.getVersion());
|
||||
encodeDataPair(data, "server", Bukkit.getVersion());
|
||||
encodeDataPair(data, "players", Integer.toString(Bukkit.getServer().getOnlinePlayers().length));
|
||||
encodeDataPair(data, "revision", String.valueOf(REVISION));
|
||||
|
||||
// If we're pinging, append it
|
||||
if (isPing)
|
||||
encodeDataPair(data, "ping", "true");
|
||||
|
||||
// Acquire a lock on the graphs, which lets us make the assumption we also lock everything
|
||||
// inside of the graph (e.g plotters)
|
||||
synchronized (graphs) {
|
||||
final Iterator<Graph> iter = graphs.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
final Graph graph = iter.next();
|
||||
|
||||
for (final Plotter plotter : graph.getPlotters()) {
|
||||
// The key name to send to the metrics server
|
||||
// The format is C-GRAPHNAME-PLOTTERNAME where separator - is defined at the top
|
||||
// Legacy (R4) submitters use the format Custom%s, or CustomPLOTTERNAME
|
||||
final String key = String.format("C%s%s%s%s", CUSTOM_DATA_SEPARATOR, graph.getName(),
|
||||
CUSTOM_DATA_SEPARATOR, plotter.getColumnName());
|
||||
|
||||
// The value to send, which for the foreseeable future is just the string
|
||||
// value of plotter.getValue()
|
||||
final String value = Integer.toString(plotter.getValue());
|
||||
|
||||
// Add it to the http post data :)
|
||||
encodeDataPair(data, key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create the url
|
||||
final URL url = new URL(BASE_URL + String.format(REPORT_URL, encode(plugin.getDescription().getName())));
|
||||
|
||||
// Connect to the website
|
||||
URLConnection connection;
|
||||
|
||||
// Mineshafter creates a socks proxy, so we can safely bypass it
|
||||
// It does not reroute POST requests so we need to go around it
|
||||
if (isMineshafterPresent())
|
||||
connection = url.openConnection(Proxy.NO_PROXY);
|
||||
else
|
||||
connection = url.openConnection();
|
||||
|
||||
connection.setDoOutput(true);
|
||||
|
||||
// Write the data
|
||||
final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
|
||||
writer.write(data.toString());
|
||||
writer.flush();
|
||||
|
||||
// Now read the response
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
final String response = reader.readLine();
|
||||
|
||||
// close resources
|
||||
writer.close();
|
||||
reader.close();
|
||||
|
||||
if (response == null || response.startsWith("ERR"))
|
||||
throw new IOException(response); // Throw the exception
|
||||
else // Is this the first update this hour?
|
||||
if (response.contains("OK This is your first update this hour"))
|
||||
synchronized (graphs) {
|
||||
final Iterator<Graph> iter = graphs.iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
final Graph graph = iter.next();
|
||||
|
||||
for (final Plotter plotter : graph.getPlotters())
|
||||
plotter.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start measuring statistics. This will immediately create an async repeating task as the plugin and send the
|
||||
* initial data to the metrics backend, and then after that it will post in increments of PING_INTERVAL * 1200
|
||||
* ticks.
|
||||
*
|
||||
* @return True if statistics measuring is running, otherwise false.
|
||||
*/
|
||||
public boolean start() {
|
||||
synchronized (optOutLock) {
|
||||
// Did we opt out?
|
||||
if (isOptOut())
|
||||
return false;
|
||||
|
||||
// Is metrics already running?
|
||||
if (taskId >= 0)
|
||||
return true;
|
||||
|
||||
// Begin hitting the server with glorious data
|
||||
taskId = plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
|
||||
|
||||
private boolean firstPost = true;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// This has to be synchronized or it can collide with the disable method.
|
||||
synchronized (optOutLock) {
|
||||
// Disable Task, if it is running and the server owner decided to opt-out
|
||||
if (isOptOut() && taskId > 0) {
|
||||
plugin.getServer().getScheduler().cancelTask(taskId);
|
||||
taskId = -1;
|
||||
// Tell all plotters to stop gathering information.
|
||||
for (final Graph graph : graphs)
|
||||
graph.onOptOut();
|
||||
}
|
||||
}
|
||||
|
||||
// We use the inverse of firstPost because if it is the first time we are posting,
|
||||
// it is not a interval ping, so it evaluates to FALSE
|
||||
// Each time thereafter it will evaluate to TRUE, i.e PING!
|
||||
postPlugin(!firstPost);
|
||||
|
||||
// After the first post we set firstPost to false
|
||||
// Each post thereafter will be a ping
|
||||
firstPost = false;
|
||||
} catch (final IOException e) {
|
||||
Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}, 0, PING_INTERVAL * 1200);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
113
src/fr/neatmonster/nocheatplus/metrics/MetricsData.java
Normal file
113
src/fr/neatmonster/nocheatplus/metrics/MetricsData.java
Normal file
@ -0,0 +1,113 @@
|
||||
package fr.neatmonster.nocheatplus.metrics;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
||||
|
||||
/*
|
||||
* M"""""`'"""`YM dP oo M""""""'YMM dP
|
||||
* M mm. mm. M 88 M mmmm. `M 88
|
||||
* M MMM MMM M .d8888b. d8888P 88d888b. dP .d8888b. .d8888b. M MMMMM M .d8888b. d8888P .d8888b.
|
||||
* M MMM MMM M 88ooood8 88 88' `88 88 88' `"" Y8ooooo. M MMMMM M 88' `88 88 88' `88
|
||||
* M MMM MMM M 88. ... 88 88 88 88. ... 88 M MMMM' .M 88. .88 88 88. .88
|
||||
* M MMM MMM M `88888P' dP dP dP `88888P' `88888P' M .MM `88888P8 dP `88888P8
|
||||
* MMMMMMMMMMMMMM MMMMMMMMMMM
|
||||
*/
|
||||
/**
|
||||
* The Metrics data.
|
||||
*/
|
||||
public class MetricsData {
|
||||
|
||||
/** The violation levels. */
|
||||
private static final Map<CheckType, Double> violationLevels = new HashMap<CheckType, Double>();
|
||||
|
||||
/** The checks fails. */
|
||||
private static final Map<CheckType, Integer> checksFails = new HashMap<CheckType, Integer>();
|
||||
|
||||
/** The events checked. */
|
||||
private static final Map<CheckType, Integer> eventsChecked = new HashMap<CheckType, Integer>();
|
||||
|
||||
/**
|
||||
* Called when an event is checked.
|
||||
*
|
||||
* @param type
|
||||
* the type
|
||||
*/
|
||||
public static void addChecked(final CheckType type) {
|
||||
if (type.getParent() != null)
|
||||
eventsChecked.put(type, getChecked(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player fails a check.
|
||||
*
|
||||
* @param violationData
|
||||
* the violation data
|
||||
*/
|
||||
public static void addViolation(final ViolationData violationData) {
|
||||
final CheckType type = violationData.check.getType();
|
||||
if (type.getParent() != null) {
|
||||
violationLevels.put(type, getViolationLevel(type) + violationData.addedVL);
|
||||
checksFails.put(type, getFailed(type) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of event checked.
|
||||
*
|
||||
* @param type
|
||||
* the type
|
||||
* @return the number of event checked
|
||||
*/
|
||||
public static int getChecked(final CheckType type) {
|
||||
if (type == CheckType.ALL) {
|
||||
int eventsChecked = 0;
|
||||
for (final double value : MetricsData.eventsChecked.values())
|
||||
eventsChecked += value;
|
||||
return eventsChecked;
|
||||
}
|
||||
if (!eventsChecked.containsKey(type))
|
||||
eventsChecked.put(type, 0);
|
||||
return eventsChecked.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of failed checks.
|
||||
*
|
||||
* @param type
|
||||
* the type
|
||||
* @return the number of failed checks
|
||||
*/
|
||||
public static int getFailed(final CheckType type) {
|
||||
if (type == CheckType.ALL) {
|
||||
int checkFails = 0;
|
||||
for (final double value : checksFails.values())
|
||||
checkFails += value;
|
||||
return checkFails;
|
||||
}
|
||||
if (!checksFails.containsKey(type))
|
||||
checksFails.put(type, 0);
|
||||
return checksFails.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the violation level.
|
||||
*
|
||||
* @param type
|
||||
* the type
|
||||
* @return the violation level
|
||||
*/
|
||||
public static double getViolationLevel(final CheckType type) {
|
||||
if (type == CheckType.ALL) {
|
||||
double violationLevel = 0D;
|
||||
for (final double value : violationLevels.values())
|
||||
violationLevel += value;
|
||||
return violationLevel;
|
||||
}
|
||||
if (!violationLevels.containsKey(type))
|
||||
violationLevels.put(type, 0D);
|
||||
return violationLevels.get(type);
|
||||
}
|
||||
}
|
@ -46,6 +46,18 @@ public class LagMeasureTask implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the average ticks.
|
||||
*
|
||||
* @return the average ticks
|
||||
*/
|
||||
public static int getAverageTicks() {
|
||||
final int averageTicks = (int) (instance.totalTicks / instance.numberOfValues);
|
||||
instance.totalTicks = 0L;
|
||||
instance.numberOfValues = 0;
|
||||
return averageTicks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if checking must be skipped (lag).
|
||||
*
|
||||
@ -72,11 +84,17 @@ public class LagMeasureTask implements Runnable {
|
||||
/** The last in game second duration. */
|
||||
private long lastInGameSecondDuration = 2000L;
|
||||
|
||||
/** The lag measure task id. */
|
||||
private int lagMeasureTaskId = -1;
|
||||
|
||||
/** The number of values. */
|
||||
private int numberOfValues = 0;
|
||||
|
||||
/** The skip check. */
|
||||
private boolean skipCheck = false;
|
||||
|
||||
/** The lag measure task id. */
|
||||
private int lagMeasureTaskId = -1;
|
||||
/** The total ticks. */
|
||||
private long totalTicks = 0L;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Runnable#run()
|
||||
@ -88,6 +106,9 @@ public class LagMeasureTask implements Runnable {
|
||||
// If the previous second took to long, skip checks during this second.
|
||||
skipCheck = lastInGameSecondDuration > 2000;
|
||||
|
||||
totalTicks += Math.round(20000D / lastInGameSecondDuration);
|
||||
numberOfValues++;
|
||||
|
||||
if (ConfigManager.getConfigFile().getBoolean(ConfPaths.LOGGING_DEBUG))
|
||||
if (oldStatus != skipCheck && skipCheck)
|
||||
System.out.println("[NoCheatPlus] Detected server lag, some checks will not work.");
|
||||
@ -96,11 +117,6 @@ public class LagMeasureTask implements Runnable {
|
||||
|
||||
final long time = System.currentTimeMillis();
|
||||
lastInGameSecondDuration = time - lastInGameSecondTime;
|
||||
if (lastInGameSecondDuration < 1000)
|
||||
lastInGameSecondDuration = 1000;
|
||||
else if (lastInGameSecondDuration > 3600000)
|
||||
// Top limit of 1 hour per "second".
|
||||
lastInGameSecondDuration = 3600000;
|
||||
lastInGameSecondTime = time;
|
||||
} catch (final Exception e) {
|
||||
// Just prevent this thread from dying for whatever reason.
|
||||
|
Loading…
Reference in New Issue
Block a user