Skip to content

Commit

Permalink
Merge pull request #2152 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Version 1.24.0
  • Loading branch information
tastybento authored Jul 3, 2023
2 parents fdc03df + 9334858 commit 363b23a
Show file tree
Hide file tree
Showing 84 changed files with 2,303 additions and 341 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '17'
- name: Cache SonarCloud packages
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
Expand All @@ -38,7 +38,7 @@ jobs:
- run: mvn --batch-mode clean org.jacoco:jacoco-maven-plugin:prepare-agent install
- run: mkdir staging && cp target/*.jar staging
- name: Save artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: Package
path: staging
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
<postgresql.version>42.2.18</postgresql.version>
<hikaricp.version>5.0.1</hikaricp.version>
<!-- More visible way to change dependency versions -->
<spigot.version>1.19.4-R0.1-SNAPSHOT</spigot.version>
<spigot.version>1.20.1-R0.1-SNAPSHOT</spigot.version>
<!-- Might differ from the last Spigot release for short periods
of time -->
<paper.version>1.19.3-R0.1-SNAPSHOT</paper.version>
<paper.version>1.20.1-R0.1-SNAPSHOT</paper.version>
<bstats.version>3.0.0</bstats.version>
<vault.version>1.7.1</vault.version>
<placeholderapi.version>2.10.9</placeholderapi.version>
Expand All @@ -88,7 +88,7 @@
<!-- 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.23.2</build.version>
<build.version>1.24.0</build.version>
<sonar.organization>bentobox-world</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<server.jars>${project.basedir}/lib</server.jars>
Expand Down
28 changes: 16 additions & 12 deletions src/main/java/world/bentobox/bentobox/BentoBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -36,7 +39,6 @@
import world.bentobox.bentobox.managers.CommandsManager;
import world.bentobox.bentobox.managers.FlagsManager;
import world.bentobox.bentobox.managers.HooksManager;
import world.bentobox.bentobox.managers.IslandChunkDeletionManager;
import world.bentobox.bentobox.managers.IslandDeletionManager;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
Expand All @@ -52,7 +54,7 @@
* Main BentoBox class
* @author tastybento, Poslovitch
*/
public class BentoBox extends JavaPlugin {
public class BentoBox extends JavaPlugin implements Listener {

private static BentoBox instance;

Expand All @@ -71,7 +73,6 @@ public class BentoBox extends JavaPlugin {
private HooksManager hooksManager;
private PlaceholdersManager placeholdersManager;
private IslandDeletionManager islandDeletionManager;
private IslandChunkDeletionManager islandChunkDeletionManager;
private WebManager webManager;

// Settings
Expand Down Expand Up @@ -227,7 +228,7 @@ private void completeSetup(long loadTime) {
// Make sure all worlds are already registered to Multiverse.
hooksManager.registerHook(new MultiverseCoreHook());
hooksManager.registerHook(new MyWorldsHook());
islandWorldManager.registerWorldsToMultiverse();
islandWorldManager.registerWorldsToMultiverse(true);

// TODO: re-enable after implementation
//hooksManager.registerHook(new DynmapHook());
Expand Down Expand Up @@ -300,8 +301,9 @@ private void registerListeners() {
manager.registerEvents(new BannedCommands(this), this);
// Death counter
manager.registerEvents(new DeathListener(this), this);
// MV unregister
manager.registerEvents(this, this);
// Island Delete Manager
islandChunkDeletionManager = new IslandChunkDeletionManager(this);
islandDeletionManager = new IslandDeletionManager(this);
manager.registerEvents(islandDeletionManager, this);
}
Expand All @@ -321,6 +323,15 @@ public void onDisable() {
if (islandsManager != null) {
islandsManager.shutdown();
}

}

@EventHandler
public void onServerStop(ServerCommandEvent e) {
if (islandWorldManager != null && (e.getCommand().equalsIgnoreCase("stop") || e.getCommand().equalsIgnoreCase("restart"))) {
// Unregister any MV worlds if () {
islandWorldManager.registerWorldsToMultiverse(false);
}
}

/**
Expand Down Expand Up @@ -531,13 +542,6 @@ public IslandDeletionManager getIslandDeletionManager() {
return islandDeletionManager;
}

/**
* @return the islandChunkDeletionManager
*/
public IslandChunkDeletionManager getIslandChunkDeletionManager() {
return islandChunkDeletionManager;
}

/**
* @return an optional of the Bstats instance
* @since 1.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
*/
private boolean onlyPlayer = false;

/**
* True if the command is only for the console
* @since 1.24.0
*/
private boolean onlyConsole = false;


/**
* True if command is a configurable rank
*/
Expand Down Expand Up @@ -241,7 +248,6 @@ public boolean execute(@NonNull CommandSender sender, @NonNull String label, Str
CompositeCommand cmd = getCommandFromArgs(args);
String cmdLabel = (cmd.subCommandLevel > 0) ? args[cmd.subCommandLevel-1] : label;
List<String> cmdArgs = Arrays.asList(args).subList(cmd.subCommandLevel, args.length);
// Call
return cmd.call(user, cmdLabel, cmdArgs);
}

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

if (isOnlyConsole() && user.isPlayer()) {
user.sendMessage("general.errors.use-in-console");
return false;
}

if (!this.runPermissionCheck(user))
{
// Error message is displayed by permission check.
return false;
}

// Set the user's addon context
user.setAddon(addon);
// Execute and trim args
Expand Down Expand Up @@ -513,6 +523,14 @@ public boolean isOnlyPlayer() {
return onlyPlayer;
}

/**
* Check if this command is only for consoles.
* @return true or false
*/
public boolean isOnlyConsole() {
return onlyConsole;
}

/**
* Sets whether this command should only be run by players.
* If this is set to {@code true}, this command will only be runnable by objects implementing {@link Player}.
Expand All @@ -525,6 +543,18 @@ public void setOnlyPlayer(boolean onlyPlayer) {
this.onlyPlayer = onlyPlayer;
}

/**
* Sets whether this command should only be run in the console.
* This is for commands that dump a lot of data or are for debugging.
* The default value provided when instantiating this CompositeCommand is {@code false}.
* Therefore, this method should only be used in case you want to explicitly edit the value.
* @param onlyConsole {@code true} if this command should only be run in the console.
* @since 1.24.0
*/
public void setOnlyConsole(boolean onlyConsole) {
this.onlyConsole = onlyConsole;
}

/**
* Sets locale reference to this command's description.
* It is used to display the help of this command.
Expand Down Expand Up @@ -623,16 +653,17 @@ public void inheritPermission() {
@Override
@NonNull
public List<String> tabComplete(final @NonNull CommandSender sender, final @NonNull String alias, final String[] args) {
List<String> options = new ArrayList<>();
// Get command object based on args entered so far
CompositeCommand command = getCommandFromArgs(args);
// Check for console and permissions
if (command.isOnlyPlayer() && !(sender instanceof Player)) {
return options;
if ((command.isOnlyPlayer() && !(sender instanceof Player))
|| (command.isOnlyConsole() && sender instanceof Player)) {
return List.of();
}
if (command.getPermission() != null && !command.getPermission().isEmpty() && !sender.hasPermission(command.getPermission()) && !sender.isOp()) {
return options;
return List.of();
}
List<String> options = new ArrayList<>();
// Add any tab completion from the subcommand
options.addAll(command.tabComplete(User.getInstance(sender), alias, new LinkedList<>(Arrays.asList(args))).orElseGet(ArrayList::new));
if (command.hasSubCommands()) {
Expand All @@ -654,17 +685,26 @@ public List<String> tabComplete(final @NonNull CommandSender sender, final @NonN
}

/**
* Returns a list containing all the labels of the subcommands for the provided CompositeCommand excluding any hidden commands
* Returns a list containing all the labels of the subcommands for the provided
* CompositeCommand excluding any hidden commands
* @param sender the CommandSender
* @param command the CompositeCommand to get the subcommands from
* @return a list of subcommands labels or an empty list.
*/
@NonNull
private List<String> getSubCommandLabels(@NonNull CommandSender sender, @NonNull CompositeCommand command) {
return command.getSubCommands().values().stream()
.filter(cmd -> !cmd.isHidden())
.filter(cmd -> !cmd.isOnlyPlayer() || sender.isOp() || (sender instanceof Player && cmd.getPermission() != null && (cmd.getPermission().isEmpty() || sender.hasPermission(cmd.getPermission()))) )
.map(CompositeCommand::getLabel).toList();
List<String> result = new ArrayList<>();
for (CompositeCommand cc: command.getSubCommands().values()) {
// Player or not
if (sender instanceof Player) {
if (!cc.isHidden() && !cc.isOnlyConsole() && (cc.getPermission().isEmpty() || sender.hasPermission(cc.getPermission()))) {
result.add(cc.getLabel());
}
} else if (!cc.isOnlyPlayer()) {
result.add(cc.getLabel());
}
}
return result;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public boolean execute(User user, String label, List<String> args) {
}
// If there are no args, then the player wants info on the island at this location
if (args.isEmpty()) {
getIslands().getIslandAt(user.getLocation()).ifPresentOrElse(i -> new IslandInfo(i).showAdminInfo(user), () ->
getIslands().getIslandAt(user.getLocation()).ifPresentOrElse(i -> new IslandInfo(i).showAdminInfo(user, getAddon()), () ->
user.sendMessage("commands.admin.info.no-island"));
return true;
}
Expand All @@ -48,7 +48,7 @@ public boolean execute(User user, String label, List<String> args) {
// Show info for this player
Island island = getIslands().getIsland(getWorld(), targetUUID);
if (island != null) {
new IslandInfo(island).showAdminInfo(user);
new IslandInfo(island).showAdminInfo(user, getAddon());
if (!getIslands().getQuarantinedIslandByUser(getWorld(), targetUUID).isEmpty()) {
user.sendMessage("commands.admin.info.islands-in-trash");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public AdminBlueprintCopyCommand(AdminBlueprintCommand parent)
@Override
public void setup()
{
inheritPermission();
setPermission("admin.blueprint.copy");
setParametersHelp("commands.admin.blueprint.copy.parameters");
setDescription("commands.admin.blueprint.copy.description");
}
Expand All @@ -37,7 +37,7 @@ public boolean execute(User user, String label, List<String> args)
AdminBlueprintCommand parent = (AdminBlueprintCommand) getParent();

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

boolean copyAir = args.stream().anyMatch(key -> key.equalsIgnoreCase("air"));
boolean copyBiome = args.stream().anyMatch(key -> key.equalsIgnoreCase("biome"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public AdminBlueprintDeleteCommand(AdminBlueprintCommand parent)
@Override
public void setup()
{
this.inheritPermission();
setPermission("admin.blueprint.delete");
this.setParametersHelp("commands.admin.blueprint.delete.parameters");
this.setDescription("commands.admin.blueprint.delete.description");
}
Expand All @@ -47,10 +47,10 @@ public boolean execute(User user, String label, List<String> args)
if (this.getPlugin().getBlueprintsManager().getBlueprints(this.getAddon()).containsKey(blueprintName))
{
this.askConfirmation(user, user.getTranslation("commands.admin.blueprint.delete.confirmation"),
() -> {
this.getPlugin().getBlueprintsManager().deleteBlueprint(this.getAddon(), blueprintName);
user.sendMessage("commands.admin.blueprint.delete.success", TextVariables.NAME, blueprintName);
});
() -> {
this.getPlugin().getBlueprintsManager().deleteBlueprint(this.getAddon(), blueprintName);
user.sendMessage("commands.admin.blueprint.delete.success", TextVariables.NAME, blueprintName);
});
return true;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public AdminBlueprintListCommand(AdminBlueprintCommand parent)
@Override
public void setup()
{
this.inheritPermission();
setPermission("admin.blueprint.list");
this.setDescription("commands.admin.blueprint.list.description");
}

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

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

if (blueprintList.isEmpty())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public AdminBlueprintLoadCommand(AdminBlueprintCommand parent) {

@Override
public void setup() {
inheritPermission();
setPermission("admin.blueprint.load");
setParametersHelp("commands.admin.blueprint.load.parameters");
setDescription("commands.admin.blueprint.load.description");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public AdminBlueprintOriginCommand(AdminBlueprintCommand parent) {

@Override
public void setup() {
inheritPermission();
setPermission("admin.blueprint.origin");
setParametersHelp("commands.admin.blueprint.origin.parameters");
setDescription("commands.admin.blueprint.origin.description");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public AdminBlueprintPasteCommand(AdminBlueprintCommand parent) {

@Override
public void setup() {
inheritPermission();
setPermission("admin.blueprint.paste");
setParametersHelp("commands.admin.blueprint.paste.parameters");
setDescription("commands.admin.blueprint.paste.description");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public AdminBlueprintPos1Command(AdminBlueprintCommand parent) {

@Override
public void setup() {
inheritPermission();
setPermission("admin.blueprint.pos1");
setParametersHelp("commands.admin.blueprint.pos1.parameters");
setDescription("commands.admin.blueprint.pos1.description");
}
Expand Down
Loading

0 comments on commit 363b23a

Please sign in to comment.