From bc21f8473d8c9c72bd36590c8f3c2d484b22ff62 Mon Sep 17 00:00:00 2001 From: LordTuxn Date: Sat, 20 Aug 2022 20:09:15 +0200 Subject: [PATCH] improve visibility of open plots when selecting plot difficulty in companion menu --- .../alpsbte/plotsystem/core/system/CityProject.java | 13 +++++++++++-- .../plotsystem/core/system/plot/PlotManager.java | 2 +- .../plotsystem/utils/io/language/LangPaths.java | 1 + src/main/resources/lang/de_DE.yml | 1 + src/main/resources/lang/en_GB.yml | 1 + src/main/resources/lang/fr_FR.yml | 1 + src/main/resources/lang/ko_KR.yml | 1 + src/main/resources/lang/ru_RU.yml | 1 + src/main/resources/lang/zh_CN.yml | 1 + src/main/resources/lang/zh_TW.yml | 1 + 10 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/alpsbte/plotsystem/core/system/CityProject.java b/src/main/java/com/alpsbte/plotsystem/core/system/CityProject.java index 962a18f6..0f70ca63 100644 --- a/src/main/java/com/alpsbte/plotsystem/core/system/CityProject.java +++ b/src/main/java/com/alpsbte/plotsystem/core/system/CityProject.java @@ -100,14 +100,15 @@ public ItemStack getItem(Player player, PlotDifficulty selectedPlotDifficulty) t int plotsOpen = PlotManager.getPlots(getID(), Status.unclaimed).size(); int plotsInProgress = PlotManager.getPlots(getID(), Status.unfinished, Status.unreviewed).size(); int plotsCompleted = PlotManager.getPlots(getID(), Status.completed).size(); - int plotsUnclaimed = PlotManager.getPlots(getID(), cpPlotDifficulty, Status.unclaimed).size(); + int plotsUnclaimed = cpPlotDifficulty != null ? PlotManager.getPlots(getID(), cpPlotDifficulty, Status.unclaimed).size() : 0; + int plotsOpenForPlayer = cpPlotDifficulty != null && plotsUnclaimed != 0 ? getOpenPlotsForPlayer(getID(), cpPlotDifficulty) : 0; return new ItemBuilder(cpItem) .setName("§b§l" + getName()) .setLore(new LoreBuilder() .addLines(getDescription(), "", - "§6" + plotsOpen + " §7" + LangUtil.get(player, LangPaths.CityProject.PROJECT_OPEN), + "§6" + plotsOpen + " §7" + LangUtil.get(player, LangPaths.CityProject.PROJECT_OPEN) + " §8" + LangUtil.get(player, LangPaths.CityProject.FOR_YOUR_DIFFICULTY, (plotsOpenForPlayer == 0 ? "§c" : "§a") + plotsOpenForPlayer + "§8"), "§8---------------------", "§6" + plotsInProgress + " §7" + LangUtil.get(player, LangPaths.CityProject.PROJECT_IN_PROGRESS), "§6" + plotsCompleted + " §7" + LangUtil.get(player, LangPaths.CityProject.PROJECT_COMPLETED), @@ -146,6 +147,14 @@ public static List getCityProjects(Country country, boolean onlyVis return new ArrayList<>(); } + private int getOpenPlotsForPlayer(int plotID, PlotDifficulty plotDifficulty) throws SQLException { + int openPlots = 0; + for (PlotDifficulty pd : PlotDifficulty.values()) { + if (pd.ordinal() <= plotDifficulty.ordinal()) openPlots += PlotManager.getPlots(plotID, pd, Status.unclaimed).size(); + } + return openPlots; + } + public static List getCityProjects(boolean onlyVisible) { return getCityProjects(null, onlyVisible); diff --git a/src/main/java/com/alpsbte/plotsystem/core/system/plot/PlotManager.java b/src/main/java/com/alpsbte/plotsystem/core/system/plot/PlotManager.java index d3437f9d..062f6077 100644 --- a/src/main/java/com/alpsbte/plotsystem/core/system/plot/PlotManager.java +++ b/src/main/java/com/alpsbte/plotsystem/core/system/plot/PlotManager.java @@ -528,7 +528,7 @@ public static CompletableFuture getPlotDifficultyForBuilder(int return CompletableFuture.completedFuture(PlotDifficulty.MEDIUM); } } - return CompletableFuture.completedFuture(PlotDifficulty.HARD); // If nothing is available return hard (plot availability will be checked later additionally) + return CompletableFuture.completedFuture(null); // If nothing is available return null } public static boolean isPlotWorld(World world) { diff --git a/src/main/java/com/alpsbte/plotsystem/utils/io/language/LangPaths.java b/src/main/java/com/alpsbte/plotsystem/utils/io/language/LangPaths.java index 32154006..c4e14adb 100644 --- a/src/main/java/com/alpsbte/plotsystem/utils/io/language/LangPaths.java +++ b/src/main/java/com/alpsbte/plotsystem/utils/io/language/LangPaths.java @@ -36,6 +36,7 @@ public static final class CityProject { public static final String PROJECT_COMPLETED = CITY_PROJECT + "completed"; public static final String PROJECT_PLOTS_AVAILABLE = CITY_PROJECT + "plots-available"; public static final String PROJECT_NO_PLOTS_AVAILABLE = CITY_PROJECT + "no-plots-available"; + public static final String FOR_YOUR_DIFFICULTY = CITY_PROJECT + "for-your-difficulty"; } public static final class Country { diff --git a/src/main/resources/lang/de_DE.yml b/src/main/resources/lang/de_DE.yml index eac502c1..61ba3a9a 100644 --- a/src/main/resources/lang/de_DE.yml +++ b/src/main/resources/lang/de_DE.yml @@ -46,6 +46,7 @@ city-project: completed: "Abgeschlossene Plots" plots-available: 'Plots Verfügbar' no-plots-available: "Keine Plots Verfügbar" + for-your-difficulty: "({0} für deinen Schwierigkeitsgrad)" # ----------------------------------------------------- # | Countries diff --git a/src/main/resources/lang/en_GB.yml b/src/main/resources/lang/en_GB.yml index dc411fd1..d4104fb8 100644 --- a/src/main/resources/lang/en_GB.yml +++ b/src/main/resources/lang/en_GB.yml @@ -46,6 +46,7 @@ city-project: completed: "Plots Completed" plots-available: 'Plots Available' no-plots-available: "No Plots Available" + for-your-difficulty: "({0} for your difficulty)" # ----------------------------------------------------- # | Countries diff --git a/src/main/resources/lang/fr_FR.yml b/src/main/resources/lang/fr_FR.yml index 6265bbc8..ec114aba 100644 --- a/src/main/resources/lang/fr_FR.yml +++ b/src/main/resources/lang/fr_FR.yml @@ -46,6 +46,7 @@ city-project: completed: 'Plots Complété' plots-available: 'Plots Available' no-plots-available: 'Aucun Plots Disponibles' + for-your-difficulty: "({0} for your difficulty)" # ----------------------------------------------------- # | Countries diff --git a/src/main/resources/lang/ko_KR.yml b/src/main/resources/lang/ko_KR.yml index f27470c6..214bcde4 100644 --- a/src/main/resources/lang/ko_KR.yml +++ b/src/main/resources/lang/ko_KR.yml @@ -46,6 +46,7 @@ city-project: completed: "개의 완성된 플롯" plots-available: 'Plots Available' no-plots-available: "건축할 수 있는 플롯이 없음" + for-your-difficulty: "({0} for your difficulty)" # ----------------------------------------------------- # | Countries diff --git a/src/main/resources/lang/ru_RU.yml b/src/main/resources/lang/ru_RU.yml index f2266e03..2d136e69 100644 --- a/src/main/resources/lang/ru_RU.yml +++ b/src/main/resources/lang/ru_RU.yml @@ -46,6 +46,7 @@ city-project: completed: "Завершённых Участков" plots-available: 'Plots Available' no-plots-available: "Доступных Участков Нет" + for-your-difficulty: "({0} for your difficulty)" # ----------------------------------------------------- # | Countries diff --git a/src/main/resources/lang/zh_CN.yml b/src/main/resources/lang/zh_CN.yml index 6b224d08..46bb0f16 100644 --- a/src/main/resources/lang/zh_CN.yml +++ b/src/main/resources/lang/zh_CN.yml @@ -46,6 +46,7 @@ city-project: completed: "已完成建地" plots-available: 'Plots Available' no-plots-available: "无可用建地" + for-your-difficulty: "({0} for your difficulty)" # ----------------------------------------------------- # | Countries diff --git a/src/main/resources/lang/zh_TW.yml b/src/main/resources/lang/zh_TW.yml index 715e6ee0..4389700a 100644 --- a/src/main/resources/lang/zh_TW.yml +++ b/src/main/resources/lang/zh_TW.yml @@ -46,6 +46,7 @@ city-project: completed: "已完成建地" plots-available: 'Plots Available' no-plots-available: "無可用建地" + for-your-difficulty: "({0} for your difficulty)" # ----------------------------------------------------- # | Countries