Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ paper {

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.setIncremental(true)
options.isIncremental = true
options.compilerArgs.add("-parameters")
options.release = 21
}
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/com/eternalcode/parcellockers/ParcelLockers.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.eternalcode.parcellockers.locker.validation.LockerValidationService;
import com.eternalcode.parcellockers.locker.validation.LockerValidator;
import com.eternalcode.parcellockers.notification.NoticeService;
import com.eternalcode.parcellockers.parcel.ParcelDispatchService;
import com.eternalcode.parcellockers.parcel.ParcelService;
import com.eternalcode.parcellockers.parcel.ParcelServiceImpl;
import com.eternalcode.parcellockers.parcel.ParcelStatus;
Expand Down Expand Up @@ -137,18 +138,24 @@ public void onEnable() {
ItemStorageManager itemStorageManager = new ItemStorageManager(itemStorageRepository);
DeliveryManager deliveryManager = new DeliveryManager(deliveryRepository);

ParcelDispatchService parcelDispatchService = new ParcelDispatchService(
lockerManager,
parcelService,
deliveryManager,
itemStorageManager,
scheduler,
config,
noticeService
);

// guis
TriumphGui.init(this);
GuiManager guiManager = new GuiManager(
config,
scheduler,
noticeService,
parcelService,
lockerManager,
userManager,
itemStorageManager,
parcelContentManager,
deliveryManager
parcelDispatchService
);

MainGui mainGUI = new MainGui(
Expand Down Expand Up @@ -183,7 +190,7 @@ public void onEnable() {

Stream.of(
new LockerInteractionController(lockerManager, lockerGUI),
new LockerPlaceController(config, this, lockerManager, noticeService),
new LockerPlaceController(config, messageConfig, miniMessage, lockerManager, noticeService),
new LockerBreakController(lockerManager, noticeService, scheduler),
new PrepareUserController(userManager),
new LoadUserController(userManager, server)
Expand Down Expand Up @@ -231,5 +238,3 @@ private boolean setupEconomy() {
return this.economy != null;
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ void reload(@Sender CommandSender sender) {

@Execute(name = "get")
void get(@Sender Player player) {
ItemStack lockerItem = this.config.settings.parcelLockerItem.toGuiItem().getItemStack();
ItemStack lockerItem = this.config.settings.parcelLockerItem.toRawItemStack();
player.getInventory().addItem(lockerItem);
this.noticeService.player(player.getUniqueId(), messages -> messages.locker.addedToInventory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,20 @@ void deleteAll(@Sender CommandSender sender) {
@Execute(name = "getrandomitem")
void getRandomItem(@Sender Player player, @Arg int stacks) {
if (stacks <= 0 || stacks > 36) {
this.noticeService.create()
.notice(Notice.chat("&cInvalid number of stacks. Must be between 1 and 36."))
.player(player.getUniqueId())
.send();
this.noticeService.player(player.getUniqueId(), messages -> Notice.chat("&cInvalid number of stacks. Must be between 1 and 36."));
return;
}

List<Material> itemMaterials = Arrays.stream(Material.values()).filter(Material::isItem).toList();

if (itemMaterials.isEmpty()) {
this.noticeService.create()
.notice(Notice.chat("&cNo valid item materials found."))
.player(player.getUniqueId())
.send();
if (itemMaterials.isEmpty()) { // should never happen
this.noticeService.player(player.getUniqueId(), messages -> Notice.chat("&cNo valid item materials found."));
return;
}

Random random = ThreadLocalRandom.current();

// give player random items
// Give player random items
for (int i = 0; i < stacks; i++) {
Material randomMaterial = itemMaterials.get(random.nextInt(itemMaterials.size()));
int randomAmount = Math.min(random.nextInt(64) + 1, randomMaterial.getMaxStackSize());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,19 @@ public static class ParcelMessages extends OkaeriConfig {
.chat("&2✔ &aParcel sent successfully.")
.sound(Sound.ENTITY_ITEM_PICKUP.key())
.build();

public Notice cannotSend = Notice.builder()
.chat("&4✘ &cAn error occurred while sending the parcel. Check the console for more information.")
.sound(Sound.ENTITY_VILLAGER_NO.key())
.build();
public Notice emptyName = Notice.builder()
public Notice nameCannotBeEmpty = Notice.builder()
.chat("&4✘ &cThe parcel name cannot be empty!")
.sound(Sound.ENTITY_VILLAGER_NO.key())
.build();
public Notice nameSet = Notice.builder()
.chat("&2✔ &aParcel name set successfully.")
.sound(Sound.ENTITY_EXPERIENCE_ORB_PICKUP.key())
.build();
public Notice empty = Notice.builder()
public Notice cannotBeEmpty = Notice.builder()
.chat("&4✘ &cThe parcel cannot be empty!")
.sound(Sound.ENTITY_ENDERMAN_AMBIENT.key())
.build();
Expand Down Expand Up @@ -145,10 +144,7 @@ public static class LockerMessages extends OkaeriConfig {
.chat("&2✔ &aParcel locker created successfully.")
.sound(Sound.BLOCK_ANVIL_USE.key())
.build();
public Notice descriptionPrompt = Notice.builder()
.chat("&6\uD83D\uDDC8 &eEnter a name for the parcel locker:")
.sound(Sound.BLOCK_NOTE_BLOCK_PLING.key())
.build();
public String descriptionPrompt = "&6Enter a name for the parcel locker:";
public Notice cannotBreak = Notice.builder()
.chat("&4✘ &cYou have no permission to break the parcel locker.")
.sound(Sound.ENTITY_VILLAGER_NO.key())
Expand All @@ -162,6 +158,10 @@ public static class LockerMessages extends OkaeriConfig {
.chat("&4✘ &cYou are already creating a parcel locker!")
.sound(Sound.ENTITY_VILLAGER_NO.key())
.build();
public Notice addedToInventory = Notice.builder()
.chat("&2✔ &aParcel locker item added to your inventory.")
.sound(Sound.ENTITY_ITEM_PICKUP.key())
.build();
}

public static class AdminMessages extends OkaeriConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.ApiStatus;

@Getter
@Setter
Expand Down Expand Up @@ -56,6 +57,28 @@ public ItemStack toItemStack() {
return this.toBuilder().build();
}

/**
* By default, ConfigItem#toItemStack adds a "parcellockers-mfgui" value to the item's PersistentDataContainer
* to identify it as a GUI item.
* This method, on the other hand creates a raw ItemStack without that extra data.
*/

@ApiStatus.Internal
public ItemStack toRawItemStack() {
ItemStack itemStack = new ItemStack(this.type);
itemStack.editMeta(meta -> {
meta.displayName(resetItalic(MINI_MESSAGE.deserialize(this.name)));
meta.lore(this.lore.stream()
.map(element -> resetItalic(MINI_MESSAGE.deserialize(element)))
.toList());
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
if (this.glow) {
meta.setEnchantmentGlintOverride(true);
}
});
return itemStack;
}

@Override
public ConfigItem clone() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public ParcelContent create(UUID parcel, List<ItemStack> items) {
return content;
}

public CompletableFuture<Void> delete(UUID parcel) {
public CompletableFuture<Boolean> delete(UUID parcel) {
return this.contentRepository.delete(parcel).thenApply(i -> {
this.cache.invalidate(parcel);
return null;
return i > 0;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.eternalcode.parcellockers.content.ParcelContent;
import com.eternalcode.parcellockers.database.DatabaseManager;
import com.eternalcode.parcellockers.database.wrapper.AbstractRepositoryOrmLite;
import com.eternalcode.parcellockers.shared.ParcelLockersException;
import com.eternalcode.parcellockers.shared.exception.DatabaseException;
import com.j256.ormlite.table.TableUtils;
import java.sql.SQLException;
import java.util.Optional;
Expand All @@ -19,7 +19,7 @@ public ParcelContentRepositoryOrmLite(DatabaseManager databaseManager, Scheduler
try {
TableUtils.createTableIfNotExists(databaseManager.connectionSource(), ParcelContentTable.class);
} catch (SQLException exception) {
throw new ParcelLockersException("Failed to create ParcelContent table", exception);
throw new DatabaseException("Failed to create ParcelContent table", exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.eternalcode.parcellockers.database;

import com.eternalcode.parcellockers.configuration.implementation.PluginConfig;
import com.eternalcode.parcellockers.shared.exception.DatabaseException;
import com.google.common.base.Stopwatch;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DaoManager;
Expand Down Expand Up @@ -106,7 +107,7 @@ public <T, ID> Dao<T, ID> getDao(Class<T> type) {

return (Dao<T, ID>) dao;
} catch (SQLException exception) {
throw new RuntimeException(exception);
throw new DatabaseException("Failed to get DAO for type: " + type.getSimpleName(), exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.eternalcode.parcellockers.database.persister;

import com.eternalcode.parcellockers.shared.ParcelLockersException;
import com.eternalcode.parcellockers.shared.exception.DatabaseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
Expand Down Expand Up @@ -39,7 +39,7 @@ public Object javaToSqlArg(FieldType fieldType, Object javaObject) {
try {
return JSON.writeValueAsString(stacks);
} catch (JsonProcessingException e) {
throw new ParcelLockersException("Failed to serialize itemstacks", e);
throw new DatabaseException("Failed to serialize itemstacks", e);
}
}

Expand All @@ -60,7 +60,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) {
throw new ParcelLockersException("Failed to deserialize itemstacks", exception);
throw new DatabaseException("Failed to deserialize itemstacks", exception);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
import com.eternalcode.commons.ThrowingFunction;
import com.eternalcode.commons.scheduler.Scheduler;
import com.eternalcode.parcellockers.database.DatabaseManager;
import com.eternalcode.parcellockers.shared.exception.DatabaseException;
import com.j256.ormlite.dao.Dao;
import java.sql.SQLException;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
import java.util.logging.Logger;

public abstract class AbstractRepositoryOrmLite {

private static final Logger LOGGER = Logger.getLogger(AbstractRepositoryOrmLite.class.getName());

protected final DatabaseManager databaseManager;
protected final Scheduler scheduler;

Expand Down Expand Up @@ -59,9 +64,16 @@ protected <T, ID, R> CompletableFuture<R> action(Class<T> type, ThrowingFunction

try {
completableFuture.complete(action.apply(dao));
} catch (SQLException sqlException) {
DatabaseException databaseException = new DatabaseException(
"Database operation failed for type: " + type.getSimpleName(),
sqlException
);
LOGGER.log(Level.SEVERE, "Database operation failed", databaseException);
completableFuture.completeExceptionally(databaseException);
} catch (Throwable throwable) {
LOGGER.log(Level.SEVERE, "Unexpected error during database operation", throwable);
completableFuture.completeExceptionally(throwable);
throwable.printStackTrace();
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public Delivery create(UUID parcel, Instant deliveryTimestamp) {
return delivery;
}

public CompletableFuture<Void> delete(UUID parcel) {
public CompletableFuture<Boolean> delete(UUID parcel) {
return this.deliveryRepository.delete(parcel).thenApply(i -> {
this.deliveryCache.invalidate(parcel);
return null;
return i > 0;
});
}

Expand Down
Loading