Skip to content

Commit

Permalink
chunk flags
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 25, 2021
1 parent f7aa480 commit 03507a4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
Expand Up @@ -61,7 +61,7 @@ public abstract class BukkitScriptEvent extends ScriptEvent {
// You can use "world" as a catch-all, a world name, or "world_flagged:<flag_name>" (works similar to 'item_flagged').
//
// "<area>" or similar refers to any area-defining tag type, including WorldTag, CuboidTag, EllipsoidTag, and PolygonTag.
// You can specify the name of any world, the name of any noted area, "world_flagged:<flag_name>", "area_flagged:<flag_name>" (both work similar to 'item_flagged'),
// You can specify the name of any world, the name of any noted area, "world_flagged:<flag_name>", "chunk_flagged:<flag_name>", "area_flagged:<flag_name>" (all work similar to 'item_flagged'),
// "cuboid" for any noted cuboid, "ellipsoid" for any noted ellipsoid, or "polygon" for any noted polygon.
//
// You will also often see match inputs like "<cause>" or "<reason>" or similar,
Expand Down Expand Up @@ -450,15 +450,14 @@ public boolean runInCheck(ScriptPath path, Location location) {
return runInCheck(path, location, "in");
}

public boolean runLocationFlaggedCheck(ScriptPath path, String switchName, Location location) {
public boolean runFlaggedCheck(ScriptPath path, String switchName, AbstractFlagTracker tracker) {
String flagged = path.switches.get(switchName);
if (flagged == null) {
return true;
}
if (location == null) {
if (tracker == null) {
return false;
}
AbstractFlagTracker tracker = new LocationTag(location).getFlagTracker();
for (String flag : CoreUtilities.split(flagged, '|')) {
if (!tracker.hasFlag(flag)) {
return false;
Expand All @@ -467,6 +466,10 @@ public boolean runLocationFlaggedCheck(ScriptPath path, String switchName, Locat
return true;
}

public boolean runLocationFlaggedCheck(ScriptPath path, String switchName, Location location) {
return runFlaggedCheck(path, switchName, location == null ? null : new LocationTag(location).getFlagTracker());
}

public boolean runInCheck(ScriptPath path, Location location, String innote) {
if (!runLocationFlaggedCheck(path, "location_flagged", location)) {
return false;
Expand Down Expand Up @@ -510,6 +513,9 @@ else if (subit.equals("ellipsoid")) {
if (lower.startsWith("world_flagged:")) {
return new WorldTag(location.getWorld()).getFlagTracker().hasFlag(inputText.substring("world_flagged:".length()));
}
else if (lower.startsWith("chunk_flagged:")) {
return new ChunkTag(location).getFlagTracker().hasFlag(inputText.substring("chunk_flagged:".length()));
}
else if (lower.startsWith("area_flagged:")) {
String flagName = inputText.substring("area_flagged:".length());
for (CuboidTag cuboid : NotableManager.getAllType(CuboidTag.class)) {
Expand Down
@@ -1,7 +1,11 @@
package com.denizenscript.denizen.objects;

import com.denizenscript.denizen.nms.NMSVersion;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.flags.DataPersistenceFlagTracker;
import com.denizenscript.denizen.utilities.flags.LocationFlagSearchHelper;
import com.denizenscript.denizencore.flags.AbstractFlagTracker;
import com.denizenscript.denizencore.flags.FlaggableObject;
import com.denizenscript.denizencore.objects.*;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizencore.objects.core.DurationTag;
Expand All @@ -23,7 +27,7 @@

import java.util.*;

public class ChunkTag implements ObjectTag, Adjustable {
public class ChunkTag implements ObjectTag, Adjustable, FlaggableObject {

// <--[language]
// @name ChunkTag Objects
Expand Down Expand Up @@ -235,8 +239,37 @@ public boolean isLoadedSafe() {
}
}

@Override
public AbstractFlagTracker getFlagTracker() {
if (!NMSHandler.getVersion().isAtLeast(NMSVersion.v1_16)) {
Debug.echoError("Chunk flags are only available in 1.16+");
return null;
}
return new DataPersistenceFlagTracker(getChunk(), "flag_chunk_");
}

@Override
public AbstractFlagTracker getFlagTrackerForTag() {
if (!isLoadedSafe()) {
return null;
}
return getFlagTracker();
}

@Override
public void reapplyTracker(AbstractFlagTracker tracker) {
// Nothing to do.
}

@Override
public String getReasonNotFlaggable() {
return "is the chunk loaded?";
}

public static void registerTags() {

AbstractFlagTracker.registerFlagHandlers(tagProcessor);

// <--[tag]
// @attribute <ChunkTag.add[<#>,<#>]>
// @returns ChunkTag
Expand Down
Expand Up @@ -555,11 +555,24 @@ public AbstractFlagTracker getFlagTracker() {
return new DataPersistenceFlagTracker(getChunk(), "flag_tracker_" + getBlockX() + "_" + getBlockY() + "_" + getBlockZ() + "_");
}

@Override
public AbstractFlagTracker getFlagTrackerForTag() {
if (!isChunkLoadedSafe()) {
return null;
}
return getFlagTracker();
}

@Override
public void reapplyTracker(AbstractFlagTracker tracker) {
// Nothing to do.
}

@Override
public String getReasonNotFlaggable() {
return "is the chunk loaded?";
}

/**
* Indicates whether this location is forced to identify as not-a-note or not.
*/
Expand Down

0 comments on commit 03507a4

Please sign in to comment.