mirror of
https://github.com/asofold/CompatNoCheatPlus.git
synced 2025-01-23 21:41:20 +01:00
(BIG CHANGE) Internal structure and hooks.
This commit is contained in:
parent
7d3ba1e3eb
commit
447ef2f4a9
@ -23,6 +23,7 @@ VERSION HISTORY
|
|||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
(4.0.0)
|
(4.0.0)
|
||||||
|
- (BIG CHANGE) Internal structure and hooks.
|
||||||
|
|
||||||
(3.0.0)
|
(3.0.0)
|
||||||
- (BIG CHANGE) Back to NoCheatPlus !
|
- (BIG CHANGE) Back to NoCheatPlus !
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package me.asofold.bpl.cncp;
|
package me.asofold.bpl.cncp;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Map;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -12,7 +12,8 @@ import me.asofold.bpl.cncp.config.compatlayer.CompatConfig;
|
|||||||
import me.asofold.bpl.cncp.config.compatlayer.NewConfig;
|
import me.asofold.bpl.cncp.config.compatlayer.NewConfig;
|
||||||
import me.asofold.bpl.cncp.hooks.Hook;
|
import me.asofold.bpl.cncp.hooks.Hook;
|
||||||
import me.asofold.bpl.cncp.hooks.generic.HookPlayerClass;
|
import me.asofold.bpl.cncp.hooks.generic.HookPlayerClass;
|
||||||
import me.asofold.bpl.cncp.setttings.GroupHooks;
|
import me.asofold.bpl.cncp.hooks.ncp.NCPHook;
|
||||||
|
import me.asofold.bpl.cncp.hooks.ncp.NCPHookManager;
|
||||||
import me.asofold.bpl.cncp.setttings.Settings;
|
import me.asofold.bpl.cncp.setttings.Settings;
|
||||||
import me.asofold.bpl.cncp.utils.Utils;
|
import me.asofold.bpl.cncp.utils.Utils;
|
||||||
|
|
||||||
@ -43,15 +44,6 @@ import fr.neatmonster.nocheatplus.checks.moving.SurvivalFly.SurvivalFlyEvent;
|
|||||||
*/
|
*/
|
||||||
public class CompatNoCheatPlus extends JavaPlugin implements Listener {
|
public class CompatNoCheatPlus extends JavaPlugin implements Listener {
|
||||||
|
|
||||||
/**
|
|
||||||
* Storage of hooks that are called for all events.
|
|
||||||
*/
|
|
||||||
private static final ArrayList<Hook> hooksAll = new ArrayList<Hook>(10);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Storage of hooks that are called for certain groups and checks.
|
|
||||||
*/
|
|
||||||
private static final Map<String, GroupHooks> hooksGroups = new HashMap<String, GroupHooks>(20);
|
|
||||||
|
|
||||||
private final Settings settings = new Settings();
|
private final Settings settings = new Settings();
|
||||||
|
|
||||||
@ -100,16 +92,29 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API to add a hook.
|
* API to add a hook. Adds the hook AND registers listeners if enabled. Also respects the configuration for preventing hooks.<br>
|
||||||
|
* If you want to not register the listeners use NCPHookManager.
|
||||||
* @param hook
|
* @param hook
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean addHook(Hook hook){
|
public static boolean addHook(Hook hook){
|
||||||
if (!enabled) return false;
|
|
||||||
if (Settings.preventAddHooks.contains(hook.getHookName())){
|
if (Settings.preventAddHooks.contains(hook.getHookName())){
|
||||||
System.out.println("[cncp] Prevented adding hook: "+hook.getHookName() + " / " + hook.getHookVersion());
|
System.out.println("[cncp] Prevented adding hook: "+hook.getHookName() + " / " + hook.getHookVersion());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (enabled) registerListeners(hook);
|
||||||
|
Integer[] checkIds = hook.getCheckSpec();
|
||||||
|
NCPHookManager.addHook(checkIds, hook); // This logs the message.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Conveniently register the listeners, do not use if you add/added the hook with addHook.
|
||||||
|
* @param hook
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean registerListeners(Hook hook) {
|
||||||
|
if (!enabled) return false;
|
||||||
Listener[] listeners = hook.getListeners();
|
Listener[] listeners = hook.getListeners();
|
||||||
if (listeners != null){
|
if (listeners != null){
|
||||||
// attempt to register events:
|
// attempt to register events:
|
||||||
@ -120,40 +125,9 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
|
|||||||
pm.registerEvents(listener, plg);
|
pm.registerEvents(listener, plg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String[][] specs = hook.getCheckSpec();
|
|
||||||
if (specs == null) hooksAll.add(hook);
|
|
||||||
else{
|
|
||||||
for (String[] spec : specs){
|
|
||||||
String group = spec[0].trim().toLowerCase();
|
|
||||||
GroupHooks gh = hooksGroups.get(group);
|
|
||||||
if (gh == null){
|
|
||||||
gh = new GroupHooks();
|
|
||||||
hooksGroups.put(group, gh);
|
|
||||||
}
|
|
||||||
if (spec.length == 1) gh.all.add(hook);
|
|
||||||
else{
|
|
||||||
for (int i = 1; i < spec.length; i++){
|
|
||||||
String check = spec[i].trim().toLowerCase();
|
|
||||||
ArrayList<Hook> hooks = gh.byCheck.get(check);
|
|
||||||
if (hooks == null){
|
|
||||||
hooks = new ArrayList<Hook>(10);
|
|
||||||
gh.byCheck.put(check, hooks);
|
|
||||||
}
|
|
||||||
hooks.add(hook);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println("[cncp] Added hook: "+hook.getHookName() + " / " + hook.getHookVersion());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void clearHooks() {
|
|
||||||
hooksAll.clear();
|
|
||||||
hooksGroups.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add standard hooks if available.
|
* Add standard hooks if available.
|
||||||
*/
|
*/
|
||||||
@ -167,8 +141,9 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
// cleanup
|
enabled = false; // make sure
|
||||||
clearHooks();
|
// (no cleanup)
|
||||||
|
|
||||||
// Settings:
|
// Settings:
|
||||||
settings.clear();
|
settings.clear();
|
||||||
reloadSettings();
|
reloadSettings();
|
||||||
@ -176,9 +151,27 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
|
|||||||
final PluginManager pm = getServer().getPluginManager();
|
final PluginManager pm = getServer().getPluginManager();
|
||||||
pm.registerEvents(this, this);
|
pm.registerEvents(this, this);
|
||||||
super.onEnable();
|
super.onEnable();
|
||||||
enabled = true;
|
|
||||||
// Add Hooks:
|
// Add Hooks:
|
||||||
addAvailableHooks();
|
addAvailableHooks(); // add before enable is set to not yet register listeners.
|
||||||
|
enabled = true;
|
||||||
|
|
||||||
|
// register all listeners:
|
||||||
|
for (Hook hook : getAllHooks()){
|
||||||
|
registerListeners(hook);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all cncp Hook instances that are registered with NCPHookManager.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Collection<Hook> getAllHooks() {
|
||||||
|
List<Hook> hooks = new LinkedList<Hook>();
|
||||||
|
for (NCPHook hook : NCPHookManager.getAllHooks()){
|
||||||
|
if (hook instanceof Hook) hooks.add((Hook) hook);
|
||||||
|
}
|
||||||
|
return hooks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean reloadSettings() {
|
public boolean reloadSettings() {
|
||||||
@ -244,80 +237,32 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
|
|||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
enabled = false;
|
enabled = false;
|
||||||
clearHooks();
|
// remove all registered cncp hooks:
|
||||||
|
for (Hook hook : getAllHooks()){
|
||||||
|
NCPHookManager.removeHook(hook);
|
||||||
|
}
|
||||||
super.onDisable();
|
super.onDisable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled=true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled=true)
|
||||||
final void onCheckFail(final CheckEvent event){
|
final void onCheckFail(final CheckEvent event){
|
||||||
// Check hooks, most specific first:
|
|
||||||
final String gn;
|
|
||||||
final String cn;
|
|
||||||
|
|
||||||
|
// TODO: This will be replaced by NCP invoking NCPHookManager.should... directly.
|
||||||
|
|
||||||
if (event instanceof SurvivalFlyEvent){
|
final Integer checkId;
|
||||||
gn = "moving";
|
|
||||||
cn = "survivalfly";
|
|
||||||
}
|
|
||||||
else if (event instanceof CreativeFlyEvent){
|
|
||||||
gn = "moving";
|
|
||||||
cn = "creativefly";
|
|
||||||
}
|
|
||||||
else if (event instanceof NoFallEvent){
|
|
||||||
gn = "moving";
|
|
||||||
cn = "nofall";
|
|
||||||
}
|
|
||||||
else if (event instanceof FastBreakEvent){
|
|
||||||
gn = "blockbreak";
|
|
||||||
cn = "fastbreak";
|
|
||||||
}
|
|
||||||
else if (event instanceof NoSwingEvent){
|
|
||||||
gn = "blockbreak";
|
|
||||||
cn = "noswing";
|
|
||||||
}
|
|
||||||
else if (event instanceof DirectionEvent){
|
|
||||||
gn = "blockbreak";
|
|
||||||
cn = "direction";
|
|
||||||
}
|
|
||||||
else if (event instanceof SpeedEvent){
|
|
||||||
gn = "fight";
|
|
||||||
cn = "speed";
|
|
||||||
}
|
|
||||||
else if (event instanceof AngleEvent){
|
|
||||||
gn = "fight";
|
|
||||||
cn = "angle";
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
// TODO: ...
|
|
||||||
gn = "";
|
|
||||||
cn = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
final GroupHooks gh = hooksGroups.get(gn.trim().toLowerCase());
|
// horrible :)
|
||||||
if (gh != null){
|
if (event instanceof SurvivalFlyEvent) checkId = NCPHookManager.MOVING_SURVIVALFLY;
|
||||||
final ArrayList<Hook> hooks = gh.byCheck.get(cn.trim().toLowerCase());
|
else if (event instanceof CreativeFlyEvent) checkId = NCPHookManager.MOVING_CREATIVEFLY;
|
||||||
if (hooks != null) applyHooks(gn, cn, event, hooks);
|
else if (event instanceof NoFallEvent) checkId = NCPHookManager.MOVING_NOFALL;
|
||||||
if (event.isCancelled()) return;
|
else if (event instanceof FastBreakEvent) checkId = NCPHookManager.BLOCKBREAK_FASTBREAK;
|
||||||
if (!gh.all.isEmpty()) applyHooks(gn, cn, event, gh.all);
|
else if (event instanceof NoSwingEvent) checkId = NCPHookManager.BLOCKBREAK_NOSWING;
|
||||||
}
|
else if (event instanceof DirectionEvent) checkId = NCPHookManager.BLOCKBREAK_DIRECTION;
|
||||||
if (event.isCancelled()) return;
|
else if (event instanceof SpeedEvent) checkId = NCPHookManager.FIGHT_SPEED;
|
||||||
if (!hooksAll.isEmpty()) applyHooks(gn, cn, event, hooksAll);
|
else if (event instanceof AngleEvent) checkId = NCPHookManager.FIGHT_ANGLE;
|
||||||
}
|
else checkId = NCPHookManager.UNKNOWN;
|
||||||
|
|
||||||
private final void applyHooks(final String group, final String check, final CheckEvent event, final ArrayList<Hook> hooks) {
|
if (NCPHookManager.shouldCancelVLProcessing(checkId, event.getPlayer())) event.setCancelled(true);
|
||||||
for (int i = 0; i < hooks.size(); i++){
|
|
||||||
if (event.isCancelled()) return;
|
|
||||||
final Hook hook = hooks.get(i);
|
|
||||||
try{
|
|
||||||
hook.processEvent(group, check, event);
|
|
||||||
}
|
|
||||||
catch (final Throwable t){
|
|
||||||
final Logger logger = getServer().getLogger();
|
|
||||||
logger.warning("[cncp][" + group + "/" + check + "] Unexpected exception on for hook ("+hook.getHookName()+" / "+hook.getHookVersion()+"):");
|
|
||||||
// TODO: maybe add more info about the CheckEvent ?
|
|
||||||
logger.warning(Utils.toString(t));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import org.bukkit.event.Listener;
|
|||||||
public abstract class AbstractHook implements Hook{
|
public abstract class AbstractHook implements Hook{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[][] getCheckSpec() {
|
public Integer[] getCheckSpec() {
|
||||||
// Handle all CheckEvents (improbable).
|
// Handle all CheckEvents (improbable).
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1,39 +1,24 @@
|
|||||||
package me.asofold.bpl.cncp.hooks;
|
package me.asofold.bpl.cncp.hooks;
|
||||||
|
|
||||||
|
import me.asofold.bpl.cncp.hooks.ncp.NCPHook;
|
||||||
|
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
import fr.neatmonster.nocheatplus.checks.CheckEvent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for hooking into another plugin.<br>
|
* Interface for hooking into another plugin.<br>
|
||||||
|
* NOTE: You also have to implement the methods described in NCPHook.<br>
|
||||||
|
* If you do not use listeners or don't want the prevent-hooks configuration feature
|
||||||
|
* to take effect, you can also register directly with NCPHookManager.
|
||||||
*
|
*
|
||||||
* @author mc_dev
|
* @author mc_dev
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public interface Hook{
|
public interface Hook extends NCPHook{
|
||||||
/**
|
|
||||||
* Must not cause exceptions.
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getHookName();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Must not cause exceptions.
|
* The check ids to register for, see NCPHookManager for reference, you can use ALL,
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public String getHookVersion();
|
public Integer[] getCheckSpec();
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the specification for which checks to call this.<br>
|
|
||||||
* <hr>
|
|
||||||
* The return value should be an array of arrays, each of which specifies the group name and the check names within that group.<br>
|
|
||||||
* You can return null to register for ALL checks.<br>
|
|
||||||
* You can just register the group name to get all checks for that group.<br>
|
|
||||||
* <hr>
|
|
||||||
* Currently group and check names are processed with trim().toLowerCase() !
|
|
||||||
* @return (see description)
|
|
||||||
*/
|
|
||||||
public String[][] getCheckSpec();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get listener instances to be registered with cncp.
|
* Get listener instances to be registered with cncp.
|
||||||
@ -41,13 +26,4 @@ public interface Hook{
|
|||||||
*/
|
*/
|
||||||
public Listener[] getListeners();
|
public Listener[] getListeners();
|
||||||
|
|
||||||
/**
|
|
||||||
* This will only be called if the event has not yet been cancelled !<br>
|
|
||||||
* Cancel the event, and no further hooks will process this.
|
|
||||||
* @param group Name of check group
|
|
||||||
* @param check Name of check .
|
|
||||||
* @param event
|
|
||||||
*/
|
|
||||||
public void processEvent(final String group, final String check, final CheckEvent event);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,8 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import me.asofold.bpl.cncp.hooks.AbstractHook;
|
import me.asofold.bpl.cncp.hooks.AbstractHook;
|
||||||
import fr.neatmonster.nocheatplus.checks.CheckEvent;
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public final class HookPlayerClass extends AbstractHook {
|
public final class HookPlayerClass extends AbstractHook {
|
||||||
|
|
||||||
@ -51,27 +52,30 @@ public final class HookPlayerClass extends AbstractHook {
|
|||||||
return "0.1";
|
return "0.1";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void processEvent(final String group, final String check, final CheckEvent event) {
|
public final boolean onCheckFailure(final Integer groupId, final Integer checkId, final Player player) {
|
||||||
if (exemptAll && !event.getPlayer().getClass().getSimpleName().equals(playerClassName)) event.setCancelled(true);
|
if (exemptAll && !player.getClass().getSimpleName().equals(playerClassName)) return true;
|
||||||
else {
|
else {
|
||||||
if (classNames.isEmpty()) return;
|
if (classNames.isEmpty()) return false;
|
||||||
final Class<?> clazz = event.getPlayer().getClass();
|
final Class<?> clazz = player.getClass();
|
||||||
final String name = clazz.getSimpleName();
|
final String name = clazz.getSimpleName();
|
||||||
if (classNames.contains(name)) event.setCancelled(true);
|
if (classNames.contains(name)) return true;
|
||||||
else if (checkSuperClass){
|
else if (checkSuperClass){
|
||||||
while (true){
|
while (true){
|
||||||
final Class<?> superClass = clazz.getSuperclass();
|
final Class<?> superClass = clazz.getSuperclass();
|
||||||
if (superClass == null) return;
|
if (superClass == null) return false;
|
||||||
final String superName = superClass.getSimpleName();
|
else{
|
||||||
if (superName.equals("Object")) return;
|
final String superName = superClass.getSimpleName();
|
||||||
else if (classNames.contains(superName)){
|
if (superName.equals("Object")) return false;
|
||||||
event.setCancelled(true);
|
else if (classNames.contains(superName)){
|
||||||
return;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false; // ECLIPSE
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import me.asofold.bpl.cncp.hooks.AbstractHook;
|
import me.asofold.bpl.cncp.hooks.AbstractHook;
|
||||||
|
import me.asofold.bpl.cncp.hooks.ncp.NCPHookManager;
|
||||||
import me.asofold.bpl.cncp.utils.PluginGetter;
|
import me.asofold.bpl.cncp.utils.PluginGetter;
|
||||||
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@ -17,20 +18,18 @@ import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
|
|||||||
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
|
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
|
||||||
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
|
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
|
||||||
|
|
||||||
import fr.neatmonster.nocheatplus.checks.CheckEvent;
|
|
||||||
|
|
||||||
public final class HookmcMMO extends AbstractHook implements Listener {
|
public final class HookmcMMO extends AbstractHook implements Listener {
|
||||||
|
|
||||||
private static final Map<String, Integer> cancelChecksBlockBreak = new HashMap<String, Integer>();
|
private static final Map<Integer, Integer> cancelChecksBlockBreak = new HashMap<Integer, Integer>();
|
||||||
private static final Map<String, Integer> cancelChecksBlockDamage = new HashMap<String, Integer>();
|
private static final Map<Integer, Integer> cancelChecksBlockDamage = new HashMap<Integer, Integer>();
|
||||||
private static final Map<String, Integer> cancelChecksDamage = new HashMap<String, Integer>();
|
private static final Map<Integer, Integer> cancelChecksDamage = new HashMap<Integer, Integer>();
|
||||||
static{
|
static{
|
||||||
cancelChecksBlockBreak.put("noswing", 1);
|
cancelChecksBlockBreak.put(NCPHookManager.BLOCKBREAK_NOSWING, 1);
|
||||||
cancelChecksBlockBreak.put("fastbreak", 2);
|
cancelChecksBlockBreak.put(NCPHookManager.BLOCKBREAK_FASTBREAK, 2);
|
||||||
cancelChecksBlockDamage.put("fastbreak", 1);
|
cancelChecksBlockDamage.put(NCPHookManager.BLOCKBREAK_FASTBREAK, 1);
|
||||||
|
|
||||||
cancelChecksDamage.put("angle", 1);
|
cancelChecksDamage.put(NCPHookManager.FIGHT_ANGLE, 1);
|
||||||
cancelChecksDamage.put("speed", 1);
|
cancelChecksDamage.put(NCPHookManager.FIGHT_SPEED, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HookmcMMO(){
|
public HookmcMMO(){
|
||||||
@ -43,7 +42,7 @@ public final class HookmcMMO extends AbstractHook implements Listener {
|
|||||||
private String cancel = null;
|
private String cancel = null;
|
||||||
private long cancelTicks = 0;
|
private long cancelTicks = 0;
|
||||||
|
|
||||||
private final Map<String, Integer> cancelChecks = new HashMap<String, Integer>();
|
private final Map<Integer, Integer> cancelChecks = new HashMap<Integer, Integer>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -58,10 +57,10 @@ public final class HookmcMMO extends AbstractHook implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[][] getCheckSpec() {
|
public Integer[] getCheckSpec() {
|
||||||
return new String[][]{
|
return new Integer[]{
|
||||||
{"blockbreak", "fastbreak", "noswing"},
|
NCPHookManager.BLOCKBREAK_FASTBREAK, NCPHookManager.BLOCKBREAK_NOSWING,
|
||||||
{"fight", "angle", "speed"},
|
NCPHookManager.FIGHT_ANGLE, NCPHookManager.FIGHT_SPEED,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,14 +70,14 @@ public final class HookmcMMO extends AbstractHook implements Listener {
|
|||||||
return new Listener[]{this, fetch};
|
return new Listener[]{this, fetch};
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void setPlayer(final Entity entity, Map<String, Integer> cancelChecks){
|
private final void setPlayer(final Entity entity, Map<Integer, Integer> cancelChecks){
|
||||||
if (entity instanceof Player){
|
if (entity instanceof Player){
|
||||||
setPlayer((Player) entity, cancelChecks);
|
setPlayer((Player) entity, cancelChecks);
|
||||||
}
|
}
|
||||||
// no projectiles etc.
|
// no projectiles etc.
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void setPlayer(final Player player, Map<String, Integer> cancelChecks){
|
private final void setPlayer(final Player player, Map<Integer, Integer> cancelChecks){
|
||||||
cancel = player.getName();
|
cancel = player.getName();
|
||||||
cancelTicks = player.getTicksLived();
|
cancelTicks = player.getTicksLived();
|
||||||
this.cancelChecks.clear();
|
this.cancelChecks.clear();
|
||||||
@ -119,15 +118,14 @@ public final class HookmcMMO extends AbstractHook implements Listener {
|
|||||||
// cancel = null;
|
// cancel = null;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processEvent(final String group, final String check, final CheckEvent event) {
|
public final boolean onCheckFailure(final Integer groupId, final Integer checkId, final Player player) {
|
||||||
// System.out.println("[cncp] Handle event: " + event.getEventName());
|
// System.out.println("[cncp] Handle event: " + event.getEventName());
|
||||||
if (cancel == null){
|
if (cancel == null){
|
||||||
// System.out.println("[cncp] Return on cancel == null: "+event.getPlayer().getName());
|
// System.out.println("[cncp] Return on cancel == null: "+event.getPlayer().getName());
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Player player = event.getPlayer();
|
|
||||||
|
|
||||||
final String name = player.getName();
|
final String name = player.getName();
|
||||||
if (cancel.equals(name)){
|
if (cancel.equals(name)){
|
||||||
@ -137,21 +135,22 @@ public final class HookmcMMO extends AbstractHook implements Listener {
|
|||||||
cancel = null;
|
cancel = null;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
final Integer n = cancelChecks.get(check);
|
final Integer n = cancelChecks.get(checkId);
|
||||||
if (n == null){
|
if (n == null){
|
||||||
// System.out.println("[cncp] Expired("+check+"): "+event.getPlayer().getName());
|
// System.out.println("[cncp] Expired("+check+"): "+event.getPlayer().getName());
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
else if (n > 0){
|
else if (n > 0){
|
||||||
// System.out.println("Check with n = "+n);
|
// System.out.println("Check with n = "+n);
|
||||||
if (n == 1) cancelChecks.remove(check);
|
if (n == 1) cancelChecks.remove(checkId);
|
||||||
else cancelChecks.put(check, n - 1);
|
else cancelChecks.put(checkId, n - 1);
|
||||||
}
|
}
|
||||||
// else: allow arbitrary numbers
|
// else: allow arbitrary numbers
|
||||||
// System.out.println("[cncp] Cancel: "+event.getPlayer().getName());
|
// System.out.println("[cncp] Cancel: "+event.getPlayer().getName());
|
||||||
event.setCancelled(true);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user