diff --git a/islandsurvivalcraft.code-workspace b/islandsurvivalcraft.code-workspace index 15c77e1..604dffa 100644 --- a/islandsurvivalcraft.code-workspace +++ b/islandsurvivalcraft.code-workspace @@ -5,6 +5,17 @@ } ], "settings": { - "java.configuration.updateBuildConfiguration": "automatic" + "java.configuration.updateBuildConfiguration": "automatic", + "files.exclude": { + "**/.classpath": true, + "**/.project": true, + "**/.settings": true, + "**/.factorypath": true + }, + "cSpell.words": [ + "Bukkit", + "crafter", + "itemstack" + ] } } \ No newline at end of file diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/IslandSurvivalCraft.java b/src/main/java/ca/recrown/islandsurvivalcraft/IslandSurvivalCraft.java index 34f0309..d1f6098 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/IslandSurvivalCraft.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/IslandSurvivalCraft.java @@ -12,7 +12,7 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import ca.recrown.islandsurvivalcraft.interaction.commands.CommandProcessor; -import ca.recrown.islandsurvivalcraft.interaction.items.VariedItemManager; +import ca.recrown.islandsurvivalcraft.interaction.items.ItemVariantManager; import ca.recrown.islandsurvivalcraft.world.WorldInfoManager; import ca.recrown.islandsurvivalcraft.world.generation.GeneratorModes; @@ -20,11 +20,11 @@ public class IslandSurvivalCraft extends JavaPlugin implements Listener { private PluginManager pluginManager; private WorldInfoManager worldInfoManager; private CommandProcessor commandProcessor; - private VariedItemManager variedItemManager; + private ItemVariantManager variedItemManager; public IslandSurvivalCraft() { worldInfoManager = new WorldInfoManager(); - variedItemManager = new VariedItemManager(this); + variedItemManager = new ItemVariantManager(this); commandProcessor = new CommandProcessor(this); } diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/interaction/commands/runnables/IslandCommand.java b/src/main/java/ca/recrown/islandsurvivalcraft/interaction/commands/runnables/IslandCommand.java index bdb2797..b844be3 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/interaction/commands/runnables/IslandCommand.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/interaction/commands/runnables/IslandCommand.java @@ -77,10 +77,10 @@ public class IslandCommand implements CommandRunnable { @Override public void run() { for (Player player : playersHighlighting) { - if (player == null) return; + if (player == null) continue; if (!player.isOnline()) { playersHighlighting.remove(player); - return; + continue; } World world = player.getWorld(); WorldInfo worldInfo = islandsurvivalcraft.getWorldInfoManager().retrieve(world.getName()); diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/VariedItem.java b/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/ItemVariant.java similarity index 84% rename from src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/VariedItem.java rename to src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/ItemVariant.java index 9afbd0b..87025b5 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/VariedItem.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/ItemVariant.java @@ -1,7 +1,6 @@ package ca.recrown.islandsurvivalcraft.interaction.items; import org.bukkit.Material; -import org.bukkit.NamespacedKey; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.HumanEntity; @@ -11,24 +10,26 @@ import org.bukkit.inventory.Recipe; import ca.recrown.islandsurvivalcraft.IslandSurvivalCraft; -public interface VariedItem { +public interface ItemVariant { /** * Should be used to perform anything that need only be called once. - * Is called only when the needInitialization method returns true. + * Is called only when the needInitialization() method returns true. * Is called after assigning identity. * @param islandSurvivalCraft The IslandSurvivalCraft plugin object that contains references to various managers that may be used. */ public void initialize(IslandSurvivalCraft islandSurvivalCraft); /** + * The recipe of the item variant. If null, these features will hook directly into the original map. * @return the recipe to be registered with bukkit. */ public Recipe getRecipe(); /** - * @return The official, displayed name of the item. + * @return a string representing the key name of the item. */ - public String getName(); + public String getItemName(); + /** * @@ -36,17 +37,12 @@ public interface VariedItem { */ public Material[] getBaseItems(); - /** - * @return The namespaced key Bukkit will use to identify this variation of the item. - */ - public NamespacedKey getNamespacedKey(); - /** * Assigns a persistent metadata identifier. * This identifier should be saved to any itemstack that is considered this item. * @param identifier The identifier. */ - public void assignIdentifier(VariationItemIdentifier identifier); + public void assignIdentifier(ItemVariantIdentifier identifier); /** @@ -54,7 +50,7 @@ public interface VariedItem { * This usually should just return the assigned identifier. * @return The identifier metadata. */ - public VariationItemIdentifier getIdentifier(); + public ItemVariantIdentifier getIdentifier(); /** * If this item needs initializing. @@ -104,10 +100,4 @@ public interface VariedItem { * @param item The itemstack that represents the item in question. */ public void initializeInstanceOfItem(ItemStack item); - - /** - * - * @return A short description in regards to this variation of the item. - */ - public String getDescription(); } \ No newline at end of file diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/VariationItemIdentifier.java b/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/ItemVariantIdentifier.java similarity index 87% rename from src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/VariationItemIdentifier.java rename to src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/ItemVariantIdentifier.java index 2aca8ec..341db09 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/VariationItemIdentifier.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/ItemVariantIdentifier.java @@ -5,10 +5,10 @@ import java.nio.charset.StandardCharsets; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataType; -public class VariationItemIdentifier implements PersistentDataType { +public class ItemVariantIdentifier implements PersistentDataType { private final String ID; - public VariationItemIdentifier(String ID) { + public ItemVariantIdentifier(String ID) { this.ID = ID; } diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/VariedItemManager.java b/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/ItemVariantManager.java similarity index 69% rename from src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/VariedItemManager.java rename to src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/ItemVariantManager.java index 1949575..c5e59f1 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/VariedItemManager.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/ItemVariantManager.java @@ -6,6 +6,7 @@ import java.util.Map.Entry; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -22,24 +23,28 @@ import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.Recipe; import org.bukkit.inventory.meta.ItemMeta; import ca.recrown.islandsurvivalcraft.IslandSurvivalCraft; -public class VariedItemManager implements Listener { +public class ItemVariantManager implements Listener { private final IslandSurvivalCraft islandSurvivalCraft; - public VariedItemManager(IslandSurvivalCraft islandSurvivalCraft) { + public ItemVariantManager(IslandSurvivalCraft islandSurvivalCraft) { this.islandSurvivalCraft = islandSurvivalCraft; } public void loadAllItems() { - RegisteredVariedItem[] items = RegisteredVariedItem.values(); + RegisteredItemVariants[] items = RegisteredItemVariants.values(); for (int i = 0; i < items.length; i++) { if (items[i].getVariedItem().needInitialization()) { items[i].getVariedItem().initialize(islandSurvivalCraft); - }; - islandSurvivalCraft.getServer().addRecipe(items[i].getVariedItem().getRecipe()); + } + Recipe currRecipe = items[i].getVariedItem().getRecipe(); + if (currRecipe != null) { + islandSurvivalCraft.getServer().addRecipe(currRecipe); + } } Collection players = islandSurvivalCraft.getServer().getOnlinePlayers(); @@ -49,16 +54,16 @@ public class VariedItemManager implements Listener { } public void unloadAllItems() { - RegisteredVariedItem[] items = RegisteredVariedItem.values(); + RegisteredItemVariants[] items = RegisteredItemVariants.values(); for (int i = 0; i < items.length; i++) { - Bukkit.removeRecipe(items[i].getVariedItem().getNamespacedKey()); + Bukkit.removeRecipe(new NamespacedKey(islandSurvivalCraft, items[i].getVariedItem().getItemName())); } } @EventHandler(priority = EventPriority.MONITOR) public void onHeld(PlayerItemHeldEvent e) { ItemStack item = e.getPlayer().getInventory().getItem(e.getNewSlot()); - VariedItem variedItem = getVariedItemFromItemStack(item); + ItemVariant variedItem = getVariedItemFromItemStack(item); if (variedItem != null) { variedItem.onItemHeld(item, e.getPlayer()); } else { @@ -73,7 +78,7 @@ public class VariedItemManager implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onInventoryInteract(InventoryClickEvent e) { ItemStack item = e.getCurrentItem(); - VariedItem variedItem = getVariedItemFromItemStack(item); + ItemVariant variedItem = getVariedItemFromItemStack(item); if (e.getSlotType() == SlotType.RESULT) { if (variedItem != null) { if (variedItem.onItemCrafted(item, e.getWhoClicked())) { @@ -94,7 +99,7 @@ public class VariedItemManager implements Listener { @EventHandler(priority = EventPriority.MONITOR) public void onPlayerDropItem(PlayerDropItemEvent e) { ItemStack item = e.getItemDrop().getItemStack(); - VariedItem variedItem = getVariedItemFromItemStack(item); + ItemVariant variedItem = getVariedItemFromItemStack(item); if (variedItem != null) { variedItem.onItemPutAway(item, e.getPlayer()); } @@ -104,7 +109,7 @@ public class VariedItemManager implements Listener { public void onEntityPickup(EntityPickupItemEvent e) { ItemStack item = e.getItem().getItemStack(); if (e.getEntityType() == EntityType.PLAYER) { - VariedItem variedItem = getVariedItemFromItemStack(item); + ItemVariant variedItem = getVariedItemFromItemStack(item); if (variedItem != null) { Player player = (Player) e.getEntity(); if (player.getInventory().getHeldItemSlot() == player.getInventory().firstEmpty()) { @@ -118,7 +123,7 @@ public class VariedItemManager implements Listener { public void onPlayerInteraction(PlayerInteractEvent e) { if (e.useItemInHand() == Result.DENY || (e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK)) return; ItemStack item = e.getItem(); - VariedItem variedItem = getVariedItemFromItemStack(item); + ItemVariant variedItem = getVariedItemFromItemStack(item); if (variedItem != null) { if(variedItem.onItemRightClicked(item, e.getPlayer(), e.getHand(), e.getClickedBlock(), e.getBlockFace())) { e.setCancelled(true); @@ -131,38 +136,50 @@ public class VariedItemManager implements Listener { public void onPlayerJoin(PlayerJoinEvent e) { initializeInventoryVariedItems(e.getPlayer().getInventory()); ItemStack item = e.getPlayer().getInventory().getItemInMainHand(); - VariedItem variedItem = getVariedItemFromItemStack(item); + ItemVariant variedItem = getVariedItemFromItemStack(item); //Check to see of we can find a variation of the item. if (variedItem != null) { variedItem.onItemHeld(item, e.getPlayer()); } } private void initializeInventoryVariedItems(Inventory inv) { - RegisteredVariedItem[] registeredVariedItems = RegisteredVariedItem.values(); - for (RegisteredVariedItem registeredVariedItem : registeredVariedItems) { - VariedItem variedItem = registeredVariedItem.getVariedItem(); + RegisteredItemVariants[] registeredVariedItems = RegisteredItemVariants.values(); + for (RegisteredItemVariants registeredVariedItem : registeredVariedItems) { + ItemVariant variedItem = registeredVariedItem.getVariedItem(); Material[] bases = variedItem.getBaseItems(); for (Material base : bases) { HashMap potentials = inv.all(base); for (Entry entry : potentials.entrySet()) { - String identifier = entry.getValue().getItemMeta().getPersistentDataContainer().get(variedItem.getNamespacedKey(), variedItem.getIdentifier()); - if (identifier != null) { + if (registeredVariedItem.getVariedItem().getRecipe() != null) { + NamespacedKey key = new NamespacedKey(islandSurvivalCraft, variedItem.getItemName() + ".identifier"); + String identifier = entry.getValue().getItemMeta().getPersistentDataContainer().get(key, variedItem.getIdentifier()); + if (identifier != null) { + variedItem.initializeInstanceOfItem(entry.getValue()); + } + } else { variedItem.initializeInstanceOfItem(entry.getValue()); } } } - } } - private VariedItem getVariedItemFromItemStack(ItemStack item) { + private ItemVariant getVariedItemFromItemStack(ItemStack item) { if (item == null || item.getType() == Material.AIR) return null; ItemMeta meta = item.getItemMeta(); - RegisteredVariedItem[] items = RegisteredVariedItem.values(); + RegisteredItemVariants[] items = RegisteredItemVariants.values(); for (int i = 0; i < items.length; i++) { - VariedItem curr = items[i].getVariedItem(); - String identifier = meta.getPersistentDataContainer().get(curr.getNamespacedKey(), curr.getIdentifier()); + ItemVariant curr = items[i].getVariedItem(); + if (curr.getRecipe() == null) { + for (Material material : curr.getBaseItems()) { + if (item.getType() == material) { + return curr; + } + } + } + NamespacedKey key = new NamespacedKey(islandSurvivalCraft, curr.getItemName()); + String identifier = meta.getPersistentDataContainer().get(key, curr.getIdentifier()); if (identifier != null) { if (curr.getIdentifier().getID().equals(identifier)) { return curr; diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/PersistentBooleanDatatype.java b/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/PersistentBooleanDatatype.java deleted file mode 100644 index 800eacc..0000000 --- a/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/PersistentBooleanDatatype.java +++ /dev/null @@ -1,28 +0,0 @@ -package ca.recrown.islandsurvivalcraft.interaction.items; - -import org.bukkit.persistence.PersistentDataAdapterContext; -import org.bukkit.persistence.PersistentDataType; - -public class PersistentBooleanDatatype implements PersistentDataType { - - @Override - public Class getPrimitiveType() { - return Boolean.class; - } - - @Override - public Class getComplexType() { - return Boolean.class; - } - - @Override - public Boolean toPrimitive(Boolean complex, PersistentDataAdapterContext context) { - return complex; - } - - @Override - public Boolean fromPrimitive(Boolean primitive, PersistentDataAdapterContext context) { - return primitive; - } - -} \ No newline at end of file diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/RegisteredVariedItem.java b/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/RegisteredItemVariants.java similarity index 51% rename from src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/RegisteredVariedItem.java rename to src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/RegisteredItemVariants.java index bf633be..1b648f6 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/RegisteredVariedItem.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/RegisteredItemVariants.java @@ -2,20 +2,20 @@ package ca.recrown.islandsurvivalcraft.interaction.items; import ca.recrown.islandsurvivalcraft.interaction.items.variations.*; -public enum RegisteredVariedItem { +public enum RegisteredItemVariants { ISLAND_MAP(new IslandMapItem()) ; - private final VariedItem variedItem; - private RegisteredVariedItem(VariedItem alternateItem) { + private final ItemVariant variedItem; + private RegisteredItemVariants(ItemVariant alternateItem) { this.variedItem = alternateItem; - this.variedItem.assignIdentifier(new VariationItemIdentifier(this.name())); + this.variedItem.assignIdentifier(new ItemVariantIdentifier(this.name() + ".identifier")); } /** * @return the variedItem */ - public VariedItem getVariedItem() { + public ItemVariant getVariedItem() { return variedItem; } } \ No newline at end of file diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/variations/IslandMapItem.java b/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/variations/IslandMapItem.java index f105717..08d9b25 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/variations/IslandMapItem.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/interaction/items/variations/IslandMapItem.java @@ -1,11 +1,5 @@ package ca.recrown.islandsurvivalcraft.interaction.items.variations; -import java.awt.Color; -import java.util.ArrayList; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.block.Block; @@ -15,55 +9,35 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Recipe; -import org.bukkit.inventory.ShapelessRecipe; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.MapMeta; import org.bukkit.map.MapCanvas; import org.bukkit.map.MapPalette; import org.bukkit.map.MapRenderer; import org.bukkit.map.MapView; -import org.bukkit.map.MapView.Scale; +import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.persistence.PersistentDataType; import ca.recrown.islandsurvivalcraft.IslandSurvivalCraft; -import ca.recrown.islandsurvivalcraft.interaction.items.VariationItemIdentifier; -import ca.recrown.islandsurvivalcraft.interaction.items.VariedItem; +import ca.recrown.islandsurvivalcraft.interaction.items.ItemVariant; +import ca.recrown.islandsurvivalcraft.interaction.items.ItemVariantIdentifier; import ca.recrown.islandsurvivalcraft.utilities.GeneralUtilities; import ca.recrown.islandsurvivalcraft.utilities.datatypes.Point2; import ca.recrown.islandsurvivalcraft.world.WorldInfo; import ca.recrown.islandsurvivalcraft.world.Information.IslandInformation; import ca.recrown.islandsurvivalcraft.world.Information.IslandInformationManager; -public class IslandMapItem extends MapRenderer implements VariedItem { - Color mainColor = new Color(0, 180, 0); - private Material[] baseItems; - private VariationItemIdentifier identifier; - private IslandSurvivalCraft islandSurvivalCraft; - private NamespacedKey namespacedKey; - private ShapelessRecipe recipe; - private ArrayList lore = new ArrayList<>(); +import java.awt.Color; - @Override - public void initialize(IslandSurvivalCraft islandSurvivalCraft) { - lore.add(ChatColor.RESET.toString() + ChatColor.GRAY + "Land ho!"); - this.islandSurvivalCraft = islandSurvivalCraft; - baseItems = new Material[2]; - baseItems[0] = Material.MAP; - baseItems[1] = Material.FILLED_MAP; - namespacedKey = new NamespacedKey(islandSurvivalCraft, "island_map"); - ItemStack resultItem = new ItemStack(getBaseItems()[0], 1); - ItemMeta metadata = resultItem.getItemMeta(); - metadata.getPersistentDataContainer().set(getNamespacedKey(), getIdentifier(), getIdentifier().getID()); - metadata.setLore(lore); - resultItem.setItemMeta(metadata); - recipe = new ShapelessRecipe(namespacedKey, resultItem); - recipe.addIngredient(Material.REDSTONE); - recipe.addIngredient(new ItemStack(Material.MAP)); - } +public class IslandMapItem extends MapRenderer implements ItemVariant { + IslandSurvivalCraft plugin; + ItemVariantIdentifier identifier; + Color mainColor = new Color(0, 180, 0); @SuppressWarnings("deprecation") @Override public void render(MapView map, MapCanvas canvas, Player player) { - WorldInfo worldInfo = islandSurvivalCraft.getWorldInfoManager().retrieve(map.getWorld().getName()); + WorldInfo worldInfo = plugin.getWorldInfoManager().retrieve(map.getWorld().getName()); IslandInformationManager islandInformationManager = worldInfo.getIslandInfoManager(); int blocksPerPixel = (int) (1 * Math.pow(2, map.getScale().getValue())); for (int x = 0; x < 128; x += 1) { @@ -76,8 +50,6 @@ public class IslandMapItem extends MapRenderer implements VariedItem { IslandInformation info = islandInformationManager.getIslandInformation(pCoords, false); if (info != null) { canvas.setPixel(x, y, MapPalette.matchColor(mainColor)); - } else { - canvas.setPixel(x, y, canvas.getBasePixel(x, y)); } } else if (worldInfo.getIslandMap().isIsland(actualX, actualZ)) { canvas.setPixel(x, y, MapPalette.matchColor(mainColor)); @@ -88,87 +60,72 @@ public class IslandMapItem extends MapRenderer implements VariedItem { } @Override - public Recipe getRecipe() { - return recipe; + public void initialize(IslandSurvivalCraft islandSurvivalCraft) { + this.plugin = islandSurvivalCraft; } @Override - public String getName() { - return "Island Map"; + public Recipe getRecipe() { + return null; + } + + @Override + public String getItemName() { + return "Island_Map"; } @Override public Material[] getBaseItems() { - return baseItems; + return new Material[] {Material.FILLED_MAP}; } @Override - public NamespacedKey getNamespacedKey() { - return namespacedKey; - } - - @Override - public boolean onItemCrafted(ItemStack item, HumanEntity crafter) { - if (item.getType() != Material.FILLED_MAP) return false; - Bukkit.getScheduler().scheduleSyncDelayedTask(islandSurvivalCraft, () -> { - initializeInstanceOfItem(item); - }, 15); - return false; - } - - @Override - public void assignIdentifier(VariationItemIdentifier identifier) { + public void assignIdentifier(ItemVariantIdentifier identifier) { this.identifier = identifier; } @Override - public VariationItemIdentifier getIdentifier() { - return identifier; + public ItemVariantIdentifier getIdentifier() { + return this.identifier; } @Override public boolean needInitialization() { - return namespacedKey == null; + return this.plugin == null; + } + + @Override + public boolean onItemCrafted(ItemStack item, HumanEntity crafter) { + return false; } @Override public boolean onItemRightClicked(ItemStack item, HumanEntity clicker, EquipmentSlot hand, Block block, BlockFace blockFace) { - if (item.getType() != Material.MAP) return false; - ItemStack freshMap = new ItemStack(Material.FILLED_MAP, 1); - MapMeta mapMeta = (MapMeta) freshMap.getItemMeta(); - mapMeta.setLore(lore); - mapMeta.getPersistentDataContainer().set(getNamespacedKey(), getIdentifier(), getIdentifier().getID()); - MapView mapView = Bukkit.createMap(clicker.getWorld()); - mapView.setTrackingPosition(true); - mapView.setCenterX((Math.round(clicker.getLocation().getBlockX() / 128f) * 128) - 1); - mapView.setCenterZ((Math.round(clicker.getLocation().getBlockZ() / 128f) * 128) - 1); - mapView.setScale(Scale.CLOSEST); - mapMeta.setMapView(mapView); - freshMap.setItemMeta(mapMeta); - initializeInstanceOfItem(freshMap); - if (clicker.getGameMode() != GameMode.CREATIVE) { - clicker.getInventory().setItem(hand, freshMap); - } else { - clicker.getInventory().addItem(freshMap); - } - return true; - } + if (((Player)clicker).isSneaking()) { + ItemMeta meta = item.getItemMeta(); + PersistentDataContainer container = meta.getPersistentDataContainer(); + NamespacedKey key = new NamespacedKey(plugin, getItemName() + ".state"); + if (!container.has(key, PersistentDataType.BYTE)) { + container.set(key, PersistentDataType.BYTE, (byte) 0); + } + if (container.get(key, PersistentDataType.BYTE) == 0) { + container.set(key, PersistentDataType.BYTE, (byte) 1); + MapMeta mapMeta = (MapMeta) item.getItemMeta(); + mapMeta.getMapView().addRenderer(this); + } else { + container.set(key, PersistentDataType.BYTE, (byte) 0); + MapMeta mapMeta = (MapMeta) item.getItemMeta(); + mapMeta.getMapView().removeRenderer(this); + } - @Override - public void initializeInstanceOfItem(ItemStack item) { - if (item.getType() != Material.FILLED_MAP) return; - MapMeta mapMeta = (MapMeta) item.getItemMeta(); - MapView mapView = mapMeta.getMapView(); - if (mapView.getRenderers().contains(this)) return; - mapView.addRenderer(this); - mapMeta.setMapView(mapView); - item.setItemMeta(mapMeta); + item.setItemMeta(meta); + } + return false; } @Override public void onItemHeld(ItemStack heldItem, HumanEntity holder) { - initializeInstanceOfItem(heldItem); } @Override @@ -176,7 +133,17 @@ public class IslandMapItem extends MapRenderer implements VariedItem { } @Override - public String getDescription() { - return "A map that has island hunting properties. Will highlight islands in relation on map."; + public void initializeInstanceOfItem(ItemStack item) { + MapMeta mapMeta = (MapMeta) item.getItemMeta(); + PersistentDataContainer container = mapMeta.getPersistentDataContainer(); + NamespacedKey key = new NamespacedKey(plugin, getItemName() + ".state"); + + if (container.has(key, PersistentDataType.BYTE)) { + if (container.get(key, PersistentDataType.BYTE) == 1) { + mapMeta = (MapMeta) item.getItemMeta(); + mapMeta.getMapView().addRenderer(this); + item.setItemMeta(mapMeta); + } + } } -} \ No newline at end of file +} diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/world/Information/IslandInformationManager.java b/src/main/java/ca/recrown/islandsurvivalcraft/world/Information/IslandInformationManager.java index 3eaccb6..0e47f81 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/world/Information/IslandInformationManager.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/world/Information/IslandInformationManager.java @@ -140,9 +140,9 @@ public class IslandInformationManager implements Runnable { while (buildingCache.size() > 0) { Point2 chunkCoords = buildingCache.getMostRecentKey(); CompletableFuture> future = buildingCache.remove(chunkCoords); - HashSet islandInformations = buildChunkIslandInformation(chunkCoords); - islandSets.put(chunkCoords, islandInformations); - future.complete(islandInformations); + HashSet islandInfos = buildChunkIslandInformation(chunkCoords); + islandSets.put(chunkCoords, islandInfos); + future.complete(islandInfos); } try { synchronized (loader) { diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/world/IslandWorldMap.java b/src/main/java/ca/recrown/islandsurvivalcraft/world/IslandWorldMap.java index 286782a..19ccdcd 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/world/IslandWorldMap.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/world/IslandWorldMap.java @@ -158,7 +158,7 @@ public class IslandWorldMap { * Find the island's origin block. Will call the coordinate target validatable to end early if nessecary. * @param worldX The x coordinate of the island block in question. * @param worldZ The y coordinate of the island block in question. - * @param targetValidator The coordinate target validator to use. Optional and is null. + * @param targetValidator The coordinate target validator to use. May be null. * @return The island origin point. Will be null if the passed target target validator stops search prematurely. */ public Point2 findIslandOrigin(int worldX, int worldZ, CoordinateValidatable targetValidator) { diff --git a/src/test/java/ca/recrown/islandsurvivalcraft/utilities/pathfinding/DepthFirstSearchTest.java b/src/test/java/ca/recrown/islandsurvivalcraft/utilities/pathfinding/DepthFirstSearchTest.java index 97d6df7..8e432ad 100644 --- a/src/test/java/ca/recrown/islandsurvivalcraft/utilities/pathfinding/DepthFirstSearchTest.java +++ b/src/test/java/ca/recrown/islandsurvivalcraft/utilities/pathfinding/DepthFirstSearchTest.java @@ -15,7 +15,6 @@ import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance.Lifecycle; import ca.recrown.islandsurvivalcraft.utilities.datatypes.Point2; -import ca.recrown.islandsurvivalcraft.utilities.pathfinding.CoordinateValidatable; /** * Unit test for simple App. diff --git a/test-server/bukkit.yml b/test-server/bukkit.yml index 6ee200a..43ed810 100644 --- a/test-server/bukkit.yml +++ b/test-server/bukkit.yml @@ -24,6 +24,7 @@ settings: shutdown-message: Server closed minimum-api: none spawn-limits: + water-ambient: 20 monsters: 70 animals: 10 water-animals: 15 @@ -31,6 +32,7 @@ spawn-limits: chunk-gc: period-in-ticks: 600 ticks-per: + water-ambient-spawns: 1 animal-spawns: 400 monster-spawns: 1 water-spawns: 1