mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-28 05:35:44 +01:00
Added a bentobox command
Added reference about and info commands. These command run across worlds and currently have no perms associated with them. The main point was to enable BentoBox to have is own commands.
This commit is contained in:
parent
783caf985f
commit
1256b0ee22
@ -10,6 +10,7 @@ import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
|
||||
import world.bentobox.bentobox.api.placeholders.PlaceholderHandler;
|
||||
import world.bentobox.bentobox.api.user.Notifier;
|
||||
import world.bentobox.bentobox.commands.BentoBoxCommand;
|
||||
import world.bentobox.bentobox.database.BSBDbSetup;
|
||||
import world.bentobox.bentobox.listeners.BannedVisitorCommands;
|
||||
import world.bentobox.bentobox.listeners.BlockEndDragon;
|
||||
@ -100,7 +101,10 @@ public class BentoBox extends JavaPlugin {
|
||||
// Set up command manager
|
||||
commandsManager = new CommandsManager();
|
||||
|
||||
// Create the world if it does not exist
|
||||
// Load BentoBox commands
|
||||
new BentoBoxCommand();
|
||||
|
||||
// Start Island Worlds Manager
|
||||
islandWorldManager = new IslandWorldManager(instance);
|
||||
// Load schems manager
|
||||
schemsManager = new SchemsManager(instance);
|
||||
|
@ -566,9 +566,6 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
* @return the world
|
||||
*/
|
||||
public World getWorld() {
|
||||
if (world == null) {
|
||||
plugin.logError(getLabel() + " did not setWorld in setup!");
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,9 @@ public class DefaultHelpCommand extends CompositeCommand {
|
||||
}
|
||||
}
|
||||
if (depth == 0) {
|
||||
user.sendMessage("commands.help.header", TextVariables.LABEL, getIWM().getFriendlyName(getWorld()));
|
||||
// Get the name of the world for the help header, or console if there is no world association
|
||||
String labelText = getWorld() != null ? getIWM().getFriendlyName(getWorld()) : user.getTranslation("commands.help.console");
|
||||
user.sendMessage("commands.help.header", TextVariables.LABEL, labelText);
|
||||
}
|
||||
if (depth < MAX_DEPTH) {
|
||||
if (!parent.getLabel().equals(HELP)) {
|
||||
|
@ -1,50 +0,0 @@
|
||||
package world.bentobox.bentobox.api.commands.island;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class IslandAboutCommand extends CompositeCommand {
|
||||
|
||||
/**
|
||||
* About
|
||||
* @param islandCommand - parent command
|
||||
*/
|
||||
public IslandAboutCommand(CompositeCommand islandCommand) {
|
||||
super(islandCommand, "about", "ab");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setDescription("commands.island.about.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
user.sendRawMessage("About " + BentoBox.getInstance().getDescription().getName() + " v" + BentoBox.getInstance().getDescription().getVersion() + ":");
|
||||
user.sendRawMessage("Copyright (c) 2017 - 2018 Tastybento, Poslovitch");
|
||||
user.sendRawMessage("All rights reserved.");
|
||||
user.sendRawMessage("");
|
||||
user.sendRawMessage("Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:");
|
||||
|
||||
user.sendRawMessage(" * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.");
|
||||
user.sendRawMessage(" * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.");
|
||||
user.sendRawMessage(" * Neither the name of the development team nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.");
|
||||
|
||||
user.sendRawMessage("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" "
|
||||
+ "AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE "
|
||||
+ "IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE "
|
||||
+ "ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE "
|
||||
+ "LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR "
|
||||
+ "CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF "
|
||||
+ "SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS "
|
||||
+ "INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN "
|
||||
+ "CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) "
|
||||
+ "ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE "
|
||||
+ "POSSIBILITY OF SUCH DAMAGE.");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package world.bentobox.bentobox.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class AboutCommand extends CompositeCommand {
|
||||
|
||||
/**
|
||||
* About
|
||||
* @param islandCommand - parent command
|
||||
*/
|
||||
public AboutCommand(CompositeCommand parent) {
|
||||
super(parent, "about");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setDescription("commands.bentobox.about.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
user.sendRawMessage("About " + BentoBox.getInstance().getDescription().getName() + " v" + BentoBox.getInstance().getDescription().getVersion() + ":");
|
||||
user.sendRawMessage("Copyright (c) 2017 - 2018 Tastybento, Poslovitch");
|
||||
user.sendRawMessage("See https://www.eclipse.org/legal/epl-2.0/ for license information.");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package world.bentobox.bentobox.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class BentoBoxCommand extends CompositeCommand {
|
||||
|
||||
/**
|
||||
* About
|
||||
* @param islandCommand - parent command
|
||||
*/
|
||||
public BentoBoxCommand() {
|
||||
super("bentobox", "bbox");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setDescription("commands.bentobox.description");
|
||||
new InfoCommand(this);
|
||||
new AboutCommand(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
showHelp(this, user);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package world.bentobox.bentobox.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class InfoCommand extends CompositeCommand {
|
||||
|
||||
/**
|
||||
* Info command
|
||||
* @param parent
|
||||
*/
|
||||
public InfoCommand(CompositeCommand parent) {
|
||||
super(parent, "info");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setDescription("commands.bentobox.info.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
user.sendMessage("commands.bentobox.info.loaded-game-worlds");
|
||||
getIWM().getOverWorldNames().forEach(n -> user.sendMessage("commands.bentobox.info.game-worlds", TextVariables.NAME, n));
|
||||
user.sendMessage("commands.bentobox.info.loaded-addons");
|
||||
getPlugin().getAddonsManager()
|
||||
.getAddons()
|
||||
.forEach(a -> user.sendMessage("commands.bentobox.info.addon-syntax", TextVariables.NAME, a.getDescription().getName(),
|
||||
TextVariables.VERSION, a.getDescription().getVersion()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -48,6 +48,7 @@ commands:
|
||||
end: "&7================================="
|
||||
parameters: "[command]"
|
||||
description: "help command"
|
||||
console: "Console"
|
||||
admin:
|
||||
help:
|
||||
parameters: ""
|
||||
@ -170,9 +171,20 @@ commands:
|
||||
look-at-a-block: "&cLook at block within 20 blocks to set"
|
||||
world:
|
||||
description: "Manage world settings"
|
||||
island:
|
||||
bentobox:
|
||||
parameters: ""
|
||||
description: "BentoBox admin command"
|
||||
about:
|
||||
parameters: ""
|
||||
description: "display copyright and license info"
|
||||
info:
|
||||
parameters: ""
|
||||
description: "display info"
|
||||
loaded-addons: "Loaded Add-Ons"
|
||||
loaded-game-worlds: "Loaded Game Worlds"
|
||||
addon-syntax: "&2[name] &3[version]"
|
||||
game-worlds: "&2[name]"
|
||||
island:
|
||||
go:
|
||||
parameters: "[home number]"
|
||||
description: "teleport you to your island"
|
||||
|
@ -10,6 +10,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.junit.Before;
|
||||
@ -70,6 +71,7 @@ public class DefaultHelpCommandTest {
|
||||
CompositeCommand ic = mock(CompositeCommand.class);
|
||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
|
||||
|
||||
// No island for player to begin with (set it later in the tests)
|
||||
IslandsManager im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(false);
|
||||
@ -139,6 +141,7 @@ public class DefaultHelpCommandTest {
|
||||
when(parent.getParameters()).thenReturn("parameters");
|
||||
when(parent.getDescription()).thenReturn("description");
|
||||
when(parent.getPermission()).thenReturn("permission");
|
||||
when(parent.getWorld()).thenReturn(mock(World.class));
|
||||
when(user.getTranslation("island")).thenReturn("island");
|
||||
when(user.getTranslation("parameters")).thenReturn("");
|
||||
when(user.getTranslation("description")).thenReturn("the main island command");
|
||||
|
@ -8,6 +8,7 @@ import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
@ -25,7 +26,6 @@ import org.powermock.reflect.Whitebox;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.range.AdminRangeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
@ -77,11 +77,13 @@ public class AdminRangeCommandTest {
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
when(user.getTranslation("commands.help.console")).thenReturn("Console");
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Parent command has no aliases
|
||||
ac = mock(CompositeCommand.class);
|
||||
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
when(ac.getWorld()).thenReturn(mock(World.class));
|
||||
|
||||
// Island World Manager
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
|
@ -12,6 +12,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
@ -29,7 +30,6 @@ import org.powermock.reflect.Whitebox;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.range.AdminRangeResetCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
@ -92,6 +92,7 @@ public class AdminRangeResetCommandTest {
|
||||
// Parent command has no aliases
|
||||
ac = mock(CompositeCommand.class);
|
||||
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
when(ac.getWorld()).thenReturn(mock(World.class));
|
||||
|
||||
// Island World Manager
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
|
@ -12,6 +12,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
@ -29,7 +30,6 @@ import org.powermock.reflect.Whitebox;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.range.AdminRangeSetCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
@ -92,6 +92,7 @@ public class AdminRangeSetCommandTest {
|
||||
// Parent command has no aliases
|
||||
ac = mock(CompositeCommand.class);
|
||||
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
when(ac.getWorld()).thenReturn(mock(World.class));
|
||||
|
||||
// Island World Manager
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
|
Loading…
Reference in New Issue
Block a user