From d4ee11153def32c962cda58405e0707043be0a49 Mon Sep 17 00:00:00 2001 From: Skullian <133133667+Skullians@users.noreply.github.com> Date: Wed, 2 Oct 2024 22:20:41 +0100 Subject: [PATCH] fixed block explode + duplicate name in F Create --- .../faction/cmds/FactionCreateCommand.java | 35 ++++++++++++------- .../event/ObeliskInteractionListener.java | 21 ++++++----- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/main/java/net/skullian/torrent/skyfactions/command/faction/cmds/FactionCreateCommand.java b/src/main/java/net/skullian/torrent/skyfactions/command/faction/cmds/FactionCreateCommand.java index fb4d92cd..f1024203 100644 --- a/src/main/java/net/skullian/torrent/skyfactions/command/faction/cmds/FactionCreateCommand.java +++ b/src/main/java/net/skullian/torrent/skyfactions/command/faction/cmds/FactionCreateCommand.java @@ -55,20 +55,31 @@ public void perform(Player player, String[] args) { } else if (FactionAPI.getFaction(name) != null) { Messages.FACTION_CREATION_NAME_DUPLICATE.send(player); } else { - if (FactionAPI.hasValidName(player, name)) { - int cost = Settings.FACTION_CREATION_COST.getInt(); - if (cost > 0) { - if (!SkyFactionsReborn.ec.hasEnoughMoney(player, cost)) { - Messages.FACTION_INSUFFICIENT_FUNDS.send(player, "%creation_cost%", cost); - return; - } - - SkyFactionsReborn.ec.economy.withdrawPlayer(player, cost); - ; + FactionAPI.getFaction(name).whenComplete((faction, exc) -> { + if (exc != null) { + ErrorHandler.handleError(player, "get the Faction", "SQL_FACTION_GET", exc); + return; } - FactionAPI.createFaction(player, name); - } + if (faction != null) { + Messages.FACTION_CREATION_NAME_DUPLICATE.send(player); + } else { + if (FactionAPI.hasValidName(player, name)) { + int cost = Settings.FACTION_CREATION_COST.getInt(); + if (cost > 0) { + if (!SkyFactionsReborn.ec.hasEnoughMoney(player, cost)) { + Messages.FACTION_INSUFFICIENT_FUNDS.send(player, "%creation_cost%", cost); + return; + } + + SkyFactionsReborn.ec.economy.withdrawPlayer(player, cost); + ; + } + + FactionAPI.createFaction(player, name); + } + } + }); } }); } diff --git a/src/main/java/net/skullian/torrent/skyfactions/event/ObeliskInteractionListener.java b/src/main/java/net/skullian/torrent/skyfactions/event/ObeliskInteractionListener.java index f56fd1e1..f9229d06 100644 --- a/src/main/java/net/skullian/torrent/skyfactions/event/ObeliskInteractionListener.java +++ b/src/main/java/net/skullian/torrent/skyfactions/event/ObeliskInteractionListener.java @@ -7,7 +7,6 @@ import net.skullian.torrent.skyfactions.config.types.ObeliskConfig; import net.skullian.torrent.skyfactions.gui.obelisk.FactionObeliskUI; import net.skullian.torrent.skyfactions.gui.obelisk.PlayerObeliskUI; -import net.skullian.torrent.skyfactions.util.SLogger; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.block.Block; @@ -28,18 +27,18 @@ public class ObeliskInteractionListener implements Listener { @EventHandler public void onBlockExplode(BlockExplodeEvent event) { - SLogger.fatal("EXPLODED: " + event.getBlock()); - if (!event.getBlock().getType().equals(Material.getMaterial(ObeliskConfig.OBELISK_MATERIAL.getString())) || !event.getBlock().getType().equals(Material.BARRIER)) - return; + for (Block block : event.blockList()) { + if (!block.getType().equals(Material.getMaterial(ObeliskConfig.OBELISK_MATERIAL.getString())) && !block.getType().equals(Material.BARRIER)) + continue; - Block block = event.getBlock(); - PersistentDataContainer container = new CustomBlockData(block, SkyFactionsReborn.getInstance()); - NamespacedKey typeKey = new NamespacedKey(SkyFactionsReborn.getInstance(), "obelisk_type"); - NamespacedKey ownerKey = new NamespacedKey(SkyFactionsReborn.getInstance(), "obelisk_owner"); - if (!container.has(typeKey, PersistentDataType.STRING) || !container.has(ownerKey, PersistentDataType.STRING)) - return; + PersistentDataContainer container = new CustomBlockData(block, SkyFactionsReborn.getInstance()); + NamespacedKey typeKey = new NamespacedKey(SkyFactionsReborn.getInstance(), "obelisk_type"); + NamespacedKey ownerKey = new NamespacedKey(SkyFactionsReborn.getInstance(), "obelisk_owner"); + if (!container.has(typeKey, PersistentDataType.STRING) || !container.has(ownerKey, PersistentDataType.STRING)) + return; - event.setCancelled(true); + event.blockList().remove(block); + } } @EventHandler