Skip to content

Commit a7e12f3

Browse files
1.21.11 support
1 parent 431dc48 commit a7e12f3

12 files changed

Lines changed: 397 additions & 187 deletions

File tree

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>me.Genral_Breddok</groupId>
88
<artifactId>BlockDisplayCreator</artifactId>
9-
<version>1.5.4.1</version>
9+
<version>1.5.4.2</version>
1010
<packaging>jar</packaging>
1111

1212
<name>BlockDisplayCreator</name>
@@ -139,13 +139,13 @@
139139
<dependency>
140140
<groupId>net.kyori</groupId>
141141
<artifactId>adventure-nbt</artifactId>
142-
<version>4.25.0</version>
142+
<version>4.26.1</version>
143143
<scope>compile</scope>
144144
</dependency>
145145
<dependency>
146146
<groupId>me.clip</groupId>
147147
<artifactId>placeholderapi</artifactId>
148-
<version>2.11.6</version>
148+
<version>2.11.7</version>
149149
<scope>provided</scope>
150150
</dependency>
151151
<dependency>
@@ -157,7 +157,7 @@
157157
<dependency>
158158
<groupId>dev.jorel</groupId>
159159
<artifactId>commandapi-spigot-shade</artifactId>
160-
<version>11.0.0</version>
160+
<version>11.1.0</version>
161161
</dependency>
162162
<dependency>
163163
<groupId>com.mojang</groupId>
@@ -173,7 +173,7 @@
173173
<dependency>
174174
<groupId>com.github.retrooper</groupId>
175175
<artifactId>packetevents-spigot</artifactId>
176-
<version>2.10.1</version>
176+
<version>2.11.2</version>
177177
<scope>provided</scope>
178178
</dependency>
179179
<dependency>

