Skip to content

Commit 4ae619c

Browse files
authored
Merge pull request #120 from BentoBoxWorld/develop
Version 1.13.0
2 parents 076b71c + 9e57851 commit 4ae619c

File tree

14 files changed

+332
-81
lines changed

14 files changed

+332
-81
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ jobs:
1414
- uses: actions/checkout@v2
1515
with:
1616
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
17-
- name: Set up JDK 16
17+
- name: Set up JDK 17
1818
uses: actions/setup-java@v2
1919
with:
2020
distribution: 'adopt'
21-
java-version: '16'
21+
java-version: '17'
2222
- name: Cache SonarCloud packages
2323
uses: actions/cache@v2
2424
with:

pom.xml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@
5454
<properties>
5555
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5656
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
57-
<java.version>16</java.version>
57+
<java.version>17</java.version>
5858
<!-- Non-minecraft related dependencies -->
5959
<powermock.version>2.0.9</powermock.version>
6060
<!-- More visible way how to change dependency versions -->
61-
<spigot.version>1.17-R0.1-SNAPSHOT</spigot.version>
62-
<bentobox.version>1.18.0-SNAPSHOT</bentobox.version>
61+
<spigot.version>1.19.4-R0.1-SNAPSHOT</spigot.version>
62+
<bentobox.version>1.23.0</bentobox.version>
6363
<level.version>2.7.0-SNAPSHOT</level.version>
6464
<!-- Revision variable removes warning about dynamic version -->
6565
<revision>${build.version}-SNAPSHOT</revision>
6666
<!-- Do not change unless you want different name for local builds. -->
6767
<build.number>-LOCAL</build.number>
6868
<!-- This allows to change between versions. -->
69-
<build.version>1.12.0</build.version>
69+
<build.version>1.13.0</build.version>
7070
<!-- Sonar Cloud -->
7171
<sonar.projectKey>BentoBoxWorld_Warps</sonar.projectKey>
7272
<sonar.organization>bentobox-world</sonar.organization>
@@ -138,11 +138,6 @@
138138
<version>${spigot.version}</version>
139139
<scope>provided</scope>
140140
</dependency>
141-
<dependency>
142-
<groupId>org.spigotmc</groupId>
143-
<artifactId>plugin-annotations</artifactId>
144-
<version>1.2.3-SNAPSHOT</version>
145-
</dependency>
146141
<!-- Mockito (Unit testing) -->
147142
<dependency>
148143
<groupId>org.mockito</groupId>
@@ -234,6 +229,7 @@
234229
<version>3.0.0-M5</version>
235230
<configuration>
236231
<argLine>
232+
${argLine}
237233
--add-opens java.base/java.lang=ALL-UNNAMED
238234
--add-opens java.base/java.math=ALL-UNNAMED
239235
--add-opens java.base/java.io=ALL-UNNAMED
@@ -316,7 +312,7 @@
316312
<plugin>
317313
<groupId>org.jacoco</groupId>
318314
<artifactId>jacoco-maven-plugin</artifactId>
319-
<version>0.8.3</version>
315+
<version>0.8.7</version>
320316
<configuration>
321317
<append>true</append>
322318
<excludes>
@@ -327,16 +323,21 @@
327323
</configuration>
328324
<executions>
329325
<execution>
330-
<id>pre-unit-test</id>
326+
<id>prepare-agent</id>
331327
<goals>
332328
<goal>prepare-agent</goal>
333329
</goals>
334330
</execution>
335331
<execution>
336-
<id>post-unit-test</id>
332+
<id>report</id>
337333
<goals>
338334
<goal>report</goal>
339335
</goals>
336+
<configuration>
337+
<formats>
338+
<format>XML</format>
339+
</formats>
340+
</configuration>
340341
</execution>
341342
</executions>
342343
</plugin>

src/main/java/world/bentobox/warps/Warp.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
import java.util.UUID;
88

99
import org.bukkit.Bukkit;
10+
import org.bukkit.Material;
1011
import org.bukkit.World;
1112

