Skip to content

Commit 92308fd

Browse files
authored
Merge pull request #2765 from BentoBoxWorld/develop
Release 3.10.0
2 parents 0f659a0 + 5dd2a72 commit 92308fd

File tree

15 files changed

+1762
-1346
lines changed

15 files changed

+1762
-1346
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
<!-- Do not change unless you want different name for local builds. -->
7676
<build.number>-LOCAL</build.number>
7777
<!-- This allows to change between versions. -->
78-
<build.version>3.9.2</build.version>
78+
<build.version>3.10.0</build.version>
7979
<sonar.organization>bentobox-world</sonar.organization>
8080
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
8181
<server.jars>${project.basedir}/lib</server.jars>

src/main/java/world/bentobox/bentobox/api/commands/island/IslandGoCommand.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ private boolean checkReserved(User user, List<Island> islands) {
151151
}
152152
return false;
153153
}
154+
155+
@Override
156+
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
157+
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
158+
159+
return Optional.of(Util.tabLimit(new ArrayList<>(getNameIslandMap(user, getWorld()).keySet()), lastArg));
160+
161+
}
154162

155163
/**
156164
* Record to store island information and whether the name refers to

src/main/java/world/bentobox/bentobox/database/json/JSONDatabaseHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public List<T> loadObjects() {
5656
tableFolder.mkdirs();
5757
}
5858
// Load each object from the file system, filtered, non-null
59-
for (File file: Objects.requireNonNull(tableFolder.listFiles((dir, name) -> name.toLowerCase(Locale.ENGLISH).endsWith(JSON)))) {
59+
for (File file: Objects.requireNonNull(tableFolder.listFiles((dir, name) -> name.toLowerCase(Locale.ENGLISH).endsWith(JSON) && !name.startsWith("._")))) {
6060
try (FileReader reader = new FileReader(file)){
6161
T object = getGson().fromJson(reader, dataObject);
6262
if (object != null) {

src/main/java/world/bentobox/bentobox/database/objects/Island.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,7 @@ public boolean isPurgeProtected() {
657657
}
658658

659659
/**
660-
* Returns the island range. It is a convenience method that returns the exact
661-
* same value than island range, although it has been saved into the Island
662-
* object for easier access.
660+
* Returns the island range. Protection range can never be bigger than this.
663661
*
664662
* @return the island range
665663
* @see #getProtectionRange()
@@ -1142,6 +1140,7 @@ public void setOwner(@Nullable UUID owner) {
11421140
this.owner = owner;
11431141
if (owner == null) {
11441142
log(new LogEntry.Builder(LogType.UNOWNED).build());
1143+
setChanged();
11451144
return;
11461145
}
11471146
// Defensive code: demote any previous owner
@@ -1201,11 +1200,14 @@ public void setPurgeProtected(boolean purgeProtected) {
12011200
}
12021201

12031202
/**
1204-
* Sets the island range. This method should <u><strong>NEVER</strong></u> be
1205-
* used except for testing purposes. <br>
1203+
* Sets the island range. <br>
12061204
* The range value is a copy of {@link WorldSettings#getIslandDistance()} made
1207-
* when the Island got created in order to allow easier access to this value and
1208-
* must therefore remain <u><strong>AS IS</strong></u>.
1205+
* when the Island got created. It should not be altered mid-game unless you set
1206+
* {@link world.bentobox.bentobox.api.addons.GameModeAddon#isEnforceEqualRanges()}
1207+
* to {@code false}, and also likely set {@link world.bentobox.bentobox.api.addons.GameModeAddon#isFixIslandCenter()}
1208+
* to {@code false} too.
1209+
*
1210+
* The protection range can be set to be bigger than this, but will never report as being bigger than this.
12091211
*
12101212
* @param range the range to set
12111213
* @see #setProtectionRange(int)

src/main/java/world/bentobox/bentobox/listeners/JoinLeaveListener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public void onPlayerJoin(final PlayerJoinEvent event) {
5353
// plugins
5454
return;
5555
}
56+
// Set the addon in the User object - required to have the right context for prefixes in translations
57+
plugin.getIWM().getAddon(event.getPlayer().getWorld()).ifPresent(gm -> user.setAddon(gm));
58+
59+
// Get the UUID
5660
UUID playerUUID = event.getPlayer().getUniqueId();
5761

5862
// Check if player hasn't joined before

src/main/java/world/bentobox/bentobox/listeners/PanelListenerManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void onInventoryClick(InventoryClickEvent event) {
3333

3434
// Open the inventory panel that this player has open (they can only ever have one)
3535
if (openPanels.containsKey(user.getUniqueId()) &&
36-
openPanels.get(user.getUniqueId()).getInventory().equals(event.getInventory())) {
36+
openPanels.get(user.getUniqueId()).getInventory().equals(event.getClickedInventory())) {
3737
// Cancel the event. If they don't want it to be cancelled then the click handler(s) should
3838
// uncancel it. If gui was from our environment, then cancel event anyway.
3939
event.setCancelled(true);

src/main/java/world/bentobox/bentobox/listeners/flags/protection/BlockInteractionListener.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ private boolean checkSpecialCases(Event e, Player player, Block block) {
248248
return true;
249249
}
250250
if (Util.isVersionAtLeast("1.21.10")) {
251+
// Wooden shelves
252+
if (Tag.WOODEN_SHELVES.isTagged(type)) {
253+
this.checkIsland(e, player, loc, Flags.BOOKSHELF);
254+
return true;
255+
}
256+
251257
// Prevent animation of copper golems. Use break blocks for now. This could potentiall have it's own flag in the future.
252258
if (Tag.COPPER_GOLEM_STATUES.isTagged(type)) {
253259
this.checkIsland(e, player, loc, Flags.BREAK_BLOCKS);

src/main/java/world/bentobox/bentobox/managers/IslandsManager.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,23 @@ public Island createIsland(@NonNull Location location) {
248248
*/
249249
@Nullable
250250
public Island createIsland(@NonNull Location location, @Nullable UUID owner) {
251-
Island island = new Island(location, owner, plugin.getIWM().getIslandProtectionRange(location.getWorld()));
251+
return createIsland(location, owner, plugin.getIWM().getIslandProtectionRange(location.getWorld()));
252+
}
253+
254+
/**
255+
* Create an island with owner, and a specified protection range. Note this does not paste blocks. It just creates
256+
* the island data object.
257+
*
258+
* @param location the location, not null
259+
* @param owner the island owner UUID, may be null
260+
* @param protectionRange size of protection range
261+
* @return Island or null if the island could not be created for some reason
262+
* @since 3.10.0
263+
*/
264+
public Island createIsland(@NonNull Location location, @Nullable UUID owner, int protectionRange) {
265+
Island island = new Island(location, owner, protectionRange);
252266
// Game the gamemode name and prefix the uniqueId
253-
String gmName = plugin.getIWM().getAddon(location.getWorld()).map(gm -> gm.getDescription().getName())
254-
.orElse("");
267+
String gmName = plugin.getIWM().getAddon(location.getWorld()).map(gm -> gm.getDescription().getName()).orElse("");
255268
island.setGameMode(gmName);
256269
island.setUniqueId(gmName + island.getUniqueId());
257270
if (islandCache.addIsland(island)) {
@@ -265,6 +278,7 @@ public Island createIsland(@NonNull Location location, @Nullable UUID owner) {
265278
}
266279
return null;
267280
}
281+
268282

269283
/**
270284
* Deletes island.

src/main/java/world/bentobox/bentobox/managers/island/IslandGrid.java

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,73 @@ public IslandGrid(IslandCache im) {
3636
* @return true if successfully added, false if island already exists, or there is an overlap
3737
*/
3838
public boolean addToGrid(Island island) {
39-
// Check if we know about this island already
4039
int minX = island.getMinX();
4140
int minZ = island.getMinZ();
42-
IslandData islandData = new IslandData(island.getUniqueId(), minX, minZ, island.getRange());
43-
if (grid.containsKey(minX)) {
44-
TreeMap<Integer, IslandData> zEntry = grid.get(minX);
45-
if (zEntry.containsKey(minZ)) {
46-
// If it is the same island then it's okay
47-
return island.getUniqueId().equals(zEntry.get(minZ).id());
48-
// Island overlap, report error
49-
} else {
50-
// Add island
51-
zEntry.put(minZ, islandData);
52-
grid.put(minX, zEntry);
41+
int range = island.getRange();
42+
IslandData newIsland = new IslandData(island.getUniqueId(), minX, minZ, range);
43+
44+
// Remove this island if it is already in the grid
45+
this.removeFromGrid(island);
46+
47+
// compute bounds for the new island (upper bounds are exclusive)
48+
int newMaxX = minX + range * 2;
49+
int newMaxZ = minZ + range * 2;
50+
51+
/*
52+
* Find any existing islands that could overlap:
53+
* - Any existing island with minX <= newMaxX could extend over newMinX, so we must consider
54+
* all entries with key <= newMaxX (use headMap).
55+
* - For each candidate X entry, consider Z entries with minZ <= newMaxZ (use headMap).
56+
* This avoids missing large islands whose minX is far left of the new island.
57+
*/
58+
for (Entry<Integer, TreeMap<Integer, IslandData>> xEntry : grid.headMap(newMaxX, true).entrySet()) {
59+
TreeMap<Integer, IslandData> zMap = xEntry.getValue();
60+
for (Entry<Integer, IslandData> zEntry : zMap.headMap(newMaxZ, true).entrySet()) {
61+
IslandData existingIsland = zEntry.getValue();
62+
if (isOverlapping(newIsland, existingIsland)) {
63+
return false;
64+
}
5365
}
54-
} else {
55-
// Add island
56-
TreeMap<Integer, IslandData> zEntry = new TreeMap<>();
57-
zEntry.put(minZ, islandData);
58-
grid.put(minX, zEntry);
5966
}
67+
68+
// No overlaps found, add the island
69+
addNewEntry(minX, minZ, newIsland);
70+
return true;
71+
}
72+
73+
/**
74+
* Checks if two islands overlap
75+
* @param island1 first island
76+
* @param island2 second island
77+
* @return true if islands overlap
78+
*/
79+
private boolean isOverlapping(IslandData island1, IslandData island2) {
80+
int island1MaxX = island1.minX() + (island1.range() * 2);
81+
int island1MaxZ = island1.minZ() + (island1.range() * 2);
82+
int island2MaxX = island2.minX() + (island2.range() * 2);
83+
int island2MaxZ = island2.minZ() + (island2.range() * 2);
84+
85+
// Check if one rectangle is to the left of the other
86+
if (island1MaxX <= island2.minX() || island2MaxX <= island1.minX()) {
87+
return false;
88+
}
89+
90+
// Check if one rectangle is above the other
91+
if (island1MaxZ <= island2.minZ() || island2MaxZ <= island1.minZ()) {
92+
return false;
93+
}
94+
6095
return true;
6196
}
6297

98+
/**
99+
* Helper method to add a new entry to the grid
100+
*/
101+
private void addNewEntry(int minX, int minZ, IslandData islandData) {
102+
TreeMap<Integer, IslandData> zEntry = grid.computeIfAbsent(minX, k -> new TreeMap<>());
103+
zEntry.put(minZ, islandData);
104+
}
105+
63106
/**
64107
* Remove island from grid
65108
* @param island - the island to remove

src/main/resources/locales/en-US.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -989,11 +989,11 @@ protection:
989989
&a entering into boats.
990990
hint: No boat interaction allowed
991991
BOOKSHELF:
992-
name: Bookshelves
992+
name: Shelves
993993
description: |-
994-
&a Allow to place books
995-
&a or to take books.
996-
hint: cannot place a book or take a book.
994+
&a Allow to place item
995+
&a or to take item.
996+
hint: cannot place an item or take an item.
997997
BREAK_BLOCKS:
998998
description: Toggle breaking
999999
name: Break blocks

0 commit comments

Comments
 (0)