diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java index b9c316d..b02d945 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/Main.java @@ -25,8 +25,6 @@ public class Main extends JavaPlugin { public static Logger log; - public static LinkedBeaconTeleporterManager lbtManager; - public void onEnable() { log = getLogger(); @@ -42,7 +40,7 @@ public class Main extends JavaPlugin { loadConfigs(); - lbtManager = new LinkedBeaconTeleporterManager(); + LinkedBeaconTeleporterManager.init(); log.info("Plugin activated"); } diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/customPlayerMoveEvent/CustomPlayerMoveEvent.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/customPlayerMoveEvent/CustomPlayerMoveEvent.java index 18a4b3c..96dcb6d 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/customPlayerMoveEvent/CustomPlayerMoveEvent.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/customPlayerMoveEvent/CustomPlayerMoveEvent.java @@ -3,8 +3,6 @@ package eu.ruekov.ruakij.LinkedBeaconTeleporters.customPlayerMoveEvent; import org.bukkit.Location; import org.bukkit.entity.Player; -import java.io.InvalidObjectException; - public class CustomPlayerMoveEvent { Player p; diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporter.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporter.java index 83265b5..38f6230 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporter.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporter.java @@ -27,7 +27,7 @@ public abstract class LinkedBeaconTeleporter { this.teleporterId = teleporterId; // Check if id exists - linkedBeaconTeleporters = Main.lbtManager.placedLBTsById.get(this.teleporterId()); + linkedBeaconTeleporters = LinkedBeaconTeleporterManager.placedLBTsById.get(this.teleporterId()); if(linkedBeaconTeleporters == null){ // Create empty if not found linkedBeaconTeleporters = new ArrayList<>(); diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterBlock.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterBlock.java index bdf5b38..04b2489 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterBlock.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterBlock.java @@ -45,7 +45,7 @@ public class LinkedBeaconTeleporterBlock extends LinkedBeaconTeleporter { // TODO: Remove from placedLBTsById when empty? // Remove from loc - Main.lbtManager.placedLBTByLoc.remove( + LinkedBeaconTeleporterManager.placedLBTByLoc.remove( Function.serialiseBlockLocation(loc) ); @@ -65,9 +65,9 @@ public class LinkedBeaconTeleporterBlock extends LinkedBeaconTeleporter { // Conversion methods public static LinkedBeaconTeleporterBlock getFromLocation(Location loc){ - return Main.lbtManager.getLbtBlockFromLocation(loc); + return LinkedBeaconTeleporterManager.getLbtBlockFromLocation(loc); } public static List getListFromTeleportId(String teleportId){ - return Main.lbtManager.getLbtBlocksFromTeleportId(teleportId); + return LinkedBeaconTeleporterManager.getLbtBlocksFromTeleportId(teleportId); } } diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterItem.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterItem.java index e1bb3ec..2bb56d9 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterItem.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterItem.java @@ -24,7 +24,7 @@ public class LinkedBeaconTeleporterItem extends LinkedBeaconTeleporter { // Create a new LinkedBeaconTeleporter super(); - this.item = Main.lbtManager.getItemStackFromData(this.teleporterId); + this.item = LinkedBeaconTeleporterManager.getItemStackFromData(this.teleporterId); } public LinkedBeaconTeleporterItem(String teleporterId, ItemStack item) { super(teleporterId); @@ -34,7 +34,7 @@ public class LinkedBeaconTeleporterItem extends LinkedBeaconTeleporter { public LinkedBeaconTeleporterItem(String teleporterId){ super(teleporterId); - this.item = Main.lbtManager.getItemStackFromData(teleporterId); + this.item = LinkedBeaconTeleporterManager.getItemStackFromData(teleporterId); } public ItemStack item(){ @@ -60,11 +60,11 @@ public class LinkedBeaconTeleporterItem extends LinkedBeaconTeleporter { this.linkedBeaconTeleporters.add(lbtBlock); // Add to id if not exists - if(!Main.lbtManager.placedLBTsById.containsKey(this.teleporterId)) - Main.lbtManager.placedLBTsById.put(this.teleporterId, this.linkedBeaconTeleporters); + if(!LinkedBeaconTeleporterManager.placedLBTsById.containsKey(this.teleporterId)) + LinkedBeaconTeleporterManager.placedLBTsById.put(this.teleporterId, this.linkedBeaconTeleporters); // Add to location - Main.lbtManager.placedLBTByLoc.put( + LinkedBeaconTeleporterManager.placedLBTByLoc.put( Function.serialiseBlockLocation(loc), lbtBlock ); @@ -88,6 +88,6 @@ public class LinkedBeaconTeleporterItem extends LinkedBeaconTeleporter { // Conversion methods public static LinkedBeaconTeleporterItem getFromItemStack(ItemStack itemStack){ - return Main.lbtManager.getLbtItemFromItemStack(itemStack); + return LinkedBeaconTeleporterManager.getLbtItemFromItemStack(itemStack); } } diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java index a52ab90..d5a20e0 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterManager.java @@ -19,13 +19,13 @@ import java.util.regex.Pattern; public class LinkedBeaconTeleporterManager { // Stores all placed Beacon-Teleporters for fast access // TODO: Evaluate necessity of 2 HashMaps with main reason of performance - public HashMap> placedLBTsById = new HashMap(); - public HashMap placedLBTByLoc = new HashMap(); + public static HashMap> placedLBTsById = new HashMap(); + public static HashMap placedLBTByLoc = new HashMap(); // Regex to match item-name&lore and extract id (group 1) - String regex; + static String regex; - public LinkedBeaconTeleporterManager(){ + public static void init(){ Main.log.info("Loading LinkedBeaconTeleporter from config.."); // Construct search item-regex @@ -80,7 +80,7 @@ public class LinkedBeaconTeleporterManager { Main.log.info("All done!"); } - void constructAndAddRecipes(){ + static void constructAndAddRecipes(){ // Create result-item ItemStack item = getItemStackFromData("-"); item.setAmount(2); @@ -102,7 +102,7 @@ public class LinkedBeaconTeleporterManager { } // Conversion-methods - public ItemStack getItemStackFromData(String teleporterId){ + public static ItemStack getItemStackFromData(String teleporterId){ ItemStack item = new ItemStack(Material.BEACON); ItemMeta itemMeta = item.getItemMeta(); @@ -126,7 +126,7 @@ public class LinkedBeaconTeleporterManager { return item; } - public LinkedBeaconTeleporterItem getLbtItemFromItemStack(ItemStack itemStack){ + public static LinkedBeaconTeleporterItem getLbtItemFromItemStack(ItemStack itemStack){ ItemMeta itemMeta = itemStack.getItemMeta(); // Serialize @@ -150,13 +150,13 @@ public class LinkedBeaconTeleporterManager { return lbtItem; } - public LinkedBeaconTeleporterBlock getLbtBlockFromLocation(Location loc){ + public static LinkedBeaconTeleporterBlock getLbtBlockFromLocation(Location loc){ // Serialize String serializedLoc = Function.serialiseBlockLocation(loc); return placedLBTByLoc.get(serializedLoc); } - public List getLbtBlocksFromTeleportId(String teleportId){ + public static List getLbtBlocksFromTeleportId(String teleportId){ return placedLBTsById.get(teleportId); } @@ -174,7 +174,7 @@ public class LinkedBeaconTeleporterManager { return regex; } - String serialiseBeaconItem(String name, List lore){ + static String serialiseBeaconItem(String name, List lore){ // get name and remove control-chars String str = name.replace("\\", "\\\\"); if(lore != null){ diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnCraftItemEvent.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnCraftItemEvent.java index ef02021..acd0ca2 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnCraftItemEvent.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnCraftItemEvent.java @@ -2,6 +2,7 @@ package eu.ruekov.ruakij.LinkedBeaconTeleporters.listener; import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main; import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterItem; +import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterManager; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.event.EventHandler; @@ -21,7 +22,7 @@ public class OnCraftItemEvent implements Listener { ItemStack itemResult = recipe.getResult(); // Check if it has LinkedBeaconTeleporter-Data - LinkedBeaconTeleporterItem lbtItem = Main.lbtManager.getLbtItemFromItemStack(itemResult); + LinkedBeaconTeleporterItem lbtItem = LinkedBeaconTeleporterManager.getLbtItemFromItemStack(itemResult); // Ignore if not found if(lbtItem == null) return; diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnCustomPlayerMove.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnCustomPlayerMove.java index 82e1edd..6dfbcf9 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnCustomPlayerMove.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnCustomPlayerMove.java @@ -6,6 +6,7 @@ import eu.ruekov.ruakij.LinkedBeaconTeleporters.customPlayerMoveEvent.CustomPlay import eu.ruekov.ruakij.LinkedBeaconTeleporters.customPlayerMoveEvent.CustomPlayerMoveEventListener; import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporter; import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterBlock; +import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterManager; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -57,7 +58,7 @@ public class OnCustomPlayerMove implements CustomPlayerMoveEventListener { // TODO: Check if beacon is active // Check if beacon is a LinkedBeaconTeleporter - LinkedBeaconTeleporterBlock lbtBlock = Main.lbtManager.getLbtBlockFromLocation(block.getLocation()); + LinkedBeaconTeleporterBlock lbtBlock = LinkedBeaconTeleporterManager.getLbtBlockFromLocation(block.getLocation()); // Ignore if not found if(lbtBlock == null) return;