Load of debug - trying to solve the settings slowness

This commit is contained in:
tastybento 2024-04-21 13:12:52 -07:00
parent 9b8540a8ed
commit fd12ef9fe7
20 changed files with 88 additions and 242 deletions

View File

@ -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

View File

@ -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());
}
/**
@ -220,6 +224,7 @@ public abstract class Addon {
* @since 1.13.0
*/
public void reloadConfig() {
BentoBox.getInstance().logDebug("Config reloaded");
config = loadYamlFile();
}

View File

@ -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

View File

@ -206,11 +206,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,7 +224,6 @@ 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)

View File

@ -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));
}

View File

@ -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"));

View File

@ -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();

View File

@ -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;
}

View File

@ -384,6 +384,7 @@ public class Flag implements Comparable<Flag> {
*/
@Nullable
public PanelItem toPanelItem(BentoBox plugin, User user, World world, @Nullable Island island, boolean invisible) {
long m = System.currentTimeMillis();
// Invisibility
if (!user.isOp() && invisible) {
return null;
@ -394,10 +395,12 @@ public class Flag implements Comparable<Flag> {
.name(user.getTranslation("protection.panel.flag-item.name-layout", TextVariables.NAME, user.getTranslation(getNameReference())))
.clickHandler(clickHandler)
.invisible(invisible);
BentoBox.getInstance().logDebug("Time for pib = " + (System.currentTimeMillis() - m));
if (hasSubPanel()) {
pib.description(user.getTranslation("protection.panel.flag-item.menu-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())));
return pib.build();
}
BentoBox.getInstance().logDebug("Type = " + getType());
return switch (getType()) {
case PROTECTION -> createProtectionFlag(plugin, user, island, pib).build();
case SETTING -> createSettingFlag(user, island, pib).build();
@ -428,20 +431,24 @@ public class Flag implements Comparable<Flag> {
}
private PanelItemBuilder createProtectionFlag(BentoBox plugin, User user, Island island, PanelItemBuilder pib) {
long m = System.currentTimeMillis();
BentoBox.getInstance().logDebug("Protection flag");
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));
}
});
}
BentoBox.getInstance().logDebug("Protection flag " + (System.currentTimeMillis() - m));
return pib;
}

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)
*/
public void openPanel(int activeTab, int page) {
long m = System.currentTimeMillis();
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);
@ -84,11 +85,12 @@ public class TabbedPanel extends Panel implements PanelListener {
}
this.activeTab = activeTab;
this.activePage = page;
BentoBox.getInstance().logDebug("Time 1 " + (System.currentTimeMillis() - m));
// The items in the panel
TreeMap<Integer, PanelItem> items = new TreeMap<>();
// Get the tab
Tab tab = tpb.getTabs().get(activeTab);
BentoBox.getInstance().logDebug("Time 2 " + (System.currentTimeMillis() - m));
// 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));
@ -96,15 +98,16 @@ public class TabbedPanel extends Panel implements PanelListener {
// Set up the tabbed header
setupHeader(tab, items);
BentoBox.getInstance().logDebug("Time 3 " + (System.currentTimeMillis() - m));
// 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));
BentoBox.getInstance().logDebug("Time 4 " + (System.currentTimeMillis() - m));
// set up the footer
setupFooter(items);
BentoBox.getInstance().logDebug("Time 5 " + (System.currentTimeMillis() - m));
// Add forward and backward icons
if (page > 0) {
// Previous page icon
@ -114,6 +117,7 @@ public class TabbedPanel extends Panel implements PanelListener {
return true;
}).build());
}
BentoBox.getInstance().logDebug("Time 6 " + (System.currentTimeMillis() - m));
if ((page + 1) * ITEMS_PER_PAGE < panelItems.stream().filter(Objects::nonNull).count()) {
// Next page icon
items.put(52, new PanelItemBuilder().icon(Material.ARROW).name(tpb.getUser().getTranslation(PROTECTION_PANEL + "next")).clickHandler((panel, user1, clickType, slot1) -> {
@ -122,11 +126,14 @@ public class TabbedPanel extends Panel implements PanelListener {
return true;
}).build());
}
BentoBox.getInstance().logDebug("Time 7 " + (System.currentTimeMillis() - m));
} else {
throw new InvalidParameterException("Unknown tab slot number " + activeTab);
}
BentoBox.getInstance().logDebug("Time 8 " + (System.currentTimeMillis() - m));
// Show it to the player
this.makePanel(tab.getName(), items, tpb.getSize(), tpb.getUser(), this);
BentoBox.getInstance().logDebug("Time 9 " + (System.currentTimeMillis() - m));
}
/**

View File

@ -1711,6 +1711,7 @@ public class Island implements DataObject, MetaDataAble {
* Indicates the fields have been changed. Used to optimize saving on shutdown and notify other servers
*/
public void setChanged() {
BentoBox.getInstance().logDebug("Island changed");
this.setUpdatedDate(System.currentTimeMillis());
this.changed = true;
IslandsManager.updateIsland(this);

View File

@ -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

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
// 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 -> {

View File

@ -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);
}

