Skip to content

Commit

Permalink
Replace internal chunk data method with non-regex to avoid schematic lag
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 27, 2021
1 parent 666a4e0 commit 54758dd
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 11 deletions.
Expand Up @@ -590,5 +590,4 @@ public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
}
return null;
}

}
Expand Up @@ -67,15 +67,12 @@ public boolean couldMatch(ScriptPath path) {
@Override
public boolean matches(ScriptPath path) {
String target = path.eventArgLowerAt(0);

if (!tryEntity(entity, target)) {
return false;
}

if (!runInCheck(path, entity.getLocation())) {
return false;
}

return super.matches(path);
}

Expand Down
Expand Up @@ -178,6 +178,8 @@ public boolean isCorrectMappingsCode() {

public abstract String stringForHover(HoverEvent hover);

public abstract ArrayList<String> containerListFlags(PersistentDataContainer container, String prefix);

public abstract boolean containerHas(PersistentDataContainer container, NamespacedKey key);

public abstract String containerGetString(PersistentDataContainer container, NamespacedKey key);
Expand Down
Expand Up @@ -1447,7 +1447,7 @@ else if (mtr.angle == BlockFace.EAST) {
// Optionally, specify a maximum range to find the location from (defaults to 200).
// This uses logic equivalent to <@link tag LocationTag.precise_cursor_on_block[(range)]>.
// Note that this will return null if there is no block in range.
// This uses all blocks, ie it includes passable blocks like tall-grass and water. Use <@link tag EntityTag.cursor_on> to include passable blocks.
// This uses all blocks, ie it includes passable blocks like tall-grass and water. Use <@link tag EntityTag.cursor_on_solid> to include passable blocks.
// -->
registerSpawnedOnlyTag("cursor_on", (attribute, object) -> {
double range = attribute.getDoubleContext(1);
Expand Down
Expand Up @@ -74,7 +74,7 @@ public TakeCommand() {
//
// If an economy is registered, using 'money' instead of an item will take money from the player's economy balance.
//
// Flagged, Slot, Bydisplay all take a list as input to take multiple different item types at once.
// Flagged, Slot, ByDisplay, and Raw_Exact, all take a list as input to take multiple different item types at once.
//
// If no quantity is specified, exactly 1 item will be taken.
//
Expand Down
@@ -1,6 +1,7 @@
package com.denizenscript.denizen.utilities.flags;

import com.denizenscript.denizen.Denizen;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.utilities.DataPersistenceHelper;
import com.denizenscript.denizencore.flags.MapTagBasedFlagTracker;
import com.denizenscript.denizencore.objects.ObjectTag;
Expand All @@ -11,7 +12,6 @@
import org.bukkit.persistence.PersistentDataType;

import java.util.Collection;
import java.util.stream.Collectors;

public class DataPersistenceFlagTracker extends MapTagBasedFlagTracker {

Expand Down Expand Up @@ -47,9 +47,7 @@ public void setRootMap(String key, MapTag map) {

@Override
public Collection<String> listAllFlags() {
return holder.getPersistentDataContainer().getKeys().stream()
.filter(k -> k.getNamespace().equals("denizen") && k.getKey().startsWith(keyPrefix))
.map(k -> k.getKey().substring(keyPrefix.length())).collect(Collectors.toList());
return NMSHandler.getInstance().containerListFlags(holder.getPersistentDataContainer(), keyPrefix);
}

public static NamespacedKey expireNeededKey = new NamespacedKey(Denizen.getInstance(), "expire_flag_check_needed");
Expand Down
Expand Up @@ -563,7 +563,6 @@ else if (def.equals("__npc")) {
return null;
}


@Override
public boolean setSpecialDef(String def, ScriptQueue queue, ObjectTag value) {
if (def.equals("__player")) {
Expand Down
Expand Up @@ -41,6 +41,7 @@

import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Map;

public class Handler extends NMSHandler {
Expand Down Expand Up @@ -225,6 +226,18 @@ public String stringForHover(HoverEvent hover) {
return FormattedTextHelper.stringify(hover.getValue(), ChatColor.WHITE);
}

@Override
public ArrayList<String> containerListFlags(PersistentDataContainer container, String prefix) {
prefix = "denizen:" + prefix;
ArrayList<String> output = new ArrayList<>();
for (String key : ((CraftPersistentDataContainer) container).getRaw().keySet()) {
if (key.startsWith(prefix)) {
output.add(key.substring(prefix.length()));
}
}
return output;
}

@Override
public boolean containerHas(PersistentDataContainer container, NamespacedKey key) {
return ((CraftPersistentDataContainer) container).getRaw().containsKey(key.toString());
Expand Down
Expand Up @@ -41,6 +41,7 @@

import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Map;

public class Handler extends NMSHandler {
Expand Down Expand Up @@ -225,6 +226,18 @@ public String stringForHover(HoverEvent hover) {
return FormattedTextHelper.stringify(hover.getValue(), ChatColor.WHITE);
}

@Override
public ArrayList<String> containerListFlags(PersistentDataContainer container, String prefix) {
prefix = "denizen:" + prefix;
ArrayList<String> output = new ArrayList<>();
for (String key : ((CraftPersistentDataContainer) container).getRaw().keySet()) {
if (key.startsWith(prefix)) {
output.add(key.substring(prefix.length()));
}
}
return output;
}

@Override
public boolean containerHas(PersistentDataContainer container, NamespacedKey key) {
return ((CraftPersistentDataContainer) container).getRaw().containsKey(key.toString());
Expand Down
Expand Up @@ -48,6 +48,7 @@

import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Map;

public class Handler extends NMSHandler {
Expand Down Expand Up @@ -258,6 +259,18 @@ else if (contentObject instanceof net.md_5.bungee.api.chat.hover.content.Entity)
}
}

@Override
public ArrayList<String> containerListFlags(PersistentDataContainer container, String prefix) {
prefix = "denizen:" + prefix;
ArrayList<String> output = new ArrayList<>();
for (String key : ((CraftPersistentDataContainer) container).getRaw().keySet()) {
if (key.startsWith(prefix)) {
output.add(key.substring(prefix.length()));
}
}
return output;
}

@Override
public boolean containerHas(PersistentDataContainer container, NamespacedKey key) {
return ((CraftPersistentDataContainer) container).getRaw().containsKey(key.toString());
Expand Down

0 comments on commit 54758dd

Please sign in to comment.