Merge pull request #2347 from BentoBoxWorld/mp_debug_sesh
Mp debug sesh
This commit is contained in:
commit
7477b8049f
|
@ -59,7 +59,6 @@ public class BStats {
|
|||
registerGameModeAddonsChart();
|
||||
registerHooksChart();
|
||||
registerPlayersPerServerChart();
|
||||
registerFlagsDisplayModeChart();
|
||||
|
||||
// Single Line charts
|
||||
registerIslandsCountChart();
|
||||
|
@ -171,27 +170,6 @@ public class BStats {
|
|||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the "flags display mode" of all the online players.
|
||||
* @since 1.6.0
|
||||
*/
|
||||
private void registerFlagsDisplayModeChart() {
|
||||
metrics.addCustomChart(new AdvancedPie("flagsDisplayMode", () -> {
|
||||
Map<String, Integer> values = new HashMap<>();
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
Flag.Mode mode = plugin.getPlayers().getFlagsDisplayMode(player.getUniqueId());
|
||||
if (values.containsKey(mode.name())) {
|
||||
values.put(mode.name(), values.get(mode.name()) + 1);
|
||||
} else {
|
||||
values.put(mode.name(), 1);
|
||||
}
|
||||
});
|
||||
|
||||
return values;
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the enabled addons (except GameModeAddons) of this server as bar chart.
|
||||
* @since 1.17.1
|
||||
|
|
|
@ -419,7 +419,7 @@ public class BentoBox extends JavaPlugin implements Listener {
|
|||
* @return the ranksManager
|
||||
* @deprecated Just use {@code RanksManager.getInstance()}
|
||||
*/
|
||||
@Deprecated(since = "2.0.0")
|
||||
@Deprecated(since = "2.0.0", forRemoval = true)
|
||||
public RanksManager getRanksManager() {
|
||||
return RanksManager.getInstance();
|
||||
}
|
||||
|
|
|
@ -21,6 +21,8 @@ import org.bukkit.configuration.file.FileConfiguration;
|
|||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import com.github.puregero.multilib.MultiLib;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.request.AddonRequestHandler;
|
||||
import world.bentobox.bentobox.api.flags.Flag;
|
||||
|
@ -45,6 +47,8 @@ public abstract class Addon {
|
|||
|
||||
protected Addon() {
|
||||
state = State.DISABLED;
|
||||
// If the config is updated, update the config.
|
||||
MultiLib.onString(getPlugin(), "bentobox-config-update", v -> this.reloadConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,8 @@ import org.bukkit.generator.ChunkGenerator;
|
|||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import com.github.puregero.multilib.MultiLib;
|
||||
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
@ -129,7 +131,10 @@ public abstract class GameModeAddon extends Addon {
|
|||
* in-game and need to be saved.
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public abstract void saveWorldSettings();
|
||||
public void saveWorldSettings() {
|
||||
// Inform other servers
|
||||
MultiLib.notify("bentobox-config-update", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines if the game mode uses the latest {@link ChunkGenerator} API or
|
||||
|
|
|
@ -16,7 +16,6 @@ import org.eclipse.jdt.annotation.Nullable;
|
|||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.flags.Flag;
|
||||
import world.bentobox.bentobox.api.flags.Flag.Mode;
|
||||
import world.bentobox.bentobox.api.flags.Flag.Type;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.panels.builders.TabbedPanelBuilder;
|
||||
|
@ -206,11 +205,9 @@ public class AdminSettingsCommand extends CompositeCommand {
|
|||
switch (f.getType()) {
|
||||
case PROTECTION -> {
|
||||
island.setFlag(f, rank);
|
||||
getIslands().updateIsland(island);
|
||||
}
|
||||
case SETTING -> {
|
||||
island.setSettingsFlag(f, activeState);
|
||||
getIslands().updateIsland(island);
|
||||
}
|
||||
case WORLD_SETTING -> f.setSetting(getWorld(), activeState);
|
||||
default -> {
|
||||
|
@ -226,12 +223,11 @@ public class AdminSettingsCommand extends CompositeCommand {
|
|||
user.sendMessage("general.errors.use-in-game");
|
||||
return false;
|
||||
}
|
||||
getPlayers().setFlagsDisplayMode(user.getUniqueId(), Mode.EXPERT);
|
||||
if (args.isEmpty()) {
|
||||
new TabbedPanelBuilder()
|
||||
.user(user)
|
||||
.world(getWorld())
|
||||
.tab(1, new SettingsTab(getWorld(), user, Flag.Type.WORLD_SETTING))
|
||||
.tab(1, new SettingsTab(getWorld(), user, Flag.Type.WORLD_SETTING, Flag.Mode.EXPERT))
|
||||
.tab(2, new WorldDefaultSettingsTab(getWorld(), user))
|
||||
.startingSlot(1)
|
||||
.size(54)
|
||||
|
@ -242,8 +238,8 @@ public class AdminSettingsCommand extends CompositeCommand {
|
|||
new TabbedPanelBuilder()
|
||||
.user(user)
|
||||
.world(island.getWorld())
|
||||
.island(island).tab(1, new SettingsTab(user, Flag.Type.PROTECTION))
|
||||
.tab(2, new SettingsTab(user, Flag.Type.SETTING))
|
||||
.island(island).tab(1, new SettingsTab(getWorld(), user, Flag.Type.PROTECTION, Flag.Mode.EXPERT))
|
||||
.tab(2, new SettingsTab(getWorld(), user, Flag.Type.SETTING, Flag.Mode.EXPERT))
|
||||
.startingSlot(1)
|
||||
.size(54)
|
||||
.build().openPanel();
|
||||
|
|
|
@ -116,7 +116,6 @@ public class AdminUnregisterCommand extends ConfirmableCommand {
|
|||
targetIsland.getMembers().clear();
|
||||
targetIsland.log(new LogEntry.Builder("UNREGISTER").data("player", targetUUID.toString())
|
||||
.data("admin", user.getUniqueId().toString()).build());
|
||||
getIslands().updateIsland(targetIsland);
|
||||
user.sendMessage("commands.admin.unregister.unregistered-island", TextVariables.XYZ, Util.xyz(targetIsland.getCenter().toVector()),
|
||||
TextVariables.NAME, getPlayers().getName(targetUUID));
|
||||
}
|
||||
|
|
|
@ -40,7 +40,6 @@ public class NamePrompt extends StringPrompt {
|
|||
@Override
|
||||
public Prompt acceptInput(@NonNull ConversationContext context, String input) {
|
||||
if (island.renameHome(oldName, input)) {
|
||||
plugin.getIslands().updateIsland(island);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> user.sendMessage("general.success"));
|
||||
} else {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> user.sendMessage("commands.island.renamehome.already-exists"));
|
||||
|
|
|
@ -49,7 +49,8 @@ public class IslandSettingsCommand extends CompositeCommand {
|
|||
.user(user)
|
||||
.island(island)
|
||||
.world(island.getWorld())
|
||||
.tab(1, new SettingsTab(user, Flag.Type.PROTECTION)).tab(2, new SettingsTab(user, Flag.Type.SETTING))
|
||||
.tab(1, new SettingsTab(getWorld(), user, Flag.Type.PROTECTION))
|
||||
.tab(2, new SettingsTab(getWorld(), user, Flag.Type.SETTING))
|
||||
.startingSlot(1)
|
||||
.size(54)
|
||||
.hideIfEmpty()
|
||||
|
|
|
@ -197,7 +197,6 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
|
|||
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", TextVariables.NAME,
|
||||
user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName());
|
||||
}
|
||||
//IslandsManager.updateIsland(teamIsland);
|
||||
// Fire event
|
||||
TeamEvent.builder().island(teamIsland).reason(TeamEvent.Reason.JOINED).involvedPlayer(user.getUniqueId())
|
||||
.build();
|
||||
|
|
|
@ -92,7 +92,6 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
|
|||
IslandEvent.builder().island(island).involvedPlayer(user.getUniqueId()).admin(false)
|
||||
.reason(IslandEvent.Reason.RANK_CHANGE).rankChange(RanksManager.OWNER_RANK, RanksManager.SUB_OWNER_RANK)
|
||||
.build();
|
||||
IslandsManager.updateIsland(island);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -388,21 +388,24 @@ public class Flag implements Comparable<Flag> {
|
|||
if (!user.isOp() && invisible) {
|
||||
return null;
|
||||
}
|
||||
// Start the flag conversion
|
||||
PanelItemBuilder pib = new PanelItemBuilder()
|
||||
.icon(ItemParser.parse(user.getTranslationOrNothing(this.getIconReference()), new ItemStack(icon)))
|
||||
.name(user.getTranslation("protection.panel.flag-item.name-layout", TextVariables.NAME, user.getTranslation(getNameReference())))
|
||||
.name(user.getTranslation("protection.panel.flag-item.name-layout", TextVariables.NAME,
|
||||
user.getTranslation(getNameReference())))
|
||||
.clickHandler(clickHandler)
|
||||
.invisible(invisible);
|
||||
if (hasSubPanel()) {
|
||||
pib.description(user.getTranslation("protection.panel.flag-item.menu-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())));
|
||||
return pib.build();
|
||||
}
|
||||
|
||||
return switch (getType()) {
|
||||
case PROTECTION -> createProtectionFlag(plugin, user, island, pib).build();
|
||||
case SETTING -> createSettingFlag(user, island, pib).build();
|
||||
case WORLD_SETTING -> createWorldSettingFlag(user, world, pib).build();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
private PanelItemBuilder createWorldSettingFlag(User user, World world, PanelItemBuilder pib) {
|
||||
|
@ -429,19 +432,24 @@ public class Flag implements Comparable<Flag> {
|
|||
|
||||
private PanelItemBuilder createProtectionFlag(BentoBox plugin, User user, Island island, PanelItemBuilder pib) {
|
||||
if (island != null) {
|
||||
int y = island.getFlag(this);
|
||||
// Protection flag
|
||||
|
||||
pib.description(user.getTranslation("protection.panel.flag-item.description-layout",
|
||||
TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())));
|
||||
|
||||
RanksManager.getInstance().getRanks().forEach((reference, score) -> {
|
||||
if (score > RanksManager.BANNED_RANK && score < island.getFlag(this)) {
|
||||
|
||||
if (score > RanksManager.BANNED_RANK && score < y) {
|
||||
pib.description(user.getTranslation("protection.panel.flag-item.blocked-rank") + user.getTranslation(reference));
|
||||
} else if (score <= RanksManager.OWNER_RANK && score > island.getFlag(this)) {
|
||||
} else if (score <= RanksManager.OWNER_RANK && score > y) {
|
||||
pib.description(user.getTranslation("protection.panel.flag-item.allowed-rank") + user.getTranslation(reference));
|
||||
} else if (score == island.getFlag(this)) {
|
||||
} else if (score == y) {
|
||||
pib.description(user.getTranslation("protection.panel.flag-item.minimal-rank") + user.getTranslation(reference));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return pib;
|
||||
}
|
||||
|
||||
|
@ -469,7 +477,7 @@ public class Flag implements Comparable<Flag> {
|
|||
public Set<Flag> getSubflags() {
|
||||
return subflags;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the name of this flag for a specified locale. This enables the flag's name to be assigned via API. It will not be stored anywhere
|
||||
* and must be rewritten using this call every time the flag is built.
|
||||
|
@ -482,7 +490,7 @@ public class Flag implements Comparable<Flag> {
|
|||
public boolean setTranslatedName(Locale locale, String name) {
|
||||
return BentoBox.getInstance().getLocalesManager().setTranslation(locale, getNameReference(), name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the name of this flag for a specified locale. This enables the flag's name to be assigned via API. It will not be stored anywhere
|
||||
* and must be rewritten using this call every time the flag is built.
|
||||
|
|
|
@ -74,6 +74,7 @@ public class TabbedPanel extends Panel implements PanelListener {
|
|||
* @param page - the page of the tab to show (if multi paged)
|
||||
*/
|
||||
public void openPanel(int activeTab, int page) {
|
||||
|
||||
if (!tpb.getTabs().containsKey(activeTab)) {
|
||||
// Request to open a non-existent tab
|
||||
throw new InvalidParameterException("Attempt to open a non-existent tab in a tabbed panel. Missing tab #" + activeTab);
|
||||
|
@ -88,21 +89,17 @@ public class TabbedPanel extends Panel implements PanelListener {
|
|||
TreeMap<Integer, PanelItem> items = new TreeMap<>();
|
||||
// Get the tab
|
||||
Tab tab = tpb.getTabs().get(activeTab);
|
||||
|
||||
// Remove any tabs that have no items, if required
|
||||
if (tpb.isHideIfEmpty()) {
|
||||
tpb.getTabs().values().removeIf(t -> !t.equals(tab) && t.getPanelItems().stream().noneMatch(Objects::nonNull));
|
||||
}
|
||||
|
||||
// Set up the tabbed header
|
||||
setupHeader(tab, items);
|
||||
|
||||
// Show the active tab
|
||||
if (tpb.getTabs().containsKey(activeTab)) {
|
||||
List<PanelItem> panelItems = tab.getPanelItems();
|
||||
// Adds the flag items
|
||||
panelItems.stream().filter(Objects::nonNull).skip(page * ITEMS_PER_PAGE).limit(page * ITEMS_PER_PAGE + ITEMS_PER_PAGE).forEach(i -> items.put(items.lastKey() + 1, i));
|
||||
|
||||
// set up the footer
|
||||
setupFooter(items);
|
||||
// Add forward and backward icons
|
||||
|
@ -182,6 +179,7 @@ public class TabbedPanel extends Panel implements PanelListener {
|
|||
// Reset the closed flag
|
||||
closed = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,13 +6,10 @@ import java.util.Map;
|
|||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
|
@ -30,8 +27,6 @@ import world.bentobox.bentobox.util.Util;
|
|||
*/
|
||||
@Table(name = "Players")
|
||||
public class Players implements DataObject, MetaDataAble {
|
||||
@Expose
|
||||
private Map<Location, Integer> homeLocations = new HashMap<>();
|
||||
@Expose
|
||||
private String uniqueId;
|
||||
@Expose
|
||||
|
@ -77,7 +72,6 @@ public class Players implements DataObject, MetaDataAble {
|
|||
*/
|
||||
public Players(BentoBox plugin, UUID uniqueId) {
|
||||
this.uniqueId = uniqueId.toString();
|
||||
homeLocations = new HashMap<>();
|
||||
locale = "";
|
||||
// Try to get player's name
|
||||
this.playerName = Bukkit.getOfflinePlayer(uniqueId).getName();
|
||||
|
@ -86,72 +80,6 @@ public class Players implements DataObject, MetaDataAble {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default home location.
|
||||
* @param world - world to check
|
||||
* @return Location - home location in world
|
||||
* @deprecated Homes are stored in the Island object now
|
||||
*/
|
||||
@Deprecated(since="1.18.0", forRemoval=true)
|
||||
@Nullable
|
||||
public Location getHomeLocation(World world) {
|
||||
return getHomeLocation(world, 1); // Default
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the home location by number for world
|
||||
* @param world - includes world and any related nether or end worlds
|
||||
* @param number - a number
|
||||
* @return Location of this home or null if not available
|
||||
* @deprecated Homes are stored in the island object now
|
||||
*/
|
||||
@Deprecated(since="1.18.0", forRemoval=true)
|
||||
@Nullable
|
||||
public Location getHomeLocation(World world, int number) {
|
||||
// Remove any lost worlds/locations
|
||||
homeLocations.keySet().removeIf(l -> l == null || l.getWorld() == null);
|
||||
return homeLocations.entrySet().stream()
|
||||
.filter(en -> Util.sameWorld(en.getKey().getWorld(), world) && en.getValue() == number)
|
||||
.map(Map.Entry::getKey)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world - world
|
||||
* @return Map of home locations
|
||||
* @deprecated Homes are stored in the island object now
|
||||
*/
|
||||
@Deprecated(since="1.18.0", forRemoval=true)
|
||||
public Map<Location, Integer> getHomeLocations(World world) {
|
||||
// Remove any lost worlds/locations
|
||||
homeLocations.keySet().removeIf(l -> l == null || l.getWorld() == null);
|
||||
return homeLocations.entrySet().stream().filter(e -> Util.sameWorld(e.getKey().getWorld(),world))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the homeLocations
|
||||
* @deprecated Homes are stored in the Island object now
|
||||
*/
|
||||
@Deprecated(since="1.18.0", forRemoval=true)
|
||||
public Map<Location, Integer> getHomeLocations() {
|
||||
// Remove any lost worlds/locations
|
||||
homeLocations.keySet().removeIf(l -> l == null || l.getWorld() == null);
|
||||
return homeLocations;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param homeLocations the homeLocations to set
|
||||
* @deprecated Homes are stored in the Island object now
|
||||
*/
|
||||
@Deprecated(since="1.18.0", forRemoval=true)
|
||||
public void setHomeLocations(Map<Location, Integer> homeLocations) {
|
||||
this.homeLocations = homeLocations;
|
||||
// Remove any lost worlds/locations
|
||||
homeLocations.keySet().removeIf(l -> l == null || l.getWorld() == null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param playerName the playerName to set
|
||||
*/
|
||||
|
@ -202,30 +130,6 @@ public class Players implements DataObject, MetaDataAble {
|
|||
this.resets.put(world.getName(), resets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the home location of the player in a String format
|
||||
*
|
||||
* @param l a Bukkit location
|
||||
* @deprecated Home locations are stored in islands
|
||||
*/
|
||||
@Deprecated(since="1.18.0", forRemoval=true)
|
||||
public void setHomeLocation(final Location l) {
|
||||
setHomeLocation(l, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the numbered home location of the player. Numbering starts at 1.
|
||||
* @param location - the location
|
||||
* @param number - a number
|
||||
* @deprecated Home locations are no longer stored for players. They are stored in islands.
|
||||
*/
|
||||
@Deprecated(since="1.18.0", forRemoval=true)
|
||||
public void setHomeLocation(Location location, int number) {
|
||||
// Remove any home locations in the same world with the same number
|
||||
homeLocations.entrySet().removeIf(e -> e.getKey() == null || (Util.sameWorld(location.getWorld(), e.getKey().getWorld()) && e.getValue().equals(number)));
|
||||
homeLocations.put(location, number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the uuid for this player object
|
||||
* @param uuid - UUID
|
||||
|
@ -234,16 +138,6 @@ public class Players implements DataObject, MetaDataAble {
|
|||
uniqueId = uuid.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all home Locations in world
|
||||
* @param world - world
|
||||
* @deprecated Home locations are no longer stored for players. Use {@link world.bentobox.bentobox.managers.IslandsManager}
|
||||
*/
|
||||
@Deprecated(since="1.18.0", forRemoval=true)
|
||||
public void clearHomeLocations(World world) {
|
||||
homeLocations.keySet().removeIf(l -> l == null || l.getWorld() == null || Util.sameWorld(l.getWorld(), world));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the locale
|
||||
*/
|
||||
|
@ -350,24 +244,6 @@ public class Players implements DataObject, MetaDataAble {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the display mode for the Flags in the Settings Panel.
|
||||
* @return the display mode for the Flags in the Settings Panel.
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public Flag.Mode getFlagsDisplayMode() {
|
||||
return flagsDisplayMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the display mode for the Flags in the Settings Panel.
|
||||
* @param flagsDisplayMode the display mode for the Flags in the Settings Panel.
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public void setFlagsDisplayMode(Flag.Mode flagsDisplayMode) {
|
||||
this.flagsDisplayMode = flagsDisplayMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the metaData
|
||||
* @since 1.15.5
|
||||
|
|
|
@ -62,7 +62,7 @@ public class JoinLeaveListener implements Listener {
|
|||
|
||||
// Make sure the player is loaded into the cache or create the player if they
|
||||
// don't exist
|
||||
players.addPlayer(playerUUID);
|
||||
players.getPlayer(playerUUID);
|
||||
|
||||
// Reset island resets if required
|
||||
plugin.getIWM().getOverWorlds().stream()
|
||||
|
@ -110,7 +110,7 @@ public class JoinLeaveListener implements Listener {
|
|||
private void firstTime(User user) {
|
||||
// Make sure the player is loaded into the cache or create the player if they
|
||||
// don't exist
|
||||
players.addPlayer(user.getUniqueId());
|
||||
players.getPlayer(user.getUniqueId());
|
||||
|
||||
plugin.getIWM().getOverWorlds().stream().filter(w -> plugin.getIWM().isCreateIslandOnFirstLoginEnabled(w))
|
||||
.forEach(w -> {
|
||||
|
|
|
@ -61,6 +61,7 @@ public class PanelListenerManager implements Listener {
|
|||
// Refresh
|
||||
l.refreshPanel();
|
||||
});
|
||||
|
||||
} else {
|
||||
// Wrong name - delete this panel
|
||||
openPanels.remove(user.getUniqueId());
|
||||
|
|
|
@ -60,9 +60,6 @@ public class CommandCycleClick implements ClickHandler {
|
|||
}
|
||||
// Apply change to panel
|
||||
panel.getInventory().setItem(slot, commandRankClickListener.getPanelItem(command, user, world).getItem());
|
||||
// Save island
|
||||
plugin.getIslands().updateIsland(island);
|
||||
|
||||
} else {
|
||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
|
||||
}
|
||||
|
|
|
@ -108,7 +108,6 @@ public class IslandsManager {
|
|||
|
||||
// Listen for Island Updates
|
||||
MultiLib.onString(plugin, "bentobox-updateIsland", id -> {
|
||||
BentoBox.getInstance().logDebug("Updating island " + id);
|
||||
Island island = handler.loadObject(id);
|
||||
if (island != null) {
|
||||
islandCache.updateIsland(island);
|
||||
|
@ -117,13 +116,11 @@ public class IslandsManager {
|
|||
|
||||
// Delete island blocks
|
||||
MultiLib.onString(plugin, "bentobox-deleteIsland", id -> {
|
||||
BentoBox.getInstance().logDebug("Delete island blocks");
|
||||
IslandDeletion idd = getGson().fromJson(id, IslandDeletion.class);
|
||||
plugin.getIslandDeletionManager().getIslandChunkDeletionManager().add(idd);
|
||||
});
|
||||
// List for new islands
|
||||
MultiLib.onString(plugin, "bentobox-newIsland", id -> {
|
||||
BentoBox.getInstance().logDebug("New island " + id);
|
||||
Island island = handler.loadObject(id);
|
||||
if (island != null) {
|
||||
islandCache.addIsland(island);
|
||||
|
@ -139,7 +136,6 @@ public class IslandsManager {
|
|||
World world = Bukkit.getWorld(split[0]);
|
||||
if (world != null) {
|
||||
getIslandById(split[1]).ifPresent(i -> this.setSpawn(i));
|
||||
BentoBox.getInstance().logDebug("Setting spawn for world " + world);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -277,7 +273,6 @@ public class IslandsManager {
|
|||
* @param involvedPlayer - player related to the island deletion, if any
|
||||
*/
|
||||
public void deleteIsland(@NonNull Island island, boolean removeBlocks, @Nullable UUID involvedPlayer) {
|
||||
BentoBox.getInstance().logDebug("Deleting island " + island.getUniqueId() + " remove blocks = " + removeBlocks);
|
||||
// Fire event
|
||||
IslandBaseEvent event = IslandEvent.builder().island(island).involvedPlayer(involvedPlayer)
|
||||
.reason(Reason.DELETE).build();
|
||||
|
|
|
@ -2,7 +2,9 @@ package world.bentobox.bentobox.managers;
|
|||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
@ -14,7 +16,6 @@ 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.api.user.User;
|
||||
import world.bentobox.bentobox.database.Database;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
|
@ -27,11 +28,10 @@ public class PlayersManager {
|
|||
private final BentoBox plugin;
|
||||
private Database<Players> handler;
|
||||
private final Database<Names> names;
|
||||
private final Map<UUID, Players> playerCache = new HashMap<>();
|
||||
|
||||
private final Set<UUID> inTeleport; // this needs databasing
|
||||
|
||||
private boolean isSaveTaskRunning;
|
||||
|
||||
/**
|
||||
* Provides a memory cache of online player information
|
||||
* This is the one-stop-shop of player info
|
||||
|
@ -56,17 +56,6 @@ public class PlayersManager {
|
|||
this.handler = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all players - not normally used as to load all players into memory will be wasteful
|
||||
*/
|
||||
public void load(){
|
||||
inTeleport.clear();
|
||||
}
|
||||
|
||||
public boolean isSaveTaskRunning() {
|
||||
return isSaveTaskRunning;
|
||||
}
|
||||
|
||||
public void shutdown(){
|
||||
handler.close();
|
||||
}
|
||||
|
@ -78,28 +67,17 @@ public class PlayersManager {
|
|||
*/
|
||||
@Nullable
|
||||
public Players getPlayer(UUID uuid){
|
||||
return addPlayer(uuid);
|
||||
if (!playerCache.containsKey(uuid)) {
|
||||
playerCache.put(uuid, addPlayer(uuid));
|
||||
}
|
||||
return playerCache.get(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an <strong>unmodifiable collection</strong> of all the players that are <strong>currently in the cache</strong>.
|
||||
* @return unmodifiable collection containing every player in the cache.
|
||||
* @since 1.1
|
||||
*/
|
||||
@NonNull
|
||||
public Collection<Players> getPlayers() {
|
||||
return Collections.unmodifiableCollection(handler.loadObjects());
|
||||
}
|
||||
|
||||
/*
|
||||
* Cache control methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Adds a player to the database. If the UUID does not exist, a new player is made
|
||||
* @param playerUUID - the player's UUID
|
||||
*/
|
||||
public Players addPlayer(@NonNull UUID playerUUID) {
|
||||
private Players addPlayer(@NonNull UUID playerUUID) {
|
||||
Objects.requireNonNull(playerUUID);
|
||||
// If the player is in the database, load it, otherwise create a new player
|
||||
if (handler.objectExists(playerUUID.toString())) {
|
||||
|
@ -113,6 +91,16 @@ public class PlayersManager {
|
|||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an <strong>unmodifiable collection</strong> of all the players that are <strong>currently in the cache</strong>.
|
||||
* @return unmodifiable collection containing every player in the cache.
|
||||
* @since 1.1
|
||||
*/
|
||||
@NonNull
|
||||
public Collection<Players> getPlayers() {
|
||||
return Collections.unmodifiableCollection(handler.loadObjects());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player is known or not.
|
||||
* Will check not just the cache but if the object but in the database too.
|
||||
|
@ -149,7 +137,7 @@ public class PlayersManager {
|
|||
* @param user - the User
|
||||
*/
|
||||
public void setPlayerName(@NonNull User user) {
|
||||
Players player = addPlayer(user.getUniqueId());
|
||||
Players player = getPlayer(user.getUniqueId());
|
||||
player.setPlayerName(user.getName());
|
||||
handler.saveObject(player);
|
||||
Names newName = new Names(user.getName(), user.getUniqueId());
|
||||
|
@ -180,7 +168,7 @@ public class PlayersManager {
|
|||
* @return number of resets
|
||||
*/
|
||||
public int getResets(World world, UUID playerUUID) {
|
||||
return addPlayer(playerUUID).getResets(world);
|
||||
return getPlayer(playerUUID).getResets(world);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -192,7 +180,7 @@ public class PlayersManager {
|
|||
* @see #getResets(World, UUID)
|
||||
*/
|
||||
public int getResetsLeft(World world, UUID playerUUID) {
|
||||
addPlayer(playerUUID);
|
||||
getPlayer(playerUUID);
|
||||
if (plugin.getIWM().getResetLimit(world) == -1) {
|
||||
return -1;
|
||||
} else {
|
||||
|
@ -208,7 +196,7 @@ public class PlayersManager {
|
|||
* @param resets number of resets to set
|
||||
*/
|
||||
public void setResets(World world, UUID playerUUID, int resets) {
|
||||
Players p = addPlayer(playerUUID);
|
||||
Players p = getPlayer(playerUUID);
|
||||
p.setResets(world, resets);
|
||||
handler.saveObject(p);
|
||||
}
|
||||
|
@ -219,7 +207,7 @@ public class PlayersManager {
|
|||
* @return name of the locale this player uses
|
||||
*/
|
||||
public String getLocale(UUID playerUUID) {
|
||||
return addPlayer(playerUUID).getLocale();
|
||||
return getPlayer(playerUUID).getLocale();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -228,7 +216,7 @@ public class PlayersManager {
|
|||
* @param localeName - locale name, e.g., en-US
|
||||
*/
|
||||
public void setLocale(UUID playerUUID, String localeName) {
|
||||
Players p = addPlayer(playerUUID);
|
||||
Players p = getPlayer(playerUUID);
|
||||
p.setLocale(localeName);
|
||||
handler.saveObject(p);
|
||||
}
|
||||
|
@ -239,7 +227,7 @@ public class PlayersManager {
|
|||
* @param playerUUID - the player's UUID
|
||||
*/
|
||||
public void addDeath(World world, UUID playerUUID) {
|
||||
Players p = addPlayer(playerUUID);
|
||||
Players p = getPlayer(playerUUID);
|
||||
p.addDeath(world);
|
||||
handler.saveObject(p);
|
||||
}
|
||||
|
@ -251,7 +239,7 @@ public class PlayersManager {
|
|||
* @param deaths - number of deaths
|
||||
*/
|
||||
public void setDeaths(World world, UUID playerUUID, int deaths) {
|
||||
Players p = addPlayer(playerUUID);
|
||||
Players p = getPlayer(playerUUID);
|
||||
p.setDeaths(world, deaths);
|
||||
handler.saveObject(p);
|
||||
}
|
||||
|
@ -263,7 +251,7 @@ public class PlayersManager {
|
|||
* @return number of deaths
|
||||
*/
|
||||
public int getDeaths(World world, UUID playerUUID) {
|
||||
return addPlayer(playerUUID).getDeaths(world);
|
||||
return getPlayer(playerUUID).getDeaths(world);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -315,33 +303,11 @@ public class PlayersManager {
|
|||
* @param playerUUID player's UUID
|
||||
*/
|
||||
public void addReset(World world, UUID playerUUID) {
|
||||
Players p = addPlayer(playerUUID);
|
||||
Players p = getPlayer(playerUUID);
|
||||
p.addReset(world);
|
||||
handler.saveObject(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Flags display mode for the Settings Panel for this player.
|
||||
* @param playerUUID player's UUID
|
||||
* @param displayMode the {@link Flag.Mode} to set
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public void setFlagsDisplayMode(UUID playerUUID, Flag.Mode displayMode) {
|
||||
Players p = addPlayer(playerUUID);
|
||||
p.setFlagsDisplayMode(displayMode);
|
||||
handler.saveObject(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Flags display mode for the Settings Panel for this player.
|
||||
* @param playerUUID player's UUID
|
||||
* @return the {@link Flag.Mode display mode} for the Flags in the Settings Panel.
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public Flag.Mode getFlagsDisplayMode(UUID playerUUID) {
|
||||
return addPlayer(playerUUID).getFlagsDisplayMode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove player from database
|
||||
* @param player player to remove
|
||||
|
|
|
@ -96,6 +96,11 @@ public class IslandCache {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO REMOVE THIS DEBUG METHOD
|
||||
* @param island1 island1
|
||||
* @param island2 island 2
|
||||
*/
|
||||
public void compareIslands(Island island1, Island island2) {
|
||||
if (island1 == null || island2 == null) {
|
||||
BentoBox.getInstance().logDebug("One or both islands are null. Cannot compare.");
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.Comparator;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -16,6 +17,7 @@ import org.eclipse.jdt.annotation.Nullable;
|
|||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.flags.Flag;
|
||||
import world.bentobox.bentobox.api.flags.Flag.Mode;
|
||||
import world.bentobox.bentobox.api.flags.Flag.Type;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.panels.Panel;
|
||||
|
@ -46,16 +48,7 @@ public class SettingsTab implements Tab, ClickHandler {
|
|||
protected Island island;
|
||||
protected TabbedPanel parent;
|
||||
|
||||
/**
|
||||
* Show a tab of settings
|
||||
* @param user - user who is viewing the tab
|
||||
* @param type - flag type
|
||||
*/
|
||||
public SettingsTab(User user, Type type) {
|
||||
this.user = user;
|
||||
this.type = type;
|
||||
// Island and world are set when the parent is set.
|
||||
}
|
||||
private Map<UUID, Flag.Mode> currentMode = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Show a tab of settings
|
||||
|
@ -69,6 +62,21 @@ public class SettingsTab implements Tab, ClickHandler {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a tab of settings
|
||||
* @param world - world
|
||||
* @param user - user who is viewing the tab
|
||||
* @param type - flag type
|
||||
* @param defaultMode - the default mode to show
|
||||
* @since 2.4.0
|
||||
*/
|
||||
public SettingsTab(World world, User user, Type type, Flag.Mode defaultMode) {
|
||||
this.world = world;
|
||||
this.user = user;
|
||||
this.type = type;
|
||||
currentMode.put(user.getUniqueId(), defaultMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list of flags that will be shown in this panel
|
||||
*/
|
||||
|
@ -81,7 +89,7 @@ public class SettingsTab implements Tab, ClickHandler {
|
|||
// Remove any that are not for this game mode
|
||||
plugin.getIWM().getAddon(world).ifPresent(gm -> flags.removeIf(f -> !f.getGameModes().isEmpty() && !f.getGameModes().contains(gm)));
|
||||
// Remove any that are the wrong rank or that will be on the top row
|
||||
Flag.Mode mode = plugin.getPlayers().getFlagsDisplayMode(user.getUniqueId());
|
||||
Flag.Mode mode = currentMode.getOrDefault(user.getUniqueId(), Mode.BASIC);
|
||||
plugin.getIWM().getAddon(world).ifPresent(gm -> flags.removeIf(f -> f.getMode().isGreaterThan(mode) ||
|
||||
f.getMode().equals(Flag.Mode.TOP_ROW)));
|
||||
return flags;
|
||||
|
@ -120,13 +128,14 @@ public class SettingsTab implements Tab, ClickHandler {
|
|||
int i = 0;
|
||||
// Jump past empty tabs
|
||||
while (flags.isEmpty() && i++ < Flag.Mode.values().length) {
|
||||
plugin.getPlayers().setFlagsDisplayMode(user.getUniqueId(), plugin.getPlayers().getFlagsDisplayMode(user.getUniqueId()).getNext());
|
||||
currentMode.put(user.getUniqueId(), currentMode.getOrDefault(user.getUniqueId(), Mode.BASIC).getNext());
|
||||
flags = getFlags();
|
||||
}
|
||||
return flags.stream().map(
|
||||
List<@Nullable PanelItem> result = flags.stream().map(
|
||||
(f -> f.toPanelItem(plugin, user, world, island,
|
||||
plugin.getIWM().getHiddenFlags(world).contains(f.getID()))))
|
||||
.toList();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -137,8 +146,9 @@ public class SettingsTab implements Tab, ClickHandler {
|
|||
icons.put(4, Flags.CHANGE_SETTINGS.toPanelItem(plugin, user, world, island, false));
|
||||
icons.put(5, Flags.LOCK.toPanelItem(plugin, user, world, island, false));
|
||||
}
|
||||
|
||||
// Add the mode icon
|
||||
switch (plugin.getPlayers().getFlagsDisplayMode(user.getUniqueId())) {
|
||||
switch (currentMode.getOrDefault(user.getUniqueId(), Mode.BASIC)) {
|
||||
case ADVANCED -> icons.put(7, new PanelItemBuilder().icon(Material.GOLD_INGOT)
|
||||
.name(user.getTranslation(PROTECTION_PANEL + "mode.advanced.name"))
|
||||
.description(user.getTranslation(PROTECTION_PANEL + "mode.advanced.description"), "",
|
||||
|
@ -161,7 +171,8 @@ public class SettingsTab implements Tab, ClickHandler {
|
|||
.clickHandler(this)
|
||||
.build());
|
||||
}
|
||||
// Add the reset everything to default - it's only in the player's settings panel
|
||||
|
||||
// Add the reset everything to default - it's only in the player's settings panel
|
||||
if (island != null && user.getUniqueId().equals(island.getOwner())) {
|
||||
icons.put(8, new PanelItemBuilder().icon(Material.TNT)
|
||||
.name(user.getTranslation(PROTECTION_PANEL + "reset-to-default.name"))
|
||||
|
@ -216,7 +227,7 @@ public class SettingsTab implements Tab, ClickHandler {
|
|||
@Override
|
||||
public boolean onClick(Panel panel, User user, ClickType clickType, int slot) {
|
||||
// Cycle the mode
|
||||
plugin.getPlayers().setFlagsDisplayMode(user.getUniqueId(), plugin.getPlayers().getFlagsDisplayMode(user.getUniqueId()).getNext());
|
||||
currentMode.put(user.getUniqueId(), currentMode.getOrDefault(user.getUniqueId(), Mode.BASIC).getNext());
|
||||
if (panel instanceof TabbedPanel tp) {
|
||||
tp.setActivePage(0);
|
||||
tp.refreshPanel();
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.bukkit.Material;
|
|||
import org.bukkit.World;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.flags.Flag.Type;
|
||||
import world.bentobox.bentobox.api.flags.clicklisteners.WorldToggleClick;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
|
|
|
@ -32,10 +32,13 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
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 com.github.puregero.multilib.MultiLib;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.exceptions.InvalidAddonDescriptionException;
|
||||
import world.bentobox.bentobox.managers.AddonsManager;
|
||||
|
@ -46,7 +49,7 @@ import world.bentobox.bentobox.managers.AddonsManager;
|
|||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest( { BentoBox.class, Bukkit.class })
|
||||
@PrepareForTest({ BentoBox.class, Bukkit.class, MultiLib.class })
|
||||
public class AddonClassLoaderTest {
|
||||
|
||||
private enum mandatoryTags {
|
||||
|
@ -80,6 +83,7 @@ public class AddonClassLoaderTest {
|
|||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
PowerMockito.mockStatic(MultiLib.class, Mockito.RETURNS_MOCKS);
|
||||
// Set up plugin
|
||||
plugin = mock(BentoBox.class);
|
||||
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
|
||||
|
|
|
@ -44,13 +44,15 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
|||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import com.github.puregero.multilib.MultiLib;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.managers.AddonsManager;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
import world.bentobox.bentobox.managers.PlayersManager;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest( { BentoBox.class, Bukkit.class })
|
||||
@PrepareForTest({ BentoBox.class, Bukkit.class, MultiLib.class })
|
||||
public class AddonTest {
|
||||
|
||||
public static int BUFFER_SIZE = 10240;
|
||||
|
@ -90,6 +92,8 @@ public class AddonTest {
|
|||
// Addons manager
|
||||
when(plugin.getAddonsManager()).thenReturn(am);
|
||||
|
||||
// MultiLib
|
||||
PowerMockito.mockStatic(MultiLib.class, Mockito.RETURNS_MOCKS);
|
||||
|
||||
// Mock item factory (for itemstacks)
|
||||
ItemFactory itemFactory = mock(ItemFactory.class);
|
||||
|
|
|
@ -144,7 +144,6 @@ public class AdminSettingsCommandTest extends RanksManagerBeforeClassTest {
|
|||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
// Players manager
|
||||
when(plugin.getPlayers()).thenReturn(pm);
|
||||
when(pm.getFlagsDisplayMode(any())).thenReturn(Mode.BASIC);
|
||||
//Island Manager
|
||||
when(plugin.getIslands()).thenReturn(im);
|
||||
// Island - player has island
|
||||
|
@ -267,16 +266,6 @@ public class AdminSettingsCommandTest extends RanksManagerBeforeClassTest {
|
|||
verify(user).sendMessage("general.errors.use-in-game");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminSettingsCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteUserStringListOfStringNoArgs() {
|
||||
assertTrue(asc.execute(user, "", Collections.emptyList()));
|
||||
verify(pm).setFlagsDisplayMode(user.getUniqueId(), Mode.EXPERT);
|
||||
// Open panel
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminSettingsCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
|
||||
*/
|
||||
|
|
|
@ -278,8 +278,6 @@ public class IslandTeamSetownerCommandTest {
|
|||
assertTrue(its.canExecute(user, "", List.of("tastybento")));
|
||||
assertTrue(its.execute(user, "", List.of("tastybento")));
|
||||
verify(im).setOwner(any(), eq(user), eq(target));
|
||||
PowerMockito.verifyStatic(IslandsManager.class);
|
||||
IslandsManager.updateIsland(island);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -295,8 +293,6 @@ public class IslandTeamSetownerCommandTest {
|
|||
assertTrue(its.canExecute(user, "", List.of("tastybento")));
|
||||
assertTrue(its.execute(user, "", List.of("tastybento")));
|
||||
verify(im).setOwner(any(), eq(user), eq(target));
|
||||
PowerMockito.verifyStatic(IslandsManager.class);
|
||||
IslandsManager.updateIsland(island);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -220,8 +220,6 @@ public class JoinLeaveListenerTest {
|
|||
jll = new JoinLeaveListener(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
@After
|
||||
public void tearDown() {
|
||||
User.clearUsers();
|
||||
|
@ -237,7 +235,7 @@ public class JoinLeaveListenerTest {
|
|||
PlayerJoinEvent event = new PlayerJoinEvent(player, "");
|
||||
jll.onPlayerJoin(event);
|
||||
// Verify
|
||||
verify(pm, times(2)).addPlayer(any());
|
||||
verify(pm, times(3)).getPlayer(any());
|
||||
verify(player, never()).sendMessage(anyString());
|
||||
// Verify resets
|
||||
verify(pm).setResets(eq(world), any(), eq(0));
|
||||
|
@ -354,7 +352,7 @@ public class JoinLeaveListenerTest {
|
|||
PlayerJoinEvent event = new PlayerJoinEvent(player, "");
|
||||
jll.onPlayerJoin(event);
|
||||
// Verify
|
||||
verify(pm, times(2)).addPlayer(any());
|
||||
verify(pm, times(3)).getPlayer(any());
|
||||
verify(player).sendMessage(eq("commands.island.create.on-first-login"));
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
|
|||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.reflect.Whitebox;
|
||||
|
||||
import com.github.puregero.multilib.MultiLib;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
|
@ -49,7 +51,7 @@ import world.bentobox.bentobox.database.DatabaseSetup.DatabaseType;
|
|||
import world.bentobox.bentobox.database.objects.DataObject;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest( {Bukkit.class, BentoBox.class, DefaultPermissions.class} )
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, DefaultPermissions.class, MultiLib.class })
|
||||
public class AddonsManagerTest {
|
||||
|
||||
private BentoBox plugin;
|
||||
|
@ -81,6 +83,8 @@ public class AddonsManagerTest {
|
|||
when(plugin.getSettings()).thenReturn(s);
|
||||
|
||||
PowerMockito.mockStatic(DefaultPermissions.class);
|
||||
|
||||
PowerMockito.mockStatic(MultiLib.class, Mockito.RETURNS_MOCKS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -45,6 +45,8 @@ import org.powermock.api.mockito.PowerMockito;
|
|||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import com.github.puregero.multilib.MultiLib;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
import world.bentobox.bentobox.api.addons.AddonDescription;
|
||||
|
@ -62,7 +64,7 @@ import world.bentobox.bentobox.database.objects.Island;
|
|||
*
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest( {Bukkit.class, BentoBox.class, BlueprintPaster.class} )
|
||||
@PrepareForTest({ Bukkit.class, BentoBox.class, BlueprintPaster.class, MultiLib.class })
|
||||
public class BlueprintsManagerTest {
|
||||
|
||||
public static int BUFFER_SIZE = 10240;
|
||||
|
@ -95,10 +97,12 @@ public class BlueprintsManagerTest {
|
|||
private int times;
|
||||
@Mock
|
||||
private Server server;
|
||||
/**
|
||||
*/
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// Multilib
|
||||
PowerMockito.mockStatic(MultiLib.class, Mockito.RETURNS_MOCKS);
|
||||
|
||||
// Make the addon
|
||||
dataFolder = new File("dataFolder");
|
||||
jarFile = new File("addon.jar");
|
||||
|
|
|
@ -55,7 +55,6 @@ import org.powermock.reflect.Whitebox;
|
|||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.Settings;
|
||||
import world.bentobox.bentobox.api.flags.Flag.Mode;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.AbstractDatabaseHandler;
|
||||
import world.bentobox.bentobox.database.Database;
|
||||
|
@ -278,16 +277,6 @@ public class PlayersManagerTest {
|
|||
assertEquals(deaths + 1, pm.getDeaths(world, uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.PlayersManager#addPlayer(java.util.UUID)}.
|
||||
*/
|
||||
@Test
|
||||
public void testAddPlayer() {
|
||||
pm.addPlayer(uuid);
|
||||
assertTrue(pm.isKnown(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.PlayersManager#addReset(org.bukkit.World, java.util.UUID)}.
|
||||
|
@ -382,15 +371,6 @@ public class PlayersManagerTest {
|
|||
assertEquals(0, pm.getDeaths(world, uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.PlayersManager#getFlagsDisplayMode(java.util.UUID)}.
|
||||
*/
|
||||
@Test
|
||||
public void testGetFlagsDisplayMode() {
|
||||
assertEquals(Mode.BASIC, pm.getFlagsDisplayMode(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.PlayersManager#getLocale(java.util.UUID)}.
|
||||
|
@ -452,7 +432,7 @@ public class PlayersManagerTest {
|
|||
public void testGetSetResetsLeft() throws InstantiationException, IllegalAccessException, InvocationTargetException,
|
||||
ClassNotFoundException, NoSuchMethodException, IntrospectionException {
|
||||
// Add a player
|
||||
pm.addPlayer(uuid);
|
||||
pm.getPlayer(uuid);
|
||||
assertEquals(0, pm.getResets(world, uuid));
|
||||
pm.setResets(world, uuid, 20);
|
||||
assertEquals(20, pm.getResets(world, uuid));
|
||||
|
@ -473,7 +453,7 @@ public class PlayersManagerTest {
|
|||
ClassNotFoundException, NoSuchMethodException, IntrospectionException {
|
||||
User user = pm.getUser("random");
|
||||
assertNull(user);
|
||||
pm.addPlayer(uuid);
|
||||
pm.getPlayer(uuid);
|
||||
user = pm.getUser("tastybento");
|
||||
assertEquals("tastybento", user.getName());
|
||||
}
|
||||
|
@ -494,7 +474,7 @@ public class PlayersManagerTest {
|
|||
*/
|
||||
@Test
|
||||
public void testGetUUID() {
|
||||
pm.addPlayer(uuid);
|
||||
pm.getPlayer(uuid);
|
||||
assertEquals(uuid, pm.getUUID("tastybento"));
|
||||
assertNull(pm.getUUID("unknown"));
|
||||
}
|
||||
|
@ -507,7 +487,7 @@ public class PlayersManagerTest {
|
|||
public void testGetUUIDOfflinePlayer() {
|
||||
pm.setHandler(db);
|
||||
// Add a player to the cache
|
||||
pm.addPlayer(uuid);
|
||||
pm.getPlayer(uuid);
|
||||
UUID uuidResult = pm.getUUID("tastybento");
|
||||
assertEquals(uuid, uuidResult);
|
||||
}
|
||||
|
@ -520,7 +500,7 @@ public class PlayersManagerTest {
|
|||
public void testGetUUIDUnknownPlayer() {
|
||||
pm.setHandler(db);
|
||||
// Add a player to the cache
|
||||
pm.addPlayer(uuid);
|
||||
pm.getPlayer(uuid);
|
||||
// Unknown player should return null
|
||||
assertNull(pm.getUUID("tastybento123"));
|
||||
}
|
||||
|
@ -550,8 +530,8 @@ public class PlayersManagerTest {
|
|||
@Test
|
||||
public void testIsKnown() {
|
||||
|
||||
pm.addPlayer(uuid);
|
||||
pm.addPlayer(notUUID);
|
||||
pm.getPlayer(uuid);
|
||||
pm.getPlayer(notUUID);
|
||||
|
||||
assertFalse(pm.isKnown(null));
|
||||
assertTrue(pm.isKnown(uuid));
|
||||
|
@ -560,21 +540,11 @@ public class PlayersManagerTest {
|
|||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.PlayersManager#isSaveTaskRunning()}.
|
||||
* {@link world.bentobox.bentobox.managers.PlayersManager#setHandler(Database)}
|
||||
*/
|
||||
@Test
|
||||
public void testIsSaveTaskRunning() {
|
||||
assertFalse(pm.isSaveTaskRunning());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.PlayersManager#load()}.
|
||||
*/
|
||||
@Test
|
||||
public void testLoad() {
|
||||
public void testSetHandler() {
|
||||
pm.setHandler(db);
|
||||
pm.load();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -617,7 +587,7 @@ public class PlayersManagerTest {
|
|||
public void testSetandGetPlayerName() {
|
||||
pm.setHandler(db);
|
||||
// Add a player
|
||||
pm.addPlayer(uuid);
|
||||
pm.getPlayer(uuid);
|
||||
assertEquals("tastybento", pm.getName(user.getUniqueId()));
|
||||
pm.setPlayerName(user);
|
||||
assertEquals(user.getName(), pm.getName(user.getUniqueId()));
|
||||
|
@ -634,16 +604,6 @@ public class PlayersManagerTest {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.PlayersManager#setFlagsDisplayMode(java.util.UUID, world.bentobox.bentobox.api.flags.Flag.Mode)}.
|
||||
*/
|
||||
@Test
|
||||
public void testSetFlagsDisplayMode() {
|
||||
pm.setFlagsDisplayMode(uuid, Mode.ADVANCED);
|
||||
assertEquals(Mode.ADVANCED, pm.getFlagsDisplayMode(uuid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link world.bentobox.bentobox.managers.PlayersManager#setInTeleport(java.util.UUID)}.
|
||||
|
|
Loading…
Reference in New Issue