Skip to content

Commit

Permalink
Fixed self-player item in the top islands menu (#911)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Feb 12, 2022
1 parent 46bfef8 commit 34d40c1
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
Expand Up @@ -57,6 +57,10 @@ public SoundWrapper getLackPermissionSound() {
return lackPermissionSound;
}

public boolean ignorePagedButton() {
return false;
}

public <T extends AbstractBuilder<T, ?, M>> T applyToBuilder(AbstractBuilder<T, ?, M> buttonBuilder) {
if (buttonBuilder.buttonItem == null)
buttonBuilder.setButtonItem(this.buttonItem);
Expand Down
Expand Up @@ -56,8 +56,11 @@ public ItemStack modifyButtonItem(ItemStack buttonItem, MenuTopIslands superiorM

SuperiorPlayer inventoryViewer = superiorMenu.getInventoryViewer();

if (isSelfPlayerIsland && inventoryViewer.getIsland() != null)
if (isSelfPlayerIsland) {
island = inventoryViewer.getIsland();
if (island == null)
return getNullItem().build();
}

SuperiorPlayer islandOwner = island.getOwner();
int place = plugin.getGrid().getIslandPosition(island, superiorMenu.getSortingType()) + 1;
Expand Down Expand Up @@ -164,6 +167,11 @@ public void onButtonClick(SuperiorSkyblockPlugin plugin, MenuTopIslands superior
command.replace("PLAYER:", "").replace("%player%", clickedPlayer.getName())));
}

@Override
public boolean ignorePagedButton() {
return this.isSelfPlayerIsland;
}

public static class Builder extends PagedObjectBuilder<Builder, TopIslandsPagedObjectButton, MenuTopIslands> {

private TemplateItem noIslandItem;
Expand Down Expand Up @@ -213,6 +221,20 @@ public TopIslandsPagedObjectButton build() {
getObjectIndex());
}

public Builder copy() {
Builder cloned = new Builder();
cloned.requiredPermission = requiredPermission;
cloned.lackPermissionSound = lackPermissionSound == null ? null : lackPermissionSound.copy();
cloned.buttonItem = buttonItem == null ? null : buttonItem.copy();
cloned.clickSound = clickSound == null ? null : clickSound.copy();
cloned.commands = commands == null ? null : new ArrayList<>(commands);
cloned.noIslandItem = noIslandItem == null ? null : noIslandItem.copy();
cloned.noIslandSound = noIslandSound == null ? null : noIslandSound.copy();
cloned.noIslandCommands = noIslandCommands == null ? null : new ArrayList<>(noIslandCommands);
cloned.isPlayerSelfIsland = isPlayerSelfIsland;
return cloned;
}

}

}
Expand Up @@ -7,9 +7,6 @@
import com.bgsoftware.superiorskyblock.api.menu.ISuperiorMenu;
import com.bgsoftware.superiorskyblock.api.objects.Pair;
import com.bgsoftware.superiorskyblock.api.wrappers.SuperiorPlayer;
import com.bgsoftware.superiorskyblock.hooks.support.PlaceholderHook;
import com.bgsoftware.superiorskyblock.lang.Message;
import com.bgsoftware.superiorskyblock.lang.PlayerLocales;
import com.bgsoftware.superiorskyblock.menu.PagedSuperiorMenu;
import com.bgsoftware.superiorskyblock.menu.SuperiorMenu;
import com.bgsoftware.superiorskyblock.menu.button.impl.menu.ChangeSortingTypeButton;
Expand Down Expand Up @@ -80,9 +77,6 @@ public static void init() {

sortGlowWhenSelected = cfg.getBoolean("sort-glow-when-selected", false);

patternBuilder.mapButtons(getSlots(cfg, "player-island", menuPatternSlots), new TopIslandsPagedObjectButton.Builder()
.setPlayerSelfIsland(true));

patternBuilder.mapButtons(getSlots(cfg, "worth-sort", menuPatternSlots),
new ChangeSortingTypeButton.Builder().setSortingType(SortingTypes.BY_WORTH));

Expand Down Expand Up @@ -115,19 +109,29 @@ public static void init() {
}

if (cfg.isString("slots")) {
boolean configuredSelfPlayerButton = false;

for (char slotsChar : cfg.getString("slots", "").toCharArray()) {
ConfigurationSection itemsSection = cfg.getConfigurationSection("items." + slotsChar);

if (itemsSection == null)
continue;

patternBuilder.mapButtons(menuPatternSlots.getSlots(slotsChar), new TopIslandsPagedObjectButton.Builder()
TopIslandsPagedObjectButton.Builder slotsBuilder = new TopIslandsPagedObjectButton.Builder()
.setIslandItem(FileUtils.getItemStack("top-islands.yml", itemsSection.getConfigurationSection("island")))
.setNoIslandItem(FileUtils.getItemStack("top-islands.yml", itemsSection.getConfigurationSection("no-island")))
.setIslandSound(FileUtils.getSound(cfg.getConfigurationSection("sounds." + slotsChar + ".island")))
.setNoIslandSound(FileUtils.getSound(cfg.getConfigurationSection("sounds." + slotsChar + ".no-island")))
.setIslandCommands(cfg.getStringList("commands." + slotsChar + ".island"))
.setNoIslandCommands(cfg.getStringList("commands." + slotsChar + ".no-island")));
.setNoIslandCommands(cfg.getStringList("commands." + slotsChar + ".no-island"));

patternBuilder.mapButtons(menuPatternSlots.getSlots(slotsChar), slotsBuilder);

if (!configuredSelfPlayerButton) {
configuredSelfPlayerButton = true;
patternBuilder.mapButtons(getSlots(cfg, "player-island", menuPatternSlots),
slotsBuilder.copy().setPlayerSelfIsland(true));
}
}
}

Expand Down
Expand Up @@ -42,7 +42,7 @@ public void setupInventory(Inventory inventory, M superiorMenu) {
for (int slot = 0; slot < this.buttons.length; ++slot) {
SuperiorMenuButton<M> button = this.buttons[slot];

if (button instanceof PagedObjectButton) {
if (button instanceof PagedObjectButton && !button.ignorePagedButton()) {
PagedObjectButton<M, T> pagedObjectButton = (PagedObjectButton<M, T>) button;
int objectIndex = pagedObjectSlot + (objectsPerPage * (currentPage - 1));

Expand Down
Expand Up @@ -30,4 +30,8 @@ public ItemStack build(SuperiorPlayer superiorPlayer) {
return getBuilder().build(superiorPlayer);
}

public TemplateItem copy() {
return new TemplateItem(this.itemBuilder.copy());
}

}
Expand Up @@ -35,4 +35,9 @@ public float getVolume() {
public float getPitch() {
return pitch;
}

public SoundWrapper copy() {
return new SoundWrapper(this.sound, this.volume, this.pitch);
}

}

0 comments on commit 34d40c1

Please sign in to comment.