[BLEEDING] With NCP 3.16.1-SNAPSHOT: remove plugin enabling, add order.

* Run from NCP 3.16.1-SNAPSHOT on exclusively.
* Add default order to registration.
* Add true wrapping order to hook event handlers.
* Remove config features for enabling other plugins.
* Remove static instance storing.

Effects remain to be seen...
This commit is contained in:
asofold 2018-01-17 15:06:11 +01:00
parent b00cbbdb21
commit 7a4a8b0490
11 changed files with 668 additions and 688 deletions

View File

@ -3,7 +3,7 @@ main: me.asofold.bpl.cncp.CompatNoCheatPlus
version: ${project.version}-s${BUILD_SERIES}-b${BUILD_NUMBER}
dev-url: http://dev.bukkit.org/server-mods/compatnocheatplus-cncp/
loadbefore:
depend:
- NoCheatPlus
softdepend:
- mcMMO

View File

@ -54,7 +54,7 @@
<dependency>
<groupId>fr.neatmonster</groupId>
<artifactId>nocheatplus</artifactId>
<version>3.16.0-SNAPSHOT</version>
<version>3.16.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -2,29 +2,23 @@ package me.asofold.bpl.cncp;
import java.io.File;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.components.registry.feature.IDisableListener;
import fr.neatmonster.nocheatplus.components.registry.order.RegistrationOrder;
import fr.neatmonster.nocheatplus.hooks.NCPHook;
import fr.neatmonster.nocheatplus.hooks.NCPHookManager;
import me.asofold.bpl.cncp.config.Settings;
@ -39,16 +33,42 @@ import me.asofold.bpl.cncp.hooks.generic.HookInstaBreak;
import me.asofold.bpl.cncp.hooks.generic.HookPlayerClass;
import me.asofold.bpl.cncp.hooks.generic.HookPlayerInteract;
import me.asofold.bpl.cncp.utils.TickTask2;
import me.asofold.bpl.cncp.utils.Utils;
/**
* Quick attempt to provide compatibility to NoCheatPlus (by NeatMonster) for some other plugins that change the vanilla game mechanichs, for instance by fast block breaking.
* @author mc_dev
* Quick attempt to provide compatibility to NoCheatPlus (by NeatMonster) for
* some other plugins that change the vanilla game mechanichs, for instance by
* fast block breaking.
*
* @author asofold
*
*/
public class CompatNoCheatPlus extends JavaPlugin implements Listener {
public class CompatNoCheatPlus extends JavaPlugin {
private static CompatNoCheatPlus instance = null;
//TODO: Adjust, once NCP has order everywhere (generic + ncp-specific?).
public static final String tagEarlyFeature = "cncp.feature.early";
public static final String beforeTagEarlyFeature = ".*nocheatplus.*|.*NoCheatPlus.*";
public static final String tagLateFeature = "cncp.feature.late";
public static final String afterTagLateFeature = "cncp.system.early.*|.*nocheatplus.*|.*NoCheatPlus.*)";
public static final String tagEarlySystem = "cncp.system.early";
public static final String beforeTagEarlySystem = beforeTagEarlyFeature; // ...
public static final RegistrationOrder defaultOrderSystemEarly = new RegistrationOrder(
tagEarlySystem,
beforeTagEarlySystem,
null);
public static final RegistrationOrder defaultOrderFeatureEarly = new RegistrationOrder(
tagEarlyFeature,
beforeTagEarlyFeature,
"cncp.system.early.*");
public static final RegistrationOrder defaultOrderFeatureLate = new RegistrationOrder(
tagLateFeature,
null,
afterTagLateFeature);
private final Settings settings = new Settings();
@ -62,15 +82,6 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
*/
private static boolean enabled = false;
/**
* Experimental: static method to enable this plugin, only enables if it is not already enabled.
* @return
*/
public static boolean enableCncp(){
if (enabled) return true;
return enablePlugin("CompatNoCheatPlus");
}
/**
* Static method to enable a plugin (might also be useful for hooks).
* @param plgName
@ -104,7 +115,7 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
* @return
*/
public static CompatNoCheatPlus getInstance(){
return instance;
return CompatNoCheatPlus.getPlugin(CompatNoCheatPlus.class);
}
/**
@ -147,20 +158,26 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
* @return
*/
public static boolean registerListeners(Hook hook) {
if (!enabled) return false;
if (!enabled) {
return false;
}
Listener[] listeners = hook.getListeners();
if (listeners != null){
// attempt to register events:
PluginManager pm = Bukkit.getPluginManager();
Plugin plg = pm.getPlugin("CompatNoCheatPlus");
if (plg == null) return false;
Plugin plg = CompatNoCheatPlus.getPlugin(CompatNoCheatPlus.class);
if (plg == null) {
return false;
}
for (Listener listener : listeners) {
pm.registerEvents(listener, plg);
NCPAPIProvider.getNoCheatPlusAPI().getEventRegistry().register(listener,
defaultOrderFeatureEarly, plg);
}
}
return true;
}
// ----
/**
* Called before loading settings, adds available hooks into a list, so they will be able to read config.
*/
@ -182,11 +199,11 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
builtinHooks.add(new me.asofold.bpl.cncp.hooks.mcmmo.HookmcMMO());
}
catch (Throwable t){}
// // MagicSpells
// try{
// builtinHooks.add(new me.asofold.bpl.cncp.hooks.magicspells.HookMagicSpells());
// }
// catch (Throwable t){}
// // MagicSpells
// try{
// builtinHooks.add(new me.asofold.bpl.cncp.hooks.magicspells.HookMagicSpells());
// }
// catch (Throwable t){}
// Simple generic hooks
for (Hook hook : new Hook[]{
new HookPlayerClass(),
@ -223,7 +240,6 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
@Override
public void onEnable() {
enabled = false; // make sure
instance = this;
// (no cleanup)
// Settings:
@ -231,8 +247,7 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
setupBuiltinHooks();
loadSettings();
// Register own listener:
final PluginManager pm = getServer().getPluginManager();
pm.registerEvents(this, this);
//NCPAPIProvider.getNoCheatPlusAPI().getEventRegistry().register(this, defaultOrderSystemEarly, this);
super.onEnable();
// Add Hooks:
@ -244,32 +259,36 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
registerListeners(hook);
}
// Start ticktask 2
getServer().getScheduler().scheduleSyncRepeatingTask(this, new TickTask2(), 1, 1);
// Register to remove hooks when NCP is disabling.
NCPAPIProvider.getNoCheatPlusAPI().addComponent(new IDisableListener(){
@Override
public void onDisable() {
// Remove all registered cncp hooks:
unregisterNCPHooks();
}
});
if (!registeredHooks.isEmpty()) {
registerHooks();
}
// Check for the NoCheatPlus plugin.
Plugin plugin = pm.getPlugin("NoCheatPlus");
if (plugin == null) {
getLogger().severe("[CompatNoCheatPlus] The NoCheatPlus plugin is not present.");
}
else if (plugin.isEnabled()) {
getLogger().severe("[CompatNoCheatPlus] The NoCheatPlus plugin already is enabled, this might break several hooks.");
}
// Start ticktask 2
// TODO: Replace by using TickTask ? Needs order (depend is used now)?
getServer().getScheduler().scheduleSyncRepeatingTask(this, new TickTask2(), 1, 1);
// Finished.
getLogger().info(getDescription().getFullName() + " is enabled. Some hooks might get registered with NoCheatPlus later on.");
}
public boolean loadSettings() {
final Set<String> oldForceEnableLater = new LinkedHashSet<String>();
oldForceEnableLater.addAll(settings.forceEnableLater);
// Read and apply config to settings:
File file = new File(getDataFolder() , "cncp.yml");
CompatConfig cfg = new NewConfig(file);
cfg.load();
boolean changed = false;
// General settings:
if (Settings.addDefaults(cfg)) changed = true;
if (Settings.addDefaults(cfg)) {
changed = true;
}
settings.fromConfig(cfg);
// Settings for builtin hooks:
for (Hook hook : builtinHooks){
@ -286,51 +305,8 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
}
}
// save back config if changed:
if (changed) cfg.save();
// Re-enable plugins that were not yet on the list:
Server server = getServer();
Logger logger = server.getLogger();
for (String plgName : settings.loadPlugins){
try{
if (CompatNoCheatPlus.enablePlugin(plgName)){
System.out.println("[cncp] Ensured that the following plugin is enabled: " + plgName);
}
}
catch (Throwable t){
logger.severe("[cncp] Failed to enable the plugin: " + plgName);
logger.severe(Utils.toString(t));
}
}
BukkitScheduler sched = server.getScheduler();
for (String plgName : settings.forceEnableLater){
if (!oldForceEnableLater.remove(plgName)) oldForceEnableLater.add(plgName);
}
if (!oldForceEnableLater.isEmpty()){
System.out.println("[cncp] Schedule task to re-enable plugins later...");
sched.scheduleSyncDelayedTask(this, new Runnable() {
@Override
public void run() {
// (Later maybe re-enabling this plugin could be added.)
// TODO: log levels !
for (String plgName : oldForceEnableLater){
try{
if (disablePlugin(plgName)){
if (enablePlugin(plgName)) System.out.println("[cncp] Re-enabled plugin: " + plgName);
else System.out.println("[cncp] Could not re-enable plugin: "+plgName);
}
else{
System.out.println("[cncp] Could not disable plugin (already disabled?): "+plgName);
}
}
catch(Throwable t){
// TODO: maybe log ?
}
}
}
});
if (changed) {
cfg.save();
}
return true;
@ -340,7 +316,6 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
public void onDisable() {
unregisterNCPHooks(); // Just in case.
enabled = false;
instance = null; // Set last.
super.onDisable();
}
@ -382,26 +357,6 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
return n;
}
@EventHandler(priority = EventPriority.NORMAL)
void onPluginEnable(PluginEnableEvent event){
Plugin plugin = event.getPlugin();
if (!plugin.getName().equals("NoCheatPlus")) {
return;
}
// Register to remove hooks when NCP is disabling.
NCPAPIProvider.getNoCheatPlusAPI().addComponent(new IDisableListener(){
@Override
public void onDisable() {
// Remove all registered cncp hooks:
unregisterNCPHooks();
}
});
if (registeredHooks.isEmpty()) {
return;
}
registerHooks();
}
/* (non-Javadoc)
* @see org.bukkit.plugin.java.JavaPlugin#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
*/

View File

@ -1,7 +1,6 @@
package me.asofold.bpl.cncp.config;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Set;
@ -12,63 +11,57 @@ import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil;
import me.asofold.bpl.cncp.config.compatlayer.NewConfig;
public class Settings {
public static final int configVersion = 2;
public Set<String> forceEnableLater = new LinkedHashSet<String>();
public Set<String> loadPlugins = new LinkedHashSet<String>();
public static Set<String> preventAddHooks = new HashSet<String>();
public static CompatConfig getDefaultConfig(){
CompatConfig cfg = new NewConfig(null);
cfg.set("plugins.force-enable-later", new LinkedList<String>()); // ConfigUtil.asList(new String[]{ "NoCheatPlus" }));
cfg.set("plugins.ensure-enable", new LinkedList<String>()); // ConfigUtil.asList(new String[]{ "WorldGuard" }));
cfg.set("hooks.prevent-add", new LinkedList<String>());
cfg.set("configversion", configVersion);
return cfg;
}
public static boolean addDefaults(CompatConfig cfg){
boolean changed = false;
if (cfg.getInt("configversion", 0) == 0){
cfg.remove("plugins");
cfg.set("configversion", configVersion);
changed = true;
}
if (cfg.getInt("configversion", 0) <= 1){
if (cfg.getDouble("hooks.set-speed.fly-speed", 0.1) != 0.1){
changed = true;
cfg.set("hooks.set-speed.fly-speed", 0.1);
Bukkit.getLogger().warning("[cncp] Reset fly-speed for the set-speed hook to 0.1 (default) as a safety measure.");
}
if (cfg.getDouble("hooks.set-speed.walk-speed", 0.2) != 0.2){
changed = true;
cfg.set("hooks.set-speed.walk-speed", 0.2);
Bukkit.getLogger().warning("[cncp] Reset walk-speed for the set-speed hook to 0.2 (default) as a safety measure.");
}
}
if (ConfigUtil.forceDefaults(getDefaultConfig(), cfg)) changed = true;
if (cfg.getInt("configversion", 0) != configVersion){
cfg.set("configversion", configVersion);
changed = true;
}
return changed;
}
public boolean fromConfig(CompatConfig cfg){
// Settings ref = new Settings();
// plugins to force enabling after this plugin.
ConfigUtil.readStringSetFromList(cfg, "plugins.force-enable-later", forceEnableLater, true, true, false);
ConfigUtil.readStringSetFromList(cfg, "plugins.ensure-enable", loadPlugins, true, true, false);
// General
ConfigUtil.readStringSetFromList(cfg, "hooks.prevent-add", preventAddHooks, true, true, false);
return true;
}
public static final int configVersion = 3;
public static Set<String> preventAddHooks = new HashSet<String>();
public static CompatConfig getDefaultConfig(){
CompatConfig cfg = new NewConfig(null);
cfg.set("plugins.force-enable-later", new LinkedList<String>()); // ConfigUtil.asList(new String[]{ "NoCheatPlus" }));
cfg.set("plugins.ensure-enable", new LinkedList<String>()); // ConfigUtil.asList(new String[]{ "WorldGuard" }));
cfg.set("hooks.prevent-add", new LinkedList<String>());
cfg.set("configversion", configVersion);
return cfg;
}
public static boolean addDefaults(CompatConfig cfg){
boolean changed = false;
if (cfg.getInt("configversion", 0) == 0){
cfg.remove("plugins");
cfg.set("configversion", configVersion);
changed = true;
}
if (cfg.getInt("configversion", 0) <= 1){
if (cfg.getDouble("hooks.set-speed.fly-speed", 0.1) != 0.1){
changed = true;
cfg.set("hooks.set-speed.fly-speed", 0.1);
Bukkit.getLogger().warning("[cncp] Reset fly-speed for the set-speed hook to 0.1 (default) as a safety measure.");
}
if (cfg.getDouble("hooks.set-speed.walk-speed", 0.2) != 0.2){
changed = true;
cfg.set("hooks.set-speed.walk-speed", 0.2);
Bukkit.getLogger().warning("[cncp] Reset walk-speed for the set-speed hook to 0.2 (default) as a safety measure.");
}
}
if (ConfigUtil.forceDefaults(getDefaultConfig(), cfg)) changed = true;
if (cfg.getInt("configversion", 0) != configVersion){
cfg.set("configversion", configVersion);
changed = true;
}
return changed;
}
public boolean fromConfig(CompatConfig cfg){
// Settings ref = new Settings();
// General
ConfigUtil.readStringSetFromList(cfg, "hooks.prevent-add", preventAddHooks, true, true, false);
return true;
}
public void clear() {
// TODO: clear something !?
}
public void clear() {
forceEnableLater.clear();
}
}

View File

@ -2,6 +2,7 @@ package me.asofold.bpl.cncp.hooks.generic;
import java.util.Arrays;
import me.asofold.bpl.cncp.CompatNoCheatPlus;
import me.asofold.bpl.cncp.config.compatlayer.CompatConfig;
import org.bukkit.event.EventHandler;
@ -10,6 +11,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.components.registry.order.RegistrationOrder.RegisterMethodWithOrder;
/**
* Wrap block break events to exempt players from checks by comparison of event class names.
@ -18,47 +20,49 @@ import fr.neatmonster.nocheatplus.checks.CheckType;
*/
public class HookBlockBreak extends ClassExemptionHook implements Listener {
public HookBlockBreak() {
super("block-break.");
defaultClasses.addAll(Arrays.asList(new String[]{
// MachinaCraft
"ArtificialBlockBreakEvent",
// mcMMO
"FakeBlockBreakEvent",
// MagicSpells
"MagicSpellsBlockBreakEvent"
}));
}
public HookBlockBreak() {
super("block-break.");
defaultClasses.addAll(Arrays.asList(new String[]{
// MachinaCraft
"ArtificialBlockBreakEvent",
// mcMMO
"FakeBlockBreakEvent",
// MagicSpells
"MagicSpellsBlockBreakEvent"
}));
}
@Override
public String getHookName() {
return "BlockBreak(default)";
}
@Override
public String getHookName() {
return "BlockBreak(default)";
}
@Override
public String getHookVersion() {
return "1.1";
}
@Override
public Listener[] getListeners() {
return new Listener[]{this};
}
@Override
public String getHookVersion() {
return "1.1";
}
@Override
public void applyConfig(CompatConfig cfg, String prefix) {
super.applyConfig(cfg, prefix);
if (classes.isEmpty()) enabled = false;
}
@Override
public Listener[] getListeners() {
return new Listener[]{this};
}
@EventHandler(priority = EventPriority.LOWEST)
final void onBlockBreakLowest(final BlockBreakEvent event){
checkExempt(event.getPlayer(), event.getClass(), CheckType.BLOCKBREAK);
}
@EventHandler(priority = EventPriority.MONITOR)
final void onBlockBreakMonitor(final BlockBreakEvent event){
checkUnexempt(event.getPlayer(), event.getClass(), CheckType.BLOCKBREAK);
}
@Override
public void applyConfig(CompatConfig cfg, String prefix) {
super.applyConfig(cfg, prefix);
if (classes.isEmpty()) enabled = false;
}
@EventHandler(priority = EventPriority.LOWEST)
@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagEarlyFeature, beforeTag = CompatNoCheatPlus.beforeTagEarlyFeature)
final void onBlockBreakLowest(final BlockBreakEvent event){
checkExempt(event.getPlayer(), event.getClass(), CheckType.BLOCKBREAK);
}
@EventHandler(priority = EventPriority.MONITOR)
@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagLateFeature, afterTag = CompatNoCheatPlus.afterTagLateFeature)
final void onBlockBreakMonitor(final BlockBreakEvent event){
checkUnexempt(event.getPlayer(), event.getClass(), CheckType.BLOCKBREAK);
}
}

