Skip to content

Commit 2c91e9b

Browse files
authored
Merge branch 'master' into qodana-automation-460659264
2 parents 45ee7f8 + 712eac1 commit 2c91e9b

26 files changed

+78
-197
lines changed

Diff for: .github/workflows/build.yml

Whitespace-only changes.

Diff for: abstraction/src/main/java/com/loohp/multichatdiscordsrvaddon/config/Config.java

+6-11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import lombok.Getter;
66
import lombok.NoArgsConstructor;
77
import lombok.Setter;
8+
import me.lucko.helper.internal.LoaderUtils;
89
import org.bukkit.Bukkit;
910
import org.bukkit.Material;
1011
import org.bukkit.inventory.ItemStack;
@@ -26,8 +27,6 @@ public class Config {
2627
.build();
2728

2829
private static Config instance;
29-
@Setter
30-
private static File cachedDataFolder;
3130

3231
public record EmbedDisplay(
3332
String single,
@@ -750,20 +749,16 @@ public record Debug(
750749
@Comment("\nDebug configurations (useful for bug diagnosis)")
751750
Debug debug = new Debug(false, false);
752751

753-
static {
754-
cachedDataFolder = Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("MultiChatDiscordSrvAddon")).getDataFolder();
755-
}
756-
757752
public static Config i() {
758-
return Objects.requireNonNullElseGet(instance, () -> YamlConfigurations.update(new File(cachedDataFolder, "config.yml").toPath(), Config.class, properties));
753+
if (instance != null) return instance;
754+
return instance = YamlConfigurations.update(new File(LoaderUtils.getPlugin().getDataFolder(), "config.yml").toPath(), Config.class, properties);
759755
}
760756

761757
public void saveConfig() {
762-
YamlConfigurations.save(new File(cachedDataFolder, "config.yml").toPath(), Config.class, this, properties);
758+
YamlConfigurations.save(new File(LoaderUtils.getPlugin().getDataFolder(), "config.yml").toPath(), Config.class, this, properties);
763759
}
764760

765-
public void reload(File dataFolder) {
766-
cachedDataFolder = dataFolder;
767-
instance = YamlConfigurations.load(new File(dataFolder, "config.yml").toPath(), Config.class, properties);
761+
public void reload() {
762+
instance = YamlConfigurations.load(new File(LoaderUtils.getPlugin().getDataFolder(), "config.yml").toPath(), Config.class, properties);
768763
}
769764
}

Diff for: abstraction/src/main/java/com/loohp/multichatdiscordsrvaddon/objectholders/PaintingVariant.java

+10-44
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,22 @@
2020

2121
package com.loohp.multichatdiscordsrvaddon.objectholders;
2222

23+
import lombok.Getter;
2324
import net.kyori.adventure.key.Key;
2425
import net.kyori.adventure.text.Component;
2526
import net.kyori.adventure.text.format.NamedTextColor;
2627

2728
import java.util.Optional;
2829

30+
@Getter
2931
public class PaintingVariant {
3032

31-
private static Optional<Component> getLegacyPaintingTitle(Key key) {
32-
return Optional.of(Component.translatable("painting." + key.namespace() + "." + key.value() + ".title").color(NamedTextColor.YELLOW));
33+
private static Component getLegacyPaintingTitle(Key key) {
34+
return Component.translatable("painting." + key.namespace() + "." + key.value() + ".title").color(NamedTextColor.YELLOW);
3335
}
3436

35-
private static Optional<Component> getLegacyPaintingAuthor(Key key) {
36-
return Optional.of(Component.translatable("painting." + key.namespace() + "." + key.value() + ".author").color(NamedTextColor.GRAY));
37+
private static Component getLegacyPaintingAuthor(Key key) {
38+
return Component.translatable("painting." + key.namespace() + "." + key.value() + ".author").color(NamedTextColor.GRAY);
3739
}
3840

3941
private final Key key;
@@ -42,10 +44,10 @@ private static Optional<Component> getLegacyPaintingAuthor(Key key) {
4244
private final int blockWidth;
4345
private final int blockHeight;
4446

45-
private final Optional<Component> title;
46-
private final Optional<Component> author;
47+
private final Component title;
48+
private final Component author;
4749

48-
public PaintingVariant(Key key, int offsetX, int offsetY, int blockWidth, int blockHeight, Optional<Component> title, Optional<Component> author) {
50+
public PaintingVariant(Key key, int offsetX, int offsetY, int blockWidth, int blockHeight, Component title, Component author) {
4951
this.key = key;
5052
this.offsetX = offsetX;
5153
this.offsetY = offsetY;
@@ -55,7 +57,7 @@ public PaintingVariant(Key key, int offsetX, int offsetY, int blockWidth, int bl
5557
this.author = author;
5658
}
5759

58-
public PaintingVariant(Key key, int blockWidth, int blockHeight, Optional<Component> title, Optional<Component> author) {
60+
public PaintingVariant(Key key, int blockWidth, int blockHeight, Component title, Component author) {
5961
this(key, 0, 0, blockWidth, blockHeight, title, author);
6062
}
6163

@@ -66,40 +68,4 @@ public PaintingVariant(Key key, int offsetX, int offsetY, int blockWidth, int bl
6668
public PaintingVariant(Key key, int blockWidth, int blockHeight) {
6769
this(key, blockWidth, blockHeight, getLegacyPaintingTitle(key), getLegacyPaintingAuthor(key));
6870
}
69-
70-
public Key getKey() {
71-
return key;
72-
}
73-
74-
public int getOffsetX() {
75-
return offsetX;
76-
}
77-
78-
public int getOffsetY() {
79-
return offsetY;
80-
}
81-
82-
public int getPixelWidth() {
83-
return blockWidth * 16;
84-
}
85-
86-
public int getPixelHeight() {
87-
return blockHeight * 16;
88-
}
89-
90-
public int getBlockWidth() {
91-
return blockWidth;
92-
}
93-
94-
public int getBlockHeight() {
95-
return blockHeight;
96-
}
97-
98-
public Optional<Component> getTitle() {
99-
return title;
100-
}
101-
102-
public Optional<Component> getAuthor() {
103-
return author;
104-
}
10571
}

Diff for: common/src/main/java/com/loohp/multichatdiscordsrvaddon/MultiChatDiscordSrvAddon.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import com.loohp.multichatdiscordsrvaddon.integration.IntegrationManager;
2828
import com.loohp.multichatdiscordsrvaddon.objectholders.*;
2929
import com.loohp.multichatdiscordsrvaddon.registry.MultiChatRegistry;
30-
import com.loohp.multichatdiscordsrvaddon.utils.MCVersion;
31-
import com.loohp.multichatdiscordsrvaddon.utils.VersionManager;
3230
import com.loohp.multichatdiscordsrvaddon.utils.*;
3331
import me.lucko.helper.plugin.ExtendedJavaPlugin;
3432
import net.kyori.adventure.text.Component;
@@ -196,8 +194,6 @@ public void enable() {
196194

197195
AssetsDownloader.loadLibraries(getDataFolder());
198196

199-
Config.setCachedDataFolder(getDataFolder());
200-
201197
long itemDisplayTimeout = Config.i().getSettings().timeout() * 60L * 1000L;
202198
itemDisplay = new ConcurrentCacheHashMap<>(itemDisplayTimeout, 60000);
203199
inventoryDisplay = new ConcurrentCacheHashMap<>(itemDisplayTimeout, 60000);
@@ -317,11 +313,11 @@ private void cachePlayerSkin(OfflinePlayer player) {
317313
@Override
318314
public void disable() {
319315
DiscordInteractionEvents.unregisterAll();
320-
modelRenderer.close();
321-
mediaReadingService.shutdown();
322-
if (resourceManager != null) {
323-
resourceManager.close();
324-
}
316+
317+
if (modelRenderer != null) modelRenderer.close();
318+
if (mediaReadingService != null) mediaReadingService.shutdown();
319+
if (resourceManager != null) resourceManager.close();
320+
325321
ChatUtils.sendMessage("<red>MultiChat DiscordSRV Addon has been disabled.", Bukkit.getConsoleSender());
326322
}
327323

Diff for: common/src/main/java/com/loohp/multichatdiscordsrvaddon/api/events/GameMessageProcessItemEvent.java

+7-11
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
package com.loohp.multichatdiscordsrvaddon.api.events;
2222

23+
import lombok.Getter;
24+
import lombok.Setter;
2325
import net.kyori.adventure.text.Component;
2426
import org.bukkit.OfflinePlayer;
2527
import org.bukkit.inventory.Inventory;
@@ -36,15 +38,17 @@
3638
*
3739
* @author LOOHP
3840
*/
41+
@Getter
42+
@Setter
3943
public class GameMessageProcessItemEvent extends GameMessageProcessEvent {
4044

4145
private ItemStack itemstack;
42-
private Optional<Inventory> inventory;
46+
private Inventory inventory;
4347

4448
public GameMessageProcessItemEvent(OfflinePlayer sender, String title, Component component, boolean cancel, int processId, ItemStack itemstack, Inventory inventory) {
4549
super(sender, title, component, cancel, processId);
4650
this.itemstack = itemstack;
47-
this.inventory = Optional.ofNullable(inventory);
51+
this.inventory = inventory;
4852
}
4953

5054
public GameMessageProcessItemEvent(OfflinePlayer sender, String title, Component component, boolean cancel, int processId, ItemStack itemstack) {
@@ -60,15 +64,7 @@ public void setItemStack(ItemStack itemstack) {
6064
}
6165

6266
public boolean hasInventory() {
63-
return inventory.isPresent();
64-
}
65-
66-
public Inventory getInventory() {
67-
return inventory.orElse(null);
68-
}
69-
70-
public void setInventory(Inventory inventory) {
71-
this.inventory = Optional.ofNullable(inventory);
67+
return inventory != null;
7268
}
7369

7470
}

Diff for: common/src/main/java/com/loohp/multichatdiscordsrvaddon/command/CommandHandler.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313

1414
public class CommandHandler {
1515

16-
private final LegacyPaperCommandManager<CommandSender> manager;
1716
private final AnnotationParser<CommandSender> parser;
1817

1918
public CommandHandler() {
20-
this.manager = LegacyPaperCommandManager.createNative(
19+
LegacyPaperCommandManager<CommandSender> manager = LegacyPaperCommandManager.createNative(
2120
MultiChatDiscordSrvAddon.plugin,
2221
ExecutionCoordinator.asyncCoordinator()
2322
);
@@ -27,10 +26,10 @@ public CommandHandler() {
2726
// Natively, brigadier is non-blocking (async) and therefore there is no need to register async completions.
2827
// This is a simple elif statement to check if the server supports brigadier, and if it does, register it, which will support non-blocking completions.
2928
// If not, check if the server can support asynchronous completions, and if it does, register it.
30-
if (this.manager.hasCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER)) {
31-
this.manager.registerBrigadier();
32-
} else if (this.manager.hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) {
33-
this.manager.registerAsynchronousCompletions();
29+
if (manager.hasCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER)) {
30+
manager.registerBrigadier();
31+
} else if (manager.hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) {
32+
manager.registerAsynchronousCompletions();
3433
}
3534

3635
this.parser = new AnnotationParser<>(

Diff for: common/src/main/java/com/loohp/multichatdiscordsrvaddon/main/BlockModelRenderer.java

-5
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ public class BlockModelRenderer extends JFrame {
130130
public static final Pattern COLOR_HEX_PATTERN = Pattern.compile("^#[0-9a-fA-F]{6}$");
131131

132132
private String title;
133-
private BufferedImage image;
134-
private Icon icon;
135133

136134
private JTextField textFieldResourceKey;
137135
private JSpinner spinnerWidth;
@@ -180,8 +178,6 @@ public class BlockModelRenderer extends JFrame {
180178

181179
public BlockModelRenderer(String title, BufferedImage image, Icon icon) throws IllegalAccessException {
182180
this.title = title;
183-
this.image = image;
184-
this.icon = icon;
185181
this.resourceManager = null;
186182
$$$setupUI$$$();
187183
this.modelRenderer = new ModelRenderer(() -> 8, () -> (int) spinnerThreads.getValue());
@@ -570,7 +566,6 @@ public void loadResources() {
570566

571567
List<String> resourceOrder;
572568
int valuePerPack;
573-
Config.setCachedDataFolder(Paths.get("MultiChatDiscordSrvAddon").toFile());
574569
resourceOrder = Config.i().getResources().order();
575570
Collections.reverse(resourceOrder);
576571
valuePerPack = (int) ((1.0 / (double) (resourceOrder.size() + 1)) * 10000);

Diff for: common/src/main/java/com/loohp/multichatdiscordsrvaddon/main/MinecraftFontRenderer.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ public class MinecraftFontRenderer extends JFrame {
113113
private static final URLClassLoaderAccess LOADER_ACCESS = URLClassLoaderAccess.create((URLClassLoader) GUIMain.class.getClassLoader());
114114

115115
private String title;
116-
private BufferedImage image;
117-
private Icon icon;
118116

119117
private JTextArea textAreaInput;
120118
private JTextArea textAreaResources;
@@ -129,7 +127,6 @@ public class MinecraftFontRenderer extends JFrame {
129127
private JTextField backgroundColorTextField;
130128
private JComboBox<LanguageData> comboBoxLanguages;
131129
private JButton buttonDownloadLanguages;
132-
private JScrollPane scrollPaneTextInput;
133130
private JCheckBox glowingTextBox;
134131
private JSpinner defaultPackVersionSpinner;
135132

@@ -147,8 +144,6 @@ public class MinecraftFontRenderer extends JFrame {
147144

148145
public MinecraftFontRenderer(String title, BufferedImage image, Icon icon) {
149146
this.title = title;
150-
this.image = image;
151-
this.icon = icon;
152147
this.resourceManager = null;
153148
this.renderedImage = new AtomicReference<>();
154149
this.renderingComponents = new AtomicReference<>();
@@ -716,7 +711,7 @@ private List<LanguageData> getAllLanguageData(LanguageManager languageManager) {
716711
buttonDownloadLanguages = new JButton();
717712
buttonDownloadLanguages.setText("Download All Languages");
718713
panel.add(buttonDownloadLanguages, new GridConstraints(4, 8, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
719-
scrollPaneTextInput = new JScrollPane();
714+
JScrollPane scrollPaneTextInput = new JScrollPane();
720715
panel.add(scrollPaneTextInput, new GridConstraints(1, 0, 3, 14, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
721716
textAreaInput = new JTextArea();
722717
textAreaInput.setColumns(0);

Diff for: common/src/main/java/com/loohp/multichatdiscordsrvaddon/objectholders/CharacterData.java

+3-16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package com.loohp.multichatdiscordsrvaddon.objectholders;
2222

23+
import lombok.Getter;
2324
import net.kyori.adventure.key.Key;
2425
import net.kyori.adventure.text.Component;
2526
import net.kyori.adventure.text.TextComponent;
@@ -41,6 +42,8 @@
4142
import java.util.function.UnaryOperator;
4243
import java.util.stream.Collectors;
4344

45+
@Getter
46+
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
4447
public class CharacterData {
4548

4649
public static ValuePairs<String, List<CharObjectPair<CharacterData>>> fromComponent(Component component, UnaryOperator<String> shaper) {
@@ -107,20 +110,4 @@ public CharacterData(Key font, int color, OptionalInt shadowColor, List<TextDeco
107110
this.decorations = decorations;
108111
}
109112

110-
public Key getFont() {
111-
return font;
112-
}
113-
114-
public int getColor() {
115-
return color;
116-
}
117-
118-
public OptionalInt getShadowColor() {
119-
return shadowColor;
120-
}
121-
122-
public List<TextDecoration> getDecorations() {
123-
return decorations;
124-
}
125-
126113
}

Diff for: common/src/main/java/com/loohp/multichatdiscordsrvaddon/objectholders/ICPlayerEquipment.java

-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@
3333
public class ICPlayerEquipment implements EntityEquipment {
3434

3535
private final Map<EquipmentSlot, Float> dropChance;
36-
private final OfflinePlayer parent;
3736
private final OfflinePlayerData data;
3837

3938
public ICPlayerEquipment(OfflinePlayer parent, OfflinePlayerData data) {
4039
this.dropChance = new EnumMap<>(EquipmentSlot.class);
41-
this.parent = parent;
4240
this.data = data;
4341
resetChances();
4442
}

0 commit comments

Comments
 (0)