From 4f0221fa3c1d4ebb564c8132821cac7d763a6faa Mon Sep 17 00:00:00 2001 From: Eluinhost Date: Wed, 11 Jan 2017 20:53:06 +0000 Subject: [PATCH 1/4] Skript integration --- checkstyle.xml | 4 +- docs/skript.md | 41 ++++++ pom.xml | 10 ++ src/main/java/gg/uhc/uhc/UHC.java | 9 ++ .../gg/uhc/uhc/modules/DisableableModule.java | 7 +- ...vent.java => ModuleChangeStatusEvent.java} | 20 ++- .../modules/health/HardcoreHeartsModule.java | 6 +- .../team/prefixes/PrefixColourPredicate.java | 1 - .../uhc/uhc/modules/timer/TimeConverter.java | 1 - .../skript/CondDisableableModuleEnabled.java | 87 ++++++++++++ .../skript/EffDisableableModuleStatus.java | 51 +++++++ .../uhc/uhc/skript/EvtModuleStatusChange.java | 81 +++++++++++ .../uhc/uhc/skript/ExprDisableableModule.java | 124 ++++++++++++++++ .../ExprDisableableModuleName.java} | 41 +++--- .../skript/ExprDisableableModuleStatus.java | 86 +++++++++++ .../java/gg/uhc/uhc/skript/SkriptHook.java | 134 ++++++++++++++++++ .../java/gg/uhc/uhc/skript/Transition.java | 53 +++++++ src/main/resources/plugin.yml | 1 + 18 files changed, 719 insertions(+), 38 deletions(-) create mode 100644 docs/skript.md rename src/main/java/gg/uhc/uhc/modules/events/{ModuleDisableEvent.java => ModuleChangeStatusEvent.java} (79%) create mode 100644 src/main/java/gg/uhc/uhc/skript/CondDisableableModuleEnabled.java create mode 100644 src/main/java/gg/uhc/uhc/skript/EffDisableableModuleStatus.java create mode 100644 src/main/java/gg/uhc/uhc/skript/EvtModuleStatusChange.java create mode 100644 src/main/java/gg/uhc/uhc/skript/ExprDisableableModule.java rename src/main/java/gg/uhc/uhc/{modules/events/ModuleEnableEvent.java => skript/ExprDisableableModuleName.java} (61%) create mode 100644 src/main/java/gg/uhc/uhc/skript/ExprDisableableModuleStatus.java create mode 100644 src/main/java/gg/uhc/uhc/skript/SkriptHook.java create mode 100644 src/main/java/gg/uhc/uhc/skript/Transition.java diff --git a/checkstyle.xml b/checkstyle.xml index ef35644..aa2af57 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -15,7 +15,9 @@ - + + + diff --git a/docs/skript.md b/docs/skript.md new file mode 100644 index 0000000..8e1df00 --- /dev/null +++ b/docs/skript.md @@ -0,0 +1,41 @@ +## Events + +### On module change status + +Trigger on module enable/disable/toggles + +#### Pattern + +`module[s] ((change state|toggle[d])|enable[d]|disable[d]` + +#### Examples: + +`on module toggled` - Called whenever any module is toggled + +`on modules enabled` - Called whenever any module is enabled + +## Expressions + +### Module + +Get a module by its name + +#### Pattern + +`[the] module[s] called %strings%` + +## Conditions + +### Check enabled/disabled + +Checks if all of the provided modules are enabled or not + +#### Pattern + +`if %modules?% (is|are) (enabled|disabled)` + +#### Examples + +`if the module "PVP" is enabled:` + +`if all modules are disabled:` \ No newline at end of file diff --git a/pom.xml b/pom.xml index 7002d27..16dc0b3 100644 --- a/pom.xml +++ b/pom.xml @@ -36,6 +36,10 @@ uhc.gg-releases http://repo.uhc.gg/libs-release-local + + njol-repo + http://maven.njol.ch/repo/ + @@ -73,6 +77,12 @@ jar compile + + ch.njol + skript + 2.2-SNAPSHOT + provided + com.typesafe config diff --git a/src/main/java/gg/uhc/uhc/UHC.java b/src/main/java/gg/uhc/uhc/UHC.java index 8be9d8e..573816a 100644 --- a/src/main/java/gg/uhc/uhc/UHC.java +++ b/src/main/java/gg/uhc/uhc/UHC.java @@ -69,6 +69,7 @@ import gg.uhc.uhc.modules.whitelist.WhitelistClearCommand; import gg.uhc.uhc.modules.whitelist.WhitelistOnlineCommand; import gg.uhc.uhc.modules.xp.NerfQuartzXPModule; +import gg.uhc.uhc.skript.SkriptHook; import com.google.common.base.Optional; import com.typesafe.config.Config; @@ -158,6 +159,8 @@ public void run() { registry.register(new HeadDropsModule(headProvider)); registry.register(new DeathStandsModule()); + setupPluginHooks(); + setupTeamCommands(); setupCommand(new WorldBorderCommand(commandMessages("border")), "border"); @@ -267,6 +270,12 @@ protected void setupTeamCommands() { setupCommand(teamrequest, "teamrequest"); } + protected void setupPluginHooks() { + if (getServer().getPluginManager().getPlugin("Skript") != null) { + SkriptHook.register(this); + } + } + protected void setupProtocolLibModules() { if (getServer().getPluginManager().getPlugin("ProtocolLib") == null) { getLogger().info("Skipping hardcore hearts module because protocollib is not installed"); diff --git a/src/main/java/gg/uhc/uhc/modules/DisableableModule.java b/src/main/java/gg/uhc/uhc/modules/DisableableModule.java index 720d2f6..f7f3656 100644 --- a/src/main/java/gg/uhc/uhc/modules/DisableableModule.java +++ b/src/main/java/gg/uhc/uhc/modules/DisableableModule.java @@ -31,8 +31,7 @@ import gg.uhc.uhc.inventory.ClickHandler; import gg.uhc.uhc.inventory.IconInventory; import gg.uhc.uhc.inventory.IconStack; -import gg.uhc.uhc.modules.events.ModuleDisableEvent; -import gg.uhc.uhc.modules.events.ModuleEnableEvent; +import gg.uhc.uhc.modules.events.ModuleChangeStatusEvent; import com.google.common.collect.ImmutableMap; import net.md_5.bungee.api.ChatColor; @@ -168,7 +167,7 @@ protected void onDisable() {} public final boolean enable() { if (isEnabled()) return false; - final ModuleEnableEvent event = new ModuleEnableEvent(this); + final ModuleChangeStatusEvent event = new ModuleChangeStatusEvent(this, true); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) return false; @@ -185,7 +184,7 @@ public final boolean enable() { public final boolean disable() { if (!isEnabled()) return false; - final ModuleDisableEvent event = new ModuleDisableEvent(this); + final ModuleChangeStatusEvent event = new ModuleChangeStatusEvent(this, false); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) return false; diff --git a/src/main/java/gg/uhc/uhc/modules/events/ModuleDisableEvent.java b/src/main/java/gg/uhc/uhc/modules/events/ModuleChangeStatusEvent.java similarity index 79% rename from src/main/java/gg/uhc/uhc/modules/events/ModuleDisableEvent.java rename to src/main/java/gg/uhc/uhc/modules/events/ModuleChangeStatusEvent.java index 4e678d7..a5e9ad1 100644 --- a/src/main/java/gg/uhc/uhc/modules/events/ModuleDisableEvent.java +++ b/src/main/java/gg/uhc/uhc/modules/events/ModuleChangeStatusEvent.java @@ -1,6 +1,6 @@ /* * Project: UHC - * Class: gg.uhc.uhc.modules.events.ModuleDisableEvent + * Class: gg.uhc.uhc.modules.ModuleChangeStatusEvent * * The MIT License (MIT) * @@ -29,17 +29,23 @@ import gg.uhc.uhc.modules.DisableableModule; +import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -public class ModuleDisableEvent extends Event { +public class ModuleChangeStatusEvent extends Event implements Cancellable { private static final HandlerList HANDLERS = new HandlerList(); protected final DisableableModule module; + protected final boolean from; + protected final boolean to; + protected boolean cancelled; - public ModuleDisableEvent(DisableableModule module) { + public ModuleChangeStatusEvent(DisableableModule module, boolean to) { this.module = module; + this.from = module.isEnabled(); + this.to = to; } @Override @@ -62,4 +68,12 @@ public boolean isCancelled() { public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } + + public boolean isEnabled() { + return from; + } + + public boolean willBeEnabled() { + return to; + } } diff --git a/src/main/java/gg/uhc/uhc/modules/health/HardcoreHeartsModule.java b/src/main/java/gg/uhc/uhc/modules/health/HardcoreHeartsModule.java index 73dc729..c188165 100644 --- a/src/main/java/gg/uhc/uhc/modules/health/HardcoreHeartsModule.java +++ b/src/main/java/gg/uhc/uhc/modules/health/HardcoreHeartsModule.java @@ -30,7 +30,7 @@ import gg.uhc.uhc.modules.Module; import gg.uhc.uhc.modules.ModuleRegistry; import gg.uhc.uhc.modules.autorespawn.AutoRespawnModule; -import gg.uhc.uhc.modules.events.ModuleDisableEvent; +import gg.uhc.uhc.modules.events.ModuleChangeStatusEvent; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; @@ -77,8 +77,8 @@ public void initialize() throws InvalidConfigurationException { } @EventHandler(priority = EventPriority.HIGH) - public void on(ModuleDisableEvent event) { - if (event.getModule() == respawnModule) event.setCancelled(true); + public void on(ModuleChangeStatusEvent event) { + if (!event.willBeEnabled() && event.getModule() == respawnModule) event.setCancelled(true); } class HardcoreHeartsListener extends PacketAdapter { diff --git a/src/main/java/gg/uhc/uhc/modules/team/prefixes/PrefixColourPredicate.java b/src/main/java/gg/uhc/uhc/modules/team/prefixes/PrefixColourPredicate.java index f9f24ba..4e3ecfe 100644 --- a/src/main/java/gg/uhc/uhc/modules/team/prefixes/PrefixColourPredicate.java +++ b/src/main/java/gg/uhc/uhc/modules/team/prefixes/PrefixColourPredicate.java @@ -27,7 +27,6 @@ package gg.uhc.uhc.modules.team.prefixes; - import com.google.common.base.Predicate; import org.bukkit.ChatColor; diff --git a/src/main/java/gg/uhc/uhc/modules/timer/TimeConverter.java b/src/main/java/gg/uhc/uhc/modules/timer/TimeConverter.java index 51d8dc5..a960ebf 100644 --- a/src/main/java/gg/uhc/uhc/modules/timer/TimeConverter.java +++ b/src/main/java/gg/uhc/uhc/modules/timer/TimeConverter.java @@ -27,7 +27,6 @@ package gg.uhc.uhc.modules.timer; - import gg.uhc.flagcommands.joptsimple.ValueConversionException; import gg.uhc.flagcommands.joptsimple.ValueConverter; import gg.uhc.uhc.util.TimeUtil; diff --git a/src/main/java/gg/uhc/uhc/skript/CondDisableableModuleEnabled.java b/src/main/java/gg/uhc/uhc/skript/CondDisableableModuleEnabled.java new file mode 100644 index 0000000..a9e3bac --- /dev/null +++ b/src/main/java/gg/uhc/uhc/skript/CondDisableableModuleEnabled.java @@ -0,0 +1,87 @@ +/* + * Project: UHC + * Class: gg.uhc.uhc.modules.CondDisableableModuleEnabled + * + * The MIT License (MIT) + * + * Copyright (c) 2015 Graham Howden . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package gg.uhc.uhc.skript; + +import gg.uhc.uhc.modules.DisableableModule; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Condition; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.util.Kleenean; +import com.google.common.base.Function; +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; +import org.bukkit.event.Event; + +public class CondDisableableModuleEnabled extends Condition { + private Expression moduleExpression; + private boolean expecting; + + static void hook() { + Skript.registerCondition( + CondDisableableModuleEnabled.class, + "%modules% [(is|are)] (1¦enabled|2¦disabled)" + ); + } + + @SuppressWarnings("unchecked") + @Override + public boolean init( + Expression[] exprs, + int matchedPattern, + Kleenean isDelayed, + SkriptParser.ParseResult parseResult + ) { + moduleExpression = (Expression) exprs[0]; + expecting = parseResult.mark == 1; + return true; + } + + @Override + public boolean check(Event event) { + return Iterables.all( + Iterables.transform( + ImmutableList.copyOf(moduleExpression.getArray(event)), + new Function() { + @Override + public Boolean apply(DisableableModule input) { + return input.isEnabled(); + } + } + ), + Predicates.equalTo(expecting) + ); + } + + @Override + public String toString(Event event, boolean debug) { + return moduleExpression.toString(event, debug) + " is " + (expecting ? "enabled" : "disabled"); + } +} diff --git a/src/main/java/gg/uhc/uhc/skript/EffDisableableModuleStatus.java b/src/main/java/gg/uhc/uhc/skript/EffDisableableModuleStatus.java new file mode 100644 index 0000000..2900df6 --- /dev/null +++ b/src/main/java/gg/uhc/uhc/skript/EffDisableableModuleStatus.java @@ -0,0 +1,51 @@ +package gg.uhc.uhc.skript; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.util.Kleenean; +import gg.uhc.uhc.modules.DisableableModule; +import org.bukkit.event.Event; + +public class EffDisableableModuleStatus extends Effect { + private Expression moduleExpression; + private Transition type; + + static void hook() { + Skript.registerEffect( + EffDisableableModuleStatus.class, + Transition.COMBINED_PATTERN + " %modules%" + ); + } + + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + moduleExpression = (Expression) exprs[0]; + type = Transition.BY_MARK.get(parseResult.mark); + return true; + } + + @Override + protected void execute(Event e) { + for (final DisableableModule module : moduleExpression.getArray(e)) { + switch (type) { + case DISABLE: + module.disable(); + break; + case ENABLE: + module.enable(); + break; + case TOGGLE: + module.toggle(); + break; + } + } + } + + @Override + public String toString(Event event, boolean debug) { + return type.toString().toLowerCase() + " " + moduleExpression.toString(event, debug); + } +} diff --git a/src/main/java/gg/uhc/uhc/skript/EvtModuleStatusChange.java b/src/main/java/gg/uhc/uhc/skript/EvtModuleStatusChange.java new file mode 100644 index 0000000..2218c6d --- /dev/null +++ b/src/main/java/gg/uhc/uhc/skript/EvtModuleStatusChange.java @@ -0,0 +1,81 @@ +/* + * Project: UHC + * Class: gg.uhc.uhc.modules.EvtModuleStatusChange + * + * The MIT License (MIT) + * + * Copyright (c) 2015 Graham Howden . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package gg.uhc.uhc.skript; + +import gg.uhc.uhc.modules.events.ModuleChangeStatusEvent; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Literal; +import ch.njol.skript.lang.SkriptEvent; +import ch.njol.skript.lang.SkriptEventInfo; +import ch.njol.skript.lang.SkriptParser; +import org.bukkit.event.Event; + +public class EvtModuleStatusChange extends SkriptEvent { + private Transition transition; + + static SkriptEventInfo hook() { + return Skript + .registerEvent( + "UHC Module Status Change", + EvtModuleStatusChange.class, + ModuleChangeStatusEvent.class, + "module[s] " + Transition.COMBINED_PATTERN + ) + .description("Called when modules are enabled/disabled/toggled") + .examples("") + .since("1.0"); + } + + @Override + public boolean init(final Literal[] args, final int matchedPattern, final SkriptParser.ParseResult parser) { + transition = Transition.BY_MARK.get(parser.mark); + + return transition != null; + } + + @Override + public boolean check(final Event rawEvent) { + assert rawEvent instanceof ModuleChangeStatusEvent; + + final ModuleChangeStatusEvent event = (ModuleChangeStatusEvent) rawEvent; + + switch (transition) { + case TOGGLE: return true; + case ENABLE: return event.willBeEnabled(); + case DISABLE: return !event.willBeEnabled(); + default: + return false; + } + } + + @Override + public String toString(final Event event, final boolean debug) { + return "module " + transition.name().toLowerCase(); + } +} diff --git a/src/main/java/gg/uhc/uhc/skript/ExprDisableableModule.java b/src/main/java/gg/uhc/uhc/skript/ExprDisableableModule.java new file mode 100644 index 0000000..7c63f11 --- /dev/null +++ b/src/main/java/gg/uhc/uhc/skript/ExprDisableableModule.java @@ -0,0 +1,124 @@ +/* + * Project: UHC + * Class: gg.uhc.uhc.modules.ExprDisableableModule + * + * The MIT License (MIT) + * + * Copyright (c) 2015 Graham Howden . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package gg.uhc.uhc.skript; + +import gg.uhc.uhc.modules.DisableableModule; +import gg.uhc.uhc.modules.Module; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.ExpressionType; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.lang.util.SimpleExpression; +import ch.njol.util.Kleenean; +import com.google.common.base.Function; +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; +import org.bukkit.event.Event; + +public class ExprDisableableModule extends SimpleExpression { + private Expression names; + private boolean multiple; + + static void hook() { + Skript.registerExpression( + ExprDisableableModule.class, + DisableableModule.class, + ExpressionType.COMBINED, + "[all] modules", + "[the] (1¦module|2¦modules) [called] %strings%" + ); + } + + @SuppressWarnings("unchecked") + @Override + public boolean init( + Expression[] exprs, + int matchedPattern, + Kleenean isDelayed, + SkriptParser.ParseResult parseResult + ) { + if (matchedPattern == 0) { + names = null; + } else { + names = (Expression) exprs[0]; + } + + multiple = parseResult.mark == 2; + + return true; + } + + @Override + protected DisableableModule[] get(Event event) { + if (names == null) { + return Iterables.toArray(SkriptHook.getAllModules(), DisableableModule.class); + } + + return Iterables.toArray( + // Convert into disableable by casting to allow conversion to array + Iterables.transform( + // Filter out non-existing and non-disableable + Iterables.filter( + // Find the module by name (or null if not exists) + Iterables.transform( + ImmutableList.copyOf(names.getArray(event)), + SkriptHook.findModuleByNameFunction() + ), + Predicates.and( + Predicates.notNull(), + Predicates.instanceOf(DisableableModule.class) + ) + ), + new Function() { + @Override + public DisableableModule apply(Module input) { + return (DisableableModule) input; + } + } + ), + DisableableModule.class + ); + } + + @Override + public boolean isSingle() { + return !multiple; + } + + @Override + public Class getReturnType() { + return DisableableModule.class; + } + + @Override + public String toString(Event event, boolean debug) { + return names == null ? "all modules" : "the modules " + names.toString(event, debug); + } +} diff --git a/src/main/java/gg/uhc/uhc/modules/events/ModuleEnableEvent.java b/src/main/java/gg/uhc/uhc/skript/ExprDisableableModuleName.java similarity index 61% rename from src/main/java/gg/uhc/uhc/modules/events/ModuleEnableEvent.java rename to src/main/java/gg/uhc/uhc/skript/ExprDisableableModuleName.java index 6477d0c..89552e9 100644 --- a/src/main/java/gg/uhc/uhc/modules/events/ModuleEnableEvent.java +++ b/src/main/java/gg/uhc/uhc/skript/ExprDisableableModuleName.java @@ -1,6 +1,6 @@ /* * Project: UHC - * Class: gg.uhc.uhc.modules.events.ModuleEnableEvent + * Class: gg.uhc.uhc.modules.ExpDisableableModuleStatus * * The MIT License (MIT) * @@ -25,41 +25,32 @@ * THE SOFTWARE. */ -package gg.uhc.uhc.modules.events; -import gg.uhc.uhc.modules.DisableableModule; +package gg.uhc.uhc.skript; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; +import gg.uhc.uhc.modules.DisableableModule; -public class ModuleEnableEvent extends Event { - private static final HandlerList HANDLERS = new HandlerList(); +import ch.njol.skript.expressions.base.SimplePropertyExpression; - protected boolean cancelled; - protected final DisableableModule module; +public class ExprDisableableModuleName extends SimplePropertyExpression { + private static final String PROPERTY = "name"; - public ModuleEnableEvent(DisableableModule module) { - this.module = module; + static void hook() { + register(ExprDisableableModuleName.class, String.class, "name[s]", "modules"); } @Override - public HandlerList getHandlers() { - return HANDLERS; - } - - public static HandlerList getHandlerList() { - return HANDLERS; + protected String getPropertyName() { + return PROPERTY; } - public DisableableModule getModule() { - return module; - } - - public boolean isCancelled() { - return cancelled; + @Override + public String convert(final DisableableModule disableableModule) { + return disableableModule.getId(); } - public void setCancelled(boolean cancelled) { - this.cancelled = cancelled; + @Override + public Class getReturnType() { + return String.class; } } diff --git a/src/main/java/gg/uhc/uhc/skript/ExprDisableableModuleStatus.java b/src/main/java/gg/uhc/uhc/skript/ExprDisableableModuleStatus.java new file mode 100644 index 0000000..30b6387 --- /dev/null +++ b/src/main/java/gg/uhc/uhc/skript/ExprDisableableModuleStatus.java @@ -0,0 +1,86 @@ +/* + * Project: UHC + * Class: gg.uhc.uhc.modules.ExpDisableableModuleStatus + * + * The MIT License (MIT) + * + * Copyright (c) 2015 Graham Howden . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +package gg.uhc.uhc.skript; + +import gg.uhc.uhc.modules.DisableableModule; + +import ch.njol.skript.classes.Changer; +import ch.njol.skript.expressions.base.SimplePropertyExpression; +import org.bukkit.event.Event; + +public class ExprDisableableModuleStatus extends SimplePropertyExpression { + private static final String PROPERTY = "enabled status"; + + static void hook() { + register(ExprDisableableModuleStatus.class, Boolean.class, "[enabled] status[es]", "modules"); + } + + @Override + protected String getPropertyName() { + return PROPERTY; + } + + @Override + public Boolean convert(final DisableableModule disableableModule) { + return disableableModule.isEnabled(); + } + + @Override + public Class getReturnType() { + return Boolean.class; + } + + @Override + public Class[] acceptChange(final Changer.ChangeMode mode) { + if (mode == Changer.ChangeMode.SET) { + return new Class[] { Boolean.class }; + } + + return null; + } + + @Override + public void change(final Event event, final Object[] delta, final Changer.ChangeMode mode) { + if (mode == Changer.ChangeMode.SET) { + assert delta != null; + + final boolean newState = (Boolean) delta[0]; + + for (final DisableableModule module : getExpr().getArray(event)) { + if (newState) { + module.enable(); + } else { + module.disable(); + } + } + } else { + super.change(event, delta, mode); + } + } +} diff --git a/src/main/java/gg/uhc/uhc/skript/SkriptHook.java b/src/main/java/gg/uhc/uhc/skript/SkriptHook.java new file mode 100644 index 0000000..3cb3c46 --- /dev/null +++ b/src/main/java/gg/uhc/uhc/skript/SkriptHook.java @@ -0,0 +1,134 @@ +/* + * Project: UHC + * Class: gg.uhc.uhc.modules.SkriptHook + * + * The MIT License (MIT) + * + * Copyright (c) 2015 Graham Howden . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package gg.uhc.uhc.skript; + +import ch.njol.skript.classes.Changer; +import ch.njol.skript.expressions.base.EventValueExpression; +import ch.njol.skript.lang.DefaultExpression; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.util.Checker; +import ch.njol.util.Kleenean; +import gg.uhc.uhc.UHC; +import gg.uhc.uhc.modules.DisableableModule; +import gg.uhc.uhc.modules.Module; +import gg.uhc.uhc.modules.ModuleRegistry; +import gg.uhc.uhc.modules.events.ModuleChangeStatusEvent; + +import ch.njol.skript.Skript; +import ch.njol.skript.SkriptAddon; +import ch.njol.skript.classes.ClassInfo; +import ch.njol.skript.registrations.Classes; +import ch.njol.skript.registrations.EventValues; +import ch.njol.skript.util.Getter; +import com.google.common.base.Function; +import com.google.common.base.Predicates; +import com.google.common.collect.Iterables; +import org.bukkit.entity.Entity; +import org.bukkit.event.Event; + +import java.util.Iterator; +import java.util.logging.Logger; + +public final class SkriptHook { + private static ModuleRegistry registry; + + private SkriptHook() {} + + static Function findModuleByNameFunction() { + return new Function() { + @Override + public Module apply(String input) { + return SkriptHook.registry.get(input).orNull(); + } + }; + } + + static Iterable getAllModules() { + return Iterables.transform( + Iterables.filter( + registry.getModules(), + Predicates.instanceOf(DisableableModule.class) + ), + new Function() { + @Override + public DisableableModule apply(Module input) { + return (DisableableModule) input; + } + } + ); + } + + public static void register(final UHC uhc) { + registry = uhc.getRegistry(); + + final SkriptAddon addon = Skript.registerAddon(uhc); + final Logger logger = uhc.getLogger(); + logger.info("Registered skript addon " + addon); + + Classes.registerClass( + new ClassInfo<>(DisableableModule.class, "module") + .user("modules?") + .name("UHC Module") + .usage("") + .examples("") + .defaultExpression(new EventValueExpression<>(DisableableModule.class)) + ); + logger.info("Regiseted module class"); + + logger.info("Registered event: " + EvtModuleStatusChange.hook()); + + ExprDisableableModule.hook(); + logger.info("Registered module name expression"); + + ExprDisableableModuleStatus.hook(); + logger.info("Registered module status expression"); + + ExprDisableableModuleName.hook(); + logger.info("Registered module name expression"); + + CondDisableableModuleEnabled.hook(); + logger.info("Registered enabled condition"); + + EffDisableableModuleStatus.hook(); + logger.info("Registered module status efffect"); + + EventValues.registerEventValue( + ModuleChangeStatusEvent.class, + DisableableModule.class, + new Getter() { + @Override + public DisableableModule get(ModuleChangeStatusEvent arg) { + return arg.getModule(); + } + }, + 0 + ); + logger.info("Regiseterd event value for module"); + } +} diff --git a/src/main/java/gg/uhc/uhc/skript/Transition.java b/src/main/java/gg/uhc/uhc/skript/Transition.java new file mode 100644 index 0000000..c95c64c --- /dev/null +++ b/src/main/java/gg/uhc/uhc/skript/Transition.java @@ -0,0 +1,53 @@ +package gg.uhc.uhc.skript; + +import com.google.common.collect.ImmutableMap; + +import java.util.Map; + +enum Transition { + ENABLE("enable[d]", 1), + DISABLE("disable[d]", 2), + TOGGLE("(change state|toggle[d])", 3); + + static final Map BY_MARK; + static final String COMBINED_PATTERN; + + static { + final ImmutableMap.Builder temp = ImmutableMap.builder(); + + final StringBuilder sb = new StringBuilder(); + sb.append("("); + + for (final Transition transition : Transition.values()) { + temp.put(transition.getMark(), transition); + sb + .append(transition.getMark()) + .append('¦') + .append(transition.pattern) + .append("|"); + } + + sb + .deleteCharAt(sb.lastIndexOf("|")) + .append(")"); + + BY_MARK = temp.build(); + COMBINED_PATTERN = sb.toString(); + } + + private final String pattern; + private final int mark; + + Transition(String pattern, int mark) { + this.pattern = pattern; + this.mark = mark; + } + + String getPattern() { + return pattern; + } + + int getMark() { + return mark; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fe3ac87..6117435 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,6 +4,7 @@ version: ${project.version} author: ghowden/Eluinhost database: false soft-depend: [ProtocolLib] +loadbefore: [Skript] commands: showhealth: permission: uhc.command.showhealth From 9fcdc3c80895632d335402f3edc9aaacbf87666b Mon Sep 17 00:00:00 2001 From: Eluinhost Date: Mon, 16 Jan 2017 17:15:30 +0000 Subject: [PATCH 2/4] dammit checkstyle --- .../skript/EffDisableableModuleStatus.java | 61 +++++++++++++++---- .../java/gg/uhc/uhc/skript/SkriptHook.java | 11 +--- .../java/gg/uhc/uhc/skript/Transition.java | 27 ++++++++ 3 files changed, 76 insertions(+), 23 deletions(-) diff --git a/src/main/java/gg/uhc/uhc/skript/EffDisableableModuleStatus.java b/src/main/java/gg/uhc/uhc/skript/EffDisableableModuleStatus.java index 2900df6..a9239dc 100644 --- a/src/main/java/gg/uhc/uhc/skript/EffDisableableModuleStatus.java +++ b/src/main/java/gg/uhc/uhc/skript/EffDisableableModuleStatus.java @@ -1,11 +1,39 @@ +/* + * Project: UHC + * Class: gg.uhc.uhc.modules.EffDisableableModuleStatus + * + * The MIT License (MIT) + * + * Copyright (c) 2015 Graham Howden . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package gg.uhc.uhc.skript; +import gg.uhc.uhc.modules.DisableableModule; + import ch.njol.skript.Skript; import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser; import ch.njol.util.Kleenean; -import gg.uhc.uhc.modules.DisableableModule; import org.bukkit.event.Event; public class EffDisableableModuleStatus extends Effect { @@ -21,25 +49,32 @@ static void hook() { @SuppressWarnings("unchecked") @Override - public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { + public boolean init( + Expression[] exprs, + int matchedPattern, + Kleenean isDelayed, + SkriptParser.ParseResult parseResult + ) { moduleExpression = (Expression) exprs[0]; type = Transition.BY_MARK.get(parseResult.mark); return true; } @Override - protected void execute(Event e) { - for (final DisableableModule module : moduleExpression.getArray(e)) { + protected void execute(Event event) { + for (final DisableableModule module : moduleExpression.getArray(event)) { switch (type) { - case DISABLE: - module.disable(); - break; - case ENABLE: - module.enable(); - break; - case TOGGLE: - module.toggle(); - break; + case DISABLE: + module.disable(); + break; + case ENABLE: + module.enable(); + break; + case TOGGLE: + module.toggle(); + break; + default: + throw new IllegalStateException(); } } } diff --git a/src/main/java/gg/uhc/uhc/skript/SkriptHook.java b/src/main/java/gg/uhc/uhc/skript/SkriptHook.java index 3cb3c46..767e918 100644 --- a/src/main/java/gg/uhc/uhc/skript/SkriptHook.java +++ b/src/main/java/gg/uhc/uhc/skript/SkriptHook.java @@ -27,13 +27,6 @@ package gg.uhc.uhc.skript; -import ch.njol.skript.classes.Changer; -import ch.njol.skript.expressions.base.EventValueExpression; -import ch.njol.skript.lang.DefaultExpression; -import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.SkriptParser; -import ch.njol.util.Checker; -import ch.njol.util.Kleenean; import gg.uhc.uhc.UHC; import gg.uhc.uhc.modules.DisableableModule; import gg.uhc.uhc.modules.Module; @@ -43,16 +36,14 @@ import ch.njol.skript.Skript; import ch.njol.skript.SkriptAddon; import ch.njol.skript.classes.ClassInfo; +import ch.njol.skript.expressions.base.EventValueExpression; import ch.njol.skript.registrations.Classes; import ch.njol.skript.registrations.EventValues; import ch.njol.skript.util.Getter; import com.google.common.base.Function; import com.google.common.base.Predicates; import com.google.common.collect.Iterables; -import org.bukkit.entity.Entity; -import org.bukkit.event.Event; -import java.util.Iterator; import java.util.logging.Logger; public final class SkriptHook { diff --git a/src/main/java/gg/uhc/uhc/skript/Transition.java b/src/main/java/gg/uhc/uhc/skript/Transition.java index c95c64c..3fe8539 100644 --- a/src/main/java/gg/uhc/uhc/skript/Transition.java +++ b/src/main/java/gg/uhc/uhc/skript/Transition.java @@ -1,3 +1,30 @@ +/* + * Project: UHC + * Class: gg.uhc.uhc.modules.Transition + * + * The MIT License (MIT) + * + * Copyright (c) 2015 Graham Howden . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package gg.uhc.uhc.skript; import com.google.common.collect.ImmutableMap; From e940305af8811ac65adb7e137400624aa65b53b8 Mon Sep 17 00:00:00 2001 From: Eluinhost Date: Fri, 20 Jan 2017 22:06:02 +0000 Subject: [PATCH 3/4] add effect for modifying golden head heal amount --- .../uhc/skript/ExprGoldenHeadsHealAmount.java | 142 ++++++++++++++++++ .../java/gg/uhc/uhc/skript/SkriptHook.java | 3 + src/main/java/gg/uhc/uhc/util/Action.java | 32 ++++ src/main/java/gg/uhc/uhc/util/Action2.java | 32 ++++ 4 files changed, 209 insertions(+) create mode 100644 src/main/java/gg/uhc/uhc/skript/ExprGoldenHeadsHealAmount.java create mode 100644 src/main/java/gg/uhc/uhc/util/Action.java create mode 100644 src/main/java/gg/uhc/uhc/util/Action2.java diff --git a/src/main/java/gg/uhc/uhc/skript/ExprGoldenHeadsHealAmount.java b/src/main/java/gg/uhc/uhc/skript/ExprGoldenHeadsHealAmount.java new file mode 100644 index 0000000..cddfa89 --- /dev/null +++ b/src/main/java/gg/uhc/uhc/skript/ExprGoldenHeadsHealAmount.java @@ -0,0 +1,142 @@ +/* + * Project: UHC + * Class: gg.uhc.uhc.modules.ExprGoldenHeadsHealAmount + * + * The MIT License (MIT) + * + * Copyright (c) 2015 Graham Howden . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package gg.uhc.uhc.skript; + +import gg.uhc.uhc.modules.DisableableModule; +import gg.uhc.uhc.modules.heads.GoldenHeadsModule; +import gg.uhc.uhc.util.Action2; + +import ch.njol.skript.Skript; +import ch.njol.skript.classes.Changer; +import ch.njol.skript.classes.Converter; +import ch.njol.skript.expressions.base.PropertyExpression; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.ExpressionType; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.util.Kleenean; +import com.google.common.collect.ImmutableMap; +import org.bukkit.event.Event; +import org.eclipse.jdt.annotation.Nullable; + +import java.util.Map; + +public class ExprGoldenHeadsHealAmount extends PropertyExpression { + private static Map> ACTIONS = + ImmutableMap + .>builder() + .put(Changer.ChangeMode.SET, new Action2() { + @Override + public void apply(GoldenHeadsModule element, Integer delta) { + element.setHealAmount(delta); + } + }) + .put(Changer.ChangeMode.ADD, new Action2() { + @Override + public void apply(GoldenHeadsModule element, Integer element2) { + element.setHealAmount(element.getHealAmount() + element2); + } + }) + .put(Changer.ChangeMode.REMOVE, new Action2() { + @Override + public void apply(GoldenHeadsModule element, Integer element2) { + element.setHealAmount(element.getHealAmount() - element2); + } + }) + .build(); + + static void hook() { + Skript.registerExpression( + ExprGoldenHeadsHealAmount.class, + Integer.class, + ExpressionType.PROPERTY, + "[the] heal amount of %module%", "%module%'[s] heal amount"); + } + + @SuppressWarnings("unchecked") + @Override + public boolean init( + final Expression[] exprs, + final int matchedPattern, + final Kleenean isDelayed, + final SkriptParser.ParseResult parseResult + ) { + setExpr((Expression) exprs[0]); + return true; + } + + @Override + protected Integer[] get(Event event, DisableableModule[] source) { + return get(source, new Converter() { + @Override + public Integer convert(final DisableableModule module) { + if (module instanceof GoldenHeadsModule) { + return ((GoldenHeadsModule) module).getHealAmount(); + } + + Skript.error("Cannot get heal amount from module " + module.getId()); + throw new UnsupportedOperationException(); + } + }); + } + + @Override + public Class getReturnType() { + return Integer.class; + } + + @Override + @Nullable + public Class[] acceptChange(final Changer.ChangeMode mode) { + return ACTIONS.containsKey(mode) ? new Class[] { Integer.class } : super.acceptChange(mode); + } + + @Override + public void change(final Event event, final Object[] delta, final Changer.ChangeMode mode) { + final int castDelta = (Integer) delta[0]; + final Action2 action = ACTIONS.get(mode); + + if (action == null) { + super.change(event, delta, mode); + return; + } + + for (final DisableableModule module : getExpr().getArray(event)) { + if (!(module instanceof GoldenHeadsModule)) { + Skript.error("Cannot modify the heal amount of module: " + module.getId()); + continue; + } + + action.apply((GoldenHeadsModule) module, castDelta); + } + } + + @Override + public String toString(Event event, boolean debug) { + return "the heal amount of " + getExpr().toString(event, debug); + } +} diff --git a/src/main/java/gg/uhc/uhc/skript/SkriptHook.java b/src/main/java/gg/uhc/uhc/skript/SkriptHook.java index 767e918..ad4edc7 100644 --- a/src/main/java/gg/uhc/uhc/skript/SkriptHook.java +++ b/src/main/java/gg/uhc/uhc/skript/SkriptHook.java @@ -109,6 +109,9 @@ public static void register(final UHC uhc) { EffDisableableModuleStatus.hook(); logger.info("Registered module status efffect"); + ExprGoldenHeadsHealAmount.hook(); + logger.info("Registered golden heal heal amount expression"); + EventValues.registerEventValue( ModuleChangeStatusEvent.class, DisableableModule.class, diff --git a/src/main/java/gg/uhc/uhc/util/Action.java b/src/main/java/gg/uhc/uhc/util/Action.java new file mode 100644 index 0000000..cb11c9a --- /dev/null +++ b/src/main/java/gg/uhc/uhc/util/Action.java @@ -0,0 +1,32 @@ +/* + * Project: UHC + * Class: gg.uhc.uhc.util.Action + * + * The MIT License (MIT) + * + * Copyright (c) 2015 Graham Howden . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package gg.uhc.uhc.util; + +public interface Action { + void apply(T element); +} diff --git a/src/main/java/gg/uhc/uhc/util/Action2.java b/src/main/java/gg/uhc/uhc/util/Action2.java new file mode 100644 index 0000000..1802529 --- /dev/null +++ b/src/main/java/gg/uhc/uhc/util/Action2.java @@ -0,0 +1,32 @@ +/* + * Project: UHC + * Class: gg.uhc.uhc.util.Action2 + * + * The MIT License (MIT) + * + * Copyright (c) 2015 Graham Howden . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package gg.uhc.uhc.util; + +public interface Action2 { + void apply(T element, T2 element2); +} From a519781441266d437be2b7485ef193711550b5ff Mon Sep 17 00:00:00 2001 From: Eluinhost Date: Fri, 20 Jan 2017 22:12:40 +0000 Subject: [PATCH 4/4] update docs --- docs/skript.md | 75 +++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/docs/skript.md b/docs/skript.md index 8e1df00..fb996dc 100644 --- a/docs/skript.md +++ b/docs/skript.md @@ -1,41 +1,48 @@ ## Events -### On module change status - -Trigger on module enable/disable/toggles - -#### Pattern - -`module[s] ((change state|toggle[d])|enable[d]|disable[d]` - -#### Examples: - -`on module toggled` - Called whenever any module is toggled - -`on modules enabled` - Called whenever any module is enabled + - On module change status + - Description: Trigger on module enable/disable/toggles + - Pattern: `module[s] ((change state|toggle[d])|enable[d]|disable[d])` + - Examples: + - `on module toggled` - Called whenever any module is toggled + - `on modules enabled` - Called whenever any module is enabled ## Expressions -### Module - -Get a module by its name - -#### Pattern - -`[the] module[s] called %strings%` - +- Get module by name + - Pattern: `[the] module[s] called %strings%` + +- Get module's name + - Patterns: + - `[the] name[s] of %modules%"` + - `%modules%'[s] name` + +- Get module's enabled status (boolean) + - Patterns: + - `[the] [enabled] status[es] of %modules%"` + - `"%modules%'[s] [enabled] status[es]` + +- Get golden head heal amount + - Patterns: + - `[the] heal amount of %module%` + - `"%module%'[s] heal amount` + ## Conditions -### Check enabled/disabled - -Checks if all of the provided modules are enabled or not - -#### Pattern - -`if %modules?% (is|are) (enabled|disabled)` - -#### Examples - -`if the module "PVP" is enabled:` - -`if all modules are disabled:` \ No newline at end of file +- Check module status + - Description: Checks if all of the modules requested are enabled/disabled + - Pattern: `if %modules?% (is|are) (enabled|disabled)` + - Examples: + - `if the module "PVP" is enabled:` + - `if all modules are disabled:` + +## Effects + +- Change status of module + - Description: Enables/Disables/Toggles the request modules + - Pattern: `((change state|toggle[d])|enable[d]|disable[d]) %modules%` + - Examples: + - `disable all modules` + - `enable the module called "PvP"` + - `disable the modules called "GoldenHeads", "ExtendedSaturation" and "ChatHealth"` +