mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-11 01:41:51 +01:00
Merge branch 'develop'
This commit is contained in:
commit
0655b338bd
19
pom.xml
19
pom.xml
@ -15,12 +15,11 @@
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<name>Florian Cuny</name>
|
||||
<id>Poslovitch</id>
|
||||
<email>poslovitch@bentobox.world</email>
|
||||
<timezone>1</timezone>
|
||||
<roles>
|
||||
<role>Project manager</role>
|
||||
<role>Project Manager</role>
|
||||
<role>Developer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
@ -73,14 +72,16 @@
|
||||
<bstats.version>1.5</bstats.version>
|
||||
<vault.version>1.7</vault.version>
|
||||
<placeholderapi.version>2.10.3</placeholderapi.version>
|
||||
<mvdwplaceholderapi.version>2.5.1-SNAPSHOT</mvdwplaceholderapi.version>
|
||||
<githubapi.version>1.0</githubapi.version>
|
||||
<mvdwplaceholderapi.version>master-SNAPSHOT</mvdwplaceholderapi.version>
|
||||
<githubapi.version>d5f5e0bbd8</githubapi.version>
|
||||
<dynmap.version>3.0-SNAPSHOT</dynmap.version>
|
||||
<worldedit.version>7.0.0</worldedit.version>
|
||||
<!-- Revision variable removes warning about dynamic version -->
|
||||
<revision>${build.version}-SNAPSHOT</revision>
|
||||
<!-- 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.7.0</build.version>
|
||||
<build.version>1.8.0</build.version>
|
||||
</properties>
|
||||
|
||||
<!-- Profiles will allow to automatically change build version. -->
|
||||
@ -233,26 +234,26 @@
|
||||
thus making its repository unusable. -->
|
||||
<groupId>com.github.Prouser123-forks</groupId>
|
||||
<artifactId>MVdWPlaceholderAPI</artifactId>
|
||||
<version>master-SNAPSHOT</version>
|
||||
<version>${mvdwplaceholderapi.version}</version>
|
||||
</dependency>
|
||||
<!-- Hooks -->
|
||||
<dependency>
|
||||
<groupId>us.dynmap</groupId>
|
||||
<artifactId>dynmap-api</artifactId>
|
||||
<version>3.0-SNAPSHOT</version>
|
||||
<version>${dynmap.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-core</artifactId>
|
||||
<version>7.0.0</version>
|
||||
<version>${worldedit.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Shaded APIs -->
|
||||
<dependency>
|
||||
<groupId>com.github.TheBusyBiscuit</groupId>
|
||||
<artifactId>GitHubWebAPI4Java</artifactId>
|
||||
<version>d5f5e0bbd8</version>
|
||||
<version>${githubapi.version}</version>
|
||||
</dependency>
|
||||
<!-- Static analysis -->
|
||||
<!-- We are using Eclipse's annotations.
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
@ -25,7 +26,7 @@ import world.bentobox.bentobox.hooks.VaultHook;
|
||||
import world.bentobox.bentobox.hooks.WorldEditHook;
|
||||
import world.bentobox.bentobox.hooks.placeholders.MVdWPlaceholderAPIHook;
|
||||
import world.bentobox.bentobox.hooks.placeholders.PlaceholderAPIHook;
|
||||
import world.bentobox.bentobox.listeners.BannedVisitorCommands;
|
||||
import world.bentobox.bentobox.listeners.BannedCommands;
|
||||
import world.bentobox.bentobox.listeners.BlockEndDragon;
|
||||
import world.bentobox.bentobox.listeners.DeathListener;
|
||||
import world.bentobox.bentobox.listeners.JoinLeaveListener;
|
||||
@ -89,6 +90,8 @@ public class BentoBox extends JavaPlugin {
|
||||
|
||||
private Config<Settings> configObject;
|
||||
|
||||
private BukkitTask blueprintLoadingTask;
|
||||
|
||||
@Override
|
||||
public void onEnable(){
|
||||
if (!ServerCompatibility.getInstance().checkCompatibility().isCanLaunch()) {
|
||||
@ -163,7 +166,7 @@ public class BentoBox extends JavaPlugin {
|
||||
|
||||
final long loadTime = System.currentTimeMillis() - loadStart;
|
||||
|
||||
getServer().getScheduler().runTask(instance, () -> {
|
||||
Bukkit.getScheduler().runTask(instance, () -> {
|
||||
final long enableStart = System.currentTimeMillis();
|
||||
hooksManager.registerHook(new PlaceholderAPIHook());
|
||||
hooksManager.registerHook(new MVdWPlaceholderAPIHook());
|
||||
@ -183,9 +186,9 @@ public class BentoBox extends JavaPlugin {
|
||||
islandsManager.load();
|
||||
|
||||
// Save islands & players data every X minutes
|
||||
instance.getServer().getScheduler().runTaskTimer(instance, () -> {
|
||||
playersManager.saveAll();
|
||||
islandsManager.saveAll();
|
||||
Bukkit.getScheduler().runTaskTimer(instance, () -> {
|
||||
playersManager.asyncSaveAll();
|
||||
islandsManager.asyncSaveAll();
|
||||
}, getSettings().getDatabaseBackupPeriod() * 20 * 60L, getSettings().getDatabaseBackupPeriod() * 20 * 60L);
|
||||
|
||||
// Make sure all flag listeners are registered.
|
||||
@ -215,15 +218,24 @@ public class BentoBox extends JavaPlugin {
|
||||
TextVariables.VERSION, instance.getDescription().getVersion(),
|
||||
"[time]", String.valueOf(loadTime + enableTime));
|
||||
|
||||
// Fire plugin ready event - this should go last after everything else
|
||||
isLoaded = true;
|
||||
Bukkit.getServer().getPluginManager().callEvent(new BentoBoxReadyEvent());
|
||||
// Poll for blueprints loading to be finished - async so could be a completely variable time
|
||||
blueprintLoadingTask = Bukkit.getScheduler().runTaskTimer(instance, () -> {
|
||||
if (getBlueprintsManager().isBlueprintsLoaded()) {
|
||||
blueprintLoadingTask.cancel();
|
||||
// Tell all addons that everything is loaded
|
||||
isLoaded = true;
|
||||
this.addonsManager.allLoaded();
|
||||
// Fire plugin ready event - this should go last after everything else
|
||||
Bukkit.getPluginManager().callEvent(new BentoBoxReadyEvent());
|
||||
instance.log("All blueprints loaded.");
|
||||
}
|
||||
}, 0L, 1L);
|
||||
|
||||
if (getSettings().getDatabaseType().equals(DatabaseSetup.DatabaseType.YAML)) {
|
||||
logWarning("*** You're still using YAML database ! ***");
|
||||
logWarning("This database type is being deprecated from BentoBox as some official addons encountered difficulties supporting it correctly.");
|
||||
logWarning("You should switch ASAP to an alternative database type. Please refer to the comments in BentoBox's config.yml.");
|
||||
logWarning("There is NO warranty YAML database will remain properly supported in the following updates, and its usage should as such be considered a non-viable situation.");
|
||||
logWarning("There is NO guarantee YAML database will remain properly supported in the following updates, and its usage should as such be considered a non-viable situation.");
|
||||
logWarning("*** *** *** *** *** *** *** *** *** *** ***");
|
||||
}
|
||||
});
|
||||
@ -245,7 +257,7 @@ public class BentoBox extends JavaPlugin {
|
||||
// End dragon blocking
|
||||
manager.registerEvents(new BlockEndDragon(this), this);
|
||||
// Banned visitor commands
|
||||
manager.registerEvents(new BannedVisitorCommands(this), this);
|
||||
manager.registerEvents(new BannedCommands(this), this);
|
||||
// Death counter
|
||||
manager.registerEvents(new DeathListener(this), this);
|
||||
// Island Delete Manager
|
||||
|
@ -143,6 +143,11 @@ public class Settings implements ConfigObject {
|
||||
@ConfigEntry(path = "island.confirmation.commands.reset")
|
||||
private boolean resetConfirmation = true;
|
||||
|
||||
@ConfigComment("Ask the recipient to confirm trust or coop invites.")
|
||||
@ConfigComment("Team invites will always require confirmation, for safety concerns.")
|
||||
@ConfigEntry(path = "island.confirmation.invites", since = "1.8.0")
|
||||
private boolean inviteConfirmation = false;
|
||||
|
||||
@ConfigComment("Sets the minimum length an island custom name is required to have.")
|
||||
@ConfigEntry(path = "island.name.min-length")
|
||||
private int nameMinLength = 4;
|
||||
@ -560,5 +565,19 @@ public class Settings implements ConfigObject {
|
||||
this.clearRadius = clearRadius;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the inviteConfirmation
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public boolean isInviteConfirmation() {
|
||||
return inviteConfirmation;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @param inviteConfirmation the inviteConfirmation to set
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public void setInviteConfirmation(boolean inviteConfirmation) {
|
||||
this.inviteConfirmation = inviteConfirmation;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package world.bentobox.bentobox.api.addons;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@ -12,6 +13,7 @@ import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -244,8 +246,9 @@ public abstract class Addon {
|
||||
* - if true, will overwrite previous file
|
||||
* @param noPath
|
||||
* - if true, the resource's path will be ignored when saving
|
||||
* @return file written, or null if none
|
||||
*/
|
||||
public void saveResource(String jarResource, File destinationFolder, boolean replace, boolean noPath) {
|
||||
public File saveResource(String jarResource, File destinationFolder, boolean replace, boolean noPath) {
|
||||
if (jarResource == null || jarResource.equals("")) {
|
||||
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
|
||||
}
|
||||
@ -269,6 +272,7 @@ public abstract class Addon {
|
||||
if (!outFile.exists() || replace) {
|
||||
java.nio.file.Files.copy(in, outFile.toPath());
|
||||
}
|
||||
return outFile;
|
||||
}
|
||||
} else {
|
||||
// No file in the jar
|
||||
@ -279,6 +283,31 @@ public abstract class Addon {
|
||||
BentoBox.getInstance().logError(
|
||||
"Could not save from jar file. From " + jarResource + " to " + destinationFolder.getAbsolutePath());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to load a YAML file from the Jar
|
||||
* @param jarResource - YAML file in jar
|
||||
* @return YamlConfiguration - may be empty
|
||||
* @throws IOException - if the file cannot be found or loaded from the Jar
|
||||
* @throws InvalidConfigurationException - if the yaml is malformed
|
||||
*/
|
||||
public YamlConfiguration getYamlFromJar(String jarResource) throws IOException, InvalidConfigurationException {
|
||||
if (jarResource == null || jarResource.equals("")) {
|
||||
throw new IllegalArgumentException("jarResource cannot be null or empty");
|
||||
}
|
||||
YamlConfiguration result = new YamlConfiguration();
|
||||
jarResource = jarResource.replace('\\', '/');
|
||||
try (JarFile jar = new JarFile(file)) {
|
||||
JarEntry jarConfig = jar.getJarEntry(jarResource);
|
||||
if (jarConfig != null) {
|
||||
try (InputStreamReader in = new InputStreamReader(jar.getInputStream(jarConfig))) {
|
||||
result.load(in);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -418,4 +447,10 @@ public abstract class Addon {
|
||||
public boolean registerFlag(Flag flag) {
|
||||
return getPlugin().getFlagsManager().registerFlag(this, flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when all addons have been loaded by BentoBox
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public void allLoaded() {}
|
||||
}
|
||||
|
@ -673,8 +673,9 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
/**
|
||||
* @return the addon
|
||||
*/
|
||||
public Addon getAddon() {
|
||||
return addon;
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Addon> T getAddon() {
|
||||
return (T) addon;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
@ -76,6 +77,17 @@ public class AdminDeleteCommand extends ConfirmableCommand {
|
||||
// Remove them from this island (it still exists and will be deleted later)
|
||||
getIslands().removePlayer(getWorld(), targetUUID);
|
||||
if (target.isOnline()) {
|
||||
// Execute commands when leaving
|
||||
getIWM().getOnLeaveCommands(getWorld()).forEach(command -> {
|
||||
command = command.replace("[player]", target.getName());
|
||||
if (command.startsWith("[SUDO]")) {
|
||||
// Execute the command by the player
|
||||
target.performCommand(command.substring(6));
|
||||
} else {
|
||||
// Otherwise execute as the server console
|
||||
getPlugin().getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
}
|
||||
});
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
target.getPlayer().getEnderChest().clear();
|
||||
@ -86,6 +98,20 @@ public class AdminDeleteCommand extends ConfirmableCommand {
|
||||
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
||||
getPlugin().getVault().ifPresent(vault -> vault.withdraw(target, vault.getBalance(target)));
|
||||
}
|
||||
// Reset the health
|
||||
if (getIWM().isOnLeaveResetHealth(getWorld())) {
|
||||
target.getPlayer().setHealth(20.0D);
|
||||
}
|
||||
|
||||
// Reset the hunger
|
||||
if (getIWM().isOnLeaveResetHunger(getWorld())) {
|
||||
target.getPlayer().setFoodLevel(20);
|
||||
}
|
||||
|
||||
// Reset the XP
|
||||
if (getIWM().isOnLeaveResetXP(getWorld())) {
|
||||
target.getPlayer().setTotalExperience(0);
|
||||
}
|
||||
}
|
||||
vector = oldIsland.getCenter().toVector();
|
||||
getIslands().deleteIsland(oldIsland, true, targetUUID);
|
||||
|
@ -66,10 +66,23 @@ public class AdminRegisterCommand extends ConfirmableCommand {
|
||||
user.sendMessage("commands.admin.register.already-owned");
|
||||
return false;
|
||||
}
|
||||
// Check if island is spawn
|
||||
if (island.map(i -> i.isSpawn()).orElse(false)) {
|
||||
askConfirmation(user, user.getTranslation("commands.admin.register.island-is-spawn"), () -> register(user, targetUUID, island, closestIsland));
|
||||
return false;
|
||||
}
|
||||
return register(user, targetUUID, island, closestIsland);
|
||||
|
||||
}
|
||||
|
||||
private boolean register(User user, UUID targetUUID, Optional<Island> island, Location closestIsland) {
|
||||
// Register island if it exists
|
||||
if (!island.map(i -> {
|
||||
// Island exists
|
||||
getIslands().setOwner(user, targetUUID, i);
|
||||
if (i.isSpawn()) {
|
||||
getIslands().clearSpawn(i.getWorld());
|
||||
}
|
||||
user.sendMessage("commands.admin.register.registered-island", "[xyz]", Util.xyz(i.getCenter().toVector()));
|
||||
user.sendMessage("general.success");
|
||||
IslandBaseEvent event = IslandEvent.builder()
|
||||
@ -79,7 +92,7 @@ public class AdminRegisterCommand extends ConfirmableCommand {
|
||||
.involvedPlayer(targetUUID)
|
||||
.admin(true)
|
||||
.build();
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
return true;
|
||||
}).orElse(false)) {
|
||||
// Island does not exist - this is a reservation
|
||||
@ -102,11 +115,12 @@ public class AdminRegisterCommand extends ConfirmableCommand {
|
||||
.involvedPlayer(targetUUID)
|
||||
.admin(true)
|
||||
.build();
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,10 +1,17 @@
|
||||
package world.bentobox.bentobox.api.commands.admin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||
import world.bentobox.bentobox.api.flags.Flag;
|
||||
import world.bentobox.bentobox.api.flags.Flag.Type;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* Admin command to reset all islands in a world to the default flag setting in the game mode config.yml
|
||||
@ -13,25 +20,47 @@ import world.bentobox.bentobox.api.user.User;
|
||||
*/
|
||||
public class AdminResetFlagsCommand extends ConfirmableCommand {
|
||||
|
||||
private List<String> options;
|
||||
|
||||
public AdminResetFlagsCommand(CompositeCommand parent) {
|
||||
super(parent, "resetflags");
|
||||
options = getPlugin().getFlagsManager().getFlags().stream()
|
||||
.filter(f -> f.getType().equals(Type.PROTECTION) || f.getType().equals(Type.SETTING))
|
||||
.map(Flag::getID).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("admin.resetflags");
|
||||
setOnlyPlayer(false);
|
||||
setParametersHelp("commands.admin.resetflags.parameters");
|
||||
setDescription("commands.admin.resetflags.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// Everything's fine, we can set the island as spawn :)
|
||||
askConfirmation(user, () -> {
|
||||
getIslands().resetAllFlags(getWorld());
|
||||
user.sendMessage("commands.admin.resetflags.success");
|
||||
});
|
||||
return true;
|
||||
if (args.isEmpty()) {
|
||||
askConfirmation(user, user.getTranslation("commands.admin.resetflags.confirm"), () -> {
|
||||
getIslands().resetAllFlags(getWorld());
|
||||
user.sendMessage("commands.admin.resetflags.success");
|
||||
});
|
||||
return true;
|
||||
} else if (args.size() == 1 && options.contains(args.get(0).toUpperCase(Locale.ENGLISH))) {
|
||||
getPlugin().getFlagsManager().getFlag(args.get(0).toUpperCase(Locale.ENGLISH)).ifPresent(flag ->
|
||||
askConfirmation(user, user.getTranslation("commands.admin.resetflags.confirm"), () -> {
|
||||
getIslands().resetFlag(getWorld(), flag);
|
||||
user.sendMessage("commands.admin.resetflags.success-one", TextVariables.NAME, flag.getID());
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
// Show help
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ public class AdminSetspawnCommand extends ConfirmableCommand {
|
||||
.involvedPlayer(i.getOwner())
|
||||
.admin(true)
|
||||
.build();
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
// If island is owned, then unregister the owner and any members
|
||||
new ImmutableSet.Builder<UUID>().addAll(i.getMembers().keySet()).build().forEach(m -> {
|
||||
|
@ -70,7 +70,7 @@ public class AdminUnregisterCommand extends ConfirmableCommand {
|
||||
.involvedPlayer(targetUUID)
|
||||
.admin(true)
|
||||
.build();
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
// Remove all island members
|
||||
new ImmutableSet.Builder<UUID>().addAll(oldIsland.getMembers().keySet()).build().forEach(m -> {
|
||||
getIslands().removePlayer(getWorld(), m);
|
||||
|
@ -0,0 +1,50 @@
|
||||
package world.bentobox.bentobox.api.commands.admin.deaths;
|
||||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @since 1.8.0
|
||||
* @author Poslovitch
|
||||
*/
|
||||
public class AdminDeathsAddCommand extends CompositeCommand {
|
||||
|
||||
public AdminDeathsAddCommand(AdminDeathsCommand parent) {
|
||||
super(parent, "add");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setDescription("commands.admin.deaths.add.description");
|
||||
setParametersHelp("commands.admin.deaths.add.parameters");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, @NonNull List<String> args) {
|
||||
if (args.size() != 2) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
|
||||
UUID target = getPlayers().getUUID(args.get(0));
|
||||
if (target == null) {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||
} else if (!NumberUtils.isNumber(args.get(1)) || Integer.valueOf(args.get(1)) < 0) {
|
||||
user.sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, args.get(1));
|
||||
} else {
|
||||
getPlayers().setDeaths(getWorld(), target, getPlayers().getDeaths(getWorld(), target) + Integer.valueOf(args.get(1)));
|
||||
user.sendMessage("commands.admin.deaths.add.success",
|
||||
TextVariables.NAME, args.get(0), TextVariables.NUMBER, args.get(1),
|
||||
"[total]", String.valueOf(getPlayers().getDeaths(getWorld(), target)));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -21,6 +21,8 @@ public class AdminDeathsCommand extends CompositeCommand {
|
||||
|
||||
new AdminDeathsResetCommand(this);
|
||||
new AdminDeathsSetCommand(this);
|
||||
new AdminDeathsAddCommand(this);
|
||||
new AdminDeathsRemoveCommand(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,52 @@
|
||||
package world.bentobox.bentobox.api.commands.admin.deaths;
|
||||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @since 1.8.0
|
||||
* @author Poslovitch
|
||||
*/
|
||||
public class AdminDeathsRemoveCommand extends CompositeCommand {
|
||||
|
||||
public AdminDeathsRemoveCommand(AdminDeathsCommand parent) {
|
||||
super(parent, "remove");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setDescription("commands.admin.deaths.remove.description");
|
||||
setParametersHelp("commands.admin.deaths.remove.parameters");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, @NonNull List<String> args) {
|
||||
if (args.size() != 2) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
|
||||
UUID target = getPlayers().getUUID(args.get(0));
|
||||
if (target == null) {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||
} else if (!NumberUtils.isNumber(args.get(1)) || Integer.valueOf(args.get(1)) < 0) {
|
||||
user.sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, args.get(1));
|
||||
} else {
|
||||
// Make sure it cannot go under 0.
|
||||
int newDeaths = Math.max(getPlayers().getDeaths(getWorld(), target) - Integer.valueOf(args.get(1)), 0);
|
||||
getPlayers().setDeaths(getWorld(), target, newDeaths);
|
||||
user.sendMessage("commands.admin.deaths.remove.success",
|
||||
TextVariables.NAME, args.get(0), TextVariables.NUMBER, args.get(1),
|
||||
"[total]", String.valueOf(newDeaths));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package world.bentobox.bentobox.api.commands.admin.resets;
|
||||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Poslovitch
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public class AdminResetsAddCommand extends CompositeCommand {
|
||||
|
||||
public AdminResetsAddCommand(AdminResetsCommand parent) {
|
||||
super(parent, "add");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setDescription("commands.admin.resets.add.description");
|
||||
setParametersHelp("commands.admin.resets.add.parameters");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, @NonNull List<String> args) {
|
||||
if (args.size() != 2) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
|
||||
UUID target = getPlayers().getUUID(args.get(0));
|
||||
if (target == null) {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||
} else if (!NumberUtils.isNumber(args.get(1)) || Integer.valueOf(args.get(1)) < 0) {
|
||||
user.sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, args.get(1));
|
||||
} else {
|
||||
getPlayers().setResets(getWorld(), target, getPlayers().getResets(getWorld(), target) + Integer.valueOf(args.get(1)));
|
||||
user.sendMessage("commands.admin.resets.add.success",
|
||||
TextVariables.NAME, args.get(0), TextVariables.NUMBER, args.get(1),
|
||||
"[total]", String.valueOf(getPlayers().getResets(getWorld(), target)));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -18,6 +18,8 @@ public class AdminResetsCommand extends CompositeCommand {
|
||||
|
||||
new AdminResetsSetCommand(this);
|
||||
new AdminResetsResetCommand(this);
|
||||
new AdminResetsAddCommand(this);
|
||||
new AdminResetsRemoveCommand(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,52 @@
|
||||
package world.bentobox.bentobox.api.commands.admin.resets;
|
||||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Poslovitch
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public class AdminResetsRemoveCommand extends CompositeCommand {
|
||||
|
||||
public AdminResetsRemoveCommand(AdminResetsCommand parent) {
|
||||
super(parent, "remove");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setDescription("commands.admin.resets.remove.description");
|
||||
setParametersHelp("commands.admin.resets.remove.parameters");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, @NonNull List<String> args) {
|
||||
if (args.size() != 2) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
|
||||
UUID target = getPlayers().getUUID(args.get(0));
|
||||
if (target == null) {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||
} else if (!NumberUtils.isNumber(args.get(1)) || Integer.valueOf(args.get(1)) < 0) {
|
||||
user.sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, args.get(1));
|
||||
} else {
|
||||
// Make sure it cannot go under 0.
|
||||
int newResets = Math.max(getPlayers().getResets(getWorld(), target) - Integer.valueOf(args.get(1)), 0);
|
||||
getPlayers().setResets(getWorld(), target, newResets);
|
||||
user.sendMessage("commands.admin.resets.remove.success",
|
||||
TextVariables.NAME, args.get(0), TextVariables.NUMBER, args.get(1),
|
||||
"[total]", String.valueOf(newResets));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -39,7 +39,7 @@ public class AdminResetsResetCommand extends ConfirmableCommand {
|
||||
getIWM().setResetEpoch(getWorld());
|
||||
// Reset all current players
|
||||
Bukkit.getOnlinePlayers().stream().map(Player::getUniqueId).filter(getPlayers()::isKnown).forEach(u -> getPlayers().setResets(getWorld(), u, 0));
|
||||
user.sendMessage("general.success");
|
||||
user.sendMessage("commands.admin.resets.reset.success-everyone");
|
||||
});
|
||||
return true;
|
||||
} else {
|
||||
@ -50,7 +50,7 @@ public class AdminResetsResetCommand extends ConfirmableCommand {
|
||||
return false;
|
||||
} else {
|
||||
getPlayers().setResets(getWorld(), target, 0);
|
||||
user.sendMessage("general.success");
|
||||
user.sendMessage("commands.admin.resets.reset.success", TextVariables.NAME, args.get(0));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class AdminResetsSetCommand extends CompositeCommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (args.isEmpty() || args.size() != 2) {
|
||||
if (args.size() != 2) {
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
@ -31,11 +31,12 @@ public class AdminResetsSetCommand extends CompositeCommand {
|
||||
UUID target = getPlayers().getUUID(args.get(0));
|
||||
if (target == null) {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||
} else if (!NumberUtils.isNumber(args.get(1)) || Integer.valueOf(args.get(1)) < 0) {
|
||||
} else if (!NumberUtils.isNumber(args.get(1)) || Integer.valueOf(args.get(1)) <= 0) {
|
||||
user.sendMessage("general.errors.must-be-positive-number", TextVariables.NUMBER, args.get(1));
|
||||
} else {
|
||||
getPlayers().setResets(getWorld(), target, Integer.valueOf(args.get(1)));
|
||||
user.sendMessage("general.success");
|
||||
user.sendMessage("commands.admin.resets.set.success",
|
||||
TextVariables.NAME, args.get(0), TextVariables.NUMBER, args.get(1));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ public class AdminTeamAddCommand extends CompositeCommand {
|
||||
.involvedPlayer(targetUUID)
|
||||
.admin(true)
|
||||
.build();
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
return true;
|
||||
} else {
|
||||
user.sendMessage("general.errors.player-has-no-island");
|
||||
|
@ -63,7 +63,7 @@ public class AdminTeamDisbandCommand extends CompositeCommand {
|
||||
.involvedPlayer(targetUUID)
|
||||
.admin(true)
|
||||
.build();
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
});
|
||||
user.sendMessage("commands.admin.team.disband.success", TextVariables.NAME, args.get(0));
|
||||
|
@ -67,6 +67,7 @@ public class AdminTeamKickCommand extends CompositeCommand {
|
||||
target.sendMessage("commands.admin.team.kick.admin-kicked");
|
||||
|
||||
getIslands().removePlayer(getWorld(), targetUUID);
|
||||
getPlayers().clearHomeLocations(getWorld(), targetUUID);
|
||||
user.sendMessage("commands.admin.team.kick.success", TextVariables.NAME, target.getName(), "[owner]", getPlayers().getName(island.getOwner()));
|
||||
|
||||
// Fire event so add-ons know
|
||||
@ -76,7 +77,7 @@ public class AdminTeamKickCommand extends CompositeCommand {
|
||||
.involvedPlayer(targetUUID)
|
||||
.admin(true)
|
||||
.build();
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
|
||||
.involvedPlayer(targetUUID)
|
||||
.admin(true)
|
||||
.build();
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -79,9 +79,7 @@ public class IslandBanCommand extends CompositeCommand {
|
||||
}
|
||||
target = User.getInstance(targetUUID);
|
||||
// Cannot ban ops
|
||||
if (target.isOp() || (target.isOnline() && target.hasPermission(
|
||||
getAddon()
|
||||
.getPermissionPrefix() + "admin.noban"))) {
|
||||
if (target.isOp() || (target.isOnline() && target.hasPermission(this.getPermissionPrefix() + "admin.noban"))) {
|
||||
user.sendMessage("commands.island.ban.cannot-ban");
|
||||
return false;
|
||||
}
|
||||
|
@ -84,7 +84,9 @@ public class IslandExpelCommand extends CompositeCommand {
|
||||
return false;
|
||||
}
|
||||
// Cannot ban ops
|
||||
if (target.isOp() || target.hasPermission("admin.noexpel") || target.hasPermission("mod.bypassexpel")) {
|
||||
if (target.isOp() ||
|
||||
target.hasPermission(this.getPermissionPrefix() + "admin.noexpel") ||
|
||||
target.hasPermission(this.getPermissionPrefix() + "mod.bypassexpel")) {
|
||||
user.sendMessage(CANNOT_EXPEL);
|
||||
return false;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class IslandNearCommand extends CompositeCommand {
|
||||
}
|
||||
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
if (!getIslands().hasIsland(getWorld(), playerUUID) || !getIslands().inTeam(getWorld(), playerUUID)) {
|
||||
if (!getIslands().hasIsland(getWorld(), playerUUID) && !getIslands().inTeam(getWorld(), playerUUID)) {
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return false;
|
||||
}
|
||||
@ -57,7 +57,11 @@ public class IslandNearCommand extends CompositeCommand {
|
||||
boolean noNeighbors = true;
|
||||
for (BlockFace face : COMPASS_POINTS) {
|
||||
String name = getIslands().getIslandAt(
|
||||
island.getCenter().getBlock().getRelative(face, dist).getLocation())
|
||||
island
|
||||
.getCenter()
|
||||
.getBlock()
|
||||
.getRelative(face, dist)
|
||||
.getLocation())
|
||||
.map(i -> getName(user, i)).orElse("");
|
||||
if (!name.isEmpty()) {
|
||||
noNeighbors = false;
|
||||
|
@ -131,7 +131,7 @@ public class IslandResetCommand extends ConfirmableCommand {
|
||||
Builder builder = NewIsland.builder()
|
||||
.player(user)
|
||||
.reason(Reason.RESET)
|
||||
.addon((GameModeAddon)getAddon())
|
||||
.addon(getAddon())
|
||||
.oldIsland(oldIsland)
|
||||
.name(name);
|
||||
if (noPaste) builder.noPaste();
|
||||
@ -155,15 +155,27 @@ public class IslandResetCommand extends ConfirmableCommand {
|
||||
* Therefore, we need to do it manually.
|
||||
* Plus, a more specific team event (TeamDeleteEvent) is called by this method.
|
||||
*/
|
||||
|
||||
island.getMemberSet().forEach(memberUUID -> {
|
||||
getIslands().removePlayer(getWorld(), memberUUID);
|
||||
User member = User.getInstance(memberUUID);
|
||||
|
||||
// Send a "you're kicked" message if the member is not the island owner
|
||||
User member = User.getInstance(memberUUID);
|
||||
// Send a "you're kicked" message if the member is not the island owner (send before removing!)
|
||||
if (!memberUUID.equals(island.getOwner())) {
|
||||
member.sendMessage("commands.island.reset.kicked-from-island", "[gamemode]", getAddon().getDescription().getName());
|
||||
}
|
||||
// Remove player
|
||||
getIslands().removePlayer(getWorld(), memberUUID);
|
||||
|
||||
// Execute commands when leaving
|
||||
getIWM().getOnLeaveCommands(island.getWorld()).forEach(command -> {
|
||||
command = command.replace("[player]", member.getName());
|
||||
if (command.startsWith("[SUDO]") && member.isOnline()) {
|
||||
// Execute the command by the player
|
||||
member.performCommand(command.substring(6));
|
||||
} else {
|
||||
// Otherwise execute as the server console
|
||||
getPlugin().getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
}
|
||||
});
|
||||
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
@ -187,6 +199,21 @@ public class IslandResetCommand extends ConfirmableCommand {
|
||||
getPlugin().getVault().ifPresent(vault -> vault.withdraw(member, vault.getBalance(member)));
|
||||
}
|
||||
|
||||
// Reset the health
|
||||
if (getIWM().isOnLeaveResetHealth(getWorld())) {
|
||||
member.getPlayer().setHealth(20.0D);
|
||||
}
|
||||
|
||||
// Reset the hunger
|
||||
if (getIWM().isOnLeaveResetHunger(getWorld())) {
|
||||
member.getPlayer().setFoodLevel(20);
|
||||
}
|
||||
|
||||
// Reset the XP
|
||||
if (getIWM().isOnLeaveResetXP(getWorld())) {
|
||||
member.getPlayer().setTotalExperience(0);
|
||||
}
|
||||
|
||||
// Fire event
|
||||
IslandBaseEvent e = TeamEvent.builder()
|
||||
.island(island)
|
||||
|
@ -0,0 +1,84 @@
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Represents an invite
|
||||
* @author tastybento
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public class Invite {
|
||||
|
||||
/**
|
||||
* Type of invitation
|
||||
*
|
||||
*/
|
||||
public enum Type {
|
||||
COOP,
|
||||
TEAM,
|
||||
TRUST
|
||||
}
|
||||
|
||||
private final Type type;
|
||||
private final UUID inviter;
|
||||
private final UUID invitee;
|
||||
|
||||
/**
|
||||
* @param type
|
||||
* @param inviter
|
||||
* @param invitee
|
||||
*/
|
||||
public Invite(Type type, UUID inviter, UUID invitee) {
|
||||
this.type = type;
|
||||
this.inviter = inviter;
|
||||
this.invitee = invitee;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type
|
||||
*/
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the inviter
|
||||
*/
|
||||
public UUID getInviter() {
|
||||
return inviter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the invitee
|
||||
*/
|
||||
public UUID getInvitee() {
|
||||
return invitee;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(invitee, inviter, type);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof Invite)) {
|
||||
return false;
|
||||
}
|
||||
Invite other = (Invite) obj;
|
||||
return Objects.equals(invitee, other.invitee) && Objects.equals(inviter, other.inviter) && type == other.type;
|
||||
}
|
||||
}
|
@ -1,11 +1,15 @@
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||
@ -14,10 +18,17 @@ import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
public class IslandTeamCommand extends CompositeCommand {
|
||||
|
||||
/**
|
||||
* Invited list. Key is the invited party, value is the invite.
|
||||
* @since 1.8.0
|
||||
*/
|
||||
private Map<UUID, Invite> inviteMap;
|
||||
|
||||
private IslandTeamInviteCommand inviteCommand;
|
||||
|
||||
public IslandTeamCommand(CompositeCommand parent) {
|
||||
super(parent, "team");
|
||||
inviteMap = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -76,15 +87,59 @@ public class IslandTeamCommand extends CompositeCommand {
|
||||
.reason(TeamEvent.Reason.INFO)
|
||||
.involvedPlayer(user.getUniqueId())
|
||||
.build();
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
return event.isCancelled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the inviteCommand
|
||||
* Add an invite
|
||||
* @param type - type of invite
|
||||
* @param inviter - uuid of inviter
|
||||
* @param invitee - uuid of invitee
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public IslandTeamInviteCommand getInviteCommand() {
|
||||
return inviteCommand;
|
||||
public void addInvite(Invite.Type type, @NonNull UUID inviter, @NonNull UUID invitee) {
|
||||
inviteMap.put(invitee, new Invite(type, inviter, invitee));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player has been invited
|
||||
* @param invitee - UUID of invitee to check
|
||||
* @return true if invited, false if not
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public boolean isInvited(@NonNull UUID invitee) {
|
||||
return inviteMap.containsKey(invitee);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whoever invited invitee
|
||||
* @param invitee - uuid
|
||||
* @return UUID of inviter, or null if invitee has not been invited
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@Nullable
|
||||
public UUID getInviter(UUID invitee) {
|
||||
return isInvited(invitee) ? inviteMap.get(invitee).getInviter() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the invite for an invitee.
|
||||
* @param invitee - UUID of invitee
|
||||
* @return invite or null if none
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@Nullable
|
||||
public Invite getInvite(UUID invitee) {
|
||||
return inviteMap.get(invitee);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a pending invite.
|
||||
* @param invitee - UUID of invited user
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public void removeInvite(@NonNull UUID invitee) {
|
||||
inviteMap.remove(invitee);
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.util.UUID;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
@ -20,10 +21,12 @@ import world.bentobox.bentobox.util.Util;
|
||||
*/
|
||||
public class IslandTeamCoopCommand extends CompositeCommand {
|
||||
|
||||
private IslandTeamCommand itc;
|
||||
private @Nullable UUID targetUUID;
|
||||
|
||||
public IslandTeamCoopCommand(CompositeCommand parentCommand) {
|
||||
public IslandTeamCoopCommand(IslandTeamCommand parentCommand) {
|
||||
super(parentCommand, "coop");
|
||||
this.itc = parentCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -72,6 +75,11 @@ public class IslandTeamCoopCommand extends CompositeCommand {
|
||||
user.sendMessage("commands.island.team.coop.already-has-rank");
|
||||
return false;
|
||||
}
|
||||
if (itc.isInvited(targetUUID) && itc.getInviter(targetUUID).equals(user.getUniqueId()) && itc.getInvite(targetUUID).getType().equals(Type.COOP)) {
|
||||
// Prevent spam
|
||||
user.sendMessage("commands.island.team.invite.errors.you-have-already-invited");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -80,9 +88,19 @@ public class IslandTeamCoopCommand extends CompositeCommand {
|
||||
User target = User.getInstance(targetUUID);
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
if (island != null) {
|
||||
island.setRank(target, RanksManager.COOP_RANK);
|
||||
user.sendMessage("commands.island.team.coop.success", TextVariables.NAME, target.getName());
|
||||
target.sendMessage("commands.island.team.coop.you-are-a-coop-member", TextVariables.NAME, user.getName());
|
||||
if (getPlugin().getSettings().isInviteConfirmation()) {
|
||||
// Put the invited player (key) onto the list with inviter (value)
|
||||
// If someone else has invited a player, then this invite will overwrite the previous invite!
|
||||
itc.addInvite(Invite.Type.COOP, user.getUniqueId(), target.getUniqueId());
|
||||
user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, target.getName());
|
||||
// Send message to online player
|
||||
target.sendMessage("commands.island.team.coop.name-has-invited-you", TextVariables.NAME, user.getName());
|
||||
target.sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, getTopLabel());
|
||||
} else {
|
||||
island.setRank(target, RanksManager.COOP_RANK);
|
||||
user.sendMessage("commands.island.team.coop.success", TextVariables.NAME, target.getName());
|
||||
target.sendMessage("commands.island.team.coop.you-are-a-coop-member", TextVariables.NAME, user.getName());
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// Should not happen
|
||||
|
@ -6,14 +6,14 @@ import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.RanksManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
@ -40,8 +40,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
||||
public boolean canExecute(User user, String label, List<String> args) {
|
||||
playerUUID = user.getUniqueId();
|
||||
// Check if player has been invited
|
||||
BiMap<UUID, UUID> inviteList = itc.getInviteCommand().getInviteList();
|
||||
if (!inviteList.containsKey(playerUUID)) {
|
||||
if (!itc.isInvited(playerUUID)) {
|
||||
user.sendMessage("commands.island.team.invite.errors.none-invited-you");
|
||||
return false;
|
||||
}
|
||||
@ -51,72 +50,116 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
||||
return false;
|
||||
}
|
||||
// Get the island owner
|
||||
prospectiveOwnerUUID = inviteList.get(playerUUID);
|
||||
prospectiveOwnerUUID = itc.getInviter(playerUUID);
|
||||
if (!getIslands().hasIsland(getWorld(), prospectiveOwnerUUID)) {
|
||||
user.sendMessage("commands.island.team.invite.errors.invalid-invite");
|
||||
inviteList.remove(playerUUID);
|
||||
itc.removeInvite(playerUUID);
|
||||
return false;
|
||||
}
|
||||
// Fire event so add-ons can run commands, etc.
|
||||
IslandBaseEvent event = TeamEvent.builder()
|
||||
.island(getIslands().getIsland(getWorld(), prospectiveOwnerUUID))
|
||||
.reason(TeamEvent.Reason.JOIN)
|
||||
.involvedPlayer(playerUUID)
|
||||
.build();
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
return !event.isCancelled();
|
||||
Invite invite = itc.getInvite(playerUUID);
|
||||
if (invite.getType().equals(Type.TEAM)) {
|
||||
// Fire event so add-ons can run commands, etc.
|
||||
IslandBaseEvent event = TeamEvent.builder()
|
||||
.island(getIslands().getIsland(getWorld(), prospectiveOwnerUUID))
|
||||
.reason(TeamEvent.Reason.JOIN)
|
||||
.involvedPlayer(playerUUID)
|
||||
.build();
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
return !event.isCancelled();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
askConfirmation(user, user.getTranslation("commands.island.team.invite.accept.confirmation"), () -> {
|
||||
// Remove the invite
|
||||
itc.getInviteCommand().getInviteList().remove(playerUUID);
|
||||
// Put player into Spectator mode
|
||||
user.setGameMode(GameMode.SPECTATOR);
|
||||
// Get the player's island - may be null if the player has no island
|
||||
Island island = getIslands().getIsland(getWorld(), playerUUID);
|
||||
// Get the team's island
|
||||
Island teamIsland = getIslands().getIsland(getWorld(), prospectiveOwnerUUID);
|
||||
// Remove player as owner of the old island
|
||||
getIslands().removePlayer(getWorld(), playerUUID);
|
||||
// Remove money inventory etc. for leaving
|
||||
cleanPlayer(user);
|
||||
// Add the player as a team member of the new island
|
||||
getIslands().setJoinTeam(teamIsland, playerUUID);
|
||||
//Move player to team's island
|
||||
getPlayers().clearHomeLocations(getWorld(), playerUUID);
|
||||
getIslands().homeTeleport(getWorld(), user.getPlayer());
|
||||
// Delete the old island
|
||||
if (island != null) {
|
||||
getIslands().deleteIsland(island, true, user.getUniqueId());
|
||||
}
|
||||
// TODO Set the cooldown
|
||||
// Reset deaths
|
||||
if (getIWM().isTeamJoinDeathReset(getWorld())) {
|
||||
getPlayers().setDeaths(getWorld(), playerUUID, 0);
|
||||
}
|
||||
// Put player back into normal mode
|
||||
user.setGameMode(getIWM().getDefaultGameMode(getWorld()));
|
||||
|
||||
user.sendMessage("commands.island.team.invite.accept.you-joined-island", TextVariables.LABEL, getTopLabel());
|
||||
User inviter = User.getInstance(itc.getInviteCommand().getInviteList().get(playerUUID));
|
||||
if (inviter != null) {
|
||||
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", TextVariables.NAME, user.getName());
|
||||
}
|
||||
getIslands().save(teamIsland);
|
||||
// Fire event
|
||||
IslandBaseEvent e = TeamEvent.builder()
|
||||
.island(getIslands().getIsland(getWorld(), prospectiveOwnerUUID))
|
||||
.reason(TeamEvent.Reason.JOINED)
|
||||
.involvedPlayer(playerUUID)
|
||||
.build();
|
||||
Bukkit.getServer().getPluginManager().callEvent(e);
|
||||
});
|
||||
|
||||
// Get the invite
|
||||
Invite invite = itc.getInvite(playerUUID);
|
||||
switch (invite.getType()) {
|
||||
case COOP:
|
||||
askConfirmation(user, () -> acceptCoopInvite(user, invite));
|
||||
break;
|
||||
case TRUST:
|
||||
askConfirmation(user, () -> acceptTrustInvite(user, invite));
|
||||
break;
|
||||
default:
|
||||
askConfirmation(user, user.getTranslation("commands.island.team.invite.accept.confirmation"), () -> acceptTeamInvite(user, invite));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void acceptTrustInvite(User user, Invite invite) {
|
||||
// Remove the invite
|
||||
itc.removeInvite(playerUUID);
|
||||
User inviter = User.getInstance(invite.getInviter());
|
||||
if (inviter != null) {
|
||||
Island island = getIslands().getIsland(getWorld(), inviter);
|
||||
if (island != null) {
|
||||
island.setRank(user, RanksManager.TRUSTED_RANK);
|
||||
inviter.sendMessage("commands.island.team.trust.success", TextVariables.NAME, user.getName());
|
||||
user.sendMessage("commands.island.team.trust.you-are-trusted", TextVariables.NAME, inviter.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void acceptCoopInvite(User user, Invite invite) {
|
||||
// Remove the invite
|
||||
itc.removeInvite(playerUUID);
|
||||
User inviter = User.getInstance(invite.getInviter());
|
||||
if (inviter != null) {
|
||||
Island island = getIslands().getIsland(getWorld(), inviter);
|
||||
if (island != null) {
|
||||
island.setRank(user, RanksManager.COOP_RANK);
|
||||
inviter.sendMessage("commands.island.team.coop.success", TextVariables.NAME, user.getName());
|
||||
user.sendMessage("commands.island.team.coop.you-are-a-coop-member", TextVariables.NAME, inviter.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void acceptTeamInvite(User user, Invite invite) {
|
||||
// Remove the invite
|
||||
itc.removeInvite(playerUUID);
|
||||
// Put player into Spectator mode
|
||||
user.setGameMode(GameMode.SPECTATOR);
|
||||
// Get the player's island - may be null if the player has no island
|
||||
Island island = getIslands().getIsland(getWorld(), playerUUID);
|
||||
// Get the team's island
|
||||
Island teamIsland = getIslands().getIsland(getWorld(), prospectiveOwnerUUID);
|
||||
// Remove player as owner of the old island
|
||||
getIslands().removePlayer(getWorld(), playerUUID);
|
||||
// Remove money inventory etc. for leaving
|
||||
cleanPlayer(user);
|
||||
// Add the player as a team member of the new island
|
||||
getIslands().setJoinTeam(teamIsland, playerUUID);
|
||||
//Move player to team's island
|
||||
getPlayers().clearHomeLocations(getWorld(), playerUUID);
|
||||
getIslands().homeTeleport(getWorld(), user.getPlayer());
|
||||
// Delete the old island
|
||||
if (island != null) {
|
||||
getIslands().deleteIsland(island, true, user.getUniqueId());
|
||||
}
|
||||
// Reset deaths
|
||||
if (getIWM().isTeamJoinDeathReset(getWorld())) {
|
||||
getPlayers().setDeaths(getWorld(), playerUUID, 0);
|
||||
}
|
||||
// Put player back into normal mode
|
||||
user.setGameMode(getIWM().getDefaultGameMode(getWorld()));
|
||||
|
||||
user.sendMessage("commands.island.team.invite.accept.you-joined-island", TextVariables.LABEL, getTopLabel());
|
||||
User inviter = User.getInstance(invite.getInviter());
|
||||
if (inviter != null) {
|
||||
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", TextVariables.NAME, user.getName());
|
||||
}
|
||||
getIslands().save(teamIsland);
|
||||
// Fire event
|
||||
IslandBaseEvent e = TeamEvent.builder()
|
||||
.island(getIslands().getIsland(getWorld(), prospectiveOwnerUUID))
|
||||
.reason(TeamEvent.Reason.JOINED)
|
||||
.involvedPlayer(playerUUID)
|
||||
.build();
|
||||
Bukkit.getPluginManager().callEvent(e);
|
||||
|
||||
}
|
||||
|
||||
private void cleanPlayer(User user) {
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld()) || getIWM().isOnJoinResetEnderChest(getWorld())) {
|
||||
user.getPlayer().getEnderChest().clear();
|
||||
@ -127,5 +170,20 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
||||
if (getSettings().isUseEconomy() && (getIWM().isOnLeaveResetMoney(getWorld()) || getIWM().isOnJoinResetMoney(getWorld()))) {
|
||||
getPlugin().getVault().ifPresent(vault -> vault.withdraw(user, vault.getBalance(user)));
|
||||
}
|
||||
|
||||
// Reset the health
|
||||
if (getIWM().isOnJoinResetHealth(getWorld())) {
|
||||
user.getPlayer().setHealth(20.0D);
|
||||
}
|
||||
|
||||
// Reset the hunger
|
||||
if (getIWM().isOnJoinResetHunger(getWorld())) {
|
||||
user.getPlayer().setFoodLevel(20);
|
||||
}
|
||||
|
||||
// Reset the XP
|
||||
if (getIWM().isOnJoinResetXP(getWorld())) {
|
||||
user.getPlayer().setTotalExperience(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,10 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
import world.bentobox.bentobox.api.events.team.TeamEvent;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
@ -22,10 +20,12 @@ import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class IslandTeamInviteCommand extends CompositeCommand {
|
||||
|
||||
private BiMap<UUID, UUID> inviteList;
|
||||
private IslandTeamCommand itc;
|
||||
private @Nullable User invitedPlayer;
|
||||
|
||||
public IslandTeamInviteCommand(CompositeCommand islandCommand) {
|
||||
super(islandCommand, "invite");
|
||||
public IslandTeamInviteCommand(IslandTeamCommand parent) {
|
||||
super(parent, "invite");
|
||||
itc = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -33,7 +33,6 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
||||
setPermission("island.team");
|
||||
setOnlyPlayer(true);
|
||||
setDescription("commands.island.team.invite.description");
|
||||
inviteList = HashBiMap.create();
|
||||
setConfigurableRankCommand();
|
||||
}
|
||||
|
||||
@ -53,22 +52,27 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
||||
}
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
if (args.isEmpty() || args.size() > 1) {
|
||||
// Invite label with no name, i.e., /island invite - tells the player who has invited them so far
|
||||
if (inviteList.containsKey(playerUUID)) {
|
||||
OfflinePlayer inviter = Bukkit.getServer().getOfflinePlayer(inviteList.get(playerUUID));
|
||||
user.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, inviter.getName());
|
||||
// Invite label with no name, i.e., /island invite - tells the player who has invited them so far and why
|
||||
if (itc.isInvited(playerUUID)) {
|
||||
Invite invite = itc.getInvite(playerUUID);
|
||||
String name = getPlayers().getName(playerUUID);
|
||||
switch (invite.getType()) {
|
||||
case COOP:
|
||||
user.sendMessage("commands.island.team.invite.name-has-invited-you.coop", TextVariables.NAME, name);
|
||||
break;
|
||||
case TRUST:
|
||||
user.sendMessage("commands.island.team.invite.name-has-invited-you.trust", TextVariables.NAME, name);
|
||||
break;
|
||||
default:
|
||||
user.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, name);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Show help
|
||||
showHelp(this, user);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
|
||||
// Only online players can be invited
|
||||
UUID invitedPlayerUUID = getPlayers().getUUID(args.get(0));
|
||||
@ -76,7 +80,7 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||
return false;
|
||||
}
|
||||
User invitedPlayer = User.getInstance(invitedPlayerUUID);
|
||||
invitedPlayer = User.getInstance(invitedPlayerUUID);
|
||||
if (!invitedPlayer.isOnline()) {
|
||||
user.sendMessage("general.errors.offline-player");
|
||||
return false;
|
||||
@ -95,19 +99,24 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
||||
user.sendMessage("commands.island.team.invite.errors.already-on-team");
|
||||
return false;
|
||||
}
|
||||
return invite(user,invitedPlayer);
|
||||
|
||||
if (itc.isInvited(invitedPlayerUUID) && itc.getInviter(invitedPlayerUUID).equals(user.getUniqueId()) && itc.getInvite(invitedPlayerUUID).getType().equals(Type.TEAM)) {
|
||||
// Prevent spam
|
||||
user.sendMessage("commands.island.team.invite.errors.you-have-already-invited");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean invite(User user, User invitedPlayer) {
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
Set<UUID> teamMembers = getMembers(getWorld(), user);
|
||||
// Check if player has space on their team
|
||||
int maxSize = getMaxTeamSize(user);
|
||||
if (teamMembers.size() < maxSize) {
|
||||
// If that player already has an invite out then retract it.
|
||||
// Players can only have one invite one at a time - interesting
|
||||
if (inviteList.containsValue(user.getUniqueId())) {
|
||||
inviteList.inverse().remove(user.getUniqueId());
|
||||
if (itc.isInvited(invitedPlayer.getUniqueId())) {
|
||||
itc.removeInvite(invitedPlayer.getUniqueId());
|
||||
user.sendMessage("commands.island.team.invite.removing-invite");
|
||||
}
|
||||
// Fire event so add-ons can run commands, etc.
|
||||
@ -116,13 +125,13 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
||||
.reason(TeamEvent.Reason.INVITE)
|
||||
.involvedPlayer(invitedPlayer.getUniqueId())
|
||||
.build();
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
// Put the invited player (key) onto the list with inviter (value)
|
||||
// If someone else has invited a player, then this invite will overwrite the previous invite!
|
||||
inviteList.put(invitedPlayer.getUniqueId(), user.getUniqueId());
|
||||
itc.addInvite(Invite.Type.TEAM, user.getUniqueId(), invitedPlayer.getUniqueId());
|
||||
user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, invitedPlayer.getName());
|
||||
// Send message to online player
|
||||
invitedPlayer.sendMessage("commands.island.team.invite.name-has-invited-you", TextVariables.NAME, user.getName());
|
||||
@ -148,14 +157,6 @@ public class IslandTeamInviteCommand extends CompositeCommand {
|
||||
return Optional.of(Util.tabLimit(options, lastArg));
|
||||
}
|
||||
|
||||
/**
|
||||
* Order is Invited, Inviter
|
||||
* @return the inviteList
|
||||
*/
|
||||
public BiMap<UUID, UUID> getInviteList() {
|
||||
return inviteList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum team size for this player in this game based on the permission or the world's setting
|
||||
* @param user user
|
||||
|
@ -31,30 +31,29 @@ public class IslandTeamInviteRejectCommand extends CompositeCommand {
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
// Reject /island reject
|
||||
if (itc.getInviteCommand().getInviteList().containsKey(playerUUID)) {
|
||||
if (itc.isInvited(playerUUID)) {
|
||||
// Fire event so add-ons can run commands, etc.
|
||||
IslandBaseEvent event = TeamEvent.builder()
|
||||
.island(getIslands()
|
||||
.getIsland(getWorld(), itc.getInviteCommand().getInviteList().get(playerUUID)))
|
||||
.getIsland(getWorld(), itc.getInviter(playerUUID)))
|
||||
.reason(TeamEvent.Reason.REJECT)
|
||||
.involvedPlayer(playerUUID)
|
||||
.build();
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove this player from the global invite list
|
||||
itc.getInviteCommand().getInviteList().remove(user.getUniqueId());
|
||||
itc.removeInvite(user.getUniqueId());
|
||||
user.sendMessage("commands.island.team.invite.reject.you-rejected-invite");
|
||||
|
||||
User inviter = User.getInstance(itc.getInviteCommand().getInviteList().get(playerUUID));
|
||||
User inviter = User.getInstance(itc.getInviter(playerUUID));
|
||||
if (inviter != null) {
|
||||
inviter.sendMessage("commands.island.team.invite.reject.name-rejected-your-invite", TextVariables.NAME, user.getName());
|
||||
}
|
||||
} else {
|
||||
// Someone typed /island reject and had not been invited
|
||||
// TODO: make the error nicer if there are invites in other worlds
|
||||
user.sendMessage("commands.island.team.invite.errors.none-invited-you");
|
||||
return false;
|
||||
}
|
||||
|
@ -78,6 +78,17 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
||||
target.sendMessage("commands.island.team.kick.owner-kicked", "[gamemode]", getAddon().getDescription().getName());
|
||||
Island oldIsland = getIslands().getIsland(getWorld(), targetUUID);
|
||||
getIslands().removePlayer(getWorld(), targetUUID);
|
||||
// Execute commands when leaving
|
||||
getIWM().getOnLeaveCommands(oldIsland.getWorld()).forEach(command -> {
|
||||
command = command.replace("[player]", target.getName());
|
||||
if (command.startsWith("[SUDO]") && target.isOnline()) {
|
||||
// Execute the command by the player
|
||||
target.performCommand(command.substring(6));
|
||||
} else {
|
||||
// Otherwise execute as the server console
|
||||
getPlugin().getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
}
|
||||
});
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
if (target.isOnline()) {
|
||||
@ -99,6 +110,20 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
||||
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
||||
getPlugin().getVault().ifPresent(vault -> vault.withdraw(target, vault.getBalance(target)));
|
||||
}
|
||||
// Reset the health
|
||||
if (getIWM().isOnLeaveResetHealth(getWorld())) {
|
||||
target.getPlayer().setHealth(20.0D);
|
||||
}
|
||||
|
||||
// Reset the hunger
|
||||
if (getIWM().isOnLeaveResetHunger(getWorld())) {
|
||||
target.getPlayer().setFoodLevel(20);
|
||||
}
|
||||
|
||||
// Reset the XP
|
||||
if (getIWM().isOnLeaveResetXP(getWorld())) {
|
||||
target.getPlayer().setTotalExperience(0);
|
||||
}
|
||||
user.sendMessage("commands.island.team.kick.success", TextVariables.NAME, target.getName());
|
||||
// Fire event
|
||||
IslandBaseEvent e = TeamEvent.builder()
|
||||
@ -106,7 +131,7 @@ public class IslandTeamKickCommand extends ConfirmableCommand {
|
||||
.reason(TeamEvent.Reason.KICK)
|
||||
.involvedPlayer(targetUUID)
|
||||
.build();
|
||||
Bukkit.getServer().getPluginManager().callEvent(e);
|
||||
Bukkit.getPluginManager().callEvent(e);
|
||||
|
||||
// Add cooldown for this player and target
|
||||
if (getSettings().getInviteCooldown() > 0 && getParent() != null) {
|
||||
|
@ -72,6 +72,17 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
|
||||
User.getInstance(ownerUUID).sendMessage("commands.island.team.leave.left-your-island", TextVariables.NAME, user.getName());
|
||||
}
|
||||
getIslands().setLeaveTeam(getWorld(), user.getUniqueId());
|
||||
// Execute commands when leaving
|
||||
getIWM().getOnLeaveCommands(island.getWorld()).forEach(command -> {
|
||||
command = command.replace("[player]", user.getName());
|
||||
if (command.startsWith("[SUDO]") && user.isOnline()) {
|
||||
// Execute the command by the player
|
||||
user.performCommand(command.substring(6));
|
||||
} else {
|
||||
// Otherwise execute as the server console
|
||||
getPlugin().getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
}
|
||||
});
|
||||
// Remove money inventory etc.
|
||||
if (getIWM().isOnLeaveResetEnderChest(getWorld())) {
|
||||
user.getPlayer().getEnderChest().clear();
|
||||
@ -82,6 +93,20 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
|
||||
if (getSettings().isUseEconomy() && getIWM().isOnLeaveResetMoney(getWorld())) {
|
||||
getPlugin().getVault().ifPresent(vault -> vault.withdraw(user, vault.getBalance(user)));
|
||||
}
|
||||
// Reset the health
|
||||
if (getIWM().isOnLeaveResetHealth(getWorld())) {
|
||||
user.getPlayer().setHealth(20.0D);
|
||||
}
|
||||
|
||||
// Reset the hunger
|
||||
if (getIWM().isOnLeaveResetHunger(getWorld())) {
|
||||
user.getPlayer().setFoodLevel(20);
|
||||
}
|
||||
|
||||
// Reset the XP
|
||||
if (getIWM().isOnLeaveResetXP(getWorld())) {
|
||||
user.getPlayer().setTotalExperience(0);
|
||||
}
|
||||
// Add cooldown for this player and target
|
||||
if (getSettings().getInviteCooldown() > 0 && getParent() != null) {
|
||||
// Get the invite class from the parent
|
||||
@ -101,6 +126,6 @@ public class IslandTeamLeaveCommand extends ConfirmableCommand {
|
||||
.reason(TeamEvent.Reason.LEAVE)
|
||||
.involvedPlayer(user.getUniqueId())
|
||||
.build();
|
||||
Bukkit.getServer().getPluginManager().callEvent(e);
|
||||
Bukkit.getPluginManager().callEvent(e);
|
||||
}
|
||||
}
|
@ -68,7 +68,7 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
|
||||
.reason(TeamEvent.Reason.SETOWNER)
|
||||
.involvedPlayer(targetUUID)
|
||||
.build();
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -4,7 +4,10 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
@ -18,8 +21,12 @@ import world.bentobox.bentobox.util.Util;
|
||||
*/
|
||||
public class IslandTeamTrustCommand extends CompositeCommand {
|
||||
|
||||
public IslandTeamTrustCommand(CompositeCommand parentCommand) {
|
||||
IslandTeamCommand itc;
|
||||
private @Nullable UUID targetUUID;
|
||||
|
||||
public IslandTeamTrustCommand(IslandTeamCommand parentCommand) {
|
||||
super(parentCommand, "trust");
|
||||
this.itc = parentCommand;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -32,7 +39,7 @@ public class IslandTeamTrustCommand extends CompositeCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
public boolean canExecute(User user, String label, List<String> args) {
|
||||
if (args.size() != 1) {
|
||||
// Show help
|
||||
showHelp(this, user);
|
||||
@ -50,22 +57,18 @@ public class IslandTeamTrustCommand extends CompositeCommand {
|
||||
return false;
|
||||
}
|
||||
// Get target player
|
||||
UUID targetUUID = getPlayers().getUUID(args.get(0));
|
||||
targetUUID = getPlayers().getUUID(args.get(0));
|
||||
if (targetUUID == null) {
|
||||
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
|
||||
return false;
|
||||
}
|
||||
return (getSettings().getTrustCooldown() <= 0 || !checkCooldown(user, island.getUniqueId(), targetUUID.toString())) && trustCmd(user, targetUUID);
|
||||
}
|
||||
|
||||
private boolean trustCmd(User user, UUID targetUUID) {
|
||||
// Player cannot trust themselves
|
||||
if (user.getUniqueId().equals(targetUUID)) {
|
||||
user.sendMessage("commands.island.team.trust.trust-in-yourself");
|
||||
// Check cooldown
|
||||
if (getSettings().getTrustCooldown() > 0 && checkCooldown(user, island.getUniqueId(), targetUUID.toString())) {
|
||||
return false;
|
||||
}
|
||||
if (getIslands().getMembers(getWorld(), user.getUniqueId()).contains(targetUUID)) {
|
||||
user.sendMessage("commands.island.team.trust.members-trusted");
|
||||
// Player cannot coop themselves
|
||||
if (user.getUniqueId().equals(targetUUID)) {
|
||||
user.sendMessage("commands.island.team.trust.trust-in-yourself");
|
||||
return false;
|
||||
}
|
||||
User target = User.getInstance(targetUUID);
|
||||
@ -74,11 +77,32 @@ public class IslandTeamTrustCommand extends CompositeCommand {
|
||||
user.sendMessage("commands.island.team.trust.player-already-trusted");
|
||||
return false;
|
||||
}
|
||||
if (itc.isInvited(targetUUID) && itc.getInviter(targetUUID).equals(user.getUniqueId()) && itc.getInvite(targetUUID).getType().equals(Type.TRUST)) {
|
||||
// Prevent spam
|
||||
user.sendMessage("commands.island.team.invite.errors.you-have-already-invited");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
User target = User.getInstance(targetUUID);
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
if (island != null) {
|
||||
island.setRank(target, RanksManager.TRUSTED_RANK);
|
||||
user.sendMessage("commands.island.team.trust.success", TextVariables.NAME, target.getName());
|
||||
target.sendMessage("commands.island.team.trust.you-are-trusted", TextVariables.NAME, user.getName());
|
||||
if (getPlugin().getSettings().isInviteConfirmation()) {
|
||||
// Put the invited player (key) onto the list with inviter (value)
|
||||
// If someone else has invited a player, then this invite will overwrite the previous invite!
|
||||
itc.addInvite(Type.TRUST, user.getUniqueId(), target.getUniqueId());
|
||||
user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, target.getName());
|
||||
// Send message to online player
|
||||
target.sendMessage("commands.island.team.trust.name-has-invited-you", TextVariables.NAME, user.getName());
|
||||
target.sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, getTopLabel());
|
||||
} else {
|
||||
island.setRank(target, RanksManager.TRUSTED_RANK);
|
||||
user.sendMessage("commands.island.team.trust.success", TextVariables.NAME, target.getName());
|
||||
target.sendMessage("commands.island.team.coop.you-are-a-coop-member", TextVariables.NAME, user.getName());
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// Should not happen
|
||||
@ -87,6 +111,35 @@ public class IslandTeamTrustCommand extends CompositeCommand {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
|
||||
if (island != null) {
|
||||
if (getPlugin().getSettings().isInviteConfirmation()) {
|
||||
if (itc.isInvited(targetUUID) && itc.getInviter(targetUUID).equals(user.getUniqueId()) && itc.getInvite(targetUUID).getType().equals(Type.TRUST)) {
|
||||
// Prevent spam
|
||||
user.sendMessage("commands.island.team.invite.errors.you-have-already-invited");
|
||||
return false;
|
||||
}
|
||||
// Put the invited player (key) onto the list with inviter (value)
|
||||
// If someone else has invited a player, then this invite will overwrite the previous invite!
|
||||
itc.addInvite(Type.TRUST, user.getUniqueId(), target.getUniqueId());
|
||||
user.sendMessage("commands.island.team.invite.invitation-sent", TextVariables.NAME, target.getName());
|
||||
// Send message to online player
|
||||
target.sendMessage("commands.island.team.trust.name-has-invited-you", TextVariables.NAME, user.getName());
|
||||
target.sendMessage("commands.island.team.invite.to-accept-or-reject", TextVariables.LABEL, getTopLabel());
|
||||
} else {
|
||||
island.setRank(target, RanksManager.TRUSTED_RANK);
|
||||
user.sendMessage("commands.island.team.trust.success", TextVariables.NAME, target.getName());
|
||||
target.sendMessage("commands.island.team.trust.you-are-trusted", TextVariables.NAME, user.getName());
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// Should not happen
|
||||
user.sendMessage("general.errors.general");
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package world.bentobox.bentobox.api.configuration;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -7,6 +8,7 @@ import java.util.Set;
|
||||
import org.bukkit.Difficulty;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
import world.bentobox.bentobox.api.flags.Flag;
|
||||
|
||||
@ -134,6 +136,15 @@ public interface WorldSettings extends ConfigObject {
|
||||
* @return the visitorBannedCommands
|
||||
*/
|
||||
List<String> getVisitorBannedCommands();
|
||||
|
||||
/**
|
||||
* Optional list of commands that are banned when falling. Not applicable to all game modes so defaults to empty.
|
||||
* @return the fallingBannedCommands
|
||||
* @since 1.8.0
|
||||
*/
|
||||
default List<String> getFallingBannedCommands() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get world flags
|
||||
@ -186,6 +197,48 @@ public interface WorldSettings extends ConfigObject {
|
||||
*/
|
||||
boolean isOnJoinResetMoney();
|
||||
|
||||
/**
|
||||
* Whether the player's health should be reset upon him joining an island or creating it.
|
||||
* @return the onJoinResetHealth
|
||||
* @since 1.8.0
|
||||
*/
|
||||
boolean isOnJoinResetHealth();
|
||||
|
||||
/**
|
||||
* Whether the player's hunger should be reset upon him joining an island or creating it.
|
||||
* @return the onJoinResetHunger
|
||||
* @since 1.8.0
|
||||
*/
|
||||
boolean isOnJoinResetHunger();
|
||||
|
||||
/**
|
||||
* Whether the player's XP should be reset upon him joining an island or creating it.
|
||||
* @return the onJoinResetXP
|
||||
* @since 1.8.0
|
||||
*/
|
||||
boolean isOnJoinResetXP();
|
||||
|
||||
/**
|
||||
* Returns a list of commands that should be executed when the player joins an island or creates one.<br/>
|
||||
* These commands are executed by the console, unless otherwise stated using the {@code [SUDO]} prefix, in which case they are executed by the player.<br/>
|
||||
* <br/>
|
||||
* Available placeholders for the commands are the following:
|
||||
* <ul>
|
||||
* <li>{@code [player]}: name of the player</li>
|
||||
* </ul>
|
||||
* <br/>
|
||||
* Here are some examples of valid commands to execute:
|
||||
* <ul>
|
||||
* <li>{@code "[SUDO] bbox version"}</li>
|
||||
* <li>{@code "bsbadmin deaths set [player] 0"}</li>
|
||||
* </ul>
|
||||
* @return a list of commands.
|
||||
* @since 1.8.0
|
||||
* @see #getOnLeaveCommands()
|
||||
*/
|
||||
@NonNull
|
||||
List<String> getOnJoinCommands();
|
||||
|
||||
/**
|
||||
* @return the onLeaveResetEnderChest
|
||||
*/
|
||||
@ -201,6 +254,50 @@ public interface WorldSettings extends ConfigObject {
|
||||
*/
|
||||
boolean isOnLeaveResetMoney();
|
||||
|
||||
/**
|
||||
* Whether the player's health should be reset upon him leaving his island or resetting it.
|
||||
* @return the onLeaveResetHealth
|
||||
* @since 1.8.0
|
||||
*/
|
||||
boolean isOnLeaveResetHealth();
|
||||
|
||||
/**
|
||||
* Whether the player's hunger should be reset upon him leaving his island or resetting it.
|
||||
* @return the onLeaveResetHunger
|
||||
* @since 1.8.0
|
||||
*/
|
||||
boolean isOnLeaveResetHunger();
|
||||
|
||||
/**
|
||||
* Whether the player's XP should be reset upon him leaving his island or resetting it.
|
||||
* @return the onLeaveResetXP
|
||||
* @since 1.8.0
|
||||
*/
|
||||
boolean isOnLeaveResetXP();
|
||||
|
||||
/**
|
||||
* Returns a list of commands that should be executed when the player leaves an island or resets one.<br/>
|
||||
* These commands are executed by the console, unless otherwise stated using the {@code [SUDO]} prefix, in which case they are executed by the player.<br/>
|
||||
* <br/>
|
||||
* Available placeholders for the commands are the following:
|
||||
* <ul>
|
||||
* <li>{@code [player]}: name of the player</li>
|
||||
* </ul>
|
||||
* <br/>
|
||||
* Here are some examples of valid commands to execute:
|
||||
* <ul>
|
||||
* <li>{@code "[SUDO] bbox version"}</li>
|
||||
* <li>{@code "bsbadmin deaths set [player] 0"}</li>
|
||||
* </ul>
|
||||
* <br/>
|
||||
* Note that player-executed commands might not work, as these commands can be run with said player being offline.
|
||||
* @return a list of commands.
|
||||
* @since 1.8.0
|
||||
* @see #getOnJoinCommands()
|
||||
*/
|
||||
@NonNull
|
||||
List<String> getOnLeaveCommands();
|
||||
|
||||
/**
|
||||
* @return true if the default world generator should not operate in this world
|
||||
*/
|
||||
|
@ -440,76 +440,76 @@ public class IslandEvent extends IslandBaseEvent {
|
||||
|
||||
public IslandBaseEvent build() {
|
||||
// Call the generic event for developers who just want one event and use the Reason enum
|
||||
Bukkit.getServer().getPluginManager().callEvent(new IslandEvent(island, player, admin, location, reason));
|
||||
Bukkit.getPluginManager().callEvent(new IslandEvent(island, player, admin, location, reason));
|
||||
// Generate explicit events
|
||||
switch (reason) {
|
||||
case EXPEL:
|
||||
IslandExpelEvent expel = new IslandExpelEvent(island, player, admin, location);
|
||||
Bukkit.getServer().getPluginManager().callEvent(expel);
|
||||
Bukkit.getPluginManager().callEvent(expel);
|
||||
return expel;
|
||||
case BAN:
|
||||
IslandBanEvent ban = new IslandBanEvent(island, player, admin, location);
|
||||
Bukkit.getServer().getPluginManager().callEvent(ban);
|
||||
Bukkit.getPluginManager().callEvent(ban);
|
||||
return ban;
|
||||
case CREATE:
|
||||
IslandCreateEvent create = new IslandCreateEvent(island, player, admin, location, blueprintBundle);
|
||||
Bukkit.getServer().getPluginManager().callEvent(create);
|
||||
Bukkit.getPluginManager().callEvent(create);
|
||||
return create;
|
||||
case CREATED:
|
||||
IslandCreatedEvent created = new IslandCreatedEvent(island, player, admin, location);
|
||||
Bukkit.getServer().getPluginManager().callEvent(created);
|
||||
Bukkit.getPluginManager().callEvent(created);
|
||||
return created;
|
||||
case DELETE:
|
||||
IslandDeleteEvent delete = new IslandDeleteEvent(island, player, admin, location);
|
||||
Bukkit.getServer().getPluginManager().callEvent(delete);
|
||||
Bukkit.getPluginManager().callEvent(delete);
|
||||
return delete;
|
||||
case DELETE_CHUNKS:
|
||||
IslandDeleteChunksEvent deleteChunks = new IslandDeleteChunksEvent(island, player, admin, location, deletedIslandInfo);
|
||||
Bukkit.getServer().getPluginManager().callEvent(deleteChunks);
|
||||
Bukkit.getPluginManager().callEvent(deleteChunks);
|
||||
return deleteChunks;
|
||||
case DELETED:
|
||||
IslandDeletedEvent deleted = new IslandDeletedEvent(island, player, admin, location, deletedIslandInfo);
|
||||
Bukkit.getServer().getPluginManager().callEvent(deleted);
|
||||
Bukkit.getPluginManager().callEvent(deleted);
|
||||
return deleted;
|
||||
case ENTER:
|
||||
IslandEnterEvent enter = new IslandEnterEvent(island, player, admin, location);
|
||||
Bukkit.getServer().getPluginManager().callEvent(enter);
|
||||
Bukkit.getPluginManager().callEvent(enter);
|
||||
return enter;
|
||||
case EXIT:
|
||||
IslandExitEvent exit = new IslandExitEvent(island, player, admin, location);
|
||||
Bukkit.getServer().getPluginManager().callEvent(exit);
|
||||
Bukkit.getPluginManager().callEvent(exit);
|
||||
return exit;
|
||||
case LOCK:
|
||||
IslandLockEvent lock = new IslandLockEvent(island, player, admin, location);
|
||||
Bukkit.getServer().getPluginManager().callEvent(lock);
|
||||
Bukkit.getPluginManager().callEvent(lock);
|
||||
return lock;
|
||||
case RESET:
|
||||
IslandResetEvent reset = new IslandResetEvent(island, player, admin, location, blueprintBundle);
|
||||
Bukkit.getServer().getPluginManager().callEvent(reset);
|
||||
Bukkit.getPluginManager().callEvent(reset);
|
||||
return reset;
|
||||
case RESETTED:
|
||||
IslandResettedEvent resetted = new IslandResettedEvent(island, player, admin, location);
|
||||
Bukkit.getServer().getPluginManager().callEvent(resetted);
|
||||
Bukkit.getPluginManager().callEvent(resetted);
|
||||
return resetted;
|
||||
case UNBAN:
|
||||
IslandUnbanEvent unban = new IslandUnbanEvent(island, player, admin, location);
|
||||
Bukkit.getServer().getPluginManager().callEvent(unban);
|
||||
Bukkit.getPluginManager().callEvent(unban);
|
||||
return unban;
|
||||
case UNLOCK:
|
||||
IslandUnlockEvent unlock = new IslandUnlockEvent(island, player, admin, location);
|
||||
Bukkit.getServer().getPluginManager().callEvent(unlock);
|
||||
Bukkit.getPluginManager().callEvent(unlock);
|
||||
return unlock;
|
||||
case REGISTERED:
|
||||
IslandRegisteredEvent reg = new IslandRegisteredEvent(island, player, admin, location);
|
||||
Bukkit.getServer().getPluginManager().callEvent(reg);
|
||||
Bukkit.getPluginManager().callEvent(reg);
|
||||
return reg;
|
||||
case UNREGISTERED:
|
||||
IslandUnregisteredEvent unreg = new IslandUnregisteredEvent(island, player, admin, location);
|
||||
Bukkit.getServer().getPluginManager().callEvent(unreg);
|
||||
Bukkit.getPluginManager().callEvent(unreg);
|
||||
return unreg;
|
||||
default:
|
||||
IslandGeneralEvent general = new IslandGeneralEvent(island, player, admin, location);
|
||||
Bukkit.getServer().getPluginManager().callEvent(general);
|
||||
Bukkit.getPluginManager().callEvent(general);
|
||||
return general;
|
||||
}
|
||||
}
|
||||
|
@ -22,13 +22,19 @@ public class PanelItemBuilder {
|
||||
private boolean playerHead;
|
||||
private boolean invisible;
|
||||
|
||||
public PanelItemBuilder icon(Material icon) {
|
||||
this.icon = new ItemStack(icon);
|
||||
/**
|
||||
* Default icon if someone gives invalid material or item stack.
|
||||
*/
|
||||
private static final ItemStack DEFAULT_ICON = new ItemStack(Material.PAPER);
|
||||
|
||||
|
||||
public PanelItemBuilder icon(@Nullable Material icon) {
|
||||
this.icon = icon == null ? DEFAULT_ICON : new ItemStack(icon);
|
||||
return this;
|
||||
}
|
||||
|
||||
public PanelItemBuilder icon(ItemStack icon) {
|
||||
this.icon = icon;
|
||||
public PanelItemBuilder icon(@Nullable ItemStack icon) {
|
||||
this.icon = icon == null ? DEFAULT_ICON : icon;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -43,8 +43,7 @@ abstract class BasicPlaceholderExpansion extends PlaceholderExpansion {
|
||||
@Override
|
||||
public String onPlaceholderRequest(Player p, String placeholder) {
|
||||
User user = User.getInstance(p);
|
||||
|
||||
if (placeholders.containsKey(placeholder)) {
|
||||
if (user != null && placeholders.containsKey(placeholder)) {
|
||||
return placeholders.get(placeholder).onReplace(user);
|
||||
}
|
||||
return null;
|
||||
|
@ -87,7 +87,7 @@ public class User {
|
||||
* @return user - user
|
||||
*/
|
||||
@Nullable
|
||||
public static User getInstance(UUID uuid) {
|
||||
public static User getInstance(@Nullable UUID uuid) {
|
||||
if (uuid == null) {
|
||||
return null;
|
||||
}
|
||||
@ -293,7 +293,7 @@ public class User {
|
||||
public int getPermissionValue(String permissionPrefix, int defaultValue) {
|
||||
// If requester is console, then return the default value
|
||||
if (!isPlayer()) return defaultValue;
|
||||
|
||||
|
||||
int value = defaultValue;
|
||||
|
||||
// If there is a dot at the end of the permissionPrefix, remove it
|
||||
|
@ -56,8 +56,9 @@ public class Blueprint {
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public Blueprint setName(String name) {
|
||||
this.name = name;
|
||||
public Blueprint setName(@NonNull String name) {
|
||||
// Force lowercase
|
||||
this.name = name.toLowerCase(Locale.ENGLISH);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Banner;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
@ -288,6 +289,12 @@ public class BlueprintClipboard {
|
||||
cs.setSpawnRange(spawner.getSpawnRange());
|
||||
b.setCreatureSpawner(cs);
|
||||
}
|
||||
|
||||
// Banners
|
||||
if (blockState instanceof Banner) {
|
||||
b.setBannerPatterns(((Banner) blockState).getPatterns());
|
||||
}
|
||||
|
||||
this.bpBlocks.put(pos, b);
|
||||
return true;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Banner;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
@ -18,15 +19,10 @@ import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.type.Sign;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
import org.bukkit.entity.AbstractHorse;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.ChestedHorse;
|
||||
import org.bukkit.entity.Horse;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.material.Colorable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
@ -93,7 +89,7 @@ public class BlueprintPaster {
|
||||
* @param island - island related to this paste
|
||||
* @param task - task to run after pasting
|
||||
*/
|
||||
public BlueprintPaster(@NonNull BentoBox plugin, Blueprint bp, World world, Island island, Runnable task) {
|
||||
public BlueprintPaster(@NonNull BentoBox plugin, @NonNull Blueprint bp, World world, Island island, Runnable task) {
|
||||
this.plugin = plugin;
|
||||
// Offset due to bedrock
|
||||
Vector off = bp.getBedrock() != null ? bp.getBedrock() : new Vector(0,0,0);
|
||||
@ -135,7 +131,7 @@ public class BlueprintPaster {
|
||||
count++;
|
||||
}
|
||||
while (pasteState.equals(PasteState.ENTITIES) && count < pasteSpeed && it3.hasNext()) {
|
||||
pasteEntity(world, loc, it3.next());
|
||||
pasteEntity(world, island, loc, it3.next());
|
||||
count++;
|
||||
}
|
||||
// STATE SHIFT
|
||||
@ -211,11 +207,11 @@ public class BlueprintPaster {
|
||||
return blockData;
|
||||
}
|
||||
|
||||
private void pasteEntity(World world, Location location, Entry<Vector, List<BlueprintEntity>> entry) {
|
||||
private void pasteEntity(World world, Island island, Location location, Entry<Vector, List<BlueprintEntity>> entry) {
|
||||
int x = location.getBlockX() + entry.getKey().getBlockX();
|
||||
int y = location.getBlockY() + entry.getKey().getBlockY();
|
||||
int z = location.getBlockZ() + entry.getKey().getBlockZ();
|
||||
setEntity(new Location(world, x, y, z), entry.getValue());
|
||||
setEntity(island, new Location(world, x, y, z), entry.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -251,54 +247,45 @@ public class BlueprintPaster {
|
||||
spawner.setSpawnRange(s.getSpawnRange());
|
||||
bs.update(true, false);
|
||||
}
|
||||
// Banners
|
||||
if (bs instanceof Banner) {
|
||||
Banner banner = (Banner) bs;
|
||||
banner.setPatterns(bpBlock.getBannerPatterns());
|
||||
banner.update(true, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets any entity that is in this location
|
||||
* @param island - Island
|
||||
* @param location - location
|
||||
* @param list - list of entities to paste
|
||||
*/
|
||||
private void setEntity(Location location, List<BlueprintEntity> list) {
|
||||
private void setEntity(@Nullable Island island, Location location, List<BlueprintEntity> list) {
|
||||
list.stream().filter(k -> k.getType() != null).forEach(k -> {
|
||||
// Center, and just a bit high
|
||||
Location center = location.add(new Vector(0.5, 0.5, 0.5));
|
||||
LivingEntity e = (LivingEntity)location.getWorld().spawnEntity(center, k.getType());
|
||||
if (k.getCustomName() != null) {
|
||||
e.setCustomName(k.getCustomName());
|
||||
}
|
||||
if (e instanceof Colorable && k.getColor() != null) {
|
||||
((Colorable) e).setColor(k.getColor());
|
||||
}
|
||||
if (e instanceof Tameable && k.getTamed() != null) {
|
||||
((Tameable)e).setTamed(k.getTamed());
|
||||
}
|
||||
if (e instanceof ChestedHorse && k.getChest() != null) {
|
||||
((ChestedHorse)e).setCarryingChest(k.getChest());
|
||||
}
|
||||
if (e instanceof Ageable && k.getAdult() != null) {
|
||||
if (k.getAdult()) {
|
||||
((Ageable)e).setAdult();
|
||||
} else {
|
||||
((Ageable)e).setBaby();
|
||||
}
|
||||
}
|
||||
if (e instanceof AbstractHorse) {
|
||||
AbstractHorse horse = (AbstractHorse)e;
|
||||
if (k.getDomestication() != null) horse.setDomestication(k.getDomestication());
|
||||
if (k.getInventory() != null) {
|
||||
k.getInventory().forEach(horse.getInventory()::setItem);
|
||||
}
|
||||
}
|
||||
if (e instanceof Horse && k.getStyle() != null) {
|
||||
((Horse)e).setStyle(k.getStyle());
|
||||
}
|
||||
});
|
||||
String customName = k.getCustomName();
|
||||
|
||||
if (island != null) {
|
||||
// Parse any placeholders in the entity's name, if the owner's connected (he should)
|
||||
Player owner = User.getInstance(island.getOwner()).getPlayer();
|
||||
if (owner != null) {
|
||||
customName = plugin.getPlaceholdersManager().replacePlaceholders(owner, customName);
|
||||
}
|
||||
}
|
||||
|
||||
// Actually set the custom name
|
||||
e.setCustomName(customName);
|
||||
}
|
||||
k.configureEntity(e);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Tracks the minimum and maximum block positions
|
||||
* @param world - world
|
||||
* @param l - location of block pasted
|
||||
*/
|
||||
private void updatePos(Location l) {
|
||||
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
@ -22,6 +23,11 @@ public class BlueprintBlock {
|
||||
private Map<Integer, ItemStack> inventory;
|
||||
@Expose
|
||||
private BlueprintCreatureSpawner creatureSpawner;
|
||||
/**
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@Expose
|
||||
private List<Pattern> bannerPatterns;
|
||||
|
||||
public BlueprintBlock(String blockData) {
|
||||
this.blockData = blockData;
|
||||
@ -82,4 +88,20 @@ public class BlueprintBlock {
|
||||
public void setCreatureSpawner(BlueprintCreatureSpawner creatureSpawner) {
|
||||
this.creatureSpawner = creatureSpawner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list of the banner patterns
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public List<Pattern> getBannerPatterns() {
|
||||
return bannerPatterns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bannerPatterns the banner Patterns to set
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public void setBannerPatterns(List<Pattern> bannerPatterns) {
|
||||
this.bannerPatterns = bannerPatterns;
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,16 @@ package world.bentobox.bentobox.blueprints.dataobjects;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.entity.AbstractHorse;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.ChestedHorse;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Horse;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Horse.Style;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.Colorable;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
@ -34,6 +41,38 @@ public class BlueprintEntity {
|
||||
@Expose
|
||||
private Style style;
|
||||
|
||||
/**
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public void configureEntity(Entity e) {
|
||||
if (e instanceof Colorable) {
|
||||
((Colorable) e).setColor(color);
|
||||
}
|
||||
if (tamed != null && e instanceof Tameable) {
|
||||
((Tameable)e).setTamed(tamed);
|
||||
}
|
||||
if (chest != null && e instanceof ChestedHorse) {
|
||||
((ChestedHorse)e).setCarryingChest(chest);
|
||||
}
|
||||
if (adult != null && e instanceof Ageable) {
|
||||
if (adult) {
|
||||
((Ageable)e).setAdult();
|
||||
} else {
|
||||
((Ageable)e).setBaby();
|
||||
}
|
||||
}
|
||||
if (e instanceof AbstractHorse) {
|
||||
AbstractHorse horse = (AbstractHorse)e;
|
||||
if (domestication != null) horse.setDomestication(domestication);
|
||||
if (inventory != null) {
|
||||
inventory.forEach(horse.getInventory()::setItem);
|
||||
}
|
||||
}
|
||||
if (style != null && e instanceof Horse) {
|
||||
((Horse)e).setStyle(style);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @return the color
|
||||
*/
|
||||
|
@ -55,7 +55,7 @@ public class BentoBoxReloadCommand extends ConfirmableCommand {
|
||||
user.sendMessage("commands.bentobox.reload.locales-reloaded");
|
||||
|
||||
// Fire ready event
|
||||
Bukkit.getServer().getPluginManager().callEvent(new BentoBoxReadyEvent());
|
||||
Bukkit.getPluginManager().callEvent(new BentoBoxReadyEvent());
|
||||
});
|
||||
} else {
|
||||
showHelp(this, user);
|
||||
|
@ -18,10 +18,10 @@ public class MongoDBDatabase implements DatabaseSetup {
|
||||
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {
|
||||
BentoBox plugin = BentoBox.getInstance();
|
||||
// Check if the MongoDB plugin exists
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("BsbMongo") == null) {
|
||||
if (Bukkit.getPluginManager().getPlugin("BsbMongo") == null) {
|
||||
plugin.logError("You must install BsbMongo plugin for MongoDB support!");
|
||||
plugin.logError("See: https://github.com/tastybento/bsbMongo/releases/");
|
||||
Bukkit.getServer().getPluginManager().disablePlugin(plugin);
|
||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||
return null;
|
||||
}
|
||||
if (connector == null) {
|
||||
|
@ -3,6 +3,8 @@ package world.bentobox.bentobox.database.mongodb;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.mongodb.MongoClientException;
|
||||
import com.mongodb.MongoTimeoutException;
|
||||
import org.bson.Document;
|
||||
import org.bson.conversions.Bson;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -48,16 +50,33 @@ public class MongoDBDatabaseHandler<T> extends AbstractJSONDatabaseHandler<T> {
|
||||
super(plugin, type, dbConnecter);
|
||||
this.dbConnecter = dbConnecter;
|
||||
|
||||
// Connection to the database
|
||||
MongoDatabase database = (MongoDatabase) dbConnecter.createConnection(dataObject);
|
||||
if (database == null) {
|
||||
plugin.logError("Are the settings in config.yml correct?");
|
||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||
return;
|
||||
boolean connected = true; // if it is set to false, it will consider there has been an error upon connecting.
|
||||
try {
|
||||
// Connection to the database
|
||||
MongoDatabase database = (MongoDatabase) dbConnecter.createConnection(dataObject);
|
||||
if (database == null) {
|
||||
plugin.logError("Could not connect to the database. Are the credentials in the config.yml file correct?");
|
||||
connected = false;
|
||||
} else {
|
||||
collection = database.getCollection(dataObject.getCanonicalName());
|
||||
IndexOptions indexOptions = new IndexOptions().unique(true);
|
||||
collection.createIndex(Indexes.text(UNIQUEID), indexOptions);
|
||||
}
|
||||
} catch (MongoTimeoutException e) {
|
||||
plugin.logError("Could not connect to the database. MongoDB timed out.");
|
||||
plugin.logError("Error code: " + e.getCode());
|
||||
plugin.logError("Errors: " + String.join(", ", e.getErrorLabels()));
|
||||
connected = false;
|
||||
} catch (MongoClientException e) {
|
||||
plugin.logError("Could not connect to the database. An unhandled error occurred.");
|
||||
plugin.logStacktrace(e);
|
||||
connected = false;
|
||||
}
|
||||
|
||||
if (!connected) {
|
||||
plugin.logWarning("Disabling BentoBox...");
|
||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||
}
|
||||
collection = database.getCollection(dataObject.getCanonicalName());
|
||||
IndexOptions indexOptions = new IndexOptions().unique(true);
|
||||
collection.createIndex(Indexes.text(UNIQUEID), indexOptions);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -155,17 +155,16 @@ public class SQLDatabaseHandler<T> extends AbstractJSONDatabaseHandler<T> {
|
||||
return;
|
||||
}
|
||||
// Async
|
||||
processQueue.add(() -> store(instance, sqlConfig.getSaveObjectSQL()));
|
||||
processQueue.add(() -> store(instance.getClass().getName(), getGson().toJson(instance), sqlConfig.getSaveObjectSQL()));
|
||||
}
|
||||
|
||||
private void store(T instance, String sb) {
|
||||
String toStore = getGson().toJson(instance);
|
||||
private void store(String name, String toStore, String sb) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sb)) {
|
||||
preparedStatement.setString(1, toStore);
|
||||
preparedStatement.setString(2, toStore);
|
||||
preparedStatement.execute();
|
||||
} catch (SQLException e) {
|
||||
plugin.logError("Could not save object " + instance.getClass().getName() + " " + e.getMessage());
|
||||
plugin.logError("Could not save object " + name + " " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,7 +240,8 @@ public class SQLDatabaseHandler<T> extends AbstractJSONDatabaseHandler<T> {
|
||||
*/
|
||||
public boolean setConnection(Connection connection) {
|
||||
if (connection == null) {
|
||||
plugin.logError("Are the settings in config.yml correct?");
|
||||
plugin.logError("Could not connect to the database. Are the credentials in the config.yml file correct?");
|
||||
plugin.logWarning("Disabling the plugin...");
|
||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||
return false;
|
||||
}
|
||||
|
@ -49,9 +49,9 @@ public class SQLiteDatabaseHandler<T> extends SQLDatabaseHandler<T> {
|
||||
plugin.logError("This class is not a DataObject: " + instance.getClass().getName());
|
||||
return;
|
||||
}
|
||||
processQueue.add(() -> {
|
||||
Gson gson = getGson();
|
||||
String toStore = gson.toJson(instance);
|
||||
Gson gson = getGson();
|
||||
String toStore = gson.toJson(instance);
|
||||
processQueue.add(() -> {
|
||||
try (PreparedStatement preparedStatement = getConnection().prepareStatement(getSqlConfig().getSaveObjectSQL())) {
|
||||
preparedStatement.setString(1, toStore);
|
||||
preparedStatement.setString(2, ((DataObject)instance).getUniqueId());
|
||||
|
@ -166,6 +166,7 @@ public class YamlDatabaseConnector implements DatabaseConnector {
|
||||
Files.delete(commentedFile.toPath());
|
||||
} catch (IOException e1) {
|
||||
plugin.logError("Could not comment config file " + file.getName() + " " + e1.getMessage());
|
||||
plugin.logStacktrace(e1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,17 +32,22 @@ public class DynmapHook extends Hook {
|
||||
|
||||
@Override
|
||||
public boolean hook() {
|
||||
DynmapAPI dynmapAPI = (DynmapAPI) getPlugin();
|
||||
MarkerAPI markers = dynmapAPI.getMarkerAPI();
|
||||
try {
|
||||
DynmapAPI dynmapAPI = (DynmapAPI) getPlugin();
|
||||
|
||||
if (markers == null) {
|
||||
MarkerAPI markers = dynmapAPI.getMarkerAPI();
|
||||
|
||||
if (markers == null) {
|
||||
return false;
|
||||
}
|
||||
markerAPI = markers;
|
||||
|
||||
BentoBox.getInstance().getAddonsManager().getGameModeAddons().forEach(this::registerMarkerSet);
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
markerAPI = markers;
|
||||
|
||||
BentoBox.getInstance().getAddonsManager().getGameModeAddons().forEach(this::registerMarkerSet);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void registerMarkerSet(@NonNull GameModeAddon addon) {
|
||||
@ -79,6 +84,6 @@ public class DynmapHook extends Hook {
|
||||
|
||||
@Override
|
||||
public String getFailureCause() {
|
||||
return "the version of dynmap you're using is incompatible with this hook";
|
||||
return "the version of dynmap you're using is incompatible with this hook. Use a newer version.";
|
||||
}
|
||||
}
|
@ -21,11 +21,29 @@ public class MultiverseCoreHook extends Hook {
|
||||
super("Multiverse-Core", Material.COMPASS);
|
||||
}
|
||||
|
||||
public void registerWorld(World world) {
|
||||
String cmd1 = MULTIVERSE_IMPORT + world.getName() + " " + world.getEnvironment().name().toLowerCase() + " -g " + BentoBox.getInstance().getName();
|
||||
String cmd2 = MULTIVERSE_SET_GENERATOR + BentoBox.getInstance().getName() + " " + world.getName();
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd1);
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd2);
|
||||
/**
|
||||
* Register the world with Multiverse
|
||||
* @param world - world to register
|
||||
* @param islandWorld - if true, then this is an island world
|
||||
*/
|
||||
public void registerWorld(World world, boolean islandWorld) {
|
||||
if (islandWorld) {
|
||||
// Only register generator if one is defined in the addon (is not null)
|
||||
String generator = BentoBox.getInstance().getIWM().getAddon(world).map(gm -> gm.getDefaultWorldGenerator(world.getName(), "") != null).orElse(false) ? " -g " + BentoBox.getInstance().getName() : "";
|
||||
String cmd1 = MULTIVERSE_IMPORT + world.getName() + " " + world.getEnvironment().name().toLowerCase() + generator;
|
||||
String cmd2 = MULTIVERSE_SET_GENERATOR + BentoBox.getInstance().getName() + " " + world.getName();
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd1);
|
||||
if (!generator.isEmpty()) {
|
||||
// Register the generator
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd2);
|
||||
}
|
||||
} else {
|
||||
// Set the generator to null - this will remove any previous registration
|
||||
String cmd1 = MULTIVERSE_IMPORT + world.getName() + " " + world.getEnvironment().name().toLowerCase();
|
||||
String cmd2 = MULTIVERSE_SET_GENERATOR + "null " + world.getName();
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd1);
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,12 +23,16 @@ public class VaultHook extends Hook {
|
||||
|
||||
@Override
|
||||
public boolean hook() {
|
||||
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
try {
|
||||
RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
return false;
|
||||
}
|
||||
economy = rsp.getProvider();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
economy = rsp.getProvider();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,72 @@
|
||||
package world.bentobox.bentobox.listeners;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
|
||||
/**
|
||||
* Blocks command usage for various scenarios
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class BannedCommands implements Listener {
|
||||
|
||||
private BentoBox plugin;
|
||||
|
||||
/**
|
||||
* @param plugin - plugin
|
||||
*/
|
||||
public BannedCommands(@NonNull BentoBox plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents visitors from using commands on islands, like /spawner
|
||||
* @param e - event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onVisitorCommand(PlayerCommandPreprocessEvent e) {
|
||||
if (!plugin.getIWM().inWorld(e.getPlayer().getLocation()) || e.getPlayer().isOp()
|
||||
|| e.getPlayer().hasPermission(plugin.getIWM().getPermissionPrefix(e.getPlayer().getWorld()) + "mod.bypassprotect")
|
||||
|| plugin.getIslands().locationIsOnIsland(e.getPlayer(), e.getPlayer().getLocation())) {
|
||||
return;
|
||||
}
|
||||
World w = e.getPlayer().getWorld();
|
||||
// Check banned commands
|
||||
String[] args = e.getMessage().substring(1).toLowerCase(java.util.Locale.ENGLISH).split(" ");
|
||||
if (plugin.getIWM().getVisitorBannedCommands(w).contains(args[0])) {
|
||||
User user = User.getInstance(e.getPlayer());
|
||||
user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation("protection.command-is-banned"));
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents falling players from using commands, like /warp
|
||||
* @param e - event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onFallingCommand(PlayerCommandPreprocessEvent e) {
|
||||
if (!plugin.getIWM().inWorld(e.getPlayer().getLocation()) || e.getPlayer().isOp()
|
||||
|| e.getPlayer().hasPermission(plugin.getIWM().getPermissionPrefix(e.getPlayer().getWorld()) + "mod.bypassprotect")
|
||||
|| !Flags.PREVENT_TELEPORT_WHEN_FALLING.isSetForWorld(e.getPlayer().getWorld())) {
|
||||
return;
|
||||
}
|
||||
World w = e.getPlayer().getWorld();
|
||||
// Check banned commands
|
||||
String[] args = e.getMessage().substring(1).toLowerCase(java.util.Locale.ENGLISH).split(" ");
|
||||
if (plugin.getIWM().getFallingBannedCommands(w).contains(args[0]) && e.getPlayer().getFallDistance() > 0) {
|
||||
User user = User.getInstance(e.getPlayer());
|
||||
user.notify(Flags.PREVENT_TELEPORT_WHEN_FALLING.getHintReference());
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package world.bentobox.bentobox.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
/**
|
||||
* Blocks visitors from executing commands that they should not in the island world
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class BannedVisitorCommands implements Listener {
|
||||
|
||||
private BentoBox plugin;
|
||||
|
||||
/**
|
||||
* @param plugin - plugin
|
||||
*/
|
||||
public BannedVisitorCommands(@NonNull BentoBox plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents visitors from using commands on islands, like /spawner
|
||||
* @param e - event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onVisitorCommand(PlayerCommandPreprocessEvent e) {
|
||||
if (!plugin.getIWM().inWorld(e.getPlayer().getLocation()) || e.getPlayer().isOp()
|
||||
|| e.getPlayer().hasPermission(plugin.getIWM().getPermissionPrefix(e.getPlayer().getWorld()) + "mod.bypassprotect")
|
||||
|| plugin.getIslands().locationIsOnIsland(e.getPlayer(), e.getPlayer().getLocation())) {
|
||||
return;
|
||||
}
|
||||
// Check banned commands
|
||||
String[] args = e.getMessage().substring(1).toLowerCase(java.util.Locale.ENGLISH).split(" ");
|
||||
if (plugin.getIWM().getVisitorBannedCommands(e.getPlayer().getWorld()).contains(args[0])) {
|
||||
User user = User.getInstance(e.getPlayer());
|
||||
user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation("protection.command-is-banned"));
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -15,7 +15,9 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.blueprints.Blueprint;
|
||||
import world.bentobox.bentobox.blueprints.BlueprintPaster;
|
||||
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBundle;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
import world.bentobox.bentobox.util.teleport.SafeSpotTeleport;
|
||||
@ -115,7 +117,6 @@ public class PortalTeleportationListener implements Listener {
|
||||
new SafeSpotTeleport.Builder(plugin)
|
||||
.entity(e.getPlayer())
|
||||
.location(to)
|
||||
.portal()
|
||||
.build();
|
||||
return true;
|
||||
}
|
||||
@ -197,15 +198,24 @@ public class PortalTeleportationListener implements Listener {
|
||||
* @param env - NETHER or THE_END
|
||||
*/
|
||||
private void pasteNewIsland(Player player, Location to, Island island, Environment env) {
|
||||
String name = env.equals(Environment.NETHER) ? "nether-island" : "end-island";
|
||||
// Paste then teleport player
|
||||
plugin.getIWM().getAddon(island.getWorld()).ifPresent(addon
|
||||
-> new BlueprintPaster(plugin, plugin.getBlueprintsManager().getBlueprints(addon).get(name),
|
||||
to.getWorld(),
|
||||
island, () -> new SafeSpotTeleport.Builder(plugin)
|
||||
.entity(player)
|
||||
.location(island.getSpawnPoint(env) == null ? to : island.getSpawnPoint(env))
|
||||
// No need to use portal because there will be no portal on the other end
|
||||
.build()));
|
||||
plugin.getIWM().getAddon(island.getWorld()).ifPresent(addon -> {
|
||||
// Get the default bundle's nether or end blueprint
|
||||
BlueprintBundle bb = plugin.getBlueprintsManager().getDefaultBlueprintBundle(addon);
|
||||
if (bb != null) {
|
||||
Blueprint bp = plugin.getBlueprintsManager().getBlueprints(addon).get(bb.getBlueprint(env));
|
||||
if (bp != null) {
|
||||
new BlueprintPaster(plugin, bp,
|
||||
to.getWorld(),
|
||||
island, () -> new SafeSpotTeleport.Builder(plugin)
|
||||
.entity(player)
|
||||
.location(island.getSpawnPoint(env) == null ? to : island.getSpawnPoint(env))
|
||||
// No need to use portal because there will be no portal on the other end
|
||||
.build());
|
||||
} else {
|
||||
plugin.logError("Could not paste default island in nether or end. Is there a nether-island or end-island blueprint?");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* Handles protection of the standard Nether and/or End spawns.
|
||||
@ -74,7 +75,7 @@ public class StandardSpawnProtectionListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public boolean onExplosion(EntityExplodeEvent e) {
|
||||
if (!plugin.getIWM().inWorld(e.getLocation())
|
||||
if (!plugin.getIWM().inWorld(Util.getWorld(e.getLocation().getWorld()))
|
||||
|| plugin.getIWM().isIslandNether(e.getLocation().getWorld())
|
||||
|| plugin.getIWM().isIslandEnd(e.getLocation().getWorld())) {
|
||||
// Not used in island worlds
|
||||
@ -122,13 +123,9 @@ public class StandardSpawnProtectionListener implements Listener {
|
||||
* @return true if nothing needs to be done
|
||||
*/
|
||||
private boolean noAction(@NonNull Player player) {
|
||||
if (player.isOp()
|
||||
|| player.getWorld().getEnvironment().equals(World.Environment.NORMAL)
|
||||
|| !plugin.getIWM().inWorld(player.getLocation())) {
|
||||
return true;
|
||||
}
|
||||
// Player is in an island world and in a nether or end
|
||||
return (player.getWorld().getEnvironment().equals(World.Environment.NETHER) && plugin.getIWM().isNetherIslands(player.getWorld()))
|
||||
|| (player.getWorld().getEnvironment().equals(World.Environment.THE_END) && plugin.getIWM().isEndIslands(player.getWorld()));
|
||||
return (player.isOp() || player.getWorld().getEnvironment().equals(World.Environment.NORMAL)
|
||||
|| !plugin.getIWM().inWorld(Util.getWorld(player.getWorld()))
|
||||
|| (player.getWorld().getEnvironment().equals(World.Environment.NETHER) && plugin.getIWM().isNetherIslands(player.getWorld()))
|
||||
|| (player.getWorld().getEnvironment().equals(World.Environment.THE_END) && plugin.getIWM().isEndIslands(player.getWorld())));
|
||||
}
|
||||
}
|
||||
|
@ -287,8 +287,12 @@ public class BlockInteractionListener extends FlagListener {
|
||||
checkIsland(e, player, loc, Flags.ITEM_FRAME);
|
||||
break;
|
||||
case LECTERN:
|
||||
case SWEET_BERRY_BUSH:
|
||||
checkIsland(e, player, loc, Flags.BREAK_BLOCKS);
|
||||
break;
|
||||
case CAKE:
|
||||
checkIsland(e, player, loc, Flags.CAKE);
|
||||
break;
|
||||
default:
|
||||
if (stringFlags.containsKey(type.name())) {
|
||||
Optional<Flag> f = BentoBox.getInstance().getFlagsManager().getFlag(stringFlags.get(type.name()));
|
||||
|
@ -24,11 +24,6 @@ public class DyeListener extends FlagListener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerInteract(final PlayerInteractEvent e) {
|
||||
if (!ServerCompatibility.getInstance().isVersion(ServerCompatibility.ServerVersion.V1_14, ServerCompatibility.ServerVersion.V1_14_1)) {
|
||||
// We're disabling this check for non-1.14 servers.
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.getClickedBlock() == null || e.getItem() == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* Handles respawning back on island
|
||||
@ -30,17 +31,18 @@ public class IslandRespawnListener extends FlagListener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||
if (!getIWM().inWorld(e.getEntity().getLocation())) {
|
||||
World world = Util.getWorld(e.getEntity().getWorld());
|
||||
if (!getIWM().inWorld(world)) {
|
||||
return; // not in the island world
|
||||
}
|
||||
if (!Flags.ISLAND_RESPAWN.isSetForWorld(e.getEntity().getWorld())) {
|
||||
if (!Flags.ISLAND_RESPAWN.isSetForWorld(world)) {
|
||||
return; // world doesn't have the island respawn flag
|
||||
}
|
||||
if (!getIslands().hasIsland(e.getEntity().getWorld(), e.getEntity().getUniqueId()) || !getIslands().inTeam(e.getEntity().getWorld(), e.getEntity().getUniqueId())) {
|
||||
if (!getIslands().hasIsland(world, e.getEntity().getUniqueId()) && !getIslands().inTeam(world, e.getEntity().getUniqueId())) {
|
||||
return; // doesn't have an island in this world
|
||||
}
|
||||
|
||||
respawn.put(e.getEntity().getUniqueId(), e.getEntity().getWorld().getUID());
|
||||
respawn.put(e.getEntity().getUniqueId(), world.getUID());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -59,7 +61,7 @@ public class IslandRespawnListener extends FlagListener {
|
||||
return; // world no longer available
|
||||
}
|
||||
|
||||
final Location respawnLocation = getIslands().getSafeHomeLocation(world, User.getInstance(e.getPlayer().getUniqueId()), 1);
|
||||
final Location respawnLocation = getIslands().getSafeHomeLocation(Util.getWorld(world), User.getInstance(e.getPlayer().getUniqueId()), 1);
|
||||
if (respawnLocation != null) {
|
||||
e.setRespawnLocation(respawnLocation);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
@ -17,6 +18,16 @@ public class RemoveMobsListener extends FlagListener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onUserTeleport(PlayerTeleportEvent e) {
|
||||
// Return if this isn't a genuine teleport
|
||||
if (e.getCause().equals(TeleportCause.CHORUS_FRUIT) || e.getCause().equals(TeleportCause.ENDER_PEARL)
|
||||
|| e.getCause().equals(TeleportCause.SPECTATE)) {
|
||||
return;
|
||||
}
|
||||
// Return if this is a small teleport
|
||||
if (e.getTo().getWorld().equals(e.getPlayer().getWorld()) &&
|
||||
e.getTo().distanceSquared(e.getPlayer().getLocation()) < getPlugin().getSettings().getClearRadius() * getPlugin().getSettings().getClearRadius()) {
|
||||
return;
|
||||
}
|
||||
// Only process if flag is active
|
||||
if (getIslands().locationIsOnIsland(e.getPlayer(), e.getTo()) && Flags.REMOVE_MOBS.isSetForWorld(e.getTo().getWorld())) {
|
||||
Bukkit.getScheduler().runTask(getPlugin(), () -> getIslands().clearArea(e.getTo()));
|
||||
|
@ -22,6 +22,7 @@ public class WitherListener extends FlagListener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onExplosion(final EntityExplodeEvent e) {
|
||||
if (!getIWM().inWorld(e.getLocation())) return;
|
||||
// Remove blocks from the explosion list if required
|
||||
if((e.getEntityType().equals(EntityType.WITHER_SKULL) || e.getEntityType().equals(EntityType.WITHER))
|
||||
&& !Flags.WITHER_DAMAGE.isSetForWorld(e.getLocation().getWorld())) {
|
||||
@ -36,6 +37,7 @@ public class WitherListener extends FlagListener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onWitherChangeBlocks(final EntityChangeBlockEvent e) {
|
||||
if (!getIWM().inWorld(e.getBlock().getWorld())) return;
|
||||
e.setCancelled(e.getEntityType().equals(EntityType.WITHER) && !Flags.WITHER_DAMAGE.isSetForWorld(e.getBlock().getWorld()));
|
||||
}
|
||||
}
|
||||
|
@ -109,6 +109,7 @@ public final class Flags {
|
||||
public static final Flag REDSTONE = new Flag.Builder("REDSTONE", Material.REDSTONE).mode(Flag.Mode.ADVANCED).build();
|
||||
public static final Flag SPAWN_EGGS = new Flag.Builder("SPAWN_EGGS", Material.COW_SPAWN_EGG).build();
|
||||
public static final Flag ITEM_FRAME = new Flag.Builder("ITEM_FRAME", Material.ITEM_FRAME).mode(Flag.Mode.ADVANCED).build();
|
||||
public static final Flag CAKE = new Flag.Builder("CAKE", Material.CAKE).build();
|
||||
/**
|
||||
* Prevents players from interacting with the Dragon Egg.
|
||||
* @since 1.3.1
|
||||
@ -259,14 +260,6 @@ public final class Flags {
|
||||
*/
|
||||
public static final Flag ELYTRA = new Flag.Builder("ELYTRA", Material.ELYTRA).defaultRank(RanksManager.VISITOR_RANK).listener(new ElytraListener()).mode(Flag.Mode.ADVANCED).build();
|
||||
|
||||
|
||||
// TNT
|
||||
/**
|
||||
* @deprecated As of 1.5.0, for removal.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Flag TNT = new Flag.Builder("TNT", Material.TNT).listener(new TNTListener()).build();
|
||||
|
||||
// Island lock
|
||||
public static final Flag LOCK = new Flag.Builder("LOCK", Material.TRIPWIRE_HOOK).defaultSetting(true)
|
||||
.defaultRank(RanksManager.VISITOR_RANK).listener(new LockAndBanListener())
|
||||
|
@ -250,8 +250,9 @@ public class AddonsManager {
|
||||
* @return Optional addon object
|
||||
*/
|
||||
@NonNull
|
||||
public Optional<Addon> getAddonByName(@NonNull String name){
|
||||
return addons.stream().filter(a -> a.getDescription().getName().equalsIgnoreCase(name)).findFirst();
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Addon> Optional<T> getAddonByName(@NonNull String name){
|
||||
return addons.stream().filter(a -> a.getDescription().getName().equalsIgnoreCase(name)).map(a -> (T) a).findFirst();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@ -445,4 +446,12 @@ public class AddonsManager {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies all addons that BentoBox has loaded all addons
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public void allLoaded() {
|
||||
addons.forEach(Addon::allLoaded);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,9 +11,11 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.stream.Collectors;
|
||||
@ -79,6 +81,8 @@ public class BlueprintsManager {
|
||||
|
||||
private @NonNull BentoBox plugin;
|
||||
|
||||
private @NonNull Set<GameModeAddon> blueprintsLoaded;
|
||||
|
||||
|
||||
public BlueprintsManager(@NonNull BentoBox plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -100,6 +104,8 @@ public class BlueprintsManager {
|
||||
// Register adapter factory
|
||||
builder.registerTypeAdapterFactory(new BentoboxTypeAdapterFactory(plugin));
|
||||
gson = builder.create();
|
||||
// Loaded tracker
|
||||
blueprintsLoaded = new HashSet<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,6 +148,19 @@ public class BlueprintsManager {
|
||||
return blueprintBundles.get(addon).stream().collect(Collectors.toMap(BlueprintBundle::getUniqueId, b -> b));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default blueprint bundle for game mode
|
||||
* @param addon - game mode addon
|
||||
* @return the default blueprint bundle or null if none
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public BlueprintBundle getDefaultBlueprintBundle(@NonNull GameModeAddon addon) {
|
||||
if (blueprintBundles.containsKey(addon)) {
|
||||
return blueprintBundles.get(addon).stream().filter(bb -> bb.getUniqueId().equals(DEFAULT_BUNDLE_NAME)).findFirst().orElse(null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link File} instance of the blueprints folder of this {@link GameModeAddon}.
|
||||
*
|
||||
@ -159,10 +178,13 @@ public class BlueprintsManager {
|
||||
* @param addon the {@link GameModeAddon} to load the blueprints of.
|
||||
*/
|
||||
public void loadBlueprintBundles(@NonNull GameModeAddon addon) {
|
||||
// Set loading flag
|
||||
blueprintsLoaded.add(addon);
|
||||
Bukkit
|
||||
.getScheduler()
|
||||
.runTaskAsynchronously(
|
||||
plugin, () -> {
|
||||
// Load bundles
|
||||
blueprintBundles.put(addon, new ArrayList<>());
|
||||
// See if there are any schems that need converting
|
||||
new SchemToBlueprint(plugin).convertSchems(addon);
|
||||
@ -172,9 +194,20 @@ public class BlueprintsManager {
|
||||
}
|
||||
// Load blueprints
|
||||
loadBlueprints(addon);
|
||||
|
||||
// Clear loading flag
|
||||
blueprintsLoaded.remove(addon);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if all blueprints are loaded. Only query after all GameModes have been loaded.
|
||||
* @return true if all blueprints are loaded
|
||||
*/
|
||||
public boolean isBlueprintsLoaded() {
|
||||
return blueprintsLoaded.isEmpty();
|
||||
}
|
||||
|
||||
private boolean loadBundles(@NonNull GameModeAddon addon) {
|
||||
File bpf = getBlueprintsFolder(addon);
|
||||
if (!bpf.exists()) {
|
||||
@ -495,7 +528,7 @@ public class BlueprintsManager {
|
||||
}
|
||||
File bpf = getBlueprintsFolder(addon);
|
||||
// Get the filename
|
||||
File fileName = new File(bpf, bp.getName().toLowerCase(Locale.ENGLISH) + BLUEPRINT_SUFFIX);
|
||||
File fileName = new File(bpf, bp.getName() + BLUEPRINT_SUFFIX);
|
||||
// Delete the old file
|
||||
try {
|
||||
Files.deleteIfExists(fileName.toPath());
|
||||
@ -503,10 +536,9 @@ public class BlueprintsManager {
|
||||
plugin.logError("Could not delete old Blueprint " + e.getLocalizedMessage());
|
||||
}
|
||||
// Set new name
|
||||
bp.setName(name);
|
||||
bp.setName(name.toLowerCase(Locale.ENGLISH));
|
||||
// Save it
|
||||
saveBlueprint(addon, bp);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public class FlagsManager {
|
||||
private void registerListener(@NonNull Listener l) {
|
||||
registeredListeners.putIfAbsent(l, false);
|
||||
if (!registeredListeners.get(l)) {
|
||||
Bukkit.getServer().getPluginManager().registerEvents(l, plugin);
|
||||
Bukkit.getPluginManager().registerEvents(l, plugin);
|
||||
registeredListeners.put(l, true);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package world.bentobox.bentobox.managers;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -47,12 +48,12 @@ public class IslandWorldManager {
|
||||
|
||||
public void registerWorldsToMultiverse() {
|
||||
gameModes.values().stream().distinct().forEach(gm -> {
|
||||
registerToMultiverse(gm.getOverWorld());
|
||||
if (gm.getWorldSettings().isNetherGenerate() && gm.getWorldSettings().isNetherIslands()) {
|
||||
registerToMultiverse(gm.getNetherWorld());
|
||||
registerToMultiverse(gm.getOverWorld(), true);
|
||||
if (gm.getWorldSettings().isNetherGenerate()) {
|
||||
registerToMultiverse(gm.getNetherWorld(), gm.getWorldSettings().isNetherIslands());
|
||||
}
|
||||
if (gm.getWorldSettings().isEndGenerate() && gm.getWorldSettings().isEndIslands()) {
|
||||
registerToMultiverse(gm.getEndWorld());
|
||||
if (gm.getWorldSettings().isEndGenerate()) {
|
||||
registerToMultiverse(gm.getEndWorld(), gm.getWorldSettings().isEndIslands());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -61,14 +62,15 @@ public class IslandWorldManager {
|
||||
* Registers a world with Multiverse if Multiverse is available.
|
||||
*
|
||||
* @param world the World to register
|
||||
* @param islandWorld true if this is an island world
|
||||
*/
|
||||
private void registerToMultiverse(@NonNull World world) {
|
||||
private void registerToMultiverse(@NonNull World world, boolean islandWorld) {
|
||||
if (plugin.getHooks() != null) {
|
||||
plugin.getHooks().getHook("Multiverse-Core").ifPresent(hook -> {
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
((MultiverseCoreHook) hook).registerWorld(world);
|
||||
((MultiverseCoreHook) hook).registerWorld(world, islandWorld);
|
||||
} else {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> ((MultiverseCoreHook) hook).registerWorld(world));
|
||||
Bukkit.getScheduler().runTask(plugin, () -> ((MultiverseCoreHook) hook).registerWorld(world, islandWorld));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -151,7 +153,7 @@ public class IslandWorldManager {
|
||||
// Add worlds to map
|
||||
gameModes.put(world, gameMode);
|
||||
// Call Multiverse
|
||||
registerToMultiverse(world);
|
||||
registerToMultiverse(world, true);
|
||||
if (settings.isNetherGenerate()) {
|
||||
if (!Bukkit.getAllowNether()) {
|
||||
// Warn the users that players might not be able to teleport to these worlds later on
|
||||
@ -162,7 +164,7 @@ public class IslandWorldManager {
|
||||
|
||||
gameModes.put(gameMode.getNetherWorld(), gameMode);
|
||||
if (settings.isNetherIslands()) {
|
||||
registerToMultiverse(gameMode.getNetherWorld());
|
||||
registerToMultiverse(gameMode.getNetherWorld(), true);
|
||||
}
|
||||
}
|
||||
if (settings.isEndGenerate()) {
|
||||
@ -174,8 +176,8 @@ public class IslandWorldManager {
|
||||
}
|
||||
|
||||
gameModes.put(gameMode.getEndWorld(), gameMode);
|
||||
if (settings.isEndGenerate()) {
|
||||
registerToMultiverse(gameMode.getEndWorld());
|
||||
if (settings.isEndIslands()) {
|
||||
registerToMultiverse(gameMode.getEndWorld(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -219,11 +221,7 @@ public class IslandWorldManager {
|
||||
*/
|
||||
@Nullable
|
||||
public WorldSettings getWorldSettings(@NonNull World world) {
|
||||
if (gameModes.containsKey(world)) {
|
||||
return gameModes.get(world).getWorldSettings();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -244,105 +242,105 @@ public class IslandWorldManager {
|
||||
* @return the islandDistance
|
||||
*/
|
||||
public int getIslandDistance(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getIslandDistance();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getIslandDistance() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the islandHeight
|
||||
*/
|
||||
public int getIslandHeight(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getIslandHeight();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getIslandHeight() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the islandProtectionRange
|
||||
*/
|
||||
public int getIslandProtectionRange(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getIslandProtectionRange();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getIslandProtectionRange() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the islandStartX
|
||||
*/
|
||||
public int getIslandStartX(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getIslandStartX();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getIslandStartX() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the islandStartZ
|
||||
*/
|
||||
public int getIslandStartZ(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getIslandStartZ();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getIslandStartZ() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the islandXOffset
|
||||
*/
|
||||
public int getIslandXOffset(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getIslandXOffset();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getIslandXOffset() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the islandZOffset
|
||||
*/
|
||||
public int getIslandZOffset(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getIslandZOffset();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getIslandZOffset() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maxIslands
|
||||
*/
|
||||
public int getMaxIslands(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getMaxIslands();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getMaxIslands() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the netherSpawnRadius
|
||||
*/
|
||||
public int getNetherSpawnRadius(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getNetherSpawnRadius();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getNetherSpawnRadius() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the seaHeight
|
||||
*/
|
||||
public int getSeaHeight(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getSeaHeight();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getSeaHeight() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the worldName
|
||||
*/
|
||||
public String getWorldName(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getWorldName().toLowerCase();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getWorldName().toLowerCase() : world.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the endGenerate
|
||||
*/
|
||||
public boolean isEndGenerate(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isEndGenerate();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isEndGenerate() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the endIslands
|
||||
*/
|
||||
public boolean isEndIslands(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isEndIslands();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isEndIslands() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the netherGenerate
|
||||
*/
|
||||
public boolean isNetherGenerate(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isNetherGenerate();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isNetherGenerate() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the netherIslands
|
||||
*/
|
||||
public boolean isNetherIslands(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isNetherIslands();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isNetherIslands() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -391,29 +389,23 @@ public class IslandWorldManager {
|
||||
/**
|
||||
* Get the nether world of this overWorld
|
||||
*
|
||||
* @param overWorld - overworld
|
||||
* @param world - overworld
|
||||
* @return nether world, or null if it does not exist
|
||||
*/
|
||||
@Nullable
|
||||
public World getNetherWorld(@Nullable World overWorld) {
|
||||
if (gameModes.containsKey(overWorld)) {
|
||||
return gameModes.get(overWorld).getNetherWorld();
|
||||
}
|
||||
return null;
|
||||
public World getNetherWorld(@Nullable World world) {
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getNetherWorld() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the end world of this overWorld
|
||||
*
|
||||
* @param overWorld - overworld
|
||||
* @param world - overworld
|
||||
* @return end world, or null if it does not exist
|
||||
*/
|
||||
@Nullable
|
||||
public World getEndWorld(@Nullable World overWorld) {
|
||||
if (gameModes.containsKey(overWorld)) {
|
||||
return gameModes.get(overWorld).getEndWorld();
|
||||
}
|
||||
return null;
|
||||
public World getEndWorld(@Nullable World world) {
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getEndWorld() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -454,54 +446,51 @@ public class IslandWorldManager {
|
||||
* Get max team size for this world
|
||||
*
|
||||
* @param world - world
|
||||
* @return max team size
|
||||
* @return max team size or zero if world is not a game world
|
||||
*/
|
||||
public int getMaxTeamSize(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getMaxTeamSize();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getMaxTeamSize() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max homes for world
|
||||
*
|
||||
* @param world
|
||||
* - world
|
||||
* @return max homes
|
||||
* @param world - world
|
||||
* @return max homes or 0 if world is not a game world
|
||||
*/
|
||||
public int getMaxHomes(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getMaxHomes();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getMaxHomes() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the friendly name for world or related nether or end
|
||||
*
|
||||
* @param world
|
||||
* - world
|
||||
* @return Friendly name
|
||||
* @param world - world
|
||||
* @return Friendly name or world name if world is not a game world
|
||||
*/
|
||||
public String getFriendlyName(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getFriendlyName();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getFriendlyName() : world.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the permission prefix for this world. Trailing dot included.
|
||||
*
|
||||
* @param world - world
|
||||
* @return permission prefix for this world
|
||||
* @return permission prefix for this world or empty string if world is not a game world
|
||||
*/
|
||||
public String getPermissionPrefix(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getPermissionPrefix() + ".";
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getPermissionPrefix() + "." : "";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the invincible visitor settings for this world
|
||||
*
|
||||
* @param world
|
||||
* - world
|
||||
* @return invincible visitor settings
|
||||
* @param world - world
|
||||
* @return invincible visitor settings or an empty list if world is not a game world
|
||||
*/
|
||||
public List<String> getIvSettings(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getIvSettings();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getIvSettings() : Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -521,65 +510,147 @@ public class IslandWorldManager {
|
||||
/**
|
||||
* Get the default game mode for this world.
|
||||
*
|
||||
* @param world
|
||||
* - world
|
||||
* @return GameMode: SURVIVAL, CREATIVE, ADVENTURE, SPECTATOR
|
||||
* @param world - world
|
||||
* @return GameMode: SURVIVAL, CREATIVE, ADVENTURE, SPECTATOR. Default is SURVIVAL if world is not a game world
|
||||
*/
|
||||
public GameMode getDefaultGameMode(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getDefaultGameMode();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getDefaultGameMode() : GameMode.SURVIVAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the set of entity types not to remove when player teleports to island
|
||||
*
|
||||
* @param world
|
||||
* - world
|
||||
* @param world - world
|
||||
* @return - set of entity types
|
||||
*/
|
||||
public Set<EntityType> getRemoveMobsWhitelist(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getRemoveMobsWhitelist();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getRemoveMobsWhitelist() : Collections.emptySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the onJoinResetMoney
|
||||
*/
|
||||
public boolean isOnJoinResetMoney(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isOnJoinResetMoney();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnJoinResetMoney() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the onJoinResetInventory
|
||||
*/
|
||||
public boolean isOnJoinResetInventory(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isOnJoinResetInventory();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnJoinResetInventory() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the onJoinResetEnderChest
|
||||
*/
|
||||
public boolean isOnJoinResetEnderChest(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isOnJoinResetEnderChest();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnJoinResetEnderChest() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a player's health should be reset upon him joining or creating an island in this World.
|
||||
* @param world the World
|
||||
* @return {@code true} if health should be reset, {@code false} otherwise.
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public boolean isOnJoinResetHealth(@NonNull World world) {
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnJoinResetHealth() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a player's hunger should be reset upon him joining or creating an island in this World.
|
||||
* @param world the World
|
||||
* @return {@code true} if hunger should be reset, {@code false} otherwise.
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public boolean isOnJoinResetHunger(@NonNull World world) {
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnJoinResetHunger() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a player's XP should be reset upon him joining or creating an island in this World.
|
||||
* @param world the World
|
||||
* @return {@code true} if XP should be reset, {@code false} otherwise.
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public boolean isOnJoinResetXP(@NonNull World world) {
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnJoinResetXP() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of commands to execute when the player creates or joins an island.
|
||||
* @param world the World
|
||||
* @return a list of commands
|
||||
* @since 1.8.0
|
||||
* @see #getOnLeaveCommands(World)
|
||||
*/
|
||||
@NonNull
|
||||
public List<String> getOnJoinCommands(@NonNull World world) {
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getOnJoinCommands() : Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the onLeaveResetMoney
|
||||
*/
|
||||
public boolean isOnLeaveResetMoney(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isOnLeaveResetMoney();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnLeaveResetMoney() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the onLeaveResetInventory
|
||||
*/
|
||||
public boolean isOnLeaveResetInventory(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isOnLeaveResetInventory();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnLeaveResetInventory() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the onLeaveResetEnderChest
|
||||
*/
|
||||
public boolean isOnLeaveResetEnderChest(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isOnLeaveResetEnderChest();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnLeaveResetEnderChest() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a player's health should be reset upon him leaving or resetting his island in this World.
|
||||
* @param world the World
|
||||
* @return {@code true} if health should be reset, {@code false} otherwise.
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public boolean isOnLeaveResetHealth(@NonNull World world) {
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnLeaveResetHealth() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a player's hunger should be reset upon him leaving or resetting his island in this World.
|
||||
* @param world the World
|
||||
* @return {@code true} if hunger should be reset, {@code false} otherwise.
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public boolean isOnLeaveResetHunger(@NonNull World world) {
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnLeaveResetHunger() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a player's XP should be reset upon him leaving or resetting his island in this World.
|
||||
* @param world the World
|
||||
* @return {@code true} if XP should be reset, {@code false} otherwise.
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public boolean isOnLeaveResetXP(@NonNull World world) {
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isOnLeaveResetXP() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of commands to execute when the player resets or leaves an island.
|
||||
* @param world the World
|
||||
* @return a list of commands
|
||||
* @since 1.8.0
|
||||
* @see #getOnJoinCommands(World)
|
||||
*/
|
||||
@NonNull
|
||||
public List<String> getOnLeaveCommands(@NonNull World world) {
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getOnLeaveCommands() : Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -605,12 +676,11 @@ public class IslandWorldManager {
|
||||
/**
|
||||
* Get default island flag settings for this world.
|
||||
*
|
||||
* @param world
|
||||
* - world
|
||||
* @param world - world
|
||||
* @return default rank settings for new islands.
|
||||
*/
|
||||
public Map<Flag, Integer> getDefaultIslandFlags(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getDefaultIslandFlags();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getDefaultIslandFlags() : Collections.emptyMap();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -619,7 +689,7 @@ public class IslandWorldManager {
|
||||
* @return list of hidden flags
|
||||
*/
|
||||
public List<String> getHiddenFlags(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getHiddenFlags();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getHiddenFlags() : Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -630,11 +700,11 @@ public class IslandWorldManager {
|
||||
* @return default settings for new islands
|
||||
*/
|
||||
public Map<Flag, Integer> getDefaultIslandSettings(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getDefaultIslandSettings();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getDefaultIslandSettings() : Collections.emptyMap();
|
||||
}
|
||||
|
||||
public boolean isUseOwnGenerator(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isUseOwnGenerator();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isUseOwnGenerator() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -642,7 +712,15 @@ public class IslandWorldManager {
|
||||
* @return the visitorbannedcommands
|
||||
*/
|
||||
public List<String> getVisitorBannedCommands(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getVisitorBannedCommands();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getVisitorBannedCommands() : Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return banned commands when falling
|
||||
* @return the fallingbannedcommands
|
||||
*/
|
||||
public List<String> getFallingBannedCommands(@NonNull World world) {
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getFallingBannedCommands() : Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -651,7 +729,7 @@ public class IslandWorldManager {
|
||||
* @return true if water is not safe, e.g.for home locations
|
||||
*/
|
||||
public boolean isWaterNotSafe(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isWaterUnsafe();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isWaterUnsafe() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -660,7 +738,7 @@ public class IslandWorldManager {
|
||||
* @return list
|
||||
*/
|
||||
public List<String> getGeoLimitSettings(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getGeoLimitSettings();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getGeoLimitSettings() : Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -678,7 +756,7 @@ public class IslandWorldManager {
|
||||
* @param world - world
|
||||
*/
|
||||
public long getResetEpoch(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getResetEpoch();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getResetEpoch() : 0L;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -686,7 +764,7 @@ public class IslandWorldManager {
|
||||
* @param world - world
|
||||
*/
|
||||
public void setResetEpoch(@NonNull World world) {
|
||||
gameModes.get(world).getWorldSettings().setResetEpoch(System.currentTimeMillis());
|
||||
if (gameModes.containsKey(world)) gameModes.get(world).getWorldSettings().setResetEpoch(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -695,7 +773,7 @@ public class IslandWorldManager {
|
||||
* @return true or false
|
||||
*/
|
||||
public boolean isTeamJoinDeathReset(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isTeamJoinDeathReset();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isTeamJoinDeathReset() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -706,7 +784,7 @@ public class IslandWorldManager {
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public boolean isDeathsResetOnNewIsland(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isDeathsResetOnNewIsland();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isDeathsResetOnNewIsland() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -715,7 +793,7 @@ public class IslandWorldManager {
|
||||
* @return max deaths
|
||||
*/
|
||||
public int getDeathsMax(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getDeathsMax();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getDeathsMax() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -724,21 +802,21 @@ public class IslandWorldManager {
|
||||
* @return ban limit
|
||||
*/
|
||||
public int getBanLimit(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().getBanLimit();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().getBanLimit() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether leavers should lose a reset or not
|
||||
*/
|
||||
public boolean isLeaversLoseReset(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isLeaversLoseReset();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isLeaversLoseReset() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether players keep their inventory if they are kicked. Overrides leave inventory clearing
|
||||
*/
|
||||
public boolean isKickedKeepInventory(@NonNull World world) {
|
||||
return gameModes.get(world).getWorldSettings().isKickedKeepInventory();
|
||||
return gameModes.containsKey(world) ? gameModes.get(world).getWorldSettings().isKickedKeepInventory() : true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@ -28,6 +29,7 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.PufferFish;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
@ -38,6 +40,7 @@ import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
import world.bentobox.bentobox.api.events.island.IslandEvent;
|
||||
import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
|
||||
import world.bentobox.bentobox.api.flags.Flag;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.logs.LogEntry;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
@ -94,6 +97,12 @@ public class IslandsManager {
|
||||
@NonNull
|
||||
private List<String> deletedIslands;
|
||||
|
||||
private Set<String> toSave = new HashSet<>();
|
||||
|
||||
private Iterator<String> it;
|
||||
|
||||
private BukkitTask task;
|
||||
|
||||
/**
|
||||
* Islands Manager
|
||||
* @param plugin - plugin
|
||||
@ -670,7 +679,17 @@ public class IslandsManager {
|
||||
}
|
||||
// If this is a new island, then run commands and do resets
|
||||
if (newIsland) {
|
||||
// TODO add command running
|
||||
// Execute commands
|
||||
plugin.getIWM().getOnJoinCommands(world).forEach(command -> {
|
||||
command = command.replace("[player]", player.getName());
|
||||
if (command.startsWith("[SUDO]")) {
|
||||
// Execute the command by the player
|
||||
player.performCommand(command.substring(6));
|
||||
} else {
|
||||
// Otherwise execute as the server console
|
||||
plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
}
|
||||
});
|
||||
|
||||
// Remove money inventory etc.
|
||||
if (plugin.getIWM().isOnJoinResetEnderChest(world)) {
|
||||
@ -682,6 +701,21 @@ public class IslandsManager {
|
||||
if (plugin.getSettings().isUseEconomy() && plugin.getIWM().isOnJoinResetMoney(world)) {
|
||||
plugin.getVault().ifPresent(vault -> vault.withdraw(user, vault.getBalance(user)));
|
||||
}
|
||||
|
||||
// Reset the health
|
||||
if (plugin.getIWM().isOnJoinResetHealth(world)) {
|
||||
user.getPlayer().setHealth(20.0D);
|
||||
}
|
||||
|
||||
// Reset the hunger
|
||||
if (plugin.getIWM().isOnJoinResetHunger(world)) {
|
||||
user.getPlayer().setFoodLevel(20);
|
||||
}
|
||||
|
||||
// Reset the XP
|
||||
if (plugin.getIWM().isOnJoinResetXP(world)) {
|
||||
user.getPlayer().setTotalExperience(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -755,6 +789,19 @@ public class IslandsManager {
|
||||
this.spawn.put(spawn.getWorld(), spawn);
|
||||
spawn.setSpawn(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the spawn island for this world
|
||||
* @param world - world
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public void clearSpawn(World world) {
|
||||
Island spawnIsland = spawn.get(Util.getWorld(world));
|
||||
if (spawnIsland != null) {
|
||||
spawnIsland.setSpawn(false);
|
||||
}
|
||||
this.spawn.remove(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uniqueId - unique ID
|
||||
@ -959,6 +1006,24 @@ public class IslandsManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves all the players at a rate of 1 per tick. Used as a backup.
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public void asyncSaveAll() {
|
||||
if (!toSave.isEmpty()) return;
|
||||
// Get a list of ID's to save
|
||||
toSave = new HashSet<>(islandCache.getAllIslandIds());
|
||||
it = toSave.iterator();
|
||||
task = Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
||||
if (plugin.isEnabled() && it.hasNext()) {
|
||||
getIslandById(it.next()).ifPresent(this::save);
|
||||
} else {
|
||||
toSave.clear();
|
||||
task.cancel();
|
||||
}
|
||||
}, 0L, 1L);
|
||||
}
|
||||
/**
|
||||
* Puts a player in a team. Removes them from their old island if required.
|
||||
* @param teamIsland - team island
|
||||
@ -1201,6 +1266,17 @@ public class IslandsManager {
|
||||
this.saveAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets a flag to gamemode config.yml default
|
||||
* @param world - world
|
||||
* @param flag - flag to reset
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public void resetFlag(World world, Flag flag) {
|
||||
islandCache.resetFlag(world, flag);
|
||||
this.saveAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the specified island custom name exists in this world.
|
||||
* @param world World of the gamemode
|
||||
@ -1212,4 +1288,5 @@ public class IslandsManager {
|
||||
return getIslands(world).stream().filter(island -> island.getName() != null).map(Island::getName)
|
||||
.anyMatch(n -> ChatColor.stripColor(n).equals(ChatColor.stripColor(name)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
@ -15,6 +16,7 @@ import java.util.jar.JarFile;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
@ -108,7 +110,7 @@ public class LocalesManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies locale files from the addon jar to the file system
|
||||
* Copies locale files from the addon jar to the file system and updates current locales with the latest references
|
||||
* @param addon - addon
|
||||
*/
|
||||
void copyLocalesFromAddonJar(Addon addon) {
|
||||
@ -116,14 +118,39 @@ public class LocalesManager {
|
||||
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + addon.getDescription().getName());
|
||||
if (!localeDir.exists()) {
|
||||
localeDir.mkdirs();
|
||||
// Obtain any locale files and save them
|
||||
Util.listJarFiles(jar, LOCALE_FOLDER, ".yml").forEach(lf -> addon.saveResource(lf, localeDir, false, true));
|
||||
}
|
||||
// Obtain any locale files, save them and update
|
||||
Util.listJarFiles(jar, LOCALE_FOLDER, ".yml").forEach(lf -> {
|
||||
File file = addon.saveResource(lf, localeDir, false, true);
|
||||
// Update
|
||||
if (file != null) {
|
||||
updateLocale(addon, file, lf);
|
||||
}
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
plugin.logError(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLocale(Addon addon, File fileLocaleFile, String lf) {
|
||||
try {
|
||||
// Load the JAR locale file
|
||||
YamlConfiguration jarLocale = addon.getYamlFromJar(lf);
|
||||
// Load the locale file system locale file
|
||||
YamlConfiguration fileLocale = new YamlConfiguration();
|
||||
fileLocale.load(fileLocaleFile);
|
||||
// Copy new keys to file
|
||||
jarLocale.getKeys(true).stream().filter(k -> !fileLocale.contains(k, false)).forEach(k -> fileLocale.set(k, jarLocale.get(k)));
|
||||
// Save file
|
||||
fileLocale.save(fileLocaleFile);
|
||||
} catch (Exception e) {
|
||||
plugin.logError("Error updating locale file: " + lf + " : " + e.getMessage());
|
||||
plugin.logStacktrace(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all the locale files from the plugin jar to the filesystem.
|
||||
* Only done if the locale folder does not already exist.
|
||||
@ -135,18 +162,36 @@ public class LocalesManager {
|
||||
// If it does exist, then new files will NOT be written!
|
||||
if (!localeDir.exists()) {
|
||||
localeDir.mkdirs();
|
||||
FileLister lister = new FileLister(plugin);
|
||||
try {
|
||||
for (String name : lister.listJar(LOCALE_FOLDER)) {
|
||||
// We cannot use Bukkit's saveResource, because we want it to go into a specific folder, so...
|
||||
// Get the last part of the name
|
||||
int lastIndex = name.lastIndexOf('/');
|
||||
File targetFile = new File(localeDir, name.substring(lastIndex >= 0 ? lastIndex : 0));
|
||||
copyFile(name, targetFile);
|
||||
}
|
||||
FileLister lister = new FileLister(plugin);
|
||||
try {
|
||||
for (String name : lister.listJar(LOCALE_FOLDER)) {
|
||||
// We cannot use Bukkit's saveResource, because we want it to go into a specific folder, so...
|
||||
// Get the last part of the name
|
||||
int lastIndex = name.lastIndexOf('/');
|
||||
File targetFile = new File(localeDir, name.substring(lastIndex >= 0 ? lastIndex : 0));
|
||||
copyFile(name, targetFile);
|
||||
// Update the locale file if it exists already
|
||||
try (InputStreamReader in = new InputStreamReader(plugin.getResource(name))) {
|
||||
YamlConfiguration jarLocale = new YamlConfiguration();
|
||||
jarLocale.load(in);
|
||||
|
||||
YamlConfiguration fileLocale = new YamlConfiguration();
|
||||
fileLocale.load(targetFile);
|
||||
for (String k : jarLocale.getKeys(true)) {
|
||||
if (!fileLocale.contains(k, false)) {
|
||||
fileLocale.set(k, jarLocale.get(k));
|
||||
}
|
||||
}
|
||||
// Save it
|
||||
fileLocale.save(targetFile);
|
||||
} catch (InvalidConfigurationException e) {
|
||||
plugin.logError("Could not update locale files from jar " + e.getMessage());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
plugin.logError("Could not copy locale files from jar " + e.getMessage());
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
plugin.logError("Could not copy locale files from jar " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,9 +225,9 @@ public class LocalesManager {
|
||||
languages.put(localeObject, new BentoBoxLocale(localeObject, languageYaml));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
BentoBox.getInstance().logError("Could not load '" + language.getName() + "' : " + e.getMessage()
|
||||
plugin.logError("Could not load '" + language.getName() + "' : " + e.getMessage()
|
||||
+ " with the following cause '" + e.getCause() + "'." +
|
||||
" The file has likely an invalid YML format or has been made unreadable during the process.");
|
||||
" The file has likely an invalid YML format or has been made unreadable during the process.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -256,7 +301,11 @@ public class LocalesManager {
|
||||
plugin.log(ChatColor.AQUA + "Analyzing BentoBox locale files");
|
||||
user.sendRawMessage(ChatColor.AQUA + SPACER);
|
||||
loadLocalesFromFile(BENTOBOX);
|
||||
analyze(fix);
|
||||
if (languages.containsKey(Locale.US)) {
|
||||
analyze(user, fix);
|
||||
} else {
|
||||
user.sendRawMessage(ChatColor.RED + "No US English in BentoBox to use for analysis!");
|
||||
}
|
||||
user.sendRawMessage(ChatColor.AQUA + "Analyzing Addon locale files");
|
||||
plugin.getAddonsManager().getAddons().forEach(addon -> {
|
||||
user.sendRawMessage(ChatColor.AQUA + SPACER);
|
||||
@ -264,22 +313,23 @@ public class LocalesManager {
|
||||
user.sendRawMessage(ChatColor.AQUA + SPACER);
|
||||
languages.clear();
|
||||
loadLocalesFromFile(addon.getDescription().getName());
|
||||
analyze(fix);
|
||||
if (languages.containsKey(Locale.US)) {
|
||||
analyze(user, fix);
|
||||
} else {
|
||||
user.sendRawMessage(ChatColor.RED + "No US English to use for analysis!");
|
||||
}
|
||||
});
|
||||
reloadLanguages();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param user
|
||||
* @param fix whether or not locale files with missing translations should be fixed.
|
||||
* Not currently supported.
|
||||
* @since 1.5.0
|
||||
*/
|
||||
private void analyze(boolean fix) {
|
||||
if (!languages.containsKey(Locale.US)) {
|
||||
return;
|
||||
}
|
||||
User user = User.getInstance(Bukkit.getConsoleSender());
|
||||
private void analyze(User user, boolean fix) {
|
||||
|
||||
user.sendRawMessage(ChatColor.GREEN + "The following locales are supported:");
|
||||
languages.forEach((k,v) -> user.sendRawMessage(ChatColor.GOLD + k.toLanguageTag() + " " + k.getDisplayLanguage() + " " + k.getDisplayCountry()));
|
||||
|
@ -4,12 +4,15 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
@ -28,6 +31,9 @@ public class PlayersManager {
|
||||
|
||||
private Map<UUID, Players> playerCache;
|
||||
private Set<UUID> inTeleport;
|
||||
private Set<UUID> toSave = new HashSet<>();
|
||||
private Iterator<UUID> it;
|
||||
private BukkitTask task;
|
||||
|
||||
/**
|
||||
* Provides a memory cache of online player information
|
||||
@ -70,6 +76,25 @@ public class PlayersManager {
|
||||
Collections.unmodifiableCollection(playerCache.values()).forEach(handler::saveObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves all the players at a rate of 1 per tick. Used as a backup.
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public void asyncSaveAll() {
|
||||
if (!toSave.isEmpty()) return;
|
||||
// Get a list of ID's to save
|
||||
toSave = new HashSet<>(playerCache.keySet());
|
||||
it = toSave.iterator();
|
||||
task = Bukkit.getScheduler().runTaskTimer(plugin, () -> {
|
||||
if (plugin.isEnabled() && it.hasNext()) {
|
||||
this.save(it.next());
|
||||
} else {
|
||||
toSave.clear();
|
||||
task.cancel();
|
||||
}
|
||||
}, 0L, 1L);
|
||||
}
|
||||
|
||||
public void shutdown(){
|
||||
saveAll();
|
||||
playerCache.clear();
|
||||
@ -368,7 +393,7 @@ public class PlayersManager {
|
||||
*/
|
||||
public int getDeaths(World world, UUID playerUUID) {
|
||||
addPlayer(playerUUID);
|
||||
return playerCache.get(playerUUID).getDeaths(world);
|
||||
return playerCache.get(playerUUID) == null ? 0 : playerCache.get(playerUUID).getDeaths(world);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,36 +59,27 @@ public class WebManager {
|
||||
if (plugin.getSettings().isLogGithubDownloadData()) {
|
||||
plugin.log("Downloading data from GitHub...");
|
||||
}
|
||||
GitHubRepository repo = new GitHubRepository(gh, "BentoBoxWorld/weblink");
|
||||
GitHubRepository repo;
|
||||
try {
|
||||
repo = new GitHubRepository(gh, "BentoBoxWorld/weblink");
|
||||
} catch (Exception e) {
|
||||
plugin.logError("An unhandled exception occurred when trying to connect to GitHub...");
|
||||
plugin.logStacktrace(e);
|
||||
|
||||
String tagsContent = "";
|
||||
String topicsContent = "";
|
||||
String catalogContent = "";
|
||||
// Stop the execution of the method right away.
|
||||
return;
|
||||
}
|
||||
|
||||
// Downloading the data
|
||||
try {
|
||||
tagsContent = repo.getContent("catalog/tags.json").getContent().replaceAll("\\n", "");
|
||||
topicsContent = repo.getContent("catalog/topics.json").getContent().replaceAll("\\n", "");
|
||||
catalogContent = repo.getContent("catalog/catalog.json").getContent().replaceAll("\\n", "");
|
||||
} catch (IllegalAccessException e) {
|
||||
if (plugin.getSettings().isLogGithubDownloadData()) {
|
||||
plugin.log("Could not connect to GitHub.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
plugin.logError("An unhandled exception occurred when downloading data from GitHub...");
|
||||
plugin.logStacktrace(e);
|
||||
}
|
||||
String tagsContent = getContent(repo, "catalog/tags.json");
|
||||
String topicsContent = getContent(repo, "catalog/topics.json");
|
||||
String catalogContent = getContent(repo, "catalog/catalog.json");
|
||||
|
||||
// People were concerned that the download took ages, so we need to tell them it's over now.
|
||||
if (plugin.getSettings().isLogGithubDownloadData()) {
|
||||
plugin.log("Successfully downloaded data from GitHub.");
|
||||
}
|
||||
|
||||
// Decoding the Base64 encoded contents
|
||||
tagsContent = new String(Base64.getDecoder().decode(tagsContent), StandardCharsets.UTF_8);
|
||||
topicsContent = new String(Base64.getDecoder().decode(topicsContent), StandardCharsets.UTF_8);
|
||||
catalogContent = new String(Base64.getDecoder().decode(catalogContent), StandardCharsets.UTF_8);
|
||||
|
||||
/* Parsing the data */
|
||||
|
||||
// Register the tags translations in the locales
|
||||
@ -140,6 +131,29 @@ public class WebManager {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param repo
|
||||
* @param fileName
|
||||
* @return
|
||||
* @since 1.8.0
|
||||
*/
|
||||
@NonNull
|
||||
private String getContent(@NonNull GitHubRepository repo, String fileName) {
|
||||
try {
|
||||
String content = repo.getContent(fileName).getContent().replaceAll("\\n", "");
|
||||
return new String(Base64.getDecoder().decode(content), StandardCharsets.UTF_8);
|
||||
} catch (IllegalAccessException e) {
|
||||
if (plugin.getSettings().isLogGithubDownloadData()) {
|
||||
plugin.log("Could not connect to GitHub.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
plugin.logError("An unhandled exception occurred when downloading '" + fileName + "' from GitHub...");
|
||||
plugin.logStacktrace(e);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contents of the addons catalog (may be an empty list).
|
||||
* @return the contents of the addons catalog.
|
||||
|
@ -0,0 +1,154 @@
|
||||
package world.bentobox.bentobox.managers.island;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* The default strategy for generating locations for island
|
||||
* @author tastybento, leonardochaia
|
||||
* @since 1.8.0
|
||||
*
|
||||
*/
|
||||
public class DefaultNewIslandLocationStrategy implements NewIslandLocationStrategy {
|
||||
|
||||
/**
|
||||
* The amount times to tolerate island check returning blocks without kwnon
|
||||
* island.
|
||||
*/
|
||||
protected static final Integer MAX_UNOWNED_ISLANDS = 10;
|
||||
|
||||
protected enum Result {
|
||||
ISLAND_FOUND, BLOCK_AT_CENTER, BLOCKS_IN_AREA, FREE
|
||||
}
|
||||
|
||||
protected BentoBox plugin = BentoBox.getInstance();
|
||||
|
||||
public Location getNextLocation(World world) {
|
||||
Location last = plugin.getIslands().getLast(world);
|
||||
if (last == null) {
|
||||
last = new Location(world,
|
||||
(double) plugin.getIWM().getIslandXOffset(world) + plugin.getIWM().getIslandStartX(world),
|
||||
plugin.getIWM().getIslandHeight(world),
|
||||
(double) plugin.getIWM().getIslandZOffset(world) + plugin.getIWM().getIslandStartZ(world));
|
||||
}
|
||||
// Find a free spot
|
||||
Map<Result, Integer> result = new EnumMap<>(Result.class);
|
||||
// Check center
|
||||
last = Util.getClosestIsland(last);
|
||||
Result r = isIsland(last);
|
||||
|
||||
while (!r.equals(Result.FREE) && result.getOrDefault(Result.BLOCK_AT_CENTER, 0) < MAX_UNOWNED_ISLANDS) {
|
||||
nextGridLocation(last);
|
||||
last = Util.getClosestIsland(last);
|
||||
result.merge(r, 1, (k, v) -> v++);
|
||||
r = isIsland(last);
|
||||
}
|
||||
|
||||
if (!r.equals(Result.FREE)) {
|
||||
// We could not find a free spot within the limit required. It's likely this
|
||||
// world is not empty
|
||||
plugin.logError("Could not find a free spot for islands! Is this world empty?");
|
||||
plugin.logError("Blocks at center locations: " + result.getOrDefault(Result.BLOCK_AT_CENTER, 0) + " max "
|
||||
+ MAX_UNOWNED_ISLANDS);
|
||||
plugin.logError("Blocks around center locations: " + result.getOrDefault(Result.BLOCKS_IN_AREA, 0) + " max "
|
||||
+ MAX_UNOWNED_ISLANDS);
|
||||
plugin.logError("Known islands: " + result.getOrDefault(Result.ISLAND_FOUND, 0) + " max unlimited.");
|
||||
return null;
|
||||
}
|
||||
plugin.getIslands().setLast(last);
|
||||
return last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there is an island or blocks at this location
|
||||
*
|
||||
* @param location - the location
|
||||
* @return true if island found, null if blocks found, false if nothing found
|
||||
*/
|
||||
protected Result isIsland(Location location) {
|
||||
|
||||
// Check 4 corners
|
||||
int dist = plugin.getIWM().getIslandDistance(location.getWorld());
|
||||
Set<Location> locs = new HashSet<>();
|
||||
locs.add(location);
|
||||
|
||||
locs.add(new Location(location.getWorld(), location.getX() - dist, 0, location.getZ() - dist));
|
||||
locs.add(new Location(location.getWorld(), location.getX() - dist, 0, location.getZ() + dist - 1));
|
||||
locs.add(new Location(location.getWorld(), location.getX() + dist - 1, 0, location.getZ() - dist));
|
||||
locs.add(new Location(location.getWorld(), location.getX() + dist - 1, 0, location.getZ() + dist - 1));
|
||||
|
||||
for (Location l : locs) {
|
||||
if (plugin.getIslands().getIslandAt(l).isPresent() || plugin.getIslandDeletionManager().inDeletion(l)) {
|
||||
return Result.ISLAND_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
if (!plugin.getIWM().isUseOwnGenerator(location.getWorld())) {
|
||||
// Block check
|
||||
if (!location.getBlock().isEmpty() && !location.getBlock().getType().equals(Material.WATER)) {
|
||||
plugin.getIslands().createIsland(location);
|
||||
return Result.BLOCK_AT_CENTER;
|
||||
}
|
||||
// Look around
|
||||
for (int x = -5; x <= 5; x++) {
|
||||
for (int y = 10; y < location.getWorld().getMaxHeight(); y++) {
|
||||
for (int z = -5; z <= 5; z++) {
|
||||
if (!location.getWorld().getBlockAt(x + location.getBlockX(), y, z + location.getBlockZ())
|
||||
.isEmpty()
|
||||
&& !location.getWorld()
|
||||
.getBlockAt(x + location.getBlockX(), y, z + location.getBlockZ()).getType()
|
||||
.equals(Material.WATER)) {
|
||||
plugin.getIslands().createIsland(location);
|
||||
return Result.BLOCKS_IN_AREA;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.FREE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the next free island spot based off the last known island Uses
|
||||
* island_distance setting from the config file Builds up in a grid fashion
|
||||
*
|
||||
* @param lastIsland - last island location
|
||||
* @return Location of next free island
|
||||
*/
|
||||
private Location nextGridLocation(final Location lastIsland) {
|
||||
int x = lastIsland.getBlockX();
|
||||
int z = lastIsland.getBlockZ();
|
||||
int d = plugin.getIWM().getIslandDistance(lastIsland.getWorld()) * 2;
|
||||
if (x < z) {
|
||||
if (-1 * x < z) {
|
||||
lastIsland.setX(lastIsland.getX() + d);
|
||||
return lastIsland;
|
||||
}
|
||||
lastIsland.setZ(lastIsland.getZ() + d);
|
||||
return lastIsland;
|
||||
}
|
||||
if (x > z) {
|
||||
if (-1 * x >= z) {
|
||||
lastIsland.setX(lastIsland.getX() - d);
|
||||
return lastIsland;
|
||||
}
|
||||
lastIsland.setZ(lastIsland.getZ() - d);
|
||||
return lastIsland;
|
||||
}
|
||||
if (x <= 0) {
|
||||
lastIsland.setZ(lastIsland.getZ() + d);
|
||||
return lastIsland;
|
||||
}
|
||||
lastIsland.setZ(lastIsland.getZ() - d);
|
||||
return lastIsland;
|
||||
}
|
||||
}
|
@ -16,6 +16,8 @@ import org.bukkit.World;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.flags.Flag;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
@ -312,4 +314,25 @@ public class IslandCache {
|
||||
World w = Util.getWorld(world);
|
||||
islandsById.values().stream().filter(i -> i.getWorld().equals(w)).forEach(Island::setFlagsDefaults);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets a specific flag on all game mode islands in world to default setting
|
||||
* @param world - world
|
||||
* @param flag - flag to reset
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public void resetFlag(World world, Flag flag) {
|
||||
World w = Util.getWorld(world);
|
||||
int setting = BentoBox.getInstance().getIWM().getDefaultIslandFlags(w).getOrDefault(flag, flag.getDefaultRank());
|
||||
islandsById.values().stream().filter(i -> i.getWorld().equals(w)).forEach(i -> i.setFlag(flag, setting));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the island ids
|
||||
* @return set of ids
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public Set<String> getAllIslandIds() {
|
||||
return islandsById.keySet();
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,12 @@
|
||||
package world.bentobox.bentobox.managers.island;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import world.bentobox.bentobox.BStats;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
@ -23,7 +17,6 @@ import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.BlueprintsManager;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* Create and paste a new island
|
||||
@ -31,7 +24,6 @@ import world.bentobox.bentobox.util.Util;
|
||||
*
|
||||
*/
|
||||
public class NewIsland {
|
||||
private static final Integer MAX_UNOWNED_ISLANDS = 10;
|
||||
private BentoBox plugin;
|
||||
private Island island;
|
||||
private final User user;
|
||||
@ -41,12 +33,7 @@ public class NewIsland {
|
||||
private final boolean noPaste;
|
||||
private GameModeAddon addon;
|
||||
|
||||
private enum Result {
|
||||
ISLAND_FOUND,
|
||||
BLOCK_AT_CENTER,
|
||||
BLOCKS_IN_AREA,
|
||||
FREE
|
||||
}
|
||||
private NewIslandLocationStrategy locationStrategy;
|
||||
|
||||
public NewIsland(Builder builder) {
|
||||
plugin = BentoBox.getInstance();
|
||||
@ -56,6 +43,12 @@ public class NewIsland {
|
||||
this.name = builder.name2;
|
||||
this.noPaste = builder.noPaste2;
|
||||
this.addon = builder.addon2;
|
||||
this.locationStrategy = builder.locationStrategy2;
|
||||
|
||||
if (this.locationStrategy == null) {
|
||||
this.locationStrategy = new DefaultNewIslandLocationStrategy();
|
||||
}
|
||||
|
||||
newIsland(builder.oldIsland2);
|
||||
}
|
||||
|
||||
@ -86,6 +79,7 @@ public class NewIsland {
|
||||
private String name2 = BlueprintsManager.DEFAULT_BUNDLE_NAME;
|
||||
private boolean noPaste2;
|
||||
private GameModeAddon addon2;
|
||||
private NewIslandLocationStrategy locationStrategy2;
|
||||
|
||||
public Builder oldIsland(Island oldIsland) {
|
||||
this.oldIsland2 = oldIsland;
|
||||
@ -130,6 +124,15 @@ public class NewIsland {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param strategy - the location strategy to use
|
||||
* @since 1.8.0
|
||||
*/
|
||||
public Builder locationStrategy(NewIslandLocationStrategy strategy) {
|
||||
this.locationStrategy2 = strategy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Island
|
||||
* @throws IOException - if there are insufficient parameters defined
|
||||
@ -163,7 +166,7 @@ public class NewIsland {
|
||||
}
|
||||
// If the reservation fails, then we need to make a new island anyway
|
||||
if (next == null) {
|
||||
next = getNextIsland();
|
||||
next = this.locationStrategy.getNextLocation(world);
|
||||
if (next == null) {
|
||||
plugin.logError("Failed to make island - no unoccupied spot found");
|
||||
return;
|
||||
@ -274,121 +277,4 @@ public class NewIsland {
|
||||
// Save island
|
||||
plugin.getIslands().save(island);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the location of next free island spot
|
||||
* @return Location of island spot or null if one cannot be found
|
||||
*/
|
||||
@Nullable
|
||||
private Location getNextIsland() {
|
||||
Location last = plugin.getIslands().getLast(world);
|
||||
if (last == null) {
|
||||
last = new Location(world,
|
||||
(double) plugin.getIWM().getIslandXOffset(world) + plugin.getIWM().getIslandStartX(world),
|
||||
plugin.getIWM().getIslandHeight(world),
|
||||
(double) plugin.getIWM().getIslandZOffset(world) + plugin.getIWM().getIslandStartZ(world));
|
||||
}
|
||||
// Find a free spot
|
||||
Map<Result, Integer> result = new EnumMap<>(Result.class);
|
||||
// Check center
|
||||
Result r = isIsland(last);
|
||||
|
||||
while (!r.equals(Result.FREE) && result.getOrDefault(Result.BLOCK_AT_CENTER, 0) < MAX_UNOWNED_ISLANDS) {
|
||||
nextGridLocation(last);
|
||||
result.merge(r, 1, (k,v) -> v++);
|
||||
r = isIsland(last);
|
||||
}
|
||||
if (!r.equals(Result.FREE)) {
|
||||
// We could not find a free spot within the limit required. It's likely this world is not empty
|
||||
plugin.logError("Could not find a free spot for islands! Is this world empty?");
|
||||
plugin.logError("Blocks at center locations: " + result.getOrDefault(Result.BLOCK_AT_CENTER, 0) + " max " + MAX_UNOWNED_ISLANDS);
|
||||
plugin.logError("Blocks around center locations: " + result.getOrDefault(Result.BLOCKS_IN_AREA, 0) + " max " + MAX_UNOWNED_ISLANDS);
|
||||
plugin.logError("Known islands: " + result.getOrDefault(Result.ISLAND_FOUND, 0) + " max unlimited.");
|
||||
return null;
|
||||
}
|
||||
plugin.getIslands().setLast(last);
|
||||
return last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there is an island or blocks at this location
|
||||
* @param location - the location
|
||||
* @return true if island found, null if blocks found, false if nothing found
|
||||
*/
|
||||
private Result isIsland(Location location){
|
||||
location = Util.getClosestIsland(location);
|
||||
|
||||
// Check 4 corners
|
||||
int dist = plugin.getIWM().getIslandDistance(location.getWorld());
|
||||
Set<Location> locs = new HashSet<>();
|
||||
locs.add(location);
|
||||
|
||||
locs.add(new Location(location.getWorld(), location.getX() - dist, 0, location.getZ() - dist));
|
||||
locs.add(new Location(location.getWorld(), location.getX() - dist, 0, location.getZ() + dist - 1));
|
||||
locs.add(new Location(location.getWorld(), location.getX() + dist - 1, 0, location.getZ() - dist));
|
||||
locs.add(new Location(location.getWorld(), location.getX() + dist - 1, 0, location.getZ() + dist - 1));
|
||||
|
||||
for (Location l : locs) {
|
||||
if (plugin.getIslands().getIslandAt(l).isPresent() || plugin.getIslandDeletionManager().inDeletion(l)) {
|
||||
return Result.ISLAND_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
if (!plugin.getIWM().isUseOwnGenerator(location.getWorld())) {
|
||||
// Block check
|
||||
if (!location.getBlock().isEmpty() && !location.getBlock().getType().equals(Material.WATER)) {
|
||||
plugin.getIslands().createIsland(location);
|
||||
return Result.BLOCK_AT_CENTER;
|
||||
}
|
||||
// Look around
|
||||
for (int x = -5; x <= 5; x++) {
|
||||
for (int y = 10; y < location.getWorld().getMaxHeight(); y++) {
|
||||
for (int z = -5; z <= 5; z++) {
|
||||
if (!location.getWorld().getBlockAt(x + location.getBlockX(), y, z + location.getBlockZ()).isEmpty()
|
||||
&& !location.getWorld().getBlockAt(x + location.getBlockX(), y, z + location.getBlockZ()).getType().equals(Material.WATER)) {
|
||||
plugin.getIslands().createIsland(location);
|
||||
return Result.BLOCKS_IN_AREA;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.FREE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds the next free island spot based off the last known island Uses
|
||||
* island_distance setting from the config file Builds up in a grid fashion
|
||||
*
|
||||
* @param lastIsland - last island location
|
||||
* @return Location of next free island
|
||||
*/
|
||||
private Location nextGridLocation(final Location lastIsland) {
|
||||
int x = lastIsland.getBlockX();
|
||||
int z = lastIsland.getBlockZ();
|
||||
int d = plugin.getIWM().getIslandDistance(lastIsland.getWorld()) * 2;
|
||||
if (x < z) {
|
||||
if (-1 * x < z) {
|
||||
lastIsland.setX(lastIsland.getX() + d);
|
||||
return lastIsland;
|
||||
}
|
||||
lastIsland.setZ(lastIsland.getZ() + d);
|
||||
return lastIsland;
|
||||
}
|
||||
if (x > z) {
|
||||
if (-1 * x >= z) {
|
||||
lastIsland.setX(lastIsland.getX() - d);
|
||||
return lastIsland;
|
||||
}
|
||||
lastIsland.setZ(lastIsland.getZ() - d);
|
||||
return lastIsland;
|
||||
}
|
||||
if (x <= 0) {
|
||||
lastIsland.setZ(lastIsland.getZ() + d);
|
||||
return lastIsland;
|
||||
}
|
||||
lastIsland.setZ(lastIsland.getZ() - d);
|
||||
return lastIsland;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
package world.bentobox.bentobox.managers.island;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
/**
|
||||
* Determines the locations for new islands
|
||||
* @author tastybento, leonardochaia
|
||||
* @since 1.8.0
|
||||
*
|
||||
*/
|
||||
public interface NewIslandLocationStrategy {
|
||||
public Location getNextLocation(World world);
|
||||
}
|
@ -37,7 +37,7 @@ public class HeadGetter {
|
||||
Iterator<Entry<String, PanelItem>> it = names.entrySet().iterator();
|
||||
if (it.hasNext()) {
|
||||
Entry<String, PanelItem> en = it.next();
|
||||
ItemStack playerSkull = new ItemStack(Material.PLAYER_HEAD, 1);
|
||||
ItemStack playerSkull = new ItemStack(Material.PLAYER_HEAD, en.getValue().getItem().getAmount());
|
||||
SkullMeta meta = (SkullMeta) playerSkull.getItemMeta();
|
||||
meta.setOwner(en.getKey());
|
||||
playerSkull.setItemMeta(meta);
|
||||
|
@ -9,6 +9,8 @@ import org.bukkit.ChunkSnapshot;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
@ -27,9 +29,9 @@ import world.bentobox.bentobox.util.Pair;
|
||||
*/
|
||||
public class SafeSpotTeleport {
|
||||
|
||||
private static final int MAX_CHUNKS = 3;
|
||||
private static final int MAX_CHUNKS = 6;
|
||||
private static final long SPEED = 1;
|
||||
private static final int MAX_RADIUS = 200;
|
||||
private static final int MAX_RADIUS = 50;
|
||||
private static final int MAX_HEIGHT = 235;
|
||||
private boolean notChecking;
|
||||
private BukkitTask task;
|
||||
@ -50,7 +52,7 @@ public class SafeSpotTeleport {
|
||||
* Teleports and entity to a safe spot on island
|
||||
* @param plugin - plugin object
|
||||
* @param entity - entity to teleport
|
||||
* @param location - the location
|
||||
* @param location - the location initial desired location to go to
|
||||
* @param failureMessage - locale key for the failure message
|
||||
* @param portal - true if this is a portal teleport
|
||||
* @param homeNumber - home number to go to
|
||||
@ -128,9 +130,25 @@ public class SafeSpotTeleport {
|
||||
} else {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> ((Player)entity).performCommand("spawn"));
|
||||
}
|
||||
} else {
|
||||
// Create a spot for the player to be
|
||||
if (location.getWorld().getEnvironment().equals(Environment.NETHER)) {
|
||||
makeAndTelport(Material.NETHERRACK);
|
||||
} else if (location.getWorld().getEnvironment().equals(Environment.THE_END)) {
|
||||
makeAndTelport(Material.END_STONE);
|
||||
} else {
|
||||
makeAndTelport(Material.COBBLESTONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void makeAndTelport(Material m) {
|
||||
location.getBlock().getRelative(BlockFace.DOWN).setType(m, false);
|
||||
location.getBlock().setType(Material.AIR, false);
|
||||
location.getBlock().getRelative(BlockFace.UP).setType(Material.AIR, false);
|
||||
location.getBlock().getRelative(BlockFace.UP).getRelative(BlockFace.UP).setType(m, false);
|
||||
entity.teleport(location.clone().add(new Vector(0.5D, 0D, 0.5D)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,6 +78,8 @@ island:
|
||||
kick: true
|
||||
leave: true
|
||||
reset: true
|
||||
# Ask the recipient to confirm trust or coop invites. Team invites always require confirmation.
|
||||
invite: false
|
||||
delay:
|
||||
# Time in seconds that players have to stand still before teleport commands activate, e.g. island go.
|
||||
time: 0
|
||||
|
@ -54,9 +54,20 @@ commands:
|
||||
set:
|
||||
description: "sets the resets of this player"
|
||||
parameters: "<player> <resets>"
|
||||
success: "&aSuccessfully set &b[name]&a's resets to &b[number]&a."
|
||||
reset:
|
||||
description: "resets the resets of this player to 0"
|
||||
parameters: "<player>"
|
||||
success-everyone: "&aSuccessfully reset &beveryone&a's resets to &b0&a."
|
||||
success: "&aSuccessfully reset &b[name]&a's resets to &b0&a."
|
||||
add:
|
||||
description: "adds resets to the player"
|
||||
parameters: "<player> <resets>"
|
||||
success: "&aSuccessfully added &b[number] &aresets to &b[name], increasing the total to &b[total]&a resets."
|
||||
remove:
|
||||
description: "removes resets to the player"
|
||||
parameters: "<player> <resets>"
|
||||
success: "&aSuccessfully removed &b[number] &aresets to &b[name], decreasing the total to &b[total]&a resets."
|
||||
purge:
|
||||
parameters: "[days]"
|
||||
description: "purge islands abandoned for more than [days]"
|
||||
@ -139,6 +150,7 @@ commands:
|
||||
no-island-here: "&cThere is no island here. Confirm to make one."
|
||||
in-deletion: "&cThis island space is currently being deleted. Try later."
|
||||
cannot-make-island: "&cAn island cannot be placed here, sorry. See console for possible errors."
|
||||
island-is-spawn: "&6Island is spawn. Are you sure? Enter command again to confirm."
|
||||
unregister:
|
||||
parameters: "<owner>"
|
||||
description: "unregister owner from island, but keep island blocks"
|
||||
@ -310,8 +322,11 @@ commands:
|
||||
&aLeft click to increment
|
||||
&aRight click to decrement
|
||||
resetflags:
|
||||
parameters: "[flag]"
|
||||
description: "Reset all islands to default flag settings in config.yml"
|
||||
confirm: "&4This will reset the flag(s) to default for all islands!"
|
||||
success: "&aSuccessfully reset all islands' flags to the default settings."
|
||||
success-one: "&a[name] flag set to default for all islands."
|
||||
world:
|
||||
description: "Manage world settings"
|
||||
delete:
|
||||
@ -334,6 +349,14 @@ commands:
|
||||
description: "sets deaths of the player"
|
||||
parameters: "<player> <deaths>"
|
||||
success: "&aSuccessfully set &b[name]&a's deaths to &b[number]&a."
|
||||
add:
|
||||
description: "adds deaths to the player"
|
||||
parameters: "<player> <deaths>"
|
||||
success: "&aSuccessfully added &b[number] &adeaths to &b[name], increasing the total to &b[total]&a deaths."
|
||||
remove:
|
||||
description: "removes deaths to the player"
|
||||
parameters: "<player> <deaths>"
|
||||
success: "&aSuccessfully removed &b[number] &adeaths to &b[name], decreasing the total to &b[total]&a deaths."
|
||||
bentobox:
|
||||
description: "BentoBox admin command"
|
||||
about:
|
||||
@ -458,6 +481,7 @@ commands:
|
||||
already-has-rank: "&cPlayer already has a rank!"
|
||||
you-are-a-coop-member: "&2You were cooped by [name]"
|
||||
success: "&aYou cooped &b[name]."
|
||||
name-has-invited-you: "&a[name] has invited you to join be a coop member of their island."
|
||||
uncoop:
|
||||
description: "remove a coop rank from player"
|
||||
parameters: "<player>"
|
||||
@ -471,7 +495,7 @@ commands:
|
||||
description: "give a player trusted rank on your island"
|
||||
parameters: "<player>"
|
||||
trust-in-yourself: "&cTrust in yourself!"
|
||||
members-trusted: "&cMembers are already trusted"
|
||||
name-has-invited-you: "&a[name] has invited you to join be a trusted member of their island."
|
||||
player-already-trusted: "&cPlayer is already trusted!"
|
||||
you-are-trusted: "&2You are trusted by &b[name]&a!"
|
||||
success: "&aYou trusted &b[name]&a."
|
||||
@ -498,6 +522,7 @@ commands:
|
||||
you-already-are-in-team: "&cYou are already on a team!"
|
||||
already-on-team: "&cThat player is already on a team!"
|
||||
invalid-invite: "&cThat invite is no longer valid, sorry."
|
||||
you-have-already-invited: "&cYou have already invited that player!"
|
||||
parameters: "<player>"
|
||||
you-can-invite: "&aYou can invite [number] more players."
|
||||
accept:
|
||||
@ -639,11 +664,16 @@ protection:
|
||||
description: "Toggle button use"
|
||||
name: "Buttons"
|
||||
hint: "No button use allowed"
|
||||
CAKE:
|
||||
description: "Cake eating disabled"
|
||||
name: "Cakes"
|
||||
hint: "Toggle cake interaction"
|
||||
CONTAINER:
|
||||
name: "Containers"
|
||||
description: |-
|
||||
&aToggle interaction with chests,
|
||||
&ashulker boxes and flower pots.
|
||||
&ashulker boxes and flower pots,
|
||||
&acomposters and barrels.
|
||||
|
||||
&7Other containers are handled
|
||||
&7by dedicated flags.
|
||||
@ -1064,7 +1094,7 @@ protection:
|
||||
&aPrevent players from teleporting
|
||||
&aback to their island using commands
|
||||
&aif they are falling.
|
||||
hint: "&cYou cannot teleport back to your island while you are falling."
|
||||
hint: "&cYou cannot do that while falling."
|
||||
WITHER_DAMAGE:
|
||||
name: "Toggle wither damage"
|
||||
description: |-
|
||||
|
@ -457,11 +457,15 @@ commands:
|
||||
west: Rietumos
|
||||
reset:
|
||||
description: pārstartē salu vai izdzēš iepriekšējo
|
||||
must-remove-members: "&cTev nepieciešams izmest visus spēlētājus no komandas
|
||||
pirms vari pārstartēt salu (/island team kick <spēlētājs>)."
|
||||
none-left: "&cTu esi sasniedzis restartu limitu!"
|
||||
parameters: "<shēma>"
|
||||
resets-left: "&cTev palikuši [number] restarti"
|
||||
resets-left: "&cTev ir palikušas &b[number] &catstatīšanas reizes"
|
||||
confirmation: |-
|
||||
&cVai esi pārliecināts, ka vēlies to darīt?
|
||||
&cVisi salas biedri tiks izmesti no komandas, nāksies viņus aicināt vēlreiz.
|
||||
&cŠai darbībai nav atpakaļceļa. Salu nevarēs atjaunot!
|
||||
kicked-from-island: "&cTu esi izmests no salas iekš [gamemode], jo tās īpašnieks
|
||||
savu salu atstatīja."
|
||||
resetname:
|
||||
description: noņemt salas nosaukumu
|
||||
sethome:
|
||||
@ -481,6 +485,7 @@ commands:
|
||||
name-too-long: "&cPārāk garšs. Maksimālais izmērs ir [number] simboli."
|
||||
name-too-short: "&cPārāk īss. Minimālais izmērs ir [number] simboli."
|
||||
parameters: "<nosaukums>"
|
||||
name-already-exists: "&cSala ar šādu nosaukumu jau eksistē šajā spēles režīmā."
|
||||
settings:
|
||||
description: attaino salas iestatījumus
|
||||
spawn:
|
||||
@ -542,9 +547,9 @@ commands:
|
||||
kick:
|
||||
cannot-kick: "&cTu nevari izmest pats sevi!"
|
||||
description: izmest spēlētāju no tavas salas
|
||||
owner-kicked: "&cSalas īpašnieks izmeta tevi no salas!"
|
||||
parameters: "<spēlētājs>"
|
||||
success: "&b[name] &atika izmests no šīs salas."
|
||||
owner-kicked: "&cĪpašnieks jūs izmeta no savas salas iekš [gamemode]!"
|
||||
leave:
|
||||
cannot-leave: "&cĪpašnieks nevar pamest komandu! Nodod salu citam vai izmet
|
||||
visus no komandas."
|
||||
@ -1223,6 +1228,14 @@ protection:
|
||||
&aĻauj katlem saplēst blokus
|
||||
&aun bojāt radības.
|
||||
name: Pārslēgt
|
||||
SPAWNER_SPAWN_EGGS:
|
||||
description: |-
|
||||
&aAtļauj mainīt radību iekš radīšanas
|
||||
&ablokiem lietojot radīšanas olas.
|
||||
name: Radīšanas olas uz radīšanas blokiem
|
||||
hint: 'mainīt radību radīšanas bloka radību izmantojot radīšanas olu nav atļauta
|
||||
|
||||
'
|
||||
locked: "&cŠī sala ir slēgta!"
|
||||
panel:
|
||||
flag-item:
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,7 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ -92,13 +92,14 @@ public class TestBentoBox {
|
||||
Mockito.when(server.getVersion()).thenReturn("BentoBox_Mocking");
|
||||
|
||||
PluginManager pluginManager = mock(PluginManager.class);
|
||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
||||
|
||||
|
||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
when(Bukkit.getServer()).thenReturn(server);
|
||||
when(Bukkit.getPluginManager()).thenReturn(pluginManager);
|
||||
|
||||
SkullMeta skullMeta = mock(SkullMeta.class);
|
||||
when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
|
||||
|
@ -5,7 +5,7 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ -76,9 +76,10 @@ public class AddonTest {
|
||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||
|
||||
PluginManager pluginManager = mock(PluginManager.class);
|
||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
||||
|
||||
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
when(Bukkit.getPluginManager()).thenReturn(pluginManager);
|
||||
when(Bukkit.getServer()).thenReturn(server);
|
||||
when(Bukkit.getPluginManager()).thenReturn(pluginManager);
|
||||
when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||
|
@ -2,18 +2,20 @@ package world.bentobox.bentobox.api.commands.admin;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
@ -21,7 +23,7 @@ import org.bukkit.util.Vector;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.Mock;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
@ -47,12 +49,18 @@ import world.bentobox.bentobox.managers.PlayersManager;
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class AdminRegisterCommandTest {
|
||||
|
||||
@Mock
|
||||
private CompositeCommand ac;
|
||||
private UUID uuid;
|
||||
@Mock
|
||||
private User user;
|
||||
@Mock
|
||||
private IslandsManager im;
|
||||
@Mock
|
||||
private PlayersManager pm;
|
||||
|
||||
private UUID notUUID;
|
||||
|
||||
private IslandDeletionManager idm;
|
||||
|
||||
/**
|
||||
@ -71,7 +79,6 @@ public class AdminRegisterCommandTest {
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
user = mock(User.class);
|
||||
when(user.isOp()).thenReturn(false);
|
||||
uuid = UUID.randomUUID();
|
||||
notUUID = UUID.randomUUID();
|
||||
@ -84,7 +91,6 @@ public class AdminRegisterCommandTest {
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Parent command has no aliases
|
||||
ac = mock(CompositeCommand.class);
|
||||
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
|
||||
// Island World Manager
|
||||
@ -93,16 +99,14 @@ public class AdminRegisterCommandTest {
|
||||
|
||||
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
|
||||
when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true);
|
||||
when(im.getOwner(Mockito.any(),Mockito.any())).thenReturn(uuid);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
when(im.hasIsland(any(), any(User.class))).thenReturn(true);
|
||||
when(im.isOwner(any(),any())).thenReturn(true);
|
||||
when(im.getOwner(any(),any())).thenReturn(uuid);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
|
||||
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
@ -113,19 +117,17 @@ public class AdminRegisterCommandTest {
|
||||
|
||||
// Locales
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
||||
when(lm.get(any(), any())).thenReturn("mock translation");
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
// Deletion Manager
|
||||
idm = mock(IslandDeletionManager.class);
|
||||
when(idm.inDeletion(Mockito.any())).thenReturn(false);
|
||||
when(idm.inDeletion(any())).thenReturn(false);
|
||||
when(plugin.getIslandDeletionManager()).thenReturn(idm);
|
||||
|
||||
// Plugin Manager
|
||||
Server server = mock(Server.class);
|
||||
PluginManager pim = mock(PluginManager.class);
|
||||
when(server.getPluginManager()).thenReturn(pim);
|
||||
when(Bukkit.getServer()).thenReturn(server);
|
||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||
|
||||
}
|
||||
|
||||
@ -146,10 +148,9 @@ public class AdminRegisterCommandTest {
|
||||
@Test
|
||||
public void testExecuteUnknownPlayer() {
|
||||
AdminRegisterCommand itl = new AdminRegisterCommand(ac);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(null);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage("general.errors.unknown-player", "[name]", name[0]);
|
||||
when(pm.getUUID(any())).thenReturn(null);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
verify(user).sendMessage(eq("general.errors.unknown-player"), eq("[name]"), eq("tastybento"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,12 +159,11 @@ public class AdminRegisterCommandTest {
|
||||
@Test
|
||||
public void testExecutePlayerHasIsland() {
|
||||
AdminRegisterCommand itl = new AdminRegisterCommand(ac);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(false);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.player-has-island"));
|
||||
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
when(im.inTeam(any(), any())).thenReturn(false);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
verify(user).sendMessage(eq("general.errors.player-has-island"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -171,13 +171,12 @@ public class AdminRegisterCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteInTeam() {
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(any(), any())).thenReturn(true);
|
||||
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||
AdminRegisterCommand itl = new AdminRegisterCommand(ac);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage("commands.admin.register.cannot-register-team-player");
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
verify(user).sendMessage("commands.admin.register.cannot-register-team-player");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -185,21 +184,20 @@ public class AdminRegisterCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteAlreadyOwnedIsland() {
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(false);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(im.inTeam(any(), any())).thenReturn(false);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
|
||||
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||
Location loc = mock(Location.class);
|
||||
|
||||
// Island has owner
|
||||
Island is = mock(Island.class);
|
||||
when(is.getOwner()).thenReturn(uuid);
|
||||
Optional<Island> opi = Optional.of(is);
|
||||
when(im.getIslandAt(Mockito.any())).thenReturn(opi);
|
||||
when(im.getIslandAt(any())).thenReturn(opi);
|
||||
when(user.getLocation()).thenReturn(loc);
|
||||
AdminRegisterCommand itl = new AdminRegisterCommand(ac);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage("commands.admin.register.already-owned");
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
verify(user).sendMessage("commands.admin.register.already-owned");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -207,22 +205,21 @@ public class AdminRegisterCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteInDeletionIsland() {
|
||||
when(idm.inDeletion(Mockito.any())).thenReturn(true);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(false);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(idm.inDeletion(any())).thenReturn(true);
|
||||
when(im.inTeam(any(), any())).thenReturn(false);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
|
||||
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||
Location loc = mock(Location.class);
|
||||
|
||||
// Island has owner
|
||||
Island is = mock(Island.class);
|
||||
when(is.getOwner()).thenReturn(uuid);
|
||||
Optional<Island> opi = Optional.of(is);
|
||||
when(im.getIslandAt(Mockito.any())).thenReturn(opi);
|
||||
when(im.getIslandAt(any())).thenReturn(opi);
|
||||
when(user.getLocation()).thenReturn(loc);
|
||||
AdminRegisterCommand itl = new AdminRegisterCommand(ac);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage("commands.admin.register.in-deletion");
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
verify(user).sendMessage("commands.admin.register.in-deletion");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -230,24 +227,23 @@ public class AdminRegisterCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteSuccess() {
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(false);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(any(), any())).thenReturn(false);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
|
||||
Island is = mock(Island.class);
|
||||
Location loc = mock(Location.class);
|
||||
when(loc.toVector()).thenReturn(new Vector(123,123,432));
|
||||
when(is.getCenter()).thenReturn(loc);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is);
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(is);
|
||||
Optional<Island> opi = Optional.of(is);
|
||||
when(im.getIslandAt(Mockito.any())).thenReturn(opi);
|
||||
when(im.getIslandAt(any())).thenReturn(opi);
|
||||
when(user.getLocation()).thenReturn(loc);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||
|
||||
AdminRegisterCommand itl = new AdminRegisterCommand(ac);
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList("tastybento")));
|
||||
// Add other verifications
|
||||
Mockito.verify(user).sendMessage("commands.admin.register.registered-island", "[xyz]", "123,123,432");
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.success"));
|
||||
verify(user).sendMessage(eq("commands.admin.register.registered-island"), eq("[xyz]"), eq("123,123,432"));
|
||||
verify(user).sendMessage(eq("general.success"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,227 @@
|
||||
package world.bentobox.bentobox.api.commands.admin;
|
||||
|
||||
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.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
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.Settings;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.flags.Flag;
|
||||
import world.bentobox.bentobox.api.flags.Flag.Type;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.FlagsManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class AdminResetFlagsCommandTest {
|
||||
|
||||
@Mock
|
||||
private CompositeCommand ac;
|
||||
private UUID uuid = UUID.randomUUID();
|
||||
@Mock
|
||||
private IslandsManager im;
|
||||
@Mock
|
||||
private PlayersManager pm;
|
||||
@Mock
|
||||
private FlagsManager fm;
|
||||
@Mock
|
||||
private Flag flag;
|
||||
@Mock
|
||||
private Flag flag2;
|
||||
@Mock
|
||||
private Flag flag3;
|
||||
@Mock
|
||||
private Player player;
|
||||
|
||||
private AdminResetFlagsCommand arf;
|
||||
private @Nullable User user;
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
// Parent command has no aliases
|
||||
ac = mock(CompositeCommand.class);
|
||||
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
when(ac.getPermissionPrefix()).thenReturn("bskyblock.");
|
||||
|
||||
// Player
|
||||
when(player.getUniqueId()).thenReturn(uuid);
|
||||
user = User.getInstance(player);
|
||||
|
||||
// Flags manager
|
||||
when(plugin.getFlagsManager()).thenReturn(fm);
|
||||
when(flag.getType()).thenReturn(Type.PROTECTION);
|
||||
when(flag2.getType()).thenReturn(Type.SETTING);
|
||||
when(flag3.getType()).thenReturn(Type.WORLD_SETTING);
|
||||
when(flag.getID()).thenReturn("FLAG1");
|
||||
when(flag2.getID()).thenReturn("FLAG2");
|
||||
when(flag3.getID()).thenReturn("FLAG3");
|
||||
@NonNull
|
||||
List<Flag> list = new ArrayList<>();
|
||||
list.add(flag);
|
||||
list.add(flag2);
|
||||
list.add(flag3);
|
||||
when(fm.getFlags()).thenReturn(list);
|
||||
|
||||
// Locales & Placeholders
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
when(lm.get(any(), any())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
||||
PlaceholdersManager phm = mock(PlaceholdersManager.class);
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(phm);
|
||||
when(phm.replacePlaceholders(any(), any())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
||||
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
// Confirmation
|
||||
Settings settings = mock(Settings.class);
|
||||
when(settings.getConfirmationTime()).thenReturn(10);
|
||||
when(plugin.getSettings()).thenReturn(settings);
|
||||
|
||||
// Server & Scheduler
|
||||
BukkitScheduler sch = mock(BukkitScheduler.class);
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||
|
||||
|
||||
// Class
|
||||
arf = new AdminResetFlagsCommand(ac);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
User.clearUsers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminResetFlagsCommand#AdminResetFlagsCommand(world.bentobox.bentobox.api.commands.CompositeCommand)}.
|
||||
*/
|
||||
@Test
|
||||
public void testAdminResetFlagsCommand() {
|
||||
assertEquals("resetflags", arf.getLabel());
|
||||
verify(flag).getID();
|
||||
verify(flag2).getID();
|
||||
verify(flag3, never()).getID();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminResetFlagsCommand#setup()}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetup() {
|
||||
assertFalse(arf.isOnlyPlayer());
|
||||
assertEquals("bskyblock.admin.resetflags", arf.getPermission());
|
||||
assertEquals("commands.admin.resetflags.parameters", arf.getParameters());
|
||||
assertEquals("commands.admin.resetflags.description", arf.getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminResetFlagsCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringTwoArgs() {
|
||||
List<String> args = Arrays.asList("sdfsd", "werwerw");
|
||||
assertFalse(arf.execute(user, "", args));
|
||||
verify(player).sendMessage(eq("commands.help.header"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminResetFlagsCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringOneArgNotFlag() {
|
||||
assertFalse(arf.execute(user, "", Collections.singletonList("FLAG3")));
|
||||
verify(player).sendMessage(eq("commands.help.header"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminResetFlagsCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringOneArgFlag2() {
|
||||
assertTrue(arf.execute(user, "", Collections.singletonList("FLAG2")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminResetFlagsCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringOneArgFlag1() {
|
||||
assertTrue(arf.execute(user, "", Collections.singletonList("FLAG1")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminResetFlagsCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfString() {
|
||||
assertTrue(arf.execute(user, "", Collections.emptyList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminResetFlagsCommand#tabComplete(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testTabCompleteUserStringListOfString() {
|
||||
Optional<List<String>> list = arf.tabComplete(user, "", Collections.emptyList());
|
||||
assertTrue(list.isPresent());
|
||||
assertTrue(list.get().size() == 2);
|
||||
assertTrue(list.get().contains("FLAG1"));
|
||||
assertTrue(list.get().contains("FLAG2"));
|
||||
assertFalse(list.get().contains("FLAG3"));
|
||||
}
|
||||
|
||||
}
|
@ -3,9 +3,9 @@ package world.bentobox.bentobox.api.commands.admin;
|
||||
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.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.any;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -14,7 +14,6 @@ import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
@ -109,10 +108,8 @@ public class AdminSetspawnCommandTest {
|
||||
when(user.getTranslation(Mockito.anyString())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||
|
||||
// Plugin Manager
|
||||
Server server = mock(Server.class);
|
||||
PluginManager pim = mock(PluginManager.class);
|
||||
when(server.getPluginManager()).thenReturn(pim);
|
||||
when(Bukkit.getServer()).thenReturn(server);
|
||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||
|
||||
// Confirmable command settings
|
||||
Settings settings = mock(Settings.class);
|
||||
|
@ -12,7 +12,6 @@ import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
@ -119,10 +118,8 @@ public class AdminUnregisterCommandTest {
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
// Plugin Manager
|
||||
Server server = mock(Server.class);
|
||||
PluginManager pim = mock(PluginManager.class);
|
||||
when(server.getPluginManager()).thenReturn(pim);
|
||||
when(Bukkit.getServer()).thenReturn(server);
|
||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
@ -120,10 +119,8 @@ public class AdminTeamAddCommandTest {
|
||||
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||
|
||||
// Plugin Manager
|
||||
Server server = mock(Server.class);
|
||||
PluginManager pim = mock(PluginManager.class);
|
||||
when(server.getPluginManager()).thenReturn(pim);
|
||||
when(Bukkit.getServer()).thenReturn(server);
|
||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
@ -120,10 +119,8 @@ public class AdminTeamDisbandCommandTest {
|
||||
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||
|
||||
// Plugin Manager
|
||||
Server server = mock(Server.class);
|
||||
PluginManager pim = mock(PluginManager.class);
|
||||
when(server.getPluginManager()).thenReturn(pim);
|
||||
when(Bukkit.getServer()).thenReturn(server);
|
||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,13 @@ package world.bentobox.bentobox.api.commands.admin.team;
|
||||
|
||||
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.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -15,14 +21,14 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
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.Mock;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
@ -47,12 +53,20 @@ import world.bentobox.bentobox.managers.PlayersManager;
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class AdminTeamKickCommandTest {
|
||||
|
||||
@Mock
|
||||
private CompositeCommand ac;
|
||||
private UUID uuid;
|
||||
@Mock
|
||||
private User user;
|
||||
@Mock
|
||||
private IslandsManager im;
|
||||
@Mock
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
@Mock
|
||||
private World world;
|
||||
@Mock
|
||||
private PluginManager pim;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
@ -70,7 +84,6 @@ public class AdminTeamKickCommandTest {
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
user = mock(User.class);
|
||||
when(user.isOp()).thenReturn(false);
|
||||
uuid = UUID.randomUUID();
|
||||
notUUID = UUID.randomUUID();
|
||||
@ -83,8 +96,8 @@ public class AdminTeamKickCommandTest {
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Parent command has no aliases
|
||||
ac = mock(CompositeCommand.class);
|
||||
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
when(ac.getWorld()).thenReturn(world);
|
||||
|
||||
// Island World Manager
|
||||
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
||||
@ -92,16 +105,14 @@ public class AdminTeamKickCommandTest {
|
||||
|
||||
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
|
||||
when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true);
|
||||
when(im.getOwner(Mockito.any(),Mockito.any())).thenReturn(uuid);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
when(im.hasIsland(any(), any(User.class))).thenReturn(true);
|
||||
when(im.isOwner(any(),any())).thenReturn(true);
|
||||
when(im.getOwner(any(),any())).thenReturn(uuid);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
|
||||
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
@ -109,21 +120,16 @@ public class AdminTeamKickCommandTest {
|
||||
BukkitScheduler sch = mock(BukkitScheduler.class);
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
when(Bukkit.getScheduler()).thenReturn(sch);
|
||||
when(Bukkit.getPluginManager()).thenReturn(mock(PluginManager.class));
|
||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||
|
||||
// Locales
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
||||
when(lm.get(any(), any())).thenReturn("mock translation");
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
// Addon
|
||||
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
||||
when(iwm.getAddon(any())).thenReturn(Optional.empty());
|
||||
|
||||
// Plugin Manager
|
||||
Server server = mock(Server.class);
|
||||
PluginManager pim = mock(PluginManager.class);
|
||||
when(server.getPluginManager()).thenReturn(pim);
|
||||
when(Bukkit.getServer()).thenReturn(server);
|
||||
}
|
||||
|
||||
|
||||
@ -144,9 +150,9 @@ public class AdminTeamKickCommandTest {
|
||||
public void testCanExecuteUnknownPlayer() {
|
||||
AdminTeamKickCommand itl = new AdminTeamKickCommand(ac);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(null);
|
||||
when(pm.getUUID(any())).thenReturn(null);
|
||||
assertFalse(itl.canExecute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage("general.errors.unknown-player", "[name]", name[0]);
|
||||
verify(user).sendMessage("general.errors.unknown-player", "[name]", name[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -156,10 +162,10 @@ public class AdminTeamKickCommandTest {
|
||||
public void testCanExecutePlayerNotInTeam() {
|
||||
AdminTeamKickCommand itl = new AdminTeamKickCommand(ac);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(new HashSet<>());
|
||||
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||
when(im.getMembers(any(), any())).thenReturn(new HashSet<>());
|
||||
assertFalse(itl.canExecute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.admin.team.kick.not-in-team"));
|
||||
verify(user).sendMessage(eq("commands.admin.team.kick.not-in-team"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,18 +173,22 @@ public class AdminTeamKickCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteKickOwner() {
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.inTeam(any(), any())).thenReturn(true);
|
||||
Island is = mock(Island.class);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is);
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(is);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||
|
||||
when(is.getOwner()).thenReturn(notUUID);
|
||||
|
||||
AdminTeamKickCommand itl = new AdminTeamKickCommand(ac);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.admin.team.kick.cannot-kick-owner"));
|
||||
Mockito.verify(is).showMembers(Mockito.any());
|
||||
verify(user).sendMessage(eq("commands.admin.team.kick.cannot-kick-owner"));
|
||||
verify(is).showMembers(any());
|
||||
verify(im, never()).removePlayer(eq(world), eq(notUUID));
|
||||
verify(pm, never()).clearHomeLocations(eq(world), eq(notUUID));
|
||||
verify(user, never()).sendMessage(eq("commands.admin.team.kick.success"), anyString(), anyString(), anyString(), anyString());
|
||||
verify(pim, never()).callEvent(any());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -186,19 +196,22 @@ public class AdminTeamKickCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecute() {
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.inTeam(any(), any())).thenReturn(true);
|
||||
Island is = mock(Island.class);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is);
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(is);
|
||||
String name = "tastybento";
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(pm.getName(Mockito.any())).thenReturn(name);
|
||||
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||
when(pm.getName(any())).thenReturn(name);
|
||||
|
||||
when(is.getOwner()).thenReturn(uuid);
|
||||
|
||||
AdminTeamKickCommand itl = new AdminTeamKickCommand(ac);
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Collections.singletonList(name)));
|
||||
Mockito.verify(im).removePlayer(Mockito.any(), Mockito.eq(notUUID));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("commands.admin.team.kick.success"), Mockito.eq(TextVariables.NAME), Mockito.eq(name), Mockito.eq("[owner]"), Mockito.anyString());
|
||||
verify(im).removePlayer(eq(world), eq(notUUID));
|
||||
verify(pm).clearHomeLocations(eq(world), eq(notUUID));
|
||||
verify(user).sendMessage(eq("commands.admin.team.kick.success"), eq(TextVariables.NAME), eq(name), eq("[owner]"), anyString());
|
||||
// Offline so event will be called twice
|
||||
verify(pim, times(2)).callEvent(any());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,10 @@ package world.bentobox.bentobox.api.commands.admin.team;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -14,14 +17,13 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
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.Mock;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
@ -46,10 +48,14 @@ import world.bentobox.bentobox.managers.PlayersManager;
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class AdminTeamSetownerCommandTest {
|
||||
|
||||
@Mock
|
||||
private CompositeCommand ac;
|
||||
private UUID uuid;
|
||||
@Mock
|
||||
private User user;
|
||||
@Mock
|
||||
private IslandsManager im;
|
||||
@Mock
|
||||
private PlayersManager pm;
|
||||
private UUID notUUID;
|
||||
|
||||
@ -69,7 +75,6 @@ public class AdminTeamSetownerCommandTest {
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
// Sometimes use Mockito.withSettings().verboseLogging()
|
||||
user = mock(User.class);
|
||||
when(user.isOp()).thenReturn(false);
|
||||
uuid = UUID.randomUUID();
|
||||
notUUID = UUID.randomUUID();
|
||||
@ -82,7 +87,6 @@ public class AdminTeamSetownerCommandTest {
|
||||
User.setPlugin(plugin);
|
||||
|
||||
// Parent command has no aliases
|
||||
ac = mock(CompositeCommand.class);
|
||||
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
|
||||
// Island World Manager
|
||||
@ -91,16 +95,14 @@ public class AdminTeamSetownerCommandTest {
|
||||
|
||||
|
||||
// Player has island to begin with
|
||||
im = mock(IslandsManager.class);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(true);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(true);
|
||||
when(im.isOwner(Mockito.any(),Mockito.any())).thenReturn(true);
|
||||
when(im.getOwner(Mockito.any(),Mockito.any())).thenReturn(uuid);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
when(im.hasIsland(any(), any(User.class))).thenReturn(true);
|
||||
when(im.isOwner(any(),any())).thenReturn(true);
|
||||
when(im.getOwner(any(),any())).thenReturn(uuid);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
|
||||
// Has team
|
||||
pm = mock(PlayersManager.class);
|
||||
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
|
||||
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
|
||||
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
@ -111,14 +113,12 @@ public class AdminTeamSetownerCommandTest {
|
||||
|
||||
// Locales
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
|
||||
when(lm.get(any(), any())).thenReturn("mock translation");
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
// Plugin Manager
|
||||
Server server = mock(Server.class);
|
||||
PluginManager pim = mock(PluginManager.class);
|
||||
when(server.getPluginManager()).thenReturn(pim);
|
||||
when(Bukkit.getServer()).thenReturn(server);
|
||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||
|
||||
}
|
||||
|
||||
@ -140,9 +140,9 @@ public class AdminTeamSetownerCommandTest {
|
||||
public void testExecuteUnknownPlayer() {
|
||||
AdminTeamSetownerCommand itl = new AdminTeamSetownerCommand(ac);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(null);
|
||||
when(pm.getUUID(any())).thenReturn(null);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage("general.errors.unknown-player", "[name]", name[0]);
|
||||
verify(user).sendMessage("general.errors.unknown-player", "[name]", name[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,10 +152,10 @@ public class AdminTeamSetownerCommandTest {
|
||||
public void testExecutePlayerNotInTeam() {
|
||||
AdminTeamSetownerCommand itl = new AdminTeamSetownerCommand(ac);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(new HashSet<>());
|
||||
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||
when(im.getMembers(any(), any())).thenReturn(new HashSet<>());
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.not-in-team"));
|
||||
verify(user).sendMessage(eq("general.errors.not-in-team"));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,18 +163,18 @@ public class AdminTeamSetownerCommandTest {
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteMakeOwnerAlreadyOwner() {
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.inTeam(any(), any())).thenReturn(true);
|
||||
Island is = mock(Island.class);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is);
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(is);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(pm.getName(Mockito.any())).thenReturn(name[0]);
|
||||
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||
when(pm.getName(any())).thenReturn(name[0]);
|
||||
|
||||
when(im.getOwner(Mockito.any(), Mockito.eq(notUUID))).thenReturn(notUUID);
|
||||
when(im.getOwner(any(), eq(notUUID))).thenReturn(notUUID);
|
||||
|
||||
AdminTeamSetownerCommand itl = new AdminTeamSetownerCommand(ac);
|
||||
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
Mockito.verify(user).sendMessage("commands.admin.team.setowner.already-owner", TextVariables.NAME, name[0]);
|
||||
verify(user).sendMessage("commands.admin.team.setowner.already-owner", TextVariables.NAME, name[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -183,27 +183,27 @@ public class AdminTeamSetownerCommandTest {
|
||||
@Test
|
||||
public void testExecuteSuccess() {
|
||||
// Player is a team member, not an owner
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
|
||||
when(im.hasIsland(Mockito.any(), Mockito.any(User.class))).thenReturn(false);
|
||||
when(im.inTeam(Mockito.any(), Mockito.any())).thenReturn(true);
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
|
||||
when(im.hasIsland(any(), any(User.class))).thenReturn(false);
|
||||
when(im.inTeam(any(), any())).thenReturn(true);
|
||||
Island is = mock(Island.class);
|
||||
when(im.getIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(is);
|
||||
when(im.getIsland(any(), any(UUID.class))).thenReturn(is);
|
||||
String[] name = {"tastybento"};
|
||||
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
|
||||
when(pm.getName(Mockito.any())).thenReturn(name[0]);
|
||||
when(pm.getUUID(any())).thenReturn(notUUID);
|
||||
when(pm.getName(any())).thenReturn(name[0]);
|
||||
// Owner
|
||||
when(im.getOwner(Mockito.any(), Mockito.eq(notUUID))).thenReturn(uuid);
|
||||
when(pm.getName(Mockito.eq(uuid))).thenReturn("owner");
|
||||
when(im.getOwner(any(), eq(notUUID))).thenReturn(uuid);
|
||||
when(pm.getName(eq(uuid))).thenReturn("owner");
|
||||
// Members
|
||||
Set<UUID> members = new HashSet<>();
|
||||
members.add(uuid);
|
||||
members.add(notUUID);
|
||||
when(im.getMembers(Mockito.any(), Mockito.any())).thenReturn(members);
|
||||
when(im.getMembers(any(), any())).thenReturn(members);
|
||||
|
||||
AdminTeamSetownerCommand itl = new AdminTeamSetownerCommand(ac);
|
||||
assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
|
||||
// Add other verifications
|
||||
Mockito.verify(im).setOwner(Mockito.any(), Mockito.eq(user), Mockito.eq(notUUID));
|
||||
Mockito.verify(user).sendMessage("commands.admin.team.setowner.success", TextVariables.NAME, name[0]);
|
||||
verify(im).setOwner(any(), eq(user), eq(notUUID));
|
||||
verify(user).sendMessage("commands.admin.team.setowner.success", TextVariables.NAME, name[0]);
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,10 @@ package world.bentobox.bentobox.api.commands.island;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@ -24,7 +24,6 @@ import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
@ -136,10 +135,8 @@ public class IslandBanCommandTest {
|
||||
|
||||
|
||||
// Server and Plugin Manager for events
|
||||
Server server = mock(Server.class);
|
||||
when(Bukkit.getServer()).thenReturn(server);
|
||||
PluginManager pim = mock(PluginManager.class);
|
||||
when(server.getPluginManager()).thenReturn(pim);
|
||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||
|
||||
// Addon
|
||||
when(ic.getAddon()).thenReturn(addon);
|
||||
|
@ -6,7 +6,7 @@ package world.bentobox.bentobox.api.commands.island;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ -18,7 +18,6 @@ import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
@ -133,10 +132,8 @@ public class IslandExpelCommandTest {
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
// Server and Plugin Manager for events
|
||||
Server server = mock(Server.class);
|
||||
when(Bukkit.getServer()).thenReturn(server);
|
||||
PluginManager pim = mock(PluginManager.class);
|
||||
when(server.getPluginManager()).thenReturn(pim);
|
||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||
|
||||
when(island.getWorld()).thenReturn(mock(World.class));
|
||||
|
||||
|
@ -30,6 +30,7 @@ import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@ -581,6 +582,21 @@ public class IslandGoCommandTest {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnJoinResetHealth() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnJoinResetHunger() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnJoinResetXP() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnLeaveResetEnderChest() {
|
||||
// TODO Auto-generated method stub
|
||||
@ -599,6 +615,21 @@ public class IslandGoCommandTest {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnLeaveResetHealth() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnLeaveResetHunger() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnLeaveResetXP() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseOwnGenerator() {
|
||||
// TODO Auto-generated method stub
|
||||
@ -701,5 +732,14 @@ public class IslandGoCommandTest {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<String> getOnJoinCommands() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<String> getOnLeaveCommands() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,308 @@
|
||||
package world.bentobox.bentobox.api.commands.island;
|
||||
|
||||
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.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.After;
|
||||
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.Settings;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class})
|
||||
public class IslandNearCommandTest {
|
||||
|
||||
@Mock
|
||||
private CompositeCommand ic;
|
||||
@Mock
|
||||
private User user;
|
||||
@Mock
|
||||
private Settings s;
|
||||
@Mock
|
||||
private IslandsManager im;
|
||||
@Mock
|
||||
private PlayersManager pm;
|
||||
@Mock
|
||||
private World world;
|
||||
@Mock
|
||||
private IslandWorldManager iwm;
|
||||
@Mock
|
||||
private @Nullable Island island;
|
||||
@Mock
|
||||
private PluginManager pim;
|
||||
@Mock
|
||||
private Player pp;
|
||||
|
||||
private UUID uuid;
|
||||
|
||||
private IslandNearCommand inc;
|
||||
@Mock
|
||||
private @Nullable Location location;
|
||||
@Mock
|
||||
private Block block;
|
||||
|
||||
/**
|
||||
* @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);
|
||||
when(p.getUniqueId()).thenReturn(uuid);
|
||||
User.getInstance(p);
|
||||
when(p.isOnline()).thenReturn(true);
|
||||
// User
|
||||
User.setPlugin(plugin);
|
||||
when(pm.getName(any())).thenReturn("tastybento");
|
||||
|
||||
when(user.isOp()).thenReturn(false);
|
||||
uuid = UUID.randomUUID();
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.isOnline()).thenReturn(true);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getTranslation(any())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||
|
||||
// Parent command has no aliases
|
||||
when(ic.getSubCommandAliases()).thenReturn(new HashMap<>());
|
||||
when(ic.getTopLabel()).thenReturn("island");
|
||||
// World
|
||||
when(ic.getWorld()).thenReturn(world);
|
||||
|
||||
// IWM friendly name for help
|
||||
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
when(iwm.getIslandDistance(any())).thenReturn(400);
|
||||
|
||||
|
||||
// No island for player to begin with (set it later in the tests)
|
||||
when(im.hasIsland(any(), eq(uuid))).thenReturn(false);
|
||||
when(im.isOwner(any(), eq(uuid))).thenReturn(false);
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
Optional<Island> optionalIsland = Optional.of(island);
|
||||
when(im.getIslandAt(any(Location.class))).thenReturn(optionalIsland);
|
||||
|
||||
// Has team
|
||||
when(im.inTeam(any(), eq(uuid))).thenReturn(true);
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
|
||||
// Locales
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
when(lm.get(Mockito.any(), Mockito.any())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
PlaceholdersManager phm = mock(PlaceholdersManager.class);
|
||||
when(phm.replacePlaceholders(any(), any())).thenAnswer(invocation -> invocation.getArgument(1, String.class));
|
||||
// Placeholder manager
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(phm);
|
||||
|
||||
// Island
|
||||
when(im.getIsland(any(), any(User.class))).thenReturn(island);
|
||||
when(island.getCenter()).thenReturn(location);
|
||||
when(island.getOwner()).thenReturn(uuid);
|
||||
when(location.getBlock()).thenReturn(block);
|
||||
when(block.getRelative(any(), anyInt())).thenReturn(block);
|
||||
when(block.getLocation()).thenReturn(location);
|
||||
when(island.getName()).thenReturn("Island name");
|
||||
|
||||
|
||||
// The command
|
||||
inc = new IslandNearCommand(ic);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
User.clearUsers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandNearCommand#setup()}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetup() {
|
||||
assertEquals("island.near", inc.getPermission());
|
||||
assertTrue(inc.isOnlyPlayer());
|
||||
assertEquals("commands.island.near.parameters", inc.getParameters());
|
||||
assertEquals("commands.island.near.description", inc.getDescription());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandNearCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testCanExecuteWithArgsShowHelp() {
|
||||
assertFalse(inc.canExecute(user, "near", Collections.singletonList("fghjk")));
|
||||
verify(user).sendMessage(eq("commands.help.header"), eq(TextVariables.LABEL), eq("BSkyBlock"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandNearCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testCanExecuteHasTeam() {
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(any(), any())).thenReturn(true);
|
||||
assertTrue(inc.canExecute(user, "near", Collections.emptyList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandNearCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testCanExecuteHasIslandAndTeam() {
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
when(im.inTeam(any(), any())).thenReturn(true);
|
||||
assertTrue(inc.canExecute(user, "near", Collections.emptyList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandNearCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testCanExecuteHasIslandNoTeam() {
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(true);
|
||||
when(im.inTeam(any(), any())).thenReturn(false);
|
||||
assertTrue(inc.canExecute(user, "near", Collections.emptyList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandNearCommand#canExecute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testCanExecuteNoIslandNoTeam() {
|
||||
when(im.hasIsland(any(), any(UUID.class))).thenReturn(false);
|
||||
when(im.inTeam(any(), any())).thenReturn(false);
|
||||
assertFalse(inc.canExecute(user, "near", Collections.emptyList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandNearCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringAllFourPoints() {
|
||||
assertTrue(inc.execute(user, "near", Collections.emptyList()));
|
||||
verify(user).sendMessage(eq("commands.island.near.the-following-islands"));
|
||||
verify(user).sendMessage(eq("commands.island.near.syntax"),
|
||||
eq("[direction]"), eq("commands.island.near.north"),
|
||||
eq(TextVariables.NAME), eq("Island name"));
|
||||
verify(user).sendMessage(eq("commands.island.near.syntax"),
|
||||
eq("[direction]"), eq("commands.island.near.east"),
|
||||
eq(TextVariables.NAME), eq("Island name"));
|
||||
verify(user).sendMessage(eq("commands.island.near.syntax"),
|
||||
eq("[direction]"), eq("commands.island.near.south"),
|
||||
eq(TextVariables.NAME), eq("Island name"));
|
||||
verify(user).sendMessage(eq("commands.island.near.syntax"),
|
||||
eq("[direction]"), eq("commands.island.near.west"),
|
||||
eq(TextVariables.NAME), eq("Island name"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandNearCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringUnowned() {
|
||||
when(island.getName()).thenReturn("");
|
||||
when(island.getOwner()).thenReturn(null);
|
||||
assertTrue(inc.execute(user, "near", Collections.emptyList()));
|
||||
verify(user).sendMessage(eq("commands.island.near.the-following-islands"));
|
||||
verify(user).sendMessage(eq("commands.island.near.syntax"),
|
||||
eq("[direction]"), eq("commands.island.near.north"),
|
||||
eq(TextVariables.NAME), eq("commands.admin.info.unowned"));
|
||||
verify(user).sendMessage(eq("commands.island.near.syntax"),
|
||||
eq("[direction]"), eq("commands.island.near.east"),
|
||||
eq(TextVariables.NAME), eq("commands.admin.info.unowned"));
|
||||
verify(user).sendMessage(eq("commands.island.near.syntax"),
|
||||
eq("[direction]"), eq("commands.island.near.south"),
|
||||
eq(TextVariables.NAME), eq("commands.admin.info.unowned"));
|
||||
verify(user).sendMessage(eq("commands.island.near.syntax"),
|
||||
eq("[direction]"), eq("commands.island.near.west"),
|
||||
eq(TextVariables.NAME), eq("commands.admin.info.unowned"));
|
||||
}
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandNearCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoName() {
|
||||
when(island.getName()).thenReturn("");
|
||||
assertTrue(inc.execute(user, "near", Collections.emptyList()));
|
||||
verify(user).sendMessage(eq("commands.island.near.the-following-islands"));
|
||||
verify(user).sendMessage(eq("commands.island.near.syntax"),
|
||||
eq("[direction]"), eq("commands.island.near.north"),
|
||||
eq(TextVariables.NAME), eq("tastybento"));
|
||||
verify(user).sendMessage(eq("commands.island.near.syntax"),
|
||||
eq("[direction]"), eq("commands.island.near.east"),
|
||||
eq(TextVariables.NAME), eq("tastybento"));
|
||||
verify(user).sendMessage(eq("commands.island.near.syntax"),
|
||||
eq("[direction]"), eq("commands.island.near.south"),
|
||||
eq(TextVariables.NAME), eq("tastybento"));
|
||||
verify(user).sendMessage(eq("commands.island.near.syntax"),
|
||||
eq("[direction]"), eq("commands.island.near.west"),
|
||||
eq(TextVariables.NAME), eq("tastybento"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.IslandNearCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoIslands() {
|
||||
when(im.getIslandAt(any())).thenReturn(Optional.empty());
|
||||
assertTrue(inc.execute(user, "near", Collections.emptyList()));
|
||||
verify(user).sendMessage(eq("commands.island.near.the-following-islands"));
|
||||
verify(user, never()).sendMessage(any(), any(), any(), any(), any());
|
||||
verify(user).sendMessage(eq("commands.island.near.no-neighbors"));
|
||||
}
|
||||
|
||||
}
|
@ -3,9 +3,11 @@ package world.bentobox.bentobox.api.commands.island;
|
||||
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.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ -21,11 +23,12 @@ import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
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.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
@ -37,6 +40,8 @@ import com.google.common.collect.ImmutableSet.Builder;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.addons.AddonDescription;
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.events.IslandBaseEvent;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
@ -45,6 +50,8 @@ 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.bentobox.managers.LocalesManager;
|
||||
import world.bentobox.bentobox.managers.PlaceholdersManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
import world.bentobox.bentobox.managers.island.NewIsland;
|
||||
|
||||
@ -78,6 +85,10 @@ public class IslandResetCommandTest {
|
||||
private PluginManager pim;
|
||||
|
||||
private IslandResetCommand irc;
|
||||
|
||||
@Mock
|
||||
private Player pp;
|
||||
|
||||
private UUID uuid;
|
||||
|
||||
/**
|
||||
@ -99,10 +110,16 @@ public class IslandResetCommandTest {
|
||||
|
||||
// Player
|
||||
Player p = mock(Player.class);
|
||||
when(p.getUniqueId()).thenReturn(uuid);
|
||||
User.getInstance(p);
|
||||
when(p.isOnline()).thenReturn(true);
|
||||
// User
|
||||
User.setPlugin(plugin);
|
||||
|
||||
when(user.isOp()).thenReturn(false);
|
||||
uuid = UUID.randomUUID();
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.isOnline()).thenReturn(true);
|
||||
when(user.getPlayer()).thenReturn(p);
|
||||
when(user.getTranslation(any())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(0, String.class));
|
||||
|
||||
@ -131,7 +148,6 @@ public class IslandResetCommandTest {
|
||||
// Event
|
||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||
|
||||
|
||||
// IWM friendly name
|
||||
when(iwm.getFriendlyName(any())).thenReturn("BSkyBlock");
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
@ -147,8 +163,30 @@ public class IslandResetCommandTest {
|
||||
when(im.getIsland(any(), any(User.class))).thenReturn(island);
|
||||
Builder<UUID> members = new ImmutableSet.Builder<>();
|
||||
members.add(uuid);
|
||||
// Put a team on the island
|
||||
for (int j = 0; j < 11; j++) {
|
||||
UUID temp = UUID.randomUUID();
|
||||
when(pp.getUniqueId()).thenReturn(temp);
|
||||
User.getInstance(pp);
|
||||
members.add(temp);
|
||||
}
|
||||
when(island.getMemberSet()).thenReturn(members.build());
|
||||
|
||||
// Addon
|
||||
GameModeAddon addon1 = mock(GameModeAddon.class);
|
||||
AddonDescription desc = new AddonDescription.Builder("main", "BSkyBlock", "1.0.0").build();
|
||||
when(addon1.getDescription()).thenReturn(desc);
|
||||
when(ic.getAddon()).thenReturn(addon1);
|
||||
|
||||
// Locales
|
||||
LocalesManager lm = mock(LocalesManager.class);
|
||||
when(lm.get(Mockito.any(), Mockito.any())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
|
||||
when(plugin.getLocalesManager()).thenReturn(lm);
|
||||
|
||||
PlaceholdersManager phm = mock(PlaceholdersManager.class);
|
||||
when(phm.replacePlaceholders(any(), any())).thenAnswer(invocation -> invocation.getArgument(1, String.class));
|
||||
// Placeholder manager
|
||||
when(plugin.getPlaceholdersManager()).thenReturn(phm);
|
||||
|
||||
// The command
|
||||
irc = new IslandResetCommand(ic);
|
||||
@ -190,7 +228,6 @@ public class IslandResetCommandTest {
|
||||
/**
|
||||
* Test method for {@link IslandResetCommand#execute(User, String, java.util.List)}
|
||||
*/
|
||||
@Ignore("NPE")
|
||||
@Test
|
||||
public void testNoConfirmationRequired() throws IOException {
|
||||
// Now has island, but is not the owner
|
||||
@ -198,10 +235,6 @@ public class IslandResetCommandTest {
|
||||
// Set so no confirmation required
|
||||
when(s.isResetConfirmation()).thenReturn(false);
|
||||
|
||||
// Old island mock
|
||||
Island oldIsland = mock(Island.class);
|
||||
when(im.getIsland(any(), eq(uuid))).thenReturn(oldIsland);
|
||||
|
||||
// Mock up NewIsland builder
|
||||
NewIsland.Builder builder = mock(NewIsland.Builder.class);
|
||||
when(builder.player(any())).thenReturn(builder);
|
||||
@ -218,9 +251,17 @@ public class IslandResetCommandTest {
|
||||
// TODO Verify that panel was shown
|
||||
// verify(bpm).showPanel(any(), eq(user), eq(irc.getLabel()));
|
||||
// Verify event
|
||||
verify(pim).callEvent(any(IslandBaseEvent.class));
|
||||
verify(pim, times(12)).callEvent(any(IslandBaseEvent.class));
|
||||
// Verify messaging
|
||||
verify(user).sendMessage("commands.island.create.creating-island");
|
||||
verify(user, never()).sendMessage(eq("commands.island.reset.kicked-from-island"), eq("[gamemode]"), anyString());
|
||||
// Only 11 because the leader should not see this
|
||||
verify(pp, times(11)).sendMessage("commands.island.reset.kicked-from-island");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
User.clearUsers();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -362,7 +403,6 @@ public class IslandResetCommandTest {
|
||||
/**
|
||||
* Test method for {@link IslandResetCommand#execute(User, String, java.util.List)}
|
||||
*/
|
||||
@Ignore("NPE")
|
||||
@Test
|
||||
public void testNoConfirmationRequiredCustomSchemHasPermission() throws IOException {
|
||||
// Now has island, but is not the owner
|
||||
@ -399,7 +439,7 @@ public class IslandResetCommandTest {
|
||||
assertTrue(irc.execute(user, irc.getLabel(), Collections.singletonList("custom")));
|
||||
verify(user).sendMessage("commands.island.create.creating-island");
|
||||
// Verify event
|
||||
verify(pim).callEvent(any(IslandBaseEvent.class));
|
||||
verify(pim, times(12)).callEvent(any(IslandBaseEvent.class));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
@ -125,10 +124,8 @@ public class IslandUnbanCommandTest {
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
// Server and Plugin Manager for events
|
||||
Server server = mock(Server.class);
|
||||
when(Bukkit.getServer()).thenReturn(server);
|
||||
PluginManager pim = mock(PluginManager.class);
|
||||
when(server.getPluginManager()).thenReturn(pim);
|
||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,237 @@
|
||||
package world.bentobox.bentobox.api.commands.island.team;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
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.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
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.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.commands.island.team.Invite.Type;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.managers.CommandsManager;
|
||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
|
||||
/**
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
|
||||
public class IslandTeamCommandTest {
|
||||
|
||||
@Mock
|
||||
private CompositeCommand ic;
|
||||
|
||||
|
||||
private IslandTeamCommand tc;
|
||||
|
||||
private UUID uuid;
|
||||
|
||||
private UUID invitee;
|
||||
|
||||
@Mock
|
||||
private IslandsManager im;
|
||||
|
||||
@Mock
|
||||
private User user;
|
||||
|
||||
@Mock
|
||||
private World world;
|
||||
|
||||
@Mock
|
||||
private PluginManager pim;
|
||||
|
||||
@Mock
|
||||
private IslandWorldManager iwm;
|
||||
|
||||
@Mock
|
||||
private @Nullable Island island;
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
// Parent command
|
||||
when(ic.getPermissionPrefix()).thenReturn("bskyblock.");
|
||||
when(ic.getWorld()).thenReturn(world);
|
||||
|
||||
// user
|
||||
uuid = UUID.randomUUID();
|
||||
invitee = UUID.randomUUID();
|
||||
when(user.getUniqueId()).thenReturn(uuid);
|
||||
when(user.getPermissionValue(eq("bskyblock.team.maxsize"), anyInt())).thenReturn(3);
|
||||
|
||||
// island Manager
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
// is owner of island
|
||||
when(im.getOwner(any(), any())).thenReturn(uuid);
|
||||
// No team members
|
||||
when(im.getMembers(any(), any(UUID.class))).thenReturn(Collections.emptySet());
|
||||
// island
|
||||
when(im.getIsland(any(), eq(uuid))).thenReturn(island);
|
||||
|
||||
// Bukkit
|
||||
PowerMockito.mockStatic(Bukkit.class);
|
||||
when(Bukkit.getPluginManager()).thenReturn(pim);
|
||||
|
||||
// IWM
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
when(iwm.getPermissionPrefix(any())).thenReturn("bskyblock.");
|
||||
|
||||
// Command under test
|
||||
tc = new IslandTeamCommand(ic);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#IslandTeamCommand(world.bentobox.bentobox.api.commands.CompositeCommand)}.
|
||||
*/
|
||||
@Test
|
||||
public void testIslandTeamCommand() {
|
||||
assertEquals("team", tc.getLabel());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#setup()}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetup() {
|
||||
assertEquals("bskyblock.island.team", tc.getPermission());
|
||||
assertTrue(tc.isOnlyPlayer());
|
||||
assertEquals("commands.island.team.description", tc.getDescription());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoIsland() {
|
||||
when(im.getOwner(any(), any())).thenReturn(null);
|
||||
assertFalse(tc.execute(user, "team", Collections.emptyList()));
|
||||
verify(user).sendMessage(eq("general.errors.no-island"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringIslandIsNotFull() {
|
||||
assertTrue(tc.execute(user, "team", Collections.emptyList()));
|
||||
verify(user).sendMessage(eq("commands.island.team.invite.you-can-invite"), eq(TextVariables.NUMBER), eq("3"));
|
||||
verify(island).showMembers(eq(user));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringIslandIsFull() {
|
||||
when(user.getPermissionValue(eq("bskyblock.team.maxsize"), anyInt())).thenReturn(0);
|
||||
assertTrue(tc.execute(user, "team", Collections.emptyList()));
|
||||
verify(user).sendMessage(eq("commands.island.team.invite.errors.island-is-full"));
|
||||
verify(island).showMembers(eq(user));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#addInvite(world.bentobox.bentobox.api.commands.island.team.Invite.Type, java.util.UUID, java.util.UUID)}.
|
||||
*/
|
||||
@Test
|
||||
public void testAddInvite() {
|
||||
tc.addInvite(Invite.Type.TEAM, uuid, invitee);
|
||||
assertTrue(tc.isInvited(invitee));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#isInvited(java.util.UUID)}.
|
||||
*/
|
||||
@Test
|
||||
public void testIsInvited() {
|
||||
assertFalse(tc.isInvited(invitee));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#getInviter(java.util.UUID)}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetInviter() {
|
||||
tc.addInvite(Invite.Type.TEAM, uuid, invitee);
|
||||
assertEquals(uuid, tc.getInviter(invitee));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#getInviter(java.util.UUID)}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetInviterNoInvite() {
|
||||
assertNull(tc.getInviter(invitee));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#getInvite(java.util.UUID)}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetInvite() {
|
||||
assertNull(tc.getInvite(invitee));
|
||||
tc.addInvite(Invite.Type.TEAM, uuid, invitee);
|
||||
@Nullable
|
||||
Invite invite = tc.getInvite(invitee);
|
||||
assertEquals(invite.getInvitee(), invitee);
|
||||
assertEquals(invite.getType(), Type.TEAM);
|
||||
assertEquals(invite.getInviter(), uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.island.team.IslandTeamCommand#removeInvite(java.util.UUID)}.
|
||||
*/
|
||||
@Test
|
||||
public void testRemoveInvite() {
|
||||
assertNull(tc.getInvite(invitee));
|
||||
tc.addInvite(Invite.Type.TEAM, uuid, invitee);
|
||||
tc.removeInvite(invitee);
|
||||
assertNull(tc.getInvite(invitee));
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user