View File

@ -2,6 +2,7 @@ package me.asofold.bpl.cncp.hooks.generic;
import java.util.Arrays;
import me.asofold.bpl.cncp.CompatNoCheatPlus;
import me.asofold.bpl.cncp.config.compatlayer.CompatConfig;
import org.bukkit.event.EventHandler;
@ -10,6 +11,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.components.registry.order.RegistrationOrder.RegisterMethodWithOrder;
/**
* Wrap block place events to exempt players from checks by comparison of event class names.
@ -18,45 +20,47 @@ import fr.neatmonster.nocheatplus.checks.CheckType;
*/
public class HookBlockPlace extends ClassExemptionHook implements Listener{
public HookBlockPlace() {
super("block-place.");
defaultClasses.addAll(Arrays.asList(new String[]{
// MachinaCraft
"ArtificialBlockPlaceEvent",
// MagicSpells
"MagicSpellsBlockPlaceEvent"
}));
}
public HookBlockPlace() {
super("block-place.");
defaultClasses.addAll(Arrays.asList(new String[]{
// MachinaCraft
"ArtificialBlockPlaceEvent",
// MagicSpells
"MagicSpellsBlockPlaceEvent"
}));
}
@Override
public String getHookName() {
return "BlockPlace(default)";
}
@Override
public String getHookName() {
return "BlockPlace(default)";
}
@Override
public String getHookVersion() {
return "1.0";
}
@Override
public Listener[] getListeners() {
return new Listener[]{this};
}
@Override
public void applyConfig(CompatConfig cfg, String prefix) {
super.applyConfig(cfg, prefix);
if (classes.isEmpty()) enabled = false;
}
@Override
public String getHookVersion() {
return "1.0";
}
@EventHandler(priority = EventPriority.LOWEST)
final void onBlockPlaceLowest(final BlockPlaceEvent event){
checkExempt(event.getPlayer(), event.getClass(), CheckType.BLOCKPLACE);
}
@EventHandler(priority = EventPriority.MONITOR)
final void onBlockPlaceMonitor(final BlockPlaceEvent event){
checkUnexempt(event.getPlayer(), event.getClass(), CheckType.BLOCKPLACE);
}
@Override
public Listener[] getListeners() {
return new Listener[]{this};
}
@Override
public void applyConfig(CompatConfig cfg, String prefix) {
super.applyConfig(cfg, prefix);
if (classes.isEmpty()) enabled = false;
}
@EventHandler(priority = EventPriority.LOWEST)
@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagEarlyFeature, beforeTag = CompatNoCheatPlus.beforeTagEarlyFeature)
final void onBlockPlaceLowest(final BlockPlaceEvent event){
checkExempt(event.getPlayer(), event.getClass(), CheckType.BLOCKPLACE);
}
@EventHandler(priority = EventPriority.MONITOR)
@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagLateFeature, afterTag = CompatNoCheatPlus.afterTagLateFeature)
final void onBlockPlaceMonitor(final BlockPlaceEvent event){
checkUnexempt(event.getPlayer(), event.getClass(), CheckType.BLOCKPLACE);
}
}

