Skip to content

Commit

Permalink
static tag parsing upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 19, 2022
1 parent 0516020 commit c6a13f8
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 40 deletions.
2 changes: 2 additions & 0 deletions plugin/src/main/java/com/denizenscript/denizen/Denizen.java
Expand Up @@ -27,6 +27,7 @@
import com.denizenscript.denizen.utilities.debugging.BStatsMetricsLite;
import com.denizenscript.denizen.utilities.debugging.DebugSubmit;
import com.denizenscript.denizen.utilities.debugging.StatsRecord;
import com.denizenscript.denizen.utilities.world.WorldListChangeTracker;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.depends.Depends;
import com.denizenscript.denizen.utilities.entity.DenizenEntityType;
Expand Down Expand Up @@ -461,6 +462,7 @@ public void run() {
}
}
}.runTaskTimer(this, 100, 20 * 60 * 5);
Bukkit.getPluginManager().registerEvents(new WorldListChangeTracker(), this);
}

public boolean hasDisabled = false;
Expand Down
@@ -1,5 +1,6 @@
package com.denizenscript.denizen.objects;

import com.denizenscript.denizencore.tags.TagManager;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizencore.objects.*;
import com.denizenscript.denizencore.objects.core.ElementTag;
Expand Down Expand Up @@ -89,6 +90,9 @@ public static ColorTag valueOf(String string, TagContext context) {
string = string.substring("co@".length());
}
if (string.equals("random")) {
if (TagManager.isStaticParsing) {
return null;
}
// Get a color using random RGB values
return new ColorTag(CoreUtilities.getRandom().nextInt(256),
CoreUtilities.getRandom().nextInt(256),
Expand Down
@@ -1,6 +1,7 @@
package com.denizenscript.denizen.objects;

import com.denizenscript.denizen.utilities.NotedAreaTracker;
import com.denizenscript.denizencore.tags.TagManager;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizencore.flags.AbstractFlagTracker;
import com.denizenscript.denizencore.flags.FlaggableObject;
Expand Down Expand Up @@ -98,9 +99,11 @@ public static CuboidTag valueOf(String string, TagContext context) {
if (CoreUtilities.toLowerCase(string).startsWith("cu@")) {
string = string.substring("cu@".length());
}
Notable noted = NoteManager.getSavedObject(string);
if (noted instanceof CuboidTag) {
return (CuboidTag) noted;
if (!TagManager.isStaticParsing) {
Notable noted = NoteManager.getSavedObject(string);
if (noted instanceof CuboidTag) {
return (CuboidTag) noted;
}
}
if (CoreUtilities.contains(string, '@')) {
if (CoreUtilities.contains(string, '|') && string.contains("l@")) {
Expand All @@ -126,13 +129,13 @@ public static CuboidTag valueOf(String string, TagContext context) {
LocationTag pos_1 = LocationTag.valueOf(positions.get(i), context);
LocationTag pos_2 = LocationTag.valueOf(positions.get(i + 1), context);
if (pos_1 == null || pos_2 == null) {
if (context == null || context.showErrors()) {
if ((context == null || context.showErrors()) && !TagManager.isStaticParsing) {
Debug.echoError("valueOf in CuboidTag returning null (null locations): '" + string + "'.");
}
return null;
}
if (pos_1.getWorldName() == null || pos_2.getWorldName() == null) {
if (context == null || context.showErrors()) {
if ((context == null || context.showErrors()) && !TagManager.isStaticParsing) {
Debug.echoError("valueOf in CuboidTag returning null (null worlds): '" + string + "'.");
}
return null;
Expand All @@ -147,7 +150,7 @@ public static CuboidTag valueOf(String string, TagContext context) {
else if (CoreUtilities.contains(string, ',')) {
List<String> subStrs = CoreUtilities.split(string, ',');
if (subStrs.size() < 7 || (subStrs.size() - 1) % 6 != 0) {
if (context == null || context.showErrors()) {
if ((context == null || context.showErrors()) && !TagManager.isStaticParsing) {
Debug.echoError("valueOf CuboidTag returning null (Improper number of commas): '" + string + "'.");
}
return null;
Expand All @@ -167,7 +170,7 @@ else if (CoreUtilities.contains(string, ',')) {
}
}
catch (NumberFormatException ex) {
if (context == null || context.showErrors()) {
if ((context == null || context.showErrors()) && !TagManager.isStaticParsing) {
Debug.echoError("valueOf CuboidTag returning null (Improper number value inputs): '" + ex.getMessage() + "'.");
}
return null;
Expand All @@ -176,7 +179,7 @@ else if (CoreUtilities.contains(string, ',')) {
return toReturn;
}
}
if (context == null || context.showErrors()) {
if ((context == null || context.showErrors()) && !TagManager.isStaticParsing) {
Debug.echoError("Minor: valueOf CuboidTag returning null: " + string);
}
return null;
Expand Down
@@ -1,6 +1,7 @@
package com.denizenscript.denizen.objects;

import com.denizenscript.denizen.utilities.NotedAreaTracker;
import com.denizenscript.denizencore.tags.TagManager;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizencore.flags.AbstractFlagTracker;
import com.denizenscript.denizencore.flags.FlaggableObject;
Expand Down Expand Up @@ -76,18 +77,17 @@ public static EllipsoidTag valueOf(String string, TagContext context) {
if (string.contains("@")) {
return null;
}
Notable noted = NoteManager.getSavedObject(string);
if (noted instanceof EllipsoidTag) {
return (EllipsoidTag) noted;
if (!TagManager.isStaticParsing) {
Notable noted = NoteManager.getSavedObject(string);
if (noted instanceof EllipsoidTag) {
return (EllipsoidTag) noted;
}
}
List<String> split = CoreUtilities.split(string, ',');
if (split.size() != 7) {
return null;
}
WorldTag world = WorldTag.valueOf(split.get(3), false);
if (world == null) {
return null;
}
String worldName = split.get(3);
for (int i = 0; i < 7; i++) {
if (i != 3 && !ArgumentHelper.matchesDouble(split.get(i))) {
if (context == null || context.showErrors()) {
Expand All @@ -96,7 +96,7 @@ public static EllipsoidTag valueOf(String string, TagContext context) {
}
}
}
LocationTag location = new LocationTag(world.getWorld(), Double.parseDouble(split.get(0)), Double.parseDouble(split.get(1)), Double.parseDouble(split.get(2)));
LocationTag location = new LocationTag(Double.parseDouble(split.get(0)), Double.parseDouble(split.get(1)), Double.parseDouble(split.get(2)), worldName);
LocationTag size = new LocationTag(null, Double.parseDouble(split.get(4)), Double.parseDouble(split.get(5)), Double.parseDouble(split.get(6)));
return new EllipsoidTag(location, size);
}
Expand Down
Expand Up @@ -9,6 +9,8 @@
import com.denizenscript.denizen.utilities.flags.DataPersistenceFlagTracker;
import com.denizenscript.denizen.utilities.flags.LocationFlagSearchHelper;
import com.denizenscript.denizen.utilities.world.PathFinder;
import com.denizenscript.denizen.utilities.world.WorldListChangeTracker;
import com.denizenscript.denizencore.tags.TagManager;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.entity.DenizenEntityType;
import com.denizenscript.denizencore.flags.AbstractFlagTracker;
Expand Down Expand Up @@ -94,22 +96,28 @@ public class LocationTag extends org.bukkit.Location implements ObjectTag, Notab
* The world name if a world reference is bad.
*/
public String backupWorld;
public int trackedWorldChange;

public String getWorldName() {
if (backupWorld != null) {
return backupWorld;
}
World w = super.getWorld();
if (w != null) {
return w.getName();
backupWorld = w.getName();
}
return null;
return backupWorld;
}

@Override
public World getWorld() {
World w = super.getWorld();
if (w != null) {
if (trackedWorldChange != WorldListChangeTracker.changes) {
trackedWorldChange = WorldListChangeTracker.changes;
super.setWorld(Bukkit.getWorld(getWorldName()));
return super.getWorld();
}
return w;
}
if (backupWorld == null) {
Expand Down Expand Up @@ -163,9 +171,11 @@ public static LocationTag valueOf(String string, TagContext context) {
if (string.startsWith("l@")) {
string = string.substring(2);
}
Notable noted = NoteManager.getSavedObject(string);
if (noted instanceof LocationTag) {
return (LocationTag) noted;
if (!TagManager.isStaticParsing) {
Notable noted = NoteManager.getSavedObject(string);
if (noted instanceof LocationTag) {
return (LocationTag) noted;
}
}
List<String> split = CoreUtilities.split(string, ',');
if (split.size() == 2)
Expand Down Expand Up @@ -193,7 +203,7 @@ else if (split.size() == 3)
if (worldName.startsWith("w@")) {
worldName = worldName.substring("w@".length());
}
World world = Bukkit.getWorld(worldName);
World world = TagManager.isStaticParsing ? null : Bukkit.getWorld(worldName);
if (world != null) {
return new LocationTag(world,
Double.parseDouble(split.get(0)),
Expand Down Expand Up @@ -227,7 +237,7 @@ else if (split.size() == 4)
if (worldName.startsWith("w@")) {
worldName = worldName.substring("w@".length());
}
World world = Bukkit.getWorld(worldName);
World world = TagManager.isStaticParsing ? null : Bukkit.getWorld(worldName);
if (world != null) {
return new LocationTag(world,
Double.parseDouble(split.get(0)),
Expand Down Expand Up @@ -294,7 +304,7 @@ else if (split.size() == 6)
return null;
}
}
if (context == null || context.showErrors()) {
if ((context == null || context.showErrors()) && !TagManager.isStaticParsing) {
Debug.log("Minor: valueOf LocationTag returning null: " + string);
}
return null;
Expand Down
Expand Up @@ -15,6 +15,7 @@
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.tags.ObjectTagProcessor;
import com.denizenscript.denizencore.tags.TagContext;
import com.denizenscript.denizencore.tags.TagManager;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.YamlConfiguration;
import org.bukkit.Location;
Expand Down Expand Up @@ -135,9 +136,11 @@ public static PolygonTag valueOf(String string, TagContext context) {
if (string.contains("@")) {
return null;
}
Notable saved = NoteManager.getSavedObject(string);
if (saved instanceof PolygonTag) {
return (PolygonTag) saved;
if (!TagManager.isStaticParsing) {
Notable saved = NoteManager.getSavedObject(string);
if (saved instanceof PolygonTag) {
return (PolygonTag) saved;
}
}
List<String> parts = CoreUtilities.split(string, ',');
if (parts.size() < 3) {
Expand Down
Expand Up @@ -11,6 +11,7 @@
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.core.MapTag;
import com.denizenscript.denizencore.objects.core.ScriptTag;
import com.denizenscript.denizencore.tags.TagManager;
import com.denizenscript.denizencore.utilities.AsciiMatcher;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
Expand Down Expand Up @@ -675,7 +676,11 @@ else if (object.asString().startsWith(ChatColor.COLOR_CHAR + "[font=") && object
// Note that this is a magic Denizen tool - refer to <@link language Denizen Text Formatting>.
// -->
ElementTag.tagProcessor.registerStaticTag(ElementTag.class, ElementTag.class, "custom_color", (attribute, object, name) -> {
return new ElementTag(ChatColor.COLOR_CHAR + "[color=f]" + CustomColorTagBase.getColor(name.asLowerString(), attribute.context) + object.asString() + ChatColor.COLOR_CHAR + "[reset=color]");
String color = CustomColorTagBase.getColor(name.asLowerString(), attribute.context);
if (color == null) {
return null;
}
return new ElementTag(ChatColor.COLOR_CHAR + "[color=f]" + color + object.asString() + ChatColor.COLOR_CHAR + "[reset=color]");
});

// <--[tag]
Expand Down Expand Up @@ -704,6 +709,9 @@ else if (colorName.length() == 14 && colorName.startsWith(ChatColor.COLOR_CHAR +
}
else if (colorName.startsWith("co@")) {
ColorTag color = ColorTag.valueOf(colorName, attribute.context);
if (color == null && TagManager.isStaticParsing) {
return null;
}
StringBuilder hex = new StringBuilder(Integer.toHexString(color.getColor().asRGB()));
while (hex.length() < 6) {
hex.insert(0, "0");
Expand All @@ -725,7 +733,9 @@ else if (colorName.startsWith("co@")) {
}
return new ElementTag(ChatColor.COLOR_CHAR + "[color=#" + hex + "]" + object.asString() + ChatColor.COLOR_CHAR + "[reset=color]");
}
attribute.echoError("Color '" + colorName + "' doesn't exist (for ElementTag.color[...]).");
if (!TagManager.isStaticParsing) {
attribute.echoError("Color '" + colorName + "' doesn't exist (for ElementTag.color[...]).");
}
return null;
}
}
Expand Down
Expand Up @@ -28,6 +28,9 @@ public static String getColor(String nameLow, TagContext context) {
customColors.put(nameLow, result);
return result;
}
if (TagManager.isStaticParsing) {
return null;
}
if (defaultColor == null) {
defaultColor = TagManager.tag(defaultColorRaw, context);
}
Expand All @@ -45,7 +48,11 @@ public CustomColorTagBase() {
// Default color names are 'base', 'emphasis', 'warning', 'error'.
// -->
TagManager.registerStaticTagBaseHandler(ElementTag.class, ElementTag.class, "&", (attribute, name) -> {
return new ElementTag(getColor(name.asLowerString(), attribute.context));
String color = getColor(name.asLowerString(), attribute.context);
if (color == null) {
return null;
}
return new ElementTag(color, true);
});
}
}
Expand Up @@ -322,6 +322,9 @@ else if (colorName.length() == 7 && colorName.startsWith("#")) {
}
else if (colorName.startsWith("co@") || colorName.lastIndexOf(',') > colorName.indexOf(',')) {
ColorTag color = ColorTag.valueOf(colorName, attribute.context);
if (color == null && TagManager.isStaticParsing) {
return null;
}
String hex = Integer.toHexString(color.getColor().asRGB());
colorOut = FormattedTextHelper.stringifyRGBSpigot(hex);
}
Expand Down
Expand Up @@ -144,8 +144,7 @@ private static void registerObjectTypes() {
// Returns a color object constructed from the input value.
// Refer to <@link objecttype ColorTag>.
// -->
// non-static due to 'random' color option
TYPE_COLOR = ObjectFetcher.registerWithObjectFetcher(ColorTag.class, ColorTag.tagProcessor).setAsNOtherCode().generateBaseTag(); // co@
TYPE_COLOR = ObjectFetcher.registerWithObjectFetcher(ColorTag.class, ColorTag.tagProcessor).setAsNOtherCode().setCanConvertStatic().generateBaseTag(); // co@

// <--[tag]
// @attribute <cuboid[<cuboid>]>
Expand All @@ -154,8 +153,7 @@ private static void registerObjectTypes() {
// Returns a cuboid object constructed from the input value.
// Refer to <@link objecttype CuboidTag>.
// -->
// non-static due to notes
TYPE_CUBOID = ObjectFetcher.registerWithObjectFetcher(CuboidTag.class, CuboidTag.tagProcessor).setAsNOtherCode().generateBaseTag(); // cu@
TYPE_CUBOID = ObjectFetcher.registerWithObjectFetcher(CuboidTag.class, CuboidTag.tagProcessor).setAsNOtherCode().setCanConvertStatic().generateBaseTag(); // cu@

// <--[tag]
// @attribute <ellipsoid[<ellipsoid>]>
Expand All @@ -164,8 +162,7 @@ private static void registerObjectTypes() {
// Returns an ellipsoid object constructed from the input value.
// Refer to <@link objecttype EllipsoidTag>.
// -->
// non-static due to notes
TYPE_ELLIPSOID = ObjectFetcher.registerWithObjectFetcher(EllipsoidTag.class, EllipsoidTag.tagProcessor).setAsNOtherCode().generateBaseTag(); // ellipsoid@
TYPE_ELLIPSOID = ObjectFetcher.registerWithObjectFetcher(EllipsoidTag.class, EllipsoidTag.tagProcessor).setAsNOtherCode().setCanConvertStatic().generateBaseTag(); // ellipsoid@

// <--[tag]
// @attribute <enchantment[<enchantment>]>
Expand Down Expand Up @@ -265,8 +262,7 @@ else if (obj instanceof NPCTag) {
// Returns a location object constructed from the input value.
// Refer to <@link objecttype LocationTag>.
// -->
// non-static due to notes
TYPE_LOCATION = ObjectFetcher.registerWithObjectFetcher(LocationTag.class, LocationTag.tagProcessor).setAsNOtherCode().generateBaseTag(); // l@
TYPE_LOCATION = ObjectFetcher.registerWithObjectFetcher(LocationTag.class, LocationTag.tagProcessor).setAsNOtherCode().setCanConvertStatic().generateBaseTag(); // l@

// <--[tag]
// @attribute <material[<material>]>
Expand Down Expand Up @@ -357,8 +353,7 @@ else if (obj instanceof NPCTag) {
// Returns a polygon object constructed from the input value.
// Refer to <@link objecttype PolygonTag>.
// -->
// non-static due to notes
TYPE_POLYGON = ObjectFetcher.registerWithObjectFetcher(PolygonTag.class, PolygonTag.tagProcessor).setAsNOtherCode().generateBaseTag(); // polygon@
TYPE_POLYGON = ObjectFetcher.registerWithObjectFetcher(PolygonTag.class, PolygonTag.tagProcessor).setAsNOtherCode().setCanConvertStatic().generateBaseTag(); // polygon@

// <--[tag]
// @attribute <trade[<trade>]>
Expand Down
Expand Up @@ -179,6 +179,7 @@ public void debug(CommandContext args, CommandSender sender) throws CommandExcep
}
if (args.hasFlag('v') || args.hasValueFlag("verbose")) {
CoreConfiguration.debugVerbose = !CoreConfiguration.debugVerbose;
CoreConfiguration.debugUltraVerbose = false;
Messaging.sendInfo(sender, (CoreConfiguration.debugVerbose ? "Denizen debugger is now verbose." :
"Denizen debugger is no longer verbose."));
}
Expand Down

0 comments on commit c6a13f8

Please sign in to comment.