Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-110 Add parcel receiving logic #118

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f24c5c5
Remove recipients field from Parcel object. Convert GuiView to interface
Jakubk15 Feb 5, 2025
bc1f26a
Create ParcelCollectionGui. Simplify unit test. Add more config entries.
Jakubk15 Feb 5, 2025
44e65d7
Remove builder() method from Parcel
Jakubk15 Feb 5, 2025
d121759
Fix test
Jakubk15 Feb 5, 2025
9cda801
Exclude gson from relocation. Enable auto-relocation
Jakubk15 Feb 8, 2025
3982f80
Move checkstyle config to gradle/
Jakubk15 Feb 8, 2025
853ec0e
Rename ExceptionHandler to SentryExceptionHandler
Jakubk15 Feb 8, 2025
d39695b
Add ParcelManager#collectParcel method
Jakubk15 Feb 8, 2025
893132e
Fix relocation. Add Blossom replacement tokens
Jakubk15 Feb 8, 2025
c6c3262
Update src/main/java/com/eternalcode/parcellockers/gui/implementation…
Jakubk15 Feb 8, 2025
965fc3e
Remove checkstyle
Jakubk15 Feb 8, 2025
c0951e4
Merge remote-tracking branch 'origin/receiving-logic' into receiving-…
Jakubk15 Feb 8, 2025
2b3dde9
Implement removeAll() methods. Add DebugCommand. Fix ParcelCollectionGui
Jakubk15 Feb 8, 2025
42817d9
Implement parcel collection logic, minor code improvements
Jakubk15 Feb 15, 2025
4def015
Improve pagination logic
Jakubk15 Feb 15, 2025
fd01b8a
Update src/main/java/com/eternalcode/parcellockers/command/debug/Debu…
Jakubk15 Feb 15, 2025
2c63ae7
Update src/main/java/com/eternalcode/parcellockers/gui/implementation…
Jakubk15 Feb 15, 2025
ce8c10f
Merge remote-tracking branch 'origin/receiving-logic' into receiving-…
Jakubk15 Feb 15, 2025
8c5d200
Unify repository method naming
Jakubk15 Feb 15, 2025
a42e565
Fix build. Improve run-task tasks
Jakubk15 Feb 15, 2025
5b92da4
Fix CompletionException. Improve DebugCommand
Jakubk15 Feb 15, 2025
91387c7
apply coderabbit suggestion
Jakubk15 Feb 15, 2025
9d0b2cc
Fix items shift. Give items synchronously. migrate to commons ItemUti…
Jakubk15 Feb 15, 2025
85d9997
remove todo
Jakubk15 Feb 15, 2025
16d7cb6
Correct version in gradle
Jakubk15 Feb 15, 2025
932cd53
Update src/main/java/com/eternalcode/parcellockers/parcel/ParcelManag…
Jakubk15 Feb 16, 2025
2092096
Update src/main/java/com/eternalcode/parcellockers/command/debug/Debu…
Jakubk15 Feb 16, 2025
6c4bcf5
Update src/main/java/com/eternalcode/parcellockers/command/debug/Debu…
Jakubk15 Feb 16, 2025
693d1c9
Update src/main/java/com/eternalcode/parcellockers/command/debug/Debu…
Jakubk15 Feb 16, 2025
acf44b9
Update src/main/java/com/eternalcode/parcellockers/command/debug/Debu…
Jakubk15 Feb 16, 2025
26fdfd2
Update src/main/java/com/eternalcode/parcellockers/command/debug/Debu…
Jakubk15 Feb 16, 2025
993df00
Update src/main/java/com/eternalcode/parcellockers/command/debug/Debu…
Jakubk15 Feb 16, 2025
2c58d76
Reformat code, do not use * imports
Jakubk15 Feb 16, 2025
92993ca
Merge branch 'receiving-logic' of https://github.com/EternalCodeTeam/…
Jakubk15 Feb 16, 2025
89441b1
Import necessary classes
Jakubk15 Feb 16, 2025
2553e7a
Do not create instance of ParcelCollectionGui every time.
Jakubk15 Feb 16, 2025
9806ceb
Update src/main/java/com/eternalcode/parcellockers/configuration/impl…
Jakubk15 Feb 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
id("xyz.jpenilla.run-paper") version "2.3.1"
id("com.gradleup.shadow") version "8.3.5"
id("net.kyori.blossom") version "2.1.0"
}

