Merge branch 'develop' into 167-automated-island-ownership-transfer

This commit is contained in:
Florian CUNY 2019-01-03 16:59:13 +01:00
commit 160749c065
28 changed files with 307 additions and 653 deletions

View File

@ -18,7 +18,7 @@ import world.bentobox.bentobox.listeners.BlockEndDragon;
import world.bentobox.bentobox.listeners.DeathListener;
import world.bentobox.bentobox.listeners.JoinLeaveListener;
import world.bentobox.bentobox.listeners.NetherPortals;
import world.bentobox.bentobox.listeners.ObsidianToLava;
import world.bentobox.bentobox.listeners.ObsidianScoopingListener;
import world.bentobox.bentobox.listeners.PanelListenerManager;
import world.bentobox.bentobox.managers.AddonsManager;
import world.bentobox.bentobox.managers.CommandsManager;
@ -193,7 +193,7 @@ public class BentoBox extends JavaPlugin {
// Nether portals
manager.registerEvents(new NetherPortals(this), this);
// Obsidian to lava helper
manager.registerEvents(new ObsidianToLava(this), this);
manager.registerEvents(new ObsidianScoopingListener(this), this);
// End dragon blocking
manager.registerEvents(new BlockEndDragon(this), this);
// Banned visitor commands

View File

@ -78,15 +78,8 @@ public class Settings implements DataObject {
@ConfigEntry(path = "general.fakeplayers", experimental = true)
private Set<String> fakePlayers = new HashSet<>();
@ConfigComment("Allow obsidian to be scooped up with an empty bucket back into lava")
@ConfigComment("This only works if there is a single block of obsidian (no obsidian within 10 blocks)")
@ConfigComment("Recommendation is to keep this true so that newbies don't bother you or reset their")
@ConfigComment("island unnecessarily.")
@ConfigEntry(path = "general.allow-obsidian-scooping")
private boolean allowObsidianScooping = true;
@ConfigComment("Rank required to use a command. e.g., use the invite command. Default is owner rank is required.")
@ConfigEntry(path = "general.rank-command")
@ConfigEntry(path = "general.rank-command", experimental = true)
private Map<String, Integer> rankCommand = new HashMap<>();
@ConfigEntry(path = "panel.close-on-click-outside")
@ -145,10 +138,6 @@ public class Settings implements DataObject {
@ConfigEntry(path = "island.paste-speed")
private int pasteSpeed = 1000;
// Ranks
@ConfigEntry(path = "island.custom-ranks", experimental = true)
private Map<String, Integer> customRanks = new HashMap<>();
// Automated ownership transfer
@ConfigComment("Toggles the automated ownership transfer.")
@ConfigComment("It automatically transfers the ownership of an island to one of its members in case the current owner is inactive.")
@ -263,14 +252,6 @@ public class Settings implements DataObject {
this.fakePlayers = fakePlayers;
}
public boolean isAllowObsidianScooping() {
return allowObsidianScooping;
}
public void setAllowObsidianScooping(boolean allowObsidianScooping) {
this.allowObsidianScooping = allowObsidianScooping;
}
public Map<String, Integer> getRankCommand() {
return rankCommand;
}
@ -397,14 +378,6 @@ public class Settings implements DataObject {
return this.pasteSpeed;
}
public Map<String, Integer> getCustomRanks() {
return customRanks;
}
public void setCustomRanks(Map<String, Integer> customRanks) {
this.customRanks = customRanks;
}
public boolean isEnableAutoOwnershipTransfer() {
return enableAutoOwnershipTransfer;
}

View File

@ -1,64 +0,0 @@
package world.bentobox.bentobox.api.commands.admin;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
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.util.Util;
/**
* @deprecated Renamed and moved to {@link world.bentobox.bentobox.api.commands.admin.resets.AdminResetsResetCommand}.
*/
@Deprecated
public class AdminClearresetsCommand extends CompositeCommand {
public AdminClearresetsCommand(CompositeCommand parent) {
super(parent, "clearresets");
}
@Override
public void setup() {
setPermission("admin.clearreset");
setParametersHelp("commands.admin.clearresets.parameters");
setDescription("commands.admin.clearresets.description");
}
@Override
public boolean execute(User user, String label, List<String> args) {
// If args are not right, show help
if (args.size() != 1) {
showHelp(this, user);
return false;
}
// Get target
UUID targetUUID = getPlayers().getUUID(args.get(0));
if (targetUUID == null) {
user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0));
return false;
}
if (!getIslands().hasIsland(getWorld(), targetUUID)) {
user.sendMessage("general.errors.player-has-no-island");
return false;
}
// Clear resets
user.sendMessage("commands.admin.clearresets.cleared");
getPlayers().setResets(getWorld(), targetUUID, 0);
user.sendMessage("general.success");
return true;
}
@Override
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
if (args.isEmpty()) {
// Don't show every player on the server. Require at least the first letter
return Optional.empty();
}
List<String> options = new ArrayList<>(Util.getOnlinePlayerList(user));
return Optional.of(Util.tabLimit(options, lastArg));
}
}

