Skip to content

Commit

Permalink
clean/group lang docs, some core/bukkit code movement
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Apr 13, 2019
1 parent 8e8dce3 commit 881f599
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 52 deletions.
12 changes: 12 additions & 0 deletions plugin/src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -1294,6 +1294,18 @@ private boolean suggestClosestModifier(CommandSender sender, String command, Str
return false;
}

// --------------------------------------------------------------------------------------
// ------------------------- Begin Denizen Core Implementations -------------------------
// --------------------------------------------------------------------------------------

// <--[language]
// @name Tick
// @group Common Terminology
// @description
// A 'tick' is usually referred to as 1/20th of a second, the speed at which Minecraft servers update
// and process everything on them.
// -->

@Override
public File getScriptFolder() {
File file = null;
Expand Down
Expand Up @@ -77,7 +77,8 @@ public static EventExecutor getExecutor(RegisteredListener listener) {
public List<Map.Entry<RegisteredListener, HandlerList>> registeredHandlers;

// <--[language]
// @name bukkit event priority
// @name Bukkit Event Priority
// @group Script Events
// @description
// Script events that are backed by standard Bukkit events are able to control what underlying Bukkit event priority
// they register as.
Expand Down Expand Up @@ -272,56 +273,6 @@ public boolean runWithCheck(ScriptPath path, dItem held) {
return true;
}

public static final HashMap<String, Pattern> knownPatterns = new HashMap<>();

private static String quotify(String input) {
StringBuilder output = new StringBuilder(input.length());
int last = 0;
int index = input.indexOf('*');
while (index >= 0) {
output.append(Pattern.quote(input.substring(last, index))).append("(.*)");
last = index + 1;
index = input.indexOf('*', last);
}
output.append(Pattern.quote(input.substring(last)));
return output.toString();
}

public Pattern regexHandle(String input) {
Pattern result = knownPatterns.get(input);
if (result != null) {
return result;
}
String output;
if (input.startsWith("regex:")) {
output = input.substring("regex:".length());
}
else if (input.contains("|")) {
String[] split = input.split("\\|");
for (int i = 0; i < split.length; i++) {
split[i] = quotify(split[i]);
}
output = String.join("|", split);
}
else if (input.contains("*")) {
output = quotify(input);
}
else {
return null;
}
if (dB.verbose) {
dB.log("Event regex compile: " + output);
}
result = Pattern.compile(output);
knownPatterns.put(input, result);
return result;
}

public boolean equalityCheck(String input, String compared, Pattern regexed) {
input = CoreUtilities.toLowerCase(input);
return input.equals(compared) || (regexed != null && regexed.matcher(input).matches());
}

public boolean tryInventory(dInventory inv, String comparedto) {
comparedto = CoreUtilities.toLowerCase(comparedto);
if (comparedto.equals("inventory")) {
Expand Down
Expand Up @@ -27,8 +27,8 @@ public class PlayerBreaksBlockScriptEvent extends BukkitScriptEvent implements L
// player breaks <material>
//
// @Regex ^on player breaks [^\s]+$
// @Switch in <area>
//
// @Switch in <area>
// @Switch with <item>
//
// @Cancellable true
Expand Down

0 comments on commit 881f599

Please sign in to comment.