View File

@ -2,6 +2,7 @@ package me.asofold.bpl.cncp.hooks.generic;
import java.util.Arrays;
import me.asofold.bpl.cncp.CompatNoCheatPlus;
import me.asofold.bpl.cncp.config.compatlayer.CompatConfig;
import org.bukkit.entity.Entity;
@ -12,55 +13,58 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.components.registry.order.RegistrationOrder.RegisterMethodWithOrder;
public class HookEntityDamageByEntity extends ClassExemptionHook implements
Listener {
Listener {
public HookEntityDamageByEntity() {
super("entity-damage-by-entity.");
defaultClasses.addAll(Arrays.asList(new String[] {
// CrackShot
"WeaponDamageEntityEvent",
// MagicSpells
"MagicSpellsEntityDamageByEntityEvent" }));
}
public HookEntityDamageByEntity() {
super("entity-damage-by-entity.");
defaultClasses.addAll(Arrays.asList(new String[] {
// CrackShot
"WeaponDamageEntityEvent",
// MagicSpells
"MagicSpellsEntityDamageByEntityEvent" }));
}
@Override
public String getHookName() {
return "EntityDamageByEntity(default)";
}
@Override
public String getHookName() {
return "EntityDamageByEntity(default)";
}
@Override
public String getHookVersion() {
return "0.0";
}
@Override
public String getHookVersion() {
return "0.0";
}
@Override
public Listener[] getListeners() {
return new Listener[] { this };
}
@Override
public Listener[] getListeners() {
return new Listener[] { this };
}
@Override
public void applyConfig(CompatConfig cfg, String prefix) {
super.applyConfig(cfg, prefix);
if (classes.isEmpty())
enabled = false;
}
@Override
public void applyConfig(CompatConfig cfg, String prefix) {
super.applyConfig(cfg, prefix);
if (classes.isEmpty())
enabled = false;
}
@EventHandler(priority = EventPriority.LOWEST)
final void onDamageLowest(final EntityDamageByEntityEvent event) {
final Entity damager = event.getDamager();
if (damager instanceof Player) {
checkExempt((Player) damager, event.getClass(), CheckType.FIGHT);
}
}
@EventHandler(priority = EventPriority.LOWEST)
@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagEarlyFeature, beforeTag = CompatNoCheatPlus.beforeTagEarlyFeature)
final void onDamageLowest(final EntityDamageByEntityEvent event) {
final Entity damager = event.getDamager();
if (damager instanceof Player) {
checkExempt((Player) damager, event.getClass(), CheckType.FIGHT);
}
}
@EventHandler(priority = EventPriority.MONITOR)
final void onDamageMonitor(final EntityDamageByEntityEvent event) {
final Entity damager = event.getDamager();
if (damager instanceof Player) {
checkUnexempt((Player) damager, event.getClass(), CheckType.FIGHT);
}
}
@EventHandler(priority = EventPriority.MONITOR)
@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagLateFeature, afterTag = CompatNoCheatPlus.afterTagLateFeature)
final void onDamageMonitor(final EntityDamageByEntityEvent event) {
final Entity damager = event.getDamager();
if (damager instanceof Player) {
checkUnexempt((Player) damager, event.getClass(), CheckType.FIGHT);
}
}
}

