Skip to content

Commit

Permalink
Fixed SettingsMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Mar 3, 2024
1 parent c412b53 commit 6136b0d
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 95 deletions.
1 change: 1 addition & 0 deletions src/main/java/me/lrxh/practice/Locale.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public enum Locale {
QUEUE_LEAVE_UNRANKED("QUEUE.LEAVE_UNRANKED"),
QUEUE_JOIN_RANKED("QUEUE.JOIN_RANKED"),
RANKED_ERROR("RANKED.ERROR-MESSAGE"),
LEADERBOARD_REFRESH("LEADERBOARD.MESSAGE"),
PING_YOUR("PING.YOUR"),
PING_OTHERS("PING.OTHERS"),
QUEUE_LEAVE_RANKED("QUEUE.LEAVE_RANKED"),
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/lrxh/practice/Practice.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import me.lrxh.practice.profile.Profile;
import me.lrxh.practice.profile.ProfileListener;
import me.lrxh.practice.profile.hotbar.Hotbar;
import me.lrxh.practice.profile.hotbar.Hotbar;
import me.lrxh.practice.queue.QueueListener;
import me.lrxh.practice.queue.QueueThread;
import me.lrxh.practice.scoreboard.ScoreboardAdapter;
Expand Down Expand Up @@ -87,6 +86,7 @@ public class Practice extends JavaPlugin {
private boolean placeholder = false;
private SpigotHandler spigotHandler;
private Hotbar hotbar;

public static Practice getInstance() {
if (practice == null) {
practice = new Practice();
Expand All @@ -113,7 +113,7 @@ public void onEnable() {
loadConfigs();
loadMongo();
spigotHandler = new SpigotHandler(practice);
if(Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3].equals("v1_8_R3")){
if (Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3].equals("v1_8_R3")) {
spigotHandler.init(false);
}

Expand Down
81 changes: 40 additions & 41 deletions src/main/java/me/lrxh/practice/arena/command/ArenaCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
Expand Down Expand Up @@ -121,9 +120,9 @@ public void remove(Player player, String arenaName) {
return;
}
Arena arena = Arena.getByName(arenaName);
arena.delete();
arena.delete();

player.sendMessage(CC.GREEN + "Deleted arena " + arena.getName());
player.sendMessage(CC.GREEN + "Deleted arena " + arena.getName());
}

@Subcommand("wand")
Expand Down Expand Up @@ -155,30 +154,30 @@ public void status(Player player, String arenaName) {
return;
}
Arena arena = Arena.getByName(arenaName);
player.sendMessage(CC.GREEN + CC.BOLD + "Arena Status " + CC.GRAY + "(" +
(arena.isSetup() ? CC.GREEN : CC.RED) + arena.getName() + CC.GRAY + ")");

player.sendMessage(CC.GREEN + "Cuboid Lower Location: " + CC.YELLOW +
(arena.getLowerCorner() == null ?
StringEscapeUtils.unescapeJava("✗") :
StringEscapeUtils.unescapeJava("✓")));

player.sendMessage(CC.GREEN + "Cuboid Upper Location: " + CC.YELLOW +
(arena.getUpperCorner() == null ?
StringEscapeUtils.unescapeJava("✗") :
StringEscapeUtils.unescapeJava("✓")));

player.sendMessage(CC.GREEN + "Spawn A Location: " + CC.YELLOW +
(arena.getSpawnA() == null ?
StringEscapeUtils.unescapeJava("✗") :
StringEscapeUtils.unescapeJava("✓")));

player.sendMessage(CC.GREEN + "Spawn B Location: " + CC.YELLOW +
(arena.getSpawnB() == null ?
StringEscapeUtils.unescapeJava("✗") :
StringEscapeUtils.unescapeJava("✓")));

player.sendMessage(CC.GREEN + "Kits: " + CC.YELLOW + StringUtils.join(arena.getKits(), ", "));
player.sendMessage(CC.GREEN + CC.BOLD + "Arena Status " + CC.GRAY + "(" +
(arena.isSetup() ? CC.GREEN : CC.RED) + arena.getName() + CC.GRAY + ")");

player.sendMessage(CC.GREEN + "Cuboid Lower Location: " + CC.YELLOW +
(arena.getLowerCorner() == null ?
StringEscapeUtils.unescapeJava("✗") :
StringEscapeUtils.unescapeJava("✓")));

player.sendMessage(CC.GREEN + "Cuboid Upper Location: " + CC.YELLOW +
(arena.getUpperCorner() == null ?
StringEscapeUtils.unescapeJava("✗") :
StringEscapeUtils.unescapeJava("✓")));

player.sendMessage(CC.GREEN + "Spawn A Location: " + CC.YELLOW +
(arena.getSpawnA() == null ?
StringEscapeUtils.unescapeJava("✗") :
StringEscapeUtils.unescapeJava("✓")));

player.sendMessage(CC.GREEN + "Spawn B Location: " + CC.YELLOW +
(arena.getSpawnB() == null ?
StringEscapeUtils.unescapeJava("✗") :
StringEscapeUtils.unescapeJava("✓")));

player.sendMessage(CC.GREEN + "Kits: " + CC.YELLOW + StringUtils.join(arena.getKits(), ", "));
}

@Subcommand("genhelper")
Expand Down Expand Up @@ -350,15 +349,15 @@ public void setspawn(Player player, String arenaName, SpawnType pos) {
return;
}
Arena arena = Arena.getByName(arenaName);
if (pos.equals(SpawnType.A)) {
arena.setSpawnA(player.getLocation());
} else {
arena.setSpawnB(player.getLocation());
}
if (pos.equals(SpawnType.A)) {
arena.setSpawnA(player.getLocation());
} else {
arena.setSpawnB(player.getLocation());
}

arena.save();
arena.save();

player.sendMessage(CC.GREEN + "Updated spawn point " + pos + " for arena " + arena.getName() + "");
player.sendMessage(CC.GREEN + "Updated spawn point " + pos + " for arena " + arena.getName());
}

@Subcommand("setBedSpawn")
Expand All @@ -374,14 +373,14 @@ public void setBedSpawn(Player player, String arenaName, SpawnType pos) {
return;
}
Arena arena = Arena.getByName(arenaName);
if (pos.equals(SpawnType.A)) {
arena.setBedA(PlayerUtil.getTargetBlock(player, 6).getLocation());
} else {
arena.setBedB(PlayerUtil.getTargetBlock(player, 6).getLocation());
}
if (pos.equals(SpawnType.A)) {
arena.setBedA(PlayerUtil.getTargetBlock(player, 6).getLocation());
} else {
arena.setBedB(PlayerUtil.getTargetBlock(player, 6).getLocation());
}

arena.save();
player.sendMessage(CC.GREEN + "Updated bed " + pos + " for arena " + arena.getName());
arena.save();
player.sendMessage(CC.GREEN + "Updated bed " + pos + " for arena " + arena.getName());
}

