merge with upstream
This commit is contained in:
commit
d2b1a0527d
6
pom.xml
6
pom.xml
|
@ -57,14 +57,14 @@
|
|||
<!-- Non-minecraft related dependencies -->
|
||||
<powermock.version>2.0.2</powermock.version>
|
||||
<!-- More visible way how to change dependency versions -->
|
||||
<spigot.version>1.13.2-R0.1-SNAPSHOT</spigot.version>
|
||||
<bentobox.version>1.9.0</bentobox.version>
|
||||
<spigot.version>1.15.2-R0.1-SNAPSHOT</spigot.version>
|
||||
<bentobox.version>1.14.0-SNAPSHOT</bentobox.version>
|
||||
<!-- Revision variable removes warning about dynamic version -->
|
||||
<revision>${build.version}-SNAPSHOT</revision>
|
||||
<!-- Do not change unless you want different name for local builds. -->
|
||||
<build.number>-LOCAL</build.number>
|
||||
<!-- This allows to change between versions. -->
|
||||
<build.version>1.9.5</build.version>
|
||||
<build.version>1.14.0</build.version>
|
||||
</properties>
|
||||
|
||||
<!-- Profiles will allow to automatically change build version. -->
|
||||
|
|
|
@ -2,6 +2,7 @@ package world.bentobox.limits;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
|
@ -109,7 +110,7 @@ public class Settings {
|
|||
* @return the limits
|
||||
*/
|
||||
public Map<EntityType, Integer> getLimits() {
|
||||
return limits;
|
||||
return Collections.unmodifiableMap(limits);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package world.bentobox.limits.commands;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
|
@ -109,7 +110,7 @@ public class LimitPanel {
|
|||
pb.item(pib.build());
|
||||
}
|
||||
// Entity limits
|
||||
Map<EntityType, Integer> map = addon.getSettings().getLimits();
|
||||
Map<EntityType, Integer> map = new HashMap<>(addon.getSettings().getLimits());
|
||||
// Merge in any permission-based limits
|
||||
if (ibc != null) ibc.getEntityLimits().forEach(map::put);
|
||||
map.forEach((k,v) -> {
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
package world.bentobox.limits.commands;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -33,9 +38,20 @@ public class LimitsCalc {
|
|||
private final User sender;
|
||||
private final Set<Pair<Integer, Integer>> chunksToScan;
|
||||
private int count;
|
||||
private int chunksToScanCount;
|
||||
private BentoBox plugin;
|
||||
|
||||
|
||||
/**
|
||||
* Perform a count of all limited blocks or entities on an island
|
||||
* @param world - game world to scan
|
||||
* @param instance - BentoBox
|
||||
* @param targetPlayer - target player's island
|
||||
* @param addon - addon instance
|
||||
* @param sender - requester of the count
|
||||
*/
|
||||
LimitsCalc(World world, BentoBox instance, UUID targetPlayer, Limits addon, User sender) {
|
||||
this.plugin = instance;
|
||||
this.addon = addon;
|
||||
this.island = instance.getIslands().getIsland(world, targetPlayer);
|
||||
this.bll = addon.getBlockLimitListener();
|
||||
|
@ -47,19 +63,36 @@ public class LimitsCalc {
|
|||
// Get chunks to scan
|
||||
chunksToScan = getChunksToScan(island);
|
||||
count = 0;
|
||||
chunksToScan.forEach(c -> Util.getChunkAtAsync(world, c.x, c.z).thenAccept(ch -> {
|
||||
|
||||
boolean isNether = plugin.getIWM().isNetherGenerate(world) && plugin.getIWM().isNetherIslands(world);
|
||||
boolean isEnd = plugin.getIWM().isEndGenerate(world) && plugin.getIWM().isEndIslands(world);
|
||||
// Calculate how many chunks need to be scanned
|
||||
chunksToScanCount = chunksToScan.size() + (isNether ? chunksToScan.size():0) + (isEnd ? chunksToScan.size():0);
|
||||
chunksToScan.forEach(c -> {
|
||||
asyncScan(world, c);
|
||||
if (isNether) asyncScan(plugin.getIWM().getNetherWorld(world), c);
|
||||
if (isEnd) asyncScan(plugin.getIWM().getEndWorld(world), c);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void asyncScan(World world2, Pair<Integer, Integer> c) {
|
||||
Util.getChunkAtAsync(world2, c.x, c.z).thenAccept(ch -> {
|
||||
ChunkSnapshot snapShot = ch.getChunkSnapshot();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(addon.getPlugin(), () -> {
|
||||
this.scanChunk(snapShot);
|
||||
count++;
|
||||
if (count == chunksToScan.size()) {
|
||||
if (count == chunksToScanCount) {
|
||||
this.tidyUp();
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void scanChunk(ChunkSnapshot chunk) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
// Check if the block coordinate is inside the protection zone and if not, don't count it
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
package world.bentobox.limits.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import world.bentobox.bentobox.api.events.BentoBoxEvent;
|
||||
import world.bentobox.limits.objects.IslandBlockCount;
|
||||
|
||||
/**
|
||||
* Fired when a player joins the server and before limit settings for their island are changed based
|
||||
* on the player's permissions. If cancelled, no limit settings will be made.
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class LimitsJoinPermCheckEvent extends BentoBoxEvent implements Cancellable {
|
||||
|
||||
private final Player player;
|
||||
private final String islandId;
|
||||
private IslandBlockCount ibc;
|
||||
private boolean cancel;
|
||||
private boolean ignorePerms;
|
||||
|
||||
/**
|
||||
* Fired when a player joins the server and before limit settings for their island are changed based
|
||||
* on the player's permissions. If cancelled, no limit settings will be made.
|
||||
* @param player - player joining
|
||||
* @param islandId - the unique island id.
|
||||
* @param ibc - IslandBlockCount object for this island
|
||||
*/
|
||||
public LimitsJoinPermCheckEvent(@NonNull Player player, @NonNull String islandId, @Nullable IslandBlockCount ibc) {
|
||||
super();
|
||||
this.player = player;
|
||||
this.islandId = islandId;
|
||||
this.ibc = ibc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the player joining
|
||||
* @return the player
|
||||
*/
|
||||
@NonNull
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the unique island id. Use the islands manager to obtain the island
|
||||
* @return the islandId
|
||||
*/
|
||||
@NonNull
|
||||
public String getIslandId() {
|
||||
return islandId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the island block count
|
||||
* @return the ibc
|
||||
*/
|
||||
@Nullable
|
||||
public IslandBlockCount getIbc() {
|
||||
return ibc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the island block count to a specific setting
|
||||
* @param ibc the ibc to set
|
||||
*/
|
||||
public void setIbc(@Nullable IslandBlockCount ibc) {
|
||||
this.ibc = ibc;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancel = cancel;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if player's perms should be considered or not
|
||||
* @return the ignorePerms
|
||||
*/
|
||||
public boolean isIgnorePerms() {
|
||||
return ignorePerms;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ignore player's perms. This differs to canceling the event in that the IslandBlockCount will be used if given via
|
||||
* {@link setIbc(IslandBlockCount ibc)}
|
||||
* @param ignorePerms the ignorePerms to set
|
||||
*/
|
||||
public void setIgnorePerms(boolean ignorePerms) {
|
||||
this.ignorePerms = ignorePerms;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -146,7 +146,7 @@ public class BlockLimitsListener implements Listener {
|
|||
* Save the count database completely
|
||||
*/
|
||||
public void save() {
|
||||
islandCountMap.values().forEach(handler::saveObject);
|
||||
islandCountMap.values().forEach(handler::saveObjectAsync);
|
||||
}
|
||||
|
||||
// Player-related events
|
||||
|
@ -349,7 +349,7 @@ public class BlockLimitsListener implements Listener {
|
|||
}
|
||||
}
|
||||
if (saveMap.get(id) > CHANGE_LIMIT) {
|
||||
handler.saveObject(islandCountMap.get(id));
|
||||
handler.saveObjectAsync(islandCountMap.get(id));
|
||||
saveMap.remove(id);
|
||||
}
|
||||
return -1;
|
||||
|
@ -428,7 +428,7 @@ public class BlockLimitsListener implements Listener {
|
|||
*/
|
||||
public void setIsland(String islandId, IslandBlockCount ibc) {
|
||||
islandCountMap.put(islandId, ibc);
|
||||
handler.saveObject(ibc);
|
||||
handler.saveObjectAsync(ibc);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,6 +24,7 @@ import world.bentobox.bentobox.api.events.team.TeamEvent.TeamSetownerEvent;
|
|||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.limits.Limits;
|
||||
import world.bentobox.limits.Settings.EntityGroup;
|
||||
import world.bentobox.limits.events.LimitsJoinPermCheckEvent;
|
||||
import world.bentobox.limits.objects.IslandBlockCount;
|
||||
|
||||
/**
|
||||
|
@ -41,6 +42,18 @@ public class JoinListener implements Listener {
|
|||
|
||||
private void checkPerms(Player player, String permissionPrefix, String islandId, String gameMode) {
|
||||
IslandBlockCount ibc = addon.getBlockLimitListener().getIsland(islandId);
|
||||
// Fire event, so other addons can cancel this permissions change
|
||||
LimitsJoinPermCheckEvent e = new LimitsJoinPermCheckEvent(player, gameMode, ibc);
|
||||
Bukkit.getPluginManager().callEvent(e);
|
||||
if (e.isCancelled()) return;
|
||||
// Get ibc from event if it has changed
|
||||
ibc = e.getIbc();
|
||||
// If perms should be ignored, but the IBC given in the event used, then set it and return
|
||||
if (e.isIgnorePerms() && ibc != null) {
|
||||
addon.getBlockLimitListener().setIsland(islandId, ibc);
|
||||
return;
|
||||
}
|
||||
// Check permissions
|
||||
if (ibc != null) {
|
||||
// Clear permission limits
|
||||
ibc.getEntityLimits().clear();
|
||||
|
@ -68,7 +81,7 @@ public class JoinListener implements Listener {
|
|||
// Entities & materials
|
||||
EntityType et = Arrays.stream(EntityType.values()).filter(t -> t.name().equalsIgnoreCase(split[3])).findFirst().orElse(null);
|
||||
Material m = Arrays.stream(Material.values()).filter(t -> t.name().equalsIgnoreCase(split[3])).findFirst().orElse(null);
|
||||
EntityGroup entgroup = addon.getSettings().getGroupLimitDefinitions().stream().filter(e -> e.getName().equalsIgnoreCase(split[3])).findFirst().orElse(null);
|
||||
EntityGroup entgroup = addon.getSettings().getGroupLimitDefinitions().stream().filter(t -> t.getName().equalsIgnoreCase(split[3])).findFirst().orElse(null);
|
||||
|
||||
if (entgroup == null && et == null && m == null) {
|
||||
logError(player.getName(), perms.getPermission(), split[3].toUpperCase(Locale.ENGLISH) + " is not a valid material or entity type/group.");
|
||||
|
@ -133,7 +146,7 @@ public class JoinListener implements Listener {
|
|||
// Check if player has any islands in the game modes
|
||||
addon.getGameModes().forEach(gm -> {
|
||||
if (addon.getIslands().hasIsland(gm.getOverWorld(), e.getPlayer().getUniqueId())) {
|
||||
String islandId = addon.getIslands().getIsland(gm.getOverWorld(), e.getPlayer().getUniqueId()).getUniqueId();
|
||||
String islandId = Objects.requireNonNull(addon.getIslands().getIsland(gm.getOverWorld(), e.getPlayer().getUniqueId())).getUniqueId();
|
||||
checkPerms(e.getPlayer(), gm.getPermissionPrefix() + "island.limit.", islandId, gm.getDescription().getName());
|
||||
}
|
||||
});
|
||||
|
|
|
@ -7,11 +7,13 @@ import java.util.UUID;
|
|||
import com.google.gson.annotations.Expose;
|
||||
|
||||
import world.bentobox.bentobox.database.objects.DataObject;
|
||||
import world.bentobox.bentobox.database.objects.Table;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@Table(name = "EntityLimits")
|
||||
public class EntityLimitsDO implements DataObject {
|
||||
|
||||
@Expose
|
||||
|
|
|
@ -10,11 +10,13 @@ import org.bukkit.entity.EntityType;
|
|||
import com.google.gson.annotations.Expose;
|
||||
|
||||
import world.bentobox.bentobox.database.objects.DataObject;
|
||||
import world.bentobox.bentobox.database.objects.Table;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@Table(name = "IslandBlockCount")
|
||||
public class IslandBlockCount implements DataObject {
|
||||
|
||||
@Expose
|
||||
|
@ -178,7 +180,7 @@ public class IslandBlockCount implements DataObject {
|
|||
public void setEntityLimits(Map<EntityType, Integer> entityLimits) {
|
||||
this.entityLimits = entityLimits;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set an island-specific entity type limit
|
||||
* @param t - entity type
|
||||
|
@ -187,7 +189,7 @@ public class IslandBlockCount implements DataObject {
|
|||
public void setEntityLimit(EntityType t, int limit) {
|
||||
entityLimits.put(t, limit);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the limit for an entity type
|
||||
* @param t - entity type
|
||||
|
@ -196,7 +198,7 @@ public class IslandBlockCount implements DataObject {
|
|||
public int getEntityLimit(EntityType t) {
|
||||
return entityLimits.getOrDefault(t, -1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear all island-specific entity type limits
|
||||
*/
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
name: Limits
|
||||
main: world.bentobox.limits.Limits
|
||||
version: ${version}${build.number}
|
||||
api-version: 1.14
|
||||
|
||||
authors: tastybento
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# This is a YML file. Be careful when editing. Check your edits in a YAML checker like #
|
||||
# the one at http://yaml-online-parser.appspot.com #
|
||||
block-limits:
|
||||
hit-limit: '&c[material] limitowany do [number]!'
|
||||
entity-limits:
|
||||
hit-limit: '&cSpawnowanie [entity] limitowane do [number]!'
|
||||
limits:
|
||||
panel-title: Limity wysp
|
||||
admin:
|
||||
limits:
|
||||
main:
|
||||
parameters: <gracz>
|
||||
description: pokazuje limity wysp gracza
|
||||
calc:
|
||||
parameters: <gracz>
|
||||
description: ponownie oblicza limity wyspy dla gracza
|
||||
finished: '&aPrzeliczanie zakończone!'
|
||||
island:
|
||||
limits:
|
||||
description: pokazuje limity twojej wyspy
|
||||
max-color: '&c'
|
||||
regular-color: '&a'
|
||||
block-limit-syntax: '[number]/[limit]'
|
||||
no-limits: '&cBrak ustawionych limitów.'
|
||||
recount:
|
||||
description: określa limity dla twojej wyspy
|
|
@ -1,32 +1,25 @@
|
|||
###########################################################################################
|
||||
# This is a YML file. Be careful when editing. Check your edits in a YAML checker like #
|
||||
# the one at http://yaml-online-parser.appspot.com #
|
||||
###########################################################################################
|
||||
|
||||
entity-limits:
|
||||
hit-limit: "&3&LS&b&lC &8&L» &e[entity] &4varlığından &5[number] &4tane koyabilirsin!"
|
||||
block-limits:
|
||||
hit-limit: "&3&LS&b&lC &8&L» &e[material] &4eşyasından &5[number] &4koyabilirsin!"
|
||||
limits:
|
||||
panel-title: "&3&lSon&b&lCesurlar &eAda limiti"
|
||||
|
||||
---
|
||||
admin:
|
||||
limits:
|
||||
main:
|
||||
parameters: "<player>"
|
||||
description: "Oyuncu için ada limitlerini göster."
|
||||
calc:
|
||||
parameters: "<player>"
|
||||
description: "Oyuncu için ada limitlerini tekrar hesapla."
|
||||
finished: "&aIsland recalc finished sucessfully!"
|
||||
|
||||
calc:
|
||||
description: Oyuncu için ada limitlerini tekrar hesapla.
|
||||
parameters: "<player>"
|
||||
finished: "&aAda hesaplaması başarıyla yapıldı."
|
||||
main:
|
||||
description: Oyuncu için ada limitlerini göster.
|
||||
parameters: "<player>"
|
||||
island:
|
||||
limits:
|
||||
parameters: ""
|
||||
description: "Ada limitlerini gör."
|
||||
limits:
|
||||
block-limit-syntax: "&5[number]&7/&e[limit]"
|
||||
description: Ada limitlerini gör.
|
||||
max-color: "&c"
|
||||
regular-color: "&9"
|
||||
block-limit-syntax: "&5[number]&7/&e[limit]"
|
||||
no-limits: "&3&LS&c&lC &A&L» &4Bu dünyada limitler ayarlı değil!"
|
||||
|
||||
|
||||
no-limits: "&4Bu dünyada limitler ayarlı değil!"
|
||||
recount:
|
||||
description: Ada limitlerini tekrardan hesaplar.
|
||||
block-limits:
|
||||
hit-limit: "&e[material] &4eşyasından &5[number] &4koyabilirsin!"
|
||||
entity-limits:
|
||||
hit-limit: "&e[entity] &4varlığından &5[number] &4tane koyabilirsin!"
|
||||
limits:
|
||||
panel-title: "&eAda limiti"
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.bukkit.entity.EntityType;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -73,6 +74,8 @@ public class JoinListenerTest {
|
|||
private OfflinePlayer owner;
|
||||
@Mock
|
||||
private Island island;
|
||||
@Mock
|
||||
private PluginManager pim;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
@ -110,6 +113,7 @@ public class JoinListenerTest {
|
|||
when(owner.isOnline()).thenReturn(true);
|
||||
when(owner.getPlayer()).thenReturn(player);
|
||||
when(Bukkit.getOfflinePlayer(any(UUID.class))).thenReturn(owner);
|
||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||
|
||||
// Island
|
||||
when(island.getOwner()).thenReturn(UUID.randomUUID());
|
||||
|
@ -319,7 +323,7 @@ public class JoinListenerTest {
|
|||
verify(addon, never()).logError(anyString());
|
||||
verify(ibc).setBlockLimit(eq(Material.STONE), eq(24));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.limits.listeners.JoinListener#onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent)}.
|
||||
*/
|
||||
|
@ -384,7 +388,7 @@ public class JoinListenerTest {
|
|||
when(permAtt6.getPermission()).thenReturn("bskyblock.island.limit.cave_spider.4");
|
||||
when(permAtt6.getValue()).thenReturn(false); // negative perm
|
||||
perms.add(permAtt6);
|
||||
|
||||
|
||||
when(player.getEffectivePermissions()).thenReturn(perms);
|
||||
PlayerJoinEvent e = new PlayerJoinEvent(player, "welcome");
|
||||
jl.onPlayerJoin(e);
|
||||
|
@ -425,7 +429,7 @@ public class JoinListenerTest {
|
|||
verify(ibc, never()).setBlockLimit(eq(Material.STONE), eq(14));
|
||||
verify(ibc).setBlockLimit(eq(Material.STONE), eq(34));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.limits.listeners.JoinListener#onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent)}.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue