Make island owner the setter of limits

This commit is contained in:
tastybento 2024-10-05 01:10:08 -07:00
parent 923ce3ad17
commit e317f27869
3 changed files with 190 additions and 169 deletions

View File

@ -1,10 +1,12 @@
package world.bentobox.limits.commands.player;
import java.util.List;
import java.util.Optional;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.limits.Limits;
/**
@ -46,7 +48,22 @@ public class PlayerCommand extends CompositeCommand {
showHelp(this, user);
return false;
} else {
new LimitPanel(addon).showLimits((GameModeAddon)getAddon(), user, user.getUniqueId());
// Report the limit for the island, which is governed by the owner of the island
Optional<Island> opIsland = getIslands().getIslandAt(user.getLocation());
if (opIsland.isEmpty()) {
user.sendMessage("general.errors.no-island");
return false;
}
Island island = opIsland.get();
if (!island.getWorld().equals(getWorld())) {
user.sendMessage("general.errors.wrong-world");
return false;
}
if (island.getOwner() == null) {
user.sendMessage("general.errors.no-owner");
return false;
}
new LimitPanel(addon).showLimits((GameModeAddon) getAddon(), user, island.getOwner());
return true;
}
}

View File

@ -198,6 +198,7 @@ public class JoinListener implements Listener {
// Check if player has any islands in the game modes
addon.getGameModes().forEach(gm -> {
addon.getIslands().getIslands(gm.getOverWorld(), e.getPlayer().getUniqueId()).stream()
.filter(island -> e.getPlayer().getUniqueId().equals(island.getOwner()))
.map(Island::getUniqueId).forEach(islandId -> {
IslandBlockCount ibc = addon.getBlockLimitListener().getIsland(islandId);
if (!joinEventCheck(e.getPlayer(), islandId, ibc)) {

View File

@ -25,6 +25,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.PluginManager;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -76,6 +77,7 @@ public class JoinListenerTest {
private Island island;
@Mock
private PluginManager pim;
private @Nullable UUID uuid = UUID.randomUUID();
@Before
public void setUp() {
@ -90,12 +92,13 @@ public class JoinListenerTest {
.thenReturn(new ArrayList<>(List.of(new Settings.EntityGroup("friendly", new HashSet<>(), -1))));
// Island Manager
when(island.getUniqueId()).thenReturn("unique_id");
when(island.getOwner()).thenReturn(uuid);
when(im.getIsland(any(), any(UUID.class))).thenReturn(island);
when(im.getIslands(any(), any(UUID.class))).thenReturn(List.of(island));
// Default is that player has island
when(addon.getIslands()).thenReturn(im);
// Player
when(player.getUniqueId()).thenReturn(UUID.randomUUID());
when(player.getUniqueId()).thenReturn(uuid);
when(player.getName()).thenReturn("tastybento");
// No permissions by default
when(player.getEffectivePermissions()).thenReturn(Collections.emptySet());