src/main/java/me/general_breddok/blockdisplaycreator/BlockDisplayCreator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import lombok.Getter;
66
import lombok.experimental.FieldDefaults;
77
import me.general_breddok.blockdisplaycreator.command.BlockDisplayCreatorSpigotCommand;
8+
import me.general_breddok.blockdisplaycreator.command.CustomBlockGiveSpigotCommand;
89
import me.general_breddok.blockdisplaycreator.command.capi.BlockDisplayCreatorCAPICommand;
910
import me.general_breddok.blockdisplaycreator.command.capi.CustomBlockGiveCAPICommand;
1011
import me.general_breddok.blockdisplaycreator.common.BDCDependentPluginsManager;
@@ -168,6 +169,7 @@ public void onEnable() {
168169

169170
CommandAPISpigot.unregister("blockdisplaycreator", true, true);
170171
CommandAPISpigot.unregister("bdc", true, true);
172+
CommandAPISpigot.unregister("cb", true, true);
171173

172174
this.bdcCommand = new BlockDisplayCreatorCAPICommand(this);
173175
this.bdcCommand.register();
@@ -176,6 +178,7 @@ public void onEnable() {
176178
this.cbGiveCommand.register();
177179
} else {
178180
getCommand("blockdisplaycreator").setExecutor(new BlockDisplayCreatorSpigotCommand(this, this.customBlockService));
181+
getCommand("cb").setExecutor(new CustomBlockGiveSpigotCommand(this.customBlockService));
179182
}
180183

181184
registerDataAdapters();

src/main/java/me/general_breddok/blockdisplaycreator/command/BlockDisplayCreatorSpigotCommand.java

Lines changed: 30 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import me.general_breddok.blockdisplaycreator.permission.DefaultPermissions;
1717
import me.general_breddok.blockdisplaycreator.placeholder.universal.PlayerSkinBase64Placeholder;
1818
import me.general_breddok.blockdisplaycreator.util.ChatUtil;
19+
import me.general_breddok.blockdisplaycreator.util.CommandUtil;
1920
import me.general_breddok.blockdisplaycreator.util.ItemUtil;
2021
import me.general_breddok.blockdisplaycreator.world.WorldSelection;
2122
import org.bukkit.Bukkit;
@@ -34,17 +35,14 @@
3435
import java.util.List;
3536

3637

37-
/**
38-
* @deprecated
39-
*/
40-
@Deprecated(since = "MC1.19.4")
38+
4139
public class BlockDisplayCreatorSpigotCommand implements TabExecutor {
4240

43-
private final BlockDisplayCreator instance;
41+
private final BlockDisplayCreator plugin;
4442
private final CustomBlockService service;
4543

46-
public BlockDisplayCreatorSpigotCommand(BlockDisplayCreator instance, CustomBlockService service) {
47-
this.instance = instance;
44+
public BlockDisplayCreatorSpigotCommand(BlockDisplayCreator plugin, CustomBlockService service) {
45+
this.plugin = plugin;
4846
this.service = service;
4947
}
5048

@@ -138,7 +136,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
138136
ChatUtil.sendMessage(sender, StringMessagesValue.COMMAND_CUSTOM_BLOCK_GIVE_NO_PLAYER);
139137
return true;
140138
} else {
139+
CommandUtil.applyPlaceholdersForItem(customBlockItem, player);
140+
CommandUtil.applyPlaceholdersForCommand(abstractCustomBlock, customBlockItem, player);
141+
141142
ItemUtil.distributeItem(player, customBlockItem);
143+
142144
ChatUtil.sendMessage(player,
143145
StringMessagesValue.COMMAND_CUSTOM_BLOCK_GIVE_PLAYER_RECEIVE
144146
.replace("%customblock_name%", arg3)
@@ -149,8 +151,9 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
149151
switch (arg4) {
150152
case "@a" -> {
151153
for (Player recipient : Bukkit.getOnlinePlayers()) {
152-
applyPlaceholdersForItem(customBlockItem, recipient);
153-
applyPlaceholdersForCommand(abstractCustomBlock, customBlockItem, recipient);
154+
CommandUtil.applyPlaceholdersForItem(customBlockItem, recipient);
155+
CommandUtil.applyPlaceholdersForCommand(abstractCustomBlock, customBlockItem, recipient);
156+
154157
ItemUtil.distributeItem(recipient, customBlockItem);
155158
}
156159
ChatUtil.sendMessage(sender, "&bYou have given the &l%s&ox%s&r&b block to all players", arg3, amount);
@@ -162,9 +165,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
162165
return true;
163166
}
164167

165-
applyPlaceholdersForItem(customBlockItem, player);
166-
applyPlaceholdersForCommand(abstractCustomBlock, customBlockItem, player);
168+
CommandUtil.applyPlaceholdersForItem(customBlockItem, player);
169+
CommandUtil.applyPlaceholdersForCommand(abstractCustomBlock, customBlockItem, player);
170+
167171
ItemUtil.distributeItem(player, customBlockItem);
172+
168173
ChatUtil.sendMessage(sender, "&bYou have received the &l%s&ox%s&r&b block", arg3, amount);
169174
return true;
170175
}
@@ -176,9 +181,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
176181
return true;
177182
}
178183

179-
applyPlaceholdersForItem(customBlockItem, randomPlayer);
180-
applyPlaceholdersForCommand(abstractCustomBlock, customBlockItem, randomPlayer);
184+
CommandUtil.applyPlaceholdersForItem(customBlockItem, randomPlayer);
185+
CommandUtil.applyPlaceholdersForCommand(abstractCustomBlock, customBlockItem, randomPlayer);
186+
181187
ItemUtil.distributeItem(randomPlayer, customBlockItem);
188+
182189
ChatUtil.sendMessage(sender, "&bYou have given the &l%s&ox%s&r&b block to random player %s", arg3, amount, randomPlayer.getName());
183190
return true;
184191
}
@@ -189,10 +196,12 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
189196
}
190197

191198
Player nearestPlayer = TargetSelectorType.getNearestPlayer(player.getLocation(), player);
192-
applyPlaceholdersForItem(customBlockItem, nearestPlayer);
193-
applyPlaceholdersForCommand(abstractCustomBlock, customBlockItem, nearestPlayer);
199+
200+
CommandUtil.applyPlaceholdersForItem(customBlockItem, nearestPlayer);
201+
CommandUtil.applyPlaceholdersForCommand(abstractCustomBlock, customBlockItem, nearestPlayer);
194202

195203
ItemUtil.distributeItem(nearestPlayer, customBlockItem);
204+
196205
ChatUtil.sendMessage(sender, "&bYou have given the &l%s&ox%s&r&b block to nearest player %s", arg3, amount, nearestPlayer.getName());
197206
return true;
198207
}
@@ -204,9 +213,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
204213
return true;
205214
}
206215

