Skip to content

Commit

Permalink
Fix breaking trashcans
Browse files Browse the repository at this point in the history
  • Loading branch information
duranaaron committed Dec 26, 2024
1 parent 2f58b84 commit 80f190c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/main/java/nl/openminetopia/api/player/PlayerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public static PlayerManager getInstance() {
private final Map<UUID, MinetopiaPlayer> onlinePlayers = new ConcurrentHashMap<>();


public MinetopiaPlayer getOnlineMinetopiaPlayer(UUID uuid) {
return onlinePlayers.get(uuid);
}

public CompletableFuture<MinetopiaPlayer> getMinetopiaPlayer(OfflinePlayer player) {
CompletableFuture<MinetopiaPlayer> future = new CompletableFuture<>();
getMinetopiaPlayerAsync(player, future::complete, future::completeExceptionally);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public void bankingInteraction(PlayerInteractEvent event) {
Material material = block.getType();

BankingConfiguration bankingConfiguration = OpenMinetopia.getBankingConfiguration();

if(!bankingConfiguration.getAtmMaterials().contains(material)) return;
new BankTypeSelectionMenu(player).open(player);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import nl.openminetopia.api.player.PlayerManager;
import nl.openminetopia.configuration.MessageConfiguration;
import nl.openminetopia.utils.ChatUtils;
import org.bukkit.GameMode;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerInteractEvent;

Expand All @@ -17,8 +20,10 @@ public class PlayerInteractListener implements Listener {
public void onPlayerInteract(PlayerInteractEvent event) {
Block block = event.getClickedBlock();
if (block == null) return;
Player player = event.getPlayer();

if (!OpenMinetopia.getDefaultConfiguration().getTrashcanBlocks().contains(block.getType())) return;
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && player.getGameMode() == GameMode.CREATIVE) return;

event.setCancelled(true);

Expand All @@ -28,10 +33,13 @@ public void onPlayerInteract(PlayerInteractEvent event) {
new TrashcanMenu(InventoryType.DROPPER).open(event.getPlayer());
}

PlayerManager.getInstance().getMinetopiaPlayerAsync(event.getPlayer(), minetopiaPlayer -> {
if (minetopiaPlayer == null) return;
PlayerManager.getInstance().getMinetopiaPlayer(player).whenComplete(((minetopiaPlayer, throwable) -> {
if (throwable != null) {
throwable.printStackTrace();
return;
}
ChatUtils.sendFormattedMessage(minetopiaPlayer, MessageConfiguration.message("trashcan_message"));
}, Throwable::printStackTrace);
}));
}

private static class TrashcanMenu extends Menu {
Expand Down

0 comments on commit 80f190c

Please sign in to comment.