Skip to content

Commit

Permalink
WorldTag.hardcore
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 27, 2021
1 parent e56ae8c commit 082c984
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Expand Up @@ -8,6 +8,9 @@
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.ReflectionHelper;
import com.denizenscript.denizencore.utilities.debugging.SlowWarning;
import com.denizenscript.denizencore.utilities.debugging.VerySlowWarning;
import com.denizenscript.denizencore.utilities.debugging.Warning;
import org.bukkit.event.*;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredListener;
Expand Down Expand Up @@ -69,6 +72,9 @@ public boolean matches(ScriptPath path) {
public String getName() {
return "InternalBukkitEvent";
}

public static Warning depFieldContext = new VerySlowWarning("The context.field_<name> special tag for 'internal bukkit event' is experimental and subject to be removed or replace in the future");

@Override
public ObjectTag getContext(String name) {
if (name.equals("fields")) {
Expand All @@ -85,6 +91,7 @@ public ObjectTag getContext(String name) {
return result;
}
if (name.startsWith("field_")) {
depFieldContext.warn();
String fName = CoreUtilities.toLowerCase(name.substring("field_".length()));
Class c = currentEvent.getClass();
while (c != null && c != Object.class) {
Expand Down
Expand Up @@ -514,6 +514,17 @@ public static void registerTags() {
return new ElementTag(object.getWorld().getDifficulty().name());
});

// <--[tag]
// @attribute <WorldTag.hardcore>
// @returns ElementTag(Boolean)
// @mechanism WorldTag.hardcore
// @description
// Returns whether the world is in hardcore mode.
// -->
registerTag(ElementTag.class, "hardcore", (attribute, object) -> {
return new ElementTag(object.getWorld().isHardcore());
});

// <--[tag]
// @attribute <WorldTag.keep_spawn>
// @returns ElementTag(Boolean)
Expand Down Expand Up @@ -951,6 +962,19 @@ public void adjust(Mechanism mechanism) {
}
}

// <--[mechanism]
// @object WorldTag
// @name hardcore
// @input ElementTag(Boolean)
// @description
// Sets whether the world is hardcore mode.
// @tags
// <WorldTag.hardcore>
// -->
if (mechanism.matches("hardcore") && mechanism.requireBoolean()) {
getWorld().setHardcore(mechanism.getValue().asBoolean());
}

// <--[mechanism]
// @object WorldTag
// @name save
Expand Down

0 comments on commit 082c984

Please sign in to comment.