View File

@ -1,45 +0,0 @@
package world.bentobox.bentobox.api.commands.admin;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
import world.bentobox.bentobox.api.user.User;
/**
* @deprecated Unlike {@link AdminClearresetsCommand}, this command will be removed.
* We will be working on an alternative which will use {@link world.bentobox.bentobox.api.commands.admin.resets.AdminResetsResetCommand} instead.
*/
@Deprecated
public class AdminClearresetsallCommand extends ConfirmableCommand {
public AdminClearresetsallCommand(CompositeCommand parent) {
super(parent, "clearresetsall");
}
@Override
public void setup() {
setPermission("admin.clearresetsall");
setDescription("commands.admin.clearresetsall.description");
}
@Override
public boolean execute(User user, String label, List<String> args) {
if (!args.isEmpty()) {
showHelp(this, user);
return false;
}
this.askConfirmation(user, () -> {
// Set the reset epoch to now
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");
});
return true;
}
}

View File

@ -0,0 +1,33 @@
package world.bentobox.bentobox.api.commands.admin;
import java.util.List;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
/**
* Generic reload command for addons to use that will just call the onReload() method
* after checking permissions
* @author tastybento
*
*/
public class AdminReloadCommand extends CompositeCommand {
public AdminReloadCommand(CompositeCommand adminCommand) {
super(adminCommand, "reload");
}
@Override
public void setup() {
// Permission
setPermission("admin.reload");
setDescription("commands.admin.reload.description");
}
@Override
public boolean execute(User user, String label, List<String> args) {
getAddon().onReload();
return true;
}
}

View File