View File

@ -1641,11 +1641,14 @@ public class IslandsManager {
* @param island - island
*/
public static void updateIsland(Island island) {
long m = System.currentTimeMillis();
if (handler.objectExists(island.getUniqueId())) {
island.clearChanged();
handler.saveObjectAsync(island)
.thenAccept(b -> MultiLib.notify("bentobox-updateIsland", island.getUniqueId()));
}
BentoBox.getInstance().logDebug("Island update " + (System.currentTimeMillis() - m));
}
/**

View File

@ -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,18 @@ public class PlayersManager {
*/
@Nullable
public Players getPlayer(UUID uuid){
return addPlayer(uuid);
if (!playerCache.containsKey(uuid)) {
playerCache.put(uuid, addPlayer(uuid));
BentoBox.getInstance().logDebug("Not in cache");
}
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 +92,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.
@ -320,28 +309,6 @@ public class PlayersManager {
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

View File

@ -1,9 +1,11 @@
package world.bentobox.bentobox.panels.settings;
import java.util.ArrayList;
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 +18,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,6 +49,8 @@ public class SettingsTab implements Tab, ClickHandler {
protected Island island;
protected TabbedPanel parent;
private Map<UUID, Flag.Mode> currentMode = new HashMap<>();
/**
* Show a tab of settings
* @param user - user who is viewing the tab
@ -73,6 +78,7 @@ public class SettingsTab implements Tab, ClickHandler {
* @return list of flags that will be shown in this panel
*/
protected List<Flag> getFlags() {
long m = System.currentTimeMillis();
// Get a list of flags of the correct type and sort by the translated names
List<Flag> flags = plugin.getFlagsManager().getFlags().stream().filter(f -> f.getType().equals(type))
// We're stripping colors to avoid weird sorting issues
@ -81,9 +87,10 @@ 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)));
BentoBox.getInstance().logDebug("Time to get flags = " + (System.currentTimeMillis() - m));
return flags;
}
@ -116,17 +123,33 @@ public class SettingsTab implements Tab, ClickHandler {
@Override
@NonNull
public List<@Nullable PanelItem> getPanelItems() {
long m = System.currentTimeMillis();
BentoBox.getInstance().logDebug("Get panel items");
List<Flag> flags = getFlags();
BentoBox.getInstance().logDebug("Time for getFlags = " + (System.currentTimeMillis() - m));
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 = new ArrayList<>();
for (Flag f : flags) {
boolean x = plugin.getIWM().getHiddenFlags(world).contains(f.getID());
//BentoBox.getInstance().logDebug("Time for x = " + (System.currentTimeMillis() - m));
PanelItem pi = f.toPanelItem(plugin, user, world, island, x);
///BentoBox.getInstance().logDebug("Time for pi = " + (System.currentTimeMillis() - m));
result.add(pi);
}
/*
List<@Nullable PanelItem> result = flags.stream().map(
(f -> f.toPanelItem(plugin, user, world, island,
plugin.getIWM().getHiddenFlags(world).contains(f.getID()))))
.toList();
*/
BentoBox.getInstance().logDebug("Time for getpanelitems end = " + (System.currentTimeMillis() - m));
return result;
}
@Override
@ -138,7 +161,7 @@ public class SettingsTab implements Tab, ClickHandler {
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"), "",
@ -215,13 +238,15 @@ public class SettingsTab implements Tab, ClickHandler {
@Override
public boolean onClick(Panel panel, User user, ClickType clickType, int slot) {
long m = System.currentTimeMillis();
// 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();
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_OFF, 1F, 1F);
}
BentoBox.getInstance().logDebug("Time for onClick = " + (System.currentTimeMillis() - m));
return true;
}

View File

@ -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;
@ -69,6 +70,7 @@ public class WorldDefaultSettingsTab extends SettingsTab implements Tab {
*/
@Override
public @NonNull List<PanelItem> getPanelItems() {
BentoBox.getInstance().logDebug("Get world default settings");
// Different description and click handlers
return getFlags().stream().map(f -> {
PanelItem i = f.toPanelItem(plugin, user, world, island, false);

View File

@ -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

View File

@ -382,15 +382,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)}.
@ -634,16 +625,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)}.