group = "com.eternalcode"
Expand Down Expand Up @@ -103,7 +104,7 @@ java {
checkstyle {
toolVersion = "10.21.1"

configFile = file("${rootDir}/config/checkstyle/checkstyle.xml")
configFile = file("${rootDir}/gradle/checkstyle/checkstyle.xml")

maxErrors = 0
maxWarnings = 0
Expand All @@ -115,10 +116,9 @@ bukkit {
prefix = "ParcelLockers"
author = "EternalCodeTeam"
name = "ParcelLockers"
description =
"Plugin that provides functionality of parcel lockers in Minecraft, allowing players to send and receive parcels safely."
description = "Plugin that provides functionality of parcel lockers in Minecraft, allowing players to send and receive parcels safely."
website = "https://github.com/EternalCodeTeam/ParcelLockers"
version = "1.0.0-SNAPSHOT"
version = "0.0.1-SNAPSHOT"
}

tasks.withType<JavaCompile> {
Expand All @@ -128,6 +128,14 @@ tasks.withType<JavaCompile> {
options.release = 21
}

sourceSets.main {
blossom.javaSources {
property("@NAME@", project.name)
property("@VERSION@", project.version.toString())
property("@DEVELOPER_MODE@", System.getenv("DEVELOPER_MODE") ?: "false")
}
}

tasks {
runServer {
minecraftVersion("1.21.4")
Expand All @@ -145,25 +153,37 @@ tasks {
"org/jetbrains/annotations/**",
"META-INF/**",
"javax/**",
"javassist/**",
"org/h2/util/**"
)

mergeServiceFiles()
minimize {
exclude(dependency("de\\.rapha149\\.signgui:signgui:.*")) // https://github.com/Rapha149/SignGUI/issues/15
}

val prefix = "com.eternalcode.parcellockers.libs"
val relocationPrefix = "com.eternalcode.parcellockers.libs"
listOf(
"panda",
"org.panda_lang",
"net.dzikoysk",
"io.papermc.lib",
"org.bstats",
"dev.rollczi",
"net.kyori",
"org.json",
"org.postgresql",
"net.dzikoysk",
"net.kyori",
"io.papermc",
"io.sentry",
"dev.rollczi",
"de.eldoria",
"com.eternalcode.commons",
"com.eternalcode.gitcheck",
"com.fasterxml",
"de.rapha149"
).forEach { relocate(it, prefix) }
"com.j256",
"com.spotify",
"com.zaxxer",
"de.rapha149",
"dev.triumphteam"
).forEach { relocate(it, "$relocationPrefix.$it") }
}
}


File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/eternalcode/parcellockers/ParcelLockers.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import com.eternalcode.parcellockers.content.repository.ParcelContentRepository;
import com.eternalcode.parcellockers.content.repository.ParcelContentRepositoryOrmLite;
import com.eternalcode.parcellockers.database.DatabaseManager;
import com.eternalcode.parcellockers.gui.implementation.locker.LockerMainGUI;
import com.eternalcode.parcellockers.gui.implementation.remote.MainGUI;
import com.eternalcode.parcellockers.gui.implementation.remote.ParcelListGUI;
import com.eternalcode.parcellockers.gui.implementation.locker.LockerMainGui;
import com.eternalcode.parcellockers.gui.implementation.remote.MainGui;
import com.eternalcode.parcellockers.gui.implementation.remote.ParcelListGui;
import com.eternalcode.parcellockers.itemstorage.repository.ItemStorageRepository;
import com.eternalcode.parcellockers.itemstorage.repository.ItemStorageRepositoryOrmLite;
import com.eternalcode.parcellockers.locker.Locker;
Expand Down Expand Up @@ -138,17 +138,17 @@ public void onEnable() {
ParcelRepositoryOrmLite parcelRepository = new ParcelRepositoryOrmLite(databaseManager, scheduler, parcelCache);
parcelRepository.updateCaches();

ParcelManager parcelManager = new ParcelManager(config, announcer, parcelRepository);
ParcelContentRepository parcelContentRepository = new ParcelContentRepositoryOrmLite(databaseManager, scheduler);
ParcelManager parcelManager = new ParcelManager(config, announcer, parcelRepository, parcelContentRepository);

ItemStorageRepository itemStorageRepository = new ItemStorageRepositoryOrmLite(databaseManager, scheduler);

UserRepository userRepository = new UserRepositoryOrmLite(databaseManager, scheduler);
UserManager userManager = new UserManager(userRepository);

ParcelContentRepository parcelContentRepository = new ParcelContentRepositoryOrmLite(databaseManager, scheduler);

MainGUI mainGUI = new MainGUI(this, server, miniMessage, config, parcelRepository, lockerRepository, userManager);
ParcelListGUI parcelListGUI = new ParcelListGUI(this, server, miniMessage, config, parcelRepository, lockerRepository, userManager, mainGUI);
MainGui mainGUI = new MainGui(this, server, miniMessage, config, parcelRepository, lockerRepository, userManager);
ParcelListGui parcelListGUI = new ParcelListGui(this, server, miniMessage, config, parcelRepository, lockerRepository, userManager, mainGUI);

this.liteCommands = LiteBukkitFactory.builder("parcellockers", this)
.argument(Parcel.class, new ParcelArgument(parcelCache))
Expand All @@ -169,7 +169,7 @@ public void onEnable() {
return;
}*/

LockerMainGUI lockerMainGUI = new LockerMainGUI(this, miniMessage, config, itemStorageRepository, parcelRepository, lockerRepository, announcer, parcelContentRepository, userRepository, this.skullAPI);
LockerMainGui lockerMainGUI = new LockerMainGui(this, miniMessage, config, itemStorageRepository, parcelRepository, lockerRepository, announcer, parcelContentRepository, userRepository, this.skullAPI);

Stream.of(
new LockerInteractionController(lockerCache, lockerMainGUI),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public static class Messages {
public String parcelDestinationSet = "&2✔ &aParcel destination locker set successfully.";
public String alreadyCreatingLocker = "&4✘ &cYou are already creating a parcel locker!";
public String receiverNotSet = "&4✘ &cThe parcel receiver is not set!";
public String parcelSuccessfullyCollected = "&2✔ &aParcel collected successfully.";
public String failedToCollectParcel = "&4✘ &cAn error occurred while collecting the parcel.";
public String notEnoughInventorySpace = "&4✘ &cYou don't have enough space in your inventory to collect the parcel!";

@Description({ " ", "# The parcel info message." })
public List<String> parcelInfoMessages = List.of(
Expand All @@ -119,8 +122,7 @@ public static class Messages {
"&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}"
"&6Description: &e{DESCRIPTION}"
);
}

Expand All @@ -142,6 +144,9 @@ public static class GuiSettings {
@Description({ " ", "# The item of the parcel recipient pick GUI" })
public String parcelReceiverSelectionGuiTitle = "&5Select recipient";

@Description({ " ", "# The item of the parcel collection GUI" })
public String parcelCollectionGuiTitle = "&aCollect parcels";

@Description({ " ", "# The item of the small parcel size button" })
public ConfigItem smallParcelSizeItem = new ConfigItem()
.setName("&a✧ Small")
Expand Down Expand Up @@ -269,8 +274,7 @@ public static class GuiSettings {
"&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}"
"&6Description: &e{DESCRIPTION}"
)
)
.setType(Material.CHEST_MINECART);
Expand Down Expand Up @@ -378,5 +382,23 @@ public static class GuiSettings {
Material.SPAWNER,
Material.BEDROCK
);

@Description({ " ", "# The item of the parcel item in the collection GUI" })
public ConfigItem parcelCollectionItem = new ConfigItem()
.setName("&a{NAME}")
.setLore(List.of(
"&6UUID: &e{UUID}",
"&6Sender: &e{SENDER}",
"&6Size: &e{SIZE}",
"&6Description: &e{DESCRIPTION}"
)
)
.setType(Material.CHEST_MINECART);

@Description({ " ", "# The item that is displayed in the collection GUI when no parcels are found" })
public ConfigItem noParcelsItem = new ConfigItem()
.setName("&cNo parcels found")
.setLore(List.of("&cYou don't have any parcels to collect."))
.setType(Material.BARRIER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.sql.SQLException;
import java.util.List;

@SuppressWarnings("unchecked")
public class ItemStackPersister extends BaseDataType {

private static final ItemStackPersister instance = new ItemStackPersister();
Expand All @@ -39,8 +40,7 @@ public Object javaToSqlArg(FieldType fieldType, Object javaObject) {

try {
return JSON.writeValueAsString(stacks);
}
catch (JsonProcessingException e) {
} catch (JsonProcessingException e) {
Sentry.captureException(e);
throw new ParcelLockersException("Failed to serialize itemstacks", e);
}
Expand All @@ -62,8 +62,7 @@ public Object sqlArgToJava(FieldType fieldType, Object sqlArg, int columnPos) {

try {
return JSON.readValue(string, JSON.getTypeFactory().constructCollectionType(List.class, ItemStack.class));
}
catch (JsonProcessingException exception) {
} catch (JsonProcessingException exception) {
Sentry.captureException(exception);
throw new ParcelLockersException("Failed to deserialize itemstacks", exception);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.eternalcode.commons.scheduler.Scheduler;
import com.eternalcode.parcellockers.database.DatabaseManager;
import com.j256.ormlite.dao.Dao;
import io.sentry.Sentry;
import panda.std.function.ThrowingFunction;

import java.sql.SQLException;
Expand Down Expand Up @@ -61,9 +60,7 @@ protected <T, ID, R> CompletableFuture<R> action(Class<T> type, ThrowingFunction

try {
completableFuture.complete(action.apply(dao));
}
catch (Throwable throwable) {
Sentry.captureException(throwable);
} catch (Throwable throwable) {
completableFuture.completeExceptionally(throwable);
throwable.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@


// TODO INTERFACE
public abstract class GuiView {
public interface GuiView {

public static final int[] CORNER_SLOTS = { 0, 8, 45, 53 };
public static final int[] BORDER_SLOTS = { 1, 2, 3, 4, 5, 6, 7, 9, 17, 18, 26, 27, 35, 36, 44, 46, 47, 48, 49, 50, 51, 52 };
int[] CORNER_SLOTS = { 0, 8, 45, 53 };
int[] BORDER_SLOTS = { 1, 2, 3, 4, 5, 6, 7, 9, 17, 18, 26, 27, 35, 36, 44, 46, 47, 48, 49, 50, 51, 52 };

public abstract void show(Player player);
void show(Player player);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.eternalcode.parcellockers.locker.Locker;
import com.eternalcode.parcellockers.locker.repository.LockerPageResult;
import com.eternalcode.parcellockers.locker.repository.LockerRepository;
import com.eternalcode.parcellockers.shared.ExceptionHandler;
import com.eternalcode.parcellockers.shared.Page;
import com.eternalcode.parcellockers.shared.SentryExceptionHandler;
import dev.triumphteam.gui.guis.Gui;
import dev.triumphteam.gui.guis.GuiItem;
import dev.triumphteam.gui.guis.PaginatedGui;
Expand All @@ -22,7 +22,7 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

public class DestinationSelectionGUI extends GuiView {
public class DestinationSelectionGui implements GuiView {

private static final int WIDTH = 7;
private static final int HEIGHT = 4;
Expand All @@ -33,10 +33,10 @@ public class DestinationSelectionGUI extends GuiView {
private final PluginConfiguration config;
private final MiniMessage miniMessage;
private final LockerRepository lockerRepository;
private final ParcelSendingGUI sendingGUI;
private final ParcelSendingGUIState state;
private final ParcelSendingGui sendingGUI;
private final ParcelSendingGuiState state;

public DestinationSelectionGUI(Plugin plugin, BukkitScheduler scheduler, PluginConfiguration config, MiniMessage miniMessage, LockerRepository lockerRepository, ParcelSendingGUI sendingGUI, ParcelSendingGUIState state) {
public DestinationSelectionGui(Plugin plugin, BukkitScheduler scheduler, PluginConfiguration config, MiniMessage miniMessage, LockerRepository lockerRepository, ParcelSendingGui sendingGUI, ParcelSendingGuiState state) {
this.plugin = plugin;
this.scheduler = scheduler;
this.config = config;
Expand Down Expand Up @@ -76,17 +76,17 @@ private void show(Player player, Page page) {
gui.setItem(49, closeItem);

this.lockerRepository.findPage(page).thenAccept(result -> {
if (result.hasNextPage()) {
gui.setItem(51, nextPageItem);
}
if (result.hasNextPage()) {
gui.setItem(51, nextPageItem);
}

if (page.hasPrevious()) {
gui.setItem(47, previousPageItem);
}
if (page.hasPrevious()) {
gui.setItem(47, previousPageItem);
}

this.loadLockers(player, result, refresher).forEach(refresher::addItem);
this.scheduler.runTask(this.plugin, () -> gui.open(player));
}).whenComplete(ExceptionHandler.handler())
this.loadLockers(player, result, refresher).forEach(refresher::addItem);
this.scheduler.runTask(this.plugin, () -> gui.open(player));
}).whenComplete(SentryExceptionHandler.handler())
.orTimeout(5, TimeUnit.SECONDS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import static com.eternalcode.commons.adventure.AdventureUtil.resetItalic;

public class LockerMainGUI extends GuiView {
public class LockerMainGui implements GuiView {

private final Plugin plugin;
private final MiniMessage miniMessage;
Expand All @@ -31,7 +31,7 @@ public class LockerMainGUI extends GuiView {
private final UserRepository userRepository;
private final SkullAPI skullAPI;

public LockerMainGUI(Plugin plugin,
public LockerMainGui(Plugin plugin,
MiniMessage miniMessage,
PluginConfiguration config,
ItemStorageRepository itemStorageRepository,
Expand Down Expand Up @@ -66,7 +66,7 @@ public void show(Player player) {
GuiItem cornerItem = this.config.guiSettings.cornerItem.toGuiItem();
GuiItem closeItem = this.config.guiSettings.closeItem.toGuiItem(event -> gui.close(player));

gui.setDefaultClickAction(event -> event.setCancelled(true));
//gui.setDefaultClickAction(event -> event.setCancelled(true));

for (int slot : CORNER_SLOTS) {
gui.setItem(slot, cornerItem);
Expand All @@ -76,8 +76,14 @@ public void show(Player player) {
gui.setItem(slot, backgroundItem);
}

gui.setItem(20, this.config.guiSettings.parcelLockerCollectItem.toGuiItem(event -> event.setCancelled(true)));
gui.setItem(22, this.config.guiSettings.parcelLockerSendItem.toGuiItem(event -> new ParcelSendingGUI(this.plugin,
gui.setItem(20, this.config.guiSettings.parcelLockerCollectItem.toGuiItem(event -> new ParcelCollectionGui(this.plugin,
this.config,
this.plugin.getServer().getScheduler(),
this.parcelRepository,
this.miniMessage
).show(player)));

gui.setItem(22, this.config.guiSettings.parcelLockerSendItem.toGuiItem(event -> new ParcelSendingGui(this.plugin,
this.config,
this.miniMessage,
this.itemStorageRepository,
Expand All @@ -87,7 +93,7 @@ public void show(Player player) {
this.parcelContentRepository,
this.userRepository,
this.skullAPI,
new ParcelSendingGUIState()
new ParcelSendingGuiState()
).show(player)));

gui.setItem(24, this.config.guiSettings.parcelLockerStatusItem.toGuiItem());
Expand Down
Loading