@ -80,24 +80,24 @@ public class IslandBanCommand extends CompositeCommand {
return ban(user, target);
}
private boolean ban(User user, User targetUser) {
Island island = getIslands().getIsland(getWorld(), user.getUniqueId());
private boolean ban(User issuer, User target) {
Island island = getIslands().getIsland(getWorld(), issuer.getUniqueId());
// Check if player can ban any more players
int banLimit = user.getPermissionValue(getPermissionPrefix() + "ban.maxlimit", getIWM().getBanLimit(getWorld()));
int banLimit = issuer.getPermissionValue(getPermissionPrefix() + "ban.maxlimit", getIWM().getBanLimit(getWorld()));
if (banLimit <= -1 || island.getBanned().size() < banLimit) {
if (island.addToBanList(targetUser.getUniqueId())) {
user.sendMessage("general.success");
targetUser.sendMessage("commands.island.ban.owner-banned-you", TextVariables.NAME, user.getName());
if (island.ban(issuer.getUniqueId(), target.getUniqueId())) {
issuer.sendMessage("general.success");
target.sendMessage("commands.island.ban.owner-banned-you", TextVariables.NAME, issuer.getName());
// If the player is online, has an island and on the banned island, move them home immediately
if (targetUser.isOnline() && getIslands().hasIsland(getWorld(), targetUser.getUniqueId()) && island.onIsland(targetUser.getLocation())) {
getIslands().homeTeleport(getWorld(), targetUser.getPlayer());
island.getWorld().playSound(targetUser.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F);
if (target.isOnline() && getIslands().hasIsland(getWorld(), target.getUniqueId()) && island.onIsland(target.getLocation())) {
getIslands().homeTeleport(getWorld(), target.getPlayer());
island.getWorld().playSound(target.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1F, 1F);
}
return true;
}
} else {
user.sendMessage("commands.island.ban.cannot-ban-more-players");
issuer.sendMessage("commands.island.ban.cannot-ban-more-players");
}
// Banning was blocked, maybe due to an event cancellation. Fail silently.
return false;

View File

@ -64,14 +64,14 @@ public class IslandUnbanCommand extends CompositeCommand {
return unban(user, targetUser);
}
private boolean unban(User user, User targetUser) {
if (getIslands().getIsland(getWorld(), user.getUniqueId()).removeFromBanList(targetUser.getUniqueId())) {
user.sendMessage("general.success");
targetUser.sendMessage("commands.island.unban.you-are-unbanned", TextVariables.NAME, user.getName());
private boolean unban(User issuer, User target) {
if (getIslands().getIsland(getWorld(), issuer.getUniqueId()).unban(issuer.getUniqueId(), target.getUniqueId())) {
issuer.sendMessage("general.success");
target.sendMessage("commands.island.unban.you-are-unbanned", TextVariables.NAME, issuer.getName());
// Set cooldown
if (getSettings().getBanCooldown() > 0 && getParent() != null) {
getParent().getSubCommand("ban").ifPresent(subCommand ->
subCommand.setCooldown(user.getUniqueId(), targetUser.getUniqueId(), getSettings().getBanCooldown() * 60));
subCommand.setCooldown(issuer.getUniqueId(), target.getUniqueId(), getSettings().getBanCooldown() * 60));
}
return true;
}

View File

@ -146,6 +146,15 @@ public interface WorldSettings {
*/
String getWorldName();
/**
* Allow obsidian to be scooped up with an empty bucket back into lava.
* This only works if there is a single block of obsidian (no obsidian within 10 blocks).
* Recommendation is to keep this true so that newbies don't bother you or reset their
* island unnecessarily.
* @return whether obsidian scooping is allowed or not.
*/
boolean isAllowObsidianScooping();
/**
* @return the dragonSpawn
*/

View File

@ -1,135 +0,0 @@
package world.bentobox.bentobox.api.flags;
import org.bukkit.Material;
import org.bukkit.event.Listener;
import world.bentobox.bentobox.api.flags.Flag.Type;
import world.bentobox.bentobox.api.flags.clicklisteners.CycleClick;
import world.bentobox.bentobox.api.flags.clicklisteners.IslandToggleClick;
import world.bentobox.bentobox.api.flags.clicklisteners.WorldToggleClick;
import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.managers.RanksManager;
/**
* @deprecated Replaced by {@link Flag.Builder}.
*/
@Deprecated
public class FlagBuilder {
private String id;
private Material icon;
private Listener listener;
private boolean setting;
private Type type = Type.PROTECTION;
private int defaultRank = RanksManager.MEMBER_RANK;
private PanelItem.ClickHandler onClick;
private boolean subPanel = false;
public FlagBuilder id(String string) {
id = string;
return this;
}
/**
* The material that will become the icon for this flag
* @param icon - material
*/
public FlagBuilder icon(Material icon) {
this.icon = icon;
return this;
}
/**
* @param listener - the Bukkit listener that will be registered to handle this flag
*/
public FlagBuilder listener(Listener listener) {
this.listener = listener;
return this;
}
public Flag build() {
// If no onClick has been set, then apply default ones
if (onClick == null) {
switch (type){
case PROTECTION:
onClick = new CycleClick(id);
break;
case SETTING:
onClick = new IslandToggleClick(id);
break;
case WORLD_SETTING:
onClick = new WorldToggleClick(id);
break;
default:
onClick = new CycleClick(id);
break;
}
}
Flag f = new Flag(id, icon, listener, type, defaultRank, onClick, subPanel);
f.setDefaultSetting(setting);
return f;
}
/**
* Sets the default setting for this flag in the world
* @param setting - true or false
* @return FlagBuilder
*/
public FlagBuilder allowedByDefault(boolean setting) {
this.setting = setting;
return this;
}
/**
* Set the type of this flag
* @param type {@link Type}
* @return FlagBuilder
*/
public FlagBuilder type(Type type) {
this.type = type;
return this;
}
/**
* Set the id of this flag to the name of this enum value
* @param flag - flag
* @return FlagBuilder
*/
public FlagBuilder id(Enum<?> flag) {
id = flag.name();
return this;
}
/**
* Set a default rank for this flag. If not set, the value of RanksManager.MEMBER_RANK will be used
* @param rank - rank value
* @return FlagBuilder
*/
public FlagBuilder defaultRank(int rank) {
this.defaultRank = rank;
return this;
}
/**
* Adds a listener for clicks on this flag when it is a panel item. Default is
* {@link world.bentobox.bentobox.api.flags.clicklisteners.CycleClick}
* @param onClickListener - the listener for clicks. Must use the ClickOn interface
* @return FlagBuilder
*/
public FlagBuilder onClick(PanelItem.ClickHandler onClickListener) {
this.onClick = onClickListener;
return this;
}
/**
* Marks this flag as "using a sub-panel"
* @param subPanel - whether the flag will use a sub-panel or not
* @return FlagBuilder
*/
public FlagBuilder subPanel(boolean subPanel) {
this.subPanel = subPanel;
return this;
}
}

View File

@ -0,0 +1,74 @@
package world.bentobox.bentobox.api.logs;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
/**
* Represents an event that occurred and that is logged.
* <br/>
* An {@link world.bentobox.bentobox.database.objects.adapters.AdapterInterface} is provided to be able to save/retrieve
* a list of instances of this object to/from the database: {@link world.bentobox.bentobox.database.objects.adapters.LogEntryListAdapter}.
*
* @author Poslovitch
*/
public class LogEntry {
private final long timestamp;
private final String type;
private final Map<String, Object> data;
private LogEntry(Builder builder) {
this.timestamp = builder.timestamp;
this.type = builder.type;
this.data = builder.data;
}
public long getTimestamp() {
return timestamp;
}
public String getType() {
return type;
}
public Map<String, Object> getData() {
return data;
}
public static class Builder {
private long timestamp;
private String type;
private Map<String, Object> data;
public Builder(String type) {
this.timestamp = System.currentTimeMillis();
this.type = type.toUpperCase(Locale.ENGLISH);
this.data = new LinkedHashMap<>();
}
public Builder timestamp(long timestamp) {
this.timestamp = timestamp;
return this;
}
public Builder data(Map<String, Object> data) {
this.data = data;
return this;
}
/**
* Puts this key and this value in the currently existing data map.
* @param key key to set
* @param value value to set
* @return the Builder instance
*/
public Builder data(String key, Object value) {
this.data.put(key, value);
return this;
}
public LogEntry build() {
return new LogEntry(this);
}
}
}

View File

@ -274,13 +274,8 @@ public class User {
*/
public void sendMessage(String reference, String... variables) {
String message = getTranslation(reference, variables);
if (!ChatColor.stripColor(message).trim().isEmpty()) {
if (sender != null) {
sender.sendMessage(message);
} else {
// TODO: Offline message
// Save this message so the player can see it later
}
if (!ChatColor.stripColor(message).trim().isEmpty() && sender != null) {
sender.sendMessage(message);
}
}
@ -291,9 +286,6 @@ public class User {
public void sendRawMessage(String message) {
if (sender != null) {
sender.sendMessage(message);
} else {
// TODO: Offline message
// Save this message so the player can see it later
}
}

View File

@ -4,6 +4,8 @@ import java.util.Date;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
@ -25,6 +27,8 @@ import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.adapters.Adapter;
import world.bentobox.bentobox.database.objects.adapters.FlagSerializer;
import world.bentobox.bentobox.database.objects.adapters.LogEntryListAdapter;
import world.bentobox.bentobox.api.logs.LogEntry;
import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.Pair;
@ -88,6 +92,11 @@ public class Island implements DataObject {
@Expose
private Map<Flag, Integer> flags = new HashMap<>();
//// Island History ////
@Adapter(LogEntryListAdapter.class)
@Expose
private List<LogEntry> history = new LinkedList<>();
@Expose
private int levelHandicap;
@Expose
@ -117,14 +126,17 @@ public class Island implements DataObject {
}
/**
* Adds target to a list of banned players for this island. May be blocked by the event being cancelled.
* Bans the target player from this Island.
* If the player is a member, coop or trustee, they will be removed from those lists.
* @param targetUUID - the target's UUID
* @return true if successfully added
* @param issuer UUID of the issuer, may be null.
* Whenever possible, one should be provided.
* @param target UUID of the target, must be provided.
* @return {@code true} if the target is successfully banned, {@code false} otherwise.
*/
public boolean addToBanList(UUID targetUUID) {
if (targetUUID != null) {
members.put(targetUUID, RanksManager.BANNED_RANK);
public boolean ban(UUID issuer, UUID target) {
if (target != null) {
members.put(target, RanksManager.BANNED_RANK);
log(new LogEntry.Builder("BAN").data("player", target).data("issuer", issuer).build());
return true;
}
return false;
@ -143,6 +155,21 @@ public class Island implements DataObject {
return result;
}
/**
* Unbans the target player from this Island.
* @param issuer UUID of the issuer, may be null.
* Whenever possible, one should be provided.
* @param target UUID of the target, must be provided.
* @return {@code true} if the target is successfully unbanned, {@code false} otherwise.
*/
public boolean unban(UUID issuer, UUID target) {
if (members.remove(target) != null) {
log(new LogEntry.Builder("UNBAN").data("player", target).data("issuer", issuer).build());
return true;
}
return false;
}
/**
* @return the center Location
*/
@ -396,15 +423,6 @@ public class Island implements DataObject {
return Util.sameWorld(world, target.getWorld()) && target.getBlockX() >= getMinProtectedX() && target.getBlockX() < (getMinProtectedX() + protectionRange * 2) && target.getBlockZ() >= getMinProtectedZ() && target.getBlockZ() < (getMinProtectedZ() + protectionRange * 2);
}
/**
* Removes target from the banned list. May be cancelled by unban event.
* @param targetUUID - the target's UUID
* @return true if successful, otherwise false.
*/
public boolean removeFromBanList(UUID targetUUID) {
return (members.remove(targetUUID) != null);
}
/**
* Removes a player from the team member map. Generally, you should
* use {@link world.bentobox.bentobox.managers.IslandsManager#removePlayer(World, UUID)}
@ -695,9 +713,33 @@ public class Island implements DataObject {
/**
* Removes all of a specified rank from the member list
* @param coopRank - rank value
* @param rank rank value
*/
public void removeRank(Integer coopRank) {
members.values().removeIf(coopRank::equals);
public void removeRank(Integer rank) {
members.values().removeIf(rank::equals);
}
/**
* Gets the history of the island.
* @return the list of {@link LogEntry} for this island.
*/
public List<LogEntry> getHistory() {
return history;
}
/**
* Adds a {@link LogEntry} to the history of this island.
* @param logEntry the LogEntry to add.
*/
public void log(LogEntry logEntry) {
history.add(logEntry);
}
/**
* Sets the history of the island.
* @param history the list of {@link LogEntry} to se for this island.
*/
public void setHistory(List<LogEntry> history) {
this.history = history;
}
}

View File

@ -0,0 +1,73 @@
package world.bentobox.bentobox.database.objects.adapters;
import world.bentobox.bentobox.api.logs.LogEntry;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* @author Poslovitch
*/
/* The serialization might look a bit weird here, as I'm using JSON's array of object.
This means that, once serialized, the data will look like this (on YAML):
history:
- timestamp: 0
type: "test"
data:
player: "uuid"
action: "ISLAND_LEVEL_UPDATED"
value: 45
- timestamp: 4181
type: "lol"
data:
help: "yep"
*/
public class LogEntryListAdapter implements AdapterInterface<List<LogEntry>, List<Map<String, Object>>> {
private static final String TIMESTAMP = "timestamp";
private static final String TYPE = "type";
private static final String DATA = "data";
@SuppressWarnings("unchecked")
@Override
public List<LogEntry> deserialize(Object object) {
List<LogEntry> result = new LinkedList<>();
if (object == null) {
return result;
}
List<Map<String, Object>> serialized = (List<Map<String, Object>>) object;
for (Map<String, Object> entry : serialized) {
long timestamp = (long) entry.get(TIMESTAMP);
String type = (String) entry.get(TYPE);
Map<String, Object> data = (Map<String, Object>) entry.get(DATA);
result.add(new LogEntry.Builder(type).timestamp(timestamp).data(data).build());
}
return result;
}
@SuppressWarnings("unchecked")
@Override
public List<Map<String, Object>> serialize(Object object) {
List<Map<String, Object>> result = new LinkedList<>();
if (object == null) {
return result;
}
List<LogEntry> history = (List<LogEntry>) object;
history.forEach(logEntry -> {
Map<String, Object> value = new LinkedHashMap<>();
value.put(TIMESTAMP, logEntry.getTimestamp());
value.put(TYPE, logEntry.getType());
value.put(DATA, logEntry.getData());
result.add(value);
});
return result;
}
}

View File

@ -20,29 +20,28 @@ import world.bentobox.bentobox.api.user.User;
/**
* Enables changing of obsidian back into lava
* @author tastybento
*
*/
public class ObsidianToLava implements Listener {
public class ObsidianScoopingListener implements Listener {
private BentoBox plugin;
/**
* @param plugin - plugin
* @param plugin plugin
*/
public ObsidianToLava(BentoBox plugin) {
public ObsidianScoopingListener(BentoBox plugin) {
this.plugin = plugin;
}
/**
* Enables changing of obsidian back into lava
*
* @param e - event
* @param e event
* @return false if obsidian not scooped, true if scooped
*/
@EventHandler(priority = EventPriority.NORMAL)
public boolean onPlayerInteract(final PlayerInteractEvent e) {
if (!plugin.getSettings().isAllowObsidianScooping()
|| !plugin.getIWM().inWorld(e.getPlayer().getLocation())
if (!plugin.getIWM().inWorld(e.getPlayer().getLocation())
|| !plugin.getIWM().isAllowObsidianScooping(e.getPlayer().getWorld())
|| !e.getPlayer().getGameMode().equals(GameMode.SURVIVAL)
|| !e.getAction().equals(Action.RIGHT_CLICK_BLOCK)
|| !(e.getItem() != null && e.getItem().getType().equals(Material.BUCKET))

View File

@ -2,6 +2,7 @@ package world.bentobox.bentobox.managers;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@ -21,7 +22,13 @@ public class CommandsManager {
Field commandMapField = Bukkit.getServer().getClass().getDeclaredField("commandMap");
commandMapField.setAccessible(true);
CommandMap commandMap = (CommandMap) commandMapField.get(Bukkit.getServer());
commandMap.register(command.getLabel(), command);
String commandPrefix = "bentobox";
if (command.getAddon() != null) {
commandPrefix = command.getAddon().getDescription().getName().toLowerCase(Locale.ENGLISH);
}
commandMap.register(commandPrefix, command);
}
catch(Exception exception){
Bukkit.getLogger().severe("Bukkit server commandMap method is not there! This means no commands can be registered!");

View File

@ -251,6 +251,13 @@ public class IslandWorldManager {
return gameModes.get(Util.getWorld(world)).getWorldSettings().getWorldName();
}
/**
* @return whether obsidian scooping is allowed or not.
*/
public boolean isAllowObsidianScooping(World world) {
return gameModes.get(Util.getWorld(world)).getWorldSettings().isAllowObsidianScooping();
}
/**
* @return the endGenerate
*/

View File

@ -745,7 +745,6 @@ public class IslandsManager {
islandCache.addPlayer(playerUUID, teamIsland);
// Save the database
save(false);
}
public void setLast(Location last) {

View File

@ -50,18 +50,6 @@ public class RanksManager {
ranksPut(COOP_RANK_REF, COOP_RANK);
ranksPut(VISITOR_RANK_REF, VISITOR_RANK);
ranksPut(BANNED_RANK_REF, BANNED_RANK);
loadCustomRanks();
}
/**
* Loads the custom ranks from the settings
*/
public void loadCustomRanks() {
for (Entry<String, Integer> en : plugin.getSettings().getCustomRanks().entrySet()) {
if (!addRank(en.getKey(),en.getValue())) {
plugin.logError("Error loading custom rank: " + en.getKey() + " " + en.getValue() + " skipping...");
}
}
}
/**

View File

@ -140,7 +140,7 @@ commands:
description: "set the range of player's island"
range-updated: "Island range updated to [number]"
reload:
description: "reload the plugin"
description: "reload"
tp:
parameters: "<player>"
description: "teleport to a player's island"

View File

@ -135,7 +135,7 @@ commands:
description: "プレイヤーの島の範囲を設定する"
range-updated: "&2島の範囲は、[number]に更新"
reload:
description: "プラグインをリロードする"
description: "リロードする"
tp:
parameters: "<プレーヤー>"
description: "プレイヤーの島にテレポート"

View File

@ -108,7 +108,7 @@ commands:
description: "ustaw zasięg wyspy gracza"
range-updated: "Zaktualizowano zasięg wyspy do [number]"
reload:
description: "ponownie załaduj plugin"
description: "ponownie załaduj"
tp:
parameters: "<gracz>"
description: "teleportuj się na wyspę gracza"

View File

@ -402,7 +402,7 @@ public class TestBentoBox {
assertFalse(members.contains(member3));
// Ban member
island.addToBanList(member1);
island.ban(null, member1);
members = island.getMemberSet();
assertTrue(members.contains(playerUUID));
assertFalse(members.contains(member1));
@ -413,7 +413,7 @@ public class TestBentoBox {
assertTrue(banned.contains(member1));
// Unban
island.removeFromBanList(member1);
island.unban(null, member1);
assertFalse(island.getBanned().contains(member1));
// Protection
@ -445,7 +445,7 @@ public class TestBentoBox {
// Check if the members have capability
User mem1 = User.getInstance(member1); // Visitor
User mem2 = User.getInstance(member2); // Member
island.addToBanList(member3);
island.ban(null, member3);
User mem3 = User.getInstance(member3); // Banned
// Member 1 is a visitor

View File

@ -1,165 +0,0 @@
/**
*
*/
package world.bentobox.bentobox.api.commands.admin;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
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.user.User;
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.PlayersManager;
/**
* @author ben
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
public class AdminClearresetsCommandTest {
private CompositeCommand ac;
private User user;
private IslandsManager im;
private PlayersManager pm;
private UUID notUUID;
/**
* @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);
// Settings
Settings s = mock(Settings.class);
when(plugin.getSettings()).thenReturn(s);
// Player
Player p = mock(Player.class);
// Sometimes use Mockito.withSettings().verboseLogging()
user = mock(User.class);
when(user.isOp()).thenReturn(false);
UUID uuid = UUID.randomUUID();
notUUID = UUID.randomUUID();
while(notUUID.equals(uuid)) {
notUUID = UUID.randomUUID();
}
when(user.getUniqueId()).thenReturn(uuid);
when(user.getPlayer()).thenReturn(p);
when(user.getName()).thenReturn("tastybento");
User.setPlugin(plugin);
// Parent command has no aliases
ac = mock(CompositeCommand.class);
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
// Island World Manager
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);
// 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(plugin.getIslands()).thenReturn(im);
// Has team
pm = mock(PlayersManager.class);
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
when(plugin.getPlayers()).thenReturn(pm);
// Server & Scheduler
BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch);
// Locales
LocalesManager lm = mock(LocalesManager.class);
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
when(plugin.getLocalesManager()).thenReturn(lm);
}
/**
* Test method for .
*/
@Test
public void testExecuteNoTarget() {
AdminClearresetsCommand itl = new AdminClearresetsCommand(ac);
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>()));
// Show help
Mockito.verify(user).sendMessage(Mockito.eq("commands.help.header"), Mockito.eq("[label]"), Mockito.any());
}
/**
* Test method for .
*/
@Test
public void testExecuteUnknownPlayer() {
AdminClearresetsCommand itl = new AdminClearresetsCommand(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]);
}
/**
* Test method for .
*/
@Test
public void testExecutePlayerNoIsland() {
AdminClearresetsCommand itl = new AdminClearresetsCommand(ac);
String[] name = {"tastybento"};
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
when(im.hasIsland(Mockito.any(), Mockito.any(UUID.class))).thenReturn(false);
assertFalse(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
Mockito.verify(user).sendMessage(Mockito.eq("general.errors.player-has-no-island"));
}
@Test
public void testExecuteSuccess() {
String[] name = {"tastybento"};
when(pm.getUUID(Mockito.any())).thenReturn(notUUID);
AdminClearresetsCommand itl = new AdminClearresetsCommand(ac);
assertTrue(itl.execute(user, itl.getLabel(), Arrays.asList(name)));
// Add other verifications
Mockito.verify(user).sendMessage("commands.admin.clearresets.cleared");
Mockito.verify(user).sendMessage(Mockito.eq("general.success"));
}
}

View File

@ -1,120 +0,0 @@
package world.bentobox.bentobox.api.commands.admin;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
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.user.User;
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.PlayersManager;
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, User.class })
public class AdminClearresetsallCommandTest {
private CompositeCommand ac;
private 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);
// Settings
Settings s = mock(Settings.class);
when(s.getResetCooldown()).thenReturn(0);
when(plugin.getSettings()).thenReturn(s);
// Player
Player p = mock(Player.class);
// Sometimes use Mockito.withSettings().verboseLogging()
user = mock(User.class);
when(user.isOp()).thenReturn(false);
UUID uuid = UUID.randomUUID();
UUID notUUID = UUID.randomUUID();
while(notUUID.equals(uuid)) {
notUUID = UUID.randomUUID();
}
when(user.getUniqueId()).thenReturn(uuid);
when(user.getPlayer()).thenReturn(p);
when(user.getName()).thenReturn("tastybento");
User.setPlugin(plugin);
// Parent command has no aliases
ac = mock(CompositeCommand.class);
when(ac.getSubCommandAliases()).thenReturn(new HashMap<>());
// Island World Manager
IslandWorldManager iwm = mock(IslandWorldManager.class);
when(plugin.getIWM()).thenReturn(iwm);
// Player has island to begin with
IslandsManager 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(plugin.getIslands()).thenReturn(im);
// Has team
PlayersManager pm = mock(PlayersManager.class);
when(im.inTeam(Mockito.any(), Mockito.eq(uuid))).thenReturn(true);
when(plugin.getPlayers()).thenReturn(pm);
// Server & Scheduler
BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch);
// Locales
LocalesManager lm = mock(LocalesManager.class);
when(lm.get(Mockito.any(), Mockito.any())).thenReturn("mock translation");
when(plugin.getLocalesManager()).thenReturn(lm);
}
/**
* Test method for .
*/
@SuppressWarnings("deprecation")
@Test
public void testExecuteCheckConfirm() {
AdminClearresetsallCommand itl = new AdminClearresetsallCommand(ac);
assertFalse(itl.execute(user, itl.getLabel(), new ArrayList<>(Arrays.asList("tastybento", "bobby"))));
assertTrue(itl.execute(user, itl.getLabel(), new ArrayList<>()));
Mockito.verify(user).sendMessage(Mockito.eq("commands.confirmation.confirm"), Mockito.eq("[seconds]"), Mockito.any());
}
}

View File

@ -237,7 +237,7 @@ public class IslandBanCommandTest {
when(user.getPermissionValue(Mockito.anyString(), Mockito.anyInt())).thenReturn(-1);
// Allow adding to ban list
when(island.addToBanList(Mockito.any())).thenReturn(true);
when(island.ban(Mockito.any(), Mockito.any())).thenReturn(true);
assertTrue(ibc.execute(user, ibc.getLabel(), Collections.singletonList("bill")));
Mockito.verify(user).sendMessage("general.success");
@ -259,7 +259,7 @@ public class IslandBanCommandTest {
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(targetUser);
when(user.getPermissionValue(Mockito.anyString(), Mockito.anyInt())).thenReturn(-1);
// Allow adding to ban list
when(island.addToBanList(Mockito.any())).thenReturn(true);
when(island.ban(Mockito.any(), Mockito.any())).thenReturn(true);
assertTrue(ibc.execute(user, ibc.getLabel(), Collections.singletonList("bill")));
Mockito.verify(user).sendMessage("general.success");
@ -280,7 +280,7 @@ public class IslandBanCommandTest {
when(targetUser.isOnline()).thenReturn(true);
when(User.getInstance(Mockito.any(UUID.class))).thenReturn(targetUser);
// Disallow adding to ban list - even cancelled
when(island.addToBanList(Mockito.any())).thenReturn(false);
when(island.ban(Mockito.any(), Mockito.any())).thenReturn(false);
assertFalse(ibc.execute(user, ibc.getLabel(), Collections.singletonList("bill")));
Mockito.verify(user, Mockito.never()).sendMessage("general.success");

View File

@ -208,7 +208,7 @@ public class IslandUnbanCommandTest {
when(island.isBanned(Mockito.eq(targetUUID))).thenReturn(true);
// Allow removing from ban list
when(island.removeFromBanList(Mockito.any())).thenReturn(true);
when(island.unban(Mockito.any(), Mockito.any())).thenReturn(true);
assertTrue(iubc.execute(user, iubc.getLabel(), Collections.singletonList("bill")));
Mockito.verify(user).sendMessage("general.success");
@ -232,7 +232,7 @@ public class IslandUnbanCommandTest {
when(island.isBanned(Mockito.eq(targetUUID))).thenReturn(true);
// Allow removing from ban list
when(island.removeFromBanList(Mockito.any())).thenReturn(false);
when(island.unban(Mockito.any(), Mockito.any())).thenReturn(false);
assertFalse(iubc.execute(user, iubc.getLabel(), Collections.singletonList("bill")));
Mockito.verify(user, Mockito.never()).sendMessage("general.success");

View File

@ -40,14 +40,14 @@ import world.bentobox.bentobox.managers.LocalesManager;
@RunWith(PowerMockRunner.class)
@PrepareForTest({PlayerEvent.class, PlayerInteractEvent.class})
public class ObsidianToLavaTest {
public class ObsidianScoopingListenerTest {
private static World world;
@Test
public void testObsidianToLava() {
BentoBox plugin = mock(BentoBox.class);
assertNotNull(new ObsidianToLava(plugin));
assertNotNull(new ObsidianScoopingListener(plugin));
}
@Test
@ -75,14 +75,7 @@ public class ObsidianToLavaTest {
BentoBox plugin = mock(BentoBox.class);
// Create new object
ObsidianToLava listener = new ObsidianToLava(plugin);
// Mock settings
Settings settings = mock(Settings.class);
when(plugin.getSettings()).thenReturn(settings);
when(settings.isAllowObsidianScooping()).thenReturn(false);
// Allow scooping
when(settings.isAllowObsidianScooping()).thenReturn(true);
ObsidianScoopingListener listener = new ObsidianScoopingListener(plugin);
// Mock player
Player who = mock(Player.class);
@ -103,6 +96,7 @@ public class ObsidianToLavaTest {
when(iwm.getIslandWorld(Mockito.any())).thenReturn(world);
when(iwm.getNetherWorld(Mockito.any())).thenReturn(world);
when(iwm.getEndWorld(Mockito.any())).thenReturn(world);
when(iwm.isAllowObsidianScooping(Mockito.any())).thenReturn(true); // Allow scooping
// Mock up IslandsManager
IslandsManager im = mock(IslandsManager.class);
@ -205,7 +199,7 @@ public class ObsidianToLavaTest {
Block airBlock = mock(Block.class);
when(airBlock.getType()).thenReturn(Material.AIR);
ObsidianToLava listener = new ObsidianToLava(plugin);
ObsidianScoopingListener listener = new ObsidianScoopingListener(plugin);
PlayerInteractEvent event = new PlayerInteractEvent(who, action, item, clickedBlock, BlockFace.EAST);
if (!action.equals(Action.RIGHT_CLICK_BLOCK) || !item.getType().equals(Material.BUCKET) || !clickedBlock.getType().equals(Material.OBSIDIAN)) {
assertFalse(listener.onPlayerInteract(event));

View File

@ -32,14 +32,8 @@ public class RanksManagerTest {
@Before
public void setUp() throws Exception {
BentoBox plugin = mock(BentoBox.class);
Settings settings = mock(Settings.class);
// Blank ranks for now
Map<String, Integer> customRanks = new HashMap<>();
when(plugin.getSettings()).thenReturn(settings);
when(settings.getCustomRanks()).thenReturn(customRanks);
ranksManager = new RanksManager(plugin);
}
/**
@ -118,5 +112,4 @@ public class RanksManagerTest {
assertEquals(RanksManager.OWNER_RANK_REF, ranksManager.getRank(RanksManager.OWNER_RANK));
assertEquals("", ranksManager.getRank(-999));
}
}