WIP to having admin setting world based on the command
and not the location of the user.
This commit is contained in:
parent
edd7bcfbd2
commit
29184abf80
|
@ -377,12 +377,13 @@ public class Flag implements Comparable<Flag> {
|
|||
* Converts a flag to a panel item. The content of the flag will change depending on who the user is and where they are.
|
||||
* @param plugin - plugin
|
||||
* @param user - user that will see this flag
|
||||
* @param world - the world this flag is being shown for. If island is present, then world is the same as the island.
|
||||
* @param island - target island, if any
|
||||
* @param invisible - true if this flag is not visible to players
|
||||
* @return - PanelItem for this flag or null if item is invisible to user
|
||||
*/
|
||||
@Nullable
|
||||
public PanelItem toPanelItem(BentoBox plugin, User user, @Nullable Island island, boolean invisible) {
|
||||
public PanelItem toPanelItem(BentoBox plugin, User user, World world, @Nullable Island island, boolean invisible) {
|
||||
// Invisibility
|
||||
if (!user.isOp() && invisible) {
|
||||
return null;
|
||||
|
@ -400,12 +401,13 @@ public class Flag implements Comparable<Flag> {
|
|||
return switch (getType()) {
|
||||
case PROTECTION -> createProtectionFlag(plugin, user, island, pib).build();
|
||||
case SETTING -> createSettingFlag(user, island, pib).build();
|
||||
case WORLD_SETTING -> createWorldSettingFlag(user, pib).build();
|
||||
case WORLD_SETTING -> createWorldSettingFlag(user, world, pib).build();
|
||||
};
|
||||
}
|
||||
|
||||
private PanelItemBuilder createWorldSettingFlag(User user, PanelItemBuilder pib) {
|
||||
String worldSetting = this.isSetForWorld(user.getWorld()) ? user.getTranslation("protection.panel.flag-item.setting-active")
|
||||
private PanelItemBuilder createWorldSettingFlag(User user, World world, PanelItemBuilder pib) {
|
||||
String worldSetting = this.isSetForWorld(world)
|
||||
? user.getTranslation("protection.panel.flag-item.setting-active")
|
||||
: user.getTranslation("protection.panel.flag-item.setting-disabled");
|
||||
pib.description(user.getTranslation("protection.panel.flag-item.setting-layout", TextVariables.DESCRIPTION, user.getTranslation(getDescriptionReference())
|
||||
, "[setting]", worldSetting));
|
||||
|
|
|
@ -43,9 +43,12 @@ public class TabbedPanel extends Panel implements PanelListener {
|
|||
*/
|
||||
public TabbedPanel(TabbedPanelBuilder tpb) {
|
||||
this.tpb = tpb;
|
||||
// Set world
|
||||
this.setWorld(tpb.getWorld());
|
||||
// Set island context in Panel
|
||||
this.setIsland(tpb.getIsland());
|
||||
BentoBox.getInstance()
|
||||
.logDebug("World set in when built is " + this.getWorld().map(w -> w.getName()).orElse("NO WORLD"));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.TreeMap;
|
|||
|
||||
import org.bukkit.World;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.panels.Tab;
|
||||
import world.bentobox.bentobox.api.panels.TabbedPanel;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
@ -62,6 +63,7 @@ public class TabbedPanelBuilder {
|
|||
*/
|
||||
public TabbedPanelBuilder world(World world) {
|
||||
this.world = world;
|
||||
BentoBox.getInstance().logDebug("World set in builder is " + world.getName());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@ public class SettingsTab implements Tab, ClickHandler {
|
|||
* @param type - flag type
|
||||
*/
|
||||
public SettingsTab(World world, User user, Type type) {
|
||||
BentoBox.getInstance().logDebug("World set in consturctor to " + world);
|
||||
this.world = world;
|
||||
this.user = user;
|
||||
this.type = type;
|
||||
|
@ -124,8 +125,10 @@ public class SettingsTab implements Tab, ClickHandler {
|
|||
plugin.getPlayers().setFlagsDisplayMode(user.getUniqueId(), plugin.getPlayers().getFlagsDisplayMode(user.getUniqueId()).getNext());
|
||||
flags = getFlags();
|
||||
}
|
||||
BentoBox.getInstance().logDebug("Getting the panel items");
|
||||
return flags.stream().map(
|
||||
(f -> f.toPanelItem(plugin, user, island, plugin.getIWM().getHiddenFlags(world).contains(f.getID()))))
|
||||
(f -> f.toPanelItem(plugin, user, world, island,
|
||||
plugin.getIWM().getHiddenFlags(world).contains(f.getID()))))
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
@ -134,8 +137,8 @@ public class SettingsTab implements Tab, ClickHandler {
|
|||
Map<Integer, PanelItem> icons = new HashMap<>();
|
||||
// Add the lock icon - we want it to be displayed no matter the tab
|
||||
if (island != null) {
|
||||
icons.put(4, Flags.CHANGE_SETTINGS.toPanelItem(plugin, user, island, false));
|
||||
icons.put(5, Flags.LOCK.toPanelItem(plugin, user, 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));
|
||||
}
|
||||
// Add the mode icon
|
||||
switch (plugin.getPlayers().getFlagsDisplayMode(user.getUniqueId())) {
|
||||
|
@ -232,10 +235,11 @@ public class SettingsTab implements Tab, ClickHandler {
|
|||
|
||||
@Override
|
||||
public void setParentPanel(TabbedPanel parent) {
|
||||
BentoBox.getInstance().logDebug("Setting the parent panel ");
|
||||
this.parent = parent;
|
||||
this.island = parent.getIsland();
|
||||
this.world = island.getWorld();
|
||||
|
||||
this.world = parent.getWorld().orElse(null);
|
||||
BentoBox.getInstance().logDebug("World set is " + this.getWorld());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ public class WorldDefaultSettingsTab extends SettingsTab implements Tab {
|
|||
public @NonNull List<PanelItem> getPanelItems() {
|
||||
// Different description and click handlers
|
||||
return getFlags().stream().map(f -> {
|
||||
PanelItem i = f.toPanelItem(plugin, user, null, false);
|
||||
PanelItem i = f.toPanelItem(plugin, user, this.getParentPanel().getWorld().orElse(null), island, false);
|
||||
// Replace the click handler with WorldToggleClick
|
||||
i.setClickHandler(new WorldToggleClick(f.getID()));
|
||||
// Replace the description
|
||||
|
|
Loading…
Reference in New Issue