From 422f76e413c3e82243ed02265542c2bef59f53e9 Mon Sep 17 00:00:00 2001 From: Jakubk15 <77227023+Jakubk15@users.noreply.github.com> Date: Sat, 14 Oct 2023 09:35:34 +0200 Subject: [PATCH 01/15] Add DeliveryCode package and its objects --- .../deliverycode/DeliveryCode.java | 6 +++ .../repository/DeliveryCodeRepository.java | 18 ++++++++ .../DeliveryCodeRepositoryImpl.java | 44 +++++++++++++++++++ .../parcellockers/event/EventCaller.java | 20 +++++++++ 4 files changed, 88 insertions(+) create mode 100644 src/main/java/com/eternalcode/parcellockers/deliverycode/DeliveryCode.java create mode 100644 src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepository.java create mode 100644 src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java create mode 100644 src/main/java/com/eternalcode/parcellockers/event/EventCaller.java diff --git a/src/main/java/com/eternalcode/parcellockers/deliverycode/DeliveryCode.java b/src/main/java/com/eternalcode/parcellockers/deliverycode/DeliveryCode.java new file mode 100644 index 00000000..f5f6eb08 --- /dev/null +++ b/src/main/java/com/eternalcode/parcellockers/deliverycode/DeliveryCode.java @@ -0,0 +1,6 @@ +package com.eternalcode.parcellockers.deliverycode; + +import java.util.UUID; + +public record DeliveryCode(UUID parcelUUID, String code) { +} diff --git a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepository.java b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepository.java new file mode 100644 index 00000000..e2384be2 --- /dev/null +++ b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepository.java @@ -0,0 +1,18 @@ +package com.eternalcode.parcellockers.deliverycode.repository; + +import com.eternalcode.parcellockers.deliverycode.DeliveryCode; + +import java.util.UUID; +import java.util.concurrent.CompletableFuture; + +public interface DeliveryCodeRepository { + + CompletableFuture save(DeliveryCode deliveryCode); + + CompletableFuture findByUUID(UUID parcelUUID); + + CompletableFuture remove(DeliveryCode deliveryCode); + + CompletableFuture remove(UUID parcelUUID); + +} diff --git a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java new file mode 100644 index 00000000..d09349be --- /dev/null +++ b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java @@ -0,0 +1,44 @@ +package com.eternalcode.parcellockers.deliverycode.repository; + +import com.eternalcode.parcellockers.database.AbstractDatabaseService; +import com.eternalcode.parcellockers.deliverycode.DeliveryCode; + +import javax.sql.DataSource; +import java.sql.PreparedStatement; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; + +public class DeliveryCodeRepositoryImpl extends AbstractDatabaseService implements DeliveryCodeRepository { + + protected DeliveryCodeRepositoryImpl(DataSource dataSource) { + super(dataSource); + } + + private void initTable() { + this.executeSync("CREATE TABLE IF NOT EXISTS `delivery_codes`(" + + "`parcelUUID` VARCHAR(36) NOT NULL, " + + "`code` VARCHAR(6) NOT NULL, " + + "PRIMARY KEY (parcelUUID) " + + ");", PreparedStatement::execute); + } + + @Override + public CompletableFuture save(DeliveryCode deliveryCode) { + return null; + } + + @Override + public CompletableFuture findByUUID(UUID parcelUUID) { + return null; + } + + @Override + public CompletableFuture remove(DeliveryCode deliveryCode) { + return null; + } + + @Override + public CompletableFuture remove(UUID parcelUUID) { + return null; + } +} diff --git a/src/main/java/com/eternalcode/parcellockers/event/EventCaller.java b/src/main/java/com/eternalcode/parcellockers/event/EventCaller.java new file mode 100644 index 00000000..69eaee15 --- /dev/null +++ b/src/main/java/com/eternalcode/parcellockers/event/EventCaller.java @@ -0,0 +1,20 @@ +package com.eternalcode.parcellockers.event; + +import org.bukkit.Server; +import org.bukkit.event.Event; + +public class EventCaller { + + private final Server server; + + public EventCaller(Server server) { + this.server = server; + } + + public T callEvent(T event) { + this.server.getPluginManager().callEvent(event); + + return event; + } + +} From 7045e502b650d74ea5a69e95421a6a4285f3535c Mon Sep 17 00:00:00 2001 From: Jakubk15 <77227023+Jakubk15@users.noreply.github.com> Date: Sun, 15 Oct 2023 09:42:08 +0200 Subject: [PATCH 02/15] Implement DeliveryCodeRepository --- .../parcellockers/ParcelLockers.java | 20 ++++---- .../DeliveryCodeRepositoryImpl.java | 50 +++++++++++++++++-- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/eternalcode/parcellockers/ParcelLockers.java b/src/main/java/com/eternalcode/parcellockers/ParcelLockers.java index d2cdc9b5..6b829994 100644 --- a/src/main/java/com/eternalcode/parcellockers/ParcelLockers.java +++ b/src/main/java/com/eternalcode/parcellockers/ParcelLockers.java @@ -6,7 +6,6 @@ import com.eternalcode.parcellockers.configuration.ConfigurationManager; import com.eternalcode.parcellockers.configuration.implementation.PluginConfiguration; import com.eternalcode.parcellockers.database.DataSourceFactory; -import com.eternalcode.parcellockers.locker.LockerManager; import com.eternalcode.parcellockers.locker.controller.LockerBreakController; import com.eternalcode.parcellockers.locker.controller.LockerInteractionController; import com.eternalcode.parcellockers.locker.controller.LockerPlaceController; @@ -84,23 +83,22 @@ public void onEnable() { HikariDataSource dataSource = DataSourceFactory.buildHikariDataSource(config, this.getDataFolder()); - LockerRepositoryImpl parcelLockerRepositoryImpl = new LockerRepositoryImpl(dataSource); - parcelLockerRepositoryImpl.updatePositionCache(); + LockerRepositoryImpl lockerRepositoryImpl = new LockerRepositoryImpl(dataSource); + lockerRepositoryImpl.updatePositionCache(); ParcelRepositoryImpl parcelRepository = new ParcelRepositoryImpl(dataSource); - ParcelManager parcelManager = new ParcelManager(this, config, announcer, parcelRepository, parcelLockerRepositoryImpl); - LockerManager lockerManager = new LockerManager(parcelLockerRepositoryImpl); + ParcelManager parcelManager = new ParcelManager(config, announcer, parcelRepository); - MainGUI mainGUI = new MainGUI(this, server, miniMessage, config, parcelRepository, parcelLockerRepositoryImpl); - ParcelListGUI parcelListGUI = new ParcelListGUI(this, server, miniMessage, config, parcelRepository, parcelLockerRepositoryImpl, mainGUI); + MainGUI mainGUI = new MainGUI(this, server, miniMessage, config, parcelRepository, lockerRepositoryImpl); + ParcelListGUI parcelListGUI = new ParcelListGUI(this, server, miniMessage, config, parcelRepository, lockerRepositoryImpl, mainGUI); this.liteCommands = LiteBukkitAdventurePlatformFactory.builder(server, "parcellockers", false, this.audiences, true) .argument(Parcel.class, new ParcelArgument(parcelRepository)) .argument(Player.class, new PlayerArgument(server, config)) .contextualBind(Player.class, new BukkitOnlyPlayerContextual<>(config.messages.onlyForPlayers)) .commandInstance( - new ParcelCommand(server, parcelLockerRepositoryImpl, announcer, config, mainGUI, parcelListGUI, parcelManager), + new ParcelCommand(server, lockerRepositoryImpl, announcer, config, mainGUI, parcelListGUI, parcelManager), new ParcelLockersCommand(configManager, config, announcer, miniMessage) ) .invalidUsageHandler(new InvalidUsage(announcer, config)) @@ -114,9 +112,9 @@ public void onEnable() { } Stream.of( - new LockerInteractionController(parcelLockerRepositoryImpl, miniMessage, config), - new LockerPlaceController(config, miniMessage, this, parcelLockerRepositoryImpl, announcer), - new LockerBreakController(parcelLockerRepositoryImpl, announcer, config.messages) + new LockerInteractionController(lockerRepositoryImpl, miniMessage, config), + new LockerPlaceController(config, miniMessage, this, lockerRepositoryImpl, announcer), + new LockerBreakController(lockerRepositoryImpl, announcer, config.messages) ).forEach(controller -> server.getPluginManager().registerEvents(controller, this)); new Metrics(this, 17677); diff --git a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java index d09349be..f58f2045 100644 --- a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java +++ b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java @@ -5,13 +5,21 @@ import javax.sql.DataSource; import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; public class DeliveryCodeRepositoryImpl extends AbstractDatabaseService implements DeliveryCodeRepository { + private Map cache = new HashMap<>(); + protected DeliveryCodeRepositoryImpl(DataSource dataSource) { super(dataSource); + + this.initTable(); } private void initTable() { @@ -24,21 +32,55 @@ private void initTable() { @Override public CompletableFuture save(DeliveryCode deliveryCode) { - return null; + return this.execute("INSERT INTO `delivery_codes` (`parcelUUID`, `code`) VALUES (?, ?);", preparedStatement -> { + preparedStatement.setString(1, deliveryCode.parcelUUID().toString()); + preparedStatement.setString(2, deliveryCode.code()); + preparedStatement.execute(); + this.cache.put(deliveryCode.parcelUUID(), deliveryCode); + }); } @Override public CompletableFuture findByUUID(UUID parcelUUID) { - return null; + return this.supplyExecute("SELECT * FROM `delivery_codes` WHERE `parcelUUID` = ?;", statement -> { + statement.setString(1, parcelUUID.toString()); + ResultSet rs = statement.executeQuery(); + + if (!rs.next()) { + return null; + } + + this.cache.putIfAbsent(parcelUUID, new DeliveryCode( + UUID.fromString(rs.getString("parcelUUID")), + rs.getString("code") + )); + + return new DeliveryCode( + UUID.fromString(rs.getString("parcelUUID")), + rs.getString("code") + ); + }); } @Override public CompletableFuture remove(DeliveryCode deliveryCode) { - return null; + return this.remove(deliveryCode.parcelUUID()); } @Override public CompletableFuture remove(UUID parcelUUID) { - return null; + return this.supplyExecute("DELETE FROM `delivery_codes` WHERE `parcelUUID` = ?;", statement -> { + statement.setString(1, parcelUUID.toString()); + statement.execute(); + this.cache.remove(parcelUUID); + return null; + }); + } + + public Optional find(UUID parcelUUID) { + if (this.cache.get(parcelUUID) != null) { + return Optional.of(this.cache.get(parcelUUID)); + } + return Optional.ofNullable(this.findByUUID(parcelUUID).join()); } } From 7691d2169743dc0cf419bb5fbd1399ac11041914 Mon Sep 17 00:00:00 2001 From: Jakubk15 <77227023+Jakubk15@users.noreply.github.com> Date: Sun, 15 Oct 2023 10:07:07 +0200 Subject: [PATCH 03/15] Fix build --- .../eternalcode/parcellockers/parcel/ParcelManager.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/com/eternalcode/parcellockers/parcel/ParcelManager.java b/src/main/java/com/eternalcode/parcellockers/parcel/ParcelManager.java index 6fd74d80..135a350b 100644 --- a/src/main/java/com/eternalcode/parcellockers/parcel/ParcelManager.java +++ b/src/main/java/com/eternalcode/parcellockers/parcel/ParcelManager.java @@ -1,26 +1,20 @@ package com.eternalcode.parcellockers.parcel; import com.eternalcode.parcellockers.configuration.implementation.PluginConfiguration; -import com.eternalcode.parcellockers.locker.repository.LockerRepository; import com.eternalcode.parcellockers.notification.NotificationAnnouncer; import com.eternalcode.parcellockers.parcel.repository.ParcelRepository; import org.bukkit.command.CommandSender; -import org.bukkit.plugin.Plugin; public class ParcelManager { - private final Plugin plugin; private final PluginConfiguration config; private final NotificationAnnouncer announcer; private final ParcelRepository databaseService; - private final LockerRepository lockerRepository; - public ParcelManager(Plugin plugin, PluginConfiguration config, NotificationAnnouncer announcer, ParcelRepository databaseService, LockerRepository lockerRepository) { - this.plugin = plugin; + public ParcelManager(PluginConfiguration config, NotificationAnnouncer announcer, ParcelRepository databaseService) { this.config = config; this.announcer = announcer; this.databaseService = databaseService; - this.lockerRepository = lockerRepository; } public void createParcel(CommandSender sender, Parcel parcel) { From 88f9f0f9eebba47442b514731abbabfeb2fa44fa Mon Sep 17 00:00:00 2001 From: Jakubk15 <77227023+Jakubk15@users.noreply.github.com> Date: Sun, 15 Oct 2023 10:24:55 +0200 Subject: [PATCH 04/15] Fix codestyle --- .../parcellockers/ParcelLockers.java | 32 ++-- .../parcellockers/ParcelLockersCommand.java | 2 +- .../command/argument/PlayerArgument.java | 6 +- .../command/handler/InvalidUsage.java | 2 +- .../command/handler/PermissionMessage.java | 6 +- .../configuration/ConfigurationManager.java | 12 +- .../implementation/ConfigItem.java | 3 +- .../implementation/PluginConfiguration.java | 151 +++++++++--------- .../deliverycode/DeliveryCode.java | 1 + .../DeliveryCodeRepositoryImpl.java | 18 +-- .../controller/LockerBreakController.java | 14 +- .../LockerInteractionController.java | 14 +- .../locker/gui/LockerMainGUI.java | 2 +- .../repository/LockerRepositoryImpl.java | 26 +-- .../notification/NotificationAnnouncer.java | 10 +- .../parcellockers/parcel/Parcel.java | 3 +- .../command/argument/ParcelArgument.java | 8 +- .../parcel/gui/ParcelItemStorageGUI.java | 12 +- .../parcel/gui/ParcelListGUI.java | 10 +- .../parcel/gui/ParcelSendingGUI.java | 6 +- .../repository/ParcelRepositoryImpl.java | 62 +++---- .../parcellockers/shared/PositionAdapter.java | 3 +- .../parcellockers/updater/UpdaterService.java | 1 + .../parcellockers/util/AdventureUtil.java | 4 +- .../parcellockers/util/DurationUtil.java | 6 +- .../parcellockers/util/ItemUtil.java | 4 +- .../parcellockers/util/legacy/Legacy.java | 8 +- .../util/legacy/LegacyColorProcessor.java | 2 +- 28 files changed, 217 insertions(+), 211 deletions(-) diff --git a/src/main/java/com/eternalcode/parcellockers/ParcelLockers.java b/src/main/java/com/eternalcode/parcellockers/ParcelLockers.java index 6b829994..f167e85b 100644 --- a/src/main/java/com/eternalcode/parcellockers/ParcelLockers.java +++ b/src/main/java/com/eternalcode/parcellockers/ParcelLockers.java @@ -60,8 +60,8 @@ public void onEnable() { this.audiences = BukkitAudiences.create(this); MiniMessage miniMessage = MiniMessage.builder() - .postProcessor(new LegacyColorProcessor()) - .build(); + .postProcessor(new LegacyColorProcessor()) + .build(); NotificationAnnouncer announcer = new NotificationAnnouncer(this.audiences, miniMessage); ConfigurationManager configManager = new ConfigurationManager(this.getDataFolder()); @@ -85,25 +85,25 @@ public void onEnable() { LockerRepositoryImpl lockerRepositoryImpl = new LockerRepositoryImpl(dataSource); lockerRepositoryImpl.updatePositionCache(); - + ParcelRepositoryImpl parcelRepository = new ParcelRepositoryImpl(dataSource); ParcelManager parcelManager = new ParcelManager(config, announcer, parcelRepository); MainGUI mainGUI = new MainGUI(this, server, miniMessage, config, parcelRepository, lockerRepositoryImpl); ParcelListGUI parcelListGUI = new ParcelListGUI(this, server, miniMessage, config, parcelRepository, lockerRepositoryImpl, mainGUI); - + this.liteCommands = LiteBukkitAdventurePlatformFactory.builder(server, "parcellockers", false, this.audiences, true) - .argument(Parcel.class, new ParcelArgument(parcelRepository)) - .argument(Player.class, new PlayerArgument(server, config)) - .contextualBind(Player.class, new BukkitOnlyPlayerContextual<>(config.messages.onlyForPlayers)) - .commandInstance( - new ParcelCommand(server, lockerRepositoryImpl, announcer, config, mainGUI, parcelListGUI, parcelManager), - new ParcelLockersCommand(configManager, config, announcer, miniMessage) - ) - .invalidUsageHandler(new InvalidUsage(announcer, config)) - .permissionHandler(new PermissionMessage(announcer, config)) - .register(); + .argument(Parcel.class, new ParcelArgument(parcelRepository)) + .argument(Player.class, new PlayerArgument(server, config)) + .contextualBind(Player.class, new BukkitOnlyPlayerContextual<>(config.messages.onlyForPlayers)) + .commandInstance( + new ParcelCommand(server, lockerRepositoryImpl, announcer, config, mainGUI, parcelListGUI, parcelManager), + new ParcelLockersCommand(configManager, config, announcer, miniMessage) + ) + .invalidUsageHandler(new InvalidUsage(announcer, config)) + .permissionHandler(new PermissionMessage(announcer, config)) + .register(); if (!this.setupEconomy()) { this.getLogger().severe("Disabling due to no Vault dependency found!"); @@ -159,12 +159,12 @@ private boolean setupEconomy() { if (this.getServer().getPluginManager().getPlugin("Vault") == null) { return false; } - + RegisteredServiceProvider rsp = this.getServer().getServicesManager().getRegistration(Economy.class); if (rsp == null) { return false; } - + this.economy = rsp.getProvider(); return true; } diff --git a/src/main/java/com/eternalcode/parcellockers/ParcelLockersCommand.java b/src/main/java/com/eternalcode/parcellockers/ParcelLockersCommand.java index c3ce6620..8e492966 100644 --- a/src/main/java/com/eternalcode/parcellockers/ParcelLockersCommand.java +++ b/src/main/java/com/eternalcode/parcellockers/ParcelLockersCommand.java @@ -27,7 +27,7 @@ public ParcelLockersCommand(ConfigurationManager configManager, PluginConfigurat this.announcer = announcer; this.miniMessage = miniMessage; } - + @Async @Execute(route = "reload", aliases = {"rl"}) void reload(CommandSender sender) { diff --git a/src/main/java/com/eternalcode/parcellockers/command/argument/PlayerArgument.java b/src/main/java/com/eternalcode/parcellockers/command/argument/PlayerArgument.java index 822792aa..1087a036 100644 --- a/src/main/java/com/eternalcode/parcellockers/command/argument/PlayerArgument.java +++ b/src/main/java/com/eternalcode/parcellockers/command/argument/PlayerArgument.java @@ -36,8 +36,8 @@ public PlayerArgument(Server server, PluginConfiguration config) { @Override public List suggest(LiteInvocation invocation) { return this.server.getOnlinePlayers().stream() - .map(HumanEntity::getName) - .map(Suggestion::of) - .toList(); + .map(HumanEntity::getName) + .map(Suggestion::of) + .toList(); } } diff --git a/src/main/java/com/eternalcode/parcellockers/command/handler/InvalidUsage.java b/src/main/java/com/eternalcode/parcellockers/command/handler/InvalidUsage.java index de293ede..7ffbc404 100644 --- a/src/main/java/com/eternalcode/parcellockers/command/handler/InvalidUsage.java +++ b/src/main/java/com/eternalcode/parcellockers/command/handler/InvalidUsage.java @@ -31,7 +31,7 @@ public void handle(CommandSender sender, LiteInvocation invocation, Schematic sc for (String scheme : schematics) { Formatter formatter = new Formatter() - .register("{USAGE}", scheme); + .register("{USAGE}", scheme); this.announcer.sendMessage(sender, formatter.format(this.config.messages.invalidUsage)); } diff --git a/src/main/java/com/eternalcode/parcellockers/command/handler/PermissionMessage.java b/src/main/java/com/eternalcode/parcellockers/command/handler/PermissionMessage.java index 33614928..5bfd5df8 100644 --- a/src/main/java/com/eternalcode/parcellockers/command/handler/PermissionMessage.java +++ b/src/main/java/com/eternalcode/parcellockers/command/handler/PermissionMessage.java @@ -22,11 +22,11 @@ public PermissionMessage(NotificationAnnouncer announcer, PluginConfiguration co @Override public void handle(CommandSender commandSender, LiteInvocation invocation, RequiredPermissions requiredPermissions) { String value = Joiner.on(", ") - .join(requiredPermissions.getPermissions()) - .toString(); + .join(requiredPermissions.getPermissions()) + .toString(); Formatter formatter = new Formatter() - .register("{PERMISSION}", value); + .register("{PERMISSION}", value); this.announcer.sendMessage(commandSender, formatter.format(this.config.messages.noPermission)); } diff --git a/src/main/java/com/eternalcode/parcellockers/configuration/ConfigurationManager.java b/src/main/java/com/eternalcode/parcellockers/configuration/ConfigurationManager.java index 3d4782ac..05c604bc 100644 --- a/src/main/java/com/eternalcode/parcellockers/configuration/ConfigurationManager.java +++ b/src/main/java/com/eternalcode/parcellockers/configuration/ConfigurationManager.java @@ -11,10 +11,10 @@ public class ConfigurationManager { private static final Cdn CDN = CdnFactory - .createYamlLike() - .getSettings() - .withComposer(PositionComposer.class, new PositionComposer()) - .build(); + .createYamlLike() + .getSettings() + .withComposer(PositionComposer.class, new PositionComposer()) + .build(); private final Set configs = new HashSet<>(); private final File dataFolder; @@ -25,10 +25,10 @@ public ConfigurationManager(File dataFolder) { public T load(T config) { CDN.load(config.resource(this.dataFolder), config) - .orThrow(RuntimeException::new); + .orThrow(RuntimeException::new); CDN.render(config, config.resource(this.dataFolder)) - .orThrow(RuntimeException::new); + .orThrow(RuntimeException::new); this.configs.add(config); diff --git a/src/main/java/com/eternalcode/parcellockers/configuration/implementation/ConfigItem.java b/src/main/java/com/eternalcode/parcellockers/configuration/implementation/ConfigItem.java index d760264c..14dcac0c 100644 --- a/src/main/java/com/eternalcode/parcellockers/configuration/implementation/ConfigItem.java +++ b/src/main/java/com/eternalcode/parcellockers/configuration/implementation/ConfigItem.java @@ -33,7 +33,8 @@ public GuiItem toGuiItem(MiniMessage miniMessage, GuiAction } public GuiItem toGuiItem(MiniMessage miniMessage) { - return this.toGuiItem(miniMessage, event -> {}); + return this.toGuiItem(miniMessage, event -> { + }); } public ConfigItem setType(Material type) { diff --git a/src/main/java/com/eternalcode/parcellockers/configuration/implementation/PluginConfiguration.java b/src/main/java/com/eternalcode/parcellockers/configuration/implementation/PluginConfiguration.java index 89a304c6..df7b4465 100644 --- a/src/main/java/com/eternalcode/parcellockers/configuration/implementation/PluginConfiguration.java +++ b/src/main/java/com/eternalcode/parcellockers/configuration/implementation/PluginConfiguration.java @@ -27,11 +27,11 @@ public class PluginConfiguration implements ReloadableConfig { public static class Settings { @Description({" ", - "# Should we enable Sentry integration?", - "# Sentry is a service that collects errors and other information about the plugin.", - "# It is used to improve the plugin and fix bugs.", - "# It is also strongly recommended to enable this option.", - "# You can learn more about Sentry here: https://sentry.io/"}) + "# Should we enable Sentry integration?", + "# Sentry is a service that collects errors and other information about the plugin.", + "# It is used to improve the plugin and fix bugs.", + "# It is also strongly recommended to enable this option.", + "# You can learn more about Sentry here: https://sentry.io/"}) public boolean enableSentry = true; @Description({" ", "# Whether the player after entering the server should receive information about the new version of the plugin?"}) @@ -60,9 +60,9 @@ public static class Settings { @Description({" ", "# The parcel locker item."}) public ConfigItem parcelLockerItem = new ConfigItem() - .setName("&3Parcel locker") - .setType(Material.CHEST) - .setLore(List.of("&bPlace to create a parcel locker.")); + .setName("&3Parcel locker") + .setType(Material.CHEST) + .setLore(List.of("&bPlace to create a parcel locker.")); @Description({" ", "# Small parcel cost."}) public double smallParcelCost = 5.0; @@ -76,6 +76,7 @@ public static class Settings { @Contextual public static class Messages { + public String onlyForPlayers = "&7» &cThis command is only available to players!"; public String noPermission = "&7» &cYou don't have permission to perform this command! &c(&7{PERMISSION}&c)"; public String cantFindPlayer = "&7» &cThe specified player could not be found!"; @@ -126,101 +127,101 @@ public static class GuiSettings { @Description({" ", "# The item of the small parcel size button"}) public ConfigItem smallParcelSizeItem = new ConfigItem() - .setName("&aSmall") - .setLore(List.of("&bClick to select the small parcel size.")) - .setType(Material.LIME_STAINED_GLASS); + .setName("&aSmall") + .setLore(List.of("&bClick to select the small parcel size.")) + .setType(Material.LIME_STAINED_GLASS); @Description({" ", "# The item of the medium parcel size button"}) public ConfigItem mediumParcelSizeItem = new ConfigItem() - .setName("&eMedium") - .setLore(List.of("&bClick to select the medium parcel size.")) - .setType(Material.YELLOW_STAINED_GLASS); + .setName("&eMedium") + .setLore(List.of("&bClick to select the medium parcel size.")) + .setType(Material.YELLOW_STAINED_GLASS); @Description({" ", "# The item of the large parcel size button"}) public ConfigItem largeParcelSizeItem = new ConfigItem() - .setName("&cLarge") - .setLore(List.of("&bClick to select the large parcel size.")) - .setType(Material.RED_STAINED_GLASS); + .setName("&cLarge") + .setLore(List.of("&bClick to select the large parcel size.")) + .setType(Material.RED_STAINED_GLASS); @Description({" ", "# The item of the priority button"}) public ConfigItem priorityItem = new ConfigItem() - .setName("&aPriority") - .setLore(List.of("&bClick to select the priority.")) - .setType(Material.REDSTONE); + .setName("&aPriority") + .setLore(List.of("&bClick to select the priority.")) + .setType(Material.REDSTONE); @Description({" ", "# The close button item"}) public ConfigItem closeItem = new ConfigItem() - .setName("&cClose") - .setLore(List.of("&cClick to close the GUI.")) - .setType(Material.BARRIER); + .setName("&cClose") + .setLore(List.of("&cClick to close the GUI.")) + .setType(Material.BARRIER); @Description({" ", "# The item of the main GUI"}) public ConfigItem mainGuiBackgroundItem = new ConfigItem() - .setName("") - .setLore(Collections.emptyList()) - .setType(Material.GRAY_STAINED_GLASS_PANE); + .setName("") + .setLore(Collections.emptyList()) + .setType(Material.GRAY_STAINED_GLASS_PANE); @Description({" ", "# The item of the corner GUI item.", "# Purely for decoration purposes."}) public ConfigItem cornerItem = new ConfigItem() - .setName("") - .setLore(Collections.emptyList()) - .setType(Material.BLUE_STAINED_GLASS_PANE); + .setName("") + .setLore(Collections.emptyList()) + .setType(Material.BLUE_STAINED_GLASS_PANE); @Description({" ", "# The item of the parcel list button"}) public ConfigItem myParcelsItem = new ConfigItem() - .setName("&3My parcels") - .setLore(List.of("&bClick to open your parcels.")) - .setType(Material.ENDER_CHEST); + .setName("&3My parcels") + .setLore(List.of("&bClick to open your parcels.")) + .setType(Material.ENDER_CHEST); @Description({" ", "# The item of the sent parcels button"}) public ConfigItem sentParcelsItem = new ConfigItem() - .setName("&6Sent parcels") - .setLore(List.of("&eClick to show parcels, which you sent.", "&eYou can also cancel them here, if you want to.")) - .setType(Material.FILLED_MAP) - .setGlow(true); + .setName("&6Sent parcels") + .setLore(List.of("&eClick to show parcels, which you sent.", "&eYou can also cancel them here, if you want to.")) + .setType(Material.FILLED_MAP) + .setGlow(true); @Description({" ", "# The parcel archive item button."}) public ConfigItem parcelArchiveItem = new ConfigItem() - .setName("&5Parcel archive") - .setLore(List.of("&eClick to show all parcels, which you sent or received in the past.")) - .setType(Material.WRITTEN_BOOK); + .setName("&5Parcel archive") + .setLore(List.of("&eClick to show all parcels, which you sent or received in the past.")) + .setType(Material.WRITTEN_BOOK); @Description({" ", "# The item of the parcel locker collect button"}) public ConfigItem parcelLockerCollectItem = new ConfigItem() - .setName("&aCollect parcels") - .setLore(List.of("&aClick to collect your parcels.")) - .setType(Material.HOPPER) - .setGlow(true); + .setName("&aCollect parcels") + .setLore(List.of("&aClick to collect your parcels.")) + .setType(Material.HOPPER) + .setGlow(true); @Description({" ", "# The item of the parcel locker send button"}) public ConfigItem parcelLockerSendItem = new ConfigItem() - .setName("&bSend parcels") - .setLore(List.of("&bClick to send parcels.")) - .setType(Material.SCULK_SHRIEKER) - .setGlow(true); + .setName("&bSend parcels") + .setLore(List.of("&bClick to send parcels.")) + .setType(Material.SCULK_SHRIEKER) + .setGlow(true); @Description({" ", "# The item of the parcel locker status button"}) public ConfigItem parcelLockerStatusItem = new ConfigItem() - .setName("&3Parcel locker status") - .setLore(List.of("&bClick to show the status of your parcel locker.")) - .setType(Material.END_PORTAL_FRAME) - .setGlow(true); + .setName("&3Parcel locker status") + .setLore(List.of("&bClick to show the status of your parcel locker.")) + .setType(Material.END_PORTAL_FRAME) + .setGlow(true); @Description({" ", "# The item of the parcel"}) public ConfigItem parcelItem = new ConfigItem() - .setName("&6{NAME}") - .setLore(List.of( - "&6UUID: &e{UUID}", - "&Sender: &e{SENDER}", - "&6Receiver: &e{RECEIVER}", - "&6Size: &e{SIZE}", - "&6Position: &6X: &e{POSITION_X}, &6Y: &e{POSITION_Y}, &6Z: &e{POSITION_Z}", - "&6Priority: &e{PRIORITY}", - "&6Description: &e{DESCRIPTION}", - "&6Recipients: &e{RECIPIENTS}" - ) + .setName("&6{NAME}") + .setLore(List.of( + "&6UUID: &e{UUID}", + "&Sender: &e{SENDER}", + "&6Receiver: &e{RECEIVER}", + "&6Size: &e{SIZE}", + "&6Position: &6X: &e{POSITION_X}, &6Y: &e{POSITION_Y}, &6Z: &e{POSITION_Z}", + "&6Priority: &e{PRIORITY}", + "&6Description: &e{DESCRIPTION}", + "&6Recipients: &e{RECIPIENTS}" ) - .setType(Material.CHEST_MINECART); + ) + .setType(Material.CHEST_MINECART); @Description({" ", "# The item of the parcel item storage button"}) public ConfigItem parcelStorageItem = new ConfigItem() @@ -230,27 +231,27 @@ public static class GuiSettings { @Description({" ", "# The item of the previous page button"}) public ConfigItem previousPageItem = new ConfigItem() - .setName("&bPrevious page") - .setLore(List.of("&bClick to go to the previous page.")) - .setType(Material.ARROW); + .setName("&bPrevious page") + .setLore(List.of("&bClick to go to the previous page.")) + .setType(Material.ARROW); @Description({" ", "# The item of the next page button"}) public ConfigItem nextPageItem = new ConfigItem() - .setName("&bNext page") - .setLore(List.of("&bClick to go to the next page.")) - .setType(Material.ARROW); + .setName("&bNext page") + .setLore(List.of("&bClick to go to the next page.")) + .setType(Material.ARROW); @Description({" ", "# The item of the confirm items button"}) public ConfigItem confirmItemsItem = new ConfigItem() - .setName("&aConfirm items") - .setLore(List.of("&aClick to confirm the items.")) - .setType(Material.LIME_WOOL); + .setName("&aConfirm items") + .setLore(List.of("&aClick to confirm the items.")) + .setType(Material.LIME_WOOL); @Description({" ", "# The item of the cancel items button"}) public ConfigItem cancelItemsItem = new ConfigItem() - .setName("&cCancel items") - .setLore(List.of("&cClick to cancel the items.")) - .setType(Material.RED_WOOL); + .setName("&cCancel items") + .setLore(List.of("&cClick to cancel the items.")) + .setType(Material.RED_WOOL); @Description({" ", "# The name of the parcel small content GUI"}) public String parcelSmallContentGuiTitle = "&aSmall parcel content"; diff --git a/src/main/java/com/eternalcode/parcellockers/deliverycode/DeliveryCode.java b/src/main/java/com/eternalcode/parcellockers/deliverycode/DeliveryCode.java index f5f6eb08..1a48abb9 100644 --- a/src/main/java/com/eternalcode/parcellockers/deliverycode/DeliveryCode.java +++ b/src/main/java/com/eternalcode/parcellockers/deliverycode/DeliveryCode.java @@ -3,4 +3,5 @@ import java.util.UUID; public record DeliveryCode(UUID parcelUUID, String code) { + } diff --git a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java index f58f2045..9b4ebc92 100644 --- a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java +++ b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java @@ -14,7 +14,7 @@ public class DeliveryCodeRepositoryImpl extends AbstractDatabaseService implements DeliveryCodeRepository { - private Map cache = new HashMap<>(); + private final Map cache = new HashMap<>(); protected DeliveryCodeRepositoryImpl(DataSource dataSource) { super(dataSource); @@ -24,10 +24,10 @@ protected DeliveryCodeRepositoryImpl(DataSource dataSource) { private void initTable() { this.executeSync("CREATE TABLE IF NOT EXISTS `delivery_codes`(" + - "`parcelUUID` VARCHAR(36) NOT NULL, " + - "`code` VARCHAR(6) NOT NULL, " + - "PRIMARY KEY (parcelUUID) " + - ");", PreparedStatement::execute); + "`parcelUUID` VARCHAR(36) NOT NULL, " + + "`code` VARCHAR(6) NOT NULL, " + + "PRIMARY KEY (parcelUUID) " + + ");", PreparedStatement::execute); } @Override @@ -51,13 +51,13 @@ public CompletableFuture findByUUID(UUID parcelUUID) { } this.cache.putIfAbsent(parcelUUID, new DeliveryCode( - UUID.fromString(rs.getString("parcelUUID")), - rs.getString("code") + UUID.fromString(rs.getString("parcelUUID")), + rs.getString("code") )); return new DeliveryCode( - UUID.fromString(rs.getString("parcelUUID")), - rs.getString("code") + UUID.fromString(rs.getString("parcelUUID")), + rs.getString("code") ); }); } diff --git a/src/main/java/com/eternalcode/parcellockers/locker/controller/LockerBreakController.java b/src/main/java/com/eternalcode/parcellockers/locker/controller/LockerBreakController.java index 0751c3a2..b607da2c 100644 --- a/src/main/java/com/eternalcode/parcellockers/locker/controller/LockerBreakController.java +++ b/src/main/java/com/eternalcode/parcellockers/locker/controller/LockerBreakController.java @@ -49,16 +49,16 @@ public void onBlockBreak(BlockBreakEvent event) { UUID toRemove = this.parcelLockerRepositoryImpl.positionCache().get(position); this.parcelLockerRepositoryImpl.remove(toRemove); - + this.announcer.sendMessage(player, this.messages.parcelLockerSuccessfullyDeleted); - + Formatter formatter = new Formatter() .register("{X}", position.x()) .register("{Y}", position.y()) .register("{Z}", position.z()) .register("{WORLD}", position.world()) .register("{PLAYER}", player.getName()); - + this.announcer.broadcast(formatter.format(this.messages.broadcastParcelLockerRemoved)); } @@ -69,7 +69,7 @@ public void onBlockBurn(BlockBurnEvent event) { Block block = event.getBlock(); Location location = block.getLocation(); Position position = PositionAdapter.convert(location); - + if (this.parcelLockerRepositoryImpl.isInCache(position)) { event.setCancelled(true); } @@ -80,7 +80,7 @@ public void onBlockExplode(BlockExplodeEvent event) { Block block = event.getBlock(); Location location = block.getLocation(); Position position = PositionAdapter.convert(location); - + if (this.parcelLockerRepositoryImpl.isInCache(position)) { event.setCancelled(true); } @@ -100,7 +100,7 @@ public void onBlockIgnite(BlockIgniteEvent event) { Block block = event.getBlock(); Location location = block.getLocation(); Position position = PositionAdapter.convert(location); - + if (this.parcelLockerRepositoryImpl.isInCache(position)) { event.setCancelled(true); } @@ -111,7 +111,7 @@ public void onBlockDamage(BlockDamageEvent event) { Block block = event.getBlock(); Location location = block.getLocation(); Position position = PositionAdapter.convert(location); - + if (this.parcelLockerRepositoryImpl.isInCache(position)) { event.setCancelled(true); } diff --git a/src/main/java/com/eternalcode/parcellockers/locker/controller/LockerInteractionController.java b/src/main/java/com/eternalcode/parcellockers/locker/controller/LockerInteractionController.java index f6e61461..e598b222 100644 --- a/src/main/java/com/eternalcode/parcellockers/locker/controller/LockerInteractionController.java +++ b/src/main/java/com/eternalcode/parcellockers/locker/controller/LockerInteractionController.java @@ -31,15 +31,15 @@ public LockerInteractionController(LockerRepositoryImpl parcelLockerRepositoryIm public void onInventoryOpen(PlayerInteractEvent event) { Player player = event.getPlayer(); Position blockPos = PositionAdapter.convert(player.getTargetBlock(Set.of(Material.AIR), 4).getLocation()); - + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { return; - } - - if (event.getClickedBlock().getType() != Material.CHEST) { - return; - } - + } + + if (event.getClickedBlock().getType() != Material.CHEST) { + return; + } + if (this.parcelLockerRepositoryImpl.isInCache(blockPos)) { event.setCancelled(true); new LockerMainGUI(this.miniMessage, this.config).show(player); diff --git a/src/main/java/com/eternalcode/parcellockers/locker/gui/LockerMainGUI.java b/src/main/java/com/eternalcode/parcellockers/locker/gui/LockerMainGUI.java index 1e1b8759..a26684c4 100644 --- a/src/main/java/com/eternalcode/parcellockers/locker/gui/LockerMainGUI.java +++ b/src/main/java/com/eternalcode/parcellockers/locker/gui/LockerMainGUI.java @@ -24,7 +24,7 @@ public LockerMainGUI(MiniMessage miniMessage, PluginConfiguration config) { @Override public void show(Player player) { Component guiTitle = this.miniMessage.deserialize(this.config.guiSettings.mainGuiTitle); - + Gui gui = Gui.gui() .title(RESET_ITEM.append(guiTitle)) .rows(6) diff --git a/src/main/java/com/eternalcode/parcellockers/locker/repository/LockerRepositoryImpl.java b/src/main/java/com/eternalcode/parcellockers/locker/repository/LockerRepositoryImpl.java index 06375f99..6b281773 100644 --- a/src/main/java/com/eternalcode/parcellockers/locker/repository/LockerRepositoryImpl.java +++ b/src/main/java/com/eternalcode/parcellockers/locker/repository/LockerRepositoryImpl.java @@ -35,11 +35,11 @@ public LockerRepositoryImpl(DataSource dataSource) { private void initTable() { this.executeSync("CREATE TABLE IF NOT EXISTS `lockers`(" + - "uuid VARCHAR(36) NOT NULL, " + - "description VARCHAR(64) NOT NULL, " + - "position VARCHAR(255) NOT NULL, " + - "PRIMARY KEY (uuid)" + - ");", PreparedStatement::execute); + "uuid VARCHAR(36) NOT NULL, " + + "description VARCHAR(64) NOT NULL, " + + "position VARCHAR(255) NOT NULL, " + + "PRIMARY KEY (uuid)" + + ");", PreparedStatement::execute); } @Override @@ -47,10 +47,10 @@ public CompletableFuture save(Locker locker) { return CompletableFuture.runAsync(() -> { try (Connection connection = this.dataSource.getConnection(); PreparedStatement statement = connection.prepareStatement( - "INSERT INTO `lockers`(`uuid`, " + - "`description`, " + - "`position`" + - ") VALUES(?, ?, ?);" + "INSERT INTO `lockers`(`uuid`, " + + "`description`, " + + "`position`" + + ") VALUES(?, ?, ?);" ) ) { statement.setString(1, locker.uuid().toString()); @@ -89,7 +89,7 @@ public CompletableFuture remove(UUID uuid) { return this.execute("DELETE FROM `lockers` WHERE `uuid` = ?;", statement -> { statement.setString(1, uuid.toString()); statement.execute(); - + this.removeFromCache(uuid); }); } @@ -104,7 +104,7 @@ public CompletableFuture findPage(Page page) { return this.supplyExecute("SELECT * FROM `lockers` LIMIT ? OFFSET ?;", statement -> { statement.setInt(1, page.getLimit() + 1); statement.setInt(2, page.getOffset()); - + List lockers = this.extractParcelLockers(statement); boolean hasNext = lockers.size() > page.getLimit(); @@ -130,7 +130,7 @@ private List extractParcelLockers(PreparedStatement statement) throws SQ } list.forEach(this::addToCache); - + return list; } @@ -188,7 +188,7 @@ private CompletableFuture> findBy(String column, String value) rs.getString("description"), Position.parse(rs.getString("position")) ); - + this.addToCache(locker); return Optional.of(locker); } diff --git a/src/main/java/com/eternalcode/parcellockers/notification/NotificationAnnouncer.java b/src/main/java/com/eternalcode/parcellockers/notification/NotificationAnnouncer.java index c8b1a879..98831e23 100644 --- a/src/main/java/com/eternalcode/parcellockers/notification/NotificationAnnouncer.java +++ b/src/main/java/com/eternalcode/parcellockers/notification/NotificationAnnouncer.java @@ -14,10 +14,10 @@ public class NotificationAnnouncer { private final static Map> NOTIFICATION_HANDLERS = Map.of( - NotificationType.CHAT, Audience::sendMessage, - NotificationType.ACTION_BAR, Audience::sendActionBar, - NotificationType.TITLE, (audience, component) -> audience.showTitle(Title.title(component, Component.empty())), - NotificationType.SUBTITLE, (audience, component) -> audience.showTitle(Title.title(Component.empty(), component)) + NotificationType.CHAT, Audience::sendMessage, + NotificationType.ACTION_BAR, Audience::sendActionBar, + NotificationType.TITLE, (audience, component) -> audience.showTitle(Title.title(component, Component.empty())), + NotificationType.SUBTITLE, (audience, component) -> audience.showTitle(Title.title(Component.empty(), component)) ); private final AudienceProvider audienceProvider; @@ -50,7 +50,7 @@ public void sendMessage(CommandSender commandSender, String text) { public void broadcast(String text) { Audience audience = this.audienceProvider.all(); Component message = this.miniMessage.deserialize(text); - + audience.sendMessage(message); } diff --git a/src/main/java/com/eternalcode/parcellockers/parcel/Parcel.java b/src/main/java/com/eternalcode/parcellockers/parcel/Parcel.java index aa825e6e..67beaa6f 100644 --- a/src/main/java/com/eternalcode/parcellockers/parcel/Parcel.java +++ b/src/main/java/com/eternalcode/parcellockers/parcel/Parcel.java @@ -4,7 +4,8 @@ import java.util.UUID; -public record Parcel(UUID uuid, UUID sender, String name, String description, boolean priority, Set recipients, UUID receiver, ParcelSize size, UUID entryLocker, UUID destinationLocker) { +public record Parcel(UUID uuid, UUID sender, String name, String description, boolean priority, Set recipients, + UUID receiver, ParcelSize size, UUID entryLocker, UUID destinationLocker) { public static Builder builder() { return new Builder(); diff --git a/src/main/java/com/eternalcode/parcellockers/parcel/command/argument/ParcelArgument.java b/src/main/java/com/eternalcode/parcellockers/parcel/command/argument/ParcelArgument.java index b8c28bab..0de84ee9 100644 --- a/src/main/java/com/eternalcode/parcellockers/parcel/command/argument/ParcelArgument.java +++ b/src/main/java/com/eternalcode/parcellockers/parcel/command/argument/ParcelArgument.java @@ -23,7 +23,7 @@ public ParcelArgument(ParcelRepositoryImpl cache) { @Override public Result parse(LiteInvocation invocation, String argument) { Parcel parcel = this.databaseService.findParcel(UUID.fromString(argument)).orElse(null); - + if (parcel == null) { return Result.error(); } @@ -33,8 +33,8 @@ public ParcelArgument(ParcelRepositoryImpl cache) { @Override public List suggest(LiteInvocation invocation) { return this.databaseService.cache().values().stream() - .map(Parcel::name) - .map(Suggestion::of) - .toList(); + .map(Parcel::name) + .map(Suggestion::of) + .toList(); } } diff --git a/src/main/java/com/eternalcode/parcellockers/parcel/gui/ParcelItemStorageGUI.java b/src/main/java/com/eternalcode/parcellockers/parcel/gui/ParcelItemStorageGUI.java index 29bf51b1..ae28b92f 100644 --- a/src/main/java/com/eternalcode/parcellockers/parcel/gui/ParcelItemStorageGUI.java +++ b/src/main/java/com/eternalcode/parcellockers/parcel/gui/ParcelItemStorageGUI.java @@ -24,7 +24,7 @@ public ParcelItemStorageGUI(PluginConfiguration config, MiniMessage miniMessage) void show(Player player, ParcelSize size) { PluginConfiguration.GuiSettings guiSettings = this.config.guiSettings; - + GuiItem backgroundItem = guiSettings.mainGuiBackgroundItem.toGuiItem(this.miniMessage); GuiItem confirmItem = guiSettings.confirmItemsItem.toGuiItem(this.miniMessage, event -> { this.confirmed = true; @@ -59,23 +59,23 @@ void show(Player player, ParcelSize size) { this.gui.setItem(this.gui.getRows(), 2, cancelItem); this.gui.setCloseGuiAction(event -> { if (this.confirmed) { - return; + return; } - + if (this.gui.getInventory().getContents() == null) { return; } - + for (ItemStack item : this.gui.getInventory().getContents()) { if (item == null) { continue; } - + player.getInventory().addItem(item); this.gui.removeItem(item); } }); - + this.gui.open(player); } } diff --git a/src/main/java/com/eternalcode/parcellockers/parcel/gui/ParcelListGUI.java b/src/main/java/com/eternalcode/parcellockers/parcel/gui/ParcelListGUI.java index 1ee1ea46..9bc5856a 100644 --- a/src/main/java/com/eternalcode/parcellockers/parcel/gui/ParcelListGUI.java +++ b/src/main/java/com/eternalcode/parcellockers/parcel/gui/ParcelListGUI.java @@ -58,7 +58,7 @@ private void show(Player player, Page page) { .disableAllInteractions() .rows(6) .create(); - + GuiItem parcelItem = this.config.guiSettings.parcelItem.toGuiItem(this.miniMessage); GuiItem backgroundItem = this.config.guiSettings.mainGuiBackgroundItem.toGuiItem(this.miniMessage); GuiItem cornerItem = this.config.guiSettings.cornerItem.toGuiItem(this.miniMessage); @@ -81,19 +81,19 @@ private void show(Player player, Page page) { for (Parcel parcel : result.parcels()) { if (!player.hasPermission("parcellockers.admin.debug.seeOthersParcels")) { - continue; + continue; } - + if (!parcel.sender().equals(player.getUniqueId())) { continue; } - + if (!parcel.recipients().contains(player.getUniqueId())) { continue; } ItemMeta parcelItemMeta = parcelItem.getItemStack().getItemMeta(); - + List newLore = this.replaceParcelPlaceholders(parcel, parcelItemMeta.getLore()); parcelItemMeta.setLore(newLore); diff --git a/src/main/java/com/eternalcode/parcellockers/parcel/gui/ParcelSendingGUI.java b/src/main/java/com/eternalcode/parcellockers/parcel/gui/ParcelSendingGUI.java index d31fdc18..066f0aed 100644 --- a/src/main/java/com/eternalcode/parcellockers/parcel/gui/ParcelSendingGUI.java +++ b/src/main/java/com/eternalcode/parcellockers/parcel/gui/ParcelSendingGUI.java @@ -82,7 +82,7 @@ public void show(Player player) { private void updateSmallButton(Gui gui, ConfigItem smallButton, ConfigItem mediumButton, ConfigItem largeButton) { this.size = ParcelSize.SMALL; - + gui.updateItem(20, smallButton.setGlow(true).toGuiItem(this.miniMessage)); gui.updateItem(22, mediumButton.setGlow(false).toGuiItem(this.miniMessage, e -> this.updateMediumButton(gui, smallButton, mediumButton, largeButton))); gui.updateItem(24, largeButton.setGlow(false).toGuiItem(this.miniMessage, e -> this.updateLargeButton(gui, smallButton, mediumButton, largeButton))); @@ -90,7 +90,7 @@ private void updateSmallButton(Gui gui, ConfigItem smallButton, ConfigItem mediu private void updateMediumButton(Gui gui, ConfigItem smallButton, ConfigItem mediumButton, ConfigItem largeButton) { this.size = ParcelSize.MEDIUM; - + gui.updateItem(20, smallButton.setGlow(false).toGuiItem(this.miniMessage, e -> this.updateSmallButton(gui, smallButton, mediumButton, largeButton))); gui.updateItem(22, mediumButton.setGlow(true).toGuiItem(this.miniMessage)); gui.updateItem(24, largeButton.setGlow(false).toGuiItem(this.miniMessage, e -> this.updateLargeButton(gui, smallButton, mediumButton, largeButton))); @@ -98,7 +98,7 @@ private void updateMediumButton(Gui gui, ConfigItem smallButton, ConfigItem medi private void updateLargeButton(Gui gui, ConfigItem smallButton, ConfigItem mediumButton, ConfigItem largeButton) { this.size = ParcelSize.LARGE; - + gui.updateItem(20, smallButton.setGlow(false).toGuiItem(this.miniMessage, e -> this.updateSmallButton(gui, smallButton, mediumButton, largeButton))); gui.updateItem(22, mediumButton.setGlow(false).toGuiItem(this.miniMessage, e -> this.updateMediumButton(gui, smallButton, mediumButton, largeButton))); gui.updateItem(24, largeButton.setGlow(true).toGuiItem(this.miniMessage)); diff --git a/src/main/java/com/eternalcode/parcellockers/parcel/repository/ParcelRepositoryImpl.java b/src/main/java/com/eternalcode/parcellockers/parcel/repository/ParcelRepositoryImpl.java index 3664e0cf..38ff4637 100644 --- a/src/main/java/com/eternalcode/parcellockers/parcel/repository/ParcelRepositoryImpl.java +++ b/src/main/java/com/eternalcode/parcellockers/parcel/repository/ParcelRepositoryImpl.java @@ -34,18 +34,18 @@ public ParcelRepositoryImpl(DataSource dataSource) { private void initTable() { try (Connection connection = this.dataSource.getConnection(); PreparedStatement statement = connection.prepareStatement( - "CREATE TABLE IF NOT EXISTS `parcels`(" + - "`uuid` VARCHAR(36) NOT NULL, " + - "`name` VARCHAR(24) NOT NULL, " + - "`description` VARCHAR(64), " + - "`priority` BOOLEAN NOT NULL, " + - "`receiver` VARCHAR(36) NOT NULL, " + - "`size` VARCHAR(10) NOT NULL, " + - "`entryLocker` VARCHAR(36) NOT NULL, " + - "`destinationLocker` VARCHAR(36) NOT NULL, " + - "`sender` VARCHAR(36) NOT NULL, " + - "PRIMARY KEY (uuid) " + - ");" + "CREATE TABLE IF NOT EXISTS `parcels`(" + + "`uuid` VARCHAR(36) NOT NULL, " + + "`name` VARCHAR(24) NOT NULL, " + + "`description` VARCHAR(64), " + + "`priority` BOOLEAN NOT NULL, " + + "`receiver` VARCHAR(36) NOT NULL, " + + "`size` VARCHAR(10) NOT NULL, " + + "`entryLocker` VARCHAR(36) NOT NULL, " + + "`destinationLocker` VARCHAR(36) NOT NULL, " + + "`sender` VARCHAR(36) NOT NULL, " + + "PRIMARY KEY (uuid) " + + ");" ) ) { statement.execute(); @@ -76,7 +76,7 @@ public CompletableFuture save(Parcel parcel) { statement.setString(8, parcel.destinationLocker().toString()); statement.setString(9, parcel.sender().toString()); statement.execute(); - + this.addParcelToCache(parcel); }); } @@ -103,7 +103,7 @@ public CompletableFuture update(Parcel newParcel) { statement.setString(8, newParcel.sender().toString()); statement.setString(9, newParcel.uuid().toString()); statement.execute(); - + this.addParcelToCache(newParcel); }); } @@ -115,9 +115,9 @@ public CompletableFuture> findByUUID(UUID uuid) { ResultSet rs = statement.executeQuery(); if (rs.next()) { Parcel parcel = this.createParcel(rs); - + this.addParcelToCache(parcel); - + return Optional.of(parcel); } return Optional.empty(); @@ -129,11 +129,11 @@ public CompletableFuture> findBySender(UUID sender) { return this.supplyExecute("SELECT * FROM `parcels` WHERE `sender` = ?", statement -> { statement.setString(1, sender.toString()); ResultSet rs = statement.executeQuery(); - + List parcels = new ArrayList<>(); while (rs.next()) { Parcel parcel = this.createParcel(rs); - + this.addParcelToCache(parcel); parcels.add(parcel); } @@ -146,7 +146,7 @@ public CompletableFuture> findByReceiver(UUID receiver) { return this.supplyExecute("SELECT * FROM `parcels` WHERE `receiver` = ?", statement -> { statement.setString(1, receiver.toString()); ResultSet rs = statement.executeQuery(); - + List parcels = new ArrayList<>(); while (rs.next()) { Parcel parcel = this.createParcel(rs); @@ -168,7 +168,7 @@ public CompletableFuture remove(UUID uuid) { return this.supplyExecute("DELETE FROM `parcels` WHERE `uuid` = ?", statement -> { statement.setString(1, uuid.toString()); statement.execute(); - + this.removeParcelFromCache(uuid); return null; }); @@ -180,7 +180,7 @@ public CompletableFuture findPage(Page page) { statement.setInt(1, page.getLimit() + 1); statement.setInt(2, page.getOffset()); ResultSet rs = statement.executeQuery(); - + List parcels = new ArrayList<>(); while (rs.next()) { Parcel parcel = this.createParcel(rs); @@ -198,16 +198,16 @@ public CompletableFuture findPage(Page page) { private Parcel createParcel(ResultSet rs) throws SQLException { return new Parcel( - UUID.fromString(rs.getString("uuid")), - UUID.fromString(rs.getString("sender")), - rs.getString("name"), - rs.getString("description"), - rs.getBoolean("priority"), - new HashSet<>(), - UUID.fromString(rs.getString("receiver")), - ParcelSize.valueOf(rs.getString("size")), - UUID.fromString(rs.getString("entryLocker")), - UUID.fromString(rs.getString("destinationLocker")) + UUID.fromString(rs.getString("uuid")), + UUID.fromString(rs.getString("sender")), + rs.getString("name"), + rs.getString("description"), + rs.getBoolean("priority"), + new HashSet<>(), + UUID.fromString(rs.getString("receiver")), + ParcelSize.valueOf(rs.getString("size")), + UUID.fromString(rs.getString("entryLocker")), + UUID.fromString(rs.getString("destinationLocker")) ); } diff --git a/src/main/java/com/eternalcode/parcellockers/shared/PositionAdapter.java b/src/main/java/com/eternalcode/parcellockers/shared/PositionAdapter.java index b3e393b5..b9c7c92e 100644 --- a/src/main/java/com/eternalcode/parcellockers/shared/PositionAdapter.java +++ b/src/main/java/com/eternalcode/parcellockers/shared/PositionAdapter.java @@ -6,7 +6,8 @@ public final class PositionAdapter { - private PositionAdapter() {} + private PositionAdapter() { + } public static Position convert(Location location) { if (location.getWorld() == null) { diff --git a/src/main/java/com/eternalcode/parcellockers/updater/UpdaterService.java b/src/main/java/com/eternalcode/parcellockers/updater/UpdaterService.java index 2654bd00..e724d6e6 100644 --- a/src/main/java/com/eternalcode/parcellockers/updater/UpdaterService.java +++ b/src/main/java/com/eternalcode/parcellockers/updater/UpdaterService.java @@ -10,6 +10,7 @@ import java.util.concurrent.CompletableFuture; public class UpdaterService { + private static final GitRepository GIT_REPOSITORY = GitRepository.of("EternalCodeTeam", "ParcelLockers"); private final GitCheck gitCheck = new GitCheck(); private final Lazy gitCheckResult; diff --git a/src/main/java/com/eternalcode/parcellockers/util/AdventureUtil.java b/src/main/java/com/eternalcode/parcellockers/util/AdventureUtil.java index 3a79f534..0775ceb7 100644 --- a/src/main/java/com/eternalcode/parcellockers/util/AdventureUtil.java +++ b/src/main/java/com/eternalcode/parcellockers/util/AdventureUtil.java @@ -6,8 +6,8 @@ public final class AdventureUtil { public static final Component RESET_ITEM = Component.text() - .decoration(TextDecoration.ITALIC, false) - .build(); + .decoration(TextDecoration.ITALIC, false) + .build(); private AdventureUtil() { throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); diff --git a/src/main/java/com/eternalcode/parcellockers/util/DurationUtil.java b/src/main/java/com/eternalcode/parcellockers/util/DurationUtil.java index c373db4f..c2c3b36a 100644 --- a/src/main/java/com/eternalcode/parcellockers/util/DurationUtil.java +++ b/src/main/java/com/eternalcode/parcellockers/util/DurationUtil.java @@ -18,8 +18,8 @@ public static String format(Duration duration, boolean removeMillis) { } return duration.toString() - .substring(2) - .replaceAll("(\\d[HMS])(?!$)", "$1 ") - .toLowerCase(); + .substring(2) + .replaceAll("(\\d[HMS])(?!$)", "$1 ") + .toLowerCase(); } } diff --git a/src/main/java/com/eternalcode/parcellockers/util/ItemUtil.java b/src/main/java/com/eternalcode/parcellockers/util/ItemUtil.java index 3b3bb877..10df35c4 100644 --- a/src/main/java/com/eternalcode/parcellockers/util/ItemUtil.java +++ b/src/main/java/com/eternalcode/parcellockers/util/ItemUtil.java @@ -17,7 +17,7 @@ public static boolean compareMeta(ItemStack first, ItemStack second) { if (firstMeta == null) { return false; } - + ItemMeta secondMeta = second.getItemMeta(); if (secondMeta == null) { return false; @@ -26,7 +26,7 @@ public static boolean compareMeta(ItemStack first, ItemStack second) { if (first.getType() != second.getType()) { return false; } - + return firstMeta.getLore().containsAll(secondMeta.getLore()) && firstMeta.getDisplayName().equals(secondMeta.getDisplayName()); } diff --git a/src/main/java/com/eternalcode/parcellockers/util/legacy/Legacy.java b/src/main/java/com/eternalcode/parcellockers/util/legacy/Legacy.java index b2d42f19..7ed719f8 100644 --- a/src/main/java/com/eternalcode/parcellockers/util/legacy/Legacy.java +++ b/src/main/java/com/eternalcode/parcellockers/util/legacy/Legacy.java @@ -6,10 +6,10 @@ public class Legacy { private static final LegacyComponentSerializer AMPERSAND_SERIALIZER = LegacyComponentSerializer.builder() - .character('&') - .hexColors() - .useUnusualXRepeatedCharacterHexFormat() - .build(); + .character('&') + .hexColors() + .useUnusualXRepeatedCharacterHexFormat() + .build(); public static Component component(String text) { return AMPERSAND_SERIALIZER.deserialize(text); diff --git a/src/main/java/com/eternalcode/parcellockers/util/legacy/LegacyColorProcessor.java b/src/main/java/com/eternalcode/parcellockers/util/legacy/LegacyColorProcessor.java index 6a00b1c2..f86aa087 100644 --- a/src/main/java/com/eternalcode/parcellockers/util/legacy/LegacyColorProcessor.java +++ b/src/main/java/com/eternalcode/parcellockers/util/legacy/LegacyColorProcessor.java @@ -10,6 +10,6 @@ public class LegacyColorProcessor implements UnaryOperator { @Override public Component apply(Component component) { return component.replaceText(builder -> builder.match(Pattern.compile(".*")) - .replacement((matchResult, builder1) -> Legacy.component(matchResult.group()))); + .replacement((matchResult, builder1) -> Legacy.component(matchResult.group()))); } } From c4cd56e5b135ee8431574cb22ff9d219a685bf43 Mon Sep 17 00:00:00 2001 From: Jakubk15 <77227023+Jakubk15@users.noreply.github.com> Date: Sun, 15 Oct 2023 11:21:40 +0200 Subject: [PATCH 05/15] Fix build --- src/main/java/com/eternalcode/parcellockers/ParcelLockers.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/eternalcode/parcellockers/ParcelLockers.java b/src/main/java/com/eternalcode/parcellockers/ParcelLockers.java index 36203bdc..95a1bae2 100644 --- a/src/main/java/com/eternalcode/parcellockers/ParcelLockers.java +++ b/src/main/java/com/eternalcode/parcellockers/ParcelLockers.java @@ -89,7 +89,7 @@ public void onEnable() { ParcelRepositoryImpl parcelRepository = new ParcelRepositoryImpl(dataSource); ParcelManager parcelManager = new ParcelManager(config, announcer, parcelRepository); - LockerManager lockerManager = new LockerManager(parcelLockerRepositoryImpl); + LockerManager lockerManager = new LockerManager(lockerRepositoryImpl); MainGUI mainGUI = new MainGUI(this, server, miniMessage, config, parcelRepository, lockerRepositoryImpl); ParcelListGUI parcelListGUI = new ParcelListGUI(this, server, miniMessage, config, parcelRepository, lockerRepositoryImpl, mainGUI); From 339200e5aec38392bd3814618129ae9504eb6986 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 21 Oct 2023 13:13:05 +0000 Subject: [PATCH 06/15] Update all dependencies --- build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5aeda679..b292bdfc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -26,7 +26,7 @@ repositories { dependencies { // minecraft development api - compileOnly("org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT") + compileOnly("org.spigotmc:spigot-api:1.20.2-experimental-SNAPSHOT") implementation("net.kyori:adventure-platform-bukkit:4.3.1") implementation("net.kyori:adventure-text-minimessage:4.14.0") implementation("dev.rollczi.litecommands:bukkit-adventure:2.8.9") @@ -51,7 +51,7 @@ dependencies { // metrics and sentry implementation("org.bstats:bstats-bukkit:3.0.2") - implementation("io.sentry:sentry:6.31.0") + implementation("io.sentry:sentry:6.32.0") // database implementation("com.zaxxer:HikariCP:5.0.1") From 6ab80e0b82c62612523b4e398da930b96f24924b Mon Sep 17 00:00:00 2001 From: Jakubk15 <77227023+Jakubk15@users.noreply.github.com> Date: Sat, 21 Oct 2023 21:31:44 +0200 Subject: [PATCH 07/15] Bump dependencies, fix build --- .../java/com/eternalcode/parcellockers/ParcelLockers.java | 1 + .../locker/controller/LockerInteractionController.java | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/eternalcode/parcellockers/ParcelLockers.java b/src/main/java/com/eternalcode/parcellockers/ParcelLockers.java index 95a1bae2..e8fd99b8 100644 --- a/src/main/java/com/eternalcode/parcellockers/ParcelLockers.java +++ b/src/main/java/com/eternalcode/parcellockers/ParcelLockers.java @@ -6,6 +6,7 @@ import com.eternalcode.parcellockers.configuration.ConfigurationManager; import com.eternalcode.parcellockers.configuration.implementation.PluginConfiguration; import com.eternalcode.parcellockers.database.DataSourceFactory; +import com.eternalcode.parcellockers.locker.LockerManager; import com.eternalcode.parcellockers.locker.controller.LockerBreakController; import com.eternalcode.parcellockers.locker.controller.LockerInteractionController; import com.eternalcode.parcellockers.locker.controller.LockerPlaceController; diff --git a/src/main/java/com/eternalcode/parcellockers/locker/controller/LockerInteractionController.java b/src/main/java/com/eternalcode/parcellockers/locker/controller/LockerInteractionController.java index e598b222..674eb980 100644 --- a/src/main/java/com/eternalcode/parcellockers/locker/controller/LockerInteractionController.java +++ b/src/main/java/com/eternalcode/parcellockers/locker/controller/LockerInteractionController.java @@ -6,7 +6,7 @@ import com.eternalcode.parcellockers.shared.Position; import com.eternalcode.parcellockers.shared.PositionAdapter; import net.kyori.adventure.text.minimessage.MiniMessage; -import org.bukkit.Material; +import org.bukkit.block.BlockType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -30,13 +30,13 @@ public LockerInteractionController(LockerRepositoryImpl parcelLockerRepositoryIm @EventHandler public void onInventoryOpen(PlayerInteractEvent event) { Player player = event.getPlayer(); - Position blockPos = PositionAdapter.convert(player.getTargetBlock(Set.of(Material.AIR), 4).getLocation()); + Position blockPos = PositionAdapter.convert(player.getTargetBlock(Set.of(BlockType.AIR), 4).getLocation()); if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { return; } - if (event.getClickedBlock().getType() != Material.CHEST) { + if (event.getClickedBlock().getType() != BlockType.CHEST) { return; } From 7b1770c985fbe9b1322c833cc7f843ce4d351906 Mon Sep 17 00:00:00 2001 From: Jakubk15 <77227023+Jakubk15@users.noreply.github.com> Date: Sun, 22 Oct 2023 13:45:44 +0200 Subject: [PATCH 08/15] Don't use experimental spigot-api --- build.gradle.kts | 2 +- .../locker/controller/LockerInteractionController.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b292bdfc..183052f7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -26,7 +26,7 @@ repositories { dependencies { // minecraft development api - compileOnly("org.spigotmc:spigot-api:1.20.2-experimental-SNAPSHOT") + compileOnly("org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT") implementation("net.kyori:adventure-platform-bukkit:4.3.1") implementation("net.kyori:adventure-text-minimessage:4.14.0") implementation("dev.rollczi.litecommands:bukkit-adventure:2.8.9") diff --git a/src/main/java/com/eternalcode/parcellockers/locker/controller/LockerInteractionController.java b/src/main/java/com/eternalcode/parcellockers/locker/controller/LockerInteractionController.java index 674eb980..e598b222 100644 --- a/src/main/java/com/eternalcode/parcellockers/locker/controller/LockerInteractionController.java +++ b/src/main/java/com/eternalcode/parcellockers/locker/controller/LockerInteractionController.java @@ -6,7 +6,7 @@ import com.eternalcode.parcellockers.shared.Position; import com.eternalcode.parcellockers.shared.PositionAdapter; import net.kyori.adventure.text.minimessage.MiniMessage; -import org.bukkit.block.BlockType; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -30,13 +30,13 @@ public LockerInteractionController(LockerRepositoryImpl parcelLockerRepositoryIm @EventHandler public void onInventoryOpen(PlayerInteractEvent event) { Player player = event.getPlayer(); - Position blockPos = PositionAdapter.convert(player.getTargetBlock(Set.of(BlockType.AIR), 4).getLocation()); + Position blockPos = PositionAdapter.convert(player.getTargetBlock(Set.of(Material.AIR), 4).getLocation()); if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { return; } - if (event.getClickedBlock().getType() != BlockType.CHEST) { + if (event.getClickedBlock().getType() != Material.CHEST) { return; } From eb726dbdf18648d45b8714a2c9549546a9601297 Mon Sep 17 00:00:00 2001 From: Jakubk15 <77227023+Jakubk15@users.noreply.github.com> Date: Sun, 22 Oct 2023 14:00:10 +0200 Subject: [PATCH 09/15] Update src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java Co-authored-by: DMK <81445555+imDMK@users.noreply.github.com> --- .../repository/DeliveryCodeRepositoryImpl.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java index 9b4ebc92..559681dd 100644 --- a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java +++ b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java @@ -50,15 +50,11 @@ public CompletableFuture findByUUID(UUID parcelUUID) { return null; } - this.cache.putIfAbsent(parcelUUID, new DeliveryCode( - UUID.fromString(rs.getString("parcelUUID")), - rs.getString("code") - )); - - return new DeliveryCode( - UUID.fromString(rs.getString("parcelUUID")), - rs.getString("code") - ); + DeliveryCode deliveryCode = new DeliveryCode(UUID.fromString(rs.getString("parcelUUID")), rs.getString("code")); + + this.cache.putIfAbsent(parcelUUID, deliveryCode); + + return Optional.of(deliveryCode); }); } From 51c21dc4d72451494fdd073f3ac2efaba3eadcc3 Mon Sep 17 00:00:00 2001 From: Jakubk15 <77227023+Jakubk15@users.noreply.github.com> Date: Sun, 22 Oct 2023 14:00:29 +0200 Subject: [PATCH 10/15] Update src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java Co-authored-by: DMK <81445555+imDMK@users.noreply.github.com> --- .../deliverycode/repository/DeliveryCodeRepositoryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java index 559681dd..0ba610f1 100644 --- a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java +++ b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java @@ -41,7 +41,7 @@ public CompletableFuture save(DeliveryCode deliveryCode) { } @Override - public CompletableFuture findByUUID(UUID parcelUUID) { + public CompletableFuture> findByUUID(UUID parcelUUID) { return this.supplyExecute("SELECT * FROM `delivery_codes` WHERE `parcelUUID` = ?;", statement -> { statement.setString(1, parcelUUID.toString()); ResultSet rs = statement.executeQuery(); From 420e4907016276f633598f03c2c1273c832a5601 Mon Sep 17 00:00:00 2001 From: Jakubk15 <77227023+Jakubk15@users.noreply.github.com> Date: Sun, 22 Oct 2023 14:00:34 +0200 Subject: [PATCH 11/15] Update src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java Co-authored-by: DMK <81445555+imDMK@users.noreply.github.com> --- .../repository/DeliveryCodeRepositoryImpl.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java index 0ba610f1..02e57871 100644 --- a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java +++ b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java @@ -74,9 +74,11 @@ public CompletableFuture remove(UUID parcelUUID) { } public Optional find(UUID parcelUUID) { - if (this.cache.get(parcelUUID) != null) { - return Optional.of(this.cache.get(parcelUUID)); - } - return Optional.ofNullable(this.findByUUID(parcelUUID).join()); + Optional deliveryCodeOptional = Optional.ofNullable(this.cache.get(parcelUUID)); + if (deliveryCodeOptional.isPresent()) { + return deliveryCodeOptional; + } + + return this.findByUUID(parcelUUID).join(); } } From 745de679fc7da8f0dfce708f8c6cbc40fb515413 Mon Sep 17 00:00:00 2001 From: Jakubk15 <77227023+Jakubk15@users.noreply.github.com> Date: Sun, 22 Oct 2023 14:00:38 +0200 Subject: [PATCH 12/15] Update src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java Co-authored-by: DMK <81445555+imDMK@users.noreply.github.com> --- .../deliverycode/repository/DeliveryCodeRepositoryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java index 02e57871..5b32584b 100644 --- a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java +++ b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java @@ -47,7 +47,7 @@ public CompletableFuture> findByUUID(UUID parcelUUID) { ResultSet rs = statement.executeQuery(); if (!rs.next()) { - return null; + return Optional.empty(); } DeliveryCode deliveryCode = new DeliveryCode(UUID.fromString(rs.getString("parcelUUID")), rs.getString("code")); From af611fe5824ec293f3c5fc85d0d699366842b6d9 Mon Sep 17 00:00:00 2001 From: Jakubk15 <77227023+Jakubk15@users.noreply.github.com> Date: Sun, 22 Oct 2023 14:02:25 +0200 Subject: [PATCH 13/15] Fix whitespaces --- .../repository/DeliveryCodeRepositoryImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java index 5b32584b..6998cb9c 100644 --- a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java +++ b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java @@ -51,10 +51,10 @@ public CompletableFuture> findByUUID(UUID parcelUUID) { } DeliveryCode deliveryCode = new DeliveryCode(UUID.fromString(rs.getString("parcelUUID")), rs.getString("code")); - - this.cache.putIfAbsent(parcelUUID, deliveryCode); - - return Optional.of(deliveryCode); + + this.cache.putIfAbsent(parcelUUID, deliveryCode); + + return Optional.of(deliveryCode); }); } From c9eac0b09b98e3e8668ed9627c6e8cfbdfbb5ac8 Mon Sep 17 00:00:00 2001 From: Jakubk15 <77227023+Jakubk15@users.noreply.github.com> Date: Sun, 22 Oct 2023 22:06:15 +0200 Subject: [PATCH 14/15] Apply PR suggestions --- .../deliverycode/repository/DeliveryCodeRepository.java | 3 ++- .../deliverycode/repository/DeliveryCodeRepositoryImpl.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepository.java b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepository.java index e2384be2..100351db 100644 --- a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepository.java +++ b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepository.java @@ -2,6 +2,7 @@ import com.eternalcode.parcellockers.deliverycode.DeliveryCode; +import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -9,7 +10,7 @@ public interface DeliveryCodeRepository { CompletableFuture save(DeliveryCode deliveryCode); - CompletableFuture findByUUID(UUID parcelUUID); + CompletableFuture> findByUUID(UUID parcelUUID); CompletableFuture remove(DeliveryCode deliveryCode); diff --git a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java index 6998cb9c..e7d2ab0c 100644 --- a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java +++ b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java @@ -76,7 +76,7 @@ public CompletableFuture remove(UUID parcelUUID) { public Optional find(UUID parcelUUID) { Optional deliveryCodeOptional = Optional.ofNullable(this.cache.get(parcelUUID)); if (deliveryCodeOptional.isPresent()) { - return deliveryCodeOptional; + return Optional.ofNullable(this.cache.get(parcelUUID)).or(() -> this.findByUUID(parcelUUID).join()); } return this.findByUUID(parcelUUID).join(); From 8ad6647ce057c511338cc9069923b301a4baef6d Mon Sep 17 00:00:00 2001 From: Jakubk15 <77227023+Jakubk15@users.noreply.github.com> Date: Sun, 22 Oct 2023 22:30:56 +0200 Subject: [PATCH 15/15] Update DeliveryCodeRepositoryImpl.java Co-authored-by: DMK <81445555+imDMK@users.noreply.github.com> --- .../repository/DeliveryCodeRepositoryImpl.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java index e7d2ab0c..130a5fdb 100644 --- a/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java +++ b/src/main/java/com/eternalcode/parcellockers/deliverycode/repository/DeliveryCodeRepositoryImpl.java @@ -74,11 +74,7 @@ public CompletableFuture remove(UUID parcelUUID) { } public Optional find(UUID parcelUUID) { - Optional deliveryCodeOptional = Optional.ofNullable(this.cache.get(parcelUUID)); - if (deliveryCodeOptional.isPresent()) { - return Optional.ofNullable(this.cache.get(parcelUUID)).or(() -> this.findByUUID(parcelUUID).join()); - } - - return this.findByUUID(parcelUUID).join(); + return Optional.ofNullable(this.cache.get(parcelUUID)) + .or(() -> this.findByUUID(parcelUUID).join()); } }