Skip to content

Commit

Permalink
Fixed detection of sign warps when deleting them (#1439)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Oct 29, 2022
1 parent 81bc8d2 commit a18bbfa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
Expand Up @@ -8,13 +8,17 @@
import com.bgsoftware.superiorskyblock.commands.CommandTabCompletes;
import com.bgsoftware.superiorskyblock.commands.IPermissibleCommand;
import com.bgsoftware.superiorskyblock.commands.arguments.CommandArguments;
import com.bgsoftware.superiorskyblock.core.ChunkPosition;
import com.bgsoftware.superiorskyblock.core.messages.Message;
import com.bgsoftware.superiorskyblock.island.privilege.IslandPrivileges;
import com.bgsoftware.superiorskyblock.world.chunk.ChunkLoadReason;
import com.bgsoftware.superiorskyblock.world.chunk.ChunksProvider;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -75,23 +79,30 @@ public void execute(SuperiorSkyblockPlugin plugin, SuperiorPlayer superiorPlayer
if (!plugin.getEventsBus().callIslandDeleteWarpEvent(superiorPlayer, island, islandWarp))
return;

boolean breakSign = false;

Block signBlock = islandWarp.getLocation().getBlock();

if (signBlock.getState() instanceof Sign) {
signBlock.setType(Material.AIR);
signBlock.getWorld().dropItemNaturally(signBlock.getLocation(), new ItemStack(Material.SIGN));
breakSign = true;
}

island.deleteWarp(islandWarp.getName());

Message.DELETE_WARP.send(superiorPlayer, islandWarp.getName());

if (breakSign) {
Message.DELETE_WARP_SIGN_BROKE.send(superiorPlayer);
}
ChunksProvider.loadChunk(ChunkPosition.of(islandWarp.getLocation()), ChunkLoadReason.WARP_SIGN_BREAK, chunk -> {
Block signBlock = islandWarp.getLocation().getBlock();
// We check for a sign block at the warp's location.
if (signBlock.getState() instanceof Sign) {
Sign sign = (Sign) signBlock.getState();

List<String> configSignWarp = new ArrayList<>(plugin.getSettings().getSignWarp());
configSignWarp.replaceAll(line -> line.replace("{0}", islandWarp.getName()));
String[] signLines = sign.getLines();

for (int i = 0; i < signLines.length && i < configSignWarp.size(); ++i) {
if (!signLines[i].equals(configSignWarp.get(i)))
return;
}

// Detected warp sign
signBlock.setType(Material.AIR);
signBlock.getWorld().dropItemNaturally(signBlock.getLocation(), new ItemStack(Material.SIGN));
Message.DELETE_WARP_SIGN_BROKE.send(superiorPlayer);
}
});
}

@Override
Expand Down
Expand Up @@ -8,7 +8,7 @@ public enum ChunkLoadReason {
ENTITIES_RECALCULATE,
FIND_SAFE_SPOT,
API_REQUEST,

BIOME_REQUEST
BIOME_REQUEST,
WARP_SIGN_BREAK

}

0 comments on commit a18bbfa

Please sign in to comment.