View File

@ -6,6 +6,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import me.asofold.bpl.cncp.CompatNoCheatPlus;
import me.asofold.bpl.cncp.config.compatlayer.CompatConfig;
import me.asofold.bpl.cncp.config.compatlayer.CompatConfigFactory;
import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil;
@ -19,153 +20,157 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.components.registry.order.RegistrationOrder.RegisterMethodWithOrder;
import fr.neatmonster.nocheatplus.utilities.TickTask;
public class HookInstaBreak extends AbstractHook implements ConfigurableHook, Listener {
public static interface InstaExemption{
public void addExemptNext(CheckType[] types);
public Set<CheckType> getExemptNext();
}
public static class StackEntry{
public final CheckType[] checkTypes;
public final int tick;
public final Player player;
public boolean used = false;
public StackEntry(final Player player , final CheckType[] checkTypes){
this.player = player;
this.checkTypes = checkTypes;
tick = TickTask.getTick();
}
public boolean isOutdated(final int tick){
return tick != this.tick;
}
}
protected static InstaExemption runtime = null;
public static void addExemptNext(final CheckType[] types){
runtime.addExemptNext(types);
}
protected final ExemptionManager exMan = new ExemptionManager();
protected boolean enabled = true;
protected final List<StackEntry> stack = new LinkedList<StackEntry>();
@Override
public String getHookName() {
return "InstaBreak(default)";
}
public static interface InstaExemption{
public void addExemptNext(CheckType[] types);
public Set<CheckType> getExemptNext();
}
@Override
public String getHookVersion() {
return "1.0";
}
public static class StackEntry{
public final CheckType[] checkTypes;
public final int tick;
public final Player player;
public boolean used = false;
public StackEntry(final Player player , final CheckType[] checkTypes){
this.player = player;
this.checkTypes = checkTypes;
tick = TickTask.getTick();
}
public boolean isOutdated(final int tick){
return tick != this.tick;
}
}
@Override
public void applyConfig(CompatConfig cfg, String prefix) {
enabled = cfg.getBoolean(prefix + "insta-break.enabled", true);
}
protected static InstaExemption runtime = null;
@Override
public boolean updateConfig(CompatConfig cfg, String prefix) {
CompatConfig defaults = CompatConfigFactory.getConfig(null);
defaults.set(prefix + "insta-break.enabled", true);
return ConfigUtil.forceDefaults(defaults, cfg);
}
public static void addExemptNext(final CheckType[] types){
runtime.addExemptNext(types);
}
@Override
public boolean isEnabled() {
return enabled;
}
protected final ExemptionManager exMan = new ExemptionManager();
@Override
public CheckType[] getCheckTypes() {
return null;
}
protected boolean enabled = true;
@Override
public Listener[] getListeners() {
runtime = new InstaExemption() {
protected final Set<CheckType> types = new HashSet<CheckType>();
@Override
public final void addExemptNext(final CheckType[] types) {
for (int i = 0; i < types.length; i++){
this.types.add(types[i]);
}
}
@Override
public Set<CheckType> getExemptNext() {
return types;
}
};
return new Listener[]{this};
}
protected CheckType[] fetchTypes(){
final Set<CheckType> types = runtime.getExemptNext();
final CheckType[] a = new CheckType[types.size()];
if (!types.isEmpty()) types.toArray(a);
types.clear();
return a;
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false)
public void onBlockDamage(final BlockDamageEvent event){
checkStack();
if (!event.isCancelled() && event.getInstaBreak()){
stack.add(new StackEntry(event.getPlayer(), fetchTypes()));
}
else{
runtime.getExemptNext().clear();
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
public void onBlockBreakLowest(final BlockBreakEvent event){
checkStack();
if (!stack.isEmpty()){
final Player player = event.getPlayer();
final StackEntry entry = stack.get(stack.size() - 1);
if (player.equals(entry.player)) addExemption(entry);
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false)
public void onBlockBreakMONITOR(final BlockBreakEvent event){
if (!stack.isEmpty()){
final Player player = event.getPlayer();
final StackEntry entry = stack.get(stack.size() - 1);
if (player.equals(entry.player)) removeExemption(stack.remove(stack.size() - 1));
}
}
public void addExemption(final StackEntry entry){
entry.used = true;
for (int i = 0; i < entry.checkTypes.length; i++){
exMan.addExemption(entry.player, entry.checkTypes[i]);
}
}
public void removeExemption(final StackEntry entry){
if (!entry.used) return;
for (int i = 0; i < entry.checkTypes.length; i++){
exMan.removeExemption(entry.player, entry.checkTypes[i]);
}
}
public void checkStack(){
if (stack.isEmpty()) return;
Iterator<StackEntry> it = stack.iterator();
final int tick = TickTask.getTick();
while (it.hasNext()){
final StackEntry entry = it.next();
if (entry.isOutdated(tick)) it.remove();
if (entry.used) removeExemption(entry);
}
}
protected final List<StackEntry> stack = new LinkedList<StackEntry>();
@Override
public String getHookName() {
return "InstaBreak(default)";
}
@Override
public String getHookVersion() {
return "1.0";
}
@Override
public void applyConfig(CompatConfig cfg, String prefix) {
enabled = cfg.getBoolean(prefix + "insta-break.enabled", true);
}
@Override
public boolean updateConfig(CompatConfig cfg, String prefix) {
CompatConfig defaults = CompatConfigFactory.getConfig(null);
defaults.set(prefix + "insta-break.enabled", true);
return ConfigUtil.forceDefaults(defaults, cfg);
}
@Override
public boolean isEnabled() {
return enabled;
}
@Override
public CheckType[] getCheckTypes() {
return null;
}
@Override
public Listener[] getListeners() {
runtime = new InstaExemption() {
protected final Set<CheckType> types = new HashSet<CheckType>();
@Override
public final void addExemptNext(final CheckType[] types) {
for (int i = 0; i < types.length; i++){
this.types.add(types[i]);
}
}
@Override
public Set<CheckType> getExemptNext() {
return types;
}
};
return new Listener[]{this};
}
protected CheckType[] fetchTypes(){
final Set<CheckType> types = runtime.getExemptNext();
final CheckType[] a = new CheckType[types.size()];
if (!types.isEmpty()) types.toArray(a);
types.clear();
return a;
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false)
@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagLateFeature, afterTag = CompatNoCheatPlus.afterTagLateFeature)
public void onBlockDamage(final BlockDamageEvent event){
checkStack();
if (!event.isCancelled() && event.getInstaBreak()){
stack.add(new StackEntry(event.getPlayer(), fetchTypes()));
}
else{
runtime.getExemptNext().clear();
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagEarlyFeature, beforeTag = CompatNoCheatPlus.beforeTagEarlyFeature)
public void onBlockBreakLowest(final BlockBreakEvent event){
checkStack();
if (!stack.isEmpty()){
final Player player = event.getPlayer();
final StackEntry entry = stack.get(stack.size() - 1);
if (player.equals(entry.player)) addExemption(entry);
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false)
@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagLateFeature, afterTag = CompatNoCheatPlus.afterTagLateFeature)
public void onBlockBreakMONITOR(final BlockBreakEvent event){
if (!stack.isEmpty()){
final Player player = event.getPlayer();
final StackEntry entry = stack.get(stack.size() - 1);
if (player.equals(entry.player)) removeExemption(stack.remove(stack.size() - 1));
}
}
public void addExemption(final StackEntry entry){
entry.used = true;
for (int i = 0; i < entry.checkTypes.length; i++){
exMan.addExemption(entry.player, entry.checkTypes[i]);
}
}
public void removeExemption(final StackEntry entry){
if (!entry.used) return;
for (int i = 0; i < entry.checkTypes.length; i++){
exMan.removeExemption(entry.player, entry.checkTypes[i]);
}
}
public void checkStack(){
if (stack.isEmpty()) return;
Iterator<StackEntry> it = stack.iterator();
final int tick = TickTask.getTick();
while (it.hasNext()){
final StackEntry entry = it.next();
if (entry.isOutdated(tick)) it.remove();
if (entry.used) removeExemption(entry);
}
}
}

View File

@ -1,6 +1,8 @@
package me.asofold.bpl.cncp.hooks.generic;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.components.registry.order.RegistrationOrder.RegisterMethodWithOrder;
import me.asofold.bpl.cncp.CompatNoCheatPlus;
import me.asofold.bpl.cncp.config.compatlayer.CompatConfig;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -16,43 +18,45 @@ import java.util.Arrays;
*/
public class HookPlayerInteract extends ClassExemptionHook implements Listener{
public HookPlayerInteract() {
super("player-interact.");
defaultClasses.addAll(Arrays.asList(new String[]{
// MagicSpells
"MagicSpellsPlayerInteractEvent"
}));
}
public HookPlayerInteract() {
super("player-interact.");
defaultClasses.addAll(Arrays.asList(new String[]{
// MagicSpells
"MagicSpellsPlayerInteractEvent"
}));
}
@Override
public String getHookName() {
return "Interact(default)";
}
@Override
public String getHookName() {
return "Interact(default)";
}
@Override
public String getHookVersion() {
return "1.0";
}
@Override
public Listener[] getListeners() {
return new Listener[]{this};
}
@Override
public void applyConfig(CompatConfig cfg, String prefix) {
super.applyConfig(cfg, prefix);
if (classes.isEmpty()) enabled = false;
}
@Override
public String getHookVersion() {
return "1.0";
}
@EventHandler(priority = EventPriority.LOWEST)
final void onPlayerInteractLowest(final PlayerInteractEvent event){
checkExempt(event.getPlayer(), event.getClass(), CheckType.BLOCKINTERACT);
}
@EventHandler(priority = EventPriority.MONITOR)
final void onPlayerInteractMonitor(final PlayerInteractEvent event){
checkUnexempt(event.getPlayer(), event.getClass(), CheckType.BLOCKINTERACT);
}
@Override
public Listener[] getListeners() {
return new Listener[]{this};
}
@Override
public void applyConfig(CompatConfig cfg, String prefix) {
super.applyConfig(cfg, prefix);
if (classes.isEmpty()) enabled = false;
}
@EventHandler(priority = EventPriority.LOWEST)
@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagEarlyFeature, beforeTag = CompatNoCheatPlus.beforeTagEarlyFeature)
final void onPlayerInteractLowest(final PlayerInteractEvent event){
checkExempt(event.getPlayer(), event.getClass(), CheckType.BLOCKINTERACT);
}
@EventHandler(priority = EventPriority.MONITOR)
@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagLateFeature, afterTag = CompatNoCheatPlus.afterTagLateFeature)
final void onPlayerInteractMonitor(final PlayerInteractEvent event){
checkUnexempt(event.getPlayer(), event.getClass(), CheckType.BLOCKINTERACT);
}
}

View File

@ -1,5 +1,6 @@
package me.asofold.bpl.cncp.hooks.generic;
import me.asofold.bpl.cncp.CompatNoCheatPlus;
import me.asofold.bpl.cncp.config.compatlayer.CompatConfig;
import me.asofold.bpl.cncp.config.compatlayer.CompatConfigFactory;
import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil;
@ -13,94 +14,96 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.components.registry.order.RegistrationOrder.RegisterMethodWithOrder;
public class HookSetSpeed extends AbstractHook implements Listener, ConfigurableHook{
private static final float defaultFlySpeed = 0.1f;
private static final float defaultWalkSpeed = 0.2f;
protected float flySpeed = defaultFlySpeed;
protected float walkSpeed = defaultWalkSpeed;
protected boolean enabled = false;
// private String allowFlightPerm = "cncp.allow-flight";
public HookSetSpeed() throws SecurityException, NoSuchMethodException{
Player.class.getDeclaredMethod("setFlySpeed", float.class);
}
public void init(){
for (final Player player : Bukkit.getOnlinePlayers()){
setSpeed(player);
}
}
@Override
public String getHookName() {
return "SetSpeed(default)";
}
@Override
public String getHookVersion() {
return "2.2";
}
private static final float defaultFlySpeed = 0.1f;
private static final float defaultWalkSpeed = 0.2f;
@Override
public CheckType[] getCheckTypes() {
return new CheckType[0];
}
protected float flySpeed = defaultFlySpeed;
protected float walkSpeed = defaultWalkSpeed;
@Override
public Listener[] getListeners() {
try{
// Initialize here, at the end of enable.
init();
}
catch (Throwable t){}
return new Listener[]{this} ;
}
public final void setSpeed(final Player player){
// if (allowFlightPerm.equals("") || player.hasPermission(allowFlightPerm)) player.setAllowFlight(true);
player.setWalkSpeed(walkSpeed);
player.setFlySpeed(flySpeed);
}
@EventHandler(priority=EventPriority.LOWEST)
public final void onPlayerJoin(final PlayerJoinEvent event){
setSpeed(event.getPlayer());
}
protected boolean enabled = false;
@Override
public void applyConfig(CompatConfig cfg, String prefix) {
enabled = cfg.getBoolean(prefix + "set-speed.enabled", false);
flySpeed = cfg.getDouble(prefix + "set-speed.fly-speed", (double) defaultFlySpeed).floatValue();
walkSpeed = cfg.getDouble(prefix + "set-speed.walk-speed", (double) defaultWalkSpeed).floatValue();
// allowFlightPerm = cfg.getString(prefix + "set-speed.allow-flight-permission", ref.allowFlightPerm);
}
// private String allowFlightPerm = "cncp.allow-flight";
@Override
public boolean updateConfig(CompatConfig cfg, String prefix) {
CompatConfig defaults = CompatConfigFactory.getConfig(null);
defaults.set(prefix + "set-speed.enabled", false);
defaults.set(prefix + "set-speed.fly-speed", defaultFlySpeed);
defaults.set(prefix + "set-speed.walk-speed", defaultWalkSpeed);
// cfg.set(prefix + "set-speed.allow-flight-permission", ref.allowFlightPerm);
return ConfigUtil.forceDefaults(defaults, cfg);
}
public HookSetSpeed() throws SecurityException, NoSuchMethodException{
Player.class.getDeclaredMethod("setFlySpeed", float.class);
}
@Override
public boolean isEnabled() {
return enabled;
}
public void init(){
for (final Player player : Bukkit.getOnlinePlayers()){
setSpeed(player);
}
}
// public String getAllowFlightPerm() {
// return allowFlightPerm;
// }
@Override
public String getHookName() {
return "SetSpeed(default)";
}
// public void setAllowFlightPerm(String allowFlightPerm) {
// this.allowFlightPerm = allowFlightPerm;
// }
@Override
public String getHookVersion() {
return "2.2";
}
@Override
public CheckType[] getCheckTypes() {
return new CheckType[0];
}
@Override
public Listener[] getListeners() {
try{
// Initialize here, at the end of enable.
init();
}
catch (Throwable t){}
return new Listener[]{this} ;
}
public final void setSpeed(final Player player){
// if (allowFlightPerm.equals("") || player.hasPermission(allowFlightPerm)) player.setAllowFlight(true);
player.setWalkSpeed(walkSpeed);
player.setFlySpeed(flySpeed);
}
@EventHandler(priority=EventPriority.LOWEST)
@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagEarlyFeature, beforeTag = CompatNoCheatPlus.beforeTagEarlyFeature)
public final void onPlayerJoin(final PlayerJoinEvent event){
setSpeed(event.getPlayer());
}
@Override
public void applyConfig(CompatConfig cfg, String prefix) {
enabled = cfg.getBoolean(prefix + "set-speed.enabled", false);
flySpeed = cfg.getDouble(prefix + "set-speed.fly-speed", (double) defaultFlySpeed).floatValue();
walkSpeed = cfg.getDouble(prefix + "set-speed.walk-speed", (double) defaultWalkSpeed).floatValue();
// allowFlightPerm = cfg.getString(prefix + "set-speed.allow-flight-permission", ref.allowFlightPerm);
}
@Override
public boolean updateConfig(CompatConfig cfg, String prefix) {
CompatConfig defaults = CompatConfigFactory.getConfig(null);
defaults.set(prefix + "set-speed.enabled", false);
defaults.set(prefix + "set-speed.fly-speed", defaultFlySpeed);
defaults.set(prefix + "set-speed.walk-speed", defaultWalkSpeed);
// cfg.set(prefix + "set-speed.allow-flight-permission", ref.allowFlightPerm);
return ConfigUtil.forceDefaults(defaults, cfg);
}
@Override
public boolean isEnabled() {
return enabled;
}
// public String getAllowFlightPerm() {
// return allowFlightPerm;
// }
// public void setAllowFlightPerm(String allowFlightPerm) {
// this.allowFlightPerm = allowFlightPerm;
// }
}