private boolean checkArena(String arena) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/me/lrxh/practice/kit/KitEditorListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import me.lrxh.practice.profile.Profile;
import me.lrxh.practice.profile.ProfileState;
import me.lrxh.practice.profile.hotbar.HotbarItem;
import me.lrxh.practice.profile.hotbar.HotbarItem;
import me.lrxh.practice.util.CC;
import org.bukkit.GameMode;
import org.bukkit.Material;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.lrxh.practice.leaderboards;

import me.lrxh.practice.Locale;
import me.lrxh.practice.Practice;
import me.lrxh.practice.profile.Profile;
import me.lrxh.practice.util.CC;
Expand Down Expand Up @@ -44,8 +45,10 @@ public void run() {
Console.sendMessage(CC.translate("&aSaved Player Data!"));
Leaderboard.getEloLeaderboards().clear();
Leaderboard.setEloLeaderboards(Leaderboard.init());
for (Player player : Bukkit.getOnlinePlayers()) {
player.sendMessage(CC.translate("&aLeaderboards Refreshed!"));
if (Practice.getInstance().getMainConfig().getBoolean("LEADERBOARD.ENABLE-MESSAGE")) {
for (Player player : Bukkit.getOnlinePlayers()) {
player.sendMessage(Locale.LEADERBOARD_REFRESH.format(player));
}
}
}
sleep(SECOND_IN_MILLIS);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/me/lrxh/practice/match/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;

import java.lang.reflect.InvocationTargetException;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/me/lrxh/practice/match/MatchListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public void onBlockBreakEvent(BlockBreakEvent event) {

if (profile.getState() == ProfileState.FIGHTING) {
Match match = profile.getMatch();
if(match.kit.getGameRules().isBedwars()){
if(event.getBlock().getLocation().equals(event.getPlayer().getBedSpawnLocation())){
if (match.kit.getGameRules().isBedwars()) {
if (event.getBlock().getLocation().equals(event.getPlayer().getBedSpawnLocation())) {
event.getPlayer().sendMessage(CC.translate("&cYou can't break your own bed!"));
event.setCancelled(true);
}
Expand All @@ -130,7 +130,7 @@ public void onBlockBreakEvent(BlockBreakEvent event) {
} else {
event.setCancelled(true);
}
if(match.kit.getGameRules().isBedwars() && (event.getBlock().getType().equals(Material.BED_BLOCK) || event.getBlock().getType().equals(Material.BED))){
if (match.kit.getGameRules().isBedwars() && (event.getBlock().getType().equals(Material.BED_BLOCK) || event.getBlock().getType().equals(Material.BED))) {
event.setCancelled(false);
}
} else {
Expand Down Expand Up @@ -239,7 +239,7 @@ public void onPlayerDeathEvent(PlayerDeathEvent event) {
Profile profile = Profile.getByUuid(event.getEntity().getUniqueId());

if (profile.getState() == ProfileState.FIGHTING) {
if(profile.getMatch().kit.getGameRules().isBedwars()){
if (profile.getMatch().kit.getGameRules().isBedwars()) {
PlayerUtil.animateDeath(event.getEntity());
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/me/lrxh/practice/match/impl/BasicTeamMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public void setupPlayer(Player player) {
// Teleport the player to their spawn point
Location spawn = participantA.containsPlayer(player.getUniqueId()) ?
getArena().getSpawnA() : getArena().getSpawnB();
if(kit.getGameRules().isBedwars()){
if(participantA.containsPlayer(player.getUniqueId())){
if (kit.getGameRules().isBedwars()) {
if (participantA.containsPlayer(player.getUniqueId())) {
player.setBedSpawnLocation(arena.getBedA());
}else{
} else {
player.setBedSpawnLocation(arena.getBedB());
}
}

if (spawn.getBlock().getType() == Material.AIR) {
player.teleport(spawn);
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/me/lrxh/practice/profile/hotbar/Hotbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
@Getter
public class Hotbar {

private final Map<HotbarItem, ItemStack> items = new HashMap<>();
private final Map<HotbarItem, ItemStack> items = new HashMap<>();

public void init() {
public void init() {
FileConfiguration config = Practice.getInstance().getMainConfig().getConfiguration();

ConfigurationSection itemsSection = config.getConfigurationSection("HOTBAR_ITEMS");
Expand Down Expand Up @@ -64,7 +64,7 @@ public void init() {
}
}

public void giveHotbarItems(Player player) {
public void giveHotbarItems(Player player) {
Profile profile = Profile.getByUuid(player.getUniqueId());
PlayerUtil.reset(player);

Expand Down Expand Up @@ -98,7 +98,7 @@ public void giveHotbarItems(Player player) {
player.updateInventory();
}

public HotbarItem fromItemStack(ItemStack itemStack) {
public HotbarItem fromItemStack(ItemStack itemStack) {
for (Map.Entry<HotbarItem, ItemStack> entry : getItems().entrySet()) {
if (entry.getValue() != null && entry.getValue().equals(itemStack)) {
return entry.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void clicked(Player player, ClickType clickType) {
Queue randomQueue = queues.get(rand.nextInt(queues.size()));

player.closeInventory();
randomQueue.addPlayer(player, randomQueue.isRanked() ? profile.getKitData().get(randomQueue.getKit()).getElo() : 0, ranked);
randomQueue.addPlayer(player, randomQueue.isRanked() ? profile.getKitData().get(randomQueue.getKit()).getElo() : 0, !ranked);
randomQueue.addQueue();
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/me/lrxh/practice/setting/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public enum Settings {
SHOW_LINES("Scoreboard Lines", Material.STRING, "Toggle Scoreboard lines."),
THEME("Select Theme", Material.BOOK, "Select Color Theme."),
PING_RANGE("Ping Range", Material.STICK, "Change Ping Range."),
MENU_SOUNDS("Menu Sounds", Material.REDSTONE_COMPARATOR, "Toggle Menu Sounds."),
TIME_CHANGER("Change Time", Material.LEVER, "Change world time.");
MENU_SOUNDS("Menu Sounds", Material.REDSTONE_COMPARATOR, "Toggle Menu Sounds.");

private final String name;
private final Material material;
Expand Down
33 changes: 2 additions & 31 deletions src/main/java/me/lrxh/practice/setting/SettingsMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import me.lrxh.practice.profile.KillEffects;
import me.lrxh.practice.profile.Profile;
import me.lrxh.practice.profile.Themes;
import me.lrxh.practice.profile.Times;
import me.lrxh.practice.profile.visibility.VisibilityLogic;
import me.lrxh.practice.util.CC;
import me.lrxh.practice.util.ItemBuilder;
Expand Down Expand Up @@ -51,9 +50,9 @@ public boolean resetCursor() {
@Override
public Map<Integer, Button> getButtons(Player player) {
HashMap<Integer, Button> buttons = new HashMap<>();
int i = 10;
int i = 9;
for (Settings settings : Settings.values()) {
buttons.put(i+=1, new SettingsButton(settings));
buttons.put(i += 1, new SettingsButton(settings));
}
return buttons;
}
Expand Down Expand Up @@ -138,15 +137,6 @@ public ItemStack getButtonItem(Player player) {
lore.add("&aClick to select");
break;
}
case TIME_CHANGER: {
lore.add(profile.getOptions().time().equals(Times.DAY) ? " &7&l▶ &aDay" : " &7&l▶ &7Day");
lore.add(profile.getOptions().time().equals(Times.NIGHT) ? " &7&l▶ &aNight" : " &7&l▶ &7Night");
lore.add(profile.getOptions().time().equals(Times.SUNRISE) ? " &7&l▶ &aSunrise" : " &7&l▶ &7Sunrise");
lore.add(profile.getOptions().time().equals(Times.SUNSET) ? " &7&l▶ &aSunset" : " &7&l▶ &7Sunset");
lore.add("");
lore.add("&aClick to select");
break;
}
}
return new ItemBuilder(this.settings.getMaterial()).name(Practice.getInstance().getMenusConfig().getString("SETTINGS.SETTING-NAME").replace("<settings>", settings.getName())).lore(lore).clearEnchantments().clearFlags().clearFlags().build();
}
Expand All @@ -164,25 +154,6 @@ public void clicked(Player player, ClickType clickType) {
}
break;
}
case TIME_CHANGER: {
switch (profile.getOptions().time()) {
case DAY:
profile.getOptions().time(Times.NIGHT);
break;
case NIGHT:
profile.getOptions().time(Times.SUNRISE);
break;
case SUNRISE:
profile.getOptions().time(Times.SUNSET);
break;
case SUNSET:
profile.getOptions().time(Times.DAY);
break;
}
player.setPlayerTime(profile.getOptions().time().getTime(), false);
player.sendMessage(Locale.OPTIONS_KILLEFFECT_SELECT.format(player, profile.getOptions().killEffect().getDisplayName()));
break;
}
case MENU_SOUNDS: {
profile.getOptions().menuSounds(!profile.getOptions().menuSounds());
if (profile.getOptions().menuSounds()) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/lrxh/practice/util/PlaceholderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public static List<String> format(List<String> lines, Player player) {
}


if(Practice.getInstance().isPlaceholder()){
if (Practice.getInstance().isPlaceholder()) {
formattedLines.add(PlaceholderAPI.setPlaceholders(player, line));
}else {
} else {
formattedLines.add(line);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ RANKED:
You need {0} more wins!'
DEFAULT-THEME-COLOR: AQUA
LEADERBOARD:
ENABLE-MESSAGE: True
MESSAGE: '&aLeaderboards Refreshed!'
UPDATE-TIME: 1
JOIN_MESSAGE:
- '&7&m--------------------------------'
Expand Down

0 comments on commit 6136b0d

Please sign in to comment.