Skip to content

Commit

Permalink
Added menu sounds setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Jul 13, 2024
1 parent dec134b commit c4b7ddf
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 44 deletions.
55 changes: 37 additions & 18 deletions Plugin/src/main/java/dev/lrxh/neptune/configs/impl/MenusLocale.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,31 +297,50 @@ public enum MenusLocale implements IDataAccessor {
"&a + Left Click to increase",
"&c - Right Click to decrease"),
SETTINGS_PING_RANGE_SLOT("SETTINGS.PING-RANGE.SLOT", DataType.INT, "14"),
SETTINGS_COSMETICS_MATERIAL("SETTINGS.COSMETICS.MATERIAL", DataType.STRING, "CAKE"),
SETTINGS_COSMETICS_TITLE("SETTINGS.COSMETICS.NAME", DataType.STRING, "&bManage Cosmetics"),
SETTINGS_COSMETICS_LORE("SETTINGS.COSMETICS.LORE", DataType.STRING_LIST,
SETTINGS_COSMETICS_MATERIAL("SETTINGS.SETTINGS.COSMETICS.MATERIAL", DataType.STRING, "CAKE"),
SETTINGS_COSMETICS_TITLE("SETTINGS.SETTINGS.COSMETICS.NAME", DataType.STRING, "&bManage Cosmetics"),
SETTINGS_COSMETICS_LORE("SETTINGS.SETTINGS.COSMETICS.LORE", DataType.STRING_LIST,
"&7Manage unlocked cosmetics",
"",
" &7Current Cosmetic: &b<kill-effect>",
" ",
"&aClick to open cosmetics menu"),
SETTINGS_COSMETICS_SLOT("SETTINGS.COSMETICS.SLOT", DataType.INT, "15"),
COSMETICS_SIZE("COSMETICS.SIZE", DataType.INT, "27"),
COSMETICS_FILTER("COSMETICS.FILTER-TYPE", "FILL, BORDER, NONE", DataType.STRING, "FILL"),
COSMETICS_TITLE("COSMETICS.TITLE", DataType.STRING, "&7Cosmetics Management"),
KILL_EFFECTS_SLOT("COSMETICS.KILL-EFFECTS.SLOT", DataType.INT, "10"),
KILL_EFFECTS_NAME("COSMETICS.KILL-EFFECTS.NAME", DataType.STRING, "&bKill Effects"),
KILL_EFFECTS_LORE("COSMETICS.KILL-EFFECTS.LORE", DataType.STRING_LIST, "&7View all available kill effects", " ", "&aClick to open"),
KILL_EFFECTS_MATERIAL("COSMETICS.KILL-EFFECTS.MATERIAL", DataType.STRING, "REDSTONE"),
KILL_EFFECTS_TITLE("COSMETICS.KILL-EFFECTS.TITLE", DataType.STRING, "&7Kill Effects"),
KILL_EFFECTS_SIZE("KILL_EFFECTS.SIZE", DataType.INT, "27"),
KILL_EFFECTS_FILTER("KILL_EFFECTS.FILTER-TYPE", "FILL, BORDER, NONE", DataType.STRING, "FILL"),
KILL_EFFECTS_SELECTED_LORE("KILL_EFFECTS.SELECTED.LORE", DataType.STRING_LIST,
SETTINGS_COSMETICS_SLOT("SETTINGS.SETTINGS.COSMETICS.SLOT", DataType.INT, "15"),
COSMETICS_SIZE("SETTINGS.COSMETICS.SIZE", DataType.INT, "27"),
COSMETICS_FILTER("SETTINGS.COSMETICS.FILTER-TYPE", "FILL, BORDER, NONE", DataType.STRING, "FILL"),
COSMETICS_TITLE("SETTINGS.COSMETICS.TITLE", DataType.STRING, "&7Cosmetics Management"),
KILL_EFFECTS_SLOT("SETTINGS.COSMETICS.KILL-EFFECTS.SLOT", DataType.INT, "10"),
KILL_EFFECTS_NAME("SETTINGS.COSMETICS.KILL-EFFECTS.NAME", DataType.STRING, "&bKill Effects"),
KILL_EFFECTS_LORE("SETTINGS.COSMETICS.KILL-EFFECTS.LORE", DataType.STRING_LIST, "&7View all available kill effects", " ", "&aClick to open"),
KILL_EFFECTS_MATERIAL("SETTINGS.COSMETICS.KILL-EFFECTS.MATERIAL", DataType.STRING, "REDSTONE"),
KILL_EFFECTS_TITLE("SETTINGS.COSMETICS.KILL-EFFECTS.TITLE", DataType.STRING, "&7Kill Effects"),
KILL_EFFECTS_SIZE("SETTINGS.KILL-EFFECTS.SIZE", DataType.INT, "27"),
KILL_EFFECTS_FILTER("SETTINGS.KILL-EFFECTS.FILTER-TYPE", "FILL, BORDER, NONE", DataType.STRING, "FILL"),
KILL_EFFECTS_SELECTED_LORE("SETTINGS.KILL-EFFECTS.SELECTED.LORE", DataType.STRING_LIST,
" ", "&cClick to unselect"),
KILL_EFFECTS_UNSELECTED_LORE("KILL_EFFECTS.UNSELECTED.LORE", DataType.STRING_LIST,
KILL_EFFECTS_UNSELECTED_LORE("SETTINGS.KILL-EFFECTS.UNSELECTED.LORE", DataType.STRING_LIST,
" ", "&aClick to select"),
KILL_EFFECTS_NO_PERMISSION_LORE("KILL_EFFECTS.NO-PERMISSION.LORE", DataType.STRING_LIST,
" ", "&cNo permission");
KILL_EFFECTS_NO_PERMISSION_LORE("SETTINGS.KILL-EFFECTS.NO-PERMISSION.LORE", DataType.STRING_LIST,
" ", "&cNo permission"),
SETTINGS_MENU_SOUNDS_MATERIAL("SETTINGS.MENU-SOUNDS.MATERIAL", DataType.STRING, "BOOK"),
SETTINGS_MENU_SOUNDS_TITLE("SETTINGS.MENU-SOUNDS.NAME", DataType.STRING, "&bMenu Sounds"),
SETTINGS_MENU_SOUNDS_LORE_ENABLED("SETTINGS.MENU-SOUNDS.LORE_ENABLED", DataType.STRING_LIST,
"&7Play a sound when clicking.",
"&7a button",
" ",
" &a&l▶ &aEnabled",
" &7&l▶ &7Disabled",
" ",
"&cClick to disable."),
SETTINGS_MENU_SOUNDS_LORE_DISABLED("SETTINGS.MENU-SOUNDS.LORE_DISABLED", DataType.STRING_LIST,
"&7Play a sound when clicking",
"&7a button.",
"",
" &7&l▶ &7Enabled",
" &c&l▶ &cDisabled",
" ",
"&aClick to enable."),
SETTINGS_MENU_SOUNDS_SLOT("SETTINGS.MENU-SOUNDS.SLOT", DataType.INT, "16");

private final String path;
private final String comment;
Expand Down
8 changes: 4 additions & 4 deletions Plugin/src/main/java/dev/lrxh/neptune/match/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public abstract class Match {
private final UUID uuid = UUID.randomUUID();
private final HashSet<Location> placedBlocks = new HashSet<>();
private final HashSet<Entity> entities = new HashSet<>();
public MatchState matchState;
public MatchState state;
public Arena arena;
public Kit kit;
public List<Participant> participants;
Expand Down Expand Up @@ -139,7 +139,7 @@ public List<String> getScoreboard(UUID playerUUID) {
if (player == null) return new ArrayList<>();

if (this instanceof SoloFightMatch) {
MatchState matchState = this.getMatchState();
MatchState matchState = this.getState();

switch (matchState) {
case STARTING:
Expand Down Expand Up @@ -204,15 +204,15 @@ public void checkRules() {
forEachParticipant(participant -> {
if (!(this instanceof FfaFightMatch)) {
if (kit.is(KitRule.DENY_MOVEMENT)) {
if (matchState.equals(MatchState.STARTING)) {
if (state.equals(MatchState.STARTING)) {
PlayerUtil.denyMovement(participant.getPlayerUUID());
} else {
PlayerUtil.allowMovement(participant.getPlayerUUID());
}
}
}
if (kit.is(KitRule.SHOW_HP)) {
if (matchState.equals(MatchState.STARTING)) {
if (state.equals(MatchState.STARTING)) {
showHealth(participant.getPlayerUUID());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public FfaFightMatch(Arena arena, Kit kit, List<Participant> participants) {

@Override
public void end() {
matchState = MatchState.ENDING;
state = MatchState.ENDING;

forEachParticipant(participant -> {
if (winner == null) return;
Expand Down Expand Up @@ -85,7 +85,7 @@ public void onLeave(Participant participant) {

@Override
public void startMatch() {
matchState = MatchState.IN_ROUND;
state = MatchState.IN_ROUND;
checkRules();

showPlayerForSpectators();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public SoloFightMatch(Arena arena, Kit kit, boolean duel, List<Participant> part

@Override
public void end() {
matchState = MatchState.ENDING;
state = MatchState.ENDING;

if (!isDuel()) {
addStats();
Expand Down Expand Up @@ -115,7 +115,7 @@ public void onDeath(Participant participant) {
if (participantKiller.getRoundsWon() < rounds) {
participantKiller.setCombo(0);

matchState = MatchState.STARTING;
state = MatchState.STARTING;
new MatchRespawnRunnable(this, participant).start(0L, 20L, plugin);
return;
}
Expand Down Expand Up @@ -146,7 +146,7 @@ public void onLeave(Participant participant) {

@Override
public void startMatch() {
matchState = MatchState.IN_ROUND;
state = MatchState.IN_ROUND;
checkRules();

showPlayerForSpectators();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public MatchTeam getPlayerTeam(Participant participant) {

@Override
public void end() {
matchState = MatchState.ENDING;
state = MatchState.ENDING;
MatchTeam winnerTeam = teamA.isLoser() ? teamB : teamA;
MatchTeam loserTeam = teamA.isLoser() ? teamA : teamB;

Expand Down Expand Up @@ -105,7 +105,7 @@ public void onLeave(Participant participant) {

@Override
public void startMatch() {
matchState = MatchState.IN_ROUND;
state = MatchState.IN_ROUND;
checkRules();

showPlayerForSpectators();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
return;
}
if (match != null && match.getKit().is(KitRule.BUILD)) {
if (match.getMatchState().equals(MatchState.STARTING)) {
if (match.getState().equals(MatchState.STARTING)) {
event.setCancelled(true);
player.sendMessage(CC.color("&cYou can't place blocks yet!"));
return;
Expand All @@ -100,7 +100,7 @@ public void onProjectileLaunch(ProjectileLaunchEvent event) {
event.setCancelled(true);
return;
}
if (match.getMatchState().equals(MatchState.STARTING)) {
if (match.getState().equals(MatchState.STARTING)) {
event.setCancelled(true);
}
}
Expand Down Expand Up @@ -130,7 +130,7 @@ public void onEntityDamageByEntityMonitor(EntityDamageByEntityEvent event) {
}
}

if (!match.matchState.equals(MatchState.IN_ROUND)) {
if (!match.state.equals(MatchState.IN_ROUND)) {
event.setCancelled(true);
} else {
if (!match.getKit().is(KitRule.DAMAGE)) {
Expand Down Expand Up @@ -164,7 +164,7 @@ public void onPlayerMoveEvent(PlayerMoveEvent event) {
if (profile == null) return;
Match match = profile.getMatch();

if (match != null && match.getMatchState().equals(MatchState.IN_ROUND)) {
if (match != null && match.getState().equals(MatchState.IN_ROUND)) {
Participant participant = match.getParticipant(player.getUniqueId());
Location playerLocation = player.getLocation();

Expand All @@ -187,10 +187,16 @@ public void onEntityDamage(EntityDamageEvent event) {
if (event.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_ATTACK)) return;
Match match = profile.getMatch();

if (!profile.getState().equals(ProfileState.IN_GAME) ||
(match != null && !match.getKit().is(KitRule.FALL_DAMAGE) && event.getCause().equals(EntityDamageEvent.DamageCause.FALL))) {
boolean isNotInGame = !profile.getState().equals(ProfileState.IN_GAME);
boolean allowDamage = match != null &&
!match.getKit().is(KitRule.FALL_DAMAGE) &&
event.getCause().equals(EntityDamageEvent.DamageCause.FALL) &&
!match.getState().equals(MatchState.IN_ROUND);

if (isNotInGame || !allowDamage) {
event.setCancelled(true);
}

}
}

Expand Down Expand Up @@ -236,7 +242,7 @@ public void onBlockPlaceEvent(BlockPlaceEvent event) {
return;
}
if (match != null && match.getKit().is(KitRule.BUILD)) {
if (match.getMatchState().equals(MatchState.STARTING)) {
if (match.getState().equals(MatchState.STARTING)) {
event.setCancelled(true);
player.sendMessage(CC.color("&cYou can't place blocks yet!"));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void run() {
return;
}

if (match.getMatchState().equals(MatchState.STARTING)) {
if (match.getState().equals(MatchState.STARTING)) {
match.playSound(Sound.UI_BUTTON_CLICK);

match.sendTitle(MessagesLocale.MATCH_STARTING_TITLE_HEADER.getString().replace("<countdown-time>", String.valueOf(respawnTimer)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void run() {

return;
}
if (match.getMatchState().equals(MatchState.STARTING)) {
if (match.getState().equals(MatchState.STARTING)) {
match.playSound(Sound.UI_BUTTON_CLICK);
match.sendTitle(MessagesLocale.MATCH_STARTING_TITLE_HEADER.getString().replace("<countdown-time>", String.valueOf(startTimer)),
MessagesLocale.MATCH_STARTING_TITLE_FOOTER.getString().replace("<countdown-time>", String.valueOf(startTimer)),
Expand Down
2 changes: 2 additions & 0 deletions Plugin/src/main/java/dev/lrxh/neptune/profile/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public void load() {
settingData.setAllowParty(settingsStatistics.getBoolean("allowParty", true));
settingData.setMaxPing(settingsStatistics.getInteger("maxPing", 350));
settingData.setKillEffect(KillEffect.valueOf(settingsStatistics.getString("killEffect", "NONE")));
settingData.setMenuSound(settingsStatistics.getBoolean("menuSound", false));

}

Expand Down Expand Up @@ -122,6 +123,7 @@ public void save() {
settingsDoc.put("allowParty", settingData.isAllowParty());
settingsDoc.put("maxPing", settingData.getMaxPing());
settingsDoc.put("killEffect", settingData.getKillEffect().toString());
settingsDoc.put("menuSound", settingData.isMenuSound());

dataDocument.put("settings", settingsDoc);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class SettingData {
private boolean allowParty = true;
private int maxPing = 350;
private KillEffect killEffect = KillEffect.NONE;
private boolean menuSound = false;

public void increasePing() {
if (maxPing == 350) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public void run() {
SettingData settings1 = plugin.getProfileManager().getByUUID(uuid1).getSettingData();
SettingData settings2 = plugin.getProfileManager().getByUUID(uuid2).getSettingData();

if (!(settings2.getMaxPing() <= settings1.getMaxPing() &&
settings1.getMaxPing() <= settings2.getMaxPing())) {
if (!(PlayerUtil.getPing(uuid2) <= settings1.getMaxPing() &&
PlayerUtil.getPing(uuid1) <= settings2.getMaxPing())) {
continue;
}

Expand Down
16 changes: 16 additions & 0 deletions Plugin/src/main/java/dev/lrxh/neptune/settings/Setting.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ public void execute(Player player, ClickType clicktype) {
public void execute(Player player, ClickType clicktype) {
new CosmeticsManageMenu().openMenu(player.getUniqueId());
}
},
MENU_SOUNDS(MenusLocale.SETTINGS_MENU_SOUNDS_TITLE.getString(),
MenusLocale.SETTINGS_MENU_SOUNDS_MATERIAL.getString(),
MenusLocale.SETTINGS_MENU_SOUNDS_LORE_ENABLED.getStringList(),
MenusLocale.SETTINGS_MENU_SOUNDS_LORE_DISABLED.getStringList(),
MenusLocale.SETTINGS_MENU_SOUNDS_SLOT.getInt()) {
@Override
public void execute(Player player, ClickType clicktype) {
Profile profile = getProfile(player);
profile.getSettingData().setMenuSound(!profile.getSettingData().isMenuSound());
}

@Override
public boolean toggled(Player player) {
return getProfile(player).getSettingData().isMenuSound();
}
};

private String displayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import java.util.WeakHashMap;

public class MenuManager {
public WeakHashMap<UUID, Menu> openedMenus = new WeakHashMap<>();
public WeakHashMap<UUID, Menu> openedMenus;

public void closeMenu(UUID playerUUID) {
openedMenus.remove(playerUUID);
public MenuManager() {
this.openedMenus = new WeakHashMap<>();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package dev.lrxh.neptune.utils.menu.listener;

import dev.lrxh.neptune.Neptune;
import dev.lrxh.neptune.profile.Profile;
import dev.lrxh.neptune.utils.menu.Button;
import dev.lrxh.neptune.utils.menu.Menu;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand Down Expand Up @@ -39,8 +41,13 @@ public void onButtonPress(InventoryClickEvent event) {
}

button.onClick(player, event.getClick());
Profile profile = plugin.getProfileManager().getByUUID(player.getUniqueId());
if (profile != null && profile.getSettingData().isMenuSound()) {
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
}

if (menu.isUpdateOnClick() && plugin.getMenuManager().openedMenus.get(player.getUniqueId()).getUUID().equals(menu.getUUID())) {
Menu currentMenu = plugin.getMenuManager().openedMenus.get(player.getUniqueId());
if (menu.isUpdateOnClick() && (currentMenu != null && currentMenu.getUUID().equals(menu.getUUID()))) {
menu.update();
}

Expand Down

0 comments on commit c4b7ddf

Please sign in to comment.