Skip to content

Commit

Permalink
fixed block explode + duplicate name in F Create
Browse files Browse the repository at this point in the history
  • Loading branch information
Skullians committed Oct 2, 2024
1 parent 1ee3ff0 commit d4ee111
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit d4ee111

Please sign in to comment.