Skip to content

Commit

Permalink
stricter cleaning of item script recipe IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 18, 2019
1 parent b0073c4 commit 8d3f08a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.denizenscript.denizen.nms.NMSVersion;
import com.denizenscript.denizen.utilities.DenizenAPI;
import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.events.bukkit.ScriptReloadEvent;
import com.denizenscript.denizen.events.player.PlayerCraftsItemScriptEvent;
Expand All @@ -14,7 +15,6 @@
import com.denizenscript.denizencore.objects.core.ScriptTag;
import com.denizenscript.denizencore.scripts.ScriptBuilder;
import com.denizenscript.denizencore.tags.TagManager;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.YamlConfiguration;
import com.denizenscript.denizencore.utilities.text.StringHolder;
import org.bukkit.*;
Expand Down Expand Up @@ -80,7 +80,7 @@ public void registerShapedRecipe(ItemScriptContainer container, List<String> rec
}
}
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13)) {
String fullId = "shaped_recipe_" + CoreUtilities.toLowerCase(container.getName()) + "_" + id;
String fullId = "shaped_recipe_" + Utilities.cleanseNamespaceID(container.getName()) + "_" + id;
NamespacedKey key = new NamespacedKey("denizen", fullId);
ShapedRecipe recipe = new ShapedRecipe(key, container.getCleanReference().getItemStack());
String shape1 = "ABC".substring(0, width);
Expand Down Expand Up @@ -125,7 +125,7 @@ public void registerShapelessRecipe(ItemScriptContainer container, String shapel
for (int i = 0; i < input.length; i++) {
input[i] = ingredients.get(i).getItemStack().clone();
}
String fullId = "shapeless_recipe_" + CoreUtilities.toLowerCase(container.getName()) + "_" + id;
String fullId = "shapeless_recipe_" + Utilities.cleanseNamespaceID(container.getName()) + "_" + id;
NMSHandler.getItemHelper().registerShapelessRecipe(fullId, result, input);
}
else {
Expand All @@ -142,7 +142,7 @@ public void registerFurnaceRecipe(ItemScriptContainer container, String furnaceI
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13)) {
ItemStack result = container.getCleanReference().getItemStack().clone();
ItemStack input = furnace_item.getItemStack().clone();
String fullId = "furnace_recipe_" + CoreUtilities.toLowerCase(container.getName()) + "_" + id;
String fullId = "furnace_recipe_" + Utilities.cleanseNamespaceID(container.getName()) + "_" + id;
NMSHandler.getItemHelper().registerFurnaceRecipe(fullId, result, input, exp, time, type);
}
else {
Expand All @@ -163,7 +163,7 @@ public void registerStonecuttingRecipe(ItemScriptContainer container, String inp
}
ItemStack result = container.getCleanReference().getItemStack().clone();
ItemStack input = furnace_item.getItemStack().clone();
String fullId = "stonecutting_recipe_" + CoreUtilities.toLowerCase(container.getName()) + "_" + id;
String fullId = "stonecutting_recipe_" + Utilities.cleanseNamespaceID(container.getName()) + "_" + id;
NMSHandler.getItemHelper().registerStonecuttingRecipe(fullId, result, input);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ public static NamespacedKey parseNamespacedKey(String input) {
}
}

public static String cleanseNamespaceID(String input) {
StringBuilder output = new StringBuilder(input.length());
for (char c : input.toCharArray()) {
if (c >= 'A' && c <= 'Z') {
output.append((char)(c - ('a' - 'A')));
}
else if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_') {
output.append(c);
}
}
return output.toString();
}

public static boolean canReadFile(File f) {
if (Settings.allowStupids()) {
return true;
Expand Down

0 comments on commit 8d3f08a

Please sign in to comment.