Merge pull request #2347 from BentoBoxWorld/mp_debug_sesh

Mp debug sesh
This commit is contained in:
tastybento 2024-04-28 09:55:36 -07:00 committed by GitHub
commit 7477b8049f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
29 changed files with 131 additions and 334 deletions

View File

@ -59,7 +59,6 @@ public class BStats {
registerGameModeAddonsChart(); registerGameModeAddonsChart();
registerHooksChart(); registerHooksChart();
registerPlayersPerServerChart(); registerPlayersPerServerChart();
registerFlagsDisplayModeChart();
// Single Line charts // Single Line charts
registerIslandsCountChart(); 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. * Sends the enabled addons (except GameModeAddons) of this server as bar chart.
* @since 1.17.1 * @since 1.17.1

View File

@ -419,7 +419,7 @@ public class BentoBox extends JavaPlugin implements Listener {
* @return the ranksManager * @return the ranksManager
* @deprecated Just use {@code RanksManager.getInstance()} * @deprecated Just use {@code RanksManager.getInstance()}
*/ */
@Deprecated(since = "2.0.0") @Deprecated(since = "2.0.0", forRemoval = true)
public RanksManager getRanksManager() { public RanksManager getRanksManager() {
return RanksManager.getInstance(); return RanksManager.getInstance();
} }

View File

@ -21,6 +21,8 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import com.github.puregero.multilib.MultiLib;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.request.AddonRequestHandler; import world.bentobox.bentobox.api.addons.request.AddonRequestHandler;
import world.bentobox.bentobox.api.flags.Flag; import world.bentobox.bentobox.api.flags.Flag;
@ -45,6 +47,8 @@ public abstract class Addon {
protected Addon() { protected Addon() {
state = State.DISABLED; state = State.DISABLED;
// If the config is updated, update the config.
MultiLib.onString(getPlugin(), "bentobox-config-update", v -> this.reloadConfig());
} }
/** /**

View File

@ -8,6 +8,8 @@ import org.bukkit.generator.ChunkGenerator;
import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import com.github.puregero.multilib.MultiLib;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.configuration.WorldSettings; import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
@ -129,7 +131,10 @@ public abstract class GameModeAddon extends Addon {
* in-game and need to be saved. * in-game and need to be saved.
* @since 1.4.0 * @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 * Defines if the game mode uses the latest {@link ChunkGenerator} API or

View File

@ -16,7 +16,6 @@ import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.api.addons.GameModeAddon; import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.flags.Flag; 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.flags.Flag.Type;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.panels.builders.TabbedPanelBuilder; import world.bentobox.bentobox.api.panels.builders.TabbedPanelBuilder;
@ -206,11 +205,9 @@ public class AdminSettingsCommand extends CompositeCommand {
switch (f.getType()) { switch (f.getType()) {
case PROTECTION -> { case PROTECTION -> {
island.setFlag(f, rank); island.setFlag(f, rank);
getIslands().updateIsland(island);
} }
case SETTING -> { case SETTING -> {
island.setSettingsFlag(f, activeState); island.setSettingsFlag(f, activeState);
getIslands().updateIsland(island);
} }
case WORLD_SETTING -> f.setSetting(getWorld(), activeState); case WORLD_SETTING -> f.setSetting(getWorld(), activeState);
default -> { default -> {
@ -226,12 +223,11 @@ public class AdminSettingsCommand extends CompositeCommand {
user.sendMessage("general.errors.use-in-game"); user.sendMessage("general.errors.use-in-game");
return false; return false;
} }
getPlayers().setFlagsDisplayMode(user.getUniqueId(), Mode.EXPERT);
if (args.isEmpty()) { if (args.isEmpty()) {
new TabbedPanelBuilder() new TabbedPanelBuilder()
.user(user) .user(user)
.world(getWorld()) .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)) .tab(2, new WorldDefaultSettingsTab(getWorld(), user))
.startingSlot(1) .startingSlot(1)
.size(54) .size(54)
@ -242,8 +238,8 @@ public class AdminSettingsCommand extends CompositeCommand {
new TabbedPanelBuilder() new TabbedPanelBuilder()
.user(user) .user(user)
.world(island.getWorld()) .world(island.getWorld())
.island(island).tab(1, new SettingsTab(user, Flag.Type.PROTECTION)) .island(island).tab(1, new SettingsTab(getWorld(), user, Flag.Type.PROTECTION, Flag.Mode.EXPERT))
.tab(2, new SettingsTab(user, Flag.Type.SETTING)) .tab(2, new SettingsTab(getWorld(), user, Flag.Type.SETTING, Flag.Mode.EXPERT))
.startingSlot(1) .startingSlot(1)
.size(54) .size(54)
.build().openPanel(); .build().openPanel();

View File

@ -116,7 +116,6 @@ public class AdminUnregisterCommand extends ConfirmableCommand {
targetIsland.getMembers().clear(); targetIsland.getMembers().clear();
targetIsland.log(new LogEntry.Builder("UNREGISTER").data("player", targetUUID.toString()) targetIsland.log(new LogEntry.Builder("UNREGISTER").data("player", targetUUID.toString())
.data("admin", user.getUniqueId().toString()).build()); .data("admin", user.getUniqueId().toString()).build());
getIslands().updateIsland(targetIsland);
user.sendMessage("commands.admin.unregister.unregistered-island", TextVariables.XYZ, Util.xyz(targetIsland.getCenter().toVector()), user.sendMessage("commands.admin.unregister.unregistered-island", TextVariables.XYZ, Util.xyz(targetIsland.getCenter().toVector()),
TextVariables.NAME, getPlayers().getName(targetUUID)); TextVariables.NAME, getPlayers().getName(targetUUID));
} }

View File

@ -40,7 +40,6 @@ public class NamePrompt extends StringPrompt {
@Override @Override
public Prompt acceptInput(@NonNull ConversationContext context, String input) { public Prompt acceptInput(@NonNull ConversationContext context, String input) {
if (island.renameHome(oldName, input)) { if (island.renameHome(oldName, input)) {
plugin.getIslands().updateIsland(island);
Bukkit.getScheduler().runTask(plugin, () -> user.sendMessage("general.success")); Bukkit.getScheduler().runTask(plugin, () -> user.sendMessage("general.success"));
} else { } else {
Bukkit.getScheduler().runTask(plugin, () -> user.sendMessage("commands.island.renamehome.already-exists")); Bukkit.getScheduler().runTask(plugin, () -> user.sendMessage("commands.island.renamehome.already-exists"));

View File

@ -49,7 +49,8 @@ public class IslandSettingsCommand extends CompositeCommand {
.user(user) .user(user)
.island(island) .island(island)
.world(island.getWorld()) .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) .startingSlot(1)
.size(54) .size(54)
.hideIfEmpty() .hideIfEmpty()

View File

@ -197,7 +197,6 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", TextVariables.NAME, inviter.sendMessage("commands.island.team.invite.accept.name-joined-your-island", TextVariables.NAME,
user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName()); user.getName(), TextVariables.DISPLAY_NAME, user.getDisplayName());
} }
//IslandsManager.updateIsland(teamIsland);
// Fire event // Fire event
TeamEvent.builder().island(teamIsland).reason(TeamEvent.Reason.JOINED).involvedPlayer(user.getUniqueId()) TeamEvent.builder().island(teamIsland).reason(TeamEvent.Reason.JOINED).involvedPlayer(user.getUniqueId())
.build(); .build();

View File

@ -92,7 +92,6 @@ public class IslandTeamSetownerCommand extends CompositeCommand {
IslandEvent.builder().island(island).involvedPlayer(user.getUniqueId()).admin(false) IslandEvent.builder().island(island).involvedPlayer(user.getUniqueId()).admin(false)
.reason(IslandEvent.Reason.RANK_CHANGE).rankChange(RanksManager.OWNER_RANK, RanksManager.SUB_OWNER_RANK) .reason(IslandEvent.Reason.RANK_CHANGE).rankChange(RanksManager.OWNER_RANK, RanksManager.SUB_OWNER_RANK)
.build(); .build();
IslandsManager.updateIsland(island);
return true; return true;
} }

View File

@ -388,21 +388,24 @@ public class Flag implements Comparable<Flag> {
if (!user.isOp() && invisible) { if (!user.isOp() && invisible) {
return null; return null;
} }
// Start the flag conversion
PanelItemBuilder pib = new PanelItemBuilder() PanelItemBuilder pib = new PanelItemBuilder()
.icon(ItemParser.parse(user.getTranslationOrNothing(this.getIconReference()), new ItemStack(icon))) .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) .clickHandler(clickHandler)
.invisible(invisible); .invisible(invisible);
if (hasSubPanel()) { if (hasSubPanel()) {
pib.description(user.getTranslation("protection.panel.flag-item.menu-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference()))); pib.description(user.getTranslation("protection.panel.flag-item.menu-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())));
return pib.build(); return pib.build();
} }
return switch (getType()) { return switch (getType()) {
case PROTECTION -> createProtectionFlag(plugin, user, island, pib).build(); case PROTECTION -> createProtectionFlag(plugin, user, island, pib).build();
case SETTING -> createSettingFlag(user, island, pib).build(); case SETTING -> createSettingFlag(user, island, pib).build();
case WORLD_SETTING -> createWorldSettingFlag(user, world, pib).build(); case WORLD_SETTING -> createWorldSettingFlag(user, world, pib).build();
}; };
} }
private PanelItemBuilder createWorldSettingFlag(User user, World world, PanelItemBuilder pib) { 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) { private PanelItemBuilder createProtectionFlag(BentoBox plugin, User user, Island island, PanelItemBuilder pib) {
if (island != null) { if (island != null) {
int y = island.getFlag(this);
// Protection flag // Protection flag
pib.description(user.getTranslation("protection.panel.flag-item.description-layout", pib.description(user.getTranslation("protection.panel.flag-item.description-layout",
TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference()))); TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())));
RanksManager.getInstance().getRanks().forEach((reference, score) -> { 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)); 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)); 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)); pib.description(user.getTranslation("protection.panel.flag-item.minimal-rank") + user.getTranslation(reference));
} }
}); });
} }
return pib; return pib;
} }
@ -469,7 +477,7 @@ public class Flag implements Comparable<Flag> {
public Set<Flag> getSubflags() { public Set<Flag> getSubflags() {
return subflags; 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 * 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. * 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) { public boolean setTranslatedName(Locale locale, String name) {
return BentoBox.getInstance().getLocalesManager().setTranslation(locale, getNameReference(), 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 * 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. * and must be rewritten using this call every time the flag is built.

View File

@ -74,6 +74,7 @@ public class TabbedPanel extends Panel implements PanelListener {
* @param page - the page of the tab to show (if multi paged) * @param page - the page of the tab to show (if multi paged)
*/ */
public void openPanel(int activeTab, int page) { public void openPanel(int activeTab, int page) {
if (!tpb.getTabs().containsKey(activeTab)) { if (!tpb.getTabs().containsKey(activeTab)) {
// Request to open a non-existent tab // Request to open a non-existent tab
throw new InvalidParameterException("Attempt to open a non-existent tab in a tabbed panel. Missing tab #" + activeTab); 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<>(); TreeMap<Integer, PanelItem> items = new TreeMap<>();
// Get the tab // Get the tab
Tab tab = tpb.getTabs().get(activeTab); Tab tab = tpb.getTabs().get(activeTab);
// Remove any tabs that have no items, if required // Remove any tabs that have no items, if required
if (tpb.isHideIfEmpty()) { if (tpb.isHideIfEmpty()) {
tpb.getTabs().values().removeIf(t -> !t.equals(tab) && t.getPanelItems().stream().noneMatch(Objects::nonNull)); tpb.getTabs().values().removeIf(t -> !t.equals(tab) && t.getPanelItems().stream().noneMatch(Objects::nonNull));
} }
// Set up the tabbed header // Set up the tabbed header
setupHeader(tab, items); setupHeader(tab, items);
// Show the active tab // Show the active tab
if (tpb.getTabs().containsKey(activeTab)) { if (tpb.getTabs().containsKey(activeTab)) {
List<PanelItem> panelItems = tab.getPanelItems(); List<PanelItem> panelItems = tab.getPanelItems();
// Adds the flag items // 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)); 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 // set up the footer
setupFooter(items); setupFooter(items);
// Add forward and backward icons // Add forward and backward icons
@ -182,6 +179,7 @@ public class TabbedPanel extends Panel implements PanelListener {
// Reset the closed flag // Reset the closed flag
closed = false; closed = false;
} }
} }
/** /**

View File

@ -6,13 +6,10 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.eclipse.jdt.annotation.Nullable;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
@ -30,8 +27,6 @@ import world.bentobox.bentobox.util.Util;
*/ */
@Table(name = "Players") @Table(name = "Players")
public class Players implements DataObject, MetaDataAble { public class Players implements DataObject, MetaDataAble {
@Expose
private Map<Location, Integer> homeLocations = new HashMap<>();
@Expose @Expose
private String uniqueId; private String uniqueId;
@Expose @Expose
@ -77,7 +72,6 @@ public class Players implements DataObject, MetaDataAble {
*/ */
public Players(BentoBox plugin, UUID uniqueId) { public Players(BentoBox plugin, UUID uniqueId) {
this.uniqueId = uniqueId.toString(); this.uniqueId = uniqueId.toString();
homeLocations = new HashMap<>();
locale = ""; locale = "";
// Try to get player's name // Try to get player's name
this.playerName = Bukkit.getOfflinePlayer(uniqueId).getName(); 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 * @param playerName the playerName to set
*/ */
@ -202,30 +130,6 @@ public class Players implements DataObject, MetaDataAble {
this.resets.put(world.getName(), resets); 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 * Set the uuid for this player object
* @param uuid - UUID * @param uuid - UUID
@ -234,16 +138,6 @@ public class Players implements DataObject, MetaDataAble {
uniqueId = uuid.toString(); 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 * @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 * @return the metaData
* @since 1.15.5 * @since 1.15.5

View File

@ -62,7 +62,7 @@ public class JoinLeaveListener implements Listener {
// Make sure the player is loaded into the cache or create the player if they // Make sure the player is loaded into the cache or create the player if they
// don't exist // don't exist
players.addPlayer(playerUUID); players.getPlayer(playerUUID);
// Reset island resets if required // Reset island resets if required
plugin.getIWM().getOverWorlds().stream() plugin.getIWM().getOverWorlds().stream()
@ -110,7 +110,7 @@ public class JoinLeaveListener implements Listener {
private void firstTime(User user) { private void firstTime(User user) {
// Make sure the player is loaded into the cache or create the player if they // Make sure the player is loaded into the cache or create the player if they
// don't exist // don't exist
players.addPlayer(user.getUniqueId()); players.getPlayer(user.getUniqueId());
plugin.getIWM().getOverWorlds().stream().filter(w -> plugin.getIWM().isCreateIslandOnFirstLoginEnabled(w)) plugin.getIWM().getOverWorlds().stream().filter(w -> plugin.getIWM().isCreateIslandOnFirstLoginEnabled(w))
.forEach(w -> { .forEach(w -> {

View File

@ -61,6 +61,7 @@ public class PanelListenerManager implements Listener {
// Refresh // Refresh
l.refreshPanel(); l.refreshPanel();
}); });
} else { } else {
// Wrong name - delete this panel // Wrong name - delete this panel
openPanels.remove(user.getUniqueId()); openPanels.remove(user.getUniqueId());

View File

@ -60,9 +60,6 @@ public class CommandCycleClick implements ClickHandler {
} }
// Apply change to panel // Apply change to panel
panel.getInventory().setItem(slot, commandRankClickListener.getPanelItem(command, user, world).getItem()); panel.getInventory().setItem(slot, commandRankClickListener.getPanelItem(command, user, world).getItem());
// Save island
plugin.getIslands().updateIsland(island);
} else { } else {
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F); user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
} }

View File

@ -108,7 +108,6 @@ public class IslandsManager {
// Listen for Island Updates // Listen for Island Updates
MultiLib.onString(plugin, "bentobox-updateIsland", id -> { MultiLib.onString(plugin, "bentobox-updateIsland", id -> {
BentoBox.getInstance().logDebug("Updating island " + id);
Island island = handler.loadObject(id); Island island = handler.loadObject(id);
if (island != null) { if (island != null) {
islandCache.updateIsland(island); islandCache.updateIsland(island);
@ -117,13 +116,11 @@ public class IslandsManager {
// Delete island blocks // Delete island blocks
MultiLib.onString(plugin, "bentobox-deleteIsland", id -> { MultiLib.onString(plugin, "bentobox-deleteIsland", id -> {
BentoBox.getInstance().logDebug("Delete island blocks");
IslandDeletion idd = getGson().fromJson(id, IslandDeletion.class); IslandDeletion idd = getGson().fromJson(id, IslandDeletion.class);
plugin.getIslandDeletionManager().getIslandChunkDeletionManager().add(idd); plugin.getIslandDeletionManager().getIslandChunkDeletionManager().add(idd);
}); });
// List for new islands // List for new islands
MultiLib.onString(plugin, "bentobox-newIsland", id -> { MultiLib.onString(plugin, "bentobox-newIsland", id -> {
BentoBox.getInstance().logDebug("New island " + id);
Island island = handler.loadObject(id); Island island = handler.loadObject(id);
if (island != null) { if (island != null) {
islandCache.addIsland(island); islandCache.addIsland(island);
@ -139,7 +136,6 @@ public class IslandsManager {
World world = Bukkit.getWorld(split[0]); World world = Bukkit.getWorld(split[0]);
if (world != null) { if (world != null) {
getIslandById(split[1]).ifPresent(i -> this.setSpawn(i)); 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 * @param involvedPlayer - player related to the island deletion, if any
*/ */
public void deleteIsland(@NonNull Island island, boolean removeBlocks, @Nullable UUID involvedPlayer) { public void deleteIsland(@NonNull Island island, boolean removeBlocks, @Nullable UUID involvedPlayer) {
BentoBox.getInstance().logDebug("Deleting island " + island.getUniqueId() + " remove blocks = " + removeBlocks);
// Fire event // Fire event
IslandBaseEvent event = IslandEvent.builder().island(island).involvedPlayer(involvedPlayer) IslandBaseEvent event = IslandEvent.builder().island(island).involvedPlayer(involvedPlayer)
.reason(Reason.DELETE).build(); .reason(Reason.DELETE).build();

View File

@ -2,7 +2,9 @@ package world.bentobox.bentobox.managers;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -14,7 +16,6 @@ import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.Database; import world.bentobox.bentobox.database.Database;
import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.database.objects.Island;
@ -27,11 +28,10 @@ public class PlayersManager {
private final BentoBox plugin; private final BentoBox plugin;
private Database<Players> handler; private Database<Players> handler;
private final Database<Names> names; private final Database<Names> names;
private final Map<UUID, Players> playerCache = new HashMap<>();
private final Set<UUID> inTeleport; // this needs databasing private final Set<UUID> inTeleport; // this needs databasing
private boolean isSaveTaskRunning;
/** /**
* Provides a memory cache of online player information * Provides a memory cache of online player information
* This is the one-stop-shop of player info * This is the one-stop-shop of player info
@ -56,17 +56,6 @@ public class PlayersManager {
this.handler = handler; 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(){ public void shutdown(){
handler.close(); handler.close();
} }
@ -78,28 +67,17 @@ public class PlayersManager {
*/ */
@Nullable @Nullable
public Players getPlayer(UUID uuid){ 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 * Adds a player to the database. If the UUID does not exist, a new player is made
* @param playerUUID - the player's UUID * @param playerUUID - the player's UUID
*/ */
public Players addPlayer(@NonNull UUID playerUUID) { private Players addPlayer(@NonNull UUID playerUUID) {
Objects.requireNonNull(playerUUID); Objects.requireNonNull(playerUUID);
// If the player is in the database, load it, otherwise create a new player // If the player is in the database, load it, otherwise create a new player
if (handler.objectExists(playerUUID.toString())) { if (handler.objectExists(playerUUID.toString())) {
@ -113,6 +91,16 @@ public class PlayersManager {
return player; 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. * Checks if the player is known or not.
* Will check not just the cache but if the object but in the database too. * 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 * @param user - the User
*/ */
public void setPlayerName(@NonNull User user) { public void setPlayerName(@NonNull User user) {
Players player = addPlayer(user.getUniqueId()); Players player = getPlayer(user.getUniqueId());
player.setPlayerName(user.getName()); player.setPlayerName(user.getName());
handler.saveObject(player); handler.saveObject(player);
Names newName = new Names(user.getName(), user.getUniqueId()); Names newName = new Names(user.getName(), user.getUniqueId());
@ -180,7 +168,7 @@ public class PlayersManager {
* @return number of resets * @return number of resets
*/ */
public int getResets(World world, UUID playerUUID) { 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) * @see #getResets(World, UUID)
*/ */
public int getResetsLeft(World world, UUID playerUUID) { public int getResetsLeft(World world, UUID playerUUID) {
addPlayer(playerUUID); getPlayer(playerUUID);
if (plugin.getIWM().getResetLimit(world) == -1) { if (plugin.getIWM().getResetLimit(world) == -1) {
return -1; return -1;
} else { } else {
@ -208,7 +196,7 @@ public class PlayersManager {
* @param resets number of resets to set * @param resets number of resets to set
*/ */
public void setResets(World world, UUID playerUUID, int resets) { public void setResets(World world, UUID playerUUID, int resets) {
Players p = addPlayer(playerUUID); Players p = getPlayer(playerUUID);
p.setResets(world, resets); p.setResets(world, resets);
handler.saveObject(p); handler.saveObject(p);
} }
@ -219,7 +207,7 @@ public class PlayersManager {
* @return name of the locale this player uses * @return name of the locale this player uses
*/ */
public String getLocale(UUID playerUUID) { 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 * @param localeName - locale name, e.g., en-US
*/ */
public void setLocale(UUID playerUUID, String localeName) { public void setLocale(UUID playerUUID, String localeName) {
Players p = addPlayer(playerUUID); Players p = getPlayer(playerUUID);
p.setLocale(localeName); p.setLocale(localeName);
handler.saveObject(p); handler.saveObject(p);
} }
@ -239,7 +227,7 @@ public class PlayersManager {
* @param playerUUID - the player's UUID * @param playerUUID - the player's UUID
*/ */
public void addDeath(World world, UUID playerUUID) { public void addDeath(World world, UUID playerUUID) {
Players p = addPlayer(playerUUID); Players p = getPlayer(playerUUID);
p.addDeath(world); p.addDeath(world);
handler.saveObject(p); handler.saveObject(p);
} }
@ -251,7 +239,7 @@ public class PlayersManager {
* @param deaths - number of deaths * @param deaths - number of deaths
*/ */
public void setDeaths(World world, UUID playerUUID, int deaths) { public void setDeaths(World world, UUID playerUUID, int deaths) {
Players p = addPlayer(playerUUID); Players p = getPlayer(playerUUID);
p.setDeaths(world, deaths); p.setDeaths(world, deaths);
handler.saveObject(p); handler.saveObject(p);
} }
@ -263,7 +251,7 @@ public class PlayersManager {
* @return number of deaths * @return number of deaths
*/ */
public int getDeaths(World world, UUID playerUUID) { 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 * @param playerUUID player's UUID
*/ */
public void addReset(World world, UUID playerUUID) { public void addReset(World world, UUID playerUUID) {
Players p = addPlayer(playerUUID); Players p = getPlayer(playerUUID);
p.addReset(world); p.addReset(world);
handler.saveObject(p); 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 * Remove player from database
* @param player player to remove * @param player player to remove

View File

@ -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) { public void compareIslands(Island island1, Island island2) {
if (island1 == null || island2 == null) { if (island1 == null || island2 == null) {
BentoBox.getInstance().logDebug("One or both islands are null. Cannot compare."); BentoBox.getInstance().logDebug("One or both islands are null. Cannot compare.");

View File

@ -4,6 +4,7 @@ import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -16,6 +17,7 @@ import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.flags.Flag; 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.flags.Flag.Type;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.panels.Panel; import world.bentobox.bentobox.api.panels.Panel;
@ -46,16 +48,7 @@ public class SettingsTab implements Tab, ClickHandler {
protected Island island; protected Island island;
protected TabbedPanel parent; protected TabbedPanel parent;
/** private Map<UUID, Flag.Mode> currentMode = new HashMap<>();
* 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.
}
/** /**
* Show a tab of settings * Show a tab of settings
@ -69,6 +62,21 @@ public class SettingsTab implements Tab, ClickHandler {
this.type = type; 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 * @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 // 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))); 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 // 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) || plugin.getIWM().getAddon(world).ifPresent(gm -> flags.removeIf(f -> f.getMode().isGreaterThan(mode) ||
f.getMode().equals(Flag.Mode.TOP_ROW))); f.getMode().equals(Flag.Mode.TOP_ROW)));
return flags; return flags;
@ -120,13 +128,14 @@ public class SettingsTab implements Tab, ClickHandler {
int i = 0; int i = 0;
// Jump past empty tabs // Jump past empty tabs
while (flags.isEmpty() && i++ < Flag.Mode.values().length) { 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(); flags = getFlags();
} }
return flags.stream().map( List<@Nullable PanelItem> result = flags.stream().map(
(f -> f.toPanelItem(plugin, user, world, island, (f -> f.toPanelItem(plugin, user, world, island,
plugin.getIWM().getHiddenFlags(world).contains(f.getID())))) plugin.getIWM().getHiddenFlags(world).contains(f.getID()))))
.toList(); .toList();
return result;
} }
@Override @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(4, Flags.CHANGE_SETTINGS.toPanelItem(plugin, user, world, island, false));
icons.put(5, Flags.LOCK.toPanelItem(plugin, user, world, island, false)); icons.put(5, Flags.LOCK.toPanelItem(plugin, user, world, island, false));
} }
// Add the mode icon // 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) case ADVANCED -> icons.put(7, new PanelItemBuilder().icon(Material.GOLD_INGOT)
.name(user.getTranslation(PROTECTION_PANEL + "mode.advanced.name")) .name(user.getTranslation(PROTECTION_PANEL + "mode.advanced.name"))
.description(user.getTranslation(PROTECTION_PANEL + "mode.advanced.description"), "", .description(user.getTranslation(PROTECTION_PANEL + "mode.advanced.description"), "",
@ -161,7 +171,8 @@ public class SettingsTab implements Tab, ClickHandler {
.clickHandler(this) .clickHandler(this)
.build()); .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())) { if (island != null && user.getUniqueId().equals(island.getOwner())) {
icons.put(8, new PanelItemBuilder().icon(Material.TNT) icons.put(8, new PanelItemBuilder().icon(Material.TNT)
.name(user.getTranslation(PROTECTION_PANEL + "reset-to-default.name")) .name(user.getTranslation(PROTECTION_PANEL + "reset-to-default.name"))
@ -216,7 +227,7 @@ public class SettingsTab implements Tab, ClickHandler {
@Override @Override
public boolean onClick(Panel panel, User user, ClickType clickType, int slot) { public boolean onClick(Panel panel, User user, ClickType clickType, int slot) {
// Cycle the mode // 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) { if (panel instanceof TabbedPanel tp) {
tp.setActivePage(0); tp.setActivePage(0);
tp.refreshPanel(); tp.refreshPanel();

View File

@ -7,6 +7,7 @@ import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.eclipse.jdt.annotation.NonNull; 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.Flag.Type;
import world.bentobox.bentobox.api.flags.clicklisteners.WorldToggleClick; import world.bentobox.bentobox.api.flags.clicklisteners.WorldToggleClick;
import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.localization.TextVariables;

View File

@ -32,10 +32,13 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox; import org.powermock.reflect.Whitebox;
import com.github.puregero.multilib.MultiLib;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.exceptions.InvalidAddonDescriptionException; import world.bentobox.bentobox.api.addons.exceptions.InvalidAddonDescriptionException;
import world.bentobox.bentobox.managers.AddonsManager; import world.bentobox.bentobox.managers.AddonsManager;
@ -46,7 +49,7 @@ import world.bentobox.bentobox.managers.AddonsManager;
* *
*/ */
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest( { BentoBox.class, Bukkit.class }) @PrepareForTest({ BentoBox.class, Bukkit.class, MultiLib.class })
public class AddonClassLoaderTest { public class AddonClassLoaderTest {
private enum mandatoryTags { private enum mandatoryTags {
@ -80,6 +83,7 @@ public class AddonClassLoaderTest {
*/ */
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
PowerMockito.mockStatic(MultiLib.class, Mockito.RETURNS_MOCKS);
// Set up plugin // Set up plugin
plugin = mock(BentoBox.class); plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin); Whitebox.setInternalState(BentoBox.class, "instance", plugin);

View File

@ -44,13 +44,15 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox; import org.powermock.reflect.Whitebox;
import com.github.puregero.multilib.MultiLib;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.managers.AddonsManager; import world.bentobox.bentobox.managers.AddonsManager;
import world.bentobox.bentobox.managers.IslandsManager; import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.PlayersManager; import world.bentobox.bentobox.managers.PlayersManager;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest( { BentoBox.class, Bukkit.class }) @PrepareForTest({ BentoBox.class, Bukkit.class, MultiLib.class })
public class AddonTest { public class AddonTest {
public static int BUFFER_SIZE = 10240; public static int BUFFER_SIZE = 10240;
@ -90,6 +92,8 @@ public class AddonTest {
// Addons manager // Addons manager
when(plugin.getAddonsManager()).thenReturn(am); when(plugin.getAddonsManager()).thenReturn(am);
// MultiLib
PowerMockito.mockStatic(MultiLib.class, Mockito.RETURNS_MOCKS);
// Mock item factory (for itemstacks) // Mock item factory (for itemstacks)
ItemFactory itemFactory = mock(ItemFactory.class); ItemFactory itemFactory = mock(ItemFactory.class);

View File

@ -144,7 +144,6 @@ public class AdminSettingsCommandTest extends RanksManagerBeforeClassTest {
when(plugin.getIWM()).thenReturn(iwm); when(plugin.getIWM()).thenReturn(iwm);
// Players manager // Players manager
when(plugin.getPlayers()).thenReturn(pm); when(plugin.getPlayers()).thenReturn(pm);
when(pm.getFlagsDisplayMode(any())).thenReturn(Mode.BASIC);
//Island Manager //Island Manager
when(plugin.getIslands()).thenReturn(im); when(plugin.getIslands()).thenReturn(im);
// Island - player has island // Island - player has island
@ -267,16 +266,6 @@ public class AdminSettingsCommandTest extends RanksManagerBeforeClassTest {
verify(user).sendMessage("general.errors.use-in-game"); 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)}. * Test method for {@link world.bentobox.bentobox.api.commands.admin.AdminSettingsCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/ */

View File

@ -278,8 +278,6 @@ public class IslandTeamSetownerCommandTest {
assertTrue(its.canExecute(user, "", List.of("tastybento"))); assertTrue(its.canExecute(user, "", List.of("tastybento")));
assertTrue(its.execute(user, "", List.of("tastybento"))); assertTrue(its.execute(user, "", List.of("tastybento")));
verify(im).setOwner(any(), eq(user), eq(target)); 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.canExecute(user, "", List.of("tastybento")));
assertTrue(its.execute(user, "", List.of("tastybento"))); assertTrue(its.execute(user, "", List.of("tastybento")));
verify(im).setOwner(any(), eq(user), eq(target)); verify(im).setOwner(any(), eq(user), eq(target));
PowerMockito.verifyStatic(IslandsManager.class);
IslandsManager.updateIsland(island);
} }
/** /**

View File

@ -220,8 +220,6 @@ public class JoinLeaveListenerTest {
jll = new JoinLeaveListener(plugin); jll = new JoinLeaveListener(plugin);
} }
/**
*/
@After @After
public void tearDown() { public void tearDown() {
User.clearUsers(); User.clearUsers();
@ -237,7 +235,7 @@ public class JoinLeaveListenerTest {
PlayerJoinEvent event = new PlayerJoinEvent(player, ""); PlayerJoinEvent event = new PlayerJoinEvent(player, "");
jll.onPlayerJoin(event); jll.onPlayerJoin(event);
// Verify // Verify
verify(pm, times(2)).addPlayer(any()); verify(pm, times(3)).getPlayer(any());
verify(player, never()).sendMessage(anyString()); verify(player, never()).sendMessage(anyString());
// Verify resets // Verify resets
verify(pm).setResets(eq(world), any(), eq(0)); verify(pm).setResets(eq(world), any(), eq(0));
@ -354,7 +352,7 @@ public class JoinLeaveListenerTest {
PlayerJoinEvent event = new PlayerJoinEvent(player, ""); PlayerJoinEvent event = new PlayerJoinEvent(player, "");
jll.onPlayerJoin(event); jll.onPlayerJoin(event);
// Verify // Verify
verify(pm, times(2)).addPlayer(any()); verify(pm, times(3)).getPlayer(any());
verify(player).sendMessage(eq("commands.island.create.on-first-login")); verify(player).sendMessage(eq("commands.island.create.on-first-login"));
} }

View File

@ -37,6 +37,8 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox; import org.powermock.reflect.Whitebox;
import com.github.puregero.multilib.MultiLib;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.Settings;
import world.bentobox.bentobox.api.addons.Addon; 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; import world.bentobox.bentobox.database.objects.DataObject;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest( {Bukkit.class, BentoBox.class, DefaultPermissions.class} ) @PrepareForTest({ Bukkit.class, BentoBox.class, DefaultPermissions.class, MultiLib.class })
public class AddonsManagerTest { public class AddonsManagerTest {
private BentoBox plugin; private BentoBox plugin;
@ -81,6 +83,8 @@ public class AddonsManagerTest {
when(plugin.getSettings()).thenReturn(s); when(plugin.getSettings()).thenReturn(s);
PowerMockito.mockStatic(DefaultPermissions.class); PowerMockito.mockStatic(DefaultPermissions.class);
PowerMockito.mockStatic(MultiLib.class, Mockito.RETURNS_MOCKS);
} }
/** /**

View File

@ -45,6 +45,8 @@ import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import com.github.puregero.multilib.MultiLib;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.Addon; import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.addons.AddonDescription; import world.bentobox.bentobox.api.addons.AddonDescription;
@ -62,7 +64,7 @@ import world.bentobox.bentobox.database.objects.Island;
* *
*/ */
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest( {Bukkit.class, BentoBox.class, BlueprintPaster.class} ) @PrepareForTest({ Bukkit.class, BentoBox.class, BlueprintPaster.class, MultiLib.class })
public class BlueprintsManagerTest { public class BlueprintsManagerTest {
public static int BUFFER_SIZE = 10240; public static int BUFFER_SIZE = 10240;
@ -95,10 +97,12 @@ public class BlueprintsManagerTest {
private int times; private int times;
@Mock @Mock
private Server server; private Server server;
/**
*/
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
// Multilib
PowerMockito.mockStatic(MultiLib.class, Mockito.RETURNS_MOCKS);
// Make the addon // Make the addon
dataFolder = new File("dataFolder"); dataFolder = new File("dataFolder");
jarFile = new File("addon.jar"); jarFile = new File("addon.jar");

View File

@ -55,7 +55,6 @@ import org.powermock.reflect.Whitebox;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.Settings; import world.bentobox.bentobox.Settings;
import world.bentobox.bentobox.api.flags.Flag.Mode;
import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.AbstractDatabaseHandler; import world.bentobox.bentobox.database.AbstractDatabaseHandler;
import world.bentobox.bentobox.database.Database; import world.bentobox.bentobox.database.Database;
@ -278,16 +277,6 @@ public class PlayersManagerTest {
assertEquals(deaths + 1, pm.getDeaths(world, uuid)); 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 * Test method for
* {@link world.bentobox.bentobox.managers.PlayersManager#addReset(org.bukkit.World, java.util.UUID)}. * {@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)); 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 * Test method for
* {@link world.bentobox.bentobox.managers.PlayersManager#getLocale(java.util.UUID)}. * {@link world.bentobox.bentobox.managers.PlayersManager#getLocale(java.util.UUID)}.
@ -452,7 +432,7 @@ public class PlayersManagerTest {
public void testGetSetResetsLeft() throws InstantiationException, IllegalAccessException, InvocationTargetException, public void testGetSetResetsLeft() throws InstantiationException, IllegalAccessException, InvocationTargetException,
ClassNotFoundException, NoSuchMethodException, IntrospectionException { ClassNotFoundException, NoSuchMethodException, IntrospectionException {
// Add a player // Add a player
pm.addPlayer(uuid); pm.getPlayer(uuid);
assertEquals(0, pm.getResets(world, uuid)); assertEquals(0, pm.getResets(world, uuid));
pm.setResets(world, uuid, 20); pm.setResets(world, uuid, 20);
assertEquals(20, pm.getResets(world, uuid)); assertEquals(20, pm.getResets(world, uuid));
@ -473,7 +453,7 @@ public class PlayersManagerTest {
ClassNotFoundException, NoSuchMethodException, IntrospectionException { ClassNotFoundException, NoSuchMethodException, IntrospectionException {
User user = pm.getUser("random"); User user = pm.getUser("random");
assertNull(user); assertNull(user);
pm.addPlayer(uuid); pm.getPlayer(uuid);
user = pm.getUser("tastybento"); user = pm.getUser("tastybento");
assertEquals("tastybento", user.getName()); assertEquals("tastybento", user.getName());
} }
@ -494,7 +474,7 @@ public class PlayersManagerTest {
*/ */
@Test @Test
public void testGetUUID() { public void testGetUUID() {
pm.addPlayer(uuid); pm.getPlayer(uuid);
assertEquals(uuid, pm.getUUID("tastybento")); assertEquals(uuid, pm.getUUID("tastybento"));
assertNull(pm.getUUID("unknown")); assertNull(pm.getUUID("unknown"));
} }
@ -507,7 +487,7 @@ public class PlayersManagerTest {
public void testGetUUIDOfflinePlayer() { public void testGetUUIDOfflinePlayer() {
pm.setHandler(db); pm.setHandler(db);
// Add a player to the cache // Add a player to the cache
pm.addPlayer(uuid); pm.getPlayer(uuid);
UUID uuidResult = pm.getUUID("tastybento"); UUID uuidResult = pm.getUUID("tastybento");
assertEquals(uuid, uuidResult); assertEquals(uuid, uuidResult);
} }
@ -520,7 +500,7 @@ public class PlayersManagerTest {
public void testGetUUIDUnknownPlayer() { public void testGetUUIDUnknownPlayer() {
pm.setHandler(db); pm.setHandler(db);
// Add a player to the cache // Add a player to the cache
pm.addPlayer(uuid); pm.getPlayer(uuid);
// Unknown player should return null // Unknown player should return null
assertNull(pm.getUUID("tastybento123")); assertNull(pm.getUUID("tastybento123"));
} }
@ -550,8 +530,8 @@ public class PlayersManagerTest {
@Test @Test
public void testIsKnown() { public void testIsKnown() {
pm.addPlayer(uuid); pm.getPlayer(uuid);
pm.addPlayer(notUUID); pm.getPlayer(notUUID);
assertFalse(pm.isKnown(null)); assertFalse(pm.isKnown(null));
assertTrue(pm.isKnown(uuid)); assertTrue(pm.isKnown(uuid));
@ -560,21 +540,11 @@ public class PlayersManagerTest {
/** /**
* Test method for * Test method for
* {@link world.bentobox.bentobox.managers.PlayersManager#isSaveTaskRunning()}. * {@link world.bentobox.bentobox.managers.PlayersManager#setHandler(Database)}
*/ */
@Test @Test
public void testIsSaveTaskRunning() { public void testSetHandler() {
assertFalse(pm.isSaveTaskRunning());
}
/**
* Test method for
* {@link world.bentobox.bentobox.managers.PlayersManager#load()}.
*/
@Test
public void testLoad() {
pm.setHandler(db); pm.setHandler(db);
pm.load();
} }
/** /**
@ -617,7 +587,7 @@ public class PlayersManagerTest {
public void testSetandGetPlayerName() { public void testSetandGetPlayerName() {
pm.setHandler(db); pm.setHandler(db);
// Add a player // Add a player
pm.addPlayer(uuid); pm.getPlayer(uuid);
assertEquals("tastybento", pm.getName(user.getUniqueId())); assertEquals("tastybento", pm.getName(user.getUniqueId()));
pm.setPlayerName(user); pm.setPlayerName(user);
assertEquals(user.getName(), pm.getName(user.getUniqueId())); 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 * Test method for
* {@link world.bentobox.bentobox.managers.PlayersManager#setInTeleport(java.util.UUID)}. * {@link world.bentobox.bentobox.managers.PlayersManager#setInTeleport(java.util.UUID)}.