mirror of
https://github.com/BentoBoxWorld/BSkyBlock.git
synced 2024-11-22 11:45:36 +01:00
Upgraded to BentoBox 1.13.0 API
This commit is contained in:
parent
97485dc237
commit
baba69a74c
@ -9,10 +9,11 @@ import org.bukkit.generator.ChunkGenerator;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.api.commands.admin.DefaultAdminCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.DefaultPlayerCommand;
|
||||
import world.bentobox.bentobox.api.configuration.Config;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
import world.bentobox.bskyblock.commands.AdminCommand;
|
||||
import world.bentobox.bskyblock.commands.IslandCommand;
|
||||
import world.bentobox.bskyblock.commands.IslandAboutCommand;
|
||||
import world.bentobox.bskyblock.generators.ChunkGeneratorWorld;
|
||||
|
||||
/**
|
||||
@ -39,8 +40,17 @@ public class BSkyBlock extends GameModeAddon implements Listener {
|
||||
// Chunk generator
|
||||
chunkGenerator = settings.isUseOwnGenerator() ? null : new ChunkGeneratorWorld(this);
|
||||
// Register commands
|
||||
playerCommand = new IslandCommand(this);
|
||||
adminCommand = new AdminCommand(this);
|
||||
playerCommand = new DefaultPlayerCommand(this)
|
||||
|
||||
{
|
||||
@Override
|
||||
public void setup()
|
||||
{
|
||||
super.setup();
|
||||
new IslandAboutCommand(this);
|
||||
}
|
||||
};
|
||||
adminCommand = new DefaultAdminCommand(this) {};
|
||||
}
|
||||
|
||||
private boolean loadSettings() {
|
||||
|
@ -33,16 +33,24 @@ public class Settings implements WorldSettings {
|
||||
@ConfigComment("Island Command. What command users will run to access their island.")
|
||||
@ConfigComment("To define alias, just separate commands with white space.")
|
||||
@ConfigEntry(path = "bskyblock.command.island", since = "1.3.0")
|
||||
private String islandCommand = "island is skyblock sb";
|
||||
private String playerCommandAliases = "island is skyblock sb";
|
||||
|
||||
@ConfigComment("The island admin command.")
|
||||
@ConfigComment("To define alias, just separate commands with white space.")
|
||||
@ConfigEntry(path = "bskyblock.command.admin", since = "1.3.0")
|
||||
private String adminCommand = "bsbadmin bsb skyblockadmin sbadmin sba";
|
||||
private String adminCommandAliases = "bsbadmin bsb skyblockadmin sbadmin sba";
|
||||
|
||||
@ConfigComment("Use control panel if it exists (ControlPanel addon must be in addons)")
|
||||
@ConfigEntry(path = "bskyblock.use-control-panel", since = "1.13.0")
|
||||
private boolean useControlPanel = false;
|
||||
@ConfigComment("The default action for new player command call.")
|
||||
@ConfigComment("Sub-command of main player command that will be run on first player command call.")
|
||||
@ConfigComment("By default it is sub-command 'create'.")
|
||||
@ConfigEntry(path = "bskyblock.command.new-player-action", since = "1.13.1")
|
||||
private String defaultNewPlayerAction = "create";
|
||||
|
||||
@ConfigComment("The default action for player command.")
|
||||
@ConfigComment("Sub-command of main player command that will be run on each player command call.")
|
||||
@ConfigComment("By default it is sub-command 'go'.")
|
||||
@ConfigEntry(path = "bskyblock.command.default-action", since = "1.13.1")
|
||||
private String defaultPlayerAction = "go";
|
||||
|
||||
/* WORLD */
|
||||
@ConfigComment("Friendly name for this world. Used in admin commands. Must be a single word")
|
||||
@ -441,6 +449,11 @@ public class Settings implements WorldSettings {
|
||||
@ConfigEntry(path = "protection.geo-limit-settings")
|
||||
private List<String> geoLimitSettings = new ArrayList<>();
|
||||
|
||||
@ConfigComment("BSkyBlock blocked mobs.")
|
||||
@ConfigComment("List of mobs that should not spawn in BSkyBlock.")
|
||||
@ConfigEntry(path = "protection.block-mobs", since = "1.13.1")
|
||||
private List<String> mobLimitSettings = new ArrayList<>();
|
||||
|
||||
// Invincible visitor settings
|
||||
@ConfigComment("Invincible visitors. List of damages that will not affect visitors.")
|
||||
@ConfigComment("Make list blank if visitors should receive all damages")
|
||||
@ -1288,46 +1301,34 @@ public class Settings implements WorldSettings {
|
||||
this.banLimit = banLimit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method returns the islandCommand value.
|
||||
* @return the value of islandCommand.
|
||||
* @return the playerCommandAliases
|
||||
*/
|
||||
public String getIslandCommand()
|
||||
{
|
||||
return islandCommand;
|
||||
@Override
|
||||
public String getPlayerCommandAliases() {
|
||||
return playerCommandAliases;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method sets the islandCommand value.
|
||||
* @param islandCommand the islandCommand new value.
|
||||
*
|
||||
* @param playerCommandAliases the playerCommandAliases to set
|
||||
*/
|
||||
public void setIslandCommand(String islandCommand)
|
||||
{
|
||||
this.islandCommand = islandCommand;
|
||||
public void setPlayerCommandAliases(String playerCommandAliases) {
|
||||
this.playerCommandAliases = playerCommandAliases;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method returns the adminCommand value.
|
||||
* @return the value of adminCommand.
|
||||
* @return the adminCommandAliases
|
||||
*/
|
||||
public String getAdminCommand()
|
||||
{
|
||||
return adminCommand;
|
||||
@Override
|
||||
public String getAdminCommandAliases() {
|
||||
return adminCommandAliases;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method sets the adminCommand value.
|
||||
* @param adminCommand the adminCommand new value.
|
||||
*
|
||||
* @param adminCommandAliases the adminCommandAliases to set
|
||||
*/
|
||||
public void setAdminCommand(String adminCommand)
|
||||
{
|
||||
this.adminCommand = adminCommand;
|
||||
public void setAdminCommandAliases(String adminCommandAliases) {
|
||||
this.adminCommandAliases = adminCommandAliases;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1614,16 +1615,47 @@ public class Settings implements WorldSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the useControlPanel
|
||||
* @return the defaultNewPlayerAction
|
||||
*/
|
||||
public boolean isUseControlPanel() {
|
||||
return useControlPanel;
|
||||
@Override
|
||||
public String getDefaultNewPlayerAction() {
|
||||
return defaultNewPlayerAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param useControlPanel the useControlPanel to set
|
||||
* @param defaultNewPlayerAction the defaultNewPlayerAction to set
|
||||
*/
|
||||
public void setUseControlPanel(boolean useControlPanel) {
|
||||
this.useControlPanel = useControlPanel;
|
||||
public void setDefaultNewPlayerAction(String defaultNewPlayerAction) {
|
||||
this.defaultNewPlayerAction = defaultNewPlayerAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the defaultPlayerAction
|
||||
*/
|
||||
@Override
|
||||
public String getDefaultPlayerAction() {
|
||||
return defaultPlayerAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param defaultPlayerAction the defaultPlayerAction to set
|
||||
*/
|
||||
public void setDefaultPlayerAction(String defaultPlayerAction) {
|
||||
this.defaultPlayerAction = defaultPlayerAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the mobLimitSettings
|
||||
*/
|
||||
@Override
|
||||
public List<String> getMobLimitSettings() {
|
||||
return mobLimitSettings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mobLimitSettings the mobLimitSettings to set
|
||||
*/
|
||||
public void setMobLimitSettings(List<String> mobLimitSettings) {
|
||||
this.mobLimitSettings = mobLimitSettings;
|
||||
}
|
||||
}
|
||||
|
@ -1,103 +0,0 @@
|
||||
package world.bentobox.bskyblock.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.AdminDeleteCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.AdminGetrankCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.AdminInfoCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.AdminRegisterCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.AdminReloadCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.AdminResetFlagsCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.AdminSetrankCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.AdminSetspawnCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.AdminSettingsCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.AdminSwitchCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.AdminTeleportCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.AdminUnregisterCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.AdminVersionCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.AdminWhyCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.blueprints.AdminBlueprintCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.deaths.AdminDeathsCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.purge.AdminPurgeCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.range.AdminRangeCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.resets.AdminResetsCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.team.AdminTeamAddCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.team.AdminTeamDisbandCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.team.AdminTeamKickCommand;
|
||||
import world.bentobox.bentobox.api.commands.admin.team.AdminTeamSetownerCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bskyblock.BSkyBlock;
|
||||
|
||||
public class AdminCommand extends CompositeCommand {
|
||||
|
||||
public AdminCommand(BSkyBlock addon) {
|
||||
super(addon,
|
||||
addon.getSettings().getAdminCommand().split(" ")[0],
|
||||
addon.getSettings().getAdminCommand().split(" "));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.*");
|
||||
setOnlyPlayer(false);
|
||||
setParametersHelp("commands.admin.help.parameters");
|
||||
setDescription("commands.admin.help.description");
|
||||
new AdminVersionCommand(this);
|
||||
new AdminTeleportCommand(this, "tp");
|
||||
new AdminTeleportCommand(this, "tpnether");
|
||||
new AdminTeleportCommand(this, "tpend");
|
||||
new AdminGetrankCommand(this);
|
||||
new AdminSetrankCommand(this);
|
||||
new AdminInfoCommand(this);
|
||||
// Team commands
|
||||
new AdminTeamAddCommand(this);
|
||||
new AdminTeamKickCommand(this);
|
||||
new AdminTeamDisbandCommand(this);
|
||||
new AdminTeamSetownerCommand(this);
|
||||
// Schems
|
||||
new AdminBlueprintCommand(this);
|
||||
// Register/unregister islands
|
||||
new AdminRegisterCommand(this);
|
||||
new AdminUnregisterCommand(this);
|
||||
// Range
|
||||
new AdminRangeCommand(this);
|
||||
// Resets
|
||||
new AdminResetsCommand(this);
|
||||
// Delete
|
||||
new AdminDeleteCommand(this);
|
||||
// Why
|
||||
new AdminWhyCommand(this);
|
||||
// Deaths
|
||||
new AdminDeathsCommand(this);
|
||||
// Reload
|
||||
new AdminReloadCommand(this);
|
||||
// Spawn
|
||||
new AdminSetspawnCommand(this);
|
||||
// Reset flags
|
||||
new AdminResetFlagsCommand(this);
|
||||
// Trash
|
||||
//new AdminTrashCommand(this);
|
||||
//new AdminEmptyTrashCommand(this);
|
||||
//new AdminSwitchtoCommand(this);
|
||||
// Switch
|
||||
new AdminSwitchCommand(this);
|
||||
// Purge
|
||||
new AdminPurgeCommand(this);
|
||||
// Settings
|
||||
new AdminSettingsCommand(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (!args.isEmpty()) {
|
||||
user.sendMessage("general.errors.unknown-command", TextVariables.LABEL, getTopLabel());
|
||||
return false;
|
||||
}
|
||||
// By default run the attached help command, if it exists (it should)
|
||||
return showHelp(this, user);
|
||||
}
|
||||
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
package world.bentobox.bskyblock.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandBanCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandBanlistCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandCreateCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandExpelCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandGoCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandInfoCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandLanguageCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandNearCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandResetCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandResetnameCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandSethomeCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandSetnameCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandSettingsCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandSpawnCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.IslandUnbanCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bskyblock.BSkyBlock;
|
||||
|
||||
public class IslandCommand extends CompositeCommand {
|
||||
|
||||
public IslandCommand(BSkyBlock addon) {
|
||||
super(addon,
|
||||
addon.getSettings().getIslandCommand().split(" ")[0],
|
||||
addon.getSettings().getIslandCommand().split(" "));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see us.tastybento.bskyblock.api.commands.CompositeCommand#setup()
|
||||
*/
|
||||
@Override
|
||||
public void setup() {
|
||||
setDescription("commands.island.help.description");
|
||||
setOnlyPlayer(true);
|
||||
// Permission
|
||||
setPermission("island");
|
||||
// Set up subcommands
|
||||
new IslandAboutCommand(this);
|
||||
new IslandInfoCommand(this);
|
||||
new IslandCreateCommand(this);
|
||||
new IslandGoCommand(this);
|
||||
new IslandSpawnCommand(this);
|
||||
new IslandResetCommand(this);
|
||||
new IslandSetnameCommand(this);
|
||||
new IslandResetnameCommand(this);
|
||||
new IslandSethomeCommand(this);
|
||||
new IslandSettingsCommand(this);
|
||||
new IslandLanguageCommand(this);
|
||||
new IslandBanCommand(this);
|
||||
new IslandUnbanCommand(this);
|
||||
new IslandBanlistCommand(this);
|
||||
new IslandExpelCommand(this);
|
||||
new IslandNearCommand(this);
|
||||
// Team commands
|
||||
new IslandTeamCommand(this);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see us.tastybento.bskyblock.api.commands.CommandArgument#execute(org.bukkit.command.CommandSender, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (user == null) {
|
||||
return false;
|
||||
}
|
||||
if (args.isEmpty()) {
|
||||
// If user has an island, go
|
||||
if (getPlugin().getIslands().getIsland(getWorld(), user.getUniqueId()) != null) {
|
||||
if (((BSkyBlock)getAddon()).getSettings().isUseControlPanel()
|
||||
&& getSubCommand("controlpanel").isPresent()) {
|
||||
return getSubCommand("controlpanel").get().call(user, label, new ArrayList<>());
|
||||
}
|
||||
return getSubCommand("go").map(goCmd -> goCmd.call(user, goCmd.getLabel(), new ArrayList<>())).orElse(false);
|
||||
}
|
||||
// No islands currently
|
||||
return getSubCommand("create").map(createCmd -> createCmd.call(user, createCmd.getLabel(), new ArrayList<>())).orElse(false);
|
||||
}
|
||||
user.sendMessage("general.errors.unknown-command", TextVariables.LABEL, getTopLabel());
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
name: BSkyBlock
|
||||
main: world.bentobox.bskyblock.BSkyBlock
|
||||
version: ${version}${build.number}
|
||||
api-version: 1.13.0
|
||||
metrics: true
|
||||
icon: "OAK_SAPLING"
|
||||
repository: "BentoBoxWorld/BSkyBlock"
|
||||
|
@ -1,4 +1,4 @@
|
||||
# BSkyBlock Configuration ${version}
|
||||
# BSkyBlock Configuration {$version}
|
||||
bskyblock:
|
||||
command:
|
||||
# Island Command. What command users will run to access their island.
|
||||
@ -9,8 +9,16 @@ bskyblock:
|
||||
# To define alias, just separate commands with white space.
|
||||
# Added since 1.3.0.
|
||||
admin: bsbadmin bsb skyblockadmin sbadmin sba
|
||||
# Use control panel if it exists (ControlPanel addon must be in addons)
|
||||
use-control-panel: false
|
||||
# The default action for new player command call.
|
||||
# Sub-command of main player command that will be run on first player command call.
|
||||
# By default it is sub-command 'create'.
|
||||
# Added since 1.13.1.
|
||||
new-player-action: create
|
||||
# The default action for player command.
|
||||
# Sub-command of main player command that will be run on each player command call.
|
||||
# By default it is sub-command 'go'.
|
||||
# Added since 1.13.1.
|
||||
default-action: go
|
||||
world:
|
||||
# Friendly name for this world. Used in admin commands. Must be a single word
|
||||
friendly-name: BSkyBlock
|
||||
@ -113,10 +121,10 @@ world:
|
||||
dragon-spawn: false
|
||||
# Mob white list - these mobs will NOT be removed when logging in or doing /island
|
||||
remove-mobs-whitelist:
|
||||
- WITHER
|
||||
- PIG_ZOMBIE
|
||||
- ZOMBIE_VILLAGER
|
||||
- ENDERMAN
|
||||
- PIG_ZOMBIE
|
||||
- WITHER
|
||||
# World flags. These are boolean settings for various flags for this world
|
||||
flags:
|
||||
CREEPER_DAMAGE: true
|
||||
@ -128,12 +136,15 @@ world:
|
||||
CLEAN_SUPER_FLAT: false
|
||||
CHEST_DAMAGE: false
|
||||
PREVENT_TELEPORT_WHEN_FALLING: false
|
||||
NATURAL_SPAWNING_OUTSIDE_RANGE: true
|
||||
ENTER_EXIT_MESSAGES: true
|
||||
ENDERMAN_DEATH_DROP: true
|
||||
OFFLINE_REDSTONE: true
|
||||
REMOVE_END_EXIT_ISLAND: true
|
||||
REMOVE_MOBS: true
|
||||
ENDER_CHEST: false
|
||||
ITEM_FRAME_DAMAGE: false
|
||||
TREES_GROWING_OUTSIDE_RANGE: false
|
||||
# These are the default protection settings for new islands.
|
||||
# The value is the minimum island rank required allowed to do the action
|
||||
# Ranks are the following:
|
||||
@ -169,8 +180,8 @@ world:
|
||||
ITEM_DROP: 0
|
||||
NOTE_BLOCK: 0
|
||||
NETHER_PORTAL: 500
|
||||
ITEM_PICKUP: 0
|
||||
CROP_TRAMPLE: 500
|
||||
ITEM_PICKUP: 0
|
||||
BREWING: 500
|
||||
DROPPER: 500
|
||||
COLLECT_WATER: 500
|
||||
@ -182,8 +193,8 @@ world:
|
||||
ITEM_FRAME: 500
|
||||
PLACE_BLOCKS: 500
|
||||
CRAFTING: 0
|
||||
ENCHANTING: 0
|
||||
SHEARING: 500
|
||||
ENCHANTING: 0
|
||||
SPAWN_EGGS: 500
|
||||
BED: 500
|
||||
MILKING: 0
|
||||
@ -234,7 +245,6 @@ island:
|
||||
# permission size cannot be less than the default below.
|
||||
# Added since 1.13.0.
|
||||
max-trusted-size: 4
|
||||
|
||||
# Default maximum number of homes a player can have. Min = 1
|
||||
# Accessed via /is sethome <number> or /is go <number>
|
||||
max-homes: 1
|
||||
@ -390,6 +400,10 @@ protection:
|
||||
- GHAST
|
||||
- BAT
|
||||
- BLAZE
|
||||
# BSkyBlock blocked mobs.
|
||||
# List of mobs that should not spawn in BSkyBlock.
|
||||
# Added since 1.13.1.
|
||||
block-mobs: []
|
||||
# Invincible visitors. List of damages that will not affect visitors.
|
||||
# Make list blank if visitors should receive all damages
|
||||
invincible-visitors:
|
||||
@ -420,4 +434,3 @@ protection:
|
||||
do-not-edit-these-settings:
|
||||
# These settings should not be edited
|
||||
reset-epoch: 0
|
||||
|
||||
|
@ -494,8 +494,8 @@ public class SettingsTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetIslandCommand() {
|
||||
s.setIslandCommand("island");
|
||||
assertEquals("island", s.getIslandCommand());
|
||||
s.setPlayerCommandAliases("island");
|
||||
assertEquals("island", s.getPlayerCommandAliases());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -503,8 +503,8 @@ public class SettingsTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGetAdminCommand() {
|
||||
s.setAdminCommand("admin");
|
||||
assertEquals("admin", s.getAdminCommand());
|
||||
s.setAdminCommandAliases("admin");
|
||||
assertEquals("admin", s.getAdminCommandAliases());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,129 +0,0 @@
|
||||
package world.bentobox.bskyblock.commands;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bskyblock.BSkyBlock;
|
||||
import world.bentobox.bskyblock.Settings;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class AdminCommandTest {
|
||||
|
||||
private static final int NUM_COMMANDS = 26;
|
||||
@Mock
|
||||
private User user;
|
||||
@Mock
|
||||
private BSkyBlock addon;
|
||||
@Mock
|
||||
private FlagsManager fm;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
when(user.isOp()).thenReturn(false);
|
||||
UUID uuid = UUID.randomUUID();
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Locales
|
||||
// Return the reference (USE THIS IN THE FUTURE)
|
||||
when(user.getTranslation(Mockito.anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||
|
||||
Settings settings = mock(Settings.class);
|
||||
when(settings.getAdminCommand()).thenReturn("bsbadmin");
|
||||
when(addon.getSettings()).thenReturn(settings);
|
||||
|
||||
// Flags manager
|
||||
when(plugin.getFlagsManager()).thenReturn(fm);
|
||||
when(fm.getFlags()).thenReturn(Collections.emptyList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bskyblock.commands.AdminCommand#AdminCommand(world.bentobox.bentobox.api.addons.Addon, java.lang.String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testAdminCommand() {
|
||||
AdminCommand cmd = new AdminCommand(addon);
|
||||
assertEquals("bsbadmin", cmd.getLabel());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bskyblock.commands.AdminCommand#setup()}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetup() {
|
||||
when(addon.getPermissionPrefix()).thenReturn("bskyblock.");
|
||||
AdminCommand cmd = new AdminCommand(addon);
|
||||
assertEquals("bskyblock.admin.*", cmd.getPermission());
|
||||
assertFalse(cmd.isOnlyPlayer());
|
||||
assertEquals("commands.admin.help.parameters", cmd.getParameters());
|
||||
assertEquals("commands.admin.help.description", cmd.getDescription());
|
||||
// Number of commands = sub commands + help
|
||||
assertEquals("Number of sub commands registered", NUM_COMMANDS, cmd.getSubCommands().values().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bskyblock.commands.AdminCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringUnknownCommand() {
|
||||
AdminCommand cmd = new AdminCommand(addon);
|
||||
assertFalse(cmd.execute(user, "bsbadmin", Collections.singletonList("unknown")));
|
||||
Mockito.verify(user).sendMessage("general.errors.unknown-command", TextVariables.LABEL, "bsbadmin");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bskyblock.commands.AdminCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoCommand() {
|
||||
AdminCommand cmd = new AdminCommand(addon);
|
||||
assertTrue(cmd.execute(user, "bsbadmin", Collections.emptyList()));
|
||||
// Show help
|
||||
Mockito.verify(user).sendMessage("commands.help.header", TextVariables.LABEL, "commands.help.console");
|
||||
}
|
||||
|
||||
}
|
@ -1,236 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package world.bentobox.bskyblock.commands;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.BlueprintsManager;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bskyblock.BSkyBlock;
|
||||
import world.bentobox.bskyblock.Settings;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class IslandCommandTest {
|
||||
|
||||
private static final int NUMBER_OF_COMMANDS = 18;
|
||||
private User user;
|
||||
private IslandsManager im;
|
||||
private Island island;
|
||||
private BSkyBlock addon;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Set up plugin
|
||||
BentoBox plugin = mock(BentoBox.class);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
||||
// Command manager
|
||||
CommandsManager cm = mock(CommandsManager.class);
|
||||
when(plugin.getCommandsManager()).thenReturn(cm);
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
user = mock(User.class);
|
||||
when(user.isOp()).thenReturn(false);
|
||||
UUID uuid = UUID.randomUUID();
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getName()).thenReturn("tastybento");
|
||||
when(user.isPlayer()).thenReturn(true);
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Island World Manager
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
island = mock(Island.class);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(island);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Locales
|
||||
// Return the reference (USE THIS IN THE FUTURE)
|
||||
when(user.getTranslation(Mockito.anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||
|
||||
addon = mock(BSkyBlock.class);
|
||||
Settings settings = mock(Settings.class);
|
||||
when(settings.getIslandCommand()).thenReturn("island");
|
||||
when(addon.getSettings()).thenReturn(settings);
|
||||
when(plugin.getSettings()).thenReturn(mock(world.bentobox.bentobox.Settings.class));
|
||||
|
||||
// Blueprints
|
||||
BlueprintsManager bpm = mock(BlueprintsManager.class);
|
||||
Map<String, BlueprintBundle> map = new HashMap<>();
|
||||
BlueprintBundle bun = mock(BlueprintBundle.class);
|
||||
when(bun.getDisplayName()).thenReturn("aaa", "bbb");
|
||||
map.put("aaa", bun);
|
||||
map.put("bbb", bun);
|
||||
when(bun.getUniqueId()).thenReturn("unique1", "unique2");
|
||||
when(bun.isRequirePermission()).thenReturn(true);
|
||||
when(bpm.getBlueprintBundles(Mockito.any())).thenReturn(map);
|
||||
when(plugin.getBlueprintsManager()).thenReturn(bpm);
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
PluginManager pim = mock(PluginManager.class);
|
||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||
BukkitScheduler sch = mock(BukkitScheduler.class);
|
||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bskyblock.commands.IslandCommand#IslandCommand(world.bentobox.bentobox.api.addons.Addon, java.lang.String)}.
|
||||
*/
|
||||
@Test
|
||||
public void testIslandCommand() {
|
||||
IslandCommand cmd = new IslandCommand(addon);
|
||||
assertEquals("island", cmd.getLabel());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bskyblock.commands.IslandCommand#setup()}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetup() {
|
||||
when(addon.getPermissionPrefix()).thenReturn("bskyblock.");
|
||||
IslandCommand cmd = new IslandCommand(addon);
|
||||
assertEquals("bskyblock.island", cmd.getPermission());
|
||||
assertTrue(cmd.isOnlyPlayer());
|
||||
assertEquals("commands.island.parameters", cmd.getParameters());
|
||||
assertEquals("commands.island.help.description", cmd.getDescription());
|
||||
// Number of commands = sub commands + help
|
||||
assertEquals("Number of sub commands registered", NUMBER_OF_COMMANDS, cmd.getSubCommands().values().size());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bskyblock.commands.IslandCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNullUsers() {
|
||||
IslandCommand cmd = new IslandCommand(addon);
|
||||
assertFalse(cmd.execute(null, "island", Collections.emptyList()));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bskyblock.commands.IslandCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringUnknownCommand() {
|
||||
IslandCommand cmd = new IslandCommand(addon);
|
||||
assertFalse(cmd.execute(user, "island", Collections.singletonList("unknown")));
|
||||
verify(user).sendMessage("general.errors.unknown-command", TextVariables.LABEL, "island");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bskyblock.commands.IslandCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoArgsNoPermission() {
|
||||
IslandCommand cmd = new IslandCommand(addon);
|
||||
assertFalse(cmd.execute(user, "island", Collections.emptyList()));
|
||||
verify(user).sendMessage("general.errors.no-permission", "[permission]", "island.home");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bskyblock.commands.IslandCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoArgsSuccess() {
|
||||
when(user.hasPermission(anyString())).thenReturn(true);
|
||||
IslandCommand cmd = new IslandCommand(addon);
|
||||
assertTrue(cmd.execute(user, "island", Collections.emptyList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bskyblock.commands.IslandCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoArgsConsole() {
|
||||
when(user.isPlayer()).thenReturn(false);
|
||||
IslandCommand cmd = new IslandCommand(addon);
|
||||
assertFalse(cmd.execute(user, "island", Collections.emptyList()));
|
||||
verify(user).sendMessage("general.errors.use-in-game");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bskyblock.commands.IslandCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoArgsNoIslandConsole() {
|
||||
when(user.isPlayer()).thenReturn(false);
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(null);
|
||||
IslandCommand cmd = new IslandCommand(addon);
|
||||
assertFalse(cmd.execute(user, "island", Collections.emptyList()));
|
||||
verify(user).sendMessage("general.errors.use-in-game");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bskyblock.commands.IslandCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoArgsNoIslandNoPermission() {
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(null);
|
||||
IslandCommand cmd = new IslandCommand(addon);
|
||||
assertFalse(cmd.execute(user, "island", Collections.emptyList()));
|
||||
verify(user).sendMessage("general.errors.no-permission", "[permission]", "island.create");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bskyblock.commands.IslandCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoArgsNoIslandCreateSuccess() {
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(null);
|
||||
when(user.hasPermission(Mockito.eq("island.create"))).thenReturn(true);
|
||||
IslandCommand cmd = new IslandCommand(addon);
|
||||
assertTrue(cmd.execute(user, "island", Collections.emptyList()));
|
||||
verify(user).getTranslation("commands.island.create.pick");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user