mirror of
https://github.com/BentoBoxWorld/Limits.git
synced 2025-02-26 17:21:21 +01:00
Make island owner the setter of limits
This commit is contained in:
parent
923ce3ad17
commit
e317f27869
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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)) {
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user