Skip to content

Commit

Permalink
Add namedspaced_key method & change clashing Util methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantheleach committed Jan 11, 2022
1 parent 0c0e1cc commit 77e60d5
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.oddlama.vane.core.item;

import static org.oddlama.vane.util.Util.namespaced_key;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -17,6 +15,7 @@
import org.oddlama.vane.core.lang.TranslatedMessage;
import org.oddlama.vane.core.module.Module;
import org.oddlama.vane.core.module.ModuleComponent;
import org.oddlama.vane.util.Util;

public class CustomItemVariant<T extends Module<T>, V extends CustomItem<T, V>, U extends ItemVariantEnum>
extends ModuleComponent<T> {
Expand Down Expand Up @@ -50,7 +49,7 @@ public CustomItemVariant(CustomItem<T, V> parent, U variant) {
}

// Create namespaced_key
this.key = namespaced_key(get_module().namespace(), variant_name);
this.key = Util.namespaced_key(get_module().namespace(), variant_name);

// Check for duplicate model data
parent.check_valid_model_data(this);
Expand Down Expand Up @@ -94,7 +93,7 @@ public final NamespacedKey key() {
* Returns the namespaced key for this item with additional suffix.
*/
public final NamespacedKey key(String suffix) {
return namespaced_key(get_module().namespace(), variant_name + "_" + suffix);
return Util.namespaced_key(get_module().namespace(), variant_name + "_" + suffix);
}

public final String variant_name() {
Expand Down Expand Up @@ -144,9 +143,9 @@ public final NamespacedKey recipe_key() {
/** Returns a named recipe key */
public final NamespacedKey recipe_key(String recipe_name) {
if (recipe_name.equals("")) {
return namespaced_key(get_module().namespace(), variant_name + "_recipe");
return Util.namespaced_key(get_module().namespace(), variant_name + "_recipe");
}
return namespaced_key(get_module().namespace(), variant_name + "_recipe_" + recipe_name);
return Util.namespaced_key(get_module().namespace(), variant_name + "_recipe_" + recipe_name);
}

private final void add_recipe_or_throw(NamespacedKey recipe_key, Recipe recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.IOException;
import java.util.function.Consumer;

import org.bukkit.NamespacedKey;
import org.bukkit.scheduler.BukkitTask;
import org.json.JSONObject;
import org.oddlama.vane.core.ResourcePackGenerator;
Expand Down Expand Up @@ -69,4 +71,8 @@ public final String storage_path_of(String field) {
public final void mark_persistent_storage_dirty() {
context.mark_persistent_storage_dirty();
}

public final NamespacedKey namespaced_key(String value) {
return new NamespacedKey(get_module(), get_context().variable_yaml_path(value));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.oddlama.vane.core.module.Context;
import org.oddlama.vane.core.module.Module;
import org.oddlama.vane.util.Nms;
import org.oddlama.vane.util.Util;

public class CustomEnchantment<T extends Module<T>> extends Listener<T> {

Expand Down Expand Up @@ -53,7 +54,7 @@ public CustomEnchantment(Context<T> context) {
set_context(context);

// Create namespaced key
key = namespaced_key(get_module().namespace(), name);
key = Util.namespaced_key(get_module().namespace(), name);

// Check if instance is already exists
if (instances.get(getClass()) != null) {
Expand Down Expand Up @@ -287,9 +288,9 @@ public final NamespacedKey recipe_key() {
/** Returns a named recipe key */
public final NamespacedKey recipe_key(String recipe_name) {
if (recipe_name.equals("")) {
return namespaced_key(get_module().namespace(), "enchantment_" + name + "_recipe");
return Util.namespaced_key(get_module().namespace(), "enchantment_" + name + "_recipe");
}
return namespaced_key(get_module().namespace(), "enchantment_" + name + "_recipe_" + recipe_name);
return Util.namespaced_key(get_module().namespace(), "enchantment_" + name + "_recipe_" + recipe_name);
}

private final void add_recipe_or_throw(NamespacedKey recipe_key, Recipe recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.oddlama.vane.enchantments.Enchantments;
import org.oddlama.vane.enchantments.items.AncientTomeOfTheGods;
import org.oddlama.vane.enchantments.items.BookVariant;
import org.oddlama.vane.util.Util;

@VaneEnchantment(name = "soulbound", rarity = Rarity.RARE, treasure = true, allow_custom = true)
public class Soulbound extends CustomEnchantment<Enchantments> {
Expand All @@ -44,7 +45,7 @@ public class Soulbound extends CustomEnchantment<Enchantments> {
)
public long config_cooldown;

private static final NamespacedKey IGNORE_SOULBOUND_DROP = namespaced_key(
private static final NamespacedKey IGNORE_SOULBOUND_DROP = Util.namespaced_key(
"vane_enchantments",
"ignore_soulbound_drop"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.oddlama.vane.portals.event.PortalSelectTargetEvent;
import org.oddlama.vane.portals.event.PortalUnlinkConsoleEvent;
import org.oddlama.vane.portals.portal.Portal;
import org.oddlama.vane.util.Util;

public class ConsoleMenu extends ModuleComponent<Portals> {

Expand Down Expand Up @@ -101,15 +102,15 @@ public ConsoleMenu(Context<Portals> context) {
new TranslatedItemStack<>(
ctx,
"unlink_console",
namespaced_key("vane", "decoration_tnt_1"),
Util.namespaced_key("vane", "decoration_tnt_1"),
1,
"Used to unlink the current console."
);
item_unlink_console_confirm_accept =
new TranslatedItemStack<>(
ctx,
"unlink_console_confirm_accept",
namespaced_key("vane", "decoration_tnt_1"),
Util.namespaced_key("vane", "decoration_tnt_1"),
1,
"Used to confirm unlinking the current console."
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.oddlama.vane.portals.Portals;
import org.oddlama.vane.portals.event.PortalChangeSettingsEvent;
import org.oddlama.vane.portals.portal.Portal;
import org.oddlama.vane.util.Util;

public class SettingsMenu extends ModuleComponent<Portals> {

Expand Down Expand Up @@ -51,7 +52,7 @@ public SettingsMenu(Context<Portals> context) {
new TranslatedItemStack<>(
ctx,
"select_icon",
namespaced_key("vane", "decoration_end_portal_orb"),
Util.namespaced_key("vane", "decoration_end_portal_orb"),
1,
"Used to select the portal's icon."
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.oddlama.vane.regions.region.EnvironmentSetting;
import org.oddlama.vane.regions.region.RegionGroup;
import org.oddlama.vane.regions.region.Role;
import org.oddlama.vane.util.Util;

public class RegionGroupMenu extends ModuleComponent<Regions> {

Expand Down Expand Up @@ -64,15 +65,15 @@ public RegionGroupMenu(Context<Regions> context) {
new TranslatedItemStack<>(
ctx,
"delete",
namespaced_key("vane", "decoration_tnt_1"),
Util.namespaced_key("vane", "decoration_tnt_1"),
1,
"Used to delete this region group."
);
item_delete_confirm_accept =
new TranslatedItemStack<>(
ctx,
"delete_confirm_accept",
namespaced_key("vane", "decoration_tnt_1"),
Util.namespaced_key("vane", "decoration_tnt_1"),
1,
"Used to confirm deleting the region group."
);
Expand Down Expand Up @@ -123,7 +124,7 @@ public RegionGroupMenu(Context<Regions> context) {
new TranslatedItemStack<>(
ctx,
"setting_info_animals",
namespaced_key("vane", "animals_baby_pig_2"),
Util.namespaced_key("vane", "animals_baby_pig_2"),
1,
"Used to represent the info for the animals setting."
);
Expand All @@ -139,7 +140,7 @@ public RegionGroupMenu(Context<Regions> context) {
new TranslatedItemStack<>(
ctx,
"setting_info_explosions",
namespaced_key("vane", "monsters_creeper_with_tnt_2"),
Util.namespaced_key("vane", "monsters_creeper_with_tnt_2"),
1,
"Used to represent the info for the explosions setting."
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.oddlama.vane.regions.region.Region;
import org.oddlama.vane.regions.region.RegionGroup;
import org.oddlama.vane.regions.region.RegionSelection;
import org.oddlama.vane.util.Util;

public class RegionMenu extends ModuleComponent<Regions> {

Expand Down Expand Up @@ -53,15 +54,15 @@ public RegionMenu(Context<Regions> context) {
new TranslatedItemStack<>(
ctx,
"delete",
namespaced_key("vane", "decoration_tnt_1"),
Util.namespaced_key("vane", "decoration_tnt_1"),
1,
"Used to delete this region."
);
item_delete_confirm_accept =
new TranslatedItemStack<>(
ctx,
"delete_confirm_accept",
namespaced_key("vane", "decoration_tnt_1"),
Util.namespaced_key("vane", "decoration_tnt_1"),
1,
"Used to confirm deleting the region."
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.oddlama.vane.regions.region.Role;
import org.oddlama.vane.regions.region.RoleSetting;
import org.oddlama.vane.util.ItemUtil;
import org.oddlama.vane.util.Util;

public class RoleMenu extends ModuleComponent<Regions> {

Expand Down Expand Up @@ -66,15 +67,15 @@ public RoleMenu(Context<Regions> context) {
new TranslatedItemStack<>(
ctx,
"delete",
namespaced_key("vane", "decoration_tnt_1"),
Util.namespaced_key("vane", "decoration_tnt_1"),
1,
"Used to delete this role."
);
item_delete_confirm_accept =
new TranslatedItemStack<>(
ctx,
"delete_confirm_accept",
namespaced_key("vane", "decoration_tnt_1"),
Util.namespaced_key("vane", "decoration_tnt_1"),
1,
"Used to confirm deleting the role."
);
Expand Down

0 comments on commit 77e60d5

Please sign in to comment.