Skip to content

Commit

Permalink
corrections from testing
Browse files Browse the repository at this point in the history
and fix deprecated in-area format
  • Loading branch information
mcmonkey4eva committed Nov 14, 2021
1 parent ebf31bd commit 50c47d2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
Expand Up @@ -15,6 +15,7 @@
import com.denizenscript.denizencore.scripts.queues.core.InstantQueue;
import com.denizenscript.denizencore.tags.TagContext;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.Deprecations;
import com.denizenscript.denizencore.utilities.YamlConfiguration;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizencore.utilities.scheduling.OneTimeSchedulable;
Expand Down Expand Up @@ -137,6 +138,7 @@ public static class ScriptPath {
public ScriptContainer container;
public String event;
public String eventLower;
public String rawContainerPath;
public int priority = 0;
public ScriptEntrySet set;
public Boolean switch_cancelled;
Expand Down Expand Up @@ -239,8 +241,9 @@ public boolean checkSwitch(String key, String value) {
*/
public static HashSet<String> notSwitches = new HashSet<>(Collections.singleton("regex"));

public ScriptPath(ScriptContainer container, String event, String rawEventPath) {
public ScriptPath(ScriptContainer container, String event, String rawContainerPath) {
this.event = event;
this.rawContainerPath = rawContainerPath;
rawEventArgs = CoreUtilities.split(event, ' ').toArray(new String[0]);
this.container = container;
context = DenizenCore.implementation.getTagContext(container);
Expand All @@ -261,9 +264,9 @@ public ScriptPath(ScriptContainer container, String event, String rawEventPath)
eventArgsLower = CoreUtilities.split(eventLower, ' ').toArray(new String[0]);
switch_cancelled = switches.containsKey("cancelled") ? CoreUtilities.equalsIgnoreCase(switches.get("cancelled"), "true") : null;
switch_ignoreCancelled = switches.containsKey("ignorecancelled") ? CoreUtilities.equalsIgnoreCase(switches.get("ignorecancelled"), "true") : null;
set = container.getSetFor("events." + rawEventPath);
set = container.getSetFor("events." + rawContainerPath);
if (set == null || set.entries == null) {
Debug.echoError("Invalid script (formatting error?) in container '" + container.getName() + " at event '" + rawEventPath + "'.");
Debug.echoError("Invalid script (formatting error?) in container '" + container.getName() + " at event '" + rawContainerPath + "'.");
}
}

Expand Down Expand Up @@ -358,9 +361,13 @@ else if (evt1.low.startsWith("after ")) {
evt = evt.replace("&dot", ".").replace("&amp", "&");
ScriptPath path = new ScriptPath(container, evt, evt1.str);
path.fireAfter = after;
tryLoadDirect(path);
}

private static boolean tryLoadDirect(ScriptPath path) {
if (path.set == null) {
Debug.echoError("Script path '<Y>" + path + "<W>' is invalid (empty or misconfigured).");
return;
return false;
}
tryingToBuildPath = path;
ArrayList<ScriptEvent> toScan = couldMatchOptimizer.get(path.eventArgLowerAt(0));
Expand All @@ -372,14 +379,25 @@ else if (evt1.low.startsWith("after ")) {
Debug.log("Event <Y>" + path + "<W> is matched to multiple ScriptEvents: <Y>" + CoreUtilities.join("<W>,<Y> ", path.matches));
}
else if (path.matches.isEmpty()) {
if (path.eventArgsLower.length > 2 && path.eventArgLowerAt(path.eventArgsLower.length - 2).equals("in")) {
ScriptPath legacy = new ScriptPath(path.container, path.event.substring(0, path.eventLower.lastIndexOf(" in ")), path.rawContainerPath);
if (tryLoadDirect(legacy)) {
Deprecations.inAreaSwitchFormat.warn(path.container);
return true;
}
return false;
}
Debug.echoError("Event <Y>" + path + "<W> is not matched to any ScriptEvents.");
if (path.matchFailReasons != null) {
for (String reason : path.matchFailReasons) {
Debug.log(reason);
}
}
path.matchFailReasons = null;
return false;
}
path.matchFailReasons = null;
return true;
}

private static void tryLoadForSet(ScriptPath path, ArrayList<ScriptEvent> events) {
Expand Down Expand Up @@ -591,10 +609,8 @@ public final void registerCouldMatcher(String format) {
return;
}
String base = paren == 0 ? "" : format.substring(0, paren - 1);
String afterText = endParen + 2 == format.length() ? "" : format.substring(endParen + 2);
String afterText = endParen + 2 >= format.length() ? "" : format.substring(endParen + 2);
String optional = format.substring(paren + 1, endParen);
registerCouldMatcher(base + afterText);
registerCouldMatcher(base + " " + optional + afterText);
registerCouldMatcher(base + (afterText.isEmpty() || base.isEmpty() ? afterText : (" " + afterText)));
registerCouldMatcher((base.isEmpty() ? "" : (base + " ")) + optional + (afterText.isEmpty() ? "" : (" " + afterText)));
}
Expand Down
Expand Up @@ -199,15 +199,15 @@ public class Deprecations {
// In Bukkit impl, Added 2021/11/14.
public static Warning blockSpreads = new SlowWarning("There are two '<block> spreads' events - use 'block spreads type:<block>' or 'liquid spreads type:<block>'");

// In Bukkit impl, Added 2019/10/03, bumped to slow 2021/11/14.
public static Warning inAreaSwitchFormat = new SlowWarning("The old 'in <area>' in-line event format is deprecated, use the switch format for 'in:<area>'.");

// ==================== VERY SLOW deprecations ====================
// These are only shown minimally, so server owners are aware of them but not bugged by them. Only servers with active scripters (using 'ex reload') will see them often.

// In Bukkit impl, Added 2019/11/11, bump to normal slow warning by 2022.
public static Warning entityLocationCursorOnTag = new VerySlowWarning("entity.location.cursor_on tags should be replaced by entity.cursor_on (be careful with the slight differences though).");

// In Bukkit impl, Added 2019/10/03, bump to normal slow warning by 2023.
public static Warning inAreaSwitchFormat = new VerySlowWarning("The old 'in <area>' in-line event format is deprecated, use the switch format for 'in:<area>'.");

// Added 2020/05/23, bump to normal slow warning by 2023.
public static Warning timeTagRewrite = new VerySlowWarning("Using old Duration-Time - TimeTag is now separate from DurationTag, and some tags have changed as a result.");

Expand Down

0 comments on commit 50c47d2

Please sign in to comment.