1213
import world.bentobox.bentobox.api.addons.Addon;
1314
import world.bentobox.bentobox.api.configuration.Config;
15+
import world.bentobox.bentobox.api.flags.Flag;
16+
import world.bentobox.bentobox.api.flags.clicklisteners.CycleClick;
17+
import world.bentobox.bentobox.managers.RanksManager;
1418
import world.bentobox.bentobox.util.Util;
1519
import world.bentobox.level.Level;
1620
import world.bentobox.warps.commands.WarpCommand;
@@ -71,6 +75,11 @@ public class Warp extends Addon {
7175
*/
7276
private Config<Settings> settingsConfig;
7377

78+
/**
79+
* Create Warp Flag
80+
*/
81+
private Flag createWarpFlag;
82+
7483
// ---------------------------------------------------------------------
7584
// Section: Methods
7685
// ---------------------------------------------------------------------
@@ -146,6 +155,18 @@ public void onEnable() {
146155
logWarning("Addon did not hook into anything and is not running stand-alone");
147156
this.setState(State.DISABLED);
148157
}
158+
159+
this.createWarpFlag = new Flag.Builder("PLACE_WARP", Material.OAK_SIGN)
160+
.addon(this)
161+
.defaultRank(RanksManager.MEMBER_RANK)
162+
.clickHandler(new CycleClick("PLACE_WARP",
163+
RanksManager.MEMBER_RANK,
164+
RanksManager.OWNER_RANK))
165+
.defaultSetting(false)
166+
.mode(Flag.Mode.EXPERT)
167+
.build();
168+
169+
getPlugin().getFlagsManager().registerFlag(this, this.createWarpFlag);
149170
}
150171

151172

@@ -213,6 +234,13 @@ public Settings getSettings() {
213234
return settings;
214235
}
215236

237+
/**
238+
* @return the createWarpFlag
239+
*/
240+
public Flag getCreateWarpFlag() {
241+
return createWarpFlag;
242+
}
243+
216244
/**
217245
* Get the island level
218246
* @param world - world
@@ -224,8 +252,11 @@ public Long getLevel(World world, UUID uniqueId) {
224252
String name = this.getPlugin().getIWM().getAddon(world).map(g -> g.getDescription().getName()).orElse("");
225253
return this.getPlugin().getAddonsManager().getAddonByName(LEVEL_ADDON_NAME)
226254
.map(l -> {
227-
if (!name.isEmpty() && ((Level) l).getSettings().getGameModes().contains(name)) {
228-
return ((Level) l).getIslandLevel(world, uniqueId);
255+
final Level addon = (Level) l;
256+
//getGameModes is a list of gamemodes that Level is DISABLED in,
257+
//so we need the opposite of the contains.
258+
if (!name.isEmpty() && !addon.getSettings().getGameModes().contains(name)) {
259+
return addon.getIslandLevel(world, uniqueId);
229260
}
230261
return null;
231262
}).orElse(null);

src/main/java/world/bentobox/warps/WarpsPladdon.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
package world.bentobox.warps;
22

3-
import org.bukkit.plugin.java.annotation.dependency.Dependency;
4-
import org.bukkit.plugin.java.annotation.plugin.ApiVersion;
5-
import org.bukkit.plugin.java.annotation.plugin.Plugin;
63

74
import world.bentobox.bentobox.api.addons.Addon;
85
import world.bentobox.bentobox.api.addons.Pladdon;
96

10-
@Plugin(name="Pladdon", version="1.0")
11-
@ApiVersion(ApiVersion.Target.v1_16)
12-
@Dependency(value = "BentoBox")
7+
138
public class WarpsPladdon extends Pladdon {
149

1510
@Override

src/main/java/world/bentobox/warps/config/Settings.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ public class Settings implements ConfigObject
2323
@ConfigEntry(path = "warplevelrestriction")
2424
private int warpLevelRestriction = 10;
2525

26+
@ConfigComment("")
27+
@ConfigComment("Should warps be removed when the island protection settings")
28+
@ConfigComment("change, and the owner of the warp does no longer have")
29+
@ConfigComment("the correct rank")
30+
@ConfigEntry(path = "removeExistingWarpsWhenFlagChanges")
31+
private boolean removeExistingWarpsWhenFlagChanges = false;
32+
2633
@ConfigComment("")
2734
@ConfigComment("Text that player must put on sign to make it a warp sign")
2835
@ConfigComment("Not case sensitive!")
@@ -55,7 +62,6 @@ public class Settings implements ConfigObject
5562
@ConfigEntry(path = "warps-command")
5663
String warpsCommand = "warps";
5764

58-
5965
// ---------------------------------------------------------------------
6066
// Section: Constructor
6167
// ---------------------------------------------------------------------
@@ -198,4 +204,18 @@ public String getWarpsCommand() {
198204
public void setWarpsCommand(String warpsCommand) {
199205
this.warpsCommand = warpsCommand;
200206
}
207+
208+
/**
209+
* @return the removeExistingWarpsWhenFlagChanges
210+
*/
211+
public boolean getRemoveExistingWarpsWhenFlagChanges() {
212+
return removeExistingWarpsWhenFlagChanges;
213+
}
214+
215+
/**
216+
* @param removeExistingWarpsWhenFlagChanges the removeExistingWarpsWhenFlagChanges to set
217+
*/
218+
public void setRemoveExistingWarpsWhenFlagChanges(boolean removeExistingWarpsWhenFlagChanges) {
219+
this.removeExistingWarpsWhenFlagChanges = removeExistingWarpsWhenFlagChanges;
220+
}
201221
}

