Skip to content

Commit

Permalink
Fixed sounds not working for some menus (#1683)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Jun 23, 2023
1 parent f0c936d commit dd64c17
Show file tree
Hide file tree
Showing 28 changed files with 177 additions and 97 deletions.
Expand Up @@ -5,9 +5,12 @@
import com.bgsoftware.superiorskyblock.api.menu.button.MenuViewButton;
import com.bgsoftware.superiorskyblock.api.menu.view.MenuView;
import com.bgsoftware.superiorskyblock.api.world.GameSound;
import com.bgsoftware.superiorskyblock.core.Text;
import com.bgsoftware.superiorskyblock.core.itemstack.ItemBuilder;
import com.bgsoftware.superiorskyblock.core.menu.TemplateItem;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.List;
Expand All @@ -23,8 +26,9 @@ public abstract class AbstractMenuTemplateButton<V extends MenuView<V, ?>> imple
private final GameSound lackPermissionSound;
private final Class<?> viewButtonType;

public AbstractMenuTemplateButton(TemplateItem buttonItem, GameSound clickSound, List<String> commands,
String requiredPermission, GameSound lackPermissionSound, Class<?> viewButtonType) {
public AbstractMenuTemplateButton(@Nullable TemplateItem buttonItem, @Nullable GameSound clickSound,
@Nullable List<String> commands, @Nullable String requiredPermission,
@Nullable GameSound lackPermissionSound, Class<?> viewButtonType) {
this.buttonItem = buttonItem;
this.clickSound = clickSound;
this.commands = commands == null ? Collections.emptyList() : Collections.unmodifiableList(commands);
Expand All @@ -33,26 +37,36 @@ public AbstractMenuTemplateButton(TemplateItem buttonItem, GameSound clickSound,
this.viewButtonType = viewButtonType;
}

@Nullable
@Override
public ItemStack getButtonItem() {
return this.buttonItem == null ? null : this.buttonItem.getBuilder().build();
}

@Nullable
public TemplateItem getButtonTemplateItem() {
return buttonItem;
}

@Nullable
@Override
public GameSound getClickSound() {
return this.clickSound;
}

@Override
public List<String> getClickCommands() {
return this.commands;
}

@Nullable
@Override
public String getRequiredPermission() {
return this.requiredPermission;
}

@Nullable
@Override
public GameSound getLackPermissionSound() {
return this.lackPermissionSound;
}
Expand All @@ -73,10 +87,14 @@ public <B extends MenuTemplateButton.Builder<?>> B applyToBuilder(B buttonBuilde
if (((AbstractBuilder<?>) buttonBuilder).buttonItem == null)
((AbstractBuilder<?>) buttonBuilder).buttonItem = this.buttonItem;

buttonBuilder.setClickSound(this.clickSound);
buttonBuilder.setClickCommands(this.commands);
buttonBuilder.setRequiredPermission(this.requiredPermission);
buttonBuilder.setLackPermissionsSound(this.lackPermissionSound);
if (this.clickSound != null)
buttonBuilder.setClickSound(this.clickSound);
if (this.commands != null && !this.commands.isEmpty())
buttonBuilder.setClickCommands(this.commands);
if (!Text.isBlank(this.requiredPermission))
buttonBuilder.setRequiredPermission(this.requiredPermission);
if (this.lackPermissionSound != null)
buttonBuilder.setLackPermissionsSound(this.lackPermissionSound);

return buttonBuilder;
}
Expand Down
Expand Up @@ -11,6 +11,7 @@
import com.bgsoftware.superiorskyblock.core.threads.BukkitExecutor;
import com.bgsoftware.superiorskyblock.island.IslandUtils;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.Nullable;

import java.util.List;

Expand Down Expand Up @@ -55,8 +56,8 @@ public static class Template extends MenuTemplateButtonImpl<MenuConfirmBan.View>

private final boolean banPlayer;

Template(TemplateItem buttonItem, GameSound clickSound, List<String> commands,
String requiredPermission, GameSound lackPermissionSound, boolean banPlayer) {
Template(@Nullable TemplateItem buttonItem, @Nullable GameSound clickSound, @Nullable List<String> commands,
@Nullable String requiredPermission, @Nullable GameSound lackPermissionSound, boolean banPlayer) {
super(buttonItem, clickSound, commands, requiredPermission, lackPermissionSound,
BanButton.class, BanButton::new);
this.banPlayer = banPlayer;
Expand Down
Expand Up @@ -15,6 +15,7 @@
import com.bgsoftware.superiorskyblock.player.chat.PlayerChat;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.Nullable;

import java.math.BigDecimal;
import java.util.List;
Expand Down Expand Up @@ -83,11 +84,13 @@ public MenuTemplateButton<IslandMenuView> build() {

public static class Template extends MenuTemplateButtonImpl<IslandMenuView> {

@Nullable
private final GameSound successSound;
@Nullable
private final GameSound failSound;

Template(TemplateItem buttonItem, List<String> commands, String requiredPermission,
GameSound lackPermissionSound, GameSound successSound, GameSound failSound) {
Template(@Nullable TemplateItem buttonItem, @Nullable List<String> commands, @Nullable String requiredPermission,
@Nullable GameSound lackPermissionSound, @Nullable GameSound successSound, @Nullable GameSound failSound) {
super(buttonItem, null, commands, requiredPermission, lackPermissionSound,
BankCustomDepositButton.class, BankCustomDepositButton::new);
this.successSound = successSound;
Expand Down
Expand Up @@ -15,6 +15,7 @@
import com.bgsoftware.superiorskyblock.player.chat.PlayerChat;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.Nullable;

import java.math.BigDecimal;
import java.util.List;
Expand Down Expand Up @@ -83,11 +84,13 @@ public MenuTemplateButton<IslandMenuView> build() {

public static class Template extends MenuTemplateButtonImpl<IslandMenuView> {

@Nullable
private final GameSound successSound;
@Nullable
private final GameSound failSound;

Template(TemplateItem buttonItem, List<String> commands, String requiredPermission,
GameSound lackPermissionSound, GameSound successSound, GameSound failSound) {
Template(@Nullable TemplateItem buttonItem, @Nullable List<String> commands, @Nullable String requiredPermission,
@Nullable GameSound lackPermissionSound, @Nullable GameSound successSound, @Nullable GameSound failSound) {
super(buttonItem, null, commands, requiredPermission, lackPermissionSound,
BankCustomWithdrawButton.class, BankCustomWithdrawButton::new);
this.successSound = successSound;
Expand Down
Expand Up @@ -12,6 +12,7 @@
import com.bgsoftware.superiorskyblock.core.menu.button.MenuTemplateButtonImpl;
import com.bgsoftware.superiorskyblock.core.menu.view.IslandMenuView;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.Nullable;

import java.math.BigDecimal;
import java.util.List;
Expand Down Expand Up @@ -71,12 +72,15 @@ public MenuTemplateButton<IslandMenuView> build() {

public static class Template extends MenuTemplateButtonImpl<IslandMenuView> {

@Nullable
private final GameSound successSound;
@Nullable
private final GameSound failSound;
private final BigDecimal depositPercentage;

Template(TemplateItem buttonItem, List<String> commands, String requiredPermission,
GameSound lackPermissionSound, GameSound successSound, GameSound failSound, double depositPercentage) {
Template(@Nullable TemplateItem buttonItem, @Nullable List<String> commands, @Nullable String requiredPermission,
@Nullable GameSound lackPermissionSound, @Nullable GameSound successSound,
@Nullable GameSound failSound, double depositPercentage) {
super(buttonItem, null, commands, requiredPermission, lackPermissionSound,
BankDepositButton.class, BankDepositButton::new);
this.successSound = successSound;
Expand Down
Expand Up @@ -9,9 +9,11 @@
import com.bgsoftware.superiorskyblock.core.menu.button.MenuTemplateButtonImpl;
import com.bgsoftware.superiorskyblock.core.menu.impl.MenuBankLogs;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.Nullable;

import java.util.Comparator;
import java.util.List;
import java.util.Objects;

public class BankLogsSortButton extends AbstractMenuViewButton<MenuBankLogs.View> {

Expand Down Expand Up @@ -73,11 +75,11 @@ public static class Template extends MenuTemplateButtonImpl<MenuBankLogs.View> {

private final SortType sortType;

Template(TemplateItem buttonItem, GameSound clickSound, List<String> commands,
String requiredPermission, GameSound lackPermissionSound, SortType sortType) {
Template(@Nullable TemplateItem buttonItem, @Nullable GameSound clickSound, @Nullable List<String> commands,
@Nullable String requiredPermission, @Nullable GameSound lackPermissionSound, SortType sortType) {
super(buttonItem, clickSound, commands, requiredPermission, lackPermissionSound,
BankLogsSortButton.class, BankLogsSortButton::new);
this.sortType = sortType;
this.sortType = Objects.requireNonNull(sortType, "sortType cannot be null");
}

}
Expand Down
Expand Up @@ -12,8 +12,10 @@
import com.bgsoftware.superiorskyblock.core.menu.button.MenuTemplateButtonImpl;
import com.bgsoftware.superiorskyblock.core.menu.view.IslandMenuView;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.Nullable;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;

public class BankWithdrawButton extends AbstractMenuViewButton<IslandMenuView> {
Expand Down Expand Up @@ -77,19 +79,22 @@ public MenuTemplateButton<IslandMenuView> build() {

public static class Template extends MenuTemplateButtonImpl<IslandMenuView> {

@Nullable
private final GameSound successSound;
@Nullable
private final GameSound failSound;
private final BigDecimal withdrawValue;
private final List<String> withdrawCommands;

Template(TemplateItem buttonItem, List<String> commands, String requiredPermission, GameSound lackPermissionSound,
GameSound successSound, GameSound failSound, double withdrawValue, List<String> withdrawCommands) {
Template(@Nullable TemplateItem buttonItem, @Nullable List<String> commands, @Nullable String requiredPermission,
@Nullable GameSound lackPermissionSound, @Nullable GameSound successSound,
@Nullable GameSound failSound, double withdrawValue, @Nullable List<String> withdrawCommands) {
super(buttonItem, null, commands, requiredPermission, lackPermissionSound,
BankWithdrawButton.class, BankWithdrawButton::new);
this.successSound = successSound;
this.failSound = failSound;
this.withdrawValue = BigDecimal.valueOf(withdrawValue / 100D);
this.withdrawCommands = withdrawCommands;
this.withdrawCommands = withdrawCommands == null ? Collections.emptyList() : withdrawCommands;
}

}
Expand Down
Expand Up @@ -23,8 +23,10 @@
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

public class BiomeButton extends AbstractMenuViewButton<IslandMenuView> {

Expand Down Expand Up @@ -138,22 +140,25 @@ public MenuTemplateButton<IslandMenuView> build() {

public static class Template extends MenuTemplateButtonImpl<IslandMenuView> {

@Nullable
private final GameSound accessSound;
private final List<String> accessCommands;
@Nullable
private final TemplateItem lackPermissionItem;
private final List<String> lackPermissionCommands;
private final Biome biome;

Template(TemplateItem buttonItem, String requiredPermission, GameSound lackPermissionSound,
GameSound accessSound, List<String> accessCommands, TemplateItem lackPermissionItem,
List<String> lackPermissionCommands, Biome biome) {
Template(@Nullable TemplateItem buttonItem, @Nullable String requiredPermission,
@Nullable GameSound lackPermissionSound, @Nullable GameSound accessSound,
@Nullable List<String> accessCommands, @Nullable TemplateItem lackPermissionItem,
@Nullable List<String> lackPermissionCommands, Biome biome) {
super(buttonItem, null, null, requiredPermission, lackPermissionSound,
BiomeButton.class, BiomeButton::new);
this.accessSound = accessSound;
this.accessCommands = accessCommands;
this.accessCommands = accessCommands == null ? Collections.emptyList() : accessCommands;
this.lackPermissionItem = lackPermissionItem;
this.lackPermissionCommands = lackPermissionCommands;
this.biome = biome;
this.lackPermissionCommands = lackPermissionCommands == null ? Collections.emptyList() : lackPermissionCommands;
this.biome = Objects.requireNonNull(biome, "biome cannot be null");
}

}
Expand Down
Expand Up @@ -11,8 +11,10 @@
import com.bgsoftware.superiorskyblock.core.threads.BukkitExecutor;
import com.bgsoftware.superiorskyblock.island.IslandUtils;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Objects;

public class BorderColorButton extends AbstractMenuViewButton<BaseMenuView> {

Expand Down Expand Up @@ -51,11 +53,11 @@ public static class Template extends MenuTemplateButtonImpl<BaseMenuView> {

private final BorderColor borderColor;

Template(TemplateItem buttonItem, GameSound clickSound, List<String> commands,
String requiredPermission, GameSound lackPermissionSound, BorderColor borderColor) {
Template(@Nullable TemplateItem buttonItem, @Nullable GameSound clickSound, @Nullable List<String> commands,
@Nullable String requiredPermission, @Nullable GameSound lackPermissionSound, BorderColor borderColor) {
super(buttonItem, clickSound, commands, requiredPermission, lackPermissionSound,
BorderColorButton.class, BorderColorButton::new);
this.borderColor = borderColor;
this.borderColor = Objects.requireNonNull(borderColor, "borderColor cannot be null");
}

}
Expand Down
Expand Up @@ -11,8 +11,10 @@
import com.bgsoftware.superiorskyblock.core.threads.BukkitExecutor;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Objects;

public class BorderColorToggleButton extends AbstractMenuViewButton<BaseMenuView> {

Expand Down Expand Up @@ -64,12 +66,13 @@ public static class Template extends MenuTemplateButtonImpl<BaseMenuView> {
private final TemplateItem enabledItem;
private final TemplateItem disabledItem;

Template(GameSound clickSound, List<String> commands, String requiredPermission, GameSound lackPermissionSound,
TemplateItem enabledItem, TemplateItem disabledItem) {
Template(@Nullable GameSound clickSound, @Nullable List<String> commands, @Nullable String requiredPermission,
@Nullable GameSound lackPermissionSound, @Nullable TemplateItem enabledItem,
@Nullable TemplateItem disabledItem) {
super(null, clickSound, commands, requiredPermission, lackPermissionSound,
BorderColorToggleButton.class, BorderColorToggleButton::new);
this.enabledItem = enabledItem;
this.disabledItem = disabledItem;
this.enabledItem = enabledItem == null ? TemplateItem.AIR : enabledItem;
this.disabledItem = disabledItem == null ? TemplateItem.AIR : disabledItem;
}

}
Expand Down
Expand Up @@ -13,8 +13,10 @@
import com.bgsoftware.superiorskyblock.core.menu.impl.MenuTopIslands;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Objects;

public class ChangeSortingTypeButton extends AbstractMenuViewButton<MenuTopIslands.View> {

Expand Down Expand Up @@ -74,11 +76,11 @@ public static class Template extends MenuTemplateButtonImpl<MenuTopIslands.View>

private final SortingType sortingType;

Template(TemplateItem buttonItem, GameSound clickSound, List<String> commands,
String requiredPermission, GameSound lackPermissionSound, SortingType sortingType) {
Template(@Nullable TemplateItem buttonItem, @Nullable GameSound clickSound, @Nullable List<String> commands,
@Nullable String requiredPermission, @Nullable GameSound lackPermissionSound, SortingType sortingType) {
super(buttonItem, clickSound, commands, requiredPermission, lackPermissionSound,
ChangeSortingTypeButton.class, ChangeSortingTypeButton::new);
this.sortingType = sortingType;
this.sortingType = Objects.requireNonNull(sortingType, "sortingType cannot be null");
}

}
Expand Down
Expand Up @@ -14,8 +14,10 @@
import com.bgsoftware.superiorskyblock.core.threads.BukkitExecutor;
import com.bgsoftware.superiorskyblock.island.privilege.IslandPrivileges;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Objects;

public class ControlPanelButton extends AbstractMenuViewButton<IslandMenuView> {

Expand Down Expand Up @@ -84,11 +86,12 @@ public static class Template extends MenuTemplateButtonImpl<IslandMenuView> {

private final ControlPanelAction controlPanelAction;

Template(TemplateItem buttonItem, GameSound clickSound, List<String> commands,
String requiredPermission, GameSound lackPermissionSound, ControlPanelAction controlPanelAction) {
Template(@Nullable TemplateItem buttonItem, @Nullable GameSound clickSound, @Nullable List<String> commands,
@Nullable String requiredPermission, @Nullable GameSound lackPermissionSound,
ControlPanelAction controlPanelAction) {
super(buttonItem, clickSound, commands, requiredPermission, lackPermissionSound,
ControlPanelButton.class, ControlPanelButton::new);
this.controlPanelAction = controlPanelAction;
this.controlPanelAction = Objects.requireNonNull(controlPanelAction, "controlPanelAction cannot be null");
}

}
Expand Down

0 comments on commit dd64c17

Please sign in to comment.