mirror of
https://github.com/darksaid98/AlathranWars.git
synced 2026-12-01 14:38:55 +00:00
Move registry instance out of Main
This commit is contained in:
1 parent
1dd938da60
commit
89fc6d1769
6 files changed
+18
-9
No files matched your search
@@ -19,8 +19,6 @@ public class Main extends JavaPlugin {
|
||||
public static Main instance;
|
||||
public static Economy econ;
|
||||
public static AlathraWarLogger warLogger;
|
||||
public static WarItemRegistry itemRegistry;
|
||||
public static WarRecipeRegistry recipeRegistry;
|
||||
|
||||
static {
|
||||
instance = null;
|
||||
@@ -101,9 +99,9 @@ public class Main extends JavaPlugin {
|
||||
getServer().getPluginManager().registerEvents(new PlayerInteractListener(), this);
|
||||
|
||||
//run first
|
||||
itemRegistry = new WarItemRegistry();
|
||||
new WarItemRegistry();
|
||||
//run second
|
||||
recipeRegistry = new WarRecipeRegistry();
|
||||
new WarRecipeRegistry();
|
||||
|
||||
initData();
|
||||
initAPIs();
|
||||
|
||||
@@ -152,9 +152,9 @@ public class AdminCommands implements CommandExecutor {
|
||||
//find item
|
||||
ItemStack stack = null;
|
||||
if(args[1].contains(Main.getInstance().getName().toLowerCase())) {
|
||||
stack = Main.itemRegistry.getOrNullNamespace(args[1]);
|
||||
stack = WarItemRegistry.getInstance().getOrNullNamespace(args[1]);
|
||||
} else {
|
||||
stack = Main.itemRegistry.getOrNull(args[1]);
|
||||
stack = WarItemRegistry.getInstance().getOrNull(args[1]);
|
||||
}
|
||||
// item not real!
|
||||
if(stack == null) {
|
||||
|
||||
@@ -242,6 +242,6 @@ public class CommandHelper {
|
||||
* @return list of all alathrawar items namespaced
|
||||
*/
|
||||
public static List<String> getWarItems() {
|
||||
return new ArrayList<>(WarItemRegistry.getItemRegistry().keySet());
|
||||
return new ArrayList<>(WarItemRegistry.getInstance().getItemRegistry().keySet());
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import java.util.stream.Stream;
|
||||
|
||||
public class WarItemRegistry {
|
||||
|
||||
private static WarItemRegistry instance;
|
||||
|
||||
private static final HashMap<String, IWarItem> itemRegistry = new HashMap<>();
|
||||
|
||||
@@ -24,6 +25,8 @@ public class WarItemRegistry {
|
||||
* loads all items into the plugin registry list
|
||||
*/
|
||||
public WarItemRegistry() {
|
||||
instance = this;
|
||||
|
||||
Main.warLogger.log(Helper.chatLabel() + "Registering AlathraWar items.");
|
||||
|
||||
itemRegistry.put(registryName("ram"), new RamItem());
|
||||
@@ -31,6 +34,10 @@ public class WarItemRegistry {
|
||||
Main.warLogger.log(Helper.chatLabel() + "Registered AlathraWar items.");
|
||||
}
|
||||
|
||||
public static WarItemRegistry getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a registry name
|
||||
* @param item
|
||||
|
||||
@@ -11,12 +11,16 @@ import java.util.Set;
|
||||
|
||||
public class WarRecipeRegistry {
|
||||
|
||||
private static WarRecipeRegistry instance;
|
||||
|
||||
private static final HashMap<String, Recipe> recipeRegistry = new HashMap<>();
|
||||
|
||||
public WarRecipeRegistry() {
|
||||
instance = this;
|
||||
|
||||
Main.warLogger.log(Helper.chatLabel() + "Registering AlathraWar recipes.");
|
||||
|
||||
register(WarItemRegistry.registryName("ram"), Main.itemRegistry.getWarItem("ram").getRecipes());
|
||||
register(WarItemRegistry.registryName("ram"), WarItemRegistry.getInstance().getWarItem("ram").getRecipes());
|
||||
|
||||
Main.warLogger.log(Helper.chatLabel() + "Registered AlathraWar recipes.");
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class PlayerInteractListener implements Listener {
|
||||
if (clicked.getType().toString().contains("DOOR")) { // left click + any door types
|
||||
Door door = (Door) clicked.getBlockData();
|
||||
// lock door in the opposite position
|
||||
if (item.equals(WarItemRegistry.getOrNull("ram"))) {
|
||||
if (item.equals(Main.itemRegistry.getOrNull("ram"))) {
|
||||
boolean inSiegeOrRaid = false;
|
||||
//siege check
|
||||
for (Siege s : SiegeData.getSieges()) {
|
||||
|
||||
Reference in new issue
Block a user