mirror of
https://github.com/asofold/CompatNoCheatPlus.git
synced 2024-11-18 11:16:23 +01:00
- (add) Generic insta break hook.
- (add) Option to let mcMMO use the insta break hook.
This commit is contained in:
parent
c9d1b1e490
commit
980a39c693
@ -43,6 +43,10 @@ add a good mechanism for adding external configurable hooks (read automatically
|
||||
VERSION HISTORY
|
||||
---------------------------
|
||||
|
||||
(6.2.0)
|
||||
- (add) Generic insta break hook.
|
||||
- (add) Option to let mcMMO use the insta break hook.
|
||||
|
||||
(6.1.3)
|
||||
- (adapt) Adjust mcMMO hook to build 84 of NCP. Use exemption mechanisms where possible for better performance.
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: CompatNoCheatPlus
|
||||
main: me.asofold.bpl.cncp.CompatNoCheatPlus
|
||||
version: 6.1.3
|
||||
version: 6.2.0
|
||||
loadbefore:
|
||||
- NoCheatPlus
|
||||
softdepend:
|
||||
|
@ -15,6 +15,7 @@ import me.asofold.bpl.cncp.hooks.Hook;
|
||||
import me.asofold.bpl.cncp.hooks.generic.ConfigurableHook;
|
||||
import me.asofold.bpl.cncp.hooks.generic.HookBlockBreak;
|
||||
import me.asofold.bpl.cncp.hooks.generic.HookBlockPlace;
|
||||
import me.asofold.bpl.cncp.hooks.generic.HookInstaBreak;
|
||||
import me.asofold.bpl.cncp.hooks.generic.HookPlayerClass;
|
||||
import me.asofold.bpl.cncp.utils.Utils;
|
||||
|
||||
@ -178,6 +179,7 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
|
||||
new HookPlayerClass(),
|
||||
new HookBlockBreak(),
|
||||
new HookBlockPlace(),
|
||||
new HookInstaBreak(),
|
||||
}){
|
||||
builtinHooks.add(hook);
|
||||
}
|
||||
|
@ -0,0 +1,84 @@
|
||||
package me.asofold.bpl.cncp.hooks.generic;
|
||||
|
||||
import me.asofold.bpl.cncp.config.compatlayer.CompatConfig;
|
||||
import me.asofold.bpl.cncp.config.compatlayer.CompatConfigFactory;
|
||||
import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil;
|
||||
import me.asofold.bpl.cncp.hooks.AbstractHook;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockDamageEvent;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
|
||||
public class HookInstaBreak extends AbstractHook implements ConfigurableHook, Listener {
|
||||
|
||||
protected final ExemptionManager exMan = new ExemptionManager();
|
||||
|
||||
protected boolean enabled = true;
|
||||
|
||||
protected boolean skipNext = false;
|
||||
|
||||
@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() {
|
||||
return new Listener[]{this};
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onBlockDamage(final BlockDamageEvent event){
|
||||
if (event.getInstaBreak()) skipNext = true;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
|
||||
public void onBlockBreakLowest(final BlockBreakEvent event){
|
||||
if (skipNext){
|
||||
final Player player = event.getPlayer();
|
||||
exMan.addExemption(player, CheckType.BLOCKBREAK_FASTBREAK);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
|
||||
public void onBlockBreakMONITOR(final BlockBreakEvent event){
|
||||
if (skipNext){
|
||||
final Player player = event.getPlayer();
|
||||
exMan.removeExemption(player, CheckType.BLOCKBREAK_FASTBREAK);
|
||||
}
|
||||
skipNext = false;
|
||||
}
|
||||
|
||||
}
|
@ -49,6 +49,7 @@ public class HookFacadeImpl implements HookFacade, NCPHook {
|
||||
// protected final Map<CheckType, Integer> cancelChecksBlockDamage = new HashMap<CheckType, Integer>();
|
||||
// protected final Map<CheckType, Integer> cancelChecksDamage = new HashMap<CheckType, Integer>();
|
||||
|
||||
protected boolean useInstaBreakHook;
|
||||
protected int clicksPerSecond;
|
||||
protected String cancel = null;
|
||||
protected long cancelTicks = 0;
|
||||
@ -66,7 +67,8 @@ public class HookFacadeImpl implements HookFacade, NCPHook {
|
||||
protected int lastBreakAddCount = 0;
|
||||
protected long lastBreakCleanup = 0;
|
||||
|
||||
public HookFacadeImpl(int clicksPerSecond){
|
||||
public HookFacadeImpl(boolean useInstaBreakHook, int clicksPerSecond){
|
||||
this.useInstaBreakHook = useInstaBreakHook;
|
||||
this.clicksPerSecond = clicksPerSecond;
|
||||
cancelChecksBlockBreak.put(CheckType.BLOCKBREAK_NOSWING, 1);
|
||||
cancelChecksBlockBreak.put(CheckType.BLOCKBREAK_FASTBREAK, 1);
|
||||
@ -186,7 +188,7 @@ public class HookFacadeImpl implements HookFacade, NCPHook {
|
||||
}
|
||||
|
||||
addExemption(player, exemptBreakNormal);
|
||||
if (!isAxe){
|
||||
if (!useInstaBreakHook && !isAxe){
|
||||
setPlayer(player, cancelChecksBlockBreak);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CompatNoCheatPlus.getInstance(), new Runnable() {
|
||||
@Override
|
||||
|
@ -48,6 +48,8 @@ public final class HookmcMMO extends AbstractHook implements Listener, Configura
|
||||
|
||||
protected String configPrefix = "mcmmo.";
|
||||
|
||||
protected boolean useInstaBreakHook = true;
|
||||
|
||||
|
||||
public HookmcMMO(){
|
||||
assertPluginPresent("mcMMO");
|
||||
@ -94,7 +96,7 @@ public final class HookmcMMO extends AbstractHook implements Listener, Configura
|
||||
@Override
|
||||
public NCPHook getNCPHook() {
|
||||
if (ncpHook == null){
|
||||
ncpHook = new HookFacadeImpl(blocksPerSecond);
|
||||
ncpHook = new HookFacadeImpl(useInstaBreakHook, blocksPerSecond);
|
||||
}
|
||||
return (NCPHook) ncpHook;
|
||||
}
|
||||
@ -155,6 +157,7 @@ public final class HookmcMMO extends AbstractHook implements Listener, Configura
|
||||
@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", 30);
|
||||
}
|
||||
|
||||
@ -162,6 +165,7 @@ public final class HookmcMMO extends AbstractHook implements Listener, Configura
|
||||
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", 30);
|
||||
return ConfigUtil.forceDefaults(defaults, cfg);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user