207-
applyPlaceholdersForItem(customBlockItem, recipient);
208-
applyPlaceholdersForCommand(abstractCustomBlock, customBlockItem, recipient);
216+
CommandUtil.applyPlaceholdersForItem(customBlockItem, recipient);
217+
CommandUtil.applyPlaceholdersForCommand(abstractCustomBlock, customBlockItem, recipient);
218+
209219
ItemUtil.distributeItem(recipient, customBlockItem);
220+
210221
ChatUtil.sendMessage(sender, "&bYou have given the &l%s&ox%s&r&b block to player %s", arg3, amount, recipient.getName());
211222
return true;
212223
}
@@ -490,10 +501,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
490501
}
491502

492503
if (arg2 == null) {
493-
instance.reloadConfig();
504+
plugin.reloadConfig();
494505
ChatUtil.sendMessage(sender, "&aConfig has been reloaded!");
495506
} else {
496-
this.instance.getCustomBlockService().getStorage().reload(arg2);
507+
this.plugin.getCustomBlockService().getStorage().reload(arg2);
497508
ChatUtil.sendMessage(sender, "&a%s block has been reloaded!", arg2);
498509
}
499510
}
@@ -742,62 +753,5 @@ private void eraseCbData(BoundingBox boundingBox, Player sender) {
742753
ChatUtil.sendMessage(sender, "&6Killed %d collision entities", collisions.size());
743754
ChatUtil.sendMessage(sender, "&6Cleared %d custom blocks", blocksCount[0]);
744755
}
745-
746-
public void applyPlaceholdersForItem(ItemStack item, Player player) {
747-
ItemMeta itemMeta = item.getItemMeta();
748-
Plugin placeholderApi = BlockDisplayCreator.getInstance().getDependentPluginsManager().getPlaceholderApi();
749-
750-
if (placeholderApi == null) {
751-
return;
752-
}
753-
754-
itemMeta.setDisplayName(ChatUtil.setPlaceholders(player, itemMeta.getDisplayName(), placeholderApi));
755-
List<String> itemMetaLore = itemMeta.getLore();
756-
if (itemMetaLore != null) {
757-
List<String> lore = new ArrayList<>();
758-
itemMetaLore.forEach(line -> lore.add(ChatUtil.setPlaceholders(player, line, placeholderApi)));
759-
itemMeta.setLore(lore);
760-
}
761-
762-
763-
item.setItemMeta(itemMeta);
764-
}
765-
766-
public void applyPlaceholdersForCommand(AbstractCustomBlock abstractCustomBlock, ItemStack item, Player player) {
767-
Plugin placeholderApi = BlockDisplayCreator.getInstance().getDependentPluginsManager().getPlaceholderApi();
768-
if (placeholderApi == null) {
769-
return;
770-
}
771-
772-
GroupSummoner<Display> displaySummoner = abstractCustomBlock.getDisplaySummoner();
773-
774-
if (displaySummoner instanceof AutomaticCommandDisplaySummoner displayCommandSummoner) {
775-
if (!displayCommandSummoner.isUsePlaceholder()) {
776-
return;
777-
}
778-
779-
780-
CommandLine[] parsed = displayCommandSummoner.getCommands()
781-
.stream()
782-
.map(commandLine ->
783-
{
784-
String lineString = commandLine.toString();
785-
String base64Formatted = new PlayerSkinBase64Placeholder(player).apply(lineString);
786-
787-
return (CommandLine) new MCCommandLine(ChatUtil.setPlaceholders(
788-
player,
789-
base64Formatted,
790-
placeholderApi));
791-
}
792-
).toArray(CommandLine[]::new);
793-
794-
ItemMeta itemMeta = item.getItemMeta();
795-
PersistentData<CommandLine[]> commandListPD = new PersistentData<>(itemMeta, TypeTokens.COMMAND_ARRAY);
796-
797-
commandListPD.set(CustomBlockKey.DISPLAY_SPAWN_COMMAND, parsed);
798-
799-
item.setItemMeta(itemMeta);
800-
}
801-
}
802756
}
803757

0 commit comments

Comments
 (0)