View File

@ -1,5 +1,6 @@
package me.asofold.bpl.cncp.hooks.mcmmo;
import me.asofold.bpl.cncp.CompatNoCheatPlus;
import me.asofold.bpl.cncp.config.compatlayer.CompatConfig;
import me.asofold.bpl.cncp.config.compatlayer.CompatConfigFactory;
import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil;
@ -19,160 +20,167 @@ import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.components.registry.order.RegistrationOrder.RegisterMethodWithOrder;
import fr.neatmonster.nocheatplus.hooks.NCPHook;
public final class HookmcMMO extends AbstractHook implements Listener, ConfigurableHook {
/**
* To let the listener access this.
* @author mc_dev
*
*/
public static interface HookFacade{
public void damageLowest(Player player);
public void damageMonitor(Player player);
public void blockDamageLowest(Player player);
public void blockDamageMonitor(Player player);
/**
* If to cancel the event.
* @param player
* @return
*/
public boolean blockBreakLowest(Player player);
public void blockBreakMontitor(Player player);
}
protected HookFacade ncpHook = null;
protected boolean enabled = true;
protected String configPrefix = "mcmmo.";
protected boolean useInstaBreakHook = true;
public HookmcMMO(){
assertPluginPresent("mcMMO");
}
protected final PluginGetter<mcMMO> fetch = new PluginGetter<mcMMO>("mcMMO");
/**
* To let the listener access this.
* @author mc_dev
*
*/
public static interface HookFacade{
public void damageLowest(Player player);
public void damageMonitor(Player player);
public void blockDamageLowest(Player player);
public void blockDamageMonitor(Player player);
/**
* If to cancel the event.
* @param player
* @return
*/
public boolean blockBreakLowest(Player player);
public void blockBreakMontitor(Player player);
}
protected int blocksPerSecond = 30;
protected HookFacade ncpHook = null;
@Override
public String getHookName() {
return "mcMMO(default)";
}
protected boolean enabled = true;
@Override
public String getHookVersion() {
return "2.1";
}
protected String configPrefix = "mcmmo.";
@Override
public CheckType[] getCheckTypes() {
return new CheckType[]{
CheckType.BLOCKBREAK_FASTBREAK, CheckType.BLOCKBREAK_NOSWING, // old ones
// CheckType.BLOCKBREAK_DIRECTION, CheckType.BLOCKBREAK_FREQUENCY,
// CheckType.BLOCKBREAK_WRONGBLOCK, CheckType.BLOCKBREAK_REACH,
//
// CheckType.FIGHT_ANGLE, CheckType.FIGHT_SPEED, // old ones
//
// CheckType.FIGHT_DIRECTION, CheckType.FIGHT_NOSWING,
// CheckType.FIGHT_REACH,
};
}
@Override
public Listener[] getListeners() {
fetch.fetchPlugin();
return new Listener[]{this, fetch};
}
@Override
public NCPHook getNCPHook() {
if (ncpHook == null){
ncpHook = new HookFacadeImpl(useInstaBreakHook, blocksPerSecond);
}
return (NCPHook) ncpHook;
}
///////////////////////////
// Damage (fight)
//////////////////////////
@EventHandler(priority=EventPriority.LOWEST)
final void onDamageLowest(final FakeEntityDamageByEntityEvent event){
final Entity entity = event.getDamager();
if (entity instanceof Player)
ncpHook.damageLowest((Player) entity);
}
@EventHandler(priority=EventPriority.MONITOR)
final void onDamageMonitor(final FakeEntityDamageByEntityEvent event){
final Entity entity = event.getDamager();
if (entity instanceof Player)
ncpHook.damageMonitor((Player) entity);
}
///////////////////////////
// Block damage
//////////////////////////
@EventHandler(priority=EventPriority.LOWEST)
final void onBlockDamageLowest(final FakeBlockDamageEvent event){
ncpHook.blockDamageLowest(event.getPlayer());
}
@EventHandler(priority=EventPriority.LOWEST)
final void onBlockDamageMonitor(final FakeBlockDamageEvent event){
ncpHook.blockDamageMonitor(event.getPlayer());
}
///////////////////////////
// Block break
//////////////////////////
@EventHandler(priority=EventPriority.LOWEST)
final void onBlockBreakLowest(final FakeBlockBreakEvent event){
if (ncpHook.blockBreakLowest(event.getPlayer())){
event.setCancelled(true);
// System.out.println("Cancelled for frequency.");
}
}
@EventHandler(priority=EventPriority.MONITOR)
final void onBlockBreakLMonitor(final FakeBlockBreakEvent event){
ncpHook.blockBreakMontitor(event.getPlayer());
}
/////////////////////////////////
// Config
/////////////////////////////////
@Override
public void applyConfig(CompatConfig cfg, String prefix) {
enabled = cfg.getBoolean(prefix + configPrefix + "enabled", true);
useInstaBreakHook = cfg.getBoolean(prefix + configPrefix + "use-insta-break-hook", true);
blocksPerSecond = cfg.getInt(prefix + configPrefix + "clickspersecond", 20);
}
protected boolean useInstaBreakHook = true;
@Override
public boolean updateConfig(CompatConfig cfg, String prefix) {
CompatConfig defaults = CompatConfigFactory.getConfig(null);
defaults.set(prefix + configPrefix + "enabled", true);
defaults.set(prefix + configPrefix + "use-insta-break-hook", true);
defaults.set(prefix + configPrefix + "clickspersecond", 20);
return ConfigUtil.forceDefaults(defaults, cfg);
}
@Override
public boolean isEnabled() {
return enabled;
}
public HookmcMMO(){
assertPluginPresent("mcMMO");
}
protected final PluginGetter<mcMMO> fetch = new PluginGetter<mcMMO>("mcMMO");
protected int blocksPerSecond = 30;
@Override
public String getHookName() {
return "mcMMO(default)";
}
@Override
public String getHookVersion() {
return "2.1";
}
@Override
public CheckType[] getCheckTypes() {
return new CheckType[]{
CheckType.BLOCKBREAK_FASTBREAK, CheckType.BLOCKBREAK_NOSWING, // old ones
// CheckType.BLOCKBREAK_DIRECTION, CheckType.BLOCKBREAK_FREQUENCY,
// CheckType.BLOCKBREAK_WRONGBLOCK, CheckType.BLOCKBREAK_REACH,
//
// CheckType.FIGHT_ANGLE, CheckType.FIGHT_SPEED, // old ones
//
// CheckType.FIGHT_DIRECTION, CheckType.FIGHT_NOSWING,
// CheckType.FIGHT_REACH,
};
}
@Override
public Listener[] getListeners() {
fetch.fetchPlugin();
return new Listener[]{this, fetch};
}
@Override
public NCPHook getNCPHook() {
if (ncpHook == null){
ncpHook = new HookFacadeImpl(useInstaBreakHook, blocksPerSecond);
}
return (NCPHook) ncpHook;
}
///////////////////////////
// Damage (fight)
//////////////////////////
@EventHandler(priority=EventPriority.LOWEST)
@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagEarlyFeature, beforeTag = CompatNoCheatPlus.beforeTagEarlyFeature)
final void onDamageLowest(final FakeEntityDamageByEntityEvent event){
final Entity entity = event.getDamager();
if (entity instanceof Player)
ncpHook.damageLowest((Player) entity);
}
@EventHandler(priority=EventPriority.MONITOR)
@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagLateFeature, afterTag = CompatNoCheatPlus.afterTagLateFeature)
final void onDamageMonitor(final FakeEntityDamageByEntityEvent event){
final Entity entity = event.getDamager();
if (entity instanceof Player)
ncpHook.damageMonitor((Player) entity);
}
///////////////////////////
// Block damage
//////////////////////////
@EventHandler(priority=EventPriority.LOWEST)
@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagEarlyFeature, beforeTag = CompatNoCheatPlus.beforeTagEarlyFeature)
final void onBlockDamageLowest(final FakeBlockDamageEvent event){
ncpHook.blockDamageLowest(event.getPlayer());
}
@EventHandler(priority=EventPriority.LOWEST)
@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagEarlyFeature, beforeTag = CompatNoCheatPlus.beforeTagEarlyFeature)
final void onBlockDamageMonitor(final FakeBlockDamageEvent event){
ncpHook.blockDamageMonitor(event.getPlayer());
}
///////////////////////////
// Block break
//////////////////////////
@EventHandler(priority=EventPriority.LOWEST)
@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagEarlyFeature, beforeTag = CompatNoCheatPlus.beforeTagEarlyFeature)
final void onBlockBreakLowest(final FakeBlockBreakEvent event){
if (ncpHook.blockBreakLowest(event.getPlayer())){
event.setCancelled(true);
// System.out.println("Cancelled for frequency.");
}
}
@EventHandler(priority=EventPriority.MONITOR)
@RegisterMethodWithOrder(tag = CompatNoCheatPlus.tagLateFeature, afterTag = CompatNoCheatPlus.afterTagLateFeature)
final void onBlockBreakLMonitor(final FakeBlockBreakEvent event){
ncpHook.blockBreakMontitor(event.getPlayer());
}
/////////////////////////////////
// Config
/////////////////////////////////
@Override
public void applyConfig(CompatConfig cfg, String prefix) {
enabled = cfg.getBoolean(prefix + configPrefix + "enabled", true);
useInstaBreakHook = cfg.getBoolean(prefix + configPrefix + "use-insta-break-hook", true);
blocksPerSecond = cfg.getInt(prefix + configPrefix + "clickspersecond", 20);
}
@Override
public boolean updateConfig(CompatConfig cfg, String prefix) {
CompatConfig defaults = CompatConfigFactory.getConfig(null);
defaults.set(prefix + configPrefix + "enabled", true);
defaults.set(prefix + configPrefix + "use-insta-break-hook", true);
defaults.set(prefix + configPrefix + "clickspersecond", 20);
return ConfigUtil.forceDefaults(defaults, cfg);
}
@Override
public boolean isEnabled() {
return enabled;
}
}