Skip to content

Commit

Permalink
enchantment scripts: don't allow vanilla level generation usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Oct 5, 2021
1 parent 0961207 commit 61c70b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Expand Up @@ -95,6 +95,9 @@ else if (!scriptEntry.hasObject("format")
else if (!scriptEntry.hasObject("text")) {
scriptEntry.addObject("text", new ElementTag(arg.getRawValue()));
}
else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("text")) {
throw new InvalidArgumentsException("Missing text argument!");
Expand Down
Expand Up @@ -254,6 +254,9 @@ public String autoTagForLevel(String value, int level) {
}

public boolean canEnchant(ItemStack item) {
if (!Bukkit.isPrimaryThread()) {
return false;
}
ContextSource.SimpleMap src = new ContextSource.SimpleMap();
src.contexts = new HashMap<>();
src.contexts.put("item", new ItemTag(item));
Expand All @@ -262,6 +265,9 @@ public boolean canEnchant(ItemStack item) {
}

public boolean isCompatible(Enchantment enchantment) {
if (!Bukkit.isPrimaryThread()) {
return false; // NMS calls this method off-thread for level gen (mob equipment can have random enchants). Just say no to this for now.
}
ContextSource.SimpleMap src = new ContextSource.SimpleMap();
src.contexts = new HashMap<>();
src.contexts.put("enchantment_key", new ElementTag(enchantment.getKey().toString()));
Expand Down

0 comments on commit 61c70b8

Please sign in to comment.