diff --git a/pom.xml b/pom.xml index cca19564..834df6a7 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,11 @@ epicspawners 5.7.1 + + com.bgsoftware + wildstacker-api + b14 + org.spigotmc spigot diff --git a/src/main/java/me/goodandevil/skyblock/SkyBlock.java b/src/main/java/me/goodandevil/skyblock/SkyBlock.java index 496c8fb8..11e758f6 100644 --- a/src/main/java/me/goodandevil/skyblock/SkyBlock.java +++ b/src/main/java/me/goodandevil/skyblock/SkyBlock.java @@ -152,6 +152,11 @@ public class SkyBlock extends JavaPlugin { pluginManager.registerEvents(new Spawner(this), this); pluginManager.registerEvents(new Food(this), this); + if (pluginManager.isPluginEnabled("EpicSpawners")) + pluginManager.registerEvents(new EpicSpawners(this), this); + if (pluginManager.isPluginEnabled("WildStacker")) + pluginManager.registerEvents(new WildStacker(this), this); + pluginManager.registerEvents(new Rollback(), this); pluginManager.registerEvents(new Levelling(), this); pluginManager.registerEvents(new Generator(), this); diff --git a/src/main/java/me/goodandevil/skyblock/command/CommandManager.java b/src/main/java/me/goodandevil/skyblock/command/CommandManager.java index 46146dc6..354fa8e8 100644 --- a/src/main/java/me/goodandevil/skyblock/command/CommandManager.java +++ b/src/main/java/me/goodandevil/skyblock/command/CommandManager.java @@ -89,9 +89,10 @@ public class CommandManager implements CommandExecutor, TabCompleter { new me.goodandevil.skyblock.command.commands.admin.GeneratorCommand(), new me.goodandevil.skyblock.command.commands.admin.LevelCommand(), new me.goodandevil.skyblock.command.commands.admin.OwnerCommand(), + new me.goodandevil.skyblock.command.commands.admin.RefreshHologramsCommand(), + new me.goodandevil.skyblock.command.commands.admin.ReloadCommand(), new me.goodandevil.skyblock.command.commands.admin.RemoveHologramCommand(), new me.goodandevil.skyblock.command.commands.admin.RemoveUpgradeCommand(), - new me.goodandevil.skyblock.command.commands.admin.ReloadCommand(), new me.goodandevil.skyblock.command.commands.admin.SetHologramCommand(), new me.goodandevil.skyblock.command.commands.admin.SetSizeCommand(), new me.goodandevil.skyblock.command.commands.admin.SetSpawnCommand(), diff --git a/src/main/java/me/goodandevil/skyblock/command/commands/admin/RefreshHologramsCommand.java b/src/main/java/me/goodandevil/skyblock/command/commands/admin/RefreshHologramsCommand.java new file mode 100644 index 00000000..d19949ae --- /dev/null +++ b/src/main/java/me/goodandevil/skyblock/command/commands/admin/RefreshHologramsCommand.java @@ -0,0 +1,73 @@ +package me.goodandevil.skyblock.command.commands.admin; + +import me.goodandevil.skyblock.command.SubCommand; +import me.goodandevil.skyblock.config.FileManager; +import me.goodandevil.skyblock.config.FileManager.Config; +import me.goodandevil.skyblock.hologram.Hologram; +import me.goodandevil.skyblock.hologram.HologramManager; +import me.goodandevil.skyblock.hologram.HologramType; +import me.goodandevil.skyblock.leaderboard.LeaderboardManager; +import me.goodandevil.skyblock.message.MessageManager; +import me.goodandevil.skyblock.sound.SoundManager; +import me.goodandevil.skyblock.utils.version.Sounds; +import org.apache.commons.lang3.text.WordUtils; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; + +import java.io.File; +import java.io.IOException; + +public class RefreshHologramsCommand extends SubCommand { + + @Override + public void onCommandByPlayer(Player player, String[] args) { + onCommand(player, args); + } + + @Override + public void onCommandByConsole(ConsoleCommandSender sender, String[] args) { + onCommand(sender, args); + } + + public void onCommand(CommandSender sender, String[] args) { + MessageManager messageManager = skyblock.getMessageManager(); + SoundManager soundManager = skyblock.getSoundManager(); + FileManager fileManager = skyblock.getFileManager(); + + Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); + + LeaderboardManager leaderboardManager = skyblock.getLeaderboardManager(); + leaderboardManager.clearLeaderboard(); + leaderboardManager.resetLeaderboard(); + leaderboardManager.setupLeaderHeads(); + + skyblock.getHologramManager().resetHologram(); + + messageManager.sendMessage(sender, configLoad.getString("Command.Island.Admin.RefreshHolograms.Refreshed.Message")); + soundManager.playSound(sender, Sounds.NOTE_PLING.bukkitSound(), 1.0F, 1.0F); + } + + @Override + public String getName() { + return "refreshholograms"; + } + + @Override + public String getInfoMessagePath() { + return "Command.Island.Admin.RefreshHolograms.Info.Message"; + } + + @Override + public String[] getAliases() { + return new String[0]; + } + + @Override + public String[] getArguments() { + return new String[0]; + } +} diff --git a/src/main/java/me/goodandevil/skyblock/command/commands/admin/ReloadCommand.java b/src/main/java/me/goodandevil/skyblock/command/commands/admin/ReloadCommand.java index 2d2c113a..e4b33a59 100644 --- a/src/main/java/me/goodandevil/skyblock/command/commands/admin/ReloadCommand.java +++ b/src/main/java/me/goodandevil/skyblock/command/commands/admin/ReloadCommand.java @@ -39,8 +39,8 @@ public class ReloadCommand extends SubCommand { SoundManager soundManager = skyblock.getSoundManager(); FileManager fileManager = skyblock.getFileManager(); - messageManager.sendMessage(sender, "&cPlease note that this command is not supported and may" + - "cause issues that will make the status of the plugin unrecoverable. " + + messageManager.sendMessage(sender, "&cPlease note that this command is not supported and may " + + "cause issues that could put the plugin in an unstable state. " + "If you encounter any issues please stop your server, edit the configuration files, " + "and then start your server again. This command does NOT reload all the plugin files, only " + "the config.yml, language.yml, generators.yml, and levelling.yml."); @@ -86,18 +86,15 @@ public class ReloadCommand extends SubCommand { levellingManager.unregisterMaterials(); levellingManager.registerMaterials(); - Bukkit.getServer().getScheduler().runTask(skyblock, new Runnable() { - @Override - public void run() { - for (HologramType hologramTypeList : HologramType.values()) { - Hologram hologram = hologramManager.getHologram(hologramTypeList); + Bukkit.getServer().getScheduler().runTask(skyblock, () -> { + for (HologramType hologramTypeList : HologramType.values()) { + Hologram hologram = hologramManager.getHologram(hologramTypeList); - if (hologram != null) { - hologramManager.removeHologram(hologram); - } - - hologramManager.spawnHologram(hologramTypeList); + if (hologram != null) { + hologramManager.removeHologram(hologram); } + + hologramManager.spawnHologram(hologramTypeList); } }); diff --git a/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java b/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java index 2e8b6b21..b9b739a0 100644 --- a/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java +++ b/src/main/java/me/goodandevil/skyblock/levelling/LevellingManager.java @@ -13,7 +13,9 @@ import me.goodandevil.skyblock.utils.version.NMSUtil; import me.goodandevil.skyblock.utils.version.Sounds; import me.goodandevil.skyblock.world.WorldManager; import org.bukkit.*; +import org.bukkit.block.CreatureSpawner; import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; @@ -65,6 +67,9 @@ public class LevellingManager { } } + boolean isEpicSpawnersEnabled = Bukkit.getPluginManager().isPluginEnabled("EpicSpawners"); + boolean isWildStackerEnabled = Bukkit.getPluginManager().isPluginEnabled("WildStacker"); + Map levellingData = new HashMap<>(); for (ChunkSnapshot chunkSnapshotList : chunk.getChunkSnapshots()) { @@ -74,6 +79,7 @@ public class LevellingManager { try { org.bukkit.Material blockMaterial = org.bukkit.Material.AIR; int blockData = 0; + EntityType spawnerType = null; if (NMSVersion > 12) { if (getBlockTypeMethod == null) { @@ -109,26 +115,54 @@ public class LevellingManager { continue; long amount = 1; - if (blockMaterial == Materials.SPAWNER.parseMaterial() - && Bukkit.getPluginManager().isPluginEnabled("EpicSpawners")) { + + if (blockMaterial == Materials.SPAWNER.parseMaterial()) { World world = Bukkit.getWorld(chunkSnapshotList.getWorldName()); - com.songoda.epicspawners.api.EpicSpawners epicSpawners = - com.songoda.epicspawners.api.EpicSpawnersAPI.getImplementation(); Location location = new Location(world, chunkSnapshotList.getX() * 16 + x, y, chunkSnapshotList.getZ() * 16 + z); - if (epicSpawners.getSpawnerManager().isSpawner(location)) { - amount = epicSpawners.getSpawnerManager() - .getSpawnerFromWorld(location).getSpawnerDataCount(); + + if (isEpicSpawnersEnabled) { + com.songoda.epicspawners.api.EpicSpawners epicSpawners = com.songoda.epicspawners.api.EpicSpawnersAPI.getImplementation(); + if (epicSpawners.getSpawnerManager().isSpawner(location)) { + com.songoda.epicspawners.api.spawner.Spawner spawner = epicSpawners.getSpawnerManager().getSpawnerFromWorld(location); + amount = spawner.getSpawnerDataCount(); + spawnerType = spawner.getCreatureSpawner().getSpawnedType(); + } + } else if (isWildStackerEnabled) { + com.bgsoftware.wildstacker.api.handlers.SystemManager wildStacker = com.bgsoftware.wildstacker.api.WildStackerAPI.getWildStacker().getSystemManager(); + if (wildStacker.isStackedSpawner(location.getBlock())) { + com.bgsoftware.wildstacker.api.objects.StackedSpawner spawner = wildStacker.getStackedSpawner(location); + amount = spawner.getStackAmount(); + spawnerType = spawner.getSpawnedType(); + } + } else { + spawnerType = ((CreatureSpawner) location.getBlock().getState()).getSpawnedType(); } - } else if (stackableManager != null && stackableManager.getStackableMaterials().contains(blockMaterial)) { - World world = Bukkit.getWorld(chunkSnapshotList.getWorldName()); - Location location = new Location(world, chunkSnapshotList.getX() * 16 + x, y, chunkSnapshotList.getZ() * 16 + z); - if (stackableManager.isStacked(location)) { - Stackable stackable = stackableManager.getStack(location, blockMaterial); - amount = stackable.getSize(); + } else { + if (isWildStackerEnabled) { + World world = Bukkit.getWorld(chunkSnapshotList.getWorldName()); + Location location = new Location(world, chunkSnapshotList.getX() * 16 + x, y, chunkSnapshotList.getZ() * 16 + z); + com.bgsoftware.wildstacker.api.handlers.SystemManager wildStacker = com.bgsoftware.wildstacker.api.WildStackerAPI.getWildStacker().getSystemManager(); + if (wildStacker.isStackedBarrel(location.getBlock())) { + com.bgsoftware.wildstacker.api.objects.StackedBarrel barrel = wildStacker.getStackedBarrel(location.getBlock()); + amount = barrel.getStackAmount(); + blockMaterial = barrel.getType(); + blockData = barrel.getData(); + if (NMSUtil.getVersionNumber() > 12 && blockMaterial.name().startsWith("LEGACY_")) { + blockMaterial = Material.matchMaterial(blockMaterial.name().replace("LEGACY_", "")); + blockData = 0; + } + } + } else if (stackableManager != null && stackableManager.getStackableMaterials().contains(blockMaterial)) { + World world = Bukkit.getWorld(chunkSnapshotList.getWorldName()); + Location location = new Location(world, chunkSnapshotList.getX() * 16 + x, y, chunkSnapshotList.getZ() * 16 + z); + if (stackableManager.isStacked(location)) { + Stackable stackable = stackableManager.getStack(location, blockMaterial); + amount = stackable.getSize(); + } } } - LevellingData data = new LevellingData(blockMaterial, (byte)blockData); + LevellingData data = new LevellingData(blockMaterial, (byte)blockData, spawnerType); Long totalAmountInteger = levellingData.get(data); long totalAmount = totalAmountInteger == null ? amount : totalAmountInteger + amount; levellingData.put(data, totalAmount); @@ -233,10 +267,12 @@ public class LevellingManager { private class LevellingData { private final Material material; private final byte data; + private final EntityType spawnerType; - private LevellingData(Material material, byte data) { + private LevellingData(Material material, byte data, EntityType spawnerType) { this.material = material; this.data = data; + this.spawnerType = spawnerType; } @Override @@ -244,15 +280,19 @@ public class LevellingManager { if (!(obj instanceof LevellingData)) return false; LevellingData data = (LevellingData)obj; if (this == obj) return true; - return this.material == data.material && this.data == data.data; + return this.material == data.material && this.data == data.data && this.spawnerType == data.spawnerType; } @Override public int hashCode() { - return Objects.hash(this.material, this.data); + return Objects.hash(this.material, this.data, this.spawnerType); } private Materials getMaterials() { + if (this.spawnerType != null) { + return Materials.fromString("SPAWNER_" + this.spawnerType.name()); + } + if (NMSUtil.getVersionNumber() > 12) { try { return Materials.fromString(material.name()); diff --git a/src/main/java/me/goodandevil/skyblock/listeners/EpicSpawners.java b/src/main/java/me/goodandevil/skyblock/listeners/EpicSpawners.java new file mode 100644 index 00000000..4070183c --- /dev/null +++ b/src/main/java/me/goodandevil/skyblock/listeners/EpicSpawners.java @@ -0,0 +1,93 @@ +package me.goodandevil.skyblock.listeners; + +import com.songoda.epicspawners.api.events.SpawnerBreakEvent; +import com.songoda.epicspawners.api.events.SpawnerPlaceEvent; +import me.goodandevil.skyblock.SkyBlock; +import me.goodandevil.skyblock.config.FileManager; +import me.goodandevil.skyblock.island.Island; +import me.goodandevil.skyblock.island.IslandLevel; +import me.goodandevil.skyblock.island.IslandManager; +import me.goodandevil.skyblock.utils.version.Materials; +import me.goodandevil.skyblock.world.WorldManager; +import org.bukkit.Location; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.EntityType; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import java.io.File; + +public class EpicSpawners implements Listener { + + private final SkyBlock skyblock; + + public EpicSpawners(SkyBlock skyblock) { + this.skyblock = skyblock; + } + + @EventHandler + public void onSpawnerPlace(SpawnerPlaceEvent event) { + IslandManager islandManager = skyblock.getIslandManager(); + WorldManager worldManager = skyblock.getWorldManager(); + + Location location = event.getSpawner().getLocation(); + if (!worldManager.isIslandWorld(location.getWorld())) return; + + Island island = islandManager.getIslandAtLocation(location); + + int amount = event.getSpawner().getFirstStack().getStackSize(); + EntityType spawnerType = event.getSpawner().getCreatureSpawner().getSpawnedType(); + + FileManager.Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); + + if (configLoad.getBoolean("Island.Block.Level.Enable")) { + Materials materials = Materials.getSpawner(spawnerType); + if (materials != null) { + IslandLevel level = island.getLevel(); + + long materialAmount = 0; + if (level.hasMaterial(materials.name())) { + materialAmount = level.getMaterialAmount(materials.name()); + } + + level.setMaterialAmount(materials.name(), materialAmount + amount); + } + } + } + + @EventHandler + public void onSpawnerBreak(SpawnerBreakEvent event) { + IslandManager islandManager = skyblock.getIslandManager(); + WorldManager worldManager = skyblock.getWorldManager(); + + Location location = event.getSpawner().getLocation(); + if (!worldManager.isIslandWorld(location.getWorld())) return; + + Island island = islandManager.getIslandAtLocation(location); + + int amount = event.getSpawner().getFirstStack().getStackSize(); + EntityType spawnerType = event.getSpawner().getCreatureSpawner().getSpawnedType(); + + FileManager.Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); + + if (configLoad.getBoolean("Island.Block.Level.Enable")) { + Materials materials = Materials.getSpawner(spawnerType); + if (materials != null) { + IslandLevel level = island.getLevel(); + + if (level.hasMaterial(materials.name())) { + long materialAmount = level.getMaterialAmount(materials.name()); + + if (materialAmount - amount <= 0) { + level.removeMaterial(materials.name()); + } else { + level.setMaterialAmount(materials.name(), materialAmount - amount); + } + } + } + } + } + +} diff --git a/src/main/java/me/goodandevil/skyblock/listeners/WildStacker.java b/src/main/java/me/goodandevil/skyblock/listeners/WildStacker.java new file mode 100644 index 00000000..4095bed1 --- /dev/null +++ b/src/main/java/me/goodandevil/skyblock/listeners/WildStacker.java @@ -0,0 +1,150 @@ +package me.goodandevil.skyblock.listeners; + +import com.bgsoftware.wildstacker.api.events.BarrelUnstackEvent; +import com.bgsoftware.wildstacker.api.events.SpawnerUnstackEvent; +import me.goodandevil.skyblock.SkyBlock; +import me.goodandevil.skyblock.config.FileManager; +import me.goodandevil.skyblock.island.Island; +import me.goodandevil.skyblock.island.IslandLevel; +import me.goodandevil.skyblock.island.IslandManager; +import me.goodandevil.skyblock.utils.version.Materials; +import me.goodandevil.skyblock.utils.version.NMSUtil; +import me.goodandevil.skyblock.world.WorldManager; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.EntityType; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import java.io.File; + +public class WildStacker implements Listener { + + private final SkyBlock skyblock; + + public WildStacker(SkyBlock skyblock) { + this.skyblock = skyblock; + } + + @EventHandler + public void onBarrelUnstack(BarrelUnstackEvent event) { + IslandManager islandManager = skyblock.getIslandManager(); + WorldManager worldManager = skyblock.getWorldManager(); + + Location location = event.getBarrel().getLocation(); + if (!worldManager.isIslandWorld(location.getWorld())) return; + + Island island = islandManager.getIslandAtLocation(location); + + Material material = event.getBarrel().getType(); + byte data = (byte) event.getBarrel().getData(); + + if (NMSUtil.getVersionNumber() > 12 && material.name().startsWith("LEGACY_")) { + material = Material.matchMaterial(material.name().replace("LEGACY_", "")); + data = 0; + } + + FileManager.Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); + + if (configLoad.getBoolean("Island.Block.Level.Enable")) { + Materials materials = Materials.getMaterials(material, data); + if (materials != null) { + IslandLevel level = island.getLevel(); + + if (level.hasMaterial(materials.name())) { + long materialAmount = level.getMaterialAmount(materials.name()); + + if (materialAmount - event.getAmount() <= 0) { + level.removeMaterial(materials.name()); + } else { + level.setMaterialAmount(materials.name(), materialAmount - event.getAmount()); + } + } + } + } + } + + @EventHandler + public void onSpawnerUnstack(SpawnerUnstackEvent event) { + IslandManager islandManager = skyblock.getIslandManager(); + WorldManager worldManager = skyblock.getWorldManager(); + + Location location = event.getSpawner().getLocation(); + if (!worldManager.isIslandWorld(location.getWorld())) return; + + Island island = islandManager.getIslandAtLocation(location); + + EntityType spawnerType = event.getSpawner().getSpawnedType(); + + FileManager.Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); + + if (configLoad.getBoolean("Island.Block.Level.Enable")) { + Materials materials = Materials.getSpawner(spawnerType); + if (materials != null) { + IslandLevel level = island.getLevel(); + + if (level.hasMaterial(materials.name())) { + long materialAmount = level.getMaterialAmount(materials.name()); + + if (materialAmount - event.getAmount() <= 0) { + level.removeMaterial(materials.name()); + } else { + level.setMaterialAmount(materials.name(), materialAmount - event.getAmount()); + } + } + } + } + } + + // TODO: Readd after WildStacker 2.7.4 is released. A feature is being added that will let us multiply the drops by 2x. +// @EventHandler +// public void onMobStack(EntityStackEvent event) { +// LivingEntity livingEntity = event.getEntity().getLivingEntity(); +// +// // Certain entities shouldn't drop twice the amount +// if (livingEntity instanceof Player || +// livingEntity instanceof ArmorStand || +// livingEntity instanceof Horse) { +// return; +// } +// +// if (NMSUtil.getVersionNumber() > 8) { +// if (livingEntity instanceof Donkey || livingEntity instanceof Mule) +// return; +// } +// +// if (livingEntity.hasMetadata("SkyBlock")) { +// return; +// } +// +// IslandManager islandManager = skyblock.getIslandManager(); +// +// if (skyblock.getWorldManager().isIslandWorld(livingEntity.getWorld())) { +// Island island = islandManager.getIslandAtLocation(livingEntity.getLocation()); +// +// if (island != null) { +// List upgrades = skyblock.getUpgradeManager().getUpgrades(Upgrade.Type.Drops); +// +// if (upgrades != null && upgrades.size() > 0 && upgrades.get(0).isEnabled() +// && island.isUpgrade(Upgrade.Type.Drops)) { +// StackedEntity entity = event.getEntity(); +// StackedEntity target = event.getTarget(); +// +// List drops = target.getDrops(0); +// for (ItemStack item : drops) { +// item.setAmount(item.getAmount() * 2); +// } +// +// List newDrops = entity.getDrops(0); +// newDrops.addAll(drops); +// +// entity.setTempLootTable(newDrops); +// } +// } +// } +// } + +} diff --git a/src/main/java/me/goodandevil/skyblock/menus/Levelling.java b/src/main/java/me/goodandevil/skyblock/menus/Levelling.java index 93a5e2fd..386e1171 100644 --- a/src/main/java/me/goodandevil/skyblock/menus/Levelling.java +++ b/src/main/java/me/goodandevil/skyblock/menus/Levelling.java @@ -2,8 +2,10 @@ package me.goodandevil.skyblock.menus; import java.io.File; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import org.apache.commons.lang3.text.WordUtils; import org.bukkit.Bukkit; @@ -194,30 +196,34 @@ public class Levelling { IslandLevel level = island.getLevel(); Map testIslandMaterials = level.getMaterials(); - Map islandMaterials = new HashMap<>(); + List testIslandMaterialKeysOrdered = testIslandMaterials.keySet().stream().sorted().collect(Collectors.toList()); + LinkedHashMap islandMaterials = new LinkedHashMap<>(); Config mainConfig = fileManager.getConfig(new File(skyblock.getDataFolder(), "levelling.yml")); Config settingsConfig = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")); // Filter out ItemStacks that can't be displayed in the inventory Inventory testInventory = Bukkit.createInventory(null, 9); - for (String materialName : testIslandMaterials.keySet()) { + for (String materialName : testIslandMaterialKeysOrdered) { if (mainConfig.getFileConfiguration().getString("Materials." + materialName + ".Points") == null) continue; if (!settingsConfig.getFileConfiguration().getBoolean("Island.Levelling.IncludeEmptyPointsInList") && mainConfig.getFileConfiguration().getInt("Materials." + materialName + ".Points") <= 0) continue; + long value = testIslandMaterials.get(materialName); Materials materials = Materials.fromString(materialName); ItemStack is = materials.parseItem(); - is.setAmount(Math.min(Math.toIntExact(testIslandMaterials.get(materialName)), 64)); + + if (is == null || is.getItemMeta() == null) continue; + + is.setAmount(Math.min(Math.toIntExact(value), 64)); is.setType(MaterialUtil.correctMaterial(is.getType())); - if (is == null || is.getItemMeta() == null) continue; testInventory.clear(); testInventory.setItem(0, is); if (testInventory.getItem(0) != null) { - islandMaterials.put(materialName, testIslandMaterials.get(materialName)); + islandMaterials.put(materialName, value); } } @@ -285,18 +291,23 @@ public class Levelling { is.setAmount(Math.min(Math.toIntExact(materialAmount), 64)); is.setType(MaterialUtil.correctMaterial(is.getType())); + String name; + if (materials.isSpawner() && materials != Materials.SPAWNER) { + name = "Spawner: " + WordUtils.capitalize(material.replace("SPAWNER_", "").toLowerCase().replace("_", " ")).trim(); + } else { + name = WordUtils.capitalize(material.toLowerCase().replace("_", " ")).trim(); + } + List lore = configLoad.getStringList("Menu.Levelling.Item.Material.Lore"); lore.replaceAll(x -> x.replace("%points", NumberUtil.formatNumberByDecimal(pointsEarned)) .replace("%blocks", NumberUtil.formatNumberByDecimal(materialAmount)) - .replace("%material", - WordUtils.capitalize(material.toLowerCase().replace("_", " ")).trim())); + .replace("%material", name)); nInv.addItem(nInv.createItem(is, configLoad .getString("Menu.Levelling.Item.Material.Displayname") .replace("%points", NumberUtil.formatNumberByDecimal(pointsEarned)) .replace("%blocks", NumberUtil.formatNumberByDecimal(materialAmount)) - .replace("%material", - WordUtils.capitalize(material.toLowerCase().replace("_", " ")).trim()), + .replace("%material", name), lore, null, null, null), inventorySlot); } } diff --git a/src/main/java/me/goodandevil/skyblock/utils/version/Materials.java b/src/main/java/me/goodandevil/skyblock/utils/version/Materials.java index 48fe97b0..6fe2e5fd 100644 --- a/src/main/java/me/goodandevil/skyblock/utils/version/Materials.java +++ b/src/main/java/me/goodandevil/skyblock/utils/version/Materials.java @@ -5,6 +5,7 @@ import java.util.HashMap; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; public enum Materials { @@ -767,6 +768,63 @@ public enum Materials { SNOW_BLOCK("SNOW_BLOCK", 0), SOUL_SAND("SOUL_SAND", 0), SPAWNER("MOB_SPAWNER", 0), + SPAWNER_BAT(null, -1), + SPAWNER_BLAZE(null, -1), + SPAWNER_CAVE_SPIDER(null, -1), + SPAWNER_CHICKEN(null, -1), + SPAWNER_COD(null, -1), + SPAWNER_COW(null, -1), + SPAWNER_CREEPER(null, -1), + SPAWNER_DOLPHIN(null, -1), + SPAWNER_DONKEY(null, -1), + SPAWNER_DROWNED(null, -1), + SPAWNER_ELDER_GUARDIAN(null, -1), + SPAWNER_ENDER_DRAGON(null, -1), + SPAWNER_ENDERMAN(null, -1), + SPAWNER_ENDERMITE(null, -1), + SPAWNER_EVOKER(null, -1), + SPAWNER_GHAST(null, -1), + SPAWNER_GIANT(null, -1), + SPAWNER_GUARDIAN(null, -1), + SPAWNER_HORSE(null, -1), + SPAWNER_HUSK(null, -1), + SPAWNER_ILLUSIONER(null, -1), + SPAWNER_IRON_GOLEM(null, -1), + SPAWNER_LLAMA(null, -1), + SPAWNER_MAGMA_CUBE(null, -1), + SPAWNER_MULE(null, -1), + SPAWNER_MUSHROOM_COW(null, -1), + SPAWNER_OCELOT(null, -1), + SPAWNER_PARROT(null, -1), + SPAWNER_PHANTOM(null, -1), + SPAWNER_PIG(null, -1), + SPAWNER_PIG_ZOMBIE(null, -1), + SPAWNER_POLAR_BEAR(null, -1), + SPAWNER_PUFFERFISH(null, -1), + SPAWNER_RABBIT(null, -1), + SPAWNER_SALMON(null, -1), + SPAWNER_SHEEP(null, -1), + SPAWNER_SHULKER(null, -1), + SPAWNER_SILVERFISH(null, -1), + SPAWNER_SKELETON(null, -1), + SPAWNER_SKELETON_HORSE(null, -1), + SPAWNER_SLIME(null, -1), + SPAWNER_SNOWMAN(null, -1), + SPAWNER_SPIDER(null, -1), + SPAWNER_SQUID(null, -1), + SPAWNER_STRAY(null, -1), + SPAWNER_TROPICAL_FISH(null, -1), + SPAWNER_TURTLE(null, -1), + SPAWNER_VEX(null, -1), + SPAWNER_VILLAGER(null, -1), + SPAWNER_VINDICATOR(null, -1), + SPAWNER_WITCH(null, -1), + SPAWNER_WITHER(null, -1), + SPAWNER_WITHER_SKELETON(null, -1), + SPAWNER_WOLF(null, -1), + SPAWNER_ZOMBIE(null, -1), + SPAWNER_ZOMBIE_HORSE(null, -1), + SPAWNER_ZOMBIE_VILLAGER(null, -1), SPECTRAL_ARROW("SPECTRAL_ARROW", 0), SPIDER_EYE("SPIDER_EYE", 0), SPIDER_SPAWN_EGG("MONSTER_EGG", 0), @@ -942,6 +1000,14 @@ public enum Materials { * @return True if the Material exists */ public boolean isAvailable() { + if (this.isSpawner() && this != Materials.SPAWNER) { + String spawnerType = this.name().replace("SPAWNER_", ""); + for (EntityType entityType : EntityType.values()) + if (entityType.name().equalsIgnoreCase(spawnerType)) + return true; + return false; + } + return isNewVersion() || !this.is13only; } @@ -974,6 +1040,14 @@ public enum Materials { return null; } + public boolean isSpawner() { + return this.name().startsWith("SPAWNER"); + } + + public static Materials getSpawner(EntityType spawnerType) { + return fromString("SPAWNER_" + spawnerType.name()); + } + @SuppressWarnings("deprecation") public boolean isSameMaterial(ItemStack comp) { if (isNewVersion()) { @@ -1066,6 +1140,9 @@ public enum Materials { } public Material parseMaterial() { + if (this.isSpawner() && this != Materials.SPAWNER) + return Materials.SPAWNER.parseMaterial(); + Material mat = Material.matchMaterial(this.toString()); if (mat != null) { diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index 090414b0..237011a6 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -773,6 +773,11 @@ Command: Message: "&bSkyBlock &8| &cError&8: &eA location for that hologram has not been set." Removed: Message: "&bSkyBlock &8| &aInfo&8: &eYou have removed the '&b%type&e' hologram." + RefreshHolograms: + Info: + Message: "&f&oRefreshes any existing holograms." + Refreshed: + Message: "&bSkyBlock &8| &aInfo&8: &eRefreshed holograms." SetSize: Info: Message: "&f&oSets the size of a players Island." diff --git a/src/main/resources/levelling.yml b/src/main/resources/levelling.yml index 4d913ec5..f2076731 100644 --- a/src/main/resources/levelling.yml +++ b/src/main/resources/levelling.yml @@ -25,7 +25,6 @@ Materials: ACACIA_STAIRS: Points: 2 ACACIA_TRAPDOOR: - Points: 3 ACACIA_WOOD: Points: 1 ACTIVATOR_RAIL: @@ -1010,6 +1009,120 @@ Materials: Points: 1 SPAWNER: Points: 10 + SPAWNER_BAT: + Points: 10 + SPAWNER_BLAZE: + Points: 10 + SPAWNER_CAVE_SPIDER: + Points: 10 + SPAWNER_CHICKEN: + Points: 10 + SPAWNER_COD: + Points: 10 + SPAWNER_COW: + Points: 10 + SPAWNER_CREEPER: + Points: 10 + SPAWNER_DOLPHIN: + Points: 10 + SPAWNER_DONKEY: + Points: 10 + SPAWNER_DROWNED: + Points: 10 + SPAWNER_ELDER_GUARDIAN: + Points: 10 + SPAWNER_ENDER_DRAGON: + Points: 10 + SPAWNER_ENDERMAN: + Points: 10 + SPAWNER_ENDERMITE: + Points: 10 + SPAWNER_EVOKER: + Points: 10 + SPAWNER_GHAST: + Points: 10 + SPAWNER_GIANT: + Points: 10 + SPAWNER_GUARDIAN: + Points: 10 + SPAWNER_HORSE: + Points: 10 + SPAWNER_HUSK: + Points: 10 + SPAWNER_ILLUSIONER: + Points: 10 + SPAWNER_IRON_GOLEM: + Points: 10 + SPAWNER_LLAMA: + Points: 10 + SPAWNER_MAGMA_CUBE: + Points: 10 + SPAWNER_MULE: + Points: 10 + SPAWNER_MUSHROOM_COW: + Points: 10 + SPAWNER_OCELOT: + Points: 10 + SPAWNER_PARROT: + Points: 10 + SPAWNER_PHANTOM: + Points: 10 + SPAWNER_PIG: + Points: 10 + SPAWNER_PIG_ZOMBIE: + Points: 10 + SPAWNER_POLAR_BEAR: + Points: 10 + SPAWNER_PUFFERFISH: + Points: 10 + SPAWNER_RABBIT: + Points: 10 + SPAWNER_SALMON: + Points: 10 + SPAWNER_SHEEP: + Points: 10 + SPAWNER_SHULKER: + Points: 10 + SPAWNER_SILVERFISH: + Points: 10 + SPAWNER_SKELETON: + Points: 10 + SPAWNER_SKELETON_HORSE: + Points: 10 + SPAWNER_SLIME: + Points: 10 + SPAWNER_SNOWMAN: + Points: 10 + SPAWNER_SPIDER: + Points: 10 + SPAWNER_SQUID: + Points: 10 + SPAWNER_STRAY: + Points: 10 + SPAWNER_TROPICAL_FISH: + Points: 10 + SPAWNER_TURTLE: + Points: 10 + SPAWNER_VEX: + Points: 10 + SPAWNER_VILLAGER: + Points: 10 + SPAWNER_VINDICATOR: + Points: 10 + SPAWNER_WITCH: + Points: 10 + SPAWNER_WITHER: + Points: 10 + SPAWNER_WITHER_SKELETON: + Points: 10 + SPAWNER_WOLF: + Points: 10 + SPAWNER_ZOMBIE: + Points: 10 + SPAWNER_ZOMBIE_HORSE: + Points: 10 + SPAWNER_ZOMBIE_VILLAGER: + Points: 10 SPONGE: Points: 10 SPRUCE_BUTTON: diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 03b5f733..8f878b3f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,12 +4,11 @@ version: maven-version-number api-version: 1.13 description: A unique SkyBlock plugin author: Songoda -softdepend: [PlaceholderAPI, MVdWPlaceholderAPI, Vault, LeaderHeads] +softdepend: [PlaceholderAPI, MVdWPlaceholderAPI, Vault, LeaderHeads, WildStacker] loadbefore: [Multiverse-Core] commands: island: description: Island command aliases: [is] - skyblock: - description: Skyblock info command. \ No newline at end of file + description: Skyblock info command.