Skip to content

Commit 363b23a

Browse files
authored
Merge pull request #2152 from BentoBoxWorld/develop
Version 1.24.0
2 parents fdc03df + 9334858 commit 363b23a

File tree

84 files changed

+2303
-341
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+2303
-341
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ jobs:
1010
name: Build
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v3
1414
with:
1515
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
1616
- name: Set up JDK 17
17-
uses: actions/setup-java@v2
17+
uses: actions/setup-java@v3
1818
with:
1919
distribution: 'adopt'
2020
java-version: '17'
2121
- name: Cache SonarCloud packages
22-
uses: actions/cache@v2
22+
uses: actions/cache@v3
2323
with:
2424
path: ~/.sonar/cache
2525
key: ${{ runner.os }}-sonar
2626
restore-keys: ${{ runner.os }}-sonar
2727
- name: Cache Maven packages
28-
uses: actions/cache@v2
28+
uses: actions/cache@v3
2929
with:
3030
path: ~/.m2
3131
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
@@ -38,7 +38,7 @@ jobs:
3838
- run: mvn --batch-mode clean org.jacoco:jacoco-maven-plugin:prepare-agent install
3939
- run: mkdir staging && cp target/*.jar staging
4040
- name: Save artifacts
41-
uses: actions/upload-artifact@v2
41+
uses: actions/upload-artifact@v3
4242
with:
4343
name: Package
4444
path: staging

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@
7373
<postgresql.version>42.2.18</postgresql.version>
7474
<hikaricp.version>5.0.1</hikaricp.version>
7575
<!-- More visible way to change dependency versions -->
76-
<spigot.version>1.19.4-R0.1-SNAPSHOT</spigot.version>
76+
<spigot.version>1.20.1-R0.1-SNAPSHOT</spigot.version>
7777
<!-- Might differ from the last Spigot release for short periods
7878
of time -->
79-
<paper.version>1.19.3-R0.1-SNAPSHOT</paper.version>
79+
<paper.version>1.20.1-R0.1-SNAPSHOT</paper.version>
8080
<bstats.version>3.0.0</bstats.version>
8181
<vault.version>1.7.1</vault.version>
8282
<placeholderapi.version>2.10.9</placeholderapi.version>
@@ -88,7 +88,7 @@
8888
<!-- Do not change unless you want different name for local builds. -->
8989
<build.number>-LOCAL</build.number>
9090
<!-- This allows to change between versions. -->
91-
<build.version>1.23.2</build.version>
91+
<build.version>1.24.0</build.version>
9292
<sonar.organization>bentobox-world</sonar.organization>
9393
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
9494
<server.jars>${project.basedir}/lib</server.jars>

src/main/java/world/bentobox/bentobox/BentoBox.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
import org.apache.commons.lang.exception.ExceptionUtils;
77
import org.bukkit.Bukkit;
8+
import org.bukkit.event.EventHandler;
9+
import org.bukkit.event.Listener;
10+
import org.bukkit.event.server.ServerCommandEvent;
811
import org.bukkit.generator.ChunkGenerator;
912
import org.bukkit.plugin.PluginManager;
1013
import org.bukkit.plugin.java.JavaPlugin;
@@ -36,7 +39,6 @@
3639
import world.bentobox.bentobox.managers.CommandsManager;
3740
import world.bentobox.bentobox.managers.FlagsManager;
3841
import world.bentobox.bentobox.managers.HooksManager;
39-
import world.bentobox.bentobox.managers.IslandChunkDeletionManager;
4042
import world.bentobox.bentobox.managers.IslandDeletionManager;
4143
import world.bentobox.bentobox.managers.IslandWorldManager;
4244
import world.bentobox.bentobox.managers.IslandsManager;
@@ -52,7 +54,7 @@
5254
* Main BentoBox class
5355
* @author tastybento, Poslovitch
5456
*/
55-
public class BentoBox extends JavaPlugin {
57+
public class BentoBox extends JavaPlugin implements Listener {
5658

5759
private static BentoBox instance;
5860

@@ -71,7 +73,6 @@ public class BentoBox extends JavaPlugin {
7173
private HooksManager hooksManager;
7274
private PlaceholdersManager placeholdersManager;
7375
private IslandDeletionManager islandDeletionManager;
74-
private IslandChunkDeletionManager islandChunkDeletionManager;
7576
private WebManager webManager;
7677

7778
// Settings
@@ -227,7 +228,7 @@ private void completeSetup(long loadTime) {
227228
// Make sure all worlds are already registered to Multiverse.
228229
hooksManager.registerHook(new MultiverseCoreHook());
229230
hooksManager.registerHook(new MyWorldsHook());
230-
islandWorldManager.registerWorldsToMultiverse();
231+
islandWorldManager.registerWorldsToMultiverse(true);
231232

232233
// TODO: re-enable after implementation
233234
//hooksManager.registerHook(new DynmapHook());
@@ -300,8 +301,9 @@ private void registerListeners() {
300301
manager.registerEvents(new BannedCommands(this), this);
301302
// Death counter
302303
manager.registerEvents(new DeathListener(this), this);
304+
// MV unregister
305+
manager.registerEvents(this, this);
303306
// Island Delete Manager
304-
islandChunkDeletionManager = new IslandChunkDeletionManager(this);
305307
islandDeletionManager = new IslandDeletionManager(this);
306308
manager.registerEvents(islandDeletionManager, this);
307309
}
@@ -321,6 +323,15 @@ public void onDisable() {
321323
if (islandsManager != null) {
322324
islandsManager.shutdown();
323325
}
326+
327+
}
328+
329+
@EventHandler
330+
public void onServerStop(ServerCommandEvent e) {
331+
if (islandWorldManager != null && (e.getCommand().equalsIgnoreCase("stop") || e.getCommand().equalsIgnoreCase("restart"))) {
332+
// Unregister any MV worlds if () {
333+
islandWorldManager.registerWorldsToMultiverse(false);
334+
}
324335
}
325336

326337
/**
@@ -531,13 +542,6 @@ public IslandDeletionManager getIslandDeletionManager() {
531542
return islandDeletionManager;
532543
}
533544

534-
/**
535-
* @return the islandChunkDeletionManager
536-
*/
537-
public IslandChunkDeletionManager getIslandChunkDeletionManager() {
538-
return islandChunkDeletionManager;
539-
}
540-
541545
/**
542546
* @return an optional of the Bstats instance
543547
* @since 1.1

src/main/java/world/bentobox/bentobox/api/commands/CompositeCommand.java

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
4848
*/
4949
private boolean onlyPlayer = false;
5050

51+
/**
52+
* True if the command is only for the console
53+
* @since 1.24.0
54+
*/
55+
private boolean onlyConsole = false;
56+
57+
5158
/**
5259
* True if command is a configurable rank
5360
*/
@@ -241,7 +248,6 @@ public boolean execute(@NonNull CommandSender sender, @NonNull String label, Str
241248
CompositeCommand cmd = getCommandFromArgs(args);
242249
String cmdLabel = (cmd.subCommandLevel > 0) ? args[cmd.subCommandLevel-1] : label;
243250
List<String> cmdArgs = Arrays.asList(args).subList(cmd.subCommandLevel, args.length);
244-
// Call
245251
return cmd.call(user, cmdLabel, cmdArgs);
246252
}
247253

@@ -257,17 +263,21 @@ public boolean execute(@NonNull CommandSender sender, @NonNull String label, Str
257263
*/
258264
public boolean call(User user, String cmdLabel, List<String> cmdArgs) {
259265
// Check for console and permissions
260-
if (onlyPlayer && !user.isPlayer()) {
266+
if (isOnlyPlayer() && !user.isPlayer()) {
261267
user.sendMessage("general.errors.use-in-game");
262268
return false;
263269
}
264270

271+
if (isOnlyConsole() && user.isPlayer()) {
272+
user.sendMessage("general.errors.use-in-console");
273+
return false;
274+
}
275+
265276
if (!this.runPermissionCheck(user))
266277
{
267278
// Error message is displayed by permission check.
268279
return false;
269280
}
270-
271281
// Set the user's addon context
272282
user.setAddon(addon);
273283
// Execute and trim args
@@ -513,6 +523,14 @@ public boolean isOnlyPlayer() {
513523
return onlyPlayer;
514524
}
515525

526+
/**
527+
* Check if this command is only for consoles.
528+
* @return true or false
529+
*/
530+
public boolean isOnlyConsole() {
531+
return onlyConsole;
532+
}
533+
516534
/**
517535
* Sets whether this command should only be run by players.
518536
* If this is set to {@code true}, this command will only be runnable by objects implementing {@link Player}.
@@ -525,6 +543,18 @@ public void setOnlyPlayer(boolean onlyPlayer) {
525543
this.onlyPlayer = onlyPlayer;
526544
}
527545

546+
/**
547+
* Sets whether this command should only be run in the console.
548+
* This is for commands that dump a lot of data or are for debugging.
549+
* The default value provided when instantiating this CompositeCommand is {@code false}.
550+
* Therefore, this method should only be used in case you want to explicitly edit the value.
551+
* @param onlyConsole {@code true} if this command should only be run in the console.
552+
* @since 1.24.0
553+
*/
554+
public void setOnlyConsole(boolean onlyConsole) {
555+
this.onlyConsole = onlyConsole;
556+
}
557+
528558
/**
529559
* Sets locale reference to this command's description.
530560
* It is used to display the help of this command.
@@ -623,16 +653,17 @@ public void inheritPermission() {
623653
@Override
624654
@NonNull
625655
public List<String> tabComplete(final @NonNull CommandSender sender, final @NonNull String alias, final String[] args) {
626-
List<String> options = new ArrayList<>();
627656
// Get command object based on args entered so far
628657
CompositeCommand command = getCommandFromArgs(args);
629658
// Check for console and permissions
630-
if (command.isOnlyPlayer() && !(sender instanceof Player)) {
631-
return options;
659+
if ((command.isOnlyPlayer() && !(sender instanceof Player))
660+
|| (command.isOnlyConsole() && sender instanceof Player)) {
661+
return List.of();
632662
}
633663
if (command.getPermission() != null && !command.getPermission().isEmpty() && !sender.hasPermission(command.getPermission()) && !sender.isOp()) {
634-
return options;
664+
return List.of();
635665
}
666+
List<String> options = new ArrayList<>();
636667
// Add any tab completion from the subcommand
637668
options.addAll(command.tabComplete(User.getInstance(sender), alias, new LinkedList<>(Arrays.asList(args))).orElseGet(ArrayList::new));
638669
if (command.hasSubCommands()) {
@@ -654,17 +685,26 @@ public List<String> tabComplete(final @NonNull CommandSender sender, final @NonN
654685
}
655686

656687
/**
657-
* Returns a list containing all the labels of the subcommands for the provided CompositeCommand excluding any hidden commands
688+
* Returns a list containing all the labels of the subcommands for the provided
689+
* CompositeCommand excluding any hidden commands
658690
* @param sender the CommandSender
659691
* @param command the CompositeCommand to get the subcommands from
660692
* @return a list of subcommands labels or an empty list.
661693
*/
662694
@NonNull
663695
private List<String> getSubCommandLabels(@NonNull CommandSender sender, @NonNull CompositeCommand command) {
664-
return command.getSubCommands().values().stream()
665-
.filter(cmd -> !cmd.isHidden())
666-
.filter(cmd -> !cmd.isOnlyPlayer() || sender.isOp() || (sender instanceof Player && cmd.getPermission() != null && (cmd.getPermission().isEmpty() || sender.hasPermission(cmd.getPermission()))) )
667-
.map(CompositeCommand::getLabel).toList();
696+
List<String> result = new ArrayList<>();
697+
for (CompositeCommand cc: command.getSubCommands().values()) {
698+
// Player or not
699+
if (sender instanceof Player) {
700+
if (!cc.isHidden() && !cc.isOnlyConsole() && (cc.getPermission().isEmpty() || sender.hasPermission(cc.getPermission()))) {
701+
result.add(cc.getLabel());
702+
}
703+
} else if (!cc.isOnlyPlayer()) {
704+
result.add(cc.getLabel());
705+
}
706+
}
707+
return result;
668708
}
669709

670710
/**

src/main/java/world/bentobox/bentobox/api/commands/admin/AdminInfoCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public boolean execute(User user, String label, List<String> args) {
3535
}
3636
// If there are no args, then the player wants info on the island at this location
3737
if (args.isEmpty()) {
38-
getIslands().getIslandAt(user.getLocation()).ifPresentOrElse(i -> new IslandInfo(i).showAdminInfo(user), () ->
38+
getIslands().getIslandAt(user.getLocation()).ifPresentOrElse(i -> new IslandInfo(i).showAdminInfo(user, getAddon()), () ->
3939
user.sendMessage("commands.admin.info.no-island"));
4040
return true;
4141
}
@@ -48,7 +48,7 @@ public boolean execute(User user, String label, List<String> args) {
4848
// Show info for this player
4949
Island island = getIslands().getIsland(getWorld(), targetUUID);
5050
if (island != null) {
51-
new IslandInfo(island).showAdminInfo(user);
51+
new IslandInfo(island).showAdminInfo(user, getAddon());
5252
if (!getIslands().getQuarantinedIslandByUser(getWorld(), targetUUID).isEmpty()) {
5353
user.sendMessage("commands.admin.info.islands-in-trash");
5454
}

src/main/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintCopyCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public AdminBlueprintCopyCommand(AdminBlueprintCommand parent)
1919
@Override
2020
public void setup()
2121
{
22-
inheritPermission();
22+
setPermission("admin.blueprint.copy");
2323
setParametersHelp("commands.admin.blueprint.copy.parameters");
2424
setDescription("commands.admin.blueprint.copy.description");
2525
}
@@ -37,7 +37,7 @@ public boolean execute(User user, String label, List<String> args)
3737
AdminBlueprintCommand parent = (AdminBlueprintCommand) getParent();
3838

3939
BlueprintClipboard clipboard =
40-
parent.getClipboards().computeIfAbsent(user.getUniqueId(), v -> new BlueprintClipboard());
40+
parent.getClipboards().computeIfAbsent(user.getUniqueId(), v -> new BlueprintClipboard());
4141

4242
boolean copyAir = args.stream().anyMatch(key -> key.equalsIgnoreCase("air"));
4343
boolean copyBiome = args.stream().anyMatch(key -> key.equalsIgnoreCase("biome"));

src/main/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintDeleteCommand.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public AdminBlueprintDeleteCommand(AdminBlueprintCommand parent)
2626
@Override
2727
public void setup()
2828
{
29-
this.inheritPermission();
29+
setPermission("admin.blueprint.delete");
3030
this.setParametersHelp("commands.admin.blueprint.delete.parameters");
3131
this.setDescription("commands.admin.blueprint.delete.description");
3232
}
@@ -47,10 +47,10 @@ public boolean execute(User user, String label, List<String> args)
4747
if (this.getPlugin().getBlueprintsManager().getBlueprints(this.getAddon()).containsKey(blueprintName))
4848
{
4949
this.askConfirmation(user, user.getTranslation("commands.admin.blueprint.delete.confirmation"),
50-
() -> {
51-
this.getPlugin().getBlueprintsManager().deleteBlueprint(this.getAddon(), blueprintName);
52-
user.sendMessage("commands.admin.blueprint.delete.success", TextVariables.NAME, blueprintName);
53-
});
50+
() -> {
51+
this.getPlugin().getBlueprintsManager().deleteBlueprint(this.getAddon(), blueprintName);
52+
user.sendMessage("commands.admin.blueprint.delete.success", TextVariables.NAME, blueprintName);
53+
});
5454
return true;
5555
}
5656
else

src/main/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintListCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public AdminBlueprintListCommand(AdminBlueprintCommand parent)
2222
@Override
2323
public void setup()
2424
{
25-
this.inheritPermission();
25+
setPermission("admin.blueprint.list");
2626
this.setDescription("commands.admin.blueprint.list.description");
2727
}
2828

@@ -54,8 +54,8 @@ public boolean execute(User user, String label, List<String> args)
5454
FilenameFilter blueprintFilter = (File dir, String name) -> name.endsWith(BlueprintsManager.BLUEPRINT_SUFFIX);
5555

5656
List<String> blueprintList = Arrays.stream(Objects.requireNonNull(blueprints.list(blueprintFilter))).
57-
map(name -> name.substring(0, name.length() - BlueprintsManager.BLUEPRINT_SUFFIX.length())).
58-
toList();
57+
map(name -> name.substring(0, name.length() - BlueprintsManager.BLUEPRINT_SUFFIX.length())).
58+
toList();
5959

6060
if (blueprintList.isEmpty())
6161
{

src/main/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintLoadCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public AdminBlueprintLoadCommand(AdminBlueprintCommand parent) {
1717

1818
@Override
1919
public void setup() {
20-
inheritPermission();
20+
setPermission("admin.blueprint.load");
2121
setParametersHelp("commands.admin.blueprint.load.parameters");
2222
setDescription("commands.admin.blueprint.load.description");
2323
}

src/main/java/world/bentobox/bentobox/api/commands/admin/blueprints/AdminBlueprintOriginCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public AdminBlueprintOriginCommand(AdminBlueprintCommand parent) {
1919

2020
@Override
2121
public void setup() {
22-
inheritPermission();
22+
setPermission("admin.blueprint.origin");
2323
setParametersHelp("commands.admin.blueprint.origin.parameters");
2424
setDescription("commands.admin.blueprint.origin.description");
2525
}

0 commit comments

Comments
 (0)