diff --git a/src/main/java/de/fanta/challenges/guis/settingsgui/SettingsGui.java b/src/main/java/de/fanta/challenges/guis/settingsgui/SettingsGui.java index fc3f64b..cc1bdef 100644 --- a/src/main/java/de/fanta/challenges/guis/settingsgui/SettingsGui.java +++ b/src/main/java/de/fanta/challenges/guis/settingsgui/SettingsGui.java @@ -17,9 +17,8 @@ public class SettingsGui implements Listener { - private static final Challenges plugin = Challenges.getPlugin(); - public static final int INVENTORY_SIZE = 54; + private static final Challenges plugin = Challenges.getPlugin(); public static final Inventory SETTINGS_GUI = Bukkit.createInventory(null, INVENTORY_SIZE, plugin.getGUIPREFIX() + " >> Challenges"); private static final int CRAFTING_TABLE_INDEX = 0; @@ -369,21 +368,23 @@ } break; case WORLD_BORDER_LEVEL_INDEX: + if (plugin.getServer().getServicesManager().getRegistration(WorldBorderApi.class) == null) { + return; + } RegisteredServiceProvider worldBorderAPI = plugin.getServer().getServicesManager().getRegistration(WorldBorderApi.class); + if (worldBorderAPI == null) { + return; + } if (plugin.getConfig().getBoolean("worldborderlevel")) { GUIUtils.setConfig("worldborderlevel", false); for (Player pp : Bukkit.getOnlinePlayers()) { - if (worldBorderAPI != null) { - worldBorderAPI.getProvider().resetWorldBorderToGlobal(pp); - } + worldBorderAPI.getProvider().resetWorldBorderToGlobal(pp); } GUIUtils.sendTitleToAll("Challenge", "World Border Level deaktiviert", ChatUtil.RED); } else { GUIUtils.setConfig("worldborderlevel", true); for (Player pp : Bukkit.getOnlinePlayers()) { - if (worldBorderAPI != null) { - worldBorderAPI.getProvider().setBorder(pp, 1, plugin.getServer().getWorld("world").getSpawnLocation()); - } + worldBorderAPI.getProvider().setBorder(pp, 1, plugin.getServer().getWorld("world").getSpawnLocation()); } for (Player pp : Bukkit.getOnlinePlayers()) { diff --git a/src/main/java/de/fanta/challenges/listeners/BlockDestroyListener.java b/src/main/java/de/fanta/challenges/listeners/BlockDestroyListener.java index 0e0f37d..0913e83 100644 --- a/src/main/java/de/fanta/challenges/listeners/BlockDestroyListener.java +++ b/src/main/java/de/fanta/challenges/listeners/BlockDestroyListener.java @@ -3,6 +3,7 @@ import de.fanta.challenges.Challenges; import de.fanta.challenges.utils.ItemTypeListUtil; import de.iani.cubesideutils.bukkit.items.ItemGroups; +import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.block.Block; @@ -14,39 +15,48 @@ public class BlockDestroyListener implements Listener { - private final Challenges plugin = Challenges.getPlugin(); - - @EventHandler - public void onBlockBreak(BlockBreakEvent e) { - if ((!plugin.getTimer().isRunning()) && e.getPlayer().getGameMode() == GameMode.SURVIVAL) { - e.setCancelled(true); - } - if (plugin.getConfig().getString("event.type").equals("build") && plugin.getTimer().isRunning()) { - Material blockType = e.getBlock().getType(); - if (!ItemTypeListUtil.isInstaBreakBlock(blockType) && !ItemGroups.isDoubleBlockPlant(blockType) && !ItemGroups.isSingleBlockPlant(blockType)) { - plugin.getScoreManager().updateScore(e.getPlayer(), 1); - } - } - } + private final Challenges plugin = Challenges.getPlugin(); - @EventHandler - public void onBlockDrop(BlockDropItemEvent e) { - if (plugin.getConfig().getBoolean("silkore")) { - Block block = e.getBlock(); - Material dropType = switch (e.getBlockState().getType()) { - case IRON_ORE, DEEPSLATE_IRON_ORE -> Material.IRON_INGOT; - case GOLD_ORE, DEEPSLATE_GOLD_ORE -> Material.GOLD_INGOT; - case COPPER_ORE, DEEPSLATE_COPPER_ORE -> Material.COPPER_INGOT; - default -> null; - }; - if(dropType != null) { - e.getItems().forEach(item -> block.getLocation().getWorld().dropItem(block.getLocation().add(0.5D, 0.5D, 0.5D), new ItemStack(dropType, item.getItemStack().getAmount()))); - e.setCancelled(true); - } - } - } + @EventHandler + public void onBlockBreak(BlockBreakEvent e) { + if ((!plugin.getTimer().isRunning()) && e.getPlayer().getGameMode() == GameMode.SURVIVAL) { + e.setCancelled(true); + } + if (plugin.getConfig().getString("event.type").equals("build") && plugin.getTimer().isRunning()) { + Material blockType = e.getBlock().getType(); + if (!ItemTypeListUtil.isInstaBreakBlock(blockType) && !ItemGroups.isDoubleBlockPlant(blockType) && !ItemGroups.isSingleBlockPlant(blockType)) { + plugin.getScoreManager().updateScore(e.getPlayer(), 1); + } + } + } + @EventHandler + public void onBlockDrop(BlockDropItemEvent e) { + if (plugin.getConfig().getBoolean("silkore")) { + Block block = e.getBlock(); + int minecraftVersion = Integer.parseInt(Bukkit.getMinecraftVersion().replace(".", "")); + Material dropType; + if (minecraftVersion > 1179) { + dropType = switch (e.getBlockState().getType()) { + case IRON_ORE, DEEPSLATE_IRON_ORE -> Material.IRON_INGOT; + case GOLD_ORE, DEEPSLATE_GOLD_ORE -> Material.GOLD_INGOT; + case COPPER_ORE, DEEPSLATE_COPPER_ORE -> Material.COPPER_INGOT; + default -> null; + }; + } else { + dropType = switch (e.getBlockState().getType()) { + case IRON_ORE -> Material.IRON_INGOT; + case GOLD_ORE -> Material.GOLD_INGOT; + default -> null; + }; + } + if (dropType != null) { + e.getItems().forEach(item -> block.getLocation().getWorld().dropItem(block.getLocation().add(0.5D, 0.5D, 0.5D), new ItemStack(dropType, item.getItemStack().getAmount()))); + e.setCancelled(true); + } + } + } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e085166..0d6fd3f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,8 +3,8 @@ version: ${project.version} api-version: 1.18 author: ${project.author} -depend: [CubesideUtils, VanishNoPacket, GlobalPort, CubesideNMSUtils, WorldBorderAPI] -softdepend: [NBTAPI] +depend: [CubesideUtils, VanishNoPacket, GlobalPort, CubesideNMSUtils, ViaVersion] +softdepend: [NBTAPI, WorldBorderAPI] commands: hp: description: Verwalte die HP eines Spielers