2022-03-28 18:04:15 +02:00
|
|
|
package world.bentobox.limits.commands.player;
|
2019-02-09 19:07:16 +01:00
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2021-03-07 18:20:28 +01:00
|
|
|
import org.bukkit.Bukkit;
|
2019-02-09 19:07:16 +01:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.World;
|
2021-03-07 18:20:28 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2019-02-09 19:07:16 +01:00
|
|
|
|
2021-03-07 18:20:28 +01:00
|
|
|
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
2020-09-08 00:05:51 +02:00
|
|
|
import world.bentobox.bentobox.api.panels.builders.TabbedPanelBuilder;
|
2019-02-09 19:07:16 +01:00
|
|
|
import world.bentobox.bentobox.api.user.User;
|
|
|
|
import world.bentobox.bentobox.database.objects.Island;
|
2019-12-16 16:47:51 +01:00
|
|
|
import world.bentobox.limits.Limits;
|
|
|
|
import world.bentobox.limits.objects.IslandBlockCount;
|
2019-02-09 19:07:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows a panel of the blocks that are limited and their status
|
|
|
|
* @author tastybento
|
|
|
|
*
|
|
|
|
*/
|
2019-03-17 22:54:00 +01:00
|
|
|
public class LimitPanel {
|
2019-02-09 19:07:16 +01:00
|
|
|
|
2019-02-09 19:30:02 +01:00
|
|
|
private final Limits addon;
|
2019-02-09 19:07:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param addon - limit addon
|
|
|
|
*/
|
|
|
|
public LimitPanel(Limits addon) {
|
|
|
|
this.addon = addon;
|
|
|
|
}
|
|
|
|
|
2021-03-07 18:20:28 +01:00
|
|
|
/**
|
|
|
|
* Show the limits panel
|
|
|
|
* @param gm - game mode
|
|
|
|
* @param user - user asking
|
|
|
|
* @param target - target uuid
|
|
|
|
*/
|
|
|
|
public void showLimits(GameModeAddon gm, User user, UUID target) {
|
|
|
|
// Get world
|
|
|
|
World world = gm.getOverWorld();
|
2019-02-09 19:07:16 +01:00
|
|
|
// Get the island for the target
|
|
|
|
Island island = addon.getIslands().getIsland(world, target);
|
|
|
|
if (island == null) {
|
2019-02-09 20:13:20 +01:00
|
|
|
if (user.getUniqueId().equals(target)) {
|
|
|
|
user.sendMessage("general.errors.no-island");
|
|
|
|
} else {
|
|
|
|
user.sendMessage("general.errors.player-has-no-island");
|
|
|
|
}
|
2019-02-09 19:07:16 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-03-07 18:20:28 +01:00
|
|
|
// See if the target is online
|
|
|
|
Player targetPlayer = Bukkit.getPlayer(target);
|
|
|
|
if (targetPlayer != null) {
|
|
|
|
// Update perms
|
2021-03-27 16:39:12 +01:00
|
|
|
addon.getJoinListener().checkPerms(targetPlayer, gm.getPermissionPrefix() + "island.limit.", island.getUniqueId(), gm.getDescription().getName());
|
2021-03-07 18:20:28 +01:00
|
|
|
}
|
2020-09-08 00:05:51 +02:00
|
|
|
// Get the limits for this island
|
2019-02-09 19:07:16 +01:00
|
|
|
IslandBlockCount ibc = addon.getBlockLimitListener().getIsland(island.getUniqueId());
|
|
|
|
Map<Material, Integer> matLimits = addon.getBlockLimitListener().getMaterialLimits(world, island.getUniqueId());
|
2019-05-05 06:28:40 +02:00
|
|
|
if (matLimits.isEmpty() && addon.getSettings().getLimits().isEmpty()) {
|
2019-02-09 19:07:16 +01:00
|
|
|
user.sendMessage("island.limits.no-limits");
|
|
|
|
return;
|
|
|
|
}
|
2019-09-11 04:01:39 +02:00
|
|
|
|
2020-09-08 00:05:51 +02:00
|
|
|
new TabbedPanelBuilder()
|
|
|
|
.user(user)
|
|
|
|
.world(world)
|
|
|
|
.tab(0, new LimitTab(addon, ibc, matLimits, island, world, user, LimitTab.SORT_BY.A2Z))
|
|
|
|
.tab(1, new LimitTab(addon, ibc, matLimits, island, world, user, LimitTab.SORT_BY.Z2A))
|
|
|
|
.startingSlot(0)
|
|
|
|
.size(54)
|
|
|
|
.build().openPanel();
|
2019-02-09 19:07:16 +01:00
|
|
|
|
2020-06-21 19:50:46 +02:00
|
|
|
}
|
2020-09-08 00:05:51 +02:00
|
|
|
|
2019-02-09 19:07:16 +01:00
|
|
|
}
|