src/main/java/world/bentobox/warps/listeners/WarpSignsListener.java

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package world.bentobox.warps.listeners;
22

3-
import java.util.HashMap;
4-
import java.util.Iterator;
5-
import java.util.Map;
6-
import java.util.Objects;
7-
import java.util.UUID;
3+
import java.util.*;
4+
import java.util.stream.Collectors;
85

96
import org.bukkit.Bukkit;
107
import org.bukkit.ChatColor;
@@ -25,9 +22,11 @@
2522

2623
import world.bentobox.bentobox.BentoBox;
2724
import world.bentobox.bentobox.api.events.addon.AddonEvent;
25+
import world.bentobox.bentobox.api.events.flags.FlagProtectionChangeEvent;
2826
import world.bentobox.bentobox.api.events.team.TeamKickEvent;
2927
import world.bentobox.bentobox.api.events.team.TeamLeaveEvent;
3028
import world.bentobox.bentobox.api.user.User;
29+
import world.bentobox.bentobox.database.objects.Island;
3130
import world.bentobox.bentobox.util.Util;
3231
import world.bentobox.warps.Warp;
3332
import world.bentobox.warps.event.WarpRemoveEvent;
@@ -114,7 +113,6 @@ public void onSignBreak(BlockBreakEvent e) {
114113
return;
115114
}
116115
User user = User.getInstance(e.getPlayer());
117-
if (user == null) return;
118116
UUID owner = addon.getWarpSignsManager().getWarpOwnerUUID(b.getLocation()).orElse(null);
119117
if (isPlayersSign(e.getPlayer(), b, inWorld)) {
120118
addon.getWarpSignsManager().removeWarp(b.getLocation());
@@ -164,6 +162,13 @@ public void onSignWarpCreate(SignChangeEvent e) {
164162
e.setLine(0, ChatColor.RED + addon.getSettings().getWelcomeLine());
165163
return;
166164
}
165+
166+
if(!hasCorrectIslandRank(b, user)) {
167+
e.setLine(0, ChatColor.RED + addon.getSettings().getWelcomeLine());
168+
user.sendMessage("warps.error.not-correct-rank");
169+
return;
170+
}
171+
167172
// Check if the player already has a sign
168173
final Location oldSignLoc = addon.getWarpSignsManager().getWarp(b.getWorld(), user.getUniqueId());
169174
if (oldSignLoc != null) {
@@ -192,6 +197,46 @@ public void onSignWarpCreate(SignChangeEvent e) {
192197

193198
}
194199

200+
private boolean hasCorrectIslandRank(Block b, User user) {
201+
final Optional<Island> islandOpt = plugin.getIslands().getIslandAt(b.getLocation());
202+
203+
if(islandOpt.isEmpty()) return false;
204+
205+
final Island island = islandOpt.get();
206+
207+
final int userRank = island.getRank(user);
208+
209+
return userRank >= island.getFlag(addon.getCreateWarpFlag());
210+
}
211+
212+
@EventHandler
213+
public void onFlagChange(FlagProtectionChangeEvent e) {
214+
if(!e.getEditedFlag().equals(addon.getCreateWarpFlag())) return;
215+
if(!addon.getSettings().getRemoveExistingWarpsWhenFlagChanges()) return;
216+
217+
final Island island = e.getIsland();
218+
219+
final Map<UUID, Location> islandWarps = addon
220+
.getWarpSignsManager()
221+
.getWarpMap(island.getWorld())
222+
.entrySet()
223+
.stream()
224+
.filter(x -> island.inIslandSpace(x.getValue()))
225+
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
226+
227+
for(Map.Entry<UUID, Location> entry : islandWarps.entrySet()) {
228+
if(island.getRank(entry.getKey()) >= e.getSetTo()) continue;
229+
230+
//The user has a lower rank than the new set value.
231+
//We need to remove the warp.
232+
addon.getWarpSignsManager().removeWarp(island.getWorld(), entry.getKey());
233+
234+
if(Bukkit.getPlayer(entry.getKey()) != null) {
235+
Objects.requireNonNull(User.getInstance(entry.getKey())).sendMessage(WARPS_DEACTIVATE);
236+
}
237+
}
238+
}
239+
195240
private boolean noLevelOrIsland(User user, World world) {
196241
// Get level if level addon is available
197242
Long level = addon.getLevel(Util.getWorld(world), user.getUniqueId());

src/main/java/world/bentobox/warps/managers/WarpSignsManager.java

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.bukkit.block.Sign;
2828
import org.bukkit.entity.Player;
2929
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
30-
import org.bukkit.permissions.PermissionAttachmentInfo;
3130
import org.eclipse.jdt.annotation.NonNull;
3231
import org.eclipse.jdt.annotation.Nullable;
3332

@@ -246,8 +245,8 @@ public void removeWarp(Location loc) {
246245
if (en.getValue().equals(loc)) {
247246
// Inform player
248247
Optional.ofNullable(addon.getServer().getPlayer(en.getKey()))
249-
.map(User::getInstance)
250-
.ifPresent(user -> user.sendMessage("warps.sign-removed"));
248+
.map(User::getInstance)
249+
.ifPresent(user -> user.sendMessage("warps.sign-removed"));
251250
// Remove sign from warp panel cache
252251
addon.getSignCacheManager().removeWarp(loc.getWorld(), en.getKey());
253252
it.remove();
@@ -321,8 +320,8 @@ public SignCacheItem getSignInfo(@NonNull World world, @NonNull UUID uuid) {
321320
if (!prefix.isEmpty())
322321
{
323322
icon = Material.matchMaterial(
324-
Utils.getPermissionValue(User.getInstance(uuid), prefix + "island.warp",
325-
Material.OAK_SIGN.name()));
323+
Utils.getPermissionValue(User.getInstance(uuid), prefix + "island.warp",
324+
Material.OAK_SIGN.name()));
326325
}
327326
else
328327
{
@@ -351,21 +350,33 @@ private void warpPlayer(@NonNull User user, @NonNull Location inFront, @NonNull
351350
float yaw = Util.blockFaceToFloat(directionFacing);
352351
final Location actualWarp = new Location(inFront.getWorld(), inFront.getBlockX() + 0.5D, inFront.getBlockY(),
353352
inFront.getBlockZ() + 0.5D, yaw, 30F);
354-
Util.teleportAsync(user.getPlayer(), actualWarp, TeleportCause.COMMAND);
355-
User warpOwner = Objects.requireNonNull(User.getInstance(signOwner));
356-
// Hide invisible players
357-
if (warpOwner.isOnline() && !warpOwner.getPlayer().canSee(user.getPlayer())) {
358-
return;
359-
}
360-
if (pvp) {
361-
user.sendMessage("protection.flags.PVP_OVERWORLD.enabled");
362-
user.getWorld().playSound(Objects.requireNonNull(user.getLocation()), Sound.ENTITY_ARROW_HIT, 1F, 1F);
363-
} else {
364-
user.getWorld().playSound(Objects.requireNonNull(user.getLocation()), Sound.ENTITY_BAT_TAKEOFF, 1F, 1F);
365-
}
366-
if (!warpOwner.equals(user)) {
367-
warpOwner.sendMessage("warps.player-warped", "[name]", user.getName());
368-
}
353+
//BentoBox prevents people from teleporting to an island when
354+
//the user is banned from the island for example.
355+
//By checking if the teleport succeeded before sending the messages,
356+
//we prevent issues where no one teleported, but people still
357+
//get messages about it.
358+
Util.teleportAsync(user.getPlayer(), actualWarp, TeleportCause.COMMAND).thenAccept(tpResult -> {
359+
if(Boolean.FALSE.equals(tpResult)) return;
360+
361+
User warpOwner = Objects.requireNonNull(User.getInstance(signOwner));
362+
// Hide invisible players
363+
if (warpOwner.isOnline() && !warpOwner.getPlayer().canSee(user.getPlayer())) {
364+
return;
365+
}
366+
if (pvp) {
367+
user.sendMessage("protection.flags.PVP_OVERWORLD.enabled");
368+
user.getWorld().playSound(Objects.requireNonNull(user.getLocation()), Sound.ENTITY_ARROW_HIT, 1F, 1F);
369+
} else {
370+
user.getWorld().playSound(Objects.requireNonNull(user.getLocation()), Sound.ENTITY_BAT_TAKEOFF, 1F, 1F);
371+
}
372+
if (!warpOwner.equals(user)) {
373+
final String gameMode = BentoBox
374+
.getInstance()
375+
.getIWM()
376+
.getFriendlyName(actualWarp.getWorld());
377+
warpOwner.sendMessage("warps.player-warped", "[name]", user.getName(), "[gamemode]", gameMode);
378+
}
379+
});
369380
}
370381

371382
/**

0 commit comments

Comments
 (0)