From 78960844606c19d3225fcf5cc9d01ce882859d7a Mon Sep 17 00:00:00 2001 From: TDR Date: Tue, 28 Feb 2023 17:02:58 +0100 Subject: [PATCH 01/64] bump 1.5-SNAPSHOT --- API/pom.xml | 2 +- AdventureAPI/pom.xml | 4 +- .../core/adventure/api/AdventureAPI.java | 2 +- AdventureCore/pom.xml | 4 +- .../core/adventure/AdventureCore.java | 2 +- Core/pom.xml | 4 +- .../main/java/net/juligames/core/Core.java | 4 +- HazelAPI/pom.xml | 4 +- Master/dependency-reduced-pom.xml | 85 +++++++------- Master/pom.xml | 4 +- MiniGameAPI/pom.xml | 4 +- PaperAPI/pom.xml | 4 +- PaperCore/dependency-reduced-pom.xml | 105 +++++++++--------- PaperCore/pom.xml | 8 +- VelocityAPI/pom.xml | 4 +- VelocityCore/dependency-reduced-pom.xml | 105 +++++++++--------- VelocityCore/pom.xml | 8 +- .../juligames/core/velocity/VelocityCore.java | 2 +- pom.xml | 2 +- 19 files changed, 177 insertions(+), 180 deletions(-) diff --git a/API/pom.xml b/API/pom.xml index 725656b3..baf8ff93 100644 --- a/API/pom.xml +++ b/API/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.4 + 1.5-SNAPSHOT 4.0.0 diff --git a/AdventureAPI/pom.xml b/AdventureAPI/pom.xml index 786499f2..343f6e57 100644 --- a/AdventureAPI/pom.xml +++ b/AdventureAPI/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.4 + 1.5-SNAPSHOT 4.0.0 @@ -24,7 +24,7 @@ net.juligames.core API - 1.4 + 1.5-SNAPSHOT diff --git a/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AdventureAPI.java b/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AdventureAPI.java index 28ca8c2d..3cef11e2 100644 --- a/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AdventureAPI.java +++ b/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AdventureAPI.java @@ -16,7 +16,7 @@ * Please make sure the modules (AdventureAPI & AdventureCore) are the same version to avoid issues while execution! */ public interface AdventureAPI { - @NotNull String API_VERSION = "1.4"; + @NotNull String API_VERSION = "1.5-SNAPSHOT"; static @NotNull AdventureAPI get() { AdventureAPI api = AdventureAPICore.getAPI(); diff --git a/AdventureCore/pom.xml b/AdventureCore/pom.xml index 12f83f0b..fe28c5b2 100644 --- a/AdventureCore/pom.xml +++ b/AdventureCore/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.4 + 1.5-SNAPSHOT 4.0.0 @@ -22,7 +22,7 @@ net.juligames.core AdventureAPI - 1.4 + 1.5-SNAPSHOT diff --git a/AdventureCore/src/main/java/net/juligames/core/adventure/AdventureCore.java b/AdventureCore/src/main/java/net/juligames/core/adventure/AdventureCore.java index 1d08f5ae..6b7d0f34 100644 --- a/AdventureCore/src/main/java/net/juligames/core/adventure/AdventureCore.java +++ b/AdventureCore/src/main/java/net/juligames/core/adventure/AdventureCore.java @@ -18,7 +18,7 @@ * support it. Because of this the AdventureAPI will only function as intended when bundled with the API you are using! */ public class AdventureCore implements AdventureAPI { - final String CORE_VERSION = "1.4"; + final String CORE_VERSION = "1.5-SNAPSHOT"; private CoreAdventureTagManager adventureTagManager; private Logger logger; diff --git a/Core/pom.xml b/Core/pom.xml index 1bb1b4d5..47f30931 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.4 + 1.5-SNAPSHOT 4.0.0 @@ -27,7 +27,7 @@ net.juligames.core HazelAPI - 1.4 + 1.5-SNAPSHOT org.jdbi diff --git a/Core/src/main/java/net/juligames/core/Core.java b/Core/src/main/java/net/juligames/core/Core.java index 3c9005d2..2a3cefe9 100644 --- a/Core/src/main/java/net/juligames/core/Core.java +++ b/Core/src/main/java/net/juligames/core/Core.java @@ -48,9 +48,9 @@ public final class Core implements API { * This can be set depending on the build of the Core */ public static final String CORE_BRAND = "Core"; - public static final String CORE_VERSION_NUMBER = "1.4-SNAPSHOT"; + public static final String CORE_VERSION_NUMBER = "1.5-SNAPSHOT"; public static final String CORE_SPECIFICATION = "Gustav"; - private static final String BUILD_VERSION = "1.4-SNAPSHOT"; //POM VERSION + private static final String BUILD_VERSION = "1.5-SNAPSHOT"; //POM VERSION private static Core core; private final Registerator> hazelcastPostPreparationWorkers = new Registerator<>("hazelcastPostPreparationWorkers"); diff --git a/HazelAPI/pom.xml b/HazelAPI/pom.xml index 68b3b031..a1ad14a5 100644 --- a/HazelAPI/pom.xml +++ b/HazelAPI/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.4 + 1.5-SNAPSHOT 4.0.0 @@ -28,7 +28,7 @@ net.juligames.core API - 1.4 + 1.5-SNAPSHOT compile diff --git a/Master/dependency-reduced-pom.xml b/Master/dependency-reduced-pom.xml index 72cb4602..e4ef9459 100644 --- a/Master/dependency-reduced-pom.xml +++ b/Master/dependency-reduced-pom.xml @@ -1,45 +1,44 @@ - - - JuliGamesCore - net.juligames.core - 1.4 - - 4.0.0 - Master - - - - maven-shade-plugin - 3.4.1 - - - package - - shade - - - - - - - maven-jar-plugin - 3.3.0 - - - - true - net.juligames.core.master.CoreMaster - - - - - - - - 17 - 17 - UTF-8 - + + + JuliGamesCore + net.juligames.core + 1.5-SNAPSHOT + + 4.0.0 + Master + + + + maven-shade-plugin + 3.4.1 + + + package + + shade + + + + + + + maven-jar-plugin + 3.3.0 + + + + true + net.juligames.core.master.CoreMaster + + + + + + + + 17 + 17 + UTF-8 + diff --git a/Master/pom.xml b/Master/pom.xml index a18af302..49b6b804 100644 --- a/Master/pom.xml +++ b/Master/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.4 + 1.5-SNAPSHOT 4.0.0 @@ -22,7 +22,7 @@ net.juligames.core Core - 1.4 + 1.5-SNAPSHOT org.jetbrains diff --git a/MiniGameAPI/pom.xml b/MiniGameAPI/pom.xml index b7363088..26724fd9 100644 --- a/MiniGameAPI/pom.xml +++ b/MiniGameAPI/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.4 + 1.5-SNAPSHOT 4.0.0 @@ -22,7 +22,7 @@ net.juligames.core PaperAPI - 1.4 + 1.5-SNAPSHOT provided diff --git a/PaperAPI/pom.xml b/PaperAPI/pom.xml index d8a51d47..12fbcbc9 100644 --- a/PaperAPI/pom.xml +++ b/PaperAPI/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.4 + 1.5-SNAPSHOT 4.0.0 @@ -28,7 +28,7 @@ net.juligames.core AdventureAPI - 1.4 + 1.5-SNAPSHOT compile diff --git a/PaperCore/dependency-reduced-pom.xml b/PaperCore/dependency-reduced-pom.xml index 597a99cb..833505fb 100644 --- a/PaperCore/dependency-reduced-pom.xml +++ b/PaperCore/dependency-reduced-pom.xml @@ -1,55 +1,54 @@ - - - JuliGamesCore - net.juligames.core - 1.4 - - 4.0.0 - PaperCore - - - - true - src/main/resources - - - - - maven-shade-plugin - 3.4.1 - - - package - - shade - - - - - false - - - - - - - papermc - https://repo.papermc.io/repository/maven-public/ - - - - - io.papermc.paper - paper-api - 1.18.2-R0.1-SNAPSHOT - provided - - - - 17 - 17 - UTF-8 - + + + JuliGamesCore + net.juligames.core + 1.5-SNAPSHOT + + 4.0.0 + PaperCore + + + + true + src/main/resources + + + + + maven-shade-plugin + 3.4.1 + + + package + + shade + + + + + false + + + + + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + io.papermc.paper + paper-api + 1.18.2-R0.1-SNAPSHOT + provided + + + + 17 + 17 + UTF-8 + diff --git a/PaperCore/pom.xml b/PaperCore/pom.xml index ba8c940b..25118555 100644 --- a/PaperCore/pom.xml +++ b/PaperCore/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.4 + 1.5-SNAPSHOT 4.0.0 @@ -16,19 +16,19 @@ net.juligames.core PaperAPI - 1.4 + 1.5-SNAPSHOT compile net.juligames.core Core - 1.4 + 1.5-SNAPSHOT compile net.juligames.core AdventureCore - 1.4 + 1.5-SNAPSHOT compile diff --git a/VelocityAPI/pom.xml b/VelocityAPI/pom.xml index 44ac49ab..a5f93fd7 100644 --- a/VelocityAPI/pom.xml +++ b/VelocityAPI/pom.xml @@ -7,7 +7,7 @@ JuliGamesCore net.juligames.core - 1.4 + 1.5-SNAPSHOT 4.0.0 @@ -30,7 +30,7 @@ net.juligames.core AdventureAPI - 1.4 + 1.5-SNAPSHOT compile diff --git a/VelocityCore/dependency-reduced-pom.xml b/VelocityCore/dependency-reduced-pom.xml index 9a0be885..025447e5 100644 --- a/VelocityCore/dependency-reduced-pom.xml +++ b/VelocityCore/dependency-reduced-pom.xml @@ -1,55 +1,54 @@ - - - JuliGamesCore - net.juligames.core - 1.4 - - 4.0.0 - VelocityCore - - - - maven-shade-plugin - 3.4.1 - - - package - - shade - - - - - false - - - - - - - papermc - papermc - https://repo.papermc.io/repository/maven-public/ - - - juligames-juligames - Juligames Maven - https://maven.juligames.net/juligames - - - - - com.velocitypowered - velocity-api - 3.1.1 - provided - - - - 17 - 17 - UTF-8 - + + + JuliGamesCore + net.juligames.core + 1.5-SNAPSHOT + + 4.0.0 + VelocityCore + + + + maven-shade-plugin + 3.4.1 + + + package + + shade + + + + + false + + + + + + + papermc + papermc + https://repo.papermc.io/repository/maven-public/ + + + juligames-juligames + Juligames Maven + https://maven.juligames.net/juligames + + + + + com.velocitypowered + velocity-api + 3.1.1 + provided + + + + 17 + 17 + UTF-8 + diff --git a/VelocityCore/pom.xml b/VelocityCore/pom.xml index b6a01be7..0884d1bf 100644 --- a/VelocityCore/pom.xml +++ b/VelocityCore/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.4 + 1.5-SNAPSHOT 4.0.0 @@ -22,7 +22,7 @@ net.juligames.core VelocityAPI - 1.4 + 1.5-SNAPSHOT compile @@ -34,13 +34,13 @@ net.juligames.core Core - 1.4 + 1.5-SNAPSHOT compile net.juligames.core AdventureCore - 1.4 + 1.5-SNAPSHOT compile diff --git a/VelocityCore/src/main/java/net/juligames/core/velocity/VelocityCore.java b/VelocityCore/src/main/java/net/juligames/core/velocity/VelocityCore.java index 72bd9e21..6f3ad3b3 100644 --- a/VelocityCore/src/main/java/net/juligames/core/velocity/VelocityCore.java +++ b/VelocityCore/src/main/java/net/juligames/core/velocity/VelocityCore.java @@ -24,7 +24,7 @@ * 03.12.2022 */ -@Plugin(id = "velocitycore", name = "JuliGames Velocity Core", version = "1.4", +@Plugin(id = "velocitycore", name = "JuliGames Velocity Core", version = "1.5-SNAPSHOT", url = "https://github.com/JuliGames/JuliGamesCore", description = "Velocity Client for the core - necessary to provide the API here", authors = {"Ture Bentzin"}) public final class VelocityCore { diff --git a/pom.xml b/pom.xml index 20b1b878..806f3534 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ net.juligames.core JuliGamesCore pom - 1.4 + 1.5-SNAPSHOT PaperCore Core From 940674ab75b7258624fbe8cbae312328389fd385 Mon Sep 17 00:00:00 2001 From: TDR Date: Tue, 28 Feb 2023 18:18:55 +0100 Subject: [PATCH 02/64] Delete identifier.sqlite --- identifier.sqlite | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 identifier.sqlite diff --git a/identifier.sqlite b/identifier.sqlite deleted file mode 100644 index e69de29b..00000000 From 485243019df8e55e2f06c7fcda4833c9b511725f Mon Sep 17 00:00:00 2001 From: TDR Date: Fri, 3 Mar 2023 18:39:01 +0100 Subject: [PATCH 03/64] Update FallBackMessage.java --- .../main/java/net/juligames/core/message/FallBackMessage.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/src/main/java/net/juligames/core/message/FallBackMessage.java b/Core/src/main/java/net/juligames/core/message/FallBackMessage.java index 5f874ead..2cf30a63 100644 --- a/Core/src/main/java/net/juligames/core/message/FallBackMessage.java +++ b/Core/src/main/java/net/juligames/core/message/FallBackMessage.java @@ -9,13 +9,13 @@ public class FallBackMessage extends CoreMessage { + @Deprecated(forRemoval = true) public FallBackMessage() { - this("message not found!"); + this("null"); } public FallBackMessage(final String messageKey) { super(new CreativeMessageBean(messageKey, Core.getInstance().getMessageApi().defaultLocale(), messageKey)); - } } From 7e2c7c01f5611c0e96f70ec5434ca8008cf3eff3 Mon Sep 17 00:00:00 2001 From: TDR Date: Fri, 3 Mar 2023 18:39:03 +0100 Subject: [PATCH 04/64] Delete ApiIntegrityTest.java --- .../juligames/core/paper/ApiIntegrityTest.java | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 PaperAPI/src/main/java/net/juligames/core/paper/ApiIntegrityTest.java diff --git a/PaperAPI/src/main/java/net/juligames/core/paper/ApiIntegrityTest.java b/PaperAPI/src/main/java/net/juligames/core/paper/ApiIntegrityTest.java deleted file mode 100644 index b057a91a..00000000 --- a/PaperAPI/src/main/java/net/juligames/core/paper/ApiIntegrityTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.juligames.core.paper; - -import net.juligames.core.api.API; -import org.bukkit.Bukkit; - -/** - * @author Ture Bentzin - * 21.11.2022 - */ -public class ApiIntegrityTest { - - public static void main(String[] args) { - //Test 1 sendMessage: - PaperMessageRecipient paperMessageRecipient = new PaperMessageRecipient(Bukkit.getConsoleSender()); - API.get().getMessageApi().sendMessage("test.bommels", paperMessageRecipient, new String[]{"hallo", "hallo"}); - } -} From d9d58a588a4d8c6344b4b7c6ca0906bbbe415318 Mon Sep 17 00:00:00 2001 From: TDR Date: Fri, 3 Mar 2023 18:39:37 +0100 Subject: [PATCH 05/64] remove debugs sorry --- .../main/java/net/juligames/core/velocity/VelocityCore.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/VelocityCore/src/main/java/net/juligames/core/velocity/VelocityCore.java b/VelocityCore/src/main/java/net/juligames/core/velocity/VelocityCore.java index 6f3ad3b3..59d980ac 100644 --- a/VelocityCore/src/main/java/net/juligames/core/velocity/VelocityCore.java +++ b/VelocityCore/src/main/java/net/juligames/core/velocity/VelocityCore.java @@ -79,9 +79,6 @@ public void onProxyInitialization(ProxyInitializeEvent event) { }); core.getCommandApi().setCommandHandler(s -> server.getCommandManager().executeAsync(server.getConsoleCommandSource(), s)); - - API.get().getMessageApi().registerMessage("internal.core.velocity.boot", "DEBUG: Velocity is up! :: {0}"); - API.get().getMessageApi().broadcastMessage("internal.core.velocity.boot", new String[]{server.getBoundAddress().getHostString()}); } @Subscribe From ad4d14b021b31d8f77289201a356148977e13f1b Mon Sep 17 00:00:00 2001 From: TDR Date: Fri, 3 Mar 2023 18:48:20 +0100 Subject: [PATCH 06/64] add setIfAbsent --- .../core/api/config/Configuration.java | 67 +++++++++ .../juligames/core/caching/CoreCacheApi.java | 11 ++ .../core/config/CoreConfiguration.java | 133 ++++++++++++++++++ .../core/config/OfflineConfiguration.java | 129 +++++++++++++++++ 4 files changed, 340 insertions(+) diff --git a/API/src/main/java/net/juligames/core/api/config/Configuration.java b/API/src/main/java/net/juligames/core/api/config/Configuration.java index 4a857887..5f8e2fec 100644 --- a/API/src/main/java/net/juligames/core/api/config/Configuration.java +++ b/API/src/main/java/net/juligames/core/api/config/Configuration.java @@ -209,6 +209,73 @@ public interface Configuration extends Comparable { void set(@NotNull BasicPair basicPair); + //ifAbsent + + @ApiStatus.AvailableSince("1.5") + void setStringIfAbsent(@NotNull String key, @NotNull String value); + + @ApiStatus.AvailableSince("1.5") + void setStringIfAbsent(@NotNull String key, @NotNull Supplier value); + + @ApiStatus.AvailableSince("1.5") + void setIntegerIfAbsent(@NotNull String key, @NotNull Integer value); + + @ApiStatus.AvailableSince("1.5") + void setIntegerIfAbsent(@NotNull String key, @NotNull Supplier value); + + @ApiStatus.AvailableSince("1.5") + void setDoubleIfAbsent(@NotNull String key, @NotNull Double value); + + @ApiStatus.AvailableSince("1.5") + void setDoubleIfAbsent(@NotNull String key, @NotNull Supplier value); + + @ApiStatus.AvailableSince("1.5") + void setLongIfAbsent(@NotNull String key, @NotNull Long value); + + @ApiStatus.AvailableSince("1.5") + void setLongIfAbsent(@NotNull String key, @NotNull Supplier value); + + @ApiStatus.AvailableSince("1.5") + void setShortIfAbsent(@NotNull String key, @NotNull Short value); + + @ApiStatus.AvailableSince("1.5") + void setShortIfAbsent(@NotNull String key, @NotNull Supplier value); + + @ApiStatus.AvailableSince("1.5") + void setByteIfAbsent(@NotNull String key, @NotNull Byte value); + + @ApiStatus.AvailableSince("1.5") + void setByteIfAbsent(@NotNull String key, @NotNull Supplier value); + + @ApiStatus.AvailableSince("1.5") + void setBooleanIfAbsent(@NotNull String key, @NotNull Boolean value); + + @ApiStatus.AvailableSince("1.5") + void setBooleanIfAbsent(@NotNull String key, @NotNull Supplier value); + + @ApiStatus.AvailableSince("1.5") + void setFloatIfAbsent(@NotNull String key, @NotNull Float value); + + @ApiStatus.AvailableSince("1.5") + void setFloatIfAbsent(@NotNull String key, @NotNull Supplier value); + + @ApiStatus.AvailableSince("1.5") + void setIfAbsent(@NotNull String key, @NotNull T value, @NotNull Interpreter interpreter); + + @ApiStatus.AvailableSince("1.5") + void setIfAbsent(@NotNull String key, @NotNull Supplier value, @NotNull Interpreter interpreter); + + @ApiStatus.AvailableSince("1.5") + void setIfAbsent(@NotNull Supplier key, @NotNull T value, @NotNull Interpreter interpreter); + + @ApiStatus.AvailableSince("1.5") + void setIfAbsent(@NotNull Supplier key, @NotNull Supplier value, @NotNull Interpreter interpreter); + + @ApiStatus.AvailableSince("1.5") + void setIfAbsent(@NotNull BasicPair basicPair); + + //del + void del(@NotNull String key); void del(@NotNull Supplier keys); diff --git a/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java b/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java index c19b1161..5fbe2e01 100644 --- a/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java +++ b/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java @@ -3,8 +3,13 @@ import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; import de.bentzin.tools.pair.Pair; +import net.juligames.core.api.API; import net.juligames.core.api.cacheing.CacheApi; +import net.juligames.core.api.config.Configuration; import net.juligames.core.api.jdbi.DBMessage; +import org.jetbrains.annotations.ApiStatus; + +import java.util.Properties; /** * @author Ture Bentzin @@ -29,4 +34,10 @@ public Caffeine newBuilder() { public Cache, DBMessage> messageCache() { return MessageCaching.messageCache(); } + + @ApiStatus.AvailableSince("1.5") + public Configuration cachingConfiguration() { + Properties properties = new Properties(); + API.get().getConfigurationApi().getOrCreate() + } } diff --git a/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java b/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java index edd02bea..7f6edc4e 100644 --- a/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java +++ b/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java @@ -777,6 +777,139 @@ public void set(@NotNull BasicPair basicPair) { setString(basicPair.getFirst(), basicPair.getSecond()); } + + //ifAbsent + + @Override + public void setStringIfAbsent(@NotNull String key, @NotNull String value) { + if(isSet(key)) + setString(key,value); + } + + @Override + public void setStringIfAbsent(@NotNull String key, @NotNull Supplier value) { + if(isSet(key)) + setString(key,value); + } + + @Override + public void setIntegerIfAbsent(@NotNull String key, @NotNull Integer value) { + if(isSet(key)) + setInteger(key,value); + } + + @Override + public void setIntegerIfAbsent(@NotNull String key, @NotNull Supplier value) { + if(isSet(key)) + setInteger(key,value); + } + + @Override + public void setDoubleIfAbsent(@NotNull String key, @NotNull Double value) { + if(isSet(key)) + setDouble(key,value); + } + + @Override + public void setDoubleIfAbsent(@NotNull String key, @NotNull Supplier value) { + if(isSet(key)) + setDouble(key,value); + } + + @Override + public void setLongIfAbsent(@NotNull String key, @NotNull Long value) { + if(isSet(key)) + setLong(key,value); + } + + @Override + public void setLongIfAbsent(@NotNull String key, @NotNull Supplier value) { + if(isSet(key)) + setLong(key,value); + } + + @Override + public void setShortIfAbsent(@NotNull String key, @NotNull Short value) { + if(isSet(key)) + setShort(key,value); + } + + @Override + public void setShortIfAbsent(@NotNull String key, @NotNull Supplier value) { + if(isSet(key)) + setShort(key,value); + } + + @Override + public void setByteIfAbsent(@NotNull String key, @NotNull Byte value) { + if(isSet(key)) + setByte(key,value); + } + + @Override + public void setByteIfAbsent(@NotNull String key, @NotNull Supplier value) { + if(isSet(key)) + setByte(key,value); + } + + @Override + public void setBooleanIfAbsent(@NotNull String key, @NotNull Boolean value) { + if(isSet(key)) + setBoolean(key,value); + } + + @Override + public void setBooleanIfAbsent(@NotNull String key, @NotNull Supplier value) { + if(isSet(key)) + setBoolean(key,value); + } + + @Override + public void setFloatIfAbsent(@NotNull String key, @NotNull Float value) { + if(isSet(key)) + setFloat(key,value); + } + + @Override + public void setFloatIfAbsent(@NotNull String key, @NotNull Supplier value) { + if(isSet(key)) + setFloat(key,value); + } + + @Override + public void setIfAbsent(@NotNull String key, @NotNull T value, @NotNull Interpreter interpreter) { + if(isSet(key)) + set(key,value,interpreter); + } + + @Override + public void setIfAbsent(@NotNull String key, @NotNull Supplier value, @NotNull Interpreter interpreter) { + if(isSet(key)) + set(key,value,interpreter); + } + + @Override + public void setIfAbsent(@NotNull Supplier key, @NotNull T value, @NotNull Interpreter interpreter) { + if(isSet(key)) + set(key,value,interpreter); + } + + @Override + public void setIfAbsent(@NotNull Supplier key, @NotNull Supplier value, @NotNull Interpreter interpreter) { + if(isSet(key)) + set(key,value,interpreter); + } + + + @Override + public void setIfAbsent(@NotNull BasicPair basicPair) { + if(isSet(basicPair.getFirst())) + set(basicPair); + } + + + //continue + @Override public void doWithData(@NotNull Consumer> action) { action.accept(hazel()); diff --git a/Core/src/main/java/net/juligames/core/config/OfflineConfiguration.java b/Core/src/main/java/net/juligames/core/config/OfflineConfiguration.java index f1b2e390..3c9becdf 100644 --- a/Core/src/main/java/net/juligames/core/config/OfflineConfiguration.java +++ b/Core/src/main/java/net/juligames/core/config/OfflineConfiguration.java @@ -600,6 +600,135 @@ public void delAllRecursive(@NotNull Supplier> keys) { } + //ifAbsent + + @Override + public void setStringIfAbsent(@NotNull String key, @NotNull String value) { + if(isSet(key)) + setString(key,value); + } + + @Override + public void setStringIfAbsent(@NotNull String key, @NotNull Supplier value) { + if(isSet(key)) + setString(key,value); + } + + @Override + public void setIntegerIfAbsent(@NotNull String key, @NotNull Integer value) { + if(isSet(key)) + setInteger(key,value); + } + + @Override + public void setIntegerIfAbsent(@NotNull String key, @NotNull Supplier value) { + if(isSet(key)) + setInteger(key,value); + } + + @Override + public void setDoubleIfAbsent(@NotNull String key, @NotNull Double value) { + if(isSet(key)) + setDouble(key,value); + } + + @Override + public void setDoubleIfAbsent(@NotNull String key, @NotNull Supplier value) { + if(isSet(key)) + setDouble(key,value); + } + + @Override + public void setLongIfAbsent(@NotNull String key, @NotNull Long value) { + if(isSet(key)) + setLong(key,value); + } + + @Override + public void setLongIfAbsent(@NotNull String key, @NotNull Supplier value) { + if(isSet(key)) + setLong(key,value); + } + + @Override + public void setShortIfAbsent(@NotNull String key, @NotNull Short value) { + if(isSet(key)) + setShort(key,value); + } + + @Override + public void setShortIfAbsent(@NotNull String key, @NotNull Supplier value) { + if(isSet(key)) + setShort(key,value); + } + + @Override + public void setByteIfAbsent(@NotNull String key, @NotNull Byte value) { + if(isSet(key)) + setByte(key,value); + } + + @Override + public void setByteIfAbsent(@NotNull String key, @NotNull Supplier value) { + if(isSet(key)) + setByte(key,value); + } + + @Override + public void setBooleanIfAbsent(@NotNull String key, @NotNull Boolean value) { + if(isSet(key)) + setBoolean(key,value); + } + + @Override + public void setBooleanIfAbsent(@NotNull String key, @NotNull Supplier value) { + if(isSet(key)) + setBoolean(key,value); + } + + @Override + public void setFloatIfAbsent(@NotNull String key, @NotNull Float value) { + if(isSet(key)) + setFloat(key,value); + } + + @Override + public void setFloatIfAbsent(@NotNull String key, @NotNull Supplier value) { + if(isSet(key)) + setFloat(key,value); + } + + @Override + public void setIfAbsent(@NotNull String key, @NotNull T value, @NotNull Interpreter interpreter) { + if(isSet(key)) + set(key,value,interpreter); + } + + @Override + public void setIfAbsent(@NotNull String key, @NotNull Supplier value, @NotNull Interpreter interpreter) { + if(isSet(key)) + set(key,value,interpreter); + } + + @Override + public void setIfAbsent(@NotNull Supplier key, @NotNull T value, @NotNull Interpreter interpreter) { + if(isSet(key)) + set(key,value,interpreter); + } + + @Override + public void setIfAbsent(@NotNull Supplier key, @NotNull Supplier value, @NotNull Interpreter interpreter) { + if(isSet(key)) + set(key,value,interpreter); + } + + + @Override + public void setIfAbsent(@NotNull BasicPair basicPair) { + if(isSet(basicPair.getFirst())) + set(basicPair); + } + //query's From 07d1e3ad07ad0a1d03d2d6fe8970e8225ae31a94 Mon Sep 17 00:00:00 2001 From: TDR Date: Fri, 3 Mar 2023 18:57:09 +0100 Subject: [PATCH 07/64] Update Configuration.java --- .../core/api/config/Configuration.java | 71 ++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/API/src/main/java/net/juligames/core/api/config/Configuration.java b/API/src/main/java/net/juligames/core/api/config/Configuration.java index 5f8e2fec..bf49321b 100644 --- a/API/src/main/java/net/juligames/core/api/config/Configuration.java +++ b/API/src/main/java/net/juligames/core/api/config/Configuration.java @@ -1,6 +1,8 @@ package net.juligames.core.api.config; import de.bentzin.tools.pair.BasicPair; +import de.bentzin.tools.pair.EntryPairAdapter; +import de.bentzin.tools.pair.Pair; import net.juligames.core.api.misc.TriConsumer; import org.checkerframework.checker.optional.qual.MaybePresent; import org.jetbrains.annotations.ApiStatus; @@ -20,7 +22,8 @@ * @see BuildInInterpreters */ @SuppressWarnings("unused") -public interface Configuration extends Comparable { +public interface Configuration extends Comparable, Iterable> { + /** * This keys can be requested but never should be overridden (it is possible to override them, but only consider doing this if you really @@ -336,4 +339,70 @@ public interface Configuration extends Comparable { default int compareTo(@NotNull Configuration o) { return o.size() - size(); } + + + //from map + + /** + * Performs the given action for each entry in this map until all entries + * have been processed or the action throws an exception. Unless + * otherwise specified by the implementing class, actions are performed in + * the order of entry set iteration (if an iteration order is specified.) + * Exceptions thrown by the action are relayed to the caller. + * + * @param action The action to be performed for each entry + * @throws NullPointerException if the specified action is null + * @throws ConcurrentModificationException if an entry is found to be + * removed during iteration + * @implSpec The default implementation is equivalent to, for this {@code map}: + *
 {@code
+     * for (Map.Entry entry : map.entrySet())
+     *     action.accept(entry.getKey(), entry.getValue());
+     * }
+ *

+ * The default implementation makes no guarantees about synchronization + * or atomicity properties of this method. Any implementation providing + * atomicity guarantees must override this method and document its + * concurrency properties. + */ + @ApiStatus.AvailableSince("1.5") + default void forEach(BiConsumer action) { + Objects.requireNonNull(action); + for (Map.Entry entry : entrySet()) { + String k; + String v; + try { + k = entry.getKey(); + v = entry.getValue(); + } catch (IllegalStateException ise) { + // this usually means the entry is no longer in the map. + throw new ConcurrentModificationException(ise); + } + action.accept(k, v); + } + } + + + //Iterable + + @NotNull + @Override + @ApiStatus.AvailableSince("1.5") + default Iterator> iterator() { + return entrySet().stream().map(EntryPairAdapter::pairFromEntry).iterator(); + } + + @Override + @ApiStatus.AvailableSince("1.5") + default void forEach(Consumer> action) { + forEach((s, s2) -> action.accept(new Pair<>(s, s2))); + } + + @Override + @ApiStatus.AvailableSince("1.5") + default Spliterator> spliterator() { + return entrySet().stream().map(EntryPairAdapter::pairFromEntry).spliterator(); + } + + } From 6c01f9a56ec3c085371aea3ca3a97b23de2300cf Mon Sep 17 00:00:00 2001 From: TDR Date: Fri, 3 Mar 2023 18:57:58 +0100 Subject: [PATCH 08/64] fix naming --- .../java/net/juligames/core/api/config/Configuration.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/API/src/main/java/net/juligames/core/api/config/Configuration.java b/API/src/main/java/net/juligames/core/api/config/Configuration.java index bf49321b..8b798526 100644 --- a/API/src/main/java/net/juligames/core/api/config/Configuration.java +++ b/API/src/main/java/net/juligames/core/api/config/Configuration.java @@ -344,7 +344,7 @@ default int compareTo(@NotNull Configuration o) { //from map /** - * Performs the given action for each entry in this map until all entries + * Performs the given action for each entry in this configuration until all entries * have been processed or the action throws an exception. Unless * otherwise specified by the implementing class, actions are performed in * the order of entry set iteration (if an iteration order is specified.) @@ -354,9 +354,9 @@ default int compareTo(@NotNull Configuration o) { * @throws NullPointerException if the specified action is null * @throws ConcurrentModificationException if an entry is found to be * removed during iteration - * @implSpec The default implementation is equivalent to, for this {@code map}: + * @implSpec The default implementation is equivalent to, for this {@code configuration}: *

 {@code
-     * for (Map.Entry entry : map.entrySet())
+     * for (Map.Entry entry : configuration.entrySet())
      *     action.accept(entry.getKey(), entry.getValue());
      * }
*

From 09482d777a6c6f313aae40ae99dedf105d837065 Mon Sep 17 00:00:00 2001 From: TDR Date: Fri, 3 Mar 2023 19:14:46 +0100 Subject: [PATCH 09/64] Create ObjectHashtableToStringHashtableMapper.java --- ...bjectHashtableToStringHashtableMapper.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 API/src/main/java/net/juligames/core/api/misc/ObjectHashtableToStringHashtableMapper.java diff --git a/API/src/main/java/net/juligames/core/api/misc/ObjectHashtableToStringHashtableMapper.java b/API/src/main/java/net/juligames/core/api/misc/ObjectHashtableToStringHashtableMapper.java new file mode 100644 index 00000000..38fe0689 --- /dev/null +++ b/API/src/main/java/net/juligames/core/api/misc/ObjectHashtableToStringHashtableMapper.java @@ -0,0 +1,23 @@ +package net.juligames.core.api.misc; + +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +import java.util.Hashtable; +import java.util.function.Function; + +/** + * @author Ture Bentzin + * 03.03.2023 + */ +@ApiStatus.AvailableSince("1.5") +public class ObjectHashtableToStringHashtableMapper + implements Function, Hashtable> { + + @Override + public Hashtable apply(@NotNull Hashtable objectObjectHashtable) { + final Hashtable stringStringHashtable = new Hashtable<>(); + objectObjectHashtable.forEach((key, value) -> stringStringHashtable.put(key.toString(), value.toString())); + return stringStringHashtable; + } +} From 8a45e7e7ef57fb33c04ac261fd673b2eb0e20aff Mon Sep 17 00:00:00 2001 From: TDR Date: Fri, 3 Mar 2023 19:17:24 +0100 Subject: [PATCH 10/64] add OfflineConfiguration to API --- .../core/api/config/ConfigurationAPI.java | 13 +++ .../core/config/CoreConfiguration.java | 2 +- .../core/config/CoreConfigurationApi.java | 15 +++ .../core/config/OfflineConfiguration.java | 97 +++++++++++-------- 4 files changed, 85 insertions(+), 42 deletions(-) diff --git a/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java b/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java index f9eae7fc..0552db5b 100644 --- a/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java +++ b/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java @@ -6,6 +6,7 @@ import java.util.Collection; import java.util.Comparator; +import java.util.Map; import java.util.Properties; /** @@ -34,6 +35,18 @@ public interface ConfigurationAPI { @NotNull Comparator comparator(); + @NotNull + @ApiStatus.AvailableSince("1.5") + Configuration createNewOfflineConfiguration(String name); + + @NotNull + @ApiStatus.AvailableSince("1.5") + Configuration createNewOfflineConfiguration(Properties defaults); + + @NotNull + @ApiStatus.AvailableSince("1.5") + Configuration createNewOfflineConfiguration(Map defaults); + //collections on demand - 1.1 /** diff --git a/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java b/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java index 7f6edc4e..230be7a8 100644 --- a/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java +++ b/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java @@ -754,7 +754,7 @@ public void copyAndOverrideContentTo(@NotNull Configuration configuration) { } @Override - public @NotNull Configuration copyToOffline(@NotNull String name) { + public @NotNull OfflineConfiguration copyToOffline(@NotNull String name) { OfflineConfiguration offlineConfiguration = new OfflineConfiguration(name); copyAndOverrideContentTo(offlineConfiguration); return offlineConfiguration; diff --git a/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java b/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java index 0dfbe5a5..4b2df072 100644 --- a/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java +++ b/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java @@ -59,6 +59,21 @@ public Configuration database() { return (o1, o2) -> Comparator.naturalOrder().compare(o1, o2); } + @Override + public @NotNull OfflineConfiguration createNewOfflineConfiguration(String name) { + return new OfflineConfiguration(name); + } + + @Override + public @NotNull OfflineConfiguration createNewOfflineConfiguration(Properties defaults) { + return new OfflineConfiguration(defaults); + } + + @Override + public @NotNull OfflineConfiguration createNewOfflineConfiguration(Map defaults) { + return new OfflineConfiguration(defaults.get("configuration_name"), defaults); + } + /** * This will split the given collection using the given interpreter * diff --git a/Core/src/main/java/net/juligames/core/config/OfflineConfiguration.java b/Core/src/main/java/net/juligames/core/config/OfflineConfiguration.java index 3c9becdf..320ab51d 100644 --- a/Core/src/main/java/net/juligames/core/config/OfflineConfiguration.java +++ b/Core/src/main/java/net/juligames/core/config/OfflineConfiguration.java @@ -4,6 +4,7 @@ import net.juligames.core.Core; import net.juligames.core.api.config.Configuration; import net.juligames.core.api.config.Interpreter; +import net.juligames.core.api.misc.ObjectHashtableToStringHashtableMapper; import net.juligames.core.api.misc.TriConsumer; import org.checkerframework.checker.optional.qual.MaybePresent; import org.jetbrains.annotations.NotNull; @@ -37,6 +38,20 @@ public OfflineConfiguration(String name) { assert Objects.equals(getStringOrNull("configuration_name"), name); //just to avoid BNick content in the configurationSystem } + protected OfflineConfiguration(String name, Map customData) { + this.name = name; + data = customData; + data.put("configuration_name", name); + assert Objects.equals(getStringOrNull("configuration_name"), name); + } + + protected OfflineConfiguration(@NotNull Hashtable customData) { + Hashtable local = new ObjectHashtableToStringHashtableMapper().apply(customData); + this.name = local.get("configuration_name"); + data = local; + assert Objects.equals(getStringOrNull("configuration_name"), name); + } + @Override public void updateHazel() { @@ -604,128 +619,128 @@ public void delAllRecursive(@NotNull Supplier> keys) { @Override public void setStringIfAbsent(@NotNull String key, @NotNull String value) { - if(isSet(key)) - setString(key,value); + if (isSet(key)) + setString(key, value); } @Override public void setStringIfAbsent(@NotNull String key, @NotNull Supplier value) { - if(isSet(key)) - setString(key,value); + if (isSet(key)) + setString(key, value); } @Override public void setIntegerIfAbsent(@NotNull String key, @NotNull Integer value) { - if(isSet(key)) - setInteger(key,value); + if (isSet(key)) + setInteger(key, value); } @Override public void setIntegerIfAbsent(@NotNull String key, @NotNull Supplier value) { - if(isSet(key)) - setInteger(key,value); + if (isSet(key)) + setInteger(key, value); } @Override public void setDoubleIfAbsent(@NotNull String key, @NotNull Double value) { - if(isSet(key)) - setDouble(key,value); + if (isSet(key)) + setDouble(key, value); } @Override public void setDoubleIfAbsent(@NotNull String key, @NotNull Supplier value) { - if(isSet(key)) - setDouble(key,value); + if (isSet(key)) + setDouble(key, value); } @Override public void setLongIfAbsent(@NotNull String key, @NotNull Long value) { - if(isSet(key)) - setLong(key,value); + if (isSet(key)) + setLong(key, value); } @Override public void setLongIfAbsent(@NotNull String key, @NotNull Supplier value) { - if(isSet(key)) - setLong(key,value); + if (isSet(key)) + setLong(key, value); } @Override public void setShortIfAbsent(@NotNull String key, @NotNull Short value) { - if(isSet(key)) - setShort(key,value); + if (isSet(key)) + setShort(key, value); } @Override public void setShortIfAbsent(@NotNull String key, @NotNull Supplier value) { - if(isSet(key)) - setShort(key,value); + if (isSet(key)) + setShort(key, value); } @Override public void setByteIfAbsent(@NotNull String key, @NotNull Byte value) { - if(isSet(key)) - setByte(key,value); + if (isSet(key)) + setByte(key, value); } @Override public void setByteIfAbsent(@NotNull String key, @NotNull Supplier value) { - if(isSet(key)) - setByte(key,value); + if (isSet(key)) + setByte(key, value); } @Override public void setBooleanIfAbsent(@NotNull String key, @NotNull Boolean value) { - if(isSet(key)) - setBoolean(key,value); + if (isSet(key)) + setBoolean(key, value); } @Override public void setBooleanIfAbsent(@NotNull String key, @NotNull Supplier value) { - if(isSet(key)) - setBoolean(key,value); + if (isSet(key)) + setBoolean(key, value); } @Override public void setFloatIfAbsent(@NotNull String key, @NotNull Float value) { - if(isSet(key)) - setFloat(key,value); + if (isSet(key)) + setFloat(key, value); } @Override public void setFloatIfAbsent(@NotNull String key, @NotNull Supplier value) { - if(isSet(key)) - setFloat(key,value); + if (isSet(key)) + setFloat(key, value); } @Override public void setIfAbsent(@NotNull String key, @NotNull T value, @NotNull Interpreter interpreter) { - if(isSet(key)) - set(key,value,interpreter); + if (isSet(key)) + set(key, value, interpreter); } @Override public void setIfAbsent(@NotNull String key, @NotNull Supplier value, @NotNull Interpreter interpreter) { - if(isSet(key)) - set(key,value,interpreter); + if (isSet(key)) + set(key, value, interpreter); } @Override public void setIfAbsent(@NotNull Supplier key, @NotNull T value, @NotNull Interpreter interpreter) { - if(isSet(key)) - set(key,value,interpreter); + if (isSet(key)) + set(key, value, interpreter); } @Override public void setIfAbsent(@NotNull Supplier key, @NotNull Supplier value, @NotNull Interpreter interpreter) { - if(isSet(key)) - set(key,value,interpreter); + if (isSet(key)) + set(key, value, interpreter); } @Override public void setIfAbsent(@NotNull BasicPair basicPair) { - if(isSet(basicPair.getFirst())) + if (isSet(basicPair.getFirst())) set(basicPair); } From f1f9424d97c3302bdf92fde09b3e3c9bb7ba4f17 Mon Sep 17 00:00:00 2001 From: TDR Date: Fri, 3 Mar 2023 19:19:55 +0100 Subject: [PATCH 11/64] Update CoreCacheApi.java --- .../main/java/net/juligames/core/caching/CoreCacheApi.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java b/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java index 5fbe2e01..fa5bc34f 100644 --- a/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java +++ b/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java @@ -3,10 +3,13 @@ import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; import de.bentzin.tools.pair.Pair; +import net.juligames.core.Core; import net.juligames.core.api.API; import net.juligames.core.api.cacheing.CacheApi; import net.juligames.core.api.config.Configuration; +import net.juligames.core.api.err.dev.TODOException; import net.juligames.core.api.jdbi.DBMessage; +import net.juligames.core.config.OfflineConfiguration; import org.jetbrains.annotations.ApiStatus; import java.util.Properties; @@ -37,7 +40,6 @@ public Cache, DBMessage> messageCache() { @ApiStatus.AvailableSince("1.5") public Configuration cachingConfiguration() { - Properties properties = new Properties(); - API.get().getConfigurationApi().getOrCreate() + throw new TODOException(); } } From 1413ec8b51d995098209f8f8eac154166387561b Mon Sep 17 00:00:00 2001 From: TDR Date: Fri, 3 Mar 2023 19:24:22 +0100 Subject: [PATCH 12/64] deprecate doWithData --- .../java/net/juligames/core/api/config/Configuration.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/API/src/main/java/net/juligames/core/api/config/Configuration.java b/API/src/main/java/net/juligames/core/api/config/Configuration.java index 8b798526..f4a1dd8a 100644 --- a/API/src/main/java/net/juligames/core/api/config/Configuration.java +++ b/API/src/main/java/net/juligames/core/api/config/Configuration.java @@ -331,8 +331,15 @@ public interface Configuration extends Comparable, Iterable R doWithData(@NotNull Function, R> function); + /** + * @deprecated this method can have serious effects on the integrity of the data managed by the configuration! + * Because of this thread the {@link #setStringIfAbsent(String, String)} methods where introduced. Removal of this method + * may be accomplished later. It is not unlikely that this method will be stripped of its manipulation capabilities and + * will serve only for query operations! + */ @ApiStatus.Experimental @ApiStatus.AvailableSince("1.4") + @Deprecated void doWithData(@NotNull Consumer> action); @Override From 1e177912c3ece951b024da8a837cae54cf5b75ec Mon Sep 17 00:00:00 2001 From: TDR Date: Fri, 3 Mar 2023 19:47:45 +0100 Subject: [PATCH 13/64] add core check to API.get() --- .../main/java/net/juligames/core/api/API.java | 19 ++++ .../core/api/config/Configuration.java | 5 + .../juligames/core/api/err/APIException.java | 4 + .../core/config/CoreConfiguration.java | 91 ++++++++++--------- 4 files changed, 77 insertions(+), 42 deletions(-) diff --git a/API/src/main/java/net/juligames/core/api/API.java b/API/src/main/java/net/juligames/core/api/API.java index 5e2bf20d..658b386e 100644 --- a/API/src/main/java/net/juligames/core/api/API.java +++ b/API/src/main/java/net/juligames/core/api/API.java @@ -44,6 +44,25 @@ public interface API { if (api.isEmpty()) { throw new APIException(); } + if(!Boolean.getBoolean("acknowledgeMissingCoreClass")) + { + //this block provides security over the used implementation of the API class! + try { + Class.forName("net.juligames.core.Core"); //check that the core is installed + } catch (ClassNotFoundException e) { + try{ + api.ifPresent(api1 -> { + api1.getAPILogger().error("Error while providing this instance: " + e.getMessage() + "!"); + api1.getAPILogger().error("It seems like you are operating an unsupported implementation of the Core! \n" + + "You can acknowledge this dangerous behavior by setting the \"-DacknowledgeMissingCoreClass=true\"!"); + }); + }catch (Exception ignored) { + //ok its fucked + throw new APIException(e); + } + throw new APIException(e); + } + } return api.get(); } diff --git a/API/src/main/java/net/juligames/core/api/config/Configuration.java b/API/src/main/java/net/juligames/core/api/config/Configuration.java index f4a1dd8a..9fe1f9f8 100644 --- a/API/src/main/java/net/juligames/core/api/config/Configuration.java +++ b/API/src/main/java/net/juligames/core/api/config/Configuration.java @@ -13,6 +13,7 @@ import java.io.OutputStream; import java.util.*; import java.util.function.*; +import java.util.stream.Stream; /** * @author Ture Bentzin @@ -347,6 +348,10 @@ default int compareTo(@NotNull Configuration o) { return o.size() - size(); } + @ApiStatus.AvailableSince("1.5") + @ApiStatus.Experimental + @NotNull + Stream searchValue(@NotNull String value); //from map diff --git a/API/src/main/java/net/juligames/core/api/err/APIException.java b/API/src/main/java/net/juligames/core/api/err/APIException.java index f3cb3e3e..2c53d897 100644 --- a/API/src/main/java/net/juligames/core/api/err/APIException.java +++ b/API/src/main/java/net/juligames/core/api/err/APIException.java @@ -16,6 +16,10 @@ public APIException(String customMessage) { this.customMessage = customMessage; } + public APIException(Throwable cause) { + super(cause); + } + @Override public String getMessage() { return customMessage; diff --git a/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java b/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java index 230be7a8..c2807117 100644 --- a/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java +++ b/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java @@ -15,6 +15,7 @@ import java.io.OutputStream; import java.util.*; import java.util.function.*; +import java.util.stream.Stream; /** * @author Ture Bentzin @@ -26,7 +27,7 @@ public class CoreConfiguration implements Configuration { private final String name; private String header_comment = Core.getFullCoreName() + " :: a default configuration file"; - private IMap data;//May be removed + private IMap data; public CoreConfiguration(String name) { @@ -782,128 +783,128 @@ public void set(@NotNull BasicPair basicPair) { @Override public void setStringIfAbsent(@NotNull String key, @NotNull String value) { - if(isSet(key)) - setString(key,value); + if (isSet(key)) + setString(key, value); } @Override public void setStringIfAbsent(@NotNull String key, @NotNull Supplier value) { - if(isSet(key)) - setString(key,value); + if (isSet(key)) + setString(key, value); } @Override public void setIntegerIfAbsent(@NotNull String key, @NotNull Integer value) { - if(isSet(key)) - setInteger(key,value); + if (isSet(key)) + setInteger(key, value); } @Override public void setIntegerIfAbsent(@NotNull String key, @NotNull Supplier value) { - if(isSet(key)) - setInteger(key,value); + if (isSet(key)) + setInteger(key, value); } @Override public void setDoubleIfAbsent(@NotNull String key, @NotNull Double value) { - if(isSet(key)) - setDouble(key,value); + if (isSet(key)) + setDouble(key, value); } @Override public void setDoubleIfAbsent(@NotNull String key, @NotNull Supplier value) { - if(isSet(key)) - setDouble(key,value); + if (isSet(key)) + setDouble(key, value); } @Override public void setLongIfAbsent(@NotNull String key, @NotNull Long value) { - if(isSet(key)) - setLong(key,value); + if (isSet(key)) + setLong(key, value); } @Override public void setLongIfAbsent(@NotNull String key, @NotNull Supplier value) { - if(isSet(key)) - setLong(key,value); + if (isSet(key)) + setLong(key, value); } @Override public void setShortIfAbsent(@NotNull String key, @NotNull Short value) { - if(isSet(key)) - setShort(key,value); + if (isSet(key)) + setShort(key, value); } @Override public void setShortIfAbsent(@NotNull String key, @NotNull Supplier value) { - if(isSet(key)) - setShort(key,value); + if (isSet(key)) + setShort(key, value); } @Override public void setByteIfAbsent(@NotNull String key, @NotNull Byte value) { - if(isSet(key)) - setByte(key,value); + if (isSet(key)) + setByte(key, value); } @Override public void setByteIfAbsent(@NotNull String key, @NotNull Supplier value) { - if(isSet(key)) - setByte(key,value); + if (isSet(key)) + setByte(key, value); } @Override public void setBooleanIfAbsent(@NotNull String key, @NotNull Boolean value) { - if(isSet(key)) - setBoolean(key,value); + if (isSet(key)) + setBoolean(key, value); } @Override public void setBooleanIfAbsent(@NotNull String key, @NotNull Supplier value) { - if(isSet(key)) - setBoolean(key,value); + if (isSet(key)) + setBoolean(key, value); } @Override public void setFloatIfAbsent(@NotNull String key, @NotNull Float value) { - if(isSet(key)) - setFloat(key,value); + if (isSet(key)) + setFloat(key, value); } @Override public void setFloatIfAbsent(@NotNull String key, @NotNull Supplier value) { - if(isSet(key)) - setFloat(key,value); + if (isSet(key)) + setFloat(key, value); } @Override public void setIfAbsent(@NotNull String key, @NotNull T value, @NotNull Interpreter interpreter) { - if(isSet(key)) - set(key,value,interpreter); + if (isSet(key)) + set(key, value, interpreter); } @Override public void setIfAbsent(@NotNull String key, @NotNull Supplier value, @NotNull Interpreter interpreter) { - if(isSet(key)) - set(key,value,interpreter); + if (isSet(key)) + set(key, value, interpreter); } @Override public void setIfAbsent(@NotNull Supplier key, @NotNull T value, @NotNull Interpreter interpreter) { - if(isSet(key)) - set(key,value,interpreter); + if (isSet(key)) + set(key, value, interpreter); } @Override public void setIfAbsent(@NotNull Supplier key, @NotNull Supplier value, @NotNull Interpreter interpreter) { - if(isSet(key)) - set(key,value,interpreter); + if (isSet(key)) + set(key, value, interpreter); } @Override public void setIfAbsent(@NotNull BasicPair basicPair) { - if(isSet(basicPair.getFirst())) + if (isSet(basicPair.getFirst())) set(basicPair); } @@ -952,4 +953,10 @@ public String toString() { private void clear() { hazel().clear(); } + + @Override + public @NotNull Stream searchValue(@NotNull String value) { + Predicate> filter = stringStringEntry -> stringStringEntry.getValue().equals(value); + return entrySet().stream().filter(filter).map(Map.Entry::getKey); + } } From 8af9f4e303cf9ef56792cafd9466fc5125d1af84 Mon Sep 17 00:00:00 2001 From: TDR Date: Sat, 4 Mar 2023 14:38:25 +0100 Subject: [PATCH 14/64] add autostart to minigames --- .../juligames/core/config/OfflineConfiguration.java | 7 +++++++ .../juligames/core/paper/PaperCoreEventListener.java | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Core/src/main/java/net/juligames/core/config/OfflineConfiguration.java b/Core/src/main/java/net/juligames/core/config/OfflineConfiguration.java index 320ab51d..2e4cce5d 100644 --- a/Core/src/main/java/net/juligames/core/config/OfflineConfiguration.java +++ b/Core/src/main/java/net/juligames/core/config/OfflineConfiguration.java @@ -15,6 +15,7 @@ import java.io.OutputStream; import java.util.*; import java.util.function.*; +import java.util.stream.Stream; /** * @author Ture Bentzin @@ -905,5 +906,11 @@ public R doWithData(@NotNull Function, R> function) { public void doWithData(@NotNull Consumer> action) { action.accept(data); } + + @Override + public @NotNull Stream searchValue(@NotNull String value) { + Predicate> filter = stringStringEntry -> stringStringEntry.getValue().equals(value); + return entrySet().stream().filter(filter).map(Map.Entry::getKey); + } } diff --git a/PaperCore/src/main/java/net/juligames/core/paper/PaperCoreEventListener.java b/PaperCore/src/main/java/net/juligames/core/paper/PaperCoreEventListener.java index 3284ad01..ceb650e2 100644 --- a/PaperCore/src/main/java/net/juligames/core/paper/PaperCoreEventListener.java +++ b/PaperCore/src/main/java/net/juligames/core/paper/PaperCoreEventListener.java @@ -6,6 +6,7 @@ import net.juligames.core.paper.events.ServerBootFinishedEvent; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; @@ -41,6 +42,17 @@ public void onBoot(ServerBootFinishedEvent event) { } logger.info("Detected plugins depending on core: " + apis); + + + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onBootLow(ServerBootFinishedEvent event) { + Logger logger = API.get().getAPILogger().adopt("boot-low"); + API.get().getLocalMiniGame().ifPresent(basicMiniGame -> { + logger.info("starting: " + basicMiniGame.getPlainName()); + basicMiniGame.start(); + }); } } From e5e1eb9ad56f0368a8dd9f23c0a4113e99c97291 Mon Sep 17 00:00:00 2001 From: TDR Date: Sat, 4 Mar 2023 15:20:02 +0100 Subject: [PATCH 15/64] fix #27 --- .../main/java/net/juligames/core/minigame/api/MiniGame.java | 2 +- .../net/juligames/core/paper/PaperCoreEventListener.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java index 452ee3fb..5616f9f0 100644 --- a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java +++ b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java @@ -102,7 +102,7 @@ public final void start() { @ApiStatus.Internal @SuppressWarnings("OptionalUsedAsFieldOrParameterType") private void handleStartingError(Optional throwable) { - boolean equals = StackWalker.getInstance().getCallerClass().equals(this.getClass()); //EXPERIMENTAL + boolean equals = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass().equals(this.getClass()); //EXPERIMENTAL if (!equals) { throw new SecurityException(); } diff --git a/PaperCore/src/main/java/net/juligames/core/paper/PaperCoreEventListener.java b/PaperCore/src/main/java/net/juligames/core/paper/PaperCoreEventListener.java index ceb650e2..d5c810ee 100644 --- a/PaperCore/src/main/java/net/juligames/core/paper/PaperCoreEventListener.java +++ b/PaperCore/src/main/java/net/juligames/core/paper/PaperCoreEventListener.java @@ -46,9 +46,10 @@ public void onBoot(ServerBootFinishedEvent event) { } - @EventHandler(priority = EventPriority.LOWEST) + @EventHandler(priority = EventPriority.HIGHEST) public void onBootLow(ServerBootFinishedEvent event) { - Logger logger = API.get().getAPILogger().adopt("boot-low"); + Logger logger = API.get().getAPILogger().adopt("boot-high"); + logger.info("running last post-start utilities..."); API.get().getLocalMiniGame().ifPresent(basicMiniGame -> { logger.info("starting: " + basicMiniGame.getPlainName()); basicMiniGame.start(); From f4615d4b3ad7ba646aa67fdc6d480a45e2de5547 Mon Sep 17 00:00:00 2001 From: TDR Date: Sat, 4 Mar 2023 18:41:54 +0100 Subject: [PATCH 16/64] fix StackWalker bug --- .../src/main/java/net/juligames/core/minigame/api/MiniGame.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java index 5616f9f0..dd33ee9d 100644 --- a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java +++ b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java @@ -122,7 +122,7 @@ private void handleStartingError(Optional throwable) { @Override public final void abort() { //ABORT - Class callerClass = StackWalker.getInstance().getCallerClass(); //Deal? + Class callerClass = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass(); getLogger().warning("aborting " + getFullDescription() + " caused by: " + callerClass.getName()); try { onAbort(); From 4fc161f76501ef1c3f579b4bd7ef1c882e927ccf Mon Sep 17 00:00:00 2001 From: TDR Date: Sun, 5 Mar 2023 10:28:40 +0100 Subject: [PATCH 17/64] fixed isses with the APIProvider --- .../core/adventure/api/AdventureAPI.java | 25 ++++++++++++++++++- .../core/adventure/AdventureCore.java | 19 ++++++++++++++ .../main/java/net/juligames/core/Core.java | 2 +- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AdventureAPI.java b/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AdventureAPI.java index 3cef11e2..159212f7 100644 --- a/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AdventureAPI.java +++ b/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AdventureAPI.java @@ -4,6 +4,8 @@ import net.juligames.core.api.err.APIException; import net.juligames.core.api.message.LegacyMessageType; import net.juligames.core.api.message.MessageApi; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.text.Component; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -29,10 +31,31 @@ public interface AdventureAPI { @Deprecated @ApiStatus.AvailableSince("1.4") - void registerLegacyMessage(MessageApi messageApi, @NotNull String key, @NotNull String input, @NotNull LegacyMessageType legacyMessageType); + void registerLegacyMessage(@NotNull MessageApi messageApi, @NotNull String key, @NotNull String input, @NotNull LegacyMessageType legacyMessageType); @Deprecated @ApiStatus.AvailableSince("1.4") void registerLegacyMessage(@NotNull String key, @NotNull String input, @NotNull LegacyMessageType legacyMessageType); + /** + * This Method is a shortcut for the MessageAPI. + * It supplies the best message for the given key and locale (through audience) + * This is default implementation: + * {@code return getAdventureTagManager().resolve(API.get().getMessageApi(). + * getMessageSmart(messageKey,audience.get(Identity.LOCALE).orElseThrow(), replacements));} + */ + @ApiStatus.AvailableSince("1.5") + @NotNull Component forAudience(@NotNull String messageKey, @NotNull Audience audience, String... replacements); + + + /** + * This Method is a shortcut for the MessageAPI. + * It supplies the best message for the given key and locale (through audience) + * This is default implementation: + * {@code return getAdventureTagManager().resolve(API.get().getMessageApi(). + * getMessageSmart(messageKey,audience.get(Identity.LOCALE).orElseThrow()));} + */ + @ApiStatus.AvailableSince("1.5") + @NotNull Component forAudience(@NotNull String messageKey, @NotNull Audience audience); + } diff --git a/AdventureCore/src/main/java/net/juligames/core/adventure/AdventureCore.java b/AdventureCore/src/main/java/net/juligames/core/adventure/AdventureCore.java index 6b7d0f34..75851df6 100644 --- a/AdventureCore/src/main/java/net/juligames/core/adventure/AdventureCore.java +++ b/AdventureCore/src/main/java/net/juligames/core/adventure/AdventureCore.java @@ -7,9 +7,15 @@ import net.juligames.core.api.API; import net.juligames.core.api.message.LegacyMessageType; import net.juligames.core.api.message.MessageApi; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.identity.Identity; +import net.kyori.adventure.text.Component; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; +import java.util.Locale; +import java.util.UUID; + /** * @author Ture Bentzin * 21.11.2022 @@ -37,6 +43,7 @@ public void start() { logger.warning("AdventureAPI is at: " + API_VERSION); logger.warning("AdventureCore is at: " + CORE_VERSION); logger.warning("Core is at: " + buildVersion); + logger.warning("You will not receive support for this unsafe combination!"); logger.warning("---------------------------------------------------------------------------------"); } @@ -76,6 +83,18 @@ public void registerLegacyMessage(@NotNull String key, @NotNull String input, registerLegacyMessage(API.get().getMessageApi(), key, input, legacyMessageType); } + @Override + public @NotNull Component forAudience(@NotNull String messageKey, @NotNull Audience audience, String... replacements) { + return getAdventureTagManager().resolve(API.get().getMessageApi(). + getMessageSmart(messageKey,audience.get(Identity.LOCALE).orElseThrow(), replacements)); + } + + @Override + public @NotNull Component forAudience(@NotNull String messageKey, @NotNull Audience audience) { + return getAdventureTagManager().resolve(API.get().getMessageApi(). + getMessageSmart(messageKey,audience.get(Identity.LOCALE).orElseThrow())); + } + @ApiStatus.Internal public Logger logger() { return logger; diff --git a/Core/src/main/java/net/juligames/core/Core.java b/Core/src/main/java/net/juligames/core/Core.java index 2a3cefe9..dc06a0cf 100644 --- a/Core/src/main/java/net/juligames/core/Core.java +++ b/Core/src/main/java/net/juligames/core/Core.java @@ -116,7 +116,7 @@ public void start(String core_name, @NotNull Logger logger, boolean member) { this.core_name = core_name; if (core != null) throw new IllegalStateException("seems like a core is already running!"); core = this; - ApiProvider.CURRENT_API = this; + ApiProvider.insert(this); if (!member) hazelConnector = HazelConnector.getInstanceAndConnect(core_name); else From 5a7b8cd66f9352c123da585f14bf651b039822dd Mon Sep 17 00:00:00 2001 From: TDR Date: Sun, 5 Mar 2023 10:42:03 +0100 Subject: [PATCH 18/64] add errorprone --- Core/pom.xml | 12 ++++++++---- .../core/command/inbuild/InbuiltCommand.java | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Core/pom.xml b/Core/pom.xml index 47f30931..964a48dd 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -10,11 +10,10 @@ 4.0.0 + + Core - - - - + @@ -35,6 +34,11 @@ 3.34.0 + + com.google.errorprone + javac + 9+181-r4173-1 + org.jetbrains diff --git a/Core/src/main/java/net/juligames/core/command/inbuild/InbuiltCommand.java b/Core/src/main/java/net/juligames/core/command/inbuild/InbuiltCommand.java index aeb447eb..bdf34652 100644 --- a/Core/src/main/java/net/juligames/core/command/inbuild/InbuiltCommand.java +++ b/Core/src/main/java/net/juligames/core/command/inbuild/InbuiltCommand.java @@ -1,6 +1,7 @@ package net.juligames.core.command.inbuild; import net.juligames.core.Core; +import org.checkerframework.checker.initialization.qual.UnderInitialization; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -13,6 +14,7 @@ * 17.02.2023 */ @ApiStatus.Experimental + public class InbuiltCommand implements CommandExecutor { private final String name; private final String description; From e16f498a1934101c2a3e3ad2b60071a50f631690 Mon Sep 17 00:00:00 2001 From: Ture Bentzin Date: Mon, 6 Mar 2023 13:41:04 +0100 Subject: [PATCH 19/64] add PreDefinedInsertionProcedure --- .../team/procedures/InsertionProcedure.java | 3 +- .../PreDefinedInsertionProcedure.java | 28 +++++++++++++++++++ identifier.sqlite | 0 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/PreDefinedInsertionProcedure.java create mode 100644 identifier.sqlite diff --git a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/InsertionProcedure.java b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/InsertionProcedure.java index bc10cee2..58b9dd1d 100644 --- a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/InsertionProcedure.java +++ b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/InsertionProcedure.java @@ -11,5 +11,6 @@ * 18.12.2022 */ public sealed interface InsertionProcedure extends BiFunction, UUID, Boolean> - permits ComparatorInsertionProcedure, ConsumerInsertionProcedure, IterativeInsertionProcedure, RandomInsertionProcedure, SwitchingInsertionProcedure, WhiteListInsertionProcedure { + permits ComparatorInsertionProcedure, ConsumerInsertionProcedure, IterativeInsertionProcedure, + PreDefinedInsertionProcedure, RandomInsertionProcedure, SwitchingInsertionProcedure, WhiteListInsertionProcedure { } diff --git a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/PreDefinedInsertionProcedure.java b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/PreDefinedInsertionProcedure.java new file mode 100644 index 00000000..d40b4f5f --- /dev/null +++ b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/PreDefinedInsertionProcedure.java @@ -0,0 +1,28 @@ +package net.juligames.core.minigame.api.team.procedures; + +import net.juligames.core.minigame.api.team.Team; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +public final class PreDefinedInsertionProcedure implements InsertionProcedure{ + + private final Map preDefinedTeaming; + + public PreDefinedInsertionProcedure(Map preDefinedTeaming) { + + this.preDefinedTeaming = preDefinedTeaming; + } + @Override + public @NotNull Boolean apply(Set teams, UUID uuid) { + if(preDefinedTeaming.containsKey(uuid)) { + Team should = preDefinedTeaming.get(uuid); + if(teams.contains(should)) { + return should.tryAdd(uuid); + } + } + return false; + } +} diff --git a/identifier.sqlite b/identifier.sqlite new file mode 100644 index 00000000..e69de29b From 5c80025dd2ef30f3ed6f361e7dd28a3fa7b809fc Mon Sep 17 00:00:00 2001 From: Ture Bentzin Date: Mon, 6 Mar 2023 13:54:08 +0100 Subject: [PATCH 20/64] start fixing the SwitchingInsertionProcedure --- .../api/team/procedures/SwitchingInsertionProcedure.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/SwitchingInsertionProcedure.java b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/SwitchingInsertionProcedure.java index 48276b22..a9468c04 100644 --- a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/SwitchingInsertionProcedure.java +++ b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/SwitchingInsertionProcedure.java @@ -24,10 +24,16 @@ public final class SwitchingInsertionProcedure implements InsertionProcedure { @Contract(pure = true) @Override public @NotNull Boolean apply(@NotNull Set teams, UUID uuid) { + if (lastTeam == null) { + teams.stream().findAny().ifPresentOrElse(team -> lastTeam = team, + () -> { + throw new IllegalArgumentException("lastTeam is null and there is no team available to be selected!"); + }); + } if (!teams.contains(lastTeam)) { throw new IllegalArgumentException("lastTeam of this SwitchingInsertionProcedure is not part of teams!"); } - return new ComparatorInsertionProcedure((o1, o2) -> { //needs testing - maybe reversed order + return new ComparatorInsertionProcedure((o1, o2) -> { //needs testing - maybe reversed order - not running - no feedback on what team was selected... if (o2 == lastTeam) return 1; if (o2 == o1 || o2.equals(o1)) return 0; return -1; From f9e1b687490f33a012f6e5711075f4520321b744 Mon Sep 17 00:00:00 2001 From: TDR Date: Mon, 6 Mar 2023 15:38:32 +0100 Subject: [PATCH 21/64] add javadoc --- .../juligames/core/api/message/MessageApi.java | 17 +++++++++++++++++ .../adventure/api/AudienceMessageRecipient.java | 6 +++++- .../core/command/inbuild/InbuiltCommand.java | 1 - 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/API/src/main/java/net/juligames/core/api/message/MessageApi.java b/API/src/main/java/net/juligames/core/api/message/MessageApi.java index aa6ec978..183a85e6 100644 --- a/API/src/main/java/net/juligames/core/api/message/MessageApi.java +++ b/API/src/main/java/net/juligames/core/api/message/MessageApi.java @@ -21,6 +21,23 @@ @SuppressWarnings("unused") public interface MessageApi { + @SafeVarargs + @ApiStatus.AvailableSince("1.5") + static T[] arrFromVargs(T... ts) { + return ts; + } + + + /** + * This is an alias for {@link #arrFromVargs(Object[])} + * @apiNote You should import this method static! + */ + @SafeVarargs + @ApiStatus.AvailableSince("1.5") + static T[] repl(T... ts) { + return arrFromVargs(ts); + } + //DAO @ApiStatus.Internal @ApiStatus.Experimental diff --git a/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AudienceMessageRecipient.java b/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AudienceMessageRecipient.java index 6d993da0..2e15b126 100644 --- a/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AudienceMessageRecipient.java +++ b/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AudienceMessageRecipient.java @@ -34,8 +34,12 @@ public AudienceMessageRecipient(@NotNull String name, @NotNull Supplier this.audience = audience; } + /** + * + * @param audience needs to be able to provide {@link Identity#LOCALE} + * @return the {@link AudienceMessageRecipient} + */ @Contract("_ -> new") - @ApiStatus.Experimental public static @NotNull AudienceMessageRecipient getByPointer(@NotNull Audience audience) { String ls = API.get().getHazelDataApi().getMasterInformation().get("default_locale"); Locale locale = (audience.pointers().get(Identity.LOCALE).orElse(null)); diff --git a/Core/src/main/java/net/juligames/core/command/inbuild/InbuiltCommand.java b/Core/src/main/java/net/juligames/core/command/inbuild/InbuiltCommand.java index bdf34652..2f31752c 100644 --- a/Core/src/main/java/net/juligames/core/command/inbuild/InbuiltCommand.java +++ b/Core/src/main/java/net/juligames/core/command/inbuild/InbuiltCommand.java @@ -14,7 +14,6 @@ * 17.02.2023 */ @ApiStatus.Experimental - public class InbuiltCommand implements CommandExecutor { private final String name; private final String description; From c68b65b909319f3f17546e2107966ad17166417f Mon Sep 17 00:00:00 2001 From: TDR Date: Mon, 6 Mar 2023 16:17:30 +0100 Subject: [PATCH 22/64] add createSectionClone and new Interpreters --- .../core/api/config/BuildInInterpreters.java | 15 +++++++ .../core/api/config/ConfigurationAPI.java | 22 +++++++--- .../core/config/CoreConfigurationApi.java | 12 +++++ .../juligames/core/data/HazelDataCore.java | 12 ++++- .../api/hazel/HazelObjectInterpreter.java | 44 +++++++++++++++++++ .../core/api/hazel/NativeHazelDataAPI.java | 8 ++++ 6 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 HazelAPI/src/main/java/net/juligames/core/api/hazel/HazelObjectInterpreter.java diff --git a/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java b/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java index b6a8011d..07efd93f 100644 --- a/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java +++ b/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java @@ -9,6 +9,7 @@ import java.text.DateFormat; import java.time.Instant; import java.util.Date; +import java.util.Map; import java.util.UUID; /** @@ -51,5 +52,19 @@ public interface BuildInInterpreters { return s -> s; } + @Contract(pure = true) + static @NotNull Interpreter> clazzInterpreter() { + return new Interpreter<>() { + @Override + public @NotNull Class interpret(String input) throws Exception { + return Class.forName(input); + } + + @Override + public @NotNull String reverse(Class tClass) { + return tClass.getName(); + } + }; + } } diff --git a/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java b/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java index 0552db5b..a6ebf1fa 100644 --- a/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java +++ b/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java @@ -37,15 +37,15 @@ public interface ConfigurationAPI { @NotNull @ApiStatus.AvailableSince("1.5") - Configuration createNewOfflineConfiguration(String name); + Configuration createNewOfflineConfiguration(@NotNull String name); @NotNull @ApiStatus.AvailableSince("1.5") - Configuration createNewOfflineConfiguration(Properties defaults); + Configuration createNewOfflineConfiguration(@NotNull Properties defaults); @NotNull @ApiStatus.AvailableSince("1.5") - Configuration createNewOfflineConfiguration(Map defaults); + Configuration createNewOfflineConfiguration(@NotNull Map defaults); //collections on demand - 1.1 @@ -80,7 +80,7 @@ public interface ConfigurationAPI { * @deprecated moved to {@link Configuration#setIterable(String, Iterable, Interpreter)} */ @Deprecated - default void spiltAndWrite(@NotNull Collection collection, @NotNull Interpreter interpreter, @NotNull Configuration configuration, String keySpace) { + default void spiltAndWrite(@NotNull Collection collection, @NotNull Interpreter interpreter, @NotNull Configuration configuration, @NotNull String keySpace) { splitToWriter(collection, interpreter).write(configuration, keySpace); } @@ -117,5 +117,17 @@ default void spiltAndWrite(@NotNull Collection collection, @NotNull Inter @NotNull Properties initializeProperties(@NotNull String name, @Nullable String header); @ApiStatus.Experimental - @NotNull Configuration merge(Configuration c1, Configuration c2); + @NotNull Configuration merge(@NotNull Configuration c1, @NotNull Configuration c2); + + /** + * This method allows better narrowed down handling of individual "objects" that are stored in multiple keys and values. + * I'm currently testing this. It might be removed later. You should keep in mind that the Core Configurations are not + * a section based system! All section operations are "hacked" over a flat structure. The Configurations don't really offer + * depth... + * @param root the root + * @param section the section + * @return an OfflineConfiguration. Changes to this will not affect root + */ + @ApiStatus.AvailableSince("1.5") + @NotNull Configuration createSectionClone(@NotNull Configuration root, @NotNull String section); } diff --git a/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java b/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java index 4b2df072..bd27fe66 100644 --- a/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java +++ b/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java @@ -149,4 +149,16 @@ public Configuration database() { c1.copyAndAppendContentTo(c2); return c1; } + + @Override + @ApiStatus.Experimental + public @NotNull Configuration createSectionClone(@NotNull Configuration root, @NotNull String section) { + return new OfflineConfiguration(section + "@" + root, + new HashMap<>(root.entrySet().stream() + .filter(stringStringEntry -> stringStringEntry.getKey().startsWith(section + "_")) + .map(s -> { + String after = s.getKey().replaceFirst(section + "_", ""); + return Map.entry(section + "_" + after.substring(0, after.indexOf("_")), s.getValue()); + }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))); + } } diff --git a/Core/src/main/java/net/juligames/core/data/HazelDataCore.java b/Core/src/main/java/net/juligames/core/data/HazelDataCore.java index 846cb8a7..d5039621 100644 --- a/Core/src/main/java/net/juligames/core/data/HazelDataCore.java +++ b/Core/src/main/java/net/juligames/core/data/HazelDataCore.java @@ -3,6 +3,7 @@ import com.hazelcast.collection.IList; import com.hazelcast.collection.IQueue; import com.hazelcast.collection.ISet; +import com.hazelcast.core.DistributedObject; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.map.IMap; import com.hazelcast.topic.ITopic; @@ -11,12 +12,14 @@ import net.juligames.core.api.hazel.NativeHazelDataAPI; import org.jetbrains.annotations.NotNull; +import java.util.Collection; + /** * @author Ture Bentzin * 16.11.2022 */ public final class HazelDataCore implements HazelDataApi, NativeHazelDataAPI { - private static HazelcastInstance getHazelcastInstance() { + private static @NotNull HazelcastInstance getHazelcastInstance() { return Core.getInstance().getOrThrow(); } @@ -45,9 +48,14 @@ private static HazelcastInstance getHazelcastInstance() { } @Override - public @NotNull ITopic getTopic(String hazel) { + public @NotNull ITopic getTopic(@NotNull String hazel) { return getHazelcastInstance().getTopic(hazel); } + @Override + public @NotNull Collection getAll() { + return getHazelcastInstance().getDistributedObjects(); + } + } diff --git a/HazelAPI/src/main/java/net/juligames/core/api/hazel/HazelObjectInterpreter.java b/HazelAPI/src/main/java/net/juligames/core/api/hazel/HazelObjectInterpreter.java new file mode 100644 index 00000000..8475a61b --- /dev/null +++ b/HazelAPI/src/main/java/net/juligames/core/api/hazel/HazelObjectInterpreter.java @@ -0,0 +1,44 @@ +package net.juligames.core.api.hazel; + +import com.hazelcast.core.DistributedObject; +import com.hazelcast.core.HazelcastInstance; +import net.juligames.core.api.config.Interpreter; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.function.Supplier; + +/** + * @author Ture Bentzin + * 06.03.2023 + */ +public class HazelObjectInterpreter implements Interpreter { + + private final @NotNull Supplier> collectionSupplier; + + @Contract(pure = true) + public HazelObjectInterpreter(@NotNull HazelcastInstance instance) { + collectionSupplier = instance::getDistributedObjects; + } + + public HazelObjectInterpreter(@NotNull Supplier> collectionSupplier) { + this.collectionSupplier = collectionSupplier; + } + + @Contract("_ -> new") + public static @NotNull HazelObjectInterpreter get(@NotNull NativeHazelDataAPI nativeHazelDataAPI) { + return new HazelObjectInterpreter(nativeHazelDataAPI::getAll); + } + + @Override + public @NotNull DistributedObject interpret(String input) throws Exception { + return collectionSupplier.get().stream().filter(distributedObject -> + distributedObject.getName().equals(input)).findFirst().orElseThrow(); + } + + @Override + public @NotNull String reverse(@NotNull DistributedObject distributedObject) { + return distributedObject.getName(); + } +} diff --git a/HazelAPI/src/main/java/net/juligames/core/api/hazel/NativeHazelDataAPI.java b/HazelAPI/src/main/java/net/juligames/core/api/hazel/NativeHazelDataAPI.java index 72a70215..2854a9ad 100644 --- a/HazelAPI/src/main/java/net/juligames/core/api/hazel/NativeHazelDataAPI.java +++ b/HazelAPI/src/main/java/net/juligames/core/api/hazel/NativeHazelDataAPI.java @@ -3,8 +3,12 @@ import com.hazelcast.collection.IList; import com.hazelcast.collection.IQueue; import com.hazelcast.collection.ISet; +import com.hazelcast.core.DistributedObject; import com.hazelcast.map.IMap; import com.hazelcast.topic.ITopic; +import org.jetbrains.annotations.ApiStatus; + +import java.util.Collection; /** * @author Ture Bentzin @@ -58,4 +62,8 @@ public interface NativeHazelDataAPI { * @return the ITopic associated to the hazel */ ITopic getTopic(String hazel); + + @ApiStatus.Experimental + @ApiStatus.AvailableSince("1.5") + Collection getAll(); } From c564eae689f5d2705e373024a42703af8407089b Mon Sep 17 00:00:00 2001 From: TDR Date: Tue, 7 Mar 2023 19:26:33 +0100 Subject: [PATCH 23/64] add Environment and Property Interpreter --- .../env/EnviromentVariableInterpreter.java | 22 +++++ .../api/config/env/EnvironmentVariable.java | 16 ++++ .../config/property/PropertyInterpreter.java | 86 +++++++++++++++++++ .../api/hazel/HazelObjectInterpreter.java | 2 + 4 files changed, 126 insertions(+) create mode 100644 API/src/main/java/net/juligames/core/api/config/env/EnviromentVariableInterpreter.java create mode 100644 API/src/main/java/net/juligames/core/api/config/env/EnvironmentVariable.java create mode 100644 API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java diff --git a/API/src/main/java/net/juligames/core/api/config/env/EnviromentVariableInterpreter.java b/API/src/main/java/net/juligames/core/api/config/env/EnviromentVariableInterpreter.java new file mode 100644 index 00000000..4cdd977e --- /dev/null +++ b/API/src/main/java/net/juligames/core/api/config/env/EnviromentVariableInterpreter.java @@ -0,0 +1,22 @@ +package net.juligames.core.api.config.env; + +import net.juligames.core.api.config.Interpreter; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +/** + * @author Ture Bentzin + * 07.03.2023 + */ +@ApiStatus.AvailableSince("1.5") +public class EnviromentVariableInterpreter implements Interpreter { + @Override + public @NotNull EnvironmentVariable interpret(String input) throws Exception { + return new EnvironmentVariable(input); + } + + @Override + public @NotNull String reverse(@NotNull EnvironmentVariable environmentVariable) { + return environmentVariable.key(); + } +} diff --git a/API/src/main/java/net/juligames/core/api/config/env/EnvironmentVariable.java b/API/src/main/java/net/juligames/core/api/config/env/EnvironmentVariable.java new file mode 100644 index 00000000..a0481981 --- /dev/null +++ b/API/src/main/java/net/juligames/core/api/config/env/EnvironmentVariable.java @@ -0,0 +1,16 @@ +package net.juligames.core.api.config.env; + +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +/** + * @author Ture Bentzin + * 07.03.2023 + */ +@ApiStatus.AvailableSince("1.5") +public record EnvironmentVariable(String key) { + + public @NotNull String get() { + return System.getenv().get(key()); + } +} diff --git a/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java b/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java new file mode 100644 index 00000000..2141388a --- /dev/null +++ b/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java @@ -0,0 +1,86 @@ +package net.juligames.core.api.config.property; + +import net.juligames.core.api.config.Interpreter; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Function; + +/** + * The {@link PropertyInterpreter} allows to store a reference to a property that is set. The value that is read will + * be used as the "key" for getting the property. If you {@link #reverse(Object)} then {@link String#valueOf(Object)} + * will be used + * + * @author Ture Bentzin + * 07.03.2023 + */ +@SuppressWarnings("unused") +@ApiStatus.AvailableSince("1.5") +public final class PropertyInterpreter implements Interpreter { + + private final @NotNull Function getter; + + private PropertyInterpreter(@NotNull Function getter) { + this.getter = getter; + } + + @Contract(value = " -> new", pure = true) + public static @NotNull PropertyInterpreter stringPropertyInterpreter() { + return new PropertyInterpreter<>(System::getProperty); + } + + @Contract(value = " -> new", pure = true) + public static @NotNull PropertyInterpreter booleanPropertyInterpreter() { + return new PropertyInterpreter<>(Boolean::getBoolean); + } + + @Contract(value = " -> new", pure = true) + public static @NotNull PropertyInterpreter integerPropertyInterpreter() { + return new PropertyInterpreter<>(Integer::getInteger); + } + + @Contract(value = " -> new", pure = true) + public static @NotNull PropertyInterpreter doublePropertyInterpreter() { + return new PropertyInterpreter<>(s -> Double.parseDouble(System.getProperty(s))); + } + + @Contract(value = " -> new", pure = true) + public static @NotNull PropertyInterpreter floatPropertyInterpreter() { + return new PropertyInterpreter<>(s -> Float.parseFloat(System.getProperty(s))); + } + + @Contract(value = " -> new", pure = true) + public static @NotNull PropertyInterpreter shortPropertyInterpreter() { + return new PropertyInterpreter<>(s -> Short.parseShort(System.getProperty(s))); + } + + @Contract(value = " -> new", pure = true) + public static @NotNull PropertyInterpreter bytePropertyInterpreter() { + return new PropertyInterpreter<>(s -> Byte.parseByte(System.getProperty(s))); + } + + @Contract(value = " -> new", pure = true) + public static @NotNull PropertyInterpreter charPropertyInterpreter() { + return new PropertyInterpreter<>(s -> System.getProperty(s).charAt(0)); + } + + @Contract(value = " -> new", pure = true) + public static @NotNull PropertyInterpreter longPropertyInterpreter() { + return new PropertyInterpreter<>(Long::getLong); + } + + @Override + public @NotNull E interpret(@NotNull String input) throws Exception { + return getter.apply(input); + } + + @Override + public @NotNull String reverse(@NotNull E e) { + return String.valueOf(e); + } + + public @NotNull Function getGetter() { + return getter; + } +} diff --git a/HazelAPI/src/main/java/net/juligames/core/api/hazel/HazelObjectInterpreter.java b/HazelAPI/src/main/java/net/juligames/core/api/hazel/HazelObjectInterpreter.java index 8475a61b..302a4aef 100644 --- a/HazelAPI/src/main/java/net/juligames/core/api/hazel/HazelObjectInterpreter.java +++ b/HazelAPI/src/main/java/net/juligames/core/api/hazel/HazelObjectInterpreter.java @@ -3,6 +3,7 @@ import com.hazelcast.core.DistributedObject; import com.hazelcast.core.HazelcastInstance; import net.juligames.core.api.config.Interpreter; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -13,6 +14,7 @@ * @author Ture Bentzin * 06.03.2023 */ +@ApiStatus.AvailableSince("1.5") public class HazelObjectInterpreter implements Interpreter { private final @NotNull Supplier> collectionSupplier; From 776bf385936ecba4666f447d21d0adfd54324c9b Mon Sep 17 00:00:00 2001 From: TDR Date: Tue, 7 Mar 2023 19:46:40 +0100 Subject: [PATCH 24/64] upgrade environment interpreter --- .../env/EnviromentVariableInterpreter.java | 22 ------- .../api/config/env/EnvironmentVariable.java | 2 +- .../env/EnvironmentVariableInterpreter.java | 18 ++++++ .../api/config/env/MapFeedInterpreter.java | 58 +++++++++++++++++++ .../core/api/config/env/MapPart.java | 14 +++++ 5 files changed, 91 insertions(+), 23 deletions(-) delete mode 100644 API/src/main/java/net/juligames/core/api/config/env/EnviromentVariableInterpreter.java create mode 100644 API/src/main/java/net/juligames/core/api/config/env/EnvironmentVariableInterpreter.java create mode 100644 API/src/main/java/net/juligames/core/api/config/env/MapFeedInterpreter.java create mode 100644 API/src/main/java/net/juligames/core/api/config/env/MapPart.java diff --git a/API/src/main/java/net/juligames/core/api/config/env/EnviromentVariableInterpreter.java b/API/src/main/java/net/juligames/core/api/config/env/EnviromentVariableInterpreter.java deleted file mode 100644 index 4cdd977e..00000000 --- a/API/src/main/java/net/juligames/core/api/config/env/EnviromentVariableInterpreter.java +++ /dev/null @@ -1,22 +0,0 @@ -package net.juligames.core.api.config.env; - -import net.juligames.core.api.config.Interpreter; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; - -/** - * @author Ture Bentzin - * 07.03.2023 - */ -@ApiStatus.AvailableSince("1.5") -public class EnviromentVariableInterpreter implements Interpreter { - @Override - public @NotNull EnvironmentVariable interpret(String input) throws Exception { - return new EnvironmentVariable(input); - } - - @Override - public @NotNull String reverse(@NotNull EnvironmentVariable environmentVariable) { - return environmentVariable.key(); - } -} diff --git a/API/src/main/java/net/juligames/core/api/config/env/EnvironmentVariable.java b/API/src/main/java/net/juligames/core/api/config/env/EnvironmentVariable.java index a0481981..f5616e19 100644 --- a/API/src/main/java/net/juligames/core/api/config/env/EnvironmentVariable.java +++ b/API/src/main/java/net/juligames/core/api/config/env/EnvironmentVariable.java @@ -8,7 +8,7 @@ * 07.03.2023 */ @ApiStatus.AvailableSince("1.5") -public record EnvironmentVariable(String key) { +public record EnvironmentVariable(String key) implements MapPart { public @NotNull String get() { return System.getenv().get(key()); diff --git a/API/src/main/java/net/juligames/core/api/config/env/EnvironmentVariableInterpreter.java b/API/src/main/java/net/juligames/core/api/config/env/EnvironmentVariableInterpreter.java new file mode 100644 index 00000000..436b6f61 --- /dev/null +++ b/API/src/main/java/net/juligames/core/api/config/env/EnvironmentVariableInterpreter.java @@ -0,0 +1,18 @@ +package net.juligames.core.api.config.env; + +import org.jetbrains.annotations.ApiStatus; + +/** + * @author Ture Bentzin + * 07.03.2023 + */ +@ApiStatus.AvailableSince("1.5") +public class EnvironmentVariableInterpreter extends MapFeedInterpreter { + + + public EnvironmentVariableInterpreter() { + super(System::getenv, (s, ignored) -> new EnvironmentVariable(s)); + } + + +} diff --git a/API/src/main/java/net/juligames/core/api/config/env/MapFeedInterpreter.java b/API/src/main/java/net/juligames/core/api/config/env/MapFeedInterpreter.java new file mode 100644 index 00000000..5ba744ed --- /dev/null +++ b/API/src/main/java/net/juligames/core/api/config/env/MapFeedInterpreter.java @@ -0,0 +1,58 @@ +package net.juligames.core.api.config.env; + +import net.juligames.core.api.config.Interpreter; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.Supplier; + +/** + * @author Ture Bentzin + * 07.03.2023 + */ +@ApiStatus.AvailableSince("1.5") +public class MapFeedInterpreter implements Interpreter> { + + private final @NotNull Supplier> mapSupplier; + private final @NotNull BiFunction>, ? extends MapPart> mapPartFactory; + + + public MapFeedInterpreter(@NotNull Supplier> mapSupplier) { + this.mapSupplier = mapSupplier; + this.mapPartFactory = MapPartImpl::new; + } + + public MapFeedInterpreter(@NotNull Supplier> mapSupplier, + @NotNull BiFunction>, ? extends MapPart> mapPartFactory) { + this.mapSupplier = mapSupplier; + this.mapPartFactory = mapPartFactory; + } + + + @Override + public @NotNull MapPart interpret(@NotNull String input) throws Exception { + return new MapPartImpl<>(input, mapSupplier); + } + + @Override + public @NotNull String reverse(@NotNull MapPart eMapPart) { + return eMapPart.key(); + } + + + private record MapPartImpl(String key, Supplier> mapSupplier) implements MapPart { + + @Override + public @NotNull String key() { + return key; + } + + @Override + public @NotNull E get() { + return mapSupplier.get().get(key()); + } + } +} diff --git a/API/src/main/java/net/juligames/core/api/config/env/MapPart.java b/API/src/main/java/net/juligames/core/api/config/env/MapPart.java new file mode 100644 index 00000000..44f80cc7 --- /dev/null +++ b/API/src/main/java/net/juligames/core/api/config/env/MapPart.java @@ -0,0 +1,14 @@ +package net.juligames.core.api.config.env; + +import org.jetbrains.annotations.ApiStatus; + +/** + * @author Ture Bentzin + * 07.03.2023 + */ +@ApiStatus.AvailableSince("1.5") +public interface MapPart { + + String key(); + E get(); +} From d05c4d1029a72af62ae006f977a8660bc04e75b7 Mon Sep 17 00:00:00 2001 From: TDR Date: Tue, 7 Mar 2023 19:50:48 +0100 Subject: [PATCH 25/64] move dir --- .../api/config/{env => mapbacked}/EnvironmentVariable.java | 2 +- .../{env => mapbacked}/EnvironmentVariableInterpreter.java | 4 ++-- .../api/config/{env => mapbacked}/MapFeedInterpreter.java | 6 ++++-- .../core/api/config/{env => mapbacked}/MapPart.java | 3 ++- .../core/api/config/property/PropertyInterpreter.java | 5 +++++ 5 files changed, 14 insertions(+), 6 deletions(-) rename API/src/main/java/net/juligames/core/api/config/{env => mapbacked}/EnvironmentVariable.java (87%) rename API/src/main/java/net/juligames/core/api/config/{env => mapbacked}/EnvironmentVariableInterpreter.java (65%) rename API/src/main/java/net/juligames/core/api/config/{env => mapbacked}/MapFeedInterpreter.java (87%) rename API/src/main/java/net/juligames/core/api/config/{env => mapbacked}/MapPart.java (61%) diff --git a/API/src/main/java/net/juligames/core/api/config/env/EnvironmentVariable.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/EnvironmentVariable.java similarity index 87% rename from API/src/main/java/net/juligames/core/api/config/env/EnvironmentVariable.java rename to API/src/main/java/net/juligames/core/api/config/mapbacked/EnvironmentVariable.java index f5616e19..d1819551 100644 --- a/API/src/main/java/net/juligames/core/api/config/env/EnvironmentVariable.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/EnvironmentVariable.java @@ -1,4 +1,4 @@ -package net.juligames.core.api.config.env; +package net.juligames.core.api.config.mapbacked; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; diff --git a/API/src/main/java/net/juligames/core/api/config/env/EnvironmentVariableInterpreter.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/EnvironmentVariableInterpreter.java similarity index 65% rename from API/src/main/java/net/juligames/core/api/config/env/EnvironmentVariableInterpreter.java rename to API/src/main/java/net/juligames/core/api/config/mapbacked/EnvironmentVariableInterpreter.java index 436b6f61..7fe216a6 100644 --- a/API/src/main/java/net/juligames/core/api/config/env/EnvironmentVariableInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/EnvironmentVariableInterpreter.java @@ -1,4 +1,4 @@ -package net.juligames.core.api.config.env; +package net.juligames.core.api.config.mapbacked; import org.jetbrains.annotations.ApiStatus; @@ -7,7 +7,7 @@ * 07.03.2023 */ @ApiStatus.AvailableSince("1.5") -public class EnvironmentVariableInterpreter extends MapFeedInterpreter { +public final class EnvironmentVariableInterpreter extends MapFeedInterpreter { public EnvironmentVariableInterpreter() { diff --git a/API/src/main/java/net/juligames/core/api/config/env/MapFeedInterpreter.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java similarity index 87% rename from API/src/main/java/net/juligames/core/api/config/env/MapFeedInterpreter.java rename to API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java index 5ba744ed..9ea22e4f 100644 --- a/API/src/main/java/net/juligames/core/api/config/env/MapFeedInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java @@ -1,4 +1,4 @@ -package net.juligames.core.api.config.env; +package net.juligames.core.api.config.mapbacked; import net.juligames.core.api.config.Interpreter; import org.jetbrains.annotations.ApiStatus; @@ -6,10 +6,12 @@ import java.util.Map; import java.util.function.BiFunction; -import java.util.function.Function; import java.util.function.Supplier; /** + * This {@link Interpreter} allows to interpret keys from the config that get resolved using a given {@link Map}. + * A known implementation is the {@link EnvironmentVariableInterpreter} + * * @author Ture Bentzin * 07.03.2023 */ diff --git a/API/src/main/java/net/juligames/core/api/config/env/MapPart.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/MapPart.java similarity index 61% rename from API/src/main/java/net/juligames/core/api/config/env/MapPart.java rename to API/src/main/java/net/juligames/core/api/config/mapbacked/MapPart.java index 44f80cc7..45aa3499 100644 --- a/API/src/main/java/net/juligames/core/api/config/env/MapPart.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/MapPart.java @@ -1,8 +1,9 @@ -package net.juligames.core.api.config.env; +package net.juligames.core.api.config.mapbacked; import org.jetbrains.annotations.ApiStatus; /** + * @apiNote should only be used with the {@link MapFeedInterpreter} * @author Ture Bentzin * 07.03.2023 */ diff --git a/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java b/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java index 2141388a..970d752e 100644 --- a/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java @@ -30,6 +30,11 @@ private PropertyInterpreter(@NotNull Function getter) { return new PropertyInterpreter<>(System::getProperty); } + @Contract(value = " -> new", pure = true) + public static @NotNull PropertyInterpreter charSequencePropertyInterpreter() { + return new PropertyInterpreter<>(System::getProperty); + } + @Contract(value = " -> new", pure = true) public static @NotNull PropertyInterpreter booleanPropertyInterpreter() { return new PropertyInterpreter<>(Boolean::getBoolean); From 7ccf4db17830f1fed5a17e9f08b6513520d5b971 Mon Sep 17 00:00:00 2001 From: TDR Date: Tue, 7 Mar 2023 19:57:26 +0100 Subject: [PATCH 26/64] Create HazelFeedMapInterpreter.java --- .../mapbacked/HazelFeedMapInterpreter.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 API/src/main/java/net/juligames/core/api/config/mapbacked/HazelFeedMapInterpreter.java diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/HazelFeedMapInterpreter.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/HazelFeedMapInterpreter.java new file mode 100644 index 00000000..4ca319c5 --- /dev/null +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/HazelFeedMapInterpreter.java @@ -0,0 +1,43 @@ +package net.juligames.core.api.config.mapbacked; + +import net.juligames.core.api.API; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; +import java.util.function.Supplier; + +/** + * This {@link MapFeedInterpreter} uses {@link net.juligames.core.api.data.HazelDataApi#getMap(String)} get supply the map + * @author Ture Bentzin + * 07.03.2023 + */ +public final class HazelFeedMapInterpreter extends MapFeedInterpreter{ + + /** + * + * @deprecated This serves as an example and will be removed after testing is completed + */ + @Deprecated(forRemoval = true) + @Contract(" -> new") + @ApiStatus.Experimental + public static @NotNull HazelFeedMapInterpreter master_information() { + return new HazelFeedMapInterpreter<>(() -> API.get().getHazelDataApi().getMasterInformation()); + } + + public static @NotNull Map getStringEHazelMap(String hazel) { + return API.get().getHazelDataApi().getMap(hazel); + } + + + public HazelFeedMapInterpreter(@NotNull String hazel) { + super(() -> getStringEHazelMap(hazel)); + } + + private HazelFeedMapInterpreter(Supplier> supplier) { + super(supplier); + } + + +} From f740ff2f37017d64b49117052737e995fc957f1d Mon Sep 17 00:00:00 2001 From: TDR Date: Tue, 7 Mar 2023 20:06:50 +0100 Subject: [PATCH 27/64] add customPropertyInterpreter --- .../config/property/PropertyInterpreter.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java b/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java index 970d752e..980ed173 100644 --- a/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java @@ -25,6 +25,38 @@ private PropertyInterpreter(@NotNull Function getter) { this.getter = getter; } + /** + * @param tInterpreter WARNING: the tInterpreter#reverse method is NOT USED!!! {@link String#valueOf(T)} is used instead!! + * @return T + * @param the Type + */ + @Contract(value = "_ -> new", pure = true) + public static @NotNull PropertyInterpreter customPropertyInterpreter(Interpreter tInterpreter) { + return new PropertyInterpreter<>(s -> { + try { + return tInterpreter.interpret(System.getProperty(s)); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } + + /** + * @param tInterpreter is used with the result of {@link System#getProperty(String)} for the given input + * @return T + * @param the Type + */ + @Contract(value = "_ -> new", pure = true) + public static @NotNull PropertyInterpreter customPropertyInterpreter(Function tInterpreter) { + return new PropertyInterpreter<>(s -> { + try { + return tInterpreter.apply(System.getProperty(s)); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } + @Contract(value = " -> new", pure = true) public static @NotNull PropertyInterpreter stringPropertyInterpreter() { return new PropertyInterpreter<>(System::getProperty); From 6571958cc1a903f42301a3044f2557277a18aed4 Mon Sep 17 00:00:00 2001 From: TDR Date: Thu, 9 Mar 2023 17:29:02 +0100 Subject: [PATCH 28/64] Break "load" method of MiniGames --- .../core/api/minigame/BasicMiniGame.java | 11 +++++- .../core/api/minigame/StartType.java | 35 +++++++++++++++++++ .../juligames/core/minigame/api/MiniGame.java | 26 +++++++++++--- .../core/paper/PaperCoreEventListener.java | 14 +++++--- 4 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 API/src/main/java/net/juligames/core/api/minigame/StartType.java diff --git a/API/src/main/java/net/juligames/core/api/minigame/BasicMiniGame.java b/API/src/main/java/net/juligames/core/api/minigame/BasicMiniGame.java index 650ac389..bd7156d2 100644 --- a/API/src/main/java/net/juligames/core/api/minigame/BasicMiniGame.java +++ b/API/src/main/java/net/juligames/core/api/minigame/BasicMiniGame.java @@ -1,6 +1,8 @@ package net.juligames.core.api.minigame; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -30,10 +32,17 @@ default String getFullDescription() { return getPlainName() + " v." + getVersion() + " by " + getDeveloperName(); } + + @ApiStatus.AvailableSince("1.5") + StartType getStartType(); + /** * load the MiniGame + * @return a {@link StartType}: The handling of this is not guaranteed it might start whenever it wants. Its just an indication + * on when and how you suggest to load it */ - void load(); + @Nullable + StartType load(); /** * start the MiniGame diff --git a/API/src/main/java/net/juligames/core/api/minigame/StartType.java b/API/src/main/java/net/juligames/core/api/minigame/StartType.java new file mode 100644 index 00000000..2ac97db3 --- /dev/null +++ b/API/src/main/java/net/juligames/core/api/minigame/StartType.java @@ -0,0 +1,35 @@ +package net.juligames.core.api.minigame; + +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +/** + * @apiNote please dont temper with this interface. The current roadmap for this is currently unclear... + * @author Ture Bentzin + * 09.03.2023 + */ +@ApiStatus.AvailableSince("1.5") +public +interface StartType { + + static boolean compare(@NotNull StartType s1, StartType s2) { + return s1.isSimilar(s2); + } + + StartType DIRECT = new SimpleStartType("DIRECT"); + StartType DELAYED = new SimpleStartType("DELAYED"); + + String getName(); + + + record SimpleStartType(String name) implements StartType { + @Override + public String getName() { + return name; + } + } + + default boolean isSimilar(@NotNull StartType startType) { + return this.getName().equals(startType.getName()); + } +} diff --git a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java index dd33ee9d..6e39cf15 100644 --- a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java +++ b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java @@ -8,8 +8,10 @@ import de.bentzin.tools.logging.Logger; import de.bentzin.tools.logging.LoggingClass; import net.juligames.core.api.minigame.BasicMiniGame; +import net.juligames.core.api.minigame.StartType; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -25,6 +27,7 @@ public abstract class MiniGame extends LoggingClass implements BasicMiniGame { private final String plainName; private boolean loaded = false; + private StartType startType; public MiniGame( @NotNull final String plainName, @@ -45,7 +48,7 @@ public MiniGame( /** * Will be called as soon as the MiniGame is prepared by the Core */ - protected abstract void onLoad(); + protected abstract StartType onLoad(); /** * This will start the MiniGame @@ -65,14 +68,22 @@ public MiniGame( protected abstract void onFinish(); + /** + * load the MiniGame + * @return a {@link StartType}: The handling of this is not guaranteed it might start whenever it wants. Its just an indication + * on when and how you suggest to load it + */ @Override - public final void load() { + @Nullable + public final StartType load() { //load getLogger().info("loading " + getFullDescription() + "!"); + StartType r = null; if (!isLoaded()) { try { - onLoad(); - getLogger().info("finished loading of " + getDescription()); + r = onLoad(); + getLogger().info("finished loading of " + getFullDescription()); + getLogger().info(getFullDescription() + " suggest the following StartType: " + r.getName()); loaded = true; } catch (Exception e) { getLogger().error("Error while loading MiniGame: " + e.getMessage() + "! Is it up to date?"); @@ -81,6 +92,7 @@ public final void load() { abort(); } } + return r; } @@ -159,6 +171,12 @@ public final void setMiniGameState(@NotNull MiniGameState newState) { newState.apply(currentServer()); } + @Override + @ApiStatus.AvailableSince("1.5") + public StartType getStartType() { + return startType; + } + @Override public final boolean isLoaded() { return loaded; diff --git a/PaperCore/src/main/java/net/juligames/core/paper/PaperCoreEventListener.java b/PaperCore/src/main/java/net/juligames/core/paper/PaperCoreEventListener.java index d5c810ee..a1a295ea 100644 --- a/PaperCore/src/main/java/net/juligames/core/paper/PaperCoreEventListener.java +++ b/PaperCore/src/main/java/net/juligames/core/paper/PaperCoreEventListener.java @@ -3,12 +3,14 @@ import de.bentzin.tools.logging.Logger; import net.juligames.core.Core; import net.juligames.core.api.API; +import net.juligames.core.api.minigame.StartType; import net.juligames.core.paper.events.ServerBootFinishedEvent; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; +import org.checkerframework.checker.units.qual.A; import java.util.ArrayList; import java.util.Objects; @@ -50,10 +52,14 @@ public void onBoot(ServerBootFinishedEvent event) { public void onBootLow(ServerBootFinishedEvent event) { Logger logger = API.get().getAPILogger().adopt("boot-high"); logger.info("running last post-start utilities..."); - API.get().getLocalMiniGame().ifPresent(basicMiniGame -> { - logger.info("starting: " + basicMiniGame.getPlainName()); - basicMiniGame.start(); - }); + API.get().getLocalMiniGame() + .stream() + .filter(basicMiniGame -> basicMiniGame.getStartType().isSimilar(StartType.DIRECT)) + .findFirst() + .ifPresent(basicMiniGame -> { + logger.info("starting: " + basicMiniGame.getPlainName()); + basicMiniGame.start(); + }); } } From ed9c0030445d8756efe1a543baa7cecabd16f4e4 Mon Sep 17 00:00:00 2001 From: TDR Date: Sat, 11 Mar 2023 15:01:10 +0100 Subject: [PATCH 29/64] Create GenericHashtableToStringHashtableMapper.java --- ...nericHashtableToStringHashtableMapper.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 API/src/main/java/net/juligames/core/api/misc/GenericHashtableToStringHashtableMapper.java diff --git a/API/src/main/java/net/juligames/core/api/misc/GenericHashtableToStringHashtableMapper.java b/API/src/main/java/net/juligames/core/api/misc/GenericHashtableToStringHashtableMapper.java new file mode 100644 index 00000000..614977bf --- /dev/null +++ b/API/src/main/java/net/juligames/core/api/misc/GenericHashtableToStringHashtableMapper.java @@ -0,0 +1,38 @@ +package net.juligames.core.api.misc; + +import net.juligames.core.api.config.Interpreter; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.Hashtable; +import java.util.function.Function; + +/** + * @author Ture Bentzin + * 03.03.2023 + */ +@ApiStatus.AvailableSince("1.5") +public class GenericHashtableToStringHashtableMapper implements Function, Hashtable> { + + private final @NotNull Interpreter kInterpreter; + private final @NotNull Interpreter vInterpreter; + + public GenericHashtableToStringHashtableMapper(@NotNull Interpreter kInterpreter, @NotNull Interpreter vInterpreter) { + this.kInterpreter = kInterpreter; + this.vInterpreter = vInterpreter; + } + + @Contract(value = "_ -> new", pure = true) + public static @NotNull GenericHashtableToStringHashtableMapper createParallel(final Interpreter tInterpreter) { + return new GenericHashtableToStringHashtableMapper<>(tInterpreter, tInterpreter); + } + + @Override + public @NotNull Hashtable apply(@NotNull Hashtable objectObjectHashtable) { + final Hashtable stringStringHashtable = new Hashtable<>(); + objectObjectHashtable.forEach((key, value) -> + stringStringHashtable.put(kInterpreter.reverse(key), vInterpreter.reverse(value))); + return stringStringHashtable; + } +} From e1db6f92d3421fff68ab8f10562a918f1570d6b0 Mon Sep 17 00:00:00 2001 From: TDR Date: Sat, 11 Mar 2023 15:02:15 +0100 Subject: [PATCH 30/64] reformat code and javadoc --- .../main/java/net/juligames/core/api/API.java | 7 +- .../core/api/config/BuildInInterpreters.java | 1 - .../core/api/config/ConfigurationAPI.java | 5 +- .../mapbacked/HazelFeedMapInterpreter.java | 23 ++-- .../core/api/config/mapbacked/MapPart.java | 3 +- .../config/property/PropertyInterpreter.java | 6 +- .../core/api/message/MessageApi.java | 1 + .../core/api/minigame/BasicMiniGame.java | 1 + .../core/api/minigame/StartType.java | 15 ++- .../core/adventure/api/AdventureAPI.java | 4 +- .../api/AudienceMessageRecipient.java | 2 - .../core/adventure/AdventureCore.java | 7 +- Core/pom.xml | 2 - .../juligames/core/caching/CoreCacheApi.java | 5 - .../core/command/inbuild/InbuiltCommand.java | 1 - .../core/config/CoreConfigurationApi.java | 10 +- Master/dependency-reduced-pom.xml | 85 +++++++------- .../juligames/core/minigame/api/MiniGame.java | 1 + .../PreDefinedInsertionProcedure.java | 9 +- PaperCore/dependency-reduced-pom.xml | 105 +++++++++--------- .../core/paper/PaperCoreEventListener.java | 7 +- VelocityCore/dependency-reduced-pom.xml | 105 +++++++++--------- .../juligames/core/velocity/VelocityCore.java | 1 - 23 files changed, 198 insertions(+), 208 deletions(-) diff --git a/API/src/main/java/net/juligames/core/api/API.java b/API/src/main/java/net/juligames/core/api/API.java index 658b386e..2f71545d 100644 --- a/API/src/main/java/net/juligames/core/api/API.java +++ b/API/src/main/java/net/juligames/core/api/API.java @@ -44,19 +44,18 @@ public interface API { if (api.isEmpty()) { throw new APIException(); } - if(!Boolean.getBoolean("acknowledgeMissingCoreClass")) - { + if (!Boolean.getBoolean("acknowledgeMissingCoreClass")) { //this block provides security over the used implementation of the API class! try { Class.forName("net.juligames.core.Core"); //check that the core is installed } catch (ClassNotFoundException e) { - try{ + try { api.ifPresent(api1 -> { api1.getAPILogger().error("Error while providing this instance: " + e.getMessage() + "!"); api1.getAPILogger().error("It seems like you are operating an unsupported implementation of the Core! \n" + "You can acknowledge this dangerous behavior by setting the \"-DacknowledgeMissingCoreClass=true\"!"); }); - }catch (Exception ignored) { + } catch (Exception ignored) { //ok its fucked throw new APIException(e); } diff --git a/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java b/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java index 07efd93f..271ab3bc 100644 --- a/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java +++ b/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java @@ -9,7 +9,6 @@ import java.text.DateFormat; import java.time.Instant; import java.util.Date; -import java.util.Map; import java.util.UUID; /** diff --git a/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java b/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java index a6ebf1fa..0d295799 100644 --- a/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java +++ b/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java @@ -45,7 +45,7 @@ public interface ConfigurationAPI { @NotNull @ApiStatus.AvailableSince("1.5") - Configuration createNewOfflineConfiguration(@NotNull Map defaults); + Configuration createNewOfflineConfiguration(@NotNull Map defaults); //collections on demand - 1.1 @@ -124,7 +124,8 @@ default void spiltAndWrite(@NotNull Collection collection, @NotNull Inter * I'm currently testing this. It might be removed later. You should keep in mind that the Core Configurations are not * a section based system! All section operations are "hacked" over a flat structure. The Configurations don't really offer * depth... - * @param root the root + * + * @param root the root * @param section the section * @return an OfflineConfiguration. Changes to this will not affect root */ diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/HazelFeedMapInterpreter.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/HazelFeedMapInterpreter.java index 4ca319c5..feac18eb 100644 --- a/API/src/main/java/net/juligames/core/api/config/mapbacked/HazelFeedMapInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/HazelFeedMapInterpreter.java @@ -10,13 +10,21 @@ /** * This {@link MapFeedInterpreter} uses {@link net.juligames.core.api.data.HazelDataApi#getMap(String)} get supply the map + * * @author Ture Bentzin * 07.03.2023 */ -public final class HazelFeedMapInterpreter extends MapFeedInterpreter{ +public final class HazelFeedMapInterpreter extends MapFeedInterpreter { + + public HazelFeedMapInterpreter(@NotNull String hazel) { + super(() -> getStringEHazelMap(hazel)); + } + + private HazelFeedMapInterpreter(Supplier> supplier) { + super(supplier); + } /** - * * @deprecated This serves as an example and will be removed after testing is completed */ @Deprecated(forRemoval = true) @@ -26,18 +34,9 @@ public final class HazelFeedMapInterpreter extends MapFeedInterpreter{ return new HazelFeedMapInterpreter<>(() -> API.get().getHazelDataApi().getMasterInformation()); } - public static @NotNull Map getStringEHazelMap(String hazel) { + public static @NotNull Map getStringEHazelMap(String hazel) { return API.get().getHazelDataApi().getMap(hazel); } - public HazelFeedMapInterpreter(@NotNull String hazel) { - super(() -> getStringEHazelMap(hazel)); - } - - private HazelFeedMapInterpreter(Supplier> supplier) { - super(supplier); - } - - } diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/MapPart.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/MapPart.java index 45aa3499..bebb9d48 100644 --- a/API/src/main/java/net/juligames/core/api/config/mapbacked/MapPart.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/MapPart.java @@ -3,13 +3,14 @@ import org.jetbrains.annotations.ApiStatus; /** - * @apiNote should only be used with the {@link MapFeedInterpreter} * @author Ture Bentzin * 07.03.2023 + * @apiNote should only be used with the {@link MapFeedInterpreter} */ @ApiStatus.AvailableSince("1.5") public interface MapPart { String key(); + E get(); } diff --git a/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java b/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java index 980ed173..13c55f64 100644 --- a/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java @@ -27,8 +27,8 @@ private PropertyInterpreter(@NotNull Function getter) { /** * @param tInterpreter WARNING: the tInterpreter#reverse method is NOT USED!!! {@link String#valueOf(T)} is used instead!! + * @param the Type * @return T - * @param the Type */ @Contract(value = "_ -> new", pure = true) public static @NotNull PropertyInterpreter customPropertyInterpreter(Interpreter tInterpreter) { @@ -43,11 +43,11 @@ private PropertyInterpreter(@NotNull Function getter) { /** * @param tInterpreter is used with the result of {@link System#getProperty(String)} for the given input + * @param the Type * @return T - * @param the Type */ @Contract(value = "_ -> new", pure = true) - public static @NotNull PropertyInterpreter customPropertyInterpreter(Function tInterpreter) { + public static @NotNull PropertyInterpreter customPropertyInterpreter(Function tInterpreter) { return new PropertyInterpreter<>(s -> { try { return tInterpreter.apply(System.getProperty(s)); diff --git a/API/src/main/java/net/juligames/core/api/message/MessageApi.java b/API/src/main/java/net/juligames/core/api/message/MessageApi.java index 183a85e6..89ddb624 100644 --- a/API/src/main/java/net/juligames/core/api/message/MessageApi.java +++ b/API/src/main/java/net/juligames/core/api/message/MessageApi.java @@ -30,6 +30,7 @@ static T[] arrFromVargs(T... ts) { /** * This is an alias for {@link #arrFromVargs(Object[])} + * * @apiNote You should import this method static! */ @SafeVarargs diff --git a/API/src/main/java/net/juligames/core/api/minigame/BasicMiniGame.java b/API/src/main/java/net/juligames/core/api/minigame/BasicMiniGame.java index bd7156d2..87fe339c 100644 --- a/API/src/main/java/net/juligames/core/api/minigame/BasicMiniGame.java +++ b/API/src/main/java/net/juligames/core/api/minigame/BasicMiniGame.java @@ -38,6 +38,7 @@ default String getFullDescription() { /** * load the MiniGame + * * @return a {@link StartType}: The handling of this is not guaranteed it might start whenever it wants. Its just an indication * on when and how you suggest to load it */ diff --git a/API/src/main/java/net/juligames/core/api/minigame/StartType.java b/API/src/main/java/net/juligames/core/api/minigame/StartType.java index 2ac97db3..c4a8d712 100644 --- a/API/src/main/java/net/juligames/core/api/minigame/StartType.java +++ b/API/src/main/java/net/juligames/core/api/minigame/StartType.java @@ -4,23 +4,26 @@ import org.jetbrains.annotations.NotNull; /** - * @apiNote please dont temper with this interface. The current roadmap for this is currently unclear... * @author Ture Bentzin * 09.03.2023 + * @apiNote please dont temper with this interface. The current roadmap for this is currently unclear... */ @ApiStatus.AvailableSince("1.5") public interface StartType { + StartType DIRECT = new SimpleStartType("DIRECT"); + StartType DELAYED = new SimpleStartType("DELAYED"); + static boolean compare(@NotNull StartType s1, StartType s2) { return s1.isSimilar(s2); } - StartType DIRECT = new SimpleStartType("DIRECT"); - StartType DELAYED = new SimpleStartType("DELAYED"); - String getName(); + default boolean isSimilar(@NotNull StartType startType) { + return this.getName().equals(startType.getName()); + } record SimpleStartType(String name) implements StartType { @Override @@ -28,8 +31,4 @@ public String getName() { return name; } } - - default boolean isSimilar(@NotNull StartType startType) { - return this.getName().equals(startType.getName()); - } } diff --git a/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AdventureAPI.java b/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AdventureAPI.java index 159212f7..95d54b3b 100644 --- a/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AdventureAPI.java +++ b/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AdventureAPI.java @@ -42,7 +42,7 @@ public interface AdventureAPI { * It supplies the best message for the given key and locale (through audience) * This is default implementation: * {@code return getAdventureTagManager().resolve(API.get().getMessageApi(). - * getMessageSmart(messageKey,audience.get(Identity.LOCALE).orElseThrow(), replacements));} + * getMessageSmart(messageKey,audience.get(Identity.LOCALE).orElseThrow(), replacements));} */ @ApiStatus.AvailableSince("1.5") @NotNull Component forAudience(@NotNull String messageKey, @NotNull Audience audience, String... replacements); @@ -53,7 +53,7 @@ public interface AdventureAPI { * It supplies the best message for the given key and locale (through audience) * This is default implementation: * {@code return getAdventureTagManager().resolve(API.get().getMessageApi(). - * getMessageSmart(messageKey,audience.get(Identity.LOCALE).orElseThrow()));} + * getMessageSmart(messageKey,audience.get(Identity.LOCALE).orElseThrow()));} */ @ApiStatus.AvailableSince("1.5") @NotNull Component forAudience(@NotNull String messageKey, @NotNull Audience audience); diff --git a/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AudienceMessageRecipient.java b/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AudienceMessageRecipient.java index 2e15b126..abe93907 100644 --- a/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AudienceMessageRecipient.java +++ b/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AudienceMessageRecipient.java @@ -7,7 +7,6 @@ import net.kyori.adventure.audience.Audience; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.text.Component; -import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -35,7 +34,6 @@ public AudienceMessageRecipient(@NotNull String name, @NotNull Supplier } /** - * * @param audience needs to be able to provide {@link Identity#LOCALE} * @return the {@link AudienceMessageRecipient} */ diff --git a/AdventureCore/src/main/java/net/juligames/core/adventure/AdventureCore.java b/AdventureCore/src/main/java/net/juligames/core/adventure/AdventureCore.java index 75851df6..8968ec6a 100644 --- a/AdventureCore/src/main/java/net/juligames/core/adventure/AdventureCore.java +++ b/AdventureCore/src/main/java/net/juligames/core/adventure/AdventureCore.java @@ -13,9 +13,6 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; -import java.util.Locale; -import java.util.UUID; - /** * @author Ture Bentzin * 21.11.2022 @@ -86,13 +83,13 @@ public void registerLegacyMessage(@NotNull String key, @NotNull String input, @Override public @NotNull Component forAudience(@NotNull String messageKey, @NotNull Audience audience, String... replacements) { return getAdventureTagManager().resolve(API.get().getMessageApi(). - getMessageSmart(messageKey,audience.get(Identity.LOCALE).orElseThrow(), replacements)); + getMessageSmart(messageKey, audience.get(Identity.LOCALE).orElseThrow(), replacements)); } @Override public @NotNull Component forAudience(@NotNull String messageKey, @NotNull Audience audience) { return getAdventureTagManager().resolve(API.get().getMessageApi(). - getMessageSmart(messageKey,audience.get(Identity.LOCALE).orElseThrow())); + getMessageSmart(messageKey, audience.get(Identity.LOCALE).orElseThrow())); } @ApiStatus.Internal diff --git a/Core/pom.xml b/Core/pom.xml index 964a48dd..b5c98274 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -11,11 +11,9 @@ 4.0.0 - Core - 17 17 diff --git a/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java b/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java index fa5bc34f..63673349 100644 --- a/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java +++ b/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java @@ -3,17 +3,12 @@ import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; import de.bentzin.tools.pair.Pair; -import net.juligames.core.Core; -import net.juligames.core.api.API; import net.juligames.core.api.cacheing.CacheApi; import net.juligames.core.api.config.Configuration; import net.juligames.core.api.err.dev.TODOException; import net.juligames.core.api.jdbi.DBMessage; -import net.juligames.core.config.OfflineConfiguration; import org.jetbrains.annotations.ApiStatus; -import java.util.Properties; - /** * @author Ture Bentzin * 21.01.2023 diff --git a/Core/src/main/java/net/juligames/core/command/inbuild/InbuiltCommand.java b/Core/src/main/java/net/juligames/core/command/inbuild/InbuiltCommand.java index 2f31752c..aeb447eb 100644 --- a/Core/src/main/java/net/juligames/core/command/inbuild/InbuiltCommand.java +++ b/Core/src/main/java/net/juligames/core/command/inbuild/InbuiltCommand.java @@ -1,7 +1,6 @@ package net.juligames.core.command.inbuild; import net.juligames.core.Core; -import org.checkerframework.checker.initialization.qual.UnderInitialization; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java b/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java index bd27fe66..508cf24a 100644 --- a/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java +++ b/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java @@ -155,10 +155,10 @@ public Configuration database() { public @NotNull Configuration createSectionClone(@NotNull Configuration root, @NotNull String section) { return new OfflineConfiguration(section + "@" + root, new HashMap<>(root.entrySet().stream() - .filter(stringStringEntry -> stringStringEntry.getKey().startsWith(section + "_")) - .map(s -> { - String after = s.getKey().replaceFirst(section + "_", ""); - return Map.entry(section + "_" + after.substring(0, after.indexOf("_")), s.getValue()); - }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))); + .filter(stringStringEntry -> stringStringEntry.getKey().startsWith(section + "_")) + .map(s -> { + String after = s.getKey().replaceFirst(section + "_", ""); + return Map.entry(section + "_" + after.substring(0, after.indexOf("_")), s.getValue()); + }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))); } } diff --git a/Master/dependency-reduced-pom.xml b/Master/dependency-reduced-pom.xml index e4ef9459..792d1f67 100644 --- a/Master/dependency-reduced-pom.xml +++ b/Master/dependency-reduced-pom.xml @@ -1,44 +1,45 @@ - - - JuliGamesCore - net.juligames.core - 1.5-SNAPSHOT - - 4.0.0 - Master - - - - maven-shade-plugin - 3.4.1 - - - package - - shade - - - - - - - maven-jar-plugin - 3.3.0 - - - - true - net.juligames.core.master.CoreMaster - - - - - - - - 17 - 17 - UTF-8 - + + + JuliGamesCore + net.juligames.core + 1.5-SNAPSHOT + + 4.0.0 + Master + + + + maven-shade-plugin + 3.4.1 + + + package + + shade + + + + + + + maven-jar-plugin + 3.3.0 + + + + true + net.juligames.core.master.CoreMaster + + + + + + + + 17 + 17 + UTF-8 + diff --git a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java index 6e39cf15..3d133845 100644 --- a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java +++ b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java @@ -70,6 +70,7 @@ public MiniGame( /** * load the MiniGame + * * @return a {@link StartType}: The handling of this is not guaranteed it might start whenever it wants. Its just an indication * on when and how you suggest to load it */ diff --git a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/PreDefinedInsertionProcedure.java b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/PreDefinedInsertionProcedure.java index d40b4f5f..d77198b9 100644 --- a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/PreDefinedInsertionProcedure.java +++ b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/PreDefinedInsertionProcedure.java @@ -7,19 +7,20 @@ import java.util.Set; import java.util.UUID; -public final class PreDefinedInsertionProcedure implements InsertionProcedure{ +public final class PreDefinedInsertionProcedure implements InsertionProcedure { private final Map preDefinedTeaming; - public PreDefinedInsertionProcedure(Map preDefinedTeaming) { + public PreDefinedInsertionProcedure(Map preDefinedTeaming) { this.preDefinedTeaming = preDefinedTeaming; } + @Override public @NotNull Boolean apply(Set teams, UUID uuid) { - if(preDefinedTeaming.containsKey(uuid)) { + if (preDefinedTeaming.containsKey(uuid)) { Team should = preDefinedTeaming.get(uuid); - if(teams.contains(should)) { + if (teams.contains(should)) { return should.tryAdd(uuid); } } diff --git a/PaperCore/dependency-reduced-pom.xml b/PaperCore/dependency-reduced-pom.xml index 833505fb..83b8b779 100644 --- a/PaperCore/dependency-reduced-pom.xml +++ b/PaperCore/dependency-reduced-pom.xml @@ -1,54 +1,55 @@ - - - JuliGamesCore - net.juligames.core - 1.5-SNAPSHOT - - 4.0.0 - PaperCore - - - - true - src/main/resources - - - - - maven-shade-plugin - 3.4.1 - - - package - - shade - - - - - false - - - - - - - papermc - https://repo.papermc.io/repository/maven-public/ - - - - - io.papermc.paper - paper-api - 1.18.2-R0.1-SNAPSHOT - provided - - - - 17 - 17 - UTF-8 - + + + JuliGamesCore + net.juligames.core + 1.5-SNAPSHOT + + 4.0.0 + PaperCore + + + + true + src/main/resources + + + + + maven-shade-plugin + 3.4.1 + + + package + + shade + + + + + false + + + + + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + io.papermc.paper + paper-api + 1.18.2-R0.1-SNAPSHOT + provided + + + + 17 + 17 + UTF-8 + diff --git a/PaperCore/src/main/java/net/juligames/core/paper/PaperCoreEventListener.java b/PaperCore/src/main/java/net/juligames/core/paper/PaperCoreEventListener.java index a1a295ea..e85d3dbe 100644 --- a/PaperCore/src/main/java/net/juligames/core/paper/PaperCoreEventListener.java +++ b/PaperCore/src/main/java/net/juligames/core/paper/PaperCoreEventListener.java @@ -10,7 +10,6 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; -import org.checkerframework.checker.units.qual.A; import java.util.ArrayList; import java.util.Objects; @@ -57,9 +56,9 @@ public void onBootLow(ServerBootFinishedEvent event) { .filter(basicMiniGame -> basicMiniGame.getStartType().isSimilar(StartType.DIRECT)) .findFirst() .ifPresent(basicMiniGame -> { - logger.info("starting: " + basicMiniGame.getPlainName()); - basicMiniGame.start(); - }); + logger.info("starting: " + basicMiniGame.getPlainName()); + basicMiniGame.start(); + }); } } diff --git a/VelocityCore/dependency-reduced-pom.xml b/VelocityCore/dependency-reduced-pom.xml index 025447e5..fa5c7e24 100644 --- a/VelocityCore/dependency-reduced-pom.xml +++ b/VelocityCore/dependency-reduced-pom.xml @@ -1,54 +1,55 @@ - - - JuliGamesCore - net.juligames.core - 1.5-SNAPSHOT - - 4.0.0 - VelocityCore - - - - maven-shade-plugin - 3.4.1 - - - package - - shade - - - - - false - - - - - - - papermc - papermc - https://repo.papermc.io/repository/maven-public/ - - - juligames-juligames - Juligames Maven - https://maven.juligames.net/juligames - - - - - com.velocitypowered - velocity-api - 3.1.1 - provided - - - - 17 - 17 - UTF-8 - + + + JuliGamesCore + net.juligames.core + 1.5-SNAPSHOT + + 4.0.0 + VelocityCore + + + + maven-shade-plugin + 3.4.1 + + + package + + shade + + + + + false + + + + + + + papermc + papermc + https://repo.papermc.io/repository/maven-public/ + + + juligames-juligames + Juligames Maven + https://maven.juligames.net/juligames + + + + + com.velocitypowered + velocity-api + 3.1.1 + provided + + + + 17 + 17 + UTF-8 + diff --git a/VelocityCore/src/main/java/net/juligames/core/velocity/VelocityCore.java b/VelocityCore/src/main/java/net/juligames/core/velocity/VelocityCore.java index 59d980ac..a7a414f1 100644 --- a/VelocityCore/src/main/java/net/juligames/core/velocity/VelocityCore.java +++ b/VelocityCore/src/main/java/net/juligames/core/velocity/VelocityCore.java @@ -11,7 +11,6 @@ import net.juligames.core.Core; import net.juligames.core.adventure.AdventureCore; import net.juligames.core.adventure.api.AudienceMessageRecipient; -import net.juligames.core.api.API; import net.juligames.core.api.TODO; import org.jetbrains.annotations.NotNull; From e79bed1709ca158aee0d57835af0b51ba81139b8 Mon Sep 17 00:00:00 2001 From: TDR Date: Sat, 11 Mar 2023 15:15:23 +0100 Subject: [PATCH 31/64] Create DictionaryFeedInterpreter.java --- .../mapbacked/DictionaryFeedInterpreter.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java new file mode 100644 index 00000000..d4f9b5c8 --- /dev/null +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java @@ -0,0 +1,57 @@ +package net.juligames.core.api.config.mapbacked; + +import net.juligames.core.api.config.Interpreter; +import org.jetbrains.annotations.NotNull; + +import java.util.Dictionary; +import java.util.function.BiFunction; +import java.util.function.Supplier; + +/** + * @apiNote this can be used for {@link java.util.Hashtable}s or {@link java.util.Properties}s + * @author Ture Bentzin + * 11.03.2023 + */ +public class DictionaryFeedInterpreter implements Interpreter> { + + private final @NotNull Supplier> dictionarySupplier; + private final @NotNull BiFunction>, ? extends MapPart> dictionaryPartFactory; + + + public DictionaryFeedInterpreter(@NotNull Supplier> dictionarySupplier) { + this.dictionarySupplier = dictionarySupplier; + this.dictionaryPartFactory = DictionaryPart::new; + } + + public DictionaryFeedInterpreter(@NotNull Supplier> dictionarySupplier, + @NotNull BiFunction>, MapPart> dictionaryPartFactory) { + this.dictionarySupplier = dictionarySupplier; + this.dictionaryPartFactory = dictionaryPartFactory; + } + + + @Override + public @NotNull MapPart interpret(@NotNull String input) throws Exception { + return new DictionaryPart<>(input, dictionarySupplier); + } + + @Override + public @NotNull String reverse(@NotNull MapPart eMapPart) { + return eMapPart.key(); + } + + + private record DictionaryPart(String key, + Supplier> dictionarySupplier) implements MapPart { + + @Override + public @NotNull String key() { + return key; + } + + @Override + public @NotNull E get() { + return dictionarySupplier.get().get(key()); + } + } +} From 1f2f814de4865368457f661e137fc1d25940bce5 Mon Sep 17 00:00:00 2001 From: TDR Date: Sat, 11 Mar 2023 15:15:37 +0100 Subject: [PATCH 32/64] remove PlayerLocaleReference --- .../api/jdbi/DBPlayerLocalPreference.java | 19 ------ .../api/jdbi/PlayerLocalPreferenceDAO.java | 64 ------------------- .../bean/PlayerLocalPreferenceBean.java | 57 ----------------- .../juligames/core/jdbi/CoreSQLManager.java | 13 ---- 4 files changed, 153 deletions(-) delete mode 100644 API/src/main/java/net/juligames/core/api/jdbi/DBPlayerLocalPreference.java delete mode 100644 API/src/main/java/net/juligames/core/api/jdbi/PlayerLocalPreferenceDAO.java delete mode 100644 API/src/main/java/net/juligames/core/api/jdbi/mapper/bean/PlayerLocalPreferenceBean.java diff --git a/API/src/main/java/net/juligames/core/api/jdbi/DBPlayerLocalPreference.java b/API/src/main/java/net/juligames/core/api/jdbi/DBPlayerLocalPreference.java deleted file mode 100644 index 678d78ce..00000000 --- a/API/src/main/java/net/juligames/core/api/jdbi/DBPlayerLocalPreference.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.juligames.core.api.jdbi; - -/** - * @author Ture Bentzin - * 19.11.2022 - */ -public interface DBPlayerLocalPreference { - String uuid(); - - void setUuid(String uuid); - - String locale(); - - void setLocale(String locale); - - String fallback(); - - void setFallback(String fallback); -} diff --git a/API/src/main/java/net/juligames/core/api/jdbi/PlayerLocalPreferenceDAO.java b/API/src/main/java/net/juligames/core/api/jdbi/PlayerLocalPreferenceDAO.java deleted file mode 100644 index 0ff47b3d..00000000 --- a/API/src/main/java/net/juligames/core/api/jdbi/PlayerLocalPreferenceDAO.java +++ /dev/null @@ -1,64 +0,0 @@ -package net.juligames.core.api.jdbi; - -import net.juligames.core.api.jdbi.mapper.bean.PlayerLocalPreferenceBean; -import org.jdbi.v3.sqlobject.config.RegisterBeanMapper; -import org.jdbi.v3.sqlobject.customizer.Bind; -import org.jdbi.v3.sqlobject.customizer.BindBean; -import org.jdbi.v3.sqlobject.statement.SqlQuery; -import org.jdbi.v3.sqlobject.statement.SqlUpdate; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.UUID; - -/** - * @author Ture Bentzin - * 19.11.2022 - */ -@Deprecated(forRemoval = true) -@RegisterBeanMapper(PlayerLocalPreferenceBean.class) -public interface PlayerLocalPreferenceDAO { - - @SqlUpdate(""" - create table if not exists player_locale_preference - ( - uuid char(36) not null primary key, - locale varchar(10) not null, - fallback varchar(10) default 'EN_US' not null - );""") - void createTable(); - - @SqlQuery("SELECT * FROM player_locale_preference") - List listAllBeans(); - - @SqlUpdate("INSERT IGNORE INTO player_locale_preference(uuid, locale, fallback) values (:uuid, :locale, :fallback)") - void insert(@BindBean DBPlayerLocalPreference preferenceBean); - - @SqlUpdate("DELETE FROM player_locale_preference WHERE uuid = :uuid") - void delete(@Bind("uuid") String uuid); - - @SqlUpdate("UPDATE player_locale_preference " + - "SET locale = :locale " + - "WHERE uuid LIKE :uuid;") - void update(@Bind("uuid") String uuid, @Bind("locale") String newLocale); - - @SqlUpdate("UPDATE player_locale_preference " + - "SET fallback = :locale " + - "WHERE uuid LIKE :uuid;") - void updateFallback(@Bind("uuid") String uuid, @Bind("locale") String newLocale); - - default void delete(@NotNull UUID uuid) { - delete(uuid.toString()); - } - - @SqlQuery("SELECT * FROM player_locale_preference where uuid = :uuid") - DBPlayerLocalPreference selectBean(@Bind("uuid") String uuid); - - default DBPlayerLocalPreference select(String uuid) { - return selectBean(uuid); - } - - default List listAll() { - return listAllBeans().stream().map(bean -> (DBPlayerLocalPreference) bean).toList(); - } -} diff --git a/API/src/main/java/net/juligames/core/api/jdbi/mapper/bean/PlayerLocalPreferenceBean.java b/API/src/main/java/net/juligames/core/api/jdbi/mapper/bean/PlayerLocalPreferenceBean.java deleted file mode 100644 index fea2015b..00000000 --- a/API/src/main/java/net/juligames/core/api/jdbi/mapper/bean/PlayerLocalPreferenceBean.java +++ /dev/null @@ -1,57 +0,0 @@ -package net.juligames.core.api.jdbi.mapper.bean; - -import net.juligames.core.api.NoJavaDoc; -import net.juligames.core.api.jdbi.DBPlayerLocalPreference; - -/** - * @author Ture Bentzin - * 19.11.2022 - */ -@NoJavaDoc -@Deprecated(forRemoval = true) -public class PlayerLocalPreferenceBean implements DBPlayerLocalPreference { - - private String uuid; - private String locale; - private String fallback; - - public PlayerLocalPreferenceBean(String uuid, String locale, String fallback) { - this.uuid = uuid; - this.locale = locale; - this.fallback = fallback; - } - - private PlayerLocalPreferenceBean() { - - } - - @Override - public String uuid() { - return uuid; - } - - @Override - public void setUuid(String uuid) { - this.uuid = uuid; - } - - @Override - public String locale() { - return locale; - } - - @Override - public void setLocale(String locale) { - this.locale = locale; - } - - @Override - public String fallback() { - return fallback; - } - - @Override - public void setFallback(String fallback) { - this.fallback = fallback; - } -} diff --git a/Core/src/main/java/net/juligames/core/jdbi/CoreSQLManager.java b/Core/src/main/java/net/juligames/core/jdbi/CoreSQLManager.java index c47576b3..69fb4f1b 100644 --- a/Core/src/main/java/net/juligames/core/jdbi/CoreSQLManager.java +++ b/Core/src/main/java/net/juligames/core/jdbi/CoreSQLManager.java @@ -77,19 +77,6 @@ public void createTables() { }); logger.info("created: message"); - - //Currently not automatically used - //player_locale_preference - if (Boolean.getBoolean("legacyPlayerLocaleReference")) { - logger.info("creating: player_locale_preference"); - jdbi.withExtension(PlayerLocalPreferenceDAO.class, extension -> { - extension.createTable(); - return null; - }); - logger.info("created: player_locale_preference"); - } - - //replacementType logger.info("creating: replacementType"); jdbi.withExtension(ReplacementTypeDAO.class, extension -> { From 542de761927af9aa92b76f6d616b5c662769bdce Mon Sep 17 00:00:00 2001 From: TDR Date: Sat, 11 Mar 2023 15:17:12 +0100 Subject: [PATCH 33/64] fix some bugs --- API/src/main/java/net/juligames/core/api/API.java | 1 + API/src/main/java/net/juligames/core/api/TODO.java | 1 + .../api/config/mapbacked/DictionaryFeedInterpreter.java | 2 +- .../core/api/config/mapbacked/MapFeedInterpreter.java | 2 +- .../core/api/config/property/PropertyInterpreter.java | 2 +- API/src/main/java/net/juligames/core/api/jdbi/DBData.java | 1 + .../net/juligames/core/api/message/MessageRecipient.java | 2 +- .../net/juligames/core/api/minigame/BasicMiniGame.java | 2 +- .../java/net/juligames/core/api/minigame/StartType.java | 2 +- .../net/juligames/core/config/CoreConfigurationApi.java | 8 ++++---- .../net/juligames/core/notification/CoreNotification.java | 8 ++++---- .../juligames/core/notification/CoreNotificationApi.java | 4 ++-- .../core/notification/CoreNotificationSender.java | 8 ++++---- .../core/notification/CoreSimpleNotification.java | 5 +++-- 14 files changed, 26 insertions(+), 22 deletions(-) diff --git a/API/src/main/java/net/juligames/core/api/API.java b/API/src/main/java/net/juligames/core/api/API.java index 2f71545d..bbdef188 100644 --- a/API/src/main/java/net/juligames/core/api/API.java +++ b/API/src/main/java/net/juligames/core/api/API.java @@ -39,6 +39,7 @@ public interface API { * @return your API Instance * @throws APIException if no API is present */ + @SuppressWarnings("SpellCheckingInspection") static @NotNull API get() throws APIException { @MaybePresent Optional api = ApiProvider.optionalApi(); if (api.isEmpty()) { diff --git a/API/src/main/java/net/juligames/core/api/TODO.java b/API/src/main/java/net/juligames/core/api/TODO.java index 517c26e6..bc7364ba 100644 --- a/API/src/main/java/net/juligames/core/api/TODO.java +++ b/API/src/main/java/net/juligames/core/api/TODO.java @@ -6,6 +6,7 @@ * @apiNote Methods annotated with this might throw a {@link net.juligames.core.api.err.dev.TODOException} * @suppression may suppress convert to record and unused */ +@SuppressWarnings("JavadocDeclaration") public @interface TODO { boolean doNotcall(); } diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java index d4f9b5c8..28119755 100644 --- a/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java @@ -31,7 +31,7 @@ public DictionaryFeedInterpreter(@NotNull Supplier> dictio @Override - public @NotNull MapPart interpret(@NotNull String input) throws Exception { + public @NotNull MapPart interpret(@NotNull String input) { return new DictionaryPart<>(input, dictionarySupplier); } diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java index 9ea22e4f..7e610807 100644 --- a/API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java @@ -35,7 +35,7 @@ public MapFeedInterpreter(@NotNull Supplier> mapSupplier, @Override - public @NotNull MapPart interpret(@NotNull String input) throws Exception { + public @NotNull MapPart interpret(@NotNull String input) { return new MapPartImpl<>(input, mapSupplier); } diff --git a/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java b/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java index 13c55f64..ba267a2d 100644 --- a/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/property/PropertyInterpreter.java @@ -108,7 +108,7 @@ private PropertyInterpreter(@NotNull Function getter) { } @Override - public @NotNull E interpret(@NotNull String input) throws Exception { + public @NotNull E interpret(@NotNull String input) { return getter.apply(input); } diff --git a/API/src/main/java/net/juligames/core/api/jdbi/DBData.java b/API/src/main/java/net/juligames/core/api/jdbi/DBData.java index 2402ebc9..750a233a 100644 --- a/API/src/main/java/net/juligames/core/api/jdbi/DBData.java +++ b/API/src/main/java/net/juligames/core/api/jdbi/DBData.java @@ -9,6 +9,7 @@ * You should use a unique keyspace for your data stored in here. If this Feature will not be used, it may be removed * with 2.0 - TANDANA */ +@SuppressWarnings("SpellCheckingInspection") public interface DBData { String getKey(); diff --git a/API/src/main/java/net/juligames/core/api/message/MessageRecipient.java b/API/src/main/java/net/juligames/core/api/message/MessageRecipient.java index d4ae137f..996f6066 100644 --- a/API/src/main/java/net/juligames/core/api/message/MessageRecipient.java +++ b/API/src/main/java/net/juligames/core/api/message/MessageRecipient.java @@ -17,7 +17,7 @@ public interface MessageRecipient { @NotNull String getName(); /** - * Devlivers the specified Message to this MessageRecipient. The message should always be human-readable! + * Delivers the specified Message to this MessageRecipient. The message should always be human-readable! * * @param message the message to deliver */ diff --git a/API/src/main/java/net/juligames/core/api/minigame/BasicMiniGame.java b/API/src/main/java/net/juligames/core/api/minigame/BasicMiniGame.java index 87fe339c..5eca9174 100644 --- a/API/src/main/java/net/juligames/core/api/minigame/BasicMiniGame.java +++ b/API/src/main/java/net/juligames/core/api/minigame/BasicMiniGame.java @@ -39,7 +39,7 @@ default String getFullDescription() { /** * load the MiniGame * - * @return a {@link StartType}: The handling of this is not guaranteed it might start whenever it wants. Its just an indication + * @return a {@link StartType}: The handling of this is not guaranteed it might start whenever it wants. It's just an indication * on when and how you suggest to load it */ @Nullable diff --git a/API/src/main/java/net/juligames/core/api/minigame/StartType.java b/API/src/main/java/net/juligames/core/api/minigame/StartType.java index c4a8d712..1794f0b3 100644 --- a/API/src/main/java/net/juligames/core/api/minigame/StartType.java +++ b/API/src/main/java/net/juligames/core/api/minigame/StartType.java @@ -6,7 +6,7 @@ /** * @author Ture Bentzin * 09.03.2023 - * @apiNote please dont temper with this interface. The current roadmap for this is currently unclear... + * @apiNote please don't temper with this interface. The current roadmap for this is currently unclear... */ @ApiStatus.AvailableSince("1.5") public diff --git a/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java b/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java index 508cf24a..1930762b 100644 --- a/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java +++ b/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java @@ -60,17 +60,17 @@ public Configuration database() { } @Override - public @NotNull OfflineConfiguration createNewOfflineConfiguration(String name) { + public @NotNull OfflineConfiguration createNewOfflineConfiguration(@NotNull String name) { return new OfflineConfiguration(name); } @Override - public @NotNull OfflineConfiguration createNewOfflineConfiguration(Properties defaults) { + public @NotNull OfflineConfiguration createNewOfflineConfiguration(@NotNull Properties defaults) { return new OfflineConfiguration(defaults); } @Override - public @NotNull OfflineConfiguration createNewOfflineConfiguration(Map defaults) { + public @NotNull OfflineConfiguration createNewOfflineConfiguration(@NotNull Map defaults) { return new OfflineConfiguration(defaults.get("configuration_name"), defaults); } @@ -145,7 +145,7 @@ public Configuration database() { } @Override - public @NotNull Configuration merge(@NotNull Configuration c1, Configuration c2) { + public @NotNull Configuration merge(@NotNull Configuration c1, @NotNull Configuration c2) { c1.copyAndAppendContentTo(c2); return c1; } diff --git a/Core/src/main/java/net/juligames/core/notification/CoreNotification.java b/Core/src/main/java/net/juligames/core/notification/CoreNotification.java index a329191f..ee09d942 100644 --- a/Core/src/main/java/net/juligames/core/notification/CoreNotification.java +++ b/Core/src/main/java/net/juligames/core/notification/CoreNotification.java @@ -57,7 +57,7 @@ public CoreNotification(String message, String header, DividedPair * @return The message of this Notification */ @Override - public String message() { + public @NotNull String message() { return message; } @@ -65,7 +65,7 @@ public String message() { * @return The UUID of the sender (member) of this Notification, and the Name of the sender */ @Override - public DividedPair sender() { + public @NotNull DividedPair sender() { return sender; } @@ -73,7 +73,7 @@ public DividedPair sender() { * @return The UUIDs of all the recipients of this Notification, and the names of them */ @Override - public DividedPair[] addresses() { + public DividedPair @NotNull [] addresses() { return addresses; } @@ -81,7 +81,7 @@ public DividedPair[] addresses() { * @return Something that identifies that Notification */ @Override - public String header() { + public @NotNull String header() { return header; } diff --git a/Core/src/main/java/net/juligames/core/notification/CoreNotificationApi.java b/Core/src/main/java/net/juligames/core/notification/CoreNotificationApi.java index c2119c4c..032dd049 100644 --- a/Core/src/main/java/net/juligames/core/notification/CoreNotificationApi.java +++ b/Core/src/main/java/net/juligames/core/notification/CoreNotificationApi.java @@ -31,7 +31,7 @@ public CoreNotificationApi() { } @Override - public boolean registerListener(NotificationListener listener) { + public boolean registerListener(@NotNull NotificationListener listener) { try { listenerRegisterator.register(listener); return true; @@ -41,7 +41,7 @@ public boolean registerListener(NotificationListener listener) { } @Override - public boolean unregisterListener(NotificationListener listener) { + public boolean unregisterListener(@NotNull NotificationListener listener) { try { listenerRegisterator.unregister(listener); return true; diff --git a/Core/src/main/java/net/juligames/core/notification/CoreNotificationSender.java b/Core/src/main/java/net/juligames/core/notification/CoreNotificationSender.java index fc2f1c79..e274ff7c 100644 --- a/Core/src/main/java/net/juligames/core/notification/CoreNotificationSender.java +++ b/Core/src/main/java/net/juligames/core/notification/CoreNotificationSender.java @@ -20,7 +20,7 @@ public class CoreNotificationSender implements NotificationSender { @Override - public void sendNotification(SimpleNotification notification, UUID @NotNull ... addresses) { + public void sendNotification(@NotNull SimpleNotification notification, UUID @NotNull ... addresses) { final HazelcastInstance hazelcastInstance = Core.getInstance().getOrThrow(); final ClientService clientService = hazelcastInstance.getClientService(); //Maybe removed @@ -67,7 +67,7 @@ public void sendNotification(SimpleNotification notification, UUID @NotNull ... @Override - public void broadcastNotification(SimpleNotification notification) { + public void broadcastNotification(@NotNull SimpleNotification notification) { //members first ArrayList uuids = new ArrayList<>(); Collections.addAll(uuids, Core.getInstance().getClusterApi().getMembers()); @@ -81,12 +81,12 @@ public void broadcastNotification(SimpleNotification notification) { } @Override - public void sendNotification(String header, String message, UUID... addressees) { + public void sendNotification(@NotNull String header, @NotNull String message, UUID @NotNull ... addressees) { sendNotification(new CoreSimpleNotification(header, message), addressees); } @Override - public void broadcastNotification(String header, String message) { + public void broadcastNotification(@NotNull String header, @NotNull String message) { broadcastNotification(new CoreSimpleNotification(header, message)); } diff --git a/Core/src/main/java/net/juligames/core/notification/CoreSimpleNotification.java b/Core/src/main/java/net/juligames/core/notification/CoreSimpleNotification.java index 0d19015f..832848f1 100644 --- a/Core/src/main/java/net/juligames/core/notification/CoreSimpleNotification.java +++ b/Core/src/main/java/net/juligames/core/notification/CoreSimpleNotification.java @@ -1,6 +1,7 @@ package net.juligames.core.notification; import net.juligames.core.api.notification.SimpleNotification; +import org.jetbrains.annotations.NotNull; /** * @author Ture Bentzin @@ -25,7 +26,7 @@ class CoreSimpleNotification implements SimpleNotification { * @return Something that identifies that Notification */ @Override - public String header() { + public @NotNull String header() { return header; } @@ -33,7 +34,7 @@ public String header() { * @return The message of the Notification */ @Override - public String message() { + public @NotNull String message() { return message; } } From 212f6eedf09d3bf6655645a6f6c20d73d3b294ee Mon Sep 17 00:00:00 2001 From: TDR Date: Sat, 11 Mar 2023 15:19:26 +0100 Subject: [PATCH 34/64] add debugNotifications flag for automatic notification printing --- .../juligames/core/notification/CoreNotificationApi.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Core/src/main/java/net/juligames/core/notification/CoreNotificationApi.java b/Core/src/main/java/net/juligames/core/notification/CoreNotificationApi.java index 032dd049..62119eaa 100644 --- a/Core/src/main/java/net/juligames/core/notification/CoreNotificationApi.java +++ b/Core/src/main/java/net/juligames/core/notification/CoreNotificationApi.java @@ -78,9 +78,12 @@ public Set

getBlacklist() { @Override public void onMessage(Message message) { //call Debug... - new DebugNotificationPrinter().onMessage(message); //TODO This will stay until its finally tested under heavy load - for (NotificationListener notificationListener : listenerRegisterator) { - notificationListener.onNotification(message.getMessageObject().deserialize()); + if(Boolean.getBoolean("debugNotifications")) { + new DebugNotificationPrinter().onMessage(message); + for (NotificationListener notificationListener : listenerRegisterator) { + notificationListener.onNotification(message.getMessageObject().deserialize()); + } } + } } From 112e07e9bf03dd4451c7d2ba1469dc514f088909 Mon Sep 17 00:00:00 2001 From: TDR Date: Sat, 11 Mar 2023 15:21:07 +0100 Subject: [PATCH 35/64] Update CoreNotificationApi.java --- .../net/juligames/core/notification/CoreNotificationApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/main/java/net/juligames/core/notification/CoreNotificationApi.java b/Core/src/main/java/net/juligames/core/notification/CoreNotificationApi.java index 62119eaa..7ab38d19 100644 --- a/Core/src/main/java/net/juligames/core/notification/CoreNotificationApi.java +++ b/Core/src/main/java/net/juligames/core/notification/CoreNotificationApi.java @@ -35,7 +35,7 @@ public boolean registerListener(@NotNull NotificationListener listener) { try { listenerRegisterator.register(listener); return true; - } catch (Registerator.DuplicateEntryException ignore) { + } catch (Registerator.DuplicateEntryException ignored) { return false; } } From a22e856854edec3e4d6c88ab57537225a94a7757 Mon Sep 17 00:00:00 2001 From: TDR Date: Tue, 14 Mar 2023 18:02:18 +0100 Subject: [PATCH 36/64] bump 1.5 --- API/pom.xml | 2 +- AdventureAPI/pom.xml | 4 +- AdventureCore/pom.xml | 4 +- Core/pom.xml | 4 +- Core/src/main/resources/hazelcast-client.xml | 1 + HazelAPI/pom.xml | 4 +- Master/dependency-reduced-pom.xml | 85 +++++++------- Master/pom.xml | 4 +- MiniGameAPI/pom.xml | 4 +- PaperAPI/pom.xml | 4 +- .../core/paper/misc/PluginLogger.java | 28 +++++ PaperCore/dependency-reduced-pom.xml | 105 +++++++++--------- PaperCore/pom.xml | 8 +- PaperCore/src/main/resources/plugin.yml | 2 +- VelocityAPI/pom.xml | 4 +- VelocityCore/dependency-reduced-pom.xml | 105 +++++++++--------- VelocityCore/pom.xml | 8 +- .../juligames/core/velocity/VelocityCore.java | 2 +- config/test | 3 - pom.xml | 2 +- 20 files changed, 203 insertions(+), 180 deletions(-) create mode 100644 PaperAPI/src/main/java/net/juligames/core/paper/misc/PluginLogger.java delete mode 100644 config/test diff --git a/API/pom.xml b/API/pom.xml index baf8ff93..90c3a538 100644 --- a/API/pom.xml +++ b/API/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.5-SNAPSHOT + 1.5 4.0.0 diff --git a/AdventureAPI/pom.xml b/AdventureAPI/pom.xml index 343f6e57..a183bb67 100644 --- a/AdventureAPI/pom.xml +++ b/AdventureAPI/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.5-SNAPSHOT + 1.5 4.0.0 @@ -24,7 +24,7 @@ net.juligames.core API - 1.5-SNAPSHOT + 1.5 diff --git a/AdventureCore/pom.xml b/AdventureCore/pom.xml index fe28c5b2..a75dd7db 100644 --- a/AdventureCore/pom.xml +++ b/AdventureCore/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.5-SNAPSHOT + 1.5 4.0.0 @@ -22,7 +22,7 @@ net.juligames.core AdventureAPI - 1.5-SNAPSHOT + 1.5 diff --git a/Core/pom.xml b/Core/pom.xml index b5c98274..d9e9e55d 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.5-SNAPSHOT + 1.5 4.0.0 @@ -24,7 +24,7 @@ net.juligames.core HazelAPI - 1.5-SNAPSHOT + 1.5 org.jdbi diff --git a/Core/src/main/resources/hazelcast-client.xml b/Core/src/main/resources/hazelcast-client.xml index 11d3214d..a5b29014 100644 --- a/Core/src/main/resources/hazelcast-client.xml +++ b/Core/src/main/resources/hazelcast-client.xml @@ -31,4 +31,5 @@ xsi:schemaLocation="http://www.hazelcast.com/schema/client-config http://www.hazelcast.com/schema/client-config/hazelcast-client-config-5.2.xsd"> Core Cluster + < diff --git a/HazelAPI/pom.xml b/HazelAPI/pom.xml index a1ad14a5..d08ccce7 100644 --- a/HazelAPI/pom.xml +++ b/HazelAPI/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.5-SNAPSHOT + 1.5 4.0.0 @@ -28,7 +28,7 @@ net.juligames.core API - 1.5-SNAPSHOT + 1.5 compile diff --git a/Master/dependency-reduced-pom.xml b/Master/dependency-reduced-pom.xml index 792d1f67..a568e1ab 100644 --- a/Master/dependency-reduced-pom.xml +++ b/Master/dependency-reduced-pom.xml @@ -1,45 +1,44 @@ - - - JuliGamesCore - net.juligames.core - 1.5-SNAPSHOT - - 4.0.0 - Master - - - - maven-shade-plugin - 3.4.1 - - - package - - shade - - - - - - - maven-jar-plugin - 3.3.0 - - - - true - net.juligames.core.master.CoreMaster - - - - - - - - 17 - 17 - UTF-8 - + + + JuliGamesCore + net.juligames.core + 1.5 + + 4.0.0 + Master + + + + maven-shade-plugin + 3.4.1 + + + package + + shade + + + + + + + maven-jar-plugin + 3.3.0 + + + + true + net.juligames.core.master.CoreMaster + + + + + + + + 17 + 17 + UTF-8 + diff --git a/Master/pom.xml b/Master/pom.xml index 49b6b804..54452e2e 100644 --- a/Master/pom.xml +++ b/Master/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.5-SNAPSHOT + 1.5 4.0.0 @@ -22,7 +22,7 @@ net.juligames.core Core - 1.5-SNAPSHOT + 1.5 org.jetbrains diff --git a/MiniGameAPI/pom.xml b/MiniGameAPI/pom.xml index 26724fd9..8fce11d3 100644 --- a/MiniGameAPI/pom.xml +++ b/MiniGameAPI/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.5-SNAPSHOT + 1.5 4.0.0 @@ -22,7 +22,7 @@ net.juligames.core PaperAPI - 1.5-SNAPSHOT + 1.5 provided diff --git a/PaperAPI/pom.xml b/PaperAPI/pom.xml index 12fbcbc9..b529d78b 100644 --- a/PaperAPI/pom.xml +++ b/PaperAPI/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.5-SNAPSHOT + 1.5 4.0.0 @@ -28,7 +28,7 @@ net.juligames.core AdventureAPI - 1.5-SNAPSHOT + 1.5 compile diff --git a/PaperAPI/src/main/java/net/juligames/core/paper/misc/PluginLogger.java b/PaperAPI/src/main/java/net/juligames/core/paper/misc/PluginLogger.java new file mode 100644 index 00000000..bd551cb7 --- /dev/null +++ b/PaperAPI/src/main/java/net/juligames/core/paper/misc/PluginLogger.java @@ -0,0 +1,28 @@ +package net.juligames.core.paper.misc; + +import de.bentzin.tools.logging.JavaLogger; +import de.bentzin.tools.logging.Logger; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +/** + * @apiNote uses the {@link JavaLogger} and does not store the plugin. The {@link java.util.logging.Logger} that is present + * at the moment of the execution of the constructor is used! In the case that your logger needs to be dynamic, i suggest + * building your own Logger implementation! + * @author Ture Bentzin + * 11.03.2023 + * @see net.juligames.core.util.ConsumingLogger; (only present with Core) + */ + @SuppressWarnings("JavadocReference") + @ApiStatus.AvailableSince("1.5") +public class PluginLogger extends JavaLogger { + + public PluginLogger(String name, @NotNull Logger parent, @NotNull Plugin plugin) { + super(name, parent, plugin.getLogger()); + } + + public PluginLogger(String name, @NotNull Plugin plugin) { + super(name, plugin.getLogger()); + } +} diff --git a/PaperCore/dependency-reduced-pom.xml b/PaperCore/dependency-reduced-pom.xml index 83b8b779..5a045d83 100644 --- a/PaperCore/dependency-reduced-pom.xml +++ b/PaperCore/dependency-reduced-pom.xml @@ -1,55 +1,54 @@ - - - JuliGamesCore - net.juligames.core - 1.5-SNAPSHOT - - 4.0.0 - PaperCore - - - - true - src/main/resources - - - - - maven-shade-plugin - 3.4.1 - - - package - - shade - - - - - false - - - - - - - papermc - https://repo.papermc.io/repository/maven-public/ - - - - - io.papermc.paper - paper-api - 1.18.2-R0.1-SNAPSHOT - provided - - - - 17 - 17 - UTF-8 - + + + JuliGamesCore + net.juligames.core + 1.5 + + 4.0.0 + PaperCore + + + + true + src/main/resources + + + + + maven-shade-plugin + 3.4.1 + + + package + + shade + + + + + false + + + + + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + io.papermc.paper + paper-api + 1.18.2-R0.1-SNAPSHOT + provided + + + + 17 + 17 + UTF-8 + diff --git a/PaperCore/pom.xml b/PaperCore/pom.xml index 25118555..7fb7f88f 100644 --- a/PaperCore/pom.xml +++ b/PaperCore/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.5-SNAPSHOT + 1.5 4.0.0 @@ -16,19 +16,19 @@ net.juligames.core PaperAPI - 1.5-SNAPSHOT + 1.5 compile net.juligames.core Core - 1.5-SNAPSHOT + 1.5 compile net.juligames.core AdventureCore - 1.5-SNAPSHOT + 1.5 compile diff --git a/PaperCore/src/main/resources/plugin.yml b/PaperCore/src/main/resources/plugin.yml index 955c1807..1c1f1d5b 100644 --- a/PaperCore/src/main/resources/plugin.yml +++ b/PaperCore/src/main/resources/plugin.yml @@ -20,5 +20,5 @@ commands: description: start the installed miniGame usage: /start printMessageCache: - description: Print the local MessageCache + description: print the local MessageCache usage: / \ No newline at end of file diff --git a/VelocityAPI/pom.xml b/VelocityAPI/pom.xml index a5f93fd7..afdfeaf7 100644 --- a/VelocityAPI/pom.xml +++ b/VelocityAPI/pom.xml @@ -7,7 +7,7 @@ JuliGamesCore net.juligames.core - 1.5-SNAPSHOT + 1.5 4.0.0 @@ -30,7 +30,7 @@ net.juligames.core AdventureAPI - 1.5-SNAPSHOT + 1.5 compile diff --git a/VelocityCore/dependency-reduced-pom.xml b/VelocityCore/dependency-reduced-pom.xml index fa5c7e24..afce49d1 100644 --- a/VelocityCore/dependency-reduced-pom.xml +++ b/VelocityCore/dependency-reduced-pom.xml @@ -1,55 +1,54 @@ - - - JuliGamesCore - net.juligames.core - 1.5-SNAPSHOT - - 4.0.0 - VelocityCore - - - - maven-shade-plugin - 3.4.1 - - - package - - shade - - - - - false - - - - - - - papermc - papermc - https://repo.papermc.io/repository/maven-public/ - - - juligames-juligames - Juligames Maven - https://maven.juligames.net/juligames - - - - - com.velocitypowered - velocity-api - 3.1.1 - provided - - - - 17 - 17 - UTF-8 - + + + JuliGamesCore + net.juligames.core + 1.5 + + 4.0.0 + VelocityCore + + + + maven-shade-plugin + 3.4.1 + + + package + + shade + + + + + false + + + + + + + papermc + papermc + https://repo.papermc.io/repository/maven-public/ + + + juligames-juligames + Juligames Maven + https://maven.juligames.net/juligames + + + + + com.velocitypowered + velocity-api + 3.1.1 + provided + + + + 17 + 17 + UTF-8 + diff --git a/VelocityCore/pom.xml b/VelocityCore/pom.xml index 0884d1bf..0cbb5179 100644 --- a/VelocityCore/pom.xml +++ b/VelocityCore/pom.xml @@ -6,7 +6,7 @@ JuliGamesCore net.juligames.core - 1.5-SNAPSHOT + 1.5 4.0.0 @@ -22,7 +22,7 @@ net.juligames.core VelocityAPI - 1.5-SNAPSHOT + 1.5 compile @@ -34,13 +34,13 @@ net.juligames.core Core - 1.5-SNAPSHOT + 1.5 compile net.juligames.core AdventureCore - 1.5-SNAPSHOT + 1.5 compile diff --git a/VelocityCore/src/main/java/net/juligames/core/velocity/VelocityCore.java b/VelocityCore/src/main/java/net/juligames/core/velocity/VelocityCore.java index a7a414f1..577c53da 100644 --- a/VelocityCore/src/main/java/net/juligames/core/velocity/VelocityCore.java +++ b/VelocityCore/src/main/java/net/juligames/core/velocity/VelocityCore.java @@ -23,7 +23,7 @@ * 03.12.2022 */ -@Plugin(id = "velocitycore", name = "JuliGames Velocity Core", version = "1.5-SNAPSHOT", +@Plugin(id = "velocitycore", name = "JuliGames Velocity Core", version = "1.5", url = "https://github.com/JuliGames/JuliGamesCore", description = "Velocity Client for the core - necessary to provide the API here", authors = {"Ture Bentzin"}) public final class VelocityCore { diff --git a/config/test b/config/test deleted file mode 100644 index 75c6cd31..00000000 --- a/config/test +++ /dev/null @@ -1,3 +0,0 @@ -#configuration_header written at: 2022-11-27 | 03:48:32 -#Sun Nov 27 15:48:32 CET 2022 -configuration_name=test diff --git a/pom.xml b/pom.xml index 806f3534..3f1f5127 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ net.juligames.core JuliGamesCore pom - 1.5-SNAPSHOT + 1.5 PaperCore Core From e29ddd7ff04142cab2c91e8a365827d4deb4f2d0 Mon Sep 17 00:00:00 2001 From: TDR Date: Tue, 14 Mar 2023 18:05:11 +0100 Subject: [PATCH 37/64] bump Core and Adventure to 1.5 --- .../java/net/juligames/core/adventure/api/AdventureAPI.java | 2 +- .../main/java/net/juligames/core/adventure/AdventureCore.java | 2 +- Core/src/main/java/net/juligames/core/Core.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AdventureAPI.java b/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AdventureAPI.java index 95d54b3b..0ddd9055 100644 --- a/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AdventureAPI.java +++ b/AdventureAPI/src/main/java/net/juligames/core/adventure/api/AdventureAPI.java @@ -18,7 +18,7 @@ * Please make sure the modules (AdventureAPI & AdventureCore) are the same version to avoid issues while execution! */ public interface AdventureAPI { - @NotNull String API_VERSION = "1.5-SNAPSHOT"; + @NotNull String API_VERSION = "1.5"; static @NotNull AdventureAPI get() { AdventureAPI api = AdventureAPICore.getAPI(); diff --git a/AdventureCore/src/main/java/net/juligames/core/adventure/AdventureCore.java b/AdventureCore/src/main/java/net/juligames/core/adventure/AdventureCore.java index 8968ec6a..0a6bd57d 100644 --- a/AdventureCore/src/main/java/net/juligames/core/adventure/AdventureCore.java +++ b/AdventureCore/src/main/java/net/juligames/core/adventure/AdventureCore.java @@ -21,7 +21,7 @@ * support it. Because of this the AdventureAPI will only function as intended when bundled with the API you are using! */ public class AdventureCore implements AdventureAPI { - final String CORE_VERSION = "1.5-SNAPSHOT"; + final String CORE_VERSION = "1.5"; private CoreAdventureTagManager adventureTagManager; private Logger logger; diff --git a/Core/src/main/java/net/juligames/core/Core.java b/Core/src/main/java/net/juligames/core/Core.java index dc06a0cf..750db1a8 100644 --- a/Core/src/main/java/net/juligames/core/Core.java +++ b/Core/src/main/java/net/juligames/core/Core.java @@ -48,9 +48,9 @@ public final class Core implements API { * This can be set depending on the build of the Core */ public static final String CORE_BRAND = "Core"; - public static final String CORE_VERSION_NUMBER = "1.5-SNAPSHOT"; + public static final String CORE_VERSION_NUMBER = "1.5"; public static final String CORE_SPECIFICATION = "Gustav"; - private static final String BUILD_VERSION = "1.5-SNAPSHOT"; //POM VERSION + private static final String BUILD_VERSION = "1.5"; //POM VERSION private static Core core; private final Registerator> hazelcastPostPreparationWorkers = new Registerator<>("hazelcastPostPreparationWorkers"); From c30223eba4ab3bb2e04103f04aa2e7df75e30d71 Mon Sep 17 00:00:00 2001 From: TDR Date: Wed, 15 Mar 2023 09:50:42 +0100 Subject: [PATCH 38/64] boolean exists(String name); --- .../net/juligames/core/api/config/ConfigurationAPI.java | 7 +++++++ .../java/net/juligames/core/config/CoreConfiguration.java | 7 ++++++- .../net/juligames/core/config/CoreConfigurationApi.java | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java b/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java index 0d295799..3bbea92d 100644 --- a/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java +++ b/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java @@ -31,6 +31,13 @@ public interface ConfigurationAPI { */ @NotNull Configuration getOrCreate(@NotNull Properties defaults); + /** + * This will check if a configuration with the given name exists or not + * @param name the name + * @return if an associated {@link Configuration} was found + */ + boolean exists(String name); + @NotNull Configuration master(); @NotNull Comparator comparator(); diff --git a/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java b/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java index c2807117..4eec932c 100644 --- a/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java +++ b/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java @@ -30,6 +30,11 @@ public class CoreConfiguration implements Configuration { private IMap data; + public static @NotNull String generateHazel(@NotNull String name, boolean containingPrefix) { + return containingPrefix ? name : "config:" + name; + } + + public CoreConfiguration(String name) { this.name = name; data = hazel(); @@ -84,7 +89,7 @@ public CoreConfiguration(String name) { @ApiStatus.Internal private @NotNull IMap hazel(@SuppressWarnings("SameParameterValue") boolean containingPrefix) { - return Core.getInstance().getOrThrow().getMap(containingPrefix ? name : "config:" + name); + return Core.getInstance().getOrThrow().getMap(generateHazel(name,containingPrefix)); } public void updateHazel() { diff --git a/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java b/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java index 1930762b..c52448b4 100644 --- a/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java +++ b/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java @@ -1,5 +1,7 @@ package net.juligames.core.config; +import net.juligames.core.Core; +import net.juligames.core.api.API; import net.juligames.core.api.config.ConfigWriter; import net.juligames.core.api.config.Configuration; import net.juligames.core.api.config.ConfigurationAPI; @@ -38,6 +40,11 @@ public class CoreConfigurationApi implements ConfigurationAPI { return CoreConfiguration.fromProperties(defaults); } + @Override + public boolean exists(String name) { + return Core.getInstance().getHazelDataApi().getAll().stream().anyMatch(distributedObject -> distributedObject.getName().equals(name)); + } + @Override public @NotNull CoreConfiguration master() { return getOrCreate(MASTER_CONFIG_NAME); From 8a520dafd528ef2cd3981ac1c524485d61086a07 Mon Sep 17 00:00:00 2001 From: TDR Date: Wed, 15 Mar 2023 10:27:08 +0100 Subject: [PATCH 39/64] Update LegacyToAnsiConverter.java --- .../core/paper/{msc => misc}/LegacyToAnsiConverter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename PaperAPI/src/main/java/net/juligames/core/paper/{msc => misc}/LegacyToAnsiConverter.java (91%) diff --git a/PaperAPI/src/main/java/net/juligames/core/paper/msc/LegacyToAnsiConverter.java b/PaperAPI/src/main/java/net/juligames/core/paper/misc/LegacyToAnsiConverter.java similarity index 91% rename from PaperAPI/src/main/java/net/juligames/core/paper/msc/LegacyToAnsiConverter.java rename to PaperAPI/src/main/java/net/juligames/core/paper/misc/LegacyToAnsiConverter.java index 4cd995d9..9e8fc746 100644 --- a/PaperAPI/src/main/java/net/juligames/core/paper/msc/LegacyToAnsiConverter.java +++ b/PaperAPI/src/main/java/net/juligames/core/paper/misc/LegacyToAnsiConverter.java @@ -1,4 +1,4 @@ -package net.juligames.core.paper.msc; +package net.juligames.core.paper.misc; import net.juligames.core.api.err.dev.TODOException; import org.bukkit.ChatColor; From 9d4cd586221a524b1a64d08d2761eb977544b724 Mon Sep 17 00:00:00 2001 From: TDR Date: Wed, 15 Mar 2023 10:27:17 +0100 Subject: [PATCH 40/64] bump DevTools --- API/pom.xml | 2 +- .../core/api/misc/LoggerMessageRecipient.java | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 API/src/main/java/net/juligames/core/api/misc/LoggerMessageRecipient.java diff --git a/API/pom.xml b/API/pom.xml index 90c3a538..eda2ec2e 100644 --- a/API/pom.xml +++ b/API/pom.xml @@ -58,7 +58,7 @@ de.bentzin.tools DevTools - 2.2 + 2.3 compile diff --git a/API/src/main/java/net/juligames/core/api/misc/LoggerMessageRecipient.java b/API/src/main/java/net/juligames/core/api/misc/LoggerMessageRecipient.java new file mode 100644 index 00000000..0a98bdd7 --- /dev/null +++ b/API/src/main/java/net/juligames/core/api/misc/LoggerMessageRecipient.java @@ -0,0 +1,39 @@ +package net.juligames.core.api.misc; + +import de.bentzin.tools.logging.Logger; +import net.juligames.core.api.message.Message; +import net.juligames.core.api.message.MessageRecipient; +import net.juligames.core.api.message.MiniMessageSerializer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Ture Bentzin + * 15.03.2023 + */ +public record LoggerMessageRecipient(Logger logger, @Nullable MiniMessageSerializer miniMessageSerializer) implements MessageRecipient { + @Override + public @NotNull String getName() { + return logger.getFullName(); + } + + @Override + public void deliver(@NotNull Message message) { + if(miniMessageSerializer != null) + logger.info(message.getPlainMessage(miniMessageSerializer)); + else logger.info("UNPARSED: " + message.getPreparedMiniMessage()); + } + + @SuppressWarnings("deprecation") + @Override + public void deliver(@NotNull String miniMessage) { + if(miniMessageSerializer != null) + logger.info(miniMessageSerializer.resolvePlain(miniMessage)); + else logger.info("UNPARSED: " + miniMessage); + } + + @Override + public @Nullable String supplyLocale() { + return null; + } +} From 34efad43c77d5ddf812f3a9a94b78456e3ce6431 Mon Sep 17 00:00:00 2001 From: TDR Date: Wed, 15 Mar 2023 11:07:56 +0100 Subject: [PATCH 41/64] add some interpretation --- .../core/api/config/BuildInInterpreters.java | 71 ++++++++++++++++++- .../core/api/config/Configuration.java | 3 + .../core/api/config/EnumInterpreter.java | 33 +++++++++ .../core/api/misc/LoggerMessageRecipient.java | 2 + .../core/config/CoreConfiguration.java | 4 +- .../core/config/OfflineConfiguration.java | 3 +- .../misc/PaperLoggerMessageRecipientUtil.java | 25 +++++++ 7 files changed, 136 insertions(+), 5 deletions(-) create mode 100644 API/src/main/java/net/juligames/core/api/config/EnumInterpreter.java create mode 100644 PaperAPI/src/main/java/net/juligames/core/paper/misc/PaperLoggerMessageRecipientUtil.java diff --git a/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java b/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java index 271ab3bc..7c52206e 100644 --- a/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java +++ b/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java @@ -1,5 +1,9 @@ package net.juligames.core.api.config; +import net.juligames.core.api.API; +import net.juligames.core.api.jdbi.DBData; +import net.juligames.core.api.jdbi.DataDAO; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -7,8 +11,13 @@ import java.net.URI; import java.net.URL; import java.text.DateFormat; +import java.time.DateTimeException; +import java.time.Duration; import java.time.Instant; +import java.time.temporal.TemporalUnit; import java.util.Date; +import java.util.NoSuchElementException; +import java.util.Objects; import java.util.UUID; /** @@ -55,15 +64,73 @@ public interface BuildInInterpreters { static @NotNull Interpreter> clazzInterpreter() { return new Interpreter<>() { @Override - public @NotNull Class interpret(String input) throws Exception { + public @NotNull Class interpret(@NotNull String input) throws Exception { return Class.forName(input); } @Override - public @NotNull String reverse(Class tClass) { + public @NotNull String reverse(@NotNull Class tClass) { return tClass.getName(); } }; } + + + + @ApiStatus.AvailableSince("1.5") + @Contract(value = "_ -> new", pure = true) + static @NotNull Interpreter onlineConfigurationInterpreter(boolean createIfNotExists) { + return new Interpreter<>() { + @Override + public @NotNull Configuration interpret(@NotNull String input) throws Exception { + if (!createIfNotExists && !API.get().getConfigurationApi().exists(input)) { + throw new NoSuchElementException(input + " has no associated configuration!"); + } + return API.get().getConfigurationApi().getOrCreate(input); + } + + @Override + public @NotNull String reverse(@NotNull Configuration configuration) { + return configuration.getName(); + } + }; + } + + ; + + @Contract(value = "_ -> new", pure = true) + @ApiStatus.AvailableSince("1.5") + static @NotNull Interpreter durationInterpreter(TemporalUnit unit) { + return new Interpreter<>() { + @Override + public @NotNull Duration interpret(String input) throws DateTimeException, ArithmeticException, NumberFormatException { + return Duration.of(Long.parseLong(input), unit); + } + + @Override + public @NotNull String reverse(Duration duration) { + return String.valueOf(duration.get(unit)); + } + }; + } + + @Contract(value = " -> new", pure = true) + @ApiStatus.Experimental + @ApiStatus.AvailableSince("1.5") + static @NotNull Interpreter dbDataInterpreter() { + return new Interpreter<>() { + @Override + public @NotNull DBData interpret(String input) throws Exception { + return Objects.requireNonNull(API.get().getSQLManager().withExtension(DataDAO.class, extension -> + extension.select(input))); + } + + @Override + public @NotNull String reverse(DBData dbData) { + return dbData.getKey(); + } + }; + } + } diff --git a/API/src/main/java/net/juligames/core/api/config/Configuration.java b/API/src/main/java/net/juligames/core/api/config/Configuration.java index 9fe1f9f8..83e622af 100644 --- a/API/src/main/java/net/juligames/core/api/config/Configuration.java +++ b/API/src/main/java/net/juligames/core/api/config/Configuration.java @@ -353,6 +353,9 @@ default int compareTo(@NotNull Configuration o) { @NotNull Stream searchValue(@NotNull String value); + @ApiStatus.AvailableSince("1.5") + @NotNull String getName(); + //from map /** diff --git a/API/src/main/java/net/juligames/core/api/config/EnumInterpreter.java b/API/src/main/java/net/juligames/core/api/config/EnumInterpreter.java new file mode 100644 index 00000000..cd3e9b52 --- /dev/null +++ b/API/src/main/java/net/juligames/core/api/config/EnumInterpreter.java @@ -0,0 +1,33 @@ +package net.juligames.core.api.config; + +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +/** + * @author Ture Bentzin + * 15.03.2023 + */ +@ApiStatus.AvailableSince("1.5") +@ApiStatus.Experimental +public class EnumInterpreter> implements Interpreter { + + private final Class enumClazz; + + public EnumInterpreter(Class enumClazz) { + this.enumClazz = enumClazz; + } + + @Override + public @NotNull T interpret(@NotNull String input) throws Exception { + return T.valueOf(enumClazz, input); + } + + @Override + public @NotNull String reverse(@NotNull T t) { + return t.name(); + } + + public Class getEnumClazz() { + return enumClazz; + } +} diff --git a/API/src/main/java/net/juligames/core/api/misc/LoggerMessageRecipient.java b/API/src/main/java/net/juligames/core/api/misc/LoggerMessageRecipient.java index 0a98bdd7..98bdd1d6 100644 --- a/API/src/main/java/net/juligames/core/api/misc/LoggerMessageRecipient.java +++ b/API/src/main/java/net/juligames/core/api/misc/LoggerMessageRecipient.java @@ -4,6 +4,7 @@ import net.juligames.core.api.message.Message; import net.juligames.core.api.message.MessageRecipient; import net.juligames.core.api.message.MiniMessageSerializer; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -11,6 +12,7 @@ * @author Ture Bentzin * 15.03.2023 */ +@ApiStatus.AvailableSince("1.5") public record LoggerMessageRecipient(Logger logger, @Nullable MiniMessageSerializer miniMessageSerializer) implements MessageRecipient { @Override public @NotNull String getName() { diff --git a/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java b/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java index 4eec932c..78af38f5 100644 --- a/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java +++ b/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java @@ -38,7 +38,6 @@ public class CoreConfiguration implements Configuration { public CoreConfiguration(String name) { this.name = name; data = hazel(); - assert Objects.equals(getStringOrNull("configuration_name"), name); //just to avoid BNick content in the configurationSystem String configuration_header = getStringOrNull("configuration_header"); @@ -722,7 +721,8 @@ public void setHeader_comment(String header_comment) { this.header_comment = header_comment; } - public String getName() { + @Override + public @NotNull String getName() { return name; } diff --git a/Core/src/main/java/net/juligames/core/config/OfflineConfiguration.java b/Core/src/main/java/net/juligames/core/config/OfflineConfiguration.java index 2e4cce5d..81d40dfe 100644 --- a/Core/src/main/java/net/juligames/core/config/OfflineConfiguration.java +++ b/Core/src/main/java/net/juligames/core/config/OfflineConfiguration.java @@ -785,7 +785,8 @@ public void setHeader_comment(String header_comment) { this.header_comment = header_comment; } - public String getName() { + @Override + public @NotNull String getName() { return name; } diff --git a/PaperAPI/src/main/java/net/juligames/core/paper/misc/PaperLoggerMessageRecipientUtil.java b/PaperAPI/src/main/java/net/juligames/core/paper/misc/PaperLoggerMessageRecipientUtil.java new file mode 100644 index 00000000..793f4c07 --- /dev/null +++ b/PaperAPI/src/main/java/net/juligames/core/paper/misc/PaperLoggerMessageRecipientUtil.java @@ -0,0 +1,25 @@ +package net.juligames.core.paper.misc; + +import net.juligames.core.adventure.api.AdventureAPI; +import net.juligames.core.api.misc.LoggerMessageRecipient; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +/** + * @author Ture Bentzin + * 15.03.2023 + */ +@ApiStatus.AvailableSince("1.5") +public class PaperLoggerMessageRecipientUtil { + + private PaperLoggerMessageRecipientUtil() { + + } + + @ApiStatus.AvailableSince("1.5") + public static @NotNull LoggerMessageRecipient getMessageRecipient(@NotNull Plugin plugin) { + return new LoggerMessageRecipient(new PluginLogger(plugin.getName(), plugin), + AdventureAPI.get().getAdventureTagManager()); + } +} From 1aee57c0804e3ec69dd930361bf3bedfb882dd4d Mon Sep 17 00:00:00 2001 From: TDR Date: Wed, 15 Mar 2023 11:21:52 +0100 Subject: [PATCH 42/64] some bugfixes --- .../net/juligames/core/api/config/BuildInInterpreters.java | 2 -- .../net/juligames/core/api/config/ConfigurationAPI.java | 1 + .../api/config/mapbacked/DictionaryFeedInterpreter.java | 2 ++ .../core/api/config/mapbacked/HazelFeedMapInterpreter.java | 1 + .../main/java/net/juligames/core/api/err/APIException.java | 3 +++ .../java/net/juligames/core/api/minigame/StartType.java | 3 +-- .../juligames/core/adventure/CoreAdventureTagManager.java | 7 ++----- .../java/net/juligames/core/message/FallBackMessage.java | 3 ++- Core/src/main/resources/hazelcast-client.xml | 1 - .../core/paper/misc/ConfigurationYAMLConverter.java | 4 ++-- .../main/java/net/juligames/core/paper/bstats/Metrics.java | 4 ++-- .../juligames/core/paper/plugin/CorePluginLoadManager.java | 1 + 12 files changed, 17 insertions(+), 15 deletions(-) diff --git a/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java b/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java index 7c52206e..99840d84 100644 --- a/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java +++ b/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java @@ -97,8 +97,6 @@ public interface BuildInInterpreters { }; } - ; - @Contract(value = "_ -> new", pure = true) @ApiStatus.AvailableSince("1.5") static @NotNull Interpreter durationInterpreter(TemporalUnit unit) { diff --git a/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java b/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java index 3bbea92d..91550b79 100644 --- a/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java +++ b/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java @@ -36,6 +36,7 @@ public interface ConfigurationAPI { * @param name the name * @return if an associated {@link Configuration} was found */ + @ApiStatus.AvailableSince("1.5") boolean exists(String name); @NotNull Configuration master(); diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java index 28119755..50ba76f0 100644 --- a/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java @@ -1,6 +1,7 @@ package net.juligames.core.api.config.mapbacked; import net.juligames.core.api.config.Interpreter; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import java.util.Dictionary; @@ -12,6 +13,7 @@ * @author Ture Bentzin * 11.03.2023 */ +@ApiStatus.AvailableSince("1.5") public class DictionaryFeedInterpreter implements Interpreter> { private final @NotNull Supplier> dictionarySupplier; diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/HazelFeedMapInterpreter.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/HazelFeedMapInterpreter.java index feac18eb..a7abd90b 100644 --- a/API/src/main/java/net/juligames/core/api/config/mapbacked/HazelFeedMapInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/HazelFeedMapInterpreter.java @@ -14,6 +14,7 @@ * @author Ture Bentzin * 07.03.2023 */ +@ApiStatus.AvailableSince("1.5") public final class HazelFeedMapInterpreter extends MapFeedInterpreter { public HazelFeedMapInterpreter(@NotNull String hazel) { diff --git a/API/src/main/java/net/juligames/core/api/err/APIException.java b/API/src/main/java/net/juligames/core/api/err/APIException.java index 2c53d897..3f10edd4 100644 --- a/API/src/main/java/net/juligames/core/api/err/APIException.java +++ b/API/src/main/java/net/juligames/core/api/err/APIException.java @@ -1,5 +1,7 @@ package net.juligames.core.api.err; +import org.jetbrains.annotations.ApiStatus; + /** * @author Ture Bentzin * 16.11.2022 @@ -16,6 +18,7 @@ public APIException(String customMessage) { this.customMessage = customMessage; } + @ApiStatus.AvailableSince("1.5") public APIException(Throwable cause) { super(cause); } diff --git a/API/src/main/java/net/juligames/core/api/minigame/StartType.java b/API/src/main/java/net/juligames/core/api/minigame/StartType.java index 1794f0b3..60c621cd 100644 --- a/API/src/main/java/net/juligames/core/api/minigame/StartType.java +++ b/API/src/main/java/net/juligames/core/api/minigame/StartType.java @@ -9,8 +9,7 @@ * @apiNote please don't temper with this interface. The current roadmap for this is currently unclear... */ @ApiStatus.AvailableSince("1.5") -public -interface StartType { +public interface StartType { StartType DIRECT = new SimpleStartType("DIRECT"); StartType DELAYED = new SimpleStartType("DELAYED"); diff --git a/AdventureCore/src/main/java/net/juligames/core/adventure/CoreAdventureTagManager.java b/AdventureCore/src/main/java/net/juligames/core/adventure/CoreAdventureTagManager.java index fd0acbaf..82acc2bf 100644 --- a/AdventureCore/src/main/java/net/juligames/core/adventure/CoreAdventureTagManager.java +++ b/AdventureCore/src/main/java/net/juligames/core/adventure/CoreAdventureTagManager.java @@ -19,10 +19,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Range; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author Ture Bentzin @@ -147,7 +144,7 @@ public void clearResolver() { public void load() { List dbReplacements = API.get().getMessageApi().callReplacementExtension(ReplacementDAO::listAll); - for (DBReplacement replacement : dbReplacements) { + for (DBReplacement replacement : Objects.requireNonNull(dbReplacements)) { register(replacement); } } diff --git a/Core/src/main/java/net/juligames/core/message/FallBackMessage.java b/Core/src/main/java/net/juligames/core/message/FallBackMessage.java index 2cf30a63..6669c082 100644 --- a/Core/src/main/java/net/juligames/core/message/FallBackMessage.java +++ b/Core/src/main/java/net/juligames/core/message/FallBackMessage.java @@ -1,6 +1,7 @@ package net.juligames.core.message; import net.juligames.core.Core; +import org.jetbrains.annotations.ApiStatus; /** * @author Ture Bentzin @@ -9,7 +10,7 @@ public class FallBackMessage extends CoreMessage { - @Deprecated(forRemoval = true) + @ApiStatus.Internal public FallBackMessage() { this("null"); } diff --git a/Core/src/main/resources/hazelcast-client.xml b/Core/src/main/resources/hazelcast-client.xml index a5b29014..11d3214d 100644 --- a/Core/src/main/resources/hazelcast-client.xml +++ b/Core/src/main/resources/hazelcast-client.xml @@ -31,5 +31,4 @@ xsi:schemaLocation="http://www.hazelcast.com/schema/client-config http://www.hazelcast.com/schema/client-config/hazelcast-client-config-5.2.xsd"> Core Cluster - < diff --git a/PaperAPI/src/main/java/net/juligames/core/paper/misc/ConfigurationYAMLConverter.java b/PaperAPI/src/main/java/net/juligames/core/paper/misc/ConfigurationYAMLConverter.java index d2e94f8c..9ce4620d 100644 --- a/PaperAPI/src/main/java/net/juligames/core/paper/misc/ConfigurationYAMLConverter.java +++ b/PaperAPI/src/main/java/net/juligames/core/paper/misc/ConfigurationYAMLConverter.java @@ -43,7 +43,7 @@ public static void convert(@NotNull YamlConfiguration yamlConfiguration, @NotNul Set keys = Objects.requireNonNull(yamlConfiguration).getKeys(true); for (String key : keys) { final String value = yamlConfiguration.getString(key); - configuration.setString(key, value); + configuration.setString(key, Objects.requireNonNull(value)); } } @@ -60,7 +60,7 @@ public static void convert(@NotNull YamlConfiguration yamlConfiguration, @NotNul public static @NotNull Configuration convert(YamlConfiguration yamlConfiguration) { List> map = map(yamlConfiguration); String configurationName = yamlConfiguration.getString("configuration_name"); - Configuration configuration = API.get().getConfigurationApi().getOrCreate(configurationName); + Configuration configuration = API.get().getConfigurationApi().getOrCreate(Objects.requireNonNull(configurationName)); for (Pair stringPair : map) { configuration.set(stringPair); } diff --git a/PaperCore/src/main/java/net/juligames/core/paper/bstats/Metrics.java b/PaperCore/src/main/java/net/juligames/core/paper/bstats/Metrics.java index 7069b8b3..384e958d 100644 --- a/PaperCore/src/main/java/net/juligames/core/paper/bstats/Metrics.java +++ b/PaperCore/src/main/java/net/juligames/core/paper/bstats/Metrics.java @@ -489,7 +489,7 @@ public AdvancedPie(String chartId, Callable> callable) { @Override protected JsonObjectBuilder.JsonObject getChartData() throws Exception { - JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + @SuppressWarnings("DuplicatedCode") JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); Map map = callable.call(); if (map == null || map.isEmpty()) { // Null = skip the chart @@ -573,7 +573,7 @@ public MultiLineChart(String chartId, Callable> callable) { @Override protected JsonObjectBuilder.JsonObject getChartData() throws Exception { - JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); + @SuppressWarnings("DuplicatedCode") JsonObjectBuilder valuesBuilder = new JsonObjectBuilder(); Map map = callable.call(); if (map == null || map.isEmpty()) { // Null = skip the chart diff --git a/PaperCore/src/main/java/net/juligames/core/paper/plugin/CorePluginLoadManager.java b/PaperCore/src/main/java/net/juligames/core/paper/plugin/CorePluginLoadManager.java index 4328753c..6fbe1597 100644 --- a/PaperCore/src/main/java/net/juligames/core/paper/plugin/CorePluginLoadManager.java +++ b/PaperCore/src/main/java/net/juligames/core/paper/plugin/CorePluginLoadManager.java @@ -19,6 +19,7 @@ * @author Ture Bentzin * 08.01.2023 */ +@SuppressWarnings("DuplicatedCode") public class CorePluginLoadManager { private final File directory; From 30b7f72e2c378a86bdbca644face373b92074b2b Mon Sep 17 00:00:00 2001 From: TDR Date: Wed, 15 Mar 2023 18:14:24 +0100 Subject: [PATCH 43/64] add DurationFormat --- API/pom.xml | 6 + .../core/api/misc/DurationFormatUtils.java | 810 ++++++++++++++++++ .../core/adventure/AdventureTagManager.java | 9 + .../adventure/CoreAdventureTagManager.java | 15 +- 4 files changed, 837 insertions(+), 3 deletions(-) create mode 100644 API/src/main/java/net/juligames/core/api/misc/DurationFormatUtils.java diff --git a/API/pom.xml b/API/pom.xml index eda2ec2e..ddf41928 100644 --- a/API/pom.xml +++ b/API/pom.xml @@ -61,6 +61,12 @@ 2.3 compile + + commons-lang + commons-lang + 2.6 + compile + diff --git a/API/src/main/java/net/juligames/core/api/misc/DurationFormatUtils.java b/API/src/main/java/net/juligames/core/api/misc/DurationFormatUtils.java new file mode 100644 index 00000000..de4f44cc --- /dev/null +++ b/API/src/main/java/net/juligames/core/api/misc/DurationFormatUtils.java @@ -0,0 +1,810 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.juligames.core.api.misc; + +import net.juligames.core.api.API; +import net.juligames.core.api.message.Message; +import net.juligames.core.api.message.MiniMessageSerializer; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.text.StrBuilder; +import org.apache.commons.lang.time.DateUtils; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; + +import java.time.Duration; +import java.util.*; + +/** + *

Duration formatting utilities and constants. The following table describes the tokens + * used in the pattern language for formatting.

+ * + * + * + * + * + * + * + * + * + *
characterduration element
yyears
Mmonths
ddays
Hhours
mminutes
sseconds
Smilliseconds
+ * + * @author Apache Software Foundation + * @author Apache Ant - DateUtils + * @author Stephane Bailliez + * @author Stefan Bodewig + * @author Gary Gregory + * @author Ture Bentin (edit) + * @version $Id: DurationFormatUtils.java 1057072 2011-01-10 01:55:57Z niallp $ + * @since 2.1 + */ +@ApiStatus.AvailableSince("duration-format") +public class DurationFormatUtils { + + /** + *

Pattern used with FastDateFormat and SimpleDateFormat + * for the ISO8601 period format used in durations.

+ * + * @see org.apache.commons.lang.time.FastDateFormat + * @see java.text.SimpleDateFormat + */ + public static final @NotNull String ISO_EXTENDED_FORMAT_PATTERN = "'P'yyyy'Y'M'M'd'DT'H'H'm'M's.S'S'"; + static final @NotNull Object y = "y"; + + //----------------------------------------------------------------------- + static final @NotNull Object M = "M"; + static final @NotNull Object d = "d"; + static final @NotNull Object H = "H"; + static final @NotNull Object m = "m"; + static final @NotNull Object s = "s"; + + //----------------------------------------------------------------------- + static final @NotNull Object S = "S"; + public static @NotNull String INTERNAL_MESSAGE_PREFIX = "internal.api.misc.format."; + + /** + *

DurationFormatUtils instances should NOT be constructed in standard programming.

+ * + *

This constructor is public to permit tools that require a JavaBean instance + * to operate.

+ */ + public DurationFormatUtils() { + super(); + } + + //----------------------------------------------------------------------- + + /** + *

Formats the time gap as a string.

+ * + *

The format used is ISO8601-like: + * H:m:s.S.

+ * + * @param durationMillis the duration to format + * @return the time as a String + */ + public static @NotNull String formatDurationHMS(long durationMillis) { + return formatDuration(durationMillis, "H:mm:ss.SSS"); + } + + /** + *

Formats the time gap as a string.

+ * + *

The format used is the ISO8601 period format.

+ * + *

This method formats durations using the days and lower fields of the + * ISO format pattern, such as P7D6TH5M4.321S.

+ * + * @param durationMillis the duration to format + * @return the time as a String + */ + public static @NotNull String formatDurationISO(long durationMillis) { + return formatDuration(durationMillis, ISO_EXTENDED_FORMAT_PATTERN, false); + } + + /** + *

Formats the time gap as a string, using the specified format, and padding with zeros and + * using the default timezone.

+ * + *

This method formats durations using the days and lower fields of the + * format pattern. Months and larger are not used.

+ * + * @param durationMillis the duration to format + * @param format the way in which to format the duration + * @return the time as a String + */ + public static @NotNull String formatDuration(long durationMillis, @NotNull String format) { + return formatDuration(durationMillis, format, true); + } + + /** + *

Formats the time gap as a string, using the specified format. + * Padding the left hand side of numbers with zeroes is optional and + * the timezone may be specified.

+ * + *

This method formats durations using the days and lower fields of the + * format pattern. Months and larger are not used.

+ * + * @param durationMillis the duration to format + * @param format the way in which to format the duration + * @param padWithZeros whether to pad the left hand side of numbers with 0's + * @return the time as a String + */ + public static @NotNull String formatDuration(long durationMillis, @NotNull String format, boolean padWithZeros) { + + Token[] tokens = lexx(format); + + int days = 0; + int hours = 0; + int minutes = 0; + int seconds = 0; + int milliseconds = 0; + + if (Token.containsTokenWithValue(tokens, d)) { + days = (int) (durationMillis / DateUtils.MILLIS_PER_DAY); + durationMillis = durationMillis - (days * DateUtils.MILLIS_PER_DAY); + } + if (Token.containsTokenWithValue(tokens, H)) { + hours = (int) (durationMillis / DateUtils.MILLIS_PER_HOUR); + durationMillis = durationMillis - (hours * DateUtils.MILLIS_PER_HOUR); + } + if (Token.containsTokenWithValue(tokens, m)) { + minutes = (int) (durationMillis / DateUtils.MILLIS_PER_MINUTE); + durationMillis = durationMillis - (minutes * DateUtils.MILLIS_PER_MINUTE); + } + if (Token.containsTokenWithValue(tokens, s)) { + seconds = (int) (durationMillis / DateUtils.MILLIS_PER_SECOND); + durationMillis = durationMillis - (seconds * DateUtils.MILLIS_PER_SECOND); + } + if (Token.containsTokenWithValue(tokens, S)) { + milliseconds = (int) durationMillis; + } + + return format(tokens, 0, 0, days, hours, minutes, seconds, milliseconds, padWithZeros); + } + + /** + *

Formats an elapsed time into a plurialization correct string.

+ * + *

This method formats durations using the days and lower fields of the + * format pattern. Months and larger are not used.

+ * + * @param durationMillis the elapsed time to report in milliseconds + * @param suppressLeadingZeroElements suppresses leading 0 elements + * @param suppressTrailingZeroElements suppresses trailing 0 elements + * @return the formatted text in days/hours/minutes/seconds + */ + public static @NotNull String formatDurationWords( + long durationMillis, + boolean suppressLeadingZeroElements, + boolean suppressTrailingZeroElements) { + return formatDurationWords(durationMillis, suppressLeadingZeroElements, suppressTrailingZeroElements, getDefaultLocalisation()); + } + + /** + *

Formats an elapsed time into a plurialization correct string.

+ * + *

This method formats durations using the days and lower fields of the + * format pattern. Months and larger are not used.

+ * + * @param durationMillis the elapsed time to report in milliseconds + * @param suppressLeadingZeroElements suppresses leading 0 elements + * @param suppressTrailingZeroElements suppresses trailing 0 elements + * @return the formatted text in days/hours/minutes/seconds + */ + public static @NotNull String formatDurationWords( + long durationMillis, + boolean suppressLeadingZeroElements, + boolean suppressTrailingZeroElements, + @Nullable MiniMessageSerializer s, + @Nullable Locale locale) { + + if (locale == null) + return formatDurationWords(durationMillis, suppressLeadingZeroElements, suppressTrailingZeroElements); + return formatDurationWords(durationMillis, suppressLeadingZeroElements, + suppressTrailingZeroElements, getLocalisationFromMessageSystem(locale, s)); + } + + /** + *

Formats an elapsed time into a plurialization correct string.

+ * + *

This method formats durations using the days and lower fields of the + * format pattern. Months and larger are not used.

+ * + * @param duration the elapsed time to report in milliseconds + * @param suppressLeadingZeroElements suppresses leading 0 elements + * @param suppressTrailingZeroElements suppresses trailing 0 elements + * @return the formatted text in days/hours/minutes/seconds + */ + public static @NotNull String formatDurationWords( + Duration duration, + boolean suppressLeadingZeroElements, + boolean suppressTrailingZeroElements, + @Nullable MiniMessageSerializer s, + @Nullable Locale locale) { + + if (locale == null) + return formatDurationWords(duration.toMillis(), suppressLeadingZeroElements, suppressTrailingZeroElements); + return formatDurationWords(duration.toMillis(), suppressLeadingZeroElements, + suppressTrailingZeroElements, getLocalisationFromMessageSystem(locale, s)); + } + + public static @Unmodifiable @NotNull Map getLocalisationFromMessageSystem(@NotNull Locale locale, @Nullable MiniMessageSerializer s) { + Map localisation = new HashMap<>(); + putFromMessageSystem(localisation, "days", locale, s); + putFromMessageSystem(localisation, "hours", locale, s); + putFromMessageSystem(localisation, "minutes", locale, s); + putFromMessageSystem(localisation, "seconds", locale, s); + + putFromMessageSystem(localisation, "day", locale, s); + putFromMessageSystem(localisation, "hour", locale, s); + putFromMessageSystem(localisation, "minute", locale, s); + putFromMessageSystem(localisation, "second", locale, s); + return Map.copyOf(localisation); + + } + + public static void putFromMessageSystem(@NotNull Map m, @NotNull String key, + @NotNull Locale locale, @Nullable MiniMessageSerializer s) { + Message messageSmart = API.get().getMessageApi().getMessageSmart(INTERNAL_MESSAGE_PREFIX + key, locale); + m.put(key, s != null ? messageSmart.getPlainMessage(s) + : messageSmart.getMiniMessage()); + } + + + public static @Unmodifiable @NotNull Map getDefaultLocalisation() { + Map localisation = new HashMap<>(); + putEqual(localisation, "days"); + putEqual(localisation, "hours"); + putEqual(localisation, "minutes"); + putEqual(localisation, "seconds"); + + putEqual(localisation, "day"); + putEqual(localisation, "hour"); + putEqual(localisation, "minute"); + putEqual(localisation, "second"); + return Map.copyOf(localisation); + } + + private static void putEqual(@NotNull Map m, @NotNull K keyAndValue) { + m.putIfAbsent(keyAndValue, keyAndValue); + } + + /** + *

Formats an elapsed time into a plurialization correct string.

+ * + *

This method formats durations using the days and lower fields of the + * format pattern. Months and larger are not used.

+ * + * @param durationMillis the elapsed time to report in milliseconds + * @param suppressLeadingZeroElements suppresses leading 0 elements + * @param suppressTrailingZeroElements suppresses trailing 0 elements + * @param localisation a map with used for localisation + * @return the formatted text in days/hours/minutes/seconds + */ + public static @NotNull String formatDurationWords( + long durationMillis, + boolean suppressLeadingZeroElements, + boolean suppressTrailingZeroElements, + @NotNull Map localisation) { + + //localisation + final String + days = localisation.get("days"), + hours = localisation.get("hours"), + minutes = localisation.get("minutes"), + seconds = localisation.get("seconds"), + day = localisation.get("day"), + hour = localisation.get("hour"), + minute = localisation.get("minute"), + second = localisation.get("second"); + + // This method is generally replacable by the format method, but + // there are a series of tweaks and special cases that require + // trickery to replicate. + String duration = formatDuration(durationMillis, "d' " + days + " 'H' " + hours + " 'm' " + minutes + " 's' " + seconds + "'"); + if (suppressLeadingZeroElements) { + // this is a temporary marker on the front. Like ^ in regexp. + duration = " " + duration; + String tmp = StringUtils.replaceOnce(duration, " 0 " + days, ""); + if (tmp.length() != duration.length()) { + duration = tmp; + tmp = StringUtils.replaceOnce(duration, " 0 " + hours, ""); + if (tmp.length() != duration.length()) { + duration = tmp; + tmp = StringUtils.replaceOnce(duration, " 0 " + minutes, ""); + duration = tmp; + if (tmp.length() != duration.length()) { + duration = StringUtils.replaceOnce(tmp, " 0 " + seconds, ""); + } + } + } + if (duration.length() != 0) { + // strip the space off again + duration = duration.substring(1); + } + } + if (suppressTrailingZeroElements) { + String tmp = StringUtils.replaceOnce(duration, " 0 " + seconds, ""); + if (tmp.length() != duration.length()) { + duration = tmp; + tmp = StringUtils.replaceOnce(duration, " 0 " + minutes, ""); + if (tmp.length() != duration.length()) { + duration = tmp; + tmp = StringUtils.replaceOnce(duration, " 0 " + hours, ""); + if (tmp.length() != duration.length()) { + duration = StringUtils.replaceOnce(tmp, " 0 " + days, ""); + } + } + } + } + // handle plurals + duration = " " + duration; + duration = StringUtils.replaceOnce(duration, " 1 " + seconds, " 1 " + second); + duration = StringUtils.replaceOnce(duration, " 1 " + minutes, " 1 " + minute); + duration = StringUtils.replaceOnce(duration, " 1 " + hours, " 1 " + hour); + duration = StringUtils.replaceOnce(duration, " 1 " + days, " 1 " + day); + return duration.trim(); + } + + /** + *

Formats the time gap as a string.

+ * + *

The format used is the ISO8601 period format.

+ * + * @param startMillis the start of the duration to format + * @param endMillis the end of the duration to format + * @return the time as a String + */ + public static @NotNull String formatPeriodISO(long startMillis, long endMillis) { + return formatPeriod(startMillis, endMillis, ISO_EXTENDED_FORMAT_PATTERN, false, TimeZone.getDefault()); + } + + /** + *

Formats the time gap as a string, using the specified format. + * Padding the left hand side of numbers with zeroes is optional. + * + * @param startMillis the start of the duration + * @param endMillis the end of the duration + * @param format the way in which to format the duration + * @return the time as a String + */ + public static @NotNull String formatPeriod(long startMillis, long endMillis, @NotNull String format) { + return formatPeriod(startMillis, endMillis, format, true, TimeZone.getDefault()); + } + + /** + *

Formats the time gap as a string, using the specified format. + * Padding the left hand side of numbers with zeroes is optional and + * the timezone may be specified.

+ * + *

When calculating the difference between months/days, it chooses to + * calculate months first. So when working out the number of months and + * days between January 15th and March 10th, it choose 1 month and + * 23 days gained by choosing January->February = 1 month and then + * calculating days forwards, and not the 1 month and 26 days gained by + * choosing March -> February = 1 month and then calculating days + * backwards.

+ * + *

For more control, the Joda-Time + * library is recommended.

+ * + * @param startMillis the start of the duration + * @param endMillis the end of the duration + * @param format the way in which to format the duration + * @param padWithZeros whether to pad the left hand side of numbers with 0's + * @param timezone the millis are defined in + * @return the time as a String + */ + public static @NotNull String formatPeriod(long startMillis, long endMillis, @NotNull String format, boolean padWithZeros, + @NotNull TimeZone timezone) { + + // Used to optimise for differences under 28 days and + // called formatDuration(millis, format); however this did not work + // over leap years. + // TODO: Compare performance to see if anything was lost by + // losing this optimisation. + + Token[] tokens = lexx(format); + + // timezones get funky around 0, so normalizing everything to GMT + // stops the hours being off + Calendar start = Calendar.getInstance(timezone); + start.setTime(new Date(startMillis)); + Calendar end = Calendar.getInstance(timezone); + end.setTime(new Date(endMillis)); + + // initial estimates + int milliseconds = end.get(Calendar.MILLISECOND) - start.get(Calendar.MILLISECOND); + int seconds = end.get(Calendar.SECOND) - start.get(Calendar.SECOND); + int minutes = end.get(Calendar.MINUTE) - start.get(Calendar.MINUTE); + int hours = end.get(Calendar.HOUR_OF_DAY) - start.get(Calendar.HOUR_OF_DAY); + int days = end.get(Calendar.DAY_OF_MONTH) - start.get(Calendar.DAY_OF_MONTH); + int months = end.get(Calendar.MONTH) - start.get(Calendar.MONTH); + int years = end.get(Calendar.YEAR) - start.get(Calendar.YEAR); + + // each initial estimate is adjusted in case it is under 0 + while (milliseconds < 0) { + milliseconds += 1000; + seconds -= 1; + } + while (seconds < 0) { + seconds += 60; + minutes -= 1; + } + while (minutes < 0) { + minutes += 60; + hours -= 1; + } + while (hours < 0) { + hours += 24; + days -= 1; + } + + if (Token.containsTokenWithValue(tokens, M)) { + while (days < 0) { + days += start.getActualMaximum(Calendar.DAY_OF_MONTH); + months -= 1; + start.add(Calendar.MONTH, 1); + } + + while (months < 0) { + months += 12; + years -= 1; + } + + if (!Token.containsTokenWithValue(tokens, y) && years != 0) { + while (years != 0) { + months += 12 * years; + years = 0; + } + } + } else { + // there are no M's in the format string + + if (!Token.containsTokenWithValue(tokens, y)) { + int target = end.get(Calendar.YEAR); + if (months < 0) { + // target is end-year -1 + target -= 1; + } + + while ((start.get(Calendar.YEAR) != target)) { + days += start.getActualMaximum(Calendar.DAY_OF_YEAR) - start.get(Calendar.DAY_OF_YEAR); + + // Not sure I grok why this is needed, but the brutal tests show it is + if (start instanceof GregorianCalendar) { + if ((start.get(Calendar.MONTH) == Calendar.FEBRUARY) && + (start.get(Calendar.DAY_OF_MONTH) == 29)) { + days += 1; + } + } + + start.add(Calendar.YEAR, 1); + + days += start.get(Calendar.DAY_OF_YEAR); + } + + years = 0; + } + + while (start.get(Calendar.MONTH) != end.get(Calendar.MONTH)) { + days += start.getActualMaximum(Calendar.DAY_OF_MONTH); + start.add(Calendar.MONTH, 1); + } + + months = 0; + + while (days < 0) { + days += start.getActualMaximum(Calendar.DAY_OF_MONTH); + months -= 1; + start.add(Calendar.MONTH, 1); + } + + } + + // The rest of this code adds in values that + // aren't requested. This allows the user to ask for the + // number of months and get the real count and not just 0->11. + + if (!Token.containsTokenWithValue(tokens, d)) { + hours += 24 * days; + days = 0; + } + if (!Token.containsTokenWithValue(tokens, H)) { + minutes += 60 * hours; + hours = 0; + } + if (!Token.containsTokenWithValue(tokens, m)) { + seconds += 60 * minutes; + minutes = 0; + } + if (!Token.containsTokenWithValue(tokens, s)) { + milliseconds += 1000 * seconds; + seconds = 0; + } + + return format(tokens, years, months, days, hours, minutes, seconds, milliseconds, padWithZeros); + } + + /** + *

The internal method to do the formatting.

+ * + * @param tokens the tokens + * @param years the number of years + * @param months the number of months + * @param days the number of days + * @param hours the number of hours + * @param minutes the number of minutes + * @param seconds the number of seconds + * @param milliseconds the number of millis + * @param padWithZeros whether to pad + * @return the formatted string + */ + static @NotNull String format(Token[] tokens, int years, int months, int days, int hours, int minutes, int seconds, + int milliseconds, boolean padWithZeros) { + StrBuilder buffer = new StrBuilder(); + boolean lastOutputSeconds = false; + int sz = tokens.length; + for (int i = 0; i < sz; i++) { + Token token = tokens[i]; + Object value = token.getValue(); + int count = token.getCount(); + if (value instanceof StringBuffer) { + buffer.append(value.toString()); + } else { + if (value == y) { + buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(years), count, '0') : Integer + .toString(years)); + lastOutputSeconds = false; + } else if (value == M) { + buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(months), count, '0') : Integer + .toString(months)); + lastOutputSeconds = false; + } else if (value == d) { + buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(days), count, '0') : Integer + .toString(days)); + lastOutputSeconds = false; + } else if (value == H) { + buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(hours), count, '0') : Integer + .toString(hours)); + lastOutputSeconds = false; + } else if (value == m) { + buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(minutes), count, '0') : Integer + .toString(minutes)); + lastOutputSeconds = false; + } else if (value == s) { + buffer.append(padWithZeros ? StringUtils.leftPad(Integer.toString(seconds), count, '0') : Integer + .toString(seconds)); + lastOutputSeconds = true; + } else if (value == S) { + if (lastOutputSeconds) { + milliseconds += 1000; + String str = padWithZeros + ? StringUtils.leftPad(Integer.toString(milliseconds), count, '0') + : Integer.toString(milliseconds); + buffer.append(str.substring(1)); + } else { + buffer.append(padWithZeros + ? StringUtils.leftPad(Integer.toString(milliseconds), count, '0') + : Integer.toString(milliseconds)); + } + lastOutputSeconds = false; + } + } + } + return buffer.toString(); + } + + /** + * Parses a classic date format string into Tokens + * + * @param format to parse + * @return array of Token[] + */ + static Token[] lexx(String format) { + char[] array = format.toCharArray(); + ArrayList list = new ArrayList(array.length); + + boolean inLiteral = false; + StringBuffer buffer = null; + Token previous = null; + int sz = array.length; + for (int i = 0; i < sz; i++) { + char ch = array[i]; + if (inLiteral && ch != '\'') { + buffer.append(ch); // buffer can't be null if inLiteral is true + continue; + } + Object value = null; + switch (ch) { + // TODO: Need to handle escaping of ' + case '\'': + if (inLiteral) { + buffer = null; + inLiteral = false; + } else { + buffer = new StringBuffer(); + list.add(new Token(buffer)); + inLiteral = true; + } + break; + case 'y': + value = y; + break; + case 'M': + value = M; + break; + case 'd': + value = d; + break; + case 'H': + value = H; + break; + case 'm': + value = m; + break; + case 's': + value = s; + break; + case 'S': + value = S; + break; + default: + if (buffer == null) { + buffer = new StringBuffer(); + list.add(new Token(buffer)); + } + buffer.append(ch); + } + + if (value != null) { + if (previous != null && previous.getValue() == value) { + previous.increment(); + } else { + Token token = new Token(value); + list.add(token); + previous = token; + } + buffer = null; + } + } + return (Token[]) list.toArray(new Token[list.size()]); + } + + + /** + * Element that is parsed from the format pattern. + */ + static class Token { + + private @NotNull Object value; + private int count; + + /** + * Wraps a token around a value. A value would be something like a 'Y'. + * + * @param value to wrap + */ + Token(@NotNull Object value) { + this.value = value; + this.count = 1; + } + + /** + * Wraps a token around a repeated number of a value, for example it would + * store 'yyyy' as a value for y and a count of 4. + * + * @param value to wrap + * @param count to wrap + */ + Token(@NotNull Object value, int count) { + this.value = value; + this.count = count; + } + + /** + * Helper method to determine if a set of tokens contain a value + * + * @param tokens set to look in + * @param value to look for + * @return boolean true if contained + */ + static boolean containsTokenWithValue(Token[] tokens, @NotNull Object value) { + int sz = tokens.length; + for (int i = 0; i < sz; i++) { + if (tokens[i].getValue() == value) { + return true; + } + } + return false; + } + + /** + * Adds another one of the value + */ + void increment() { + count++; + } + + /** + * Gets the current number of values represented + * + * @return int number of values represented + */ + int getCount() { + return count; + } + + /** + * Gets the particular value this token represents. + * + * @return Object value + */ + @NotNull Object getValue() { + return value; + } + + /** + * Supports equality of this Token to another Token. + * + * @param obj2 Object to consider equality of + * @return boolean true if equal + */ + public boolean equals(@NotNull Object obj2) { + if (obj2 instanceof Token) { + Token tok2 = (Token) obj2; + if (this.value.getClass() != tok2.value.getClass()) { + return false; + } + if (this.count != tok2.count) { + return false; + } + if (this.value instanceof StringBuffer) { + return this.value.toString().equals(tok2.value.toString()); + } else if (this.value instanceof Number) { + return this.value.equals(tok2.value); + } else { + return this.value == tok2.value; + } + } + return false; + } + + /** + * Returns a hashcode for the token equal to the + * hashcode for the token's value. Thus 'TT' and 'TTTT' + * will have the same hashcode. + * + * @return The hashcode for the token + */ + public int hashCode() { + return this.value.hashCode(); + } + + /** + * Represents this token as a String. + * + * @return String representation of the token + */ + public @NotNull String toString() { + return StringUtils.repeat(this.value.toString(), this.count); + } + } + +} diff --git a/AdventureAPI/src/main/java/net/juligames/core/adventure/AdventureTagManager.java b/AdventureAPI/src/main/java/net/juligames/core/adventure/AdventureTagManager.java index a41a019d..703b2d8d 100644 --- a/AdventureAPI/src/main/java/net/juligames/core/adventure/AdventureTagManager.java +++ b/AdventureAPI/src/main/java/net/juligames/core/adventure/AdventureTagManager.java @@ -47,6 +47,15 @@ public interface AdventureTagManager extends MiniMessageSerializer { @NotNull String resolvePlain(@NotNull Message message); + /** + * This method creates a new {@link TagResolver} that combines {@link #getResolver()} and append + * @param append additional resolvers + * @return a new {@link TagResolver} + */ + @ApiStatus.AvailableSince("1.5") + @ApiStatus.Experimental + @NotNull TagResolver fork(@NotNull Collection append); + @Deprecated @NotNull String resolveLegacy(@NotNull Message message); diff --git a/AdventureCore/src/main/java/net/juligames/core/adventure/CoreAdventureTagManager.java b/AdventureCore/src/main/java/net/juligames/core/adventure/CoreAdventureTagManager.java index 82acc2bf..cbcab713 100644 --- a/AdventureCore/src/main/java/net/juligames/core/adventure/CoreAdventureTagManager.java +++ b/AdventureCore/src/main/java/net/juligames/core/adventure/CoreAdventureTagManager.java @@ -5,6 +5,7 @@ import net.juligames.core.api.jdbi.DBReplacement; import net.juligames.core.api.jdbi.ReplacementDAO; import net.juligames.core.api.message.Message; +import net.juligames.core.api.message.MiniMessageSerializer; import net.juligames.core.api.message.PatternType; import net.juligames.core.api.message.TagManager; import net.kyori.adventure.text.Component; @@ -28,9 +29,11 @@ @SuppressWarnings("ProtectedMemberInFinalClass") public final class CoreAdventureTagManager implements TagManager, AdventureTagManager { - private TagResolver internalResolver = TagResolver.standard(); + private @NotNull TagResolver internalResolver = TagResolver.standard(); - protected String buildPattern(@Range(from = 0, to = Integer.MAX_VALUE) int i) { + @Contract(pure = true) + @Deprecated(forRemoval = true) + protected @NotNull String buildPattern(@Range(from = 0, to = Integer.MAX_VALUE) int i) { return "{" + i + "}"; } @@ -103,12 +106,18 @@ public void clearResolver() { return resolve(message.getMiniMessageReadyForResolving(), resolvers); } - @Override public @NotNull String resolvePlain(@NotNull Message message) { return resolvePlain(message.getMiniMessage()); } + @Override + public @NotNull TagResolver fork(@NotNull Collection append) { + Collection local = new ArrayList<>(append); + local.add(getResolver()); + return TagResolver.resolver(local); + } + @Override @Deprecated public @NotNull String resolveLegacy(@NotNull Message message) { From c56135d58d1699c8a52c621d632afbd0c8a2278f Mon Sep 17 00:00:00 2001 From: TDR Date: Wed, 15 Mar 2023 18:32:28 +0100 Subject: [PATCH 44/64] Update DurationFormatUtils.java --- .../core/api/misc/DurationFormatUtils.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/API/src/main/java/net/juligames/core/api/misc/DurationFormatUtils.java b/API/src/main/java/net/juligames/core/api/misc/DurationFormatUtils.java index de4f44cc..1949c784 100644 --- a/API/src/main/java/net/juligames/core/api/misc/DurationFormatUtils.java +++ b/API/src/main/java/net/juligames/core/api/misc/DurationFormatUtils.java @@ -22,6 +22,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.text.StrBuilder; import org.apache.commons.lang.time.DateUtils; +import org.checkerframework.checker.units.qual.A; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -244,6 +245,40 @@ public DurationFormatUtils() { suppressTrailingZeroElements, getLocalisationFromMessageSystem(locale, s)); } + static { + API.get().getAPILogger().info(DurationFormatUtils.class.getName() + " was loaded! Trying to register default messages:"); + long s1 = System.currentTimeMillis(); + try { + registerMessages(); + //BIT + final long between = s1 - System.currentTimeMillis(); + Duration duration = Duration.ofMillis(between); + String formatDurationWords = formatDurationWords(duration, false, false, null, + API.get().getMessageApi().defaultUtilLocale()); + API.get().getAPILogger().info("finished registration of default messages! (took: " + formatDurationWords + ")"); + }catch (Exception e){ + API.get().getAPILogger().error("failed to register default messages: " + e); + ThrowableDebug.debug(e); + } + + } + + public static void registerMessages() { + registerDefaultMessage("days"); + registerDefaultMessage("hours"); + registerDefaultMessage("minutes"); + registerDefaultMessage("seconds"); + + registerDefaultMessage("day"); + registerDefaultMessage("hour"); + registerDefaultMessage("minute"); + registerDefaultMessage("second"); + } + + private static void registerDefaultMessage(String key) { + API.get().getMessageApi().registerMessage(INTERNAL_MESSAGE_PREFIX + key, key); + } + public static @Unmodifiable @NotNull Map getLocalisationFromMessageSystem(@NotNull Locale locale, @Nullable MiniMessageSerializer s) { Map localisation = new HashMap<>(); putFromMessageSystem(localisation, "days", locale, s); From a21c9378809987c38a956b2d2bb86002c0549ad5 Mon Sep 17 00:00:00 2001 From: Ture Bentzin <38729194+TureBentzin@users.noreply.github.com> Date: Sat, 18 Mar 2023 15:18:11 +0100 Subject: [PATCH 45/64] Update API/src/main/java/net/juligames/core/api/minigame/BasicMiniGame.java Co-authored-by: Bommels05 <69975756+Bommels05@users.noreply.github.com> --- .../java/net/juligames/core/api/minigame/BasicMiniGame.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/API/src/main/java/net/juligames/core/api/minigame/BasicMiniGame.java b/API/src/main/java/net/juligames/core/api/minigame/BasicMiniGame.java index 5eca9174..905f8a55 100644 --- a/API/src/main/java/net/juligames/core/api/minigame/BasicMiniGame.java +++ b/API/src/main/java/net/juligames/core/api/minigame/BasicMiniGame.java @@ -40,7 +40,7 @@ default String getFullDescription() { * load the MiniGame * * @return a {@link StartType}: The handling of this is not guaranteed it might start whenever it wants. It's just an indication - * on when and how you suggest to load it + * on when and how you suggest to start it */ @Nullable StartType load(); From 60549316c50fa2e5fda71282e60575ea83e39886 Mon Sep 17 00:00:00 2001 From: Ture Bentzin <38729194+TureBentzin@users.noreply.github.com> Date: Sat, 18 Mar 2023 15:18:30 +0100 Subject: [PATCH 46/64] Update Core/src/main/java/net/juligames/core/config/CoreConfiguration.java Co-authored-by: Bommels05 <69975756+Bommels05@users.noreply.github.com> --- .../main/java/net/juligames/core/config/CoreConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java b/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java index 78af38f5..d1116487 100644 --- a/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java +++ b/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java @@ -88,7 +88,7 @@ public CoreConfiguration(String name) { @ApiStatus.Internal private @NotNull IMap hazel(@SuppressWarnings("SameParameterValue") boolean containingPrefix) { - return Core.getInstance().getOrThrow().getMap(generateHazel(name,containingPrefix)); + return Core.getInstance().getOrThrow().getMap(generateHazel(name, containingPrefix)); } public void updateHazel() { From 8cb34c9b43c1062ab732b0a1ff50aa2464090b6f Mon Sep 17 00:00:00 2001 From: Ture Bentzin <38729194+TureBentzin@users.noreply.github.com> Date: Sat, 18 Mar 2023 15:18:46 +0100 Subject: [PATCH 47/64] Update MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java Co-authored-by: Bommels05 <69975756+Bommels05@users.noreply.github.com> --- .../src/main/java/net/juligames/core/minigame/api/MiniGame.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java index 3d133845..db3ad272 100644 --- a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java +++ b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/MiniGame.java @@ -72,7 +72,7 @@ public MiniGame( * load the MiniGame * * @return a {@link StartType}: The handling of this is not guaranteed it might start whenever it wants. Its just an indication - * on when and how you suggest to load it + * on when and how you suggest to start it */ @Override @Nullable From 0fa586eb1cdb601bf7cbe2495ce8ed01b3091e4b Mon Sep 17 00:00:00 2001 From: Ture Bentzin <38729194+TureBentzin@users.noreply.github.com> Date: Sat, 18 Mar 2023 22:22:25 +0100 Subject: [PATCH 48/64] Update API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java --- .../java/net/juligames/core/api/config/BuildInInterpreters.java | 1 + 1 file changed, 1 insertion(+) diff --git a/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java b/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java index 99840d84..e9d437e0 100644 --- a/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java +++ b/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java @@ -60,6 +60,7 @@ public interface BuildInInterpreters { return s -> s; } + @ApiStatus.AvailableSince("1.5") @Contract(pure = true) static @NotNull Interpreter> clazzInterpreter() { return new Interpreter<>() { From caf4d1c7c5a08ce1c439cf1123333bf2e527c2c3 Mon Sep 17 00:00:00 2001 From: Ture Bentzin <38729194+TureBentzin@users.noreply.github.com> Date: Sat, 18 Mar 2023 22:23:21 +0100 Subject: [PATCH 49/64] Update API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java --- .../java/net/juligames/core/api/config/ConfigurationAPI.java | 1 + 1 file changed, 1 insertion(+) diff --git a/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java b/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java index 91550b79..1753f0e1 100644 --- a/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java +++ b/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java @@ -36,6 +36,7 @@ public interface ConfigurationAPI { * @param name the name * @return if an associated {@link Configuration} was found */ + @ApiStatus.AvailableSince("1.5") @ApiStatus.AvailableSince("1.5") boolean exists(String name); From ccb7980a398a94fdd3e748aecb7a0b71cc5b98aa Mon Sep 17 00:00:00 2001 From: Ture Bentzin <38729194+TureBentzin@users.noreply.github.com> Date: Sat, 18 Mar 2023 22:23:34 +0100 Subject: [PATCH 50/64] Update API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java --- .../core/api/config/mapbacked/DictionaryFeedInterpreter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java index 50ba76f0..a15fb73c 100644 --- a/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java @@ -13,6 +13,7 @@ * @author Ture Bentzin * 11.03.2023 */ + @ApiStatus.AvailableSince("1.5") @ApiStatus.AvailableSince("1.5") public class DictionaryFeedInterpreter implements Interpreter> { From d2d32d3df12a1730376a9da323bfeb500c7181b8 Mon Sep 17 00:00:00 2001 From: Ture Bentzin <38729194+TureBentzin@users.noreply.github.com> Date: Wed, 22 Mar 2023 08:25:02 +0100 Subject: [PATCH 51/64] fix #30 removed the log entry that leaked the database credentials --- Core/src/main/java/net/juligames/core/Core.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Core/src/main/java/net/juligames/core/Core.java b/Core/src/main/java/net/juligames/core/Core.java index 750db1a8..685913f1 100644 --- a/Core/src/main/java/net/juligames/core/Core.java +++ b/Core/src/main/java/net/juligames/core/Core.java @@ -146,7 +146,6 @@ public void start(String core_name, @NotNull Logger logger, boolean member) { if (jdbc.isEmpty()) { Core.getInstance().coreLogger.warning("cant read jdbc data in database..."); } - logger.warning("database: " + getConfigurationApi().database().cloneToProperties()); sqlManager = new CoreSQLManager(jdbc.orElse("jdbc:mysql://root@localhost:3306"), logger); //jdbc:mysql://admin@localhost:3306/minecraft logger.info("connected to jdbi -> " + sqlManager); From 4f375becc21e119fed5caa620ef75a68a4c90d99 Mon Sep 17 00:00:00 2001 From: Ture Bentzin <38729194+TureBentzin@users.noreply.github.com> Date: Wed, 22 Mar 2023 08:40:56 +0100 Subject: [PATCH 52/64] fixed compiler issue --- .../java/net/juligames/core/api/config/ConfigurationAPI.java | 1 - 1 file changed, 1 deletion(-) diff --git a/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java b/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java index 1753f0e1..91550b79 100644 --- a/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java +++ b/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java @@ -36,7 +36,6 @@ public interface ConfigurationAPI { * @param name the name * @return if an associated {@link Configuration} was found */ - @ApiStatus.AvailableSince("1.5") @ApiStatus.AvailableSince("1.5") boolean exists(String name); From acb4f0beb23c373eddc3925b891e1ec6cfac8813 Mon Sep 17 00:00:00 2001 From: Ture Bentzin <38729194+TureBentzin@users.noreply.github.com> Date: Wed, 22 Mar 2023 08:42:13 +0100 Subject: [PATCH 53/64] fixed second compiler issue --- .../core/api/config/mapbacked/DictionaryFeedInterpreter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java index a15fb73c..50ba76f0 100644 --- a/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java @@ -13,7 +13,6 @@ * @author Ture Bentzin * 11.03.2023 */ - @ApiStatus.AvailableSince("1.5") @ApiStatus.AvailableSince("1.5") public class DictionaryFeedInterpreter implements Interpreter> { From c13c820cf012186fdbd1a86b678f6522c4f81bda Mon Sep 17 00:00:00 2001 From: Ture Bentzin Date: Wed, 22 Mar 2023 12:04:39 +0100 Subject: [PATCH 54/64] Update SwitchingInsertionProcedure.java --- .../SwitchingInsertionProcedure.java | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/SwitchingInsertionProcedure.java b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/SwitchingInsertionProcedure.java index a9468c04..5a5678b5 100644 --- a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/SwitchingInsertionProcedure.java +++ b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/SwitchingInsertionProcedure.java @@ -6,16 +6,23 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.crypto.spec.OAEPParameterSpec; +import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.UUID; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Stream; /** - * This is currently not working because the {@link SwitchingInsertionProcedure} has no idea what the {@link IterativeInsertionProcedure} did. + * This is now independent of the {@link IterativeInsertionProcedure}! Within the {@link #apply(Set, UUID)} method there are + * parts of the implementation of {@link ComparatorInsertionProcedure} and {@link IterativeInsertionProcedure} + * @apiNote Im not sure if i want to keep this behavior.. * * @author Ture Bentzin * 23.12.2022 */ -@TODO(doNotcall = true) +@TODO(doNotcall = false) public final class SwitchingInsertionProcedure implements InsertionProcedure { @Nullable @@ -24,23 +31,38 @@ public final class SwitchingInsertionProcedure implements InsertionProcedure { @Contract(pure = true) @Override public @NotNull Boolean apply(@NotNull Set teams, UUID uuid) { - if (lastTeam == null) { - teams.stream().findAny().ifPresentOrElse(team -> lastTeam = team, - () -> { - throw new IllegalArgumentException("lastTeam is null and there is no team available to be selected!"); - }); - } - if (!teams.contains(lastTeam)) { + if (lastTeam == null) + teams.stream().findAny().ifPresentOrElse(team -> lastTeam = team, () -> { + throw new IllegalArgumentException("lastTeam is null and there is no team available to be selected!"); + }); + + if (!teams.contains(lastTeam)) throw new IllegalArgumentException("lastTeam of this SwitchingInsertionProcedure is not part of teams!"); - } - return new ComparatorInsertionProcedure((o1, o2) -> { //needs testing - maybe reversed order - not running - no feedback on what team was selected... + /* + Boolean apply = new ComparatorInsertionProcedure((o1, o2) -> { //needs testing - maybe reversed order - not running - no feedback on what team was selected... if (o2 == lastTeam) return 1; if (o2 == o1 || o2.equals(o1)) return 0; return -1; }).apply(teams, uuid); + */ + for (Team team : teams.stream().sorted((o1, o2) -> { + if (o2 == lastTeam) return 1; + if (o2 == o1 || o2.equals(o1)) return 0; + return -1; + }).toList()) { + if (team.tryAdd(uuid)) { + lastTeam = team; + return true; + } + } + return false; } public @Nullable Team getLastTeam() { return lastTeam; } + + public @NotNull Optional lastTeamOptional() { + return Optional.ofNullable(getLastTeam()); + } } From dbdaa043dd16acfbdaf9f452e54a8c7d7b8bc8bb Mon Sep 17 00:00:00 2001 From: Ture Bentzin Date: Wed, 22 Mar 2023 12:05:31 +0100 Subject: [PATCH 55/64] some reformat --- .../core/api/config/BuildInInterpreters.java | 2 - .../core/api/config/ConfigurationAPI.java | 1 + .../mapbacked/DictionaryFeedInterpreter.java | 2 +- .../core/api/misc/LoggerMessageRecipient.java | 9 +- .../core/config/CoreConfiguration.java | 9 +- .../core/config/CoreConfigurationApi.java | 1 - .../notification/CoreNotificationApi.java | 2 +- Master/dependency-reduced-pom.xml | 85 +++++++------- .../SwitchingInsertionProcedure.java | 6 +- .../core/paper/misc/PluginLogger.java | 8 +- PaperCore/dependency-reduced-pom.xml | 105 +++++++++--------- VelocityCore/dependency-reduced-pom.xml | 105 +++++++++--------- 12 files changed, 166 insertions(+), 169 deletions(-) diff --git a/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java b/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java index e9d437e0..7b7a7e40 100644 --- a/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java +++ b/API/src/main/java/net/juligames/core/api/config/BuildInInterpreters.java @@ -77,8 +77,6 @@ public interface BuildInInterpreters { } - - @ApiStatus.AvailableSince("1.5") @Contract(value = "_ -> new", pure = true) static @NotNull Interpreter onlineConfigurationInterpreter(boolean createIfNotExists) { diff --git a/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java b/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java index 91550b79..e73287ec 100644 --- a/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java +++ b/API/src/main/java/net/juligames/core/api/config/ConfigurationAPI.java @@ -33,6 +33,7 @@ public interface ConfigurationAPI { /** * This will check if a configuration with the given name exists or not + * * @param name the name * @return if an associated {@link Configuration} was found */ diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java index 50ba76f0..6b2c1c3a 100644 --- a/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java @@ -9,9 +9,9 @@ import java.util.function.Supplier; /** - * @apiNote this can be used for {@link java.util.Hashtable}s or {@link java.util.Properties}s * @author Ture Bentzin * 11.03.2023 + * @apiNote this can be used for {@link java.util.Hashtable}s or {@link java.util.Properties}s */ @ApiStatus.AvailableSince("1.5") public class DictionaryFeedInterpreter implements Interpreter> { diff --git a/API/src/main/java/net/juligames/core/api/misc/LoggerMessageRecipient.java b/API/src/main/java/net/juligames/core/api/misc/LoggerMessageRecipient.java index 98bdd1d6..2ba5fa74 100644 --- a/API/src/main/java/net/juligames/core/api/misc/LoggerMessageRecipient.java +++ b/API/src/main/java/net/juligames/core/api/misc/LoggerMessageRecipient.java @@ -13,7 +13,8 @@ * 15.03.2023 */ @ApiStatus.AvailableSince("1.5") -public record LoggerMessageRecipient(Logger logger, @Nullable MiniMessageSerializer miniMessageSerializer) implements MessageRecipient { +public record LoggerMessageRecipient(Logger logger, + @Nullable MiniMessageSerializer miniMessageSerializer) implements MessageRecipient { @Override public @NotNull String getName() { return logger.getFullName(); @@ -21,15 +22,15 @@ public record LoggerMessageRecipient(Logger logger, @Nullable MiniMessageSeriali @Override public void deliver(@NotNull Message message) { - if(miniMessageSerializer != null) - logger.info(message.getPlainMessage(miniMessageSerializer)); + if (miniMessageSerializer != null) + logger.info(message.getPlainMessage(miniMessageSerializer)); else logger.info("UNPARSED: " + message.getPreparedMiniMessage()); } @SuppressWarnings("deprecation") @Override public void deliver(@NotNull String miniMessage) { - if(miniMessageSerializer != null) + if (miniMessageSerializer != null) logger.info(miniMessageSerializer.resolvePlain(miniMessage)); else logger.info("UNPARSED: " + miniMessage); } diff --git a/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java b/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java index d1116487..7c3a032c 100644 --- a/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java +++ b/Core/src/main/java/net/juligames/core/config/CoreConfiguration.java @@ -30,11 +30,6 @@ public class CoreConfiguration implements Configuration { private IMap data; - public static @NotNull String generateHazel(@NotNull String name, boolean containingPrefix) { - return containingPrefix ? name : "config:" + name; - } - - public CoreConfiguration(String name) { this.name = name; data = hazel(); @@ -46,6 +41,10 @@ public CoreConfiguration(String name) { } } + public static @NotNull String generateHazel(@NotNull String name, boolean containingPrefix) { + return containingPrefix ? name : "config:" + name; + } + /** * This will not override data in the {@link Map} unless override is set to true * diff --git a/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java b/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java index c52448b4..a6c41cd0 100644 --- a/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java +++ b/Core/src/main/java/net/juligames/core/config/CoreConfigurationApi.java @@ -1,7 +1,6 @@ package net.juligames.core.config; import net.juligames.core.Core; -import net.juligames.core.api.API; import net.juligames.core.api.config.ConfigWriter; import net.juligames.core.api.config.Configuration; import net.juligames.core.api.config.ConfigurationAPI; diff --git a/Core/src/main/java/net/juligames/core/notification/CoreNotificationApi.java b/Core/src/main/java/net/juligames/core/notification/CoreNotificationApi.java index 7ab38d19..84b63a13 100644 --- a/Core/src/main/java/net/juligames/core/notification/CoreNotificationApi.java +++ b/Core/src/main/java/net/juligames/core/notification/CoreNotificationApi.java @@ -78,7 +78,7 @@ public Set
getBlacklist() { @Override public void onMessage(Message message) { //call Debug... - if(Boolean.getBoolean("debugNotifications")) { + if (Boolean.getBoolean("debugNotifications")) { new DebugNotificationPrinter().onMessage(message); for (NotificationListener notificationListener : listenerRegisterator) { notificationListener.onNotification(message.getMessageObject().deserialize()); diff --git a/Master/dependency-reduced-pom.xml b/Master/dependency-reduced-pom.xml index a568e1ab..b5fcafe4 100644 --- a/Master/dependency-reduced-pom.xml +++ b/Master/dependency-reduced-pom.xml @@ -1,44 +1,45 @@ - - - JuliGamesCore - net.juligames.core - 1.5 - - 4.0.0 - Master - - - - maven-shade-plugin - 3.4.1 - - - package - - shade - - - - - - - maven-jar-plugin - 3.3.0 - - - - true - net.juligames.core.master.CoreMaster - - - - - - - - 17 - 17 - UTF-8 - + + + JuliGamesCore + net.juligames.core + 1.5 + + 4.0.0 + Master + + + + maven-shade-plugin + 3.4.1 + + + package + + shade + + + + + + + maven-jar-plugin + 3.3.0 + + + + true + net.juligames.core.master.CoreMaster + + + + + + + + 17 + 17 + UTF-8 + diff --git a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/SwitchingInsertionProcedure.java b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/SwitchingInsertionProcedure.java index 5a5678b5..87d4746d 100644 --- a/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/SwitchingInsertionProcedure.java +++ b/MiniGameAPI/src/main/java/net/juligames/core/minigame/api/team/procedures/SwitchingInsertionProcedure.java @@ -6,21 +6,17 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import javax.crypto.spec.OAEPParameterSpec; -import java.util.List; import java.util.Optional; import java.util.Set; import java.util.UUID; -import java.util.concurrent.atomic.AtomicReference; -import java.util.stream.Stream; /** * This is now independent of the {@link IterativeInsertionProcedure}! Within the {@link #apply(Set, UUID)} method there are * parts of the implementation of {@link ComparatorInsertionProcedure} and {@link IterativeInsertionProcedure} - * @apiNote Im not sure if i want to keep this behavior.. * * @author Ture Bentzin * 23.12.2022 + * @apiNote Im not sure if i want to keep this behavior.. */ @TODO(doNotcall = false) public final class SwitchingInsertionProcedure implements InsertionProcedure { diff --git a/PaperAPI/src/main/java/net/juligames/core/paper/misc/PluginLogger.java b/PaperAPI/src/main/java/net/juligames/core/paper/misc/PluginLogger.java index bd551cb7..52ae9609 100644 --- a/PaperAPI/src/main/java/net/juligames/core/paper/misc/PluginLogger.java +++ b/PaperAPI/src/main/java/net/juligames/core/paper/misc/PluginLogger.java @@ -7,15 +7,15 @@ import org.jetbrains.annotations.NotNull; /** + * @author Ture Bentzin + * 11.03.2023 * @apiNote uses the {@link JavaLogger} and does not store the plugin. The {@link java.util.logging.Logger} that is present * at the moment of the execution of the constructor is used! In the case that your logger needs to be dynamic, i suggest * building your own Logger implementation! - * @author Ture Bentzin - * 11.03.2023 * @see net.juligames.core.util.ConsumingLogger; (only present with Core) */ - @SuppressWarnings("JavadocReference") - @ApiStatus.AvailableSince("1.5") +@SuppressWarnings("JavadocReference") +@ApiStatus.AvailableSince("1.5") public class PluginLogger extends JavaLogger { public PluginLogger(String name, @NotNull Logger parent, @NotNull Plugin plugin) { diff --git a/PaperCore/dependency-reduced-pom.xml b/PaperCore/dependency-reduced-pom.xml index 5a045d83..ca50dabb 100644 --- a/PaperCore/dependency-reduced-pom.xml +++ b/PaperCore/dependency-reduced-pom.xml @@ -1,54 +1,55 @@ - - - JuliGamesCore - net.juligames.core - 1.5 - - 4.0.0 - PaperCore - - - - true - src/main/resources - - - - - maven-shade-plugin - 3.4.1 - - - package - - shade - - - - - false - - - - - - - papermc - https://repo.papermc.io/repository/maven-public/ - - - - - io.papermc.paper - paper-api - 1.18.2-R0.1-SNAPSHOT - provided - - - - 17 - 17 - UTF-8 - + + + JuliGamesCore + net.juligames.core + 1.5 + + 4.0.0 + PaperCore + + + + true + src/main/resources + + + + + maven-shade-plugin + 3.4.1 + + + package + + shade + + + + + false + + + + + + + papermc + https://repo.papermc.io/repository/maven-public/ + + + + + io.papermc.paper + paper-api + 1.18.2-R0.1-SNAPSHOT + provided + + + + 17 + 17 + UTF-8 + diff --git a/VelocityCore/dependency-reduced-pom.xml b/VelocityCore/dependency-reduced-pom.xml index afce49d1..bdd4a20c 100644 --- a/VelocityCore/dependency-reduced-pom.xml +++ b/VelocityCore/dependency-reduced-pom.xml @@ -1,54 +1,55 @@ - - - JuliGamesCore - net.juligames.core - 1.5 - - 4.0.0 - VelocityCore - - - - maven-shade-plugin - 3.4.1 - - - package - - shade - - - - - false - - - - - - - papermc - papermc - https://repo.papermc.io/repository/maven-public/ - - - juligames-juligames - Juligames Maven - https://maven.juligames.net/juligames - - - - - com.velocitypowered - velocity-api - 3.1.1 - provided - - - - 17 - 17 - UTF-8 - + + + JuliGamesCore + net.juligames.core + 1.5 + + 4.0.0 + VelocityCore + + + + maven-shade-plugin + 3.4.1 + + + package + + shade + + + + + false + + + + + + + papermc + papermc + https://repo.papermc.io/repository/maven-public/ + + + juligames-juligames + Juligames Maven + https://maven.juligames.net/juligames + + + + + com.velocitypowered + velocity-api + 3.1.1 + provided + + + + 17 + 17 + UTF-8 + From fcee9d897b1f21c5f34c09541e2ccec3bc47958a Mon Sep 17 00:00:00 2001 From: Ture Bentzin Date: Wed, 22 Mar 2023 12:10:05 +0100 Subject: [PATCH 56/64] removed cachingConfiguration --- .../main/java/net/juligames/core/caching/CoreCacheApi.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java b/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java index 63673349..d33ad91f 100644 --- a/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java +++ b/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java @@ -32,9 +32,4 @@ public Caffeine newBuilder() { public Cache, DBMessage> messageCache() { return MessageCaching.messageCache(); } - - @ApiStatus.AvailableSince("1.5") - public Configuration cachingConfiguration() { - throw new TODOException(); - } } From b33ae1d170031720c2da40f9740078ab61d77247 Mon Sep 17 00:00:00 2001 From: Ture Bentzin Date: Wed, 22 Mar 2023 12:48:32 +0100 Subject: [PATCH 57/64] Add EntryInterpretation --- .../juligames/core/api/cacheing/CacheApi.java | 10 ++++ .../api/misc/EntryInterpretationUtil.java | 48 +++++++++++++++++++ .../juligames/core/caching/CoreCacheApi.java | 21 ++++++-- 3 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 API/src/main/java/net/juligames/core/api/misc/EntryInterpretationUtil.java diff --git a/API/src/main/java/net/juligames/core/api/cacheing/CacheApi.java b/API/src/main/java/net/juligames/core/api/cacheing/CacheApi.java index 00afa4bd..b4e12f58 100644 --- a/API/src/main/java/net/juligames/core/api/cacheing/CacheApi.java +++ b/API/src/main/java/net/juligames/core/api/cacheing/CacheApi.java @@ -3,7 +3,11 @@ import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; import de.bentzin.tools.pair.Pair; +import net.juligames.core.api.config.Interpreter; import net.juligames.core.api.jdbi.DBMessage; +import org.jetbrains.annotations.ApiStatus; + +import java.util.Map; /** * @author Ture Bentzin @@ -20,6 +24,12 @@ public interface CacheApi { */ Cache newCache(); + @ApiStatus.AvailableSince("1.5") + Map reverseCache(Interpreter kInterpreter, Interpreter vInterpreter, Cache cache); + + @ApiStatus.AvailableSince("1.5") + Map interpretCache(Interpreter kInterpreter, Interpreter vInterpreter, Cache cache); + /** * Creates a builder to create your custom caches by default this will enter the suggested settings * diff --git a/API/src/main/java/net/juligames/core/api/misc/EntryInterpretationUtil.java b/API/src/main/java/net/juligames/core/api/misc/EntryInterpretationUtil.java new file mode 100644 index 00000000..bc45d5cc --- /dev/null +++ b/API/src/main/java/net/juligames/core/api/misc/EntryInterpretationUtil.java @@ -0,0 +1,48 @@ +package net.juligames.core.api.misc; + +import net.juligames.core.api.config.Interpreter; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.Collection; +import java.util.Map; +import java.util.stream.Collectors; + +public class EntryInterpretationUtil { + + private EntryInterpretationUtil() { + + } + + @Contract("_, _, _ -> new") + public static Map.@NotNull @Unmodifiable Entry interpretEntry(Map.@NotNull Entry stringStringEntry, @NotNull Interpreter kInterpreter, @NotNull Interpreter vInterpreter) throws Exception { + return Map.entry(kInterpreter.interpret(stringStringEntry.getKey()), vInterpreter.interpret(stringStringEntry.getValue())); + } + + @Contract("_, _, _ -> new") + public static Map.@NotNull @Unmodifiable Entry reverseEntry(Map.@NotNull Entry stringStringEntry, @NotNull Interpreter kInterpreter, @NotNull Interpreter vInterpreter) throws Exception { + return Map.entry(kInterpreter.reverse(stringStringEntry.getKey()), vInterpreter.reverse(stringStringEntry.getValue())); + } + + public static @Unmodifiable Collection> reverseEntries(@NotNull Collection> collection, Interpreter kInterpreter, Interpreter vInterpreter) { + return collection.stream().map(kvEntry -> { + try { + return reverseEntry(kvEntry,kInterpreter,vInterpreter); + } catch (Exception e) { + throw new RuntimeException(e); + } + }).collect(Collectors.toUnmodifiableSet()); + } + + + public static @Unmodifiable Collection> interpretEntries(@NotNull Collection> collection, Interpreter kInterpreter, Interpreter vInterpreter) { + return collection.stream().map(kvEntry -> { + try { + return interpretEntry(kvEntry,kInterpreter,vInterpreter); + } catch (Exception e) { + throw new RuntimeException(e); + } + }).collect(Collectors.toUnmodifiableSet()); + } +} diff --git a/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java b/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java index d33ad91f..5c61a2db 100644 --- a/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java +++ b/Core/src/main/java/net/juligames/core/caching/CoreCacheApi.java @@ -4,10 +4,12 @@ import com.github.benmanes.caffeine.cache.Caffeine; import de.bentzin.tools.pair.Pair; import net.juligames.core.api.cacheing.CacheApi; -import net.juligames.core.api.config.Configuration; -import net.juligames.core.api.err.dev.TODOException; +import net.juligames.core.api.config.Interpreter; import net.juligames.core.api.jdbi.DBMessage; -import org.jetbrains.annotations.ApiStatus; +import net.juligames.core.api.misc.EntryInterpretationUtil; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; /** * @author Ture Bentzin @@ -22,6 +24,19 @@ public Cache newCache() { return Caffeine.newBuilder().build(); } + @SuppressWarnings("unchecked") + @Override + public Map reverseCache(Interpreter kInterpreter, Interpreter vInterpreter, @NotNull Cache cache) { + return Map.ofEntries(EntryInterpretationUtil.reverseEntries(cache.asMap().entrySet(), kInterpreter, vInterpreter).toArray(Map.Entry[]::new)); + } + + + @SuppressWarnings("unchecked") + @Override + public Map interpretCache(Interpreter kInterpreter, Interpreter vInterpreter, @NotNull Cache cache) { + return Map.ofEntries(EntryInterpretationUtil.interpretEntries(cache.asMap().entrySet(), kInterpreter, vInterpreter).toArray(Map.Entry[]::new)); + } + @SuppressWarnings({"rawtypes", "unchecked"}) @Override public Caffeine newBuilder() { From 85474c94b9ad8853b3bcc277d0cb43fa13e6bdd2 Mon Sep 17 00:00:00 2001 From: Ture Bentzin Date: Wed, 22 Mar 2023 12:56:28 +0100 Subject: [PATCH 58/64] fix exception handeling with entry interpretation --- .../core/api/misc/EntryInterpretationUtil.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/API/src/main/java/net/juligames/core/api/misc/EntryInterpretationUtil.java b/API/src/main/java/net/juligames/core/api/misc/EntryInterpretationUtil.java index bc45d5cc..8f794f8b 100644 --- a/API/src/main/java/net/juligames/core/api/misc/EntryInterpretationUtil.java +++ b/API/src/main/java/net/juligames/core/api/misc/EntryInterpretationUtil.java @@ -21,18 +21,12 @@ private EntryInterpretationUtil() { } @Contract("_, _, _ -> new") - public static Map.@NotNull @Unmodifiable Entry reverseEntry(Map.@NotNull Entry stringStringEntry, @NotNull Interpreter kInterpreter, @NotNull Interpreter vInterpreter) throws Exception { + public static Map.@NotNull @Unmodifiable Entry reverseEntry(Map.@NotNull Entry stringStringEntry, @NotNull Interpreter kInterpreter, @NotNull Interpreter vInterpreter) { return Map.entry(kInterpreter.reverse(stringStringEntry.getKey()), vInterpreter.reverse(stringStringEntry.getValue())); } public static @Unmodifiable Collection> reverseEntries(@NotNull Collection> collection, Interpreter kInterpreter, Interpreter vInterpreter) { - return collection.stream().map(kvEntry -> { - try { - return reverseEntry(kvEntry,kInterpreter,vInterpreter); - } catch (Exception e) { - throw new RuntimeException(e); - } - }).collect(Collectors.toUnmodifiableSet()); + return collection.stream().map(kvEntry -> reverseEntry(kvEntry,kInterpreter,vInterpreter)).collect(Collectors.toUnmodifiableSet()); } From 8dfef5f21cbbe874825dec6d0fa780481855664b Mon Sep 17 00:00:00 2001 From: TDR Date: Wed, 22 Mar 2023 17:20:09 +0100 Subject: [PATCH 59/64] Update DurationFormatUtils.java --- .../java/net/juligames/core/api/misc/DurationFormatUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/API/src/main/java/net/juligames/core/api/misc/DurationFormatUtils.java b/API/src/main/java/net/juligames/core/api/misc/DurationFormatUtils.java index 1949c784..6285d582 100644 --- a/API/src/main/java/net/juligames/core/api/misc/DurationFormatUtils.java +++ b/API/src/main/java/net/juligames/core/api/misc/DurationFormatUtils.java @@ -50,7 +50,7 @@ * @author Stephane Bailliez * @author Stefan Bodewig * @author Gary Gregory - * @author Ture Bentin (edit) + * @author Ture Bentzin (edit) * @version $Id: DurationFormatUtils.java 1057072 2011-01-10 01:55:57Z niallp $ * @since 2.1 */ From ccfc2be27ab15a24394e73acf041f1e9ffacee07 Mon Sep 17 00:00:00 2001 From: TDR Date: Wed, 22 Mar 2023 17:40:42 +0100 Subject: [PATCH 60/64] integrate the Factories more --- .../mapbacked/DictionaryFeedInterpreter.java | 15 ++++++++++++++- .../api/config/mapbacked/EnvironmentVariable.java | 11 +++++++++++ .../mapbacked/EnvironmentVariableInterpreter.java | 2 -- .../api/config/mapbacked/MapFeedInterpreter.java | 13 ++++++++++++- .../core/adventure/CoreAdventureTagManager.java | 4 +++- 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java index 6b2c1c3a..7ef937c5 100644 --- a/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java @@ -5,6 +5,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Dictionary; +import java.util.Map; import java.util.function.BiFunction; import java.util.function.Supplier; @@ -34,7 +35,19 @@ public DictionaryFeedInterpreter(@NotNull Supplier> dictio @Override public @NotNull MapPart interpret(@NotNull String input) { - return new DictionaryPart<>(input, dictionarySupplier); + return fabricate(input); + } + + public BiFunction>, ? extends MapPart> getDictionaryPartFactory() { + return dictionaryPartFactory; + } + + public @NotNull MapPart fabricate(@NotNull String key, @NotNull Supplier> mapSupplier) { + return new DictionaryPart(key, dictionarySupplier); + } + + protected @NotNull MapPart fabricate(@NotNull String key) { + return new DictionaryPart(key, dictionarySupplier); } @Override diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/EnvironmentVariable.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/EnvironmentVariable.java index d1819551..9f42faf2 100644 --- a/API/src/main/java/net/juligames/core/api/config/mapbacked/EnvironmentVariable.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/EnvironmentVariable.java @@ -1,11 +1,14 @@ package net.juligames.core.api.config.mapbacked; +import net.juligames.core.api.config.Interpreter; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author Ture Bentzin * 07.03.2023 + * @apiNote This can be used as a standalone class for accessing environment variables! */ @ApiStatus.AvailableSince("1.5") public record EnvironmentVariable(String key) implements MapPart { @@ -13,4 +16,12 @@ public record EnvironmentVariable(String key) implements MapPart { public @NotNull String get() { return System.getenv().get(key()); } + + public @Nullable T get(@NotNull Interpreter tInterpreter) { + try { + return tInterpreter.interpret(get()); + } catch (Exception e) { + return null; + } + } } diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/EnvironmentVariableInterpreter.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/EnvironmentVariableInterpreter.java index 7fe216a6..ae1f3e75 100644 --- a/API/src/main/java/net/juligames/core/api/config/mapbacked/EnvironmentVariableInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/EnvironmentVariableInterpreter.java @@ -9,10 +9,8 @@ @ApiStatus.AvailableSince("1.5") public final class EnvironmentVariableInterpreter extends MapFeedInterpreter { - public EnvironmentVariableInterpreter() { super(System::getenv, (s, ignored) -> new EnvironmentVariable(s)); } - } diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java index 7e610807..496dd147 100644 --- a/API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java @@ -36,7 +36,7 @@ public MapFeedInterpreter(@NotNull Supplier> mapSupplier, @Override public @NotNull MapPart interpret(@NotNull String input) { - return new MapPartImpl<>(input, mapSupplier); + return fabricate(input); } @Override @@ -44,6 +44,17 @@ public MapFeedInterpreter(@NotNull Supplier> mapSupplier, return eMapPart.key(); } + public @NotNull BiFunction>, ? extends MapPart> getMapPartFactory() { + return mapPartFactory; + } + + public @NotNull MapPart fabricate(@NotNull String key, @NotNull Supplier> mapSupplier) { + return new MapPartImpl<>(key , mapSupplier); + } + + protected @NotNull MapPart fabricate(@NotNull String key) { + return new MapPartImpl<>(key , mapSupplier); + } private record MapPartImpl(String key, Supplier> mapSupplier) implements MapPart { diff --git a/AdventureCore/src/main/java/net/juligames/core/adventure/CoreAdventureTagManager.java b/AdventureCore/src/main/java/net/juligames/core/adventure/CoreAdventureTagManager.java index 82acc2bf..37d22079 100644 --- a/AdventureCore/src/main/java/net/juligames/core/adventure/CoreAdventureTagManager.java +++ b/AdventureCore/src/main/java/net/juligames/core/adventure/CoreAdventureTagManager.java @@ -30,7 +30,9 @@ public final class CoreAdventureTagManager implements TagManager, AdventureTagMa private TagResolver internalResolver = TagResolver.standard(); - protected String buildPattern(@Range(from = 0, to = Integer.MAX_VALUE) int i) { + @Contract(pure = true) + @Deprecated(forRemoval = true) + protected @NotNull String buildPattern(@Range(from = 0, to = Integer.MAX_VALUE) int i) { return "{" + i + "}"; } From 634ef9291df2cbb2dfb229bed719160e20d84f52 Mon Sep 17 00:00:00 2001 From: TDR Date: Wed, 22 Mar 2023 17:43:38 +0100 Subject: [PATCH 61/64] Update EnvironmentVariable.java --- .../core/api/config/mapbacked/EnvironmentVariable.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/EnvironmentVariable.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/EnvironmentVariable.java index 9f42faf2..35597627 100644 --- a/API/src/main/java/net/juligames/core/api/config/mapbacked/EnvironmentVariable.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/EnvironmentVariable.java @@ -24,4 +24,13 @@ public record EnvironmentVariable(String key) implements MapPart { return null; } } + + @Override + public @NotNull String toString() { + return "EnvironmentVariable: { \"" + key() + "\" : \"" + get() + "\"}"; + } + + public @NotNull String toString(@NotNull Interpreter interpreter) { + return "EnvironmentVariable: { \"" + key() + "\" : \"" + get(interpreter) + "\"}"; + } } From 60c01e98f9916bc8f8e623e88be9eac3ef739096 Mon Sep 17 00:00:00 2001 From: TDR Date: Wed, 22 Mar 2023 17:43:57 +0100 Subject: [PATCH 62/64] Delete Transaction.java --- .../net/juligames/core/api/data/Transaction.java | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 API/src/main/java/net/juligames/core/api/data/Transaction.java diff --git a/API/src/main/java/net/juligames/core/api/data/Transaction.java b/API/src/main/java/net/juligames/core/api/data/Transaction.java deleted file mode 100644 index 90147eeb..00000000 --- a/API/src/main/java/net/juligames/core/api/data/Transaction.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.juligames.core.api.data; - -import de.bentzin.tools.Workless; -import net.juligames.core.api.TODO; - -/** - * @author Ture Bentzin - * 16.11.2022 - */ -@Workless -@TODO(doNotcall = true) -public interface Transaction { - - void executeTransaction(); - -} From 2e6aa0ba169536afb4d71586fa545fc3206fe8c7 Mon Sep 17 00:00:00 2001 From: TDR Date: Wed, 22 Mar 2023 17:47:57 +0100 Subject: [PATCH 63/64] removed Experimental Status --- .../java/net/juligames/core/api/cacheing/CacheApi.java | 4 ++-- .../java/net/juligames/core/api/config/ConfigWriter.java | 6 ------ .../core/api/config/mapbacked/MapFeedInterpreter.java | 4 ++-- .../juligames/core/api/misc/EntryInterpretationUtil.java | 8 ++++---- .../java/net/juligames/core/api/misc/ThrowableDebug.java | 1 - Core/src/main/java/net/juligames/core/Core.java | 1 - 6 files changed, 8 insertions(+), 16 deletions(-) diff --git a/API/src/main/java/net/juligames/core/api/cacheing/CacheApi.java b/API/src/main/java/net/juligames/core/api/cacheing/CacheApi.java index b4e12f58..6065f390 100644 --- a/API/src/main/java/net/juligames/core/api/cacheing/CacheApi.java +++ b/API/src/main/java/net/juligames/core/api/cacheing/CacheApi.java @@ -25,10 +25,10 @@ public interface CacheApi { Cache newCache(); @ApiStatus.AvailableSince("1.5") - Map reverseCache(Interpreter kInterpreter, Interpreter vInterpreter, Cache cache); + Map reverseCache(Interpreter kInterpreter, Interpreter vInterpreter, Cache cache); @ApiStatus.AvailableSince("1.5") - Map interpretCache(Interpreter kInterpreter, Interpreter vInterpreter, Cache cache); + Map interpretCache(Interpreter kInterpreter, Interpreter vInterpreter, Cache cache); /** * Creates a builder to create your custom caches by default this will enter the suggested settings diff --git a/API/src/main/java/net/juligames/core/api/config/ConfigWriter.java b/API/src/main/java/net/juligames/core/api/config/ConfigWriter.java index cb3b266b..366067de 100644 --- a/API/src/main/java/net/juligames/core/api/config/ConfigWriter.java +++ b/API/src/main/java/net/juligames/core/api/config/ConfigWriter.java @@ -1,13 +1,7 @@ package net.juligames.core.api.config; -import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; -/** - * @author Ture Bentzin - * 10.01.2023 - */ -@ApiStatus.Experimental public interface ConfigWriter { /** * Writes the data of this {@link ConfigWriter} to the configuration diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java index 496dd147..87f01c3a 100644 --- a/API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java @@ -49,11 +49,11 @@ public MapFeedInterpreter(@NotNull Supplier> mapSupplier, } public @NotNull MapPart fabricate(@NotNull String key, @NotNull Supplier> mapSupplier) { - return new MapPartImpl<>(key , mapSupplier); + return new MapPartImpl<>(key, mapSupplier); } protected @NotNull MapPart fabricate(@NotNull String key) { - return new MapPartImpl<>(key , mapSupplier); + return new MapPartImpl<>(key, mapSupplier); } private record MapPartImpl(String key, Supplier> mapSupplier) implements MapPart { diff --git a/API/src/main/java/net/juligames/core/api/misc/EntryInterpretationUtil.java b/API/src/main/java/net/juligames/core/api/misc/EntryInterpretationUtil.java index 8f794f8b..d16c6d75 100644 --- a/API/src/main/java/net/juligames/core/api/misc/EntryInterpretationUtil.java +++ b/API/src/main/java/net/juligames/core/api/misc/EntryInterpretationUtil.java @@ -25,15 +25,15 @@ private EntryInterpretationUtil() { return Map.entry(kInterpreter.reverse(stringStringEntry.getKey()), vInterpreter.reverse(stringStringEntry.getValue())); } - public static @Unmodifiable Collection> reverseEntries(@NotNull Collection> collection, Interpreter kInterpreter, Interpreter vInterpreter) { - return collection.stream().map(kvEntry -> reverseEntry(kvEntry,kInterpreter,vInterpreter)).collect(Collectors.toUnmodifiableSet()); + public static @Unmodifiable Collection> reverseEntries(@NotNull Collection> collection, Interpreter kInterpreter, Interpreter vInterpreter) { + return collection.stream().map(kvEntry -> reverseEntry(kvEntry, kInterpreter, vInterpreter)).collect(Collectors.toUnmodifiableSet()); } - public static @Unmodifiable Collection> interpretEntries(@NotNull Collection> collection, Interpreter kInterpreter, Interpreter vInterpreter) { + public static @Unmodifiable Collection> interpretEntries(@NotNull Collection> collection, Interpreter kInterpreter, Interpreter vInterpreter) { return collection.stream().map(kvEntry -> { try { - return interpretEntry(kvEntry,kInterpreter,vInterpreter); + return interpretEntry(kvEntry, kInterpreter, vInterpreter); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/API/src/main/java/net/juligames/core/api/misc/ThrowableDebug.java b/API/src/main/java/net/juligames/core/api/misc/ThrowableDebug.java index d1d3a688..e00d4c16 100644 --- a/API/src/main/java/net/juligames/core/api/misc/ThrowableDebug.java +++ b/API/src/main/java/net/juligames/core/api/misc/ThrowableDebug.java @@ -16,7 +16,6 @@ public final class ThrowableDebug { private ThrowableDebug() { } - @ApiStatus.Experimental public static void debug(@NotNull Throwable throwable) { StringWriter stringWriter = new StringWriter(); PrintWriter writer = new PrintWriter(stringWriter); diff --git a/Core/src/main/java/net/juligames/core/Core.java b/Core/src/main/java/net/juligames/core/Core.java index 685913f1..0c5e00a1 100644 --- a/Core/src/main/java/net/juligames/core/Core.java +++ b/Core/src/main/java/net/juligames/core/Core.java @@ -78,7 +78,6 @@ public Core() { * * @param core_name the core name */ - @ApiStatus.Experimental public Core(String core_name) { start(core_name); } From 10af82a702d6aebec058012e6a6ef7e6b3264f1c Mon Sep 17 00:00:00 2001 From: TDR Date: Thu, 23 Mar 2023 17:44:42 +0100 Subject: [PATCH 64/64] fixed some bugs --- .../java/net/juligames/core/api/config/ConfigWriter.java | 4 ++++ .../api/config/mapbacked/DictionaryFeedInterpreter.java | 7 +++---- .../core/api/config/mapbacked/MapFeedInterpreter.java | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/API/src/main/java/net/juligames/core/api/config/ConfigWriter.java b/API/src/main/java/net/juligames/core/api/config/ConfigWriter.java index 366067de..a7abb1b7 100644 --- a/API/src/main/java/net/juligames/core/api/config/ConfigWriter.java +++ b/API/src/main/java/net/juligames/core/api/config/ConfigWriter.java @@ -2,6 +2,10 @@ import org.jetbrains.annotations.NotNull; +/** + * @author Ture Bentzin + * 10.01.2023 + */ public interface ConfigWriter { /** * Writes the data of this {@link ConfigWriter} to the configuration diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java index 7ef937c5..6142d7b4 100644 --- a/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/DictionaryFeedInterpreter.java @@ -5,7 +5,6 @@ import org.jetbrains.annotations.NotNull; import java.util.Dictionary; -import java.util.Map; import java.util.function.BiFunction; import java.util.function.Supplier; @@ -42,12 +41,12 @@ public DictionaryFeedInterpreter(@NotNull Supplier> dictio return dictionaryPartFactory; } - public @NotNull MapPart fabricate(@NotNull String key, @NotNull Supplier> mapSupplier) { - return new DictionaryPart(key, dictionarySupplier); + public @NotNull MapPart fabricate(@NotNull String key, @NotNull Supplier> dictionarySupplier) { + return dictionaryPartFactory.apply(key, dictionarySupplier); } protected @NotNull MapPart fabricate(@NotNull String key) { - return new DictionaryPart(key, dictionarySupplier); + return dictionaryPartFactory.apply(key, dictionarySupplier); } @Override diff --git a/API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java b/API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java index 87f01c3a..71851f69 100644 --- a/API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java +++ b/API/src/main/java/net/juligames/core/api/config/mapbacked/MapFeedInterpreter.java @@ -49,11 +49,11 @@ public MapFeedInterpreter(@NotNull Supplier> mapSupplier, } public @NotNull MapPart fabricate(@NotNull String key, @NotNull Supplier> mapSupplier) { - return new MapPartImpl<>(key, mapSupplier); + return mapPartFactory.apply(key,mapSupplier); } protected @NotNull MapPart fabricate(@NotNull String key) { - return new MapPartImpl<>(key, mapSupplier); + return mapPartFactory.apply(key,mapSupplier); } private record MapPartImpl(String key, Supplier> mapSupplier) implements MapPart {