Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
More bugs!
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniFoldi committed Jan 21, 2022
1 parent bf52bf1 commit 3a710ec
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group 'com.danifoldi'
version '2.4.0'
version '2.4.1'
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16

Expand Down
48 changes: 46 additions & 2 deletions src/main/java/com/danifoldi/protogui/main/GuiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,17 @@ Map<Integer, GuiItem> loadItemMap(Config guiItems, int size) {
}

Map<Integer, GuiItem> loadItemMap(Config guiItems, int size, Map<Integer, GuiItem> fallback) {
Map<Integer, GuiItem> itemMap = loadItemMap(guiItems, size);
Map<Integer, GuiItem> itemMap = new ConcurrentHashMap<>();

for (final @NotNull Config.Entry guiItem : guiItems.entrySet()) {
final @NotNull Set<Integer> slots = SlotUtil.getSlots(guiItem.getKey(), SlotUtil.getInventorySize(SlotUtil.getInventoryType(size)));
final @NotNull Config itemData = guiItem.getValue();

for (final int slot : slots) {
GuiItem item = loadItem(itemData, fallback.get(slot));
itemMap.put(slot, item.copy());
}
}

fallback.forEach(itemMap::putIfAbsent);

Expand Down Expand Up @@ -228,6 +238,19 @@ GuiSound loadClickSound(Config item) {
return clickSound;
}

GuiSound loadClickSound(Config item, GuiSound fallback) {
if (item.contains("clickSound")) {
return GuiSound.builder()
.soundName(item.getOrElse("clickSound.sound", fallback.getSoundName()))
.soundCategory(item.getEnumOrElse("clickSound.soundCategory", fallback.getSoundCategory(), EnumGetMethod.NAME_IGNORECASE))
.volume(item.getOrElse("clickSound.volume", fallback.getVolume()))
.pitch(item.getOrElse("clickSound.pitch", fallback.getPitch()))
.build();
} else {
return fallback;
}
}

GuiItem loadItem(Config item) {
return GuiItem.builder()
.type(item.getEnumOrElse("type", ItemType.STONE, EnumGetMethod.NAME_IGNORECASE))
Expand All @@ -245,6 +268,27 @@ GuiItem loadItem(Config item) {
.build();
}

GuiItem loadItem(Config item, GuiItem fallback) {
if (fallback == null) {
return loadItem(item);
}

return GuiItem.builder()
.type(item.getEnumOrElse("type", fallback.getType(), EnumGetMethod.NAME_IGNORECASE))
.amount(item.getOrElse("count", fallback.getAmount()))
.title(item.getOrElse("name", fallback.getName()))
.lore(item.getOrElse("lore", fallback.getLore()))
.data(item.getOrElse("data", fallback.getData()))
.commands(item.getOrElse("commands", fallback.getCommands()))
.rightCommands(item.getOrElse("rightCommands", fallback.getRightCommands()))
.leftCommands(item.getOrElse("leftCommands", fallback.getLeftCommands()))
.enchanted(item.getOrElse("enchanted", fallback.isEnchanted()))
.clickSound(loadClickSound(item, fallback.getClickSound()))
.clickableIf(item.getOrElse("clickableIf", fallback.getClickableIf()))
.shownIf(item.getOrElse("shownIf", fallback.getShownIf()))
.build();
}

GuiAction loadAction(Config action) {
return GuiAction.builder()
.server(action.getOrElse("server", ""))
Expand Down Expand Up @@ -402,7 +446,7 @@ void runCommand(final @NotNull UUID uuid, final @NotNull GuiGrid openGui, final
PlatformInteraction.ProtoPlayer player = ProtoGuiAPI.getInstance().getPlatform().getPlayer(uuid);

if (commandData.getFirst().equalsIgnoreCase("console")) {
ProtoGuiAPI.getInstance().getPlatform().runConsoleCommand(Message.replace(command, Pair.of("player", player.name()), Pair.of("target", target)));
ProtoGuiAPI.getInstance().getPlatform().runConsoleCommand(Message.replace(commandData.getSecond(), Pair.of("player", player.name()), Pair.of("target", target)));
continue;
}

Expand Down

0 comments on commit 3a710ec

Please sign in to comment.