Skip to content

Commit 6747b31

Browse files
committed
Migrate: DiscordCommands to IC-dependent code [ci skip]
1 parent 392bed3 commit 6747b31

File tree

11 files changed

+527
-57
lines changed

11 files changed

+527
-57
lines changed

common/src/main/java/com/loohp/multichatdiscordsrvaddon/InteractiveChatDiscordSrvAddon.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,13 @@ public class InteractiveChatDiscordSrvAddon extends JavaPlugin implements Listen
283283
public static ICPlaceholder enderChestPlaceholder = null;
284284
public ItemStack invFrame1 = null;
285285
public ItemStack invFrame2 = null;
286+
public static ItemStack itemFrame1;
287+
public static ItemStack itemFrame2;
286288
public static Map<UUID, ICPlaceholder> placeholderList = new LinkedHashMap<>();
287289

290+
public int itemTagMaxLength = 32767;
291+
public boolean sendOriginalIfTooLong = false;
292+
288293
public ConcurrentCacheHashMap<String, Inventory> itemDisplay = new ConcurrentCacheHashMap<>(itemDisplayTimeout, 60000);
289294
public ConcurrentCacheHashMap<String, Inventory> inventoryDisplay = new ConcurrentCacheHashMap<>(itemDisplayTimeout, 60000);
290295
public ConcurrentCacheHashMap<String, Inventory> inventoryDisplay1Upper = new ConcurrentCacheHashMap<>(itemDisplayTimeout, 60000);
@@ -294,6 +299,10 @@ public class InteractiveChatDiscordSrvAddon extends JavaPlugin implements Listen
294299
public Set<Inventory> upperSharedInventory = Collections.synchronizedSet(Collections.newSetFromMap(new WeakHashMap<>()));
295300
public Set<Inventory> lowerSharedInventory = Collections.synchronizedSet(Collections.newSetFromMap(new WeakHashMap<>()));
296301

302+
public static int remoteDelay = 500;
303+
304+
public boolean previewMaps = true;
305+
297306
private ResourceManager resourceManager;
298307
public ModelRenderer modelRenderer;
299308
public ExecutorService mediaReadingService;
@@ -650,6 +659,8 @@ public void reloadConfig() {
650659
useTooltipOnTab = config.getConfiguration().getBoolean("TabCompletion.PlayerNameTooltip.Enabled");
651660
tabTooltip = ChatColorUtils.translateAlternateColorCodes('&', config.getConfiguration().getString("TabCompletion.PlayerNameTooltip.Tooltip"));
652661

662+
previewMaps = config.getConfiguration().getBoolean("InventoryImage.Item.PreviewMaps");
663+
653664
try {
654665
ItemStack unknown = new ItemStack(Material.valueOf(getConfig().getString("Settings.UnknownItem.ReplaceItem").toUpperCase()));
655666
ItemMeta meta = unknown.getItemMeta();
@@ -674,6 +685,9 @@ public void reloadConfig() {
674685
LanguageUtils.loadTranslations(language);
675686
forceUnicode = config.getConfiguration().getBoolean("Resources.ForceUnicodeFont");
676687

688+
itemTagMaxLength = config.getConfiguration().getInt("Settings.ItemTagMaxLength");
689+
sendOriginalIfTooLong = config.getConfiguration().getBoolean("Settings.SendOriginalMessageIfExceedLengthLimit");
690+
677691
Pattern itemPlaceholderPattern = Pattern.compile(config.getConfiguration().getString("Placeholders.Item"));
678692
Pattern inventoryPlaceholderPattern = Pattern.compile(config.getConfiguration().getString("Placeholders.Inventory"));
679693
Pattern enderChestPlaceholderPattern = Pattern.compile(config.getConfiguration().getString("Placeholders.EnderChest"));

common/src/main/java/com/loohp/multichatdiscordsrvaddon/api/InteractiveChatDiscordSrvAddonAPI.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ public static ResourceManager getCurrentResourceManager() {
5757
return InteractiveChatDiscordSrvAddon.plugin.isResourceManagerReady() ? InteractiveChatDiscordSrvAddon.plugin.getResourceManager() : null;
5858
}
5959

60+
/**
61+
* Add a map to the shared map list
62+
*
63+
* @param hash key
64+
* @param item
65+
* @return The hashed key which can be used to retrieve the inventory
66+
*/
67+
public static String addMapToMapSharedList(String hash, ItemStack item) {
68+
InteractiveChatDiscordSrvAddon.plugin.mapDisplay.put(hash, item);
69+
return hash;
70+
}
71+
6072
/**
6173
* Get all active discord attachments
6274
*
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* This file is part of InteractiveChat.
3+
*
4+
* Copyright (C) 2020 - 2025. LoohpJames <[email protected]>
5+
* Copyright (C) 2020 - 2025. Contributors
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
package com.loohp.multichatdiscordsrvaddon.api.events;
22+
23+
import net.kyori.adventure.text.Component;
24+
import org.bukkit.Material;
25+
import org.bukkit.entity.Player;
26+
import org.bukkit.event.HandlerList;
27+
import org.bukkit.inventory.ItemStack;
28+
29+
/**
30+
* This event is called whenever the item placeholder is used. Only the itemStack
31+
* can be changed in this event, nothing else. Changing the Component or
32+
* Canceling the event will cause UnsupportedOperationException to be thrown.
33+
*
34+
* @author LOOHP
35+
*/
36+
public class ItemPlaceholderEvent extends PlaceholderEvent {
37+
38+
private static final HandlerList HANDLERS = new HandlerList();
39+
40+
public static HandlerList getHandlerList() {
41+
return HANDLERS;
42+
}
43+
44+
private ItemStack itemStack;
45+
46+
public ItemPlaceholderEvent(Player sender, Player receiver, Component component, long timeSent, ItemStack itemStack) {
47+
super(sender, receiver, component, timeSent);
48+
this.itemStack = itemStack;
49+
}
50+
51+
public ItemStack getItemStack() {
52+
return itemStack;
53+
}
54+
55+
public void setItemStack(ItemStack itemStack) {
56+
if (itemStack == null) {
57+
itemStack = new ItemStack(Material.AIR);
58+
}
59+
this.itemStack = itemStack;
60+
}
61+
62+
@Override
63+
public Component getComponent() {
64+
return component;
65+
}
66+
67+
@Override
68+
@Deprecated
69+
public void setComponent(Component component) {
70+
throw new UnsupportedOperationException("Changing the Component in this event is not allowed");
71+
}
72+
73+
@Override
74+
@Deprecated
75+
public void setCancelled(boolean cancel) {
76+
throw new UnsupportedOperationException("Cancelling this event is not allowed");
77+
}
78+
79+
public HandlerList getHandlers() {
80+
return HANDLERS;
81+
}
82+
83+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* This file is part of InteractiveChat.
3+
*
4+
* Copyright (C) 2020 - 2025. LoohpJames <[email protected]>
5+
* Copyright (C) 2020 - 2025. Contributors
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
package com.loohp.multichatdiscordsrvaddon.api.events;
22+
23+
import com.loohp.interactivechat.objectholders.ICPlayer;
24+
import net.kyori.adventure.text.Component;
25+
import org.bukkit.Bukkit;
26+
import org.bukkit.entity.Player;
27+
import org.bukkit.event.Cancellable;
28+
import org.bukkit.event.Event;
29+
import org.bukkit.event.HandlerList;
30+
31+
/**
32+
* This is the base class of all events related to parsing placeholders.
33+
*
34+
* @author LOOHP
35+
*/
36+
public class PlaceholderEvent extends Event implements Cancellable {
37+
38+
private static final HandlerList HANDLERS = new HandlerList();
39+
40+
public static HandlerList getHandlerList() {
41+
return HANDLERS;
42+
}
43+
44+
protected final Player sender;
45+
protected final Player receiver;
46+
protected final long timeSent;
47+
protected Component component;
48+
protected boolean isCancelled;
49+
50+
public PlaceholderEvent(Player sender, Player receiver, Component component, long timeSent) {
51+
super(!Bukkit.isPrimaryThread());
52+
this.sender = sender;
53+
this.receiver = receiver;
54+
this.component = component;
55+
this.timeSent = timeSent;
56+
this.isCancelled = false;
57+
}
58+
59+
public PlaceholderEvent(Player receiver, Component component, long timeSent) {
60+
this(null, receiver, component, timeSent);
61+
}
62+
63+
public boolean hasSender() {
64+
return sender != null;
65+
}
66+
67+
public Player getSender() {
68+
return sender;
69+
}
70+
71+
public Player getReceiver() {
72+
return receiver;
73+
}
74+
75+
public Component getComponent() {
76+
return component;
77+
}
78+
79+
public void setComponent(Component component) {
80+
this.component = component;
81+
}
82+
83+
public long getTimeSent() {
84+
return timeSent;
85+
}
86+
87+
@Override
88+
public boolean isCancelled() {
89+
return isCancelled;
90+
}
91+
92+
@Override
93+
public void setCancelled(boolean cancel) {
94+
this.isCancelled = cancel;
95+
}
96+
97+
public HandlerList getHandlers() {
98+
return HANDLERS;
99+
}
100+
101+
}

0 commit comments

Comments
 (0)