Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
<property name="fileExtensions" value="java"/>
</module>
<module name="SuppressWarningsFilter" />
<module name="NewlineAtEndOfFile"/>
<module name="NewlineAtEndOfFile">
<property name="lineSeparator" value="lf" />
</module>
<module name="TreeWalker">
<module name="SuppressWarningsHolder" />
<module name="AnnotationUseStyle"/>
Expand Down
48 changes: 48 additions & 0 deletions docs/skript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## Events

- 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

- 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 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"`

10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<name>uhc.gg-releases</name>
<url>http://repo.uhc.gg/libs-release-local</url>
</repository>
<repository>
<id>njol-repo</id>
<url>http://maven.njol.ch/repo/</url>
</repository>
</repositories>

<distributionManagement>
Expand Down Expand Up @@ -73,6 +77,12 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.njol</groupId>
<artifactId>skript</artifactId>
<version>2.2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/gg/uhc/uhc/UHC.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -158,6 +159,8 @@ public void run() {
registry.register(new HeadDropsModule(headProvider));
registry.register(new DeathStandsModule());

setupPluginHooks();

setupTeamCommands();

setupCommand(new WorldBorderCommand(commandMessages("border")), "border");
Expand Down Expand Up @@ -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");
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/gg/uhc/uhc/modules/DisableableModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Project: UHC
* Class: gg.uhc.uhc.modules.events.ModuleDisableEvent
* Class: gg.uhc.uhc.modules.ModuleChangeStatusEvent
*
* The MIT License (MIT)
*
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

package gg.uhc.uhc.modules.team.prefixes;


import com.google.common.base.Predicate;
import org.bukkit.ChatColor;

Expand Down
1 change: 0 additions & 1 deletion src/main/java/gg/uhc/uhc/modules/timer/TimeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
87 changes: 87 additions & 0 deletions src/main/java/gg/uhc/uhc/skript/CondDisableableModuleEnabled.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Project: UHC
* Class: gg.uhc.uhc.modules.CondDisableableModuleEnabled
*
* The MIT License (MIT)
*
* Copyright (c) 2015 Graham Howden <graham_howden1 at yahoo.co.uk>.
*
* 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<DisableableModule> 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<DisableableModule>) 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<DisableableModule, Boolean>() {
@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");
}
}
86 changes: 86 additions & 0 deletions src/main/java/gg/uhc/uhc/skript/EffDisableableModuleStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Project: UHC
* Class: gg.uhc.uhc.modules.EffDisableableModuleStatus
*
* The MIT License (MIT)
*
* Copyright (c) 2015 Graham Howden <graham_howden1 at yahoo.co.uk>.
*
* 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 org.bukkit.event.Event;

public class EffDisableableModuleStatus extends Effect {
private Expression<DisableableModule> 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<DisableableModule>) exprs[0];
type = Transition.BY_MARK.get(parseResult.mark);
return true;
}

@Override
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;
default:
throw new IllegalStateException();
}
}
}

@Override
public String toString(Event event, boolean debug) {
return type.toString().toLowerCase() + " " + moduleExpression.toString(event, debug);
}
}
Loading