Skip to content

Commit 2d64a8d

Browse files
committed
Spigot version bump for crafter support (Not compat with sub 1.21 yet),
Initial Kyori updates, Full # and Hex code support( couple visual bugs but working otherwise) Spigot and Paper adaptor for chat events (No more using "p.sendmessage", USE "PSL.msg" Need to add all hardcoded msgs to the Messages.yml
1 parent 55fe14c commit 2d64a8d

42 files changed

Lines changed: 1473 additions & 1136 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pom.xml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
<dependency>
214214
<groupId>com.sk89q.worldguard</groupId>
215215
<artifactId>worldguard-bukkit</artifactId>
216-
<version>7.0.9-SNAPSHOT</version>
216+
<version>7.0.14-SNAPSHOT</version>
217217
<scope>provided</scope>
218218
<exclusions>
219219
<exclusion>
@@ -231,7 +231,7 @@
231231
<dependency>
232232
<groupId>com.sk89q.worldedit</groupId>
233233
<artifactId>worldedit-bukkit</artifactId>
234-
<version>7.2.6-SNAPSHOT</version>
234+
<version>7.3.16-SNAPSHOT</version>
235235
<scope>provided</scope>
236236
<exclusions>
237237
<exclusion>
@@ -240,6 +240,36 @@
240240
</exclusion>
241241
</exclusions>
242242
</dependency>
243+
<dependency>
244+
<groupId>net.kyori</groupId>
245+
<artifactId>adventure-api</artifactId>
246+
<version>4.17.0</version>
247+
<scope>compile</scope>
248+
</dependency>
249+
<dependency>
250+
<groupId>net.kyori</groupId>
251+
<artifactId>adventure-platform-bukkit</artifactId>
252+
<version>4.3.2</version>
253+
<scope>compile</scope>
254+
</dependency>
255+
<dependency>
256+
<groupId>net.kyori</groupId>
257+
<artifactId>adventure-text-serializer-plain</artifactId>
258+
<version>4.17.0</version>
259+
<scope>compile</scope>
260+
</dependency>
261+
<dependency>
262+
<groupId>net.kyori</groupId>
263+
<artifactId>adventure-text-serializer-bungeecord</artifactId>
264+
<version>4.4.1</version>
265+
<scope>compile</scope>
266+
</dependency>
267+
<dependency>
268+
<groupId>net.kyori</groupId>
269+
<artifactId>adventure-text-minimessage</artifactId>
270+
<version>4.17.0</version>
271+
<scope>compile</scope>
272+
</dependency>
243273
<dependency>
244274
<groupId>me.clip</groupId>
245275
<artifactId>placeholderapi</artifactId>

src/main/java/dev/espi/protectionstones/BlockHandler.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,15 @@
3030
import dev.espi.protectionstones.utils.MiscUtil;
3131
import dev.espi.protectionstones.utils.WGMerge;
3232
import dev.espi.protectionstones.utils.WGUtils;
33+
import net.kyori.adventure.text.Component;
3334
import net.md_5.bungee.api.chat.TextComponent;
3435
import net.milkbowl.vault.economy.EconomyResponse;
3536
import org.bukkit.*;
3637
import org.bukkit.block.Block;
3738
import org.bukkit.entity.Player;
3839
import org.bukkit.event.block.BlockPlaceEvent;
3940

40-
import java.util.ArrayList;
41-
import java.util.Arrays;
42-
import java.util.HashMap;
43-
import java.util.List;
41+
import java.util.*;
4442

4543
public class BlockHandler {
4644
private static HashMap<Player, Double> lastProtectStonePlaced = new HashMap<>();
@@ -140,7 +138,7 @@ public static boolean createPSRegion(Player p, Location l, PSProtectBlock blockO
140138
if (ProtectionStones.getInstance().getConfigOptions().placingCooldown != -1) {
141139
String time = checkCooldown(p);
142140
if (time != null) {
143-
PSL.msg(p, PSL.COOLDOWN.msg().replace("%time%", time));
141+
PSL.msg(p, PSL.COOLDOWN.replace("%time%", time));
144142
return false;
145143
}
146144
}
@@ -168,7 +166,7 @@ public static boolean createPSRegion(Player p, Location l, PSProtectBlock blockO
168166

169167
// check if player has enough money
170168
if (ProtectionStones.getInstance().isVaultSupportEnabled() && blockOptions.costToPlace != 0 && !ProtectionStones.getInstance().getVaultEconomy().has(p, blockOptions.costToPlace)) {
171-
PSL.msg(p, PSL.NOT_ENOUGH_MONEY.msg().replace("%price%", String.format("%.2f", blockOptions.costToPlace)));
169+
PSL.msg(p, PSL.NOT_ENOUGH_MONEY.replace("%price%", String.format("%.2f", blockOptions.costToPlace)));
172170
return false;
173171
}
174172

@@ -183,10 +181,10 @@ public static boolean createPSRegion(Player p, Location l, PSProtectBlock blockO
183181
if (ProtectionStones.getInstance().isVaultSupportEnabled() && blockOptions.costToPlace != 0) {
184182
EconomyResponse er = ProtectionStones.getInstance().getVaultEconomy().withdrawPlayer(p, blockOptions.costToPlace);
185183
if (!er.transactionSuccess()) {
186-
PSL.msg(p, er.errorMessage);
184+
PSL.msg(p, Component.text(er.errorMessage));
187185
return true;
188186
}
189-
PSL.msg(p, PSL.PAID_MONEY.msg().replace("%price%", String.format("%.2f", blockOptions.costToPlace)));
187+
PSL.msg(p, PSL.PAID_MONEY.replace("%price%", String.format("%.2f", blockOptions.costToPlace)));
190188
}
191189

192190
return true;
@@ -214,7 +212,7 @@ public static boolean createActualRegion(Player p, Location l, PSProtectBlock bl
214212
// check for minimum distance between claims by using fake region
215213
if (blockOptions.distanceBetweenClaims != -1 && !p.hasPermission("protectionstones.superowner")) {
216214
if (!isFarEnoughFromOtherClaims(blockOptions, p.getWorld(), lp, bx, by, bz)) {
217-
PSL.msg(p, PSL.REGION_TOO_CLOSE.msg().replace("%num%", "" + blockOptions.distanceBetweenClaims));
215+
PSL.msg(p, PSL.REGION_TOO_CLOSE.replace("%num%", "" + blockOptions.distanceBetweenClaims));
218216
return false;
219217
}
220218
}
@@ -315,7 +313,7 @@ private static void playerMergeTask(Player p, PSRegion r) {
315313
Bukkit.getScheduler().runTaskAsynchronously(ProtectionStones.getInstance(), () -> {
316314
try {
317315
WGMerge.mergeRealRegions(p.getWorld(), r.getWGRegionManager(), finalMergeTo, Arrays.asList(finalMergeTo, r));
318-
PSL.msg(p, PSL.MERGE_AUTO_MERGED.msg().replace("%region%", finalMergeTo.getId()));
316+
PSL.msg(p, PSL.MERGE_AUTO_MERGED.replace("%region%", finalMergeTo.getId()));
319317
} catch (WGMerge.RegionHoleException e) {
320318
PSL.msg(p, PSL.NO_REGION_HOLES.msg()); // TODO github issue #120, prevent holes even if showGUI is true
321319
} catch (WGMerge.RegionCannotMergeWhileRentedException e) {
@@ -327,14 +325,21 @@ private static void playerMergeTask(Player p, PSRegion r) {
327325

328326
// show merge gui
329327
if (showGUI) {
330-
List<TextComponent> tc = ArgMerge.getGUI(p, r);
328+
List<Component> tc = ArgMerge.getGUI(p, r);
331329
if (!tc.isEmpty()) { // if there are regions you can merge into
332-
p.sendMessage(ChatColor.WHITE + ""); // send empty line
330+
PSL.msg(p, Component.empty());
333331
PSL.msg(p, PSL.MERGE_INTO.msg());
334-
PSL.msg(p, PSL.MERGE_HEADER.msg().replace("%region%", r.getId()));
335-
for (TextComponent t : tc) p.spigot().sendMessage(t);
336-
p.sendMessage(ChatColor.WHITE + ""); // send empty line
332+
PSL.msg(p, PSL.MERGE_HEADER.replaceAll(Map.of("%region%", r.getId())));
333+
334+
// GUI entries
335+
for (Component t : tc) {
336+
PSL.msg(p, t);
337+
}
338+
339+
// empty line again
340+
PSL.msg(p, Component.empty());
337341
}
338342
}
343+
339344
}
340345
}

src/main/java/dev/espi/protectionstones/ListenerClass.java

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import dev.espi.protectionstones.utils.RecipeUtil;
3030
import dev.espi.protectionstones.utils.UUIDCache;
3131
import dev.espi.protectionstones.utils.WGUtils;
32+
import net.kyori.adventure.text.Component;
33+
import net.kyori.adventure.text.format.NamedTextColor;
3234
import org.bukkit.Bukkit;
3335
import org.bukkit.ChatColor;
3436
import org.bukkit.Material;
@@ -37,6 +39,7 @@
3739
import org.bukkit.block.BlockFace;
3840
import org.bukkit.block.BlockState;
3941
import org.bukkit.block.Furnace;
42+
import org.bukkit.block.data.type.Crafter;
4043
import org.bukkit.command.CommandSender;
4144
import org.bukkit.enchantments.Enchantment;
4245
import org.bukkit.entity.Player;
@@ -53,10 +56,7 @@
5356
import org.bukkit.event.player.PlayerJoinEvent;
5457
import org.bukkit.event.player.PlayerTeleportEvent;
5558
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
56-
import org.bukkit.inventory.CraftingRecipe;
57-
import org.bukkit.inventory.ItemStack;
58-
import org.bukkit.inventory.ShapedRecipe;
59-
import org.bukkit.inventory.ShapelessRecipe;
59+
import org.bukkit.inventory.*;
6060

6161
import java.util.List;
6262

@@ -95,7 +95,7 @@ public void onPlayerJoin(PlayerJoinEvent e) {
9595
}
9696

9797
if (amount != 0) {
98-
PSL.msg(psp, PSL.TAX_JOIN_MSG_PENDING_PAYMENTS.msg().replace("%money%", "" + amount));
98+
PSL.msg(psp.getPlayer(), PSL.TAX_JOIN_MSG_PENDING_PAYMENTS.replace("%money%", "" + amount));
9999
}
100100
});
101101
}
@@ -140,7 +140,7 @@ public void onBlockPlace(BlockPlaceEvent e) {
140140

141141
// returns the error message, or "" if the player has permission to break the region
142142
// TODO: refactor and move this to PSRegion, so that /ps unclaim can use the same checks
143-
private String checkPermissionToBreakProtection(Player p, PSRegion r) {
143+
private Component checkPermissionToBreakProtection(Player p, PSRegion r) {
144144
// check for destroy permission
145145
if (!p.hasPermission("protectionstones.destroy")) {
146146
return PSL.NO_PERMISSION_DESTROY.msg();
@@ -156,7 +156,7 @@ private String checkPermissionToBreakProtection(Player p, PSRegion r) {
156156
return PSL.RENT_CANNOT_BREAK_WHILE_RENTING.msg();
157157
}
158158

159-
return "";
159+
return Component.empty();
160160
}
161161

162162
// helper method for breaking protection blocks
@@ -165,8 +165,8 @@ private boolean playerBreakProtection(Player p, PSRegion r) {
165165
PSProtectBlock blockOptions = r.getTypeOptions();
166166

167167
// check if player has permission to break the protection
168-
String error = checkPermissionToBreakProtection(p, r);
169-
if (!error.isEmpty()) {
168+
Component error = checkPermissionToBreakProtection(p, r);
169+
if (!error.contains(Component.empty())) {
170170
PSL.msg(p, error);
171171
return false;
172172
}
@@ -235,8 +235,8 @@ public void onBlockBreakLowPriority(BlockBreakEvent e) {
235235
ProtectionStones.getInstance().debug("Player:"+ p.getName()+", Holding:"+ p.getPlayer().getInventory().getItemInMainHand().getType().name()+", Enchants:" +p.getPlayer().getInventory().getItemInMainHand().getEnchantments());
236236

237237

238-
String error = checkPermissionToBreakProtection(p, r);
239-
if (!error.isEmpty()) {
238+
Component error = checkPermissionToBreakProtection(p, r);
239+
if (!error.contains(Component.empty())) {
240240
PSL.msg(p, error);
241241
e.setCancelled(true);
242242
}
@@ -318,37 +318,42 @@ public void onPrepareItemCraft(PrepareItemCraftEvent e) {
318318
}
319319
}
320320

321-
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
322-
public void onCrafterCraft(CrafterCraftEvent e) {
323-
ProtectionStones.getInstance().debug("ListenerClass.java, onCrafterCraft");
324-
325-
CraftingRecipe recipe = e.getRecipe();
326-
if (recipe == null) return;
327-
328-
// Shaped recipes (grid-based)
329-
if (recipe instanceof ShapedRecipe shaped) {
330-
for (ItemStack ingredient : shaped.getIngredientMap().values()) {
331-
if (ingredient != null) {
332-
PSProtectBlock options = ProtectionStones.getBlockOptions(ingredient);
333-
if (options != null && !options.allowUseInCrafting) {
334-
e.setResult(new ItemStack(Material.AIR));
335-
e.setCancelled(true);
336-
return;
337-
}
338-
}
321+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
322+
public void onCrafterClick(InventoryClickEvent e) {
323+
if (!(e.getInventory().getHolder() instanceof Crafter)) return;
324+
325+
ItemStack item = e.getCursor(); // item being placed
326+
if (item != null && ProtectionStones.getBlockOptions(item) != null) {
327+
e.setCancelled(true);
328+
e.getWhoClicked().sendMessage(ChatColor.RED + "You cannot insert ProtectionStone blocks into a Crafter.");
329+
}
330+
}
331+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
332+
public void onCrafterHopperMove(InventoryMoveItemEvent e) {
333+
if (!(e.getDestination().getHolder() instanceof Crafter)) return;
334+
335+
ItemStack item = e.getItem();
336+
if (item != null) {
337+
PSProtectBlock options = ProtectionStones.getBlockOptions(item);
338+
if (options != null && !options.allowUseInCrafting) {
339+
e.setCancelled(true);
339340
}
340341
}
342+
}
341343

342-
// Shapeless recipes (unordered list)
343-
if (recipe instanceof ShapelessRecipe shapeless) {
344-
for (ItemStack ingredient : shapeless.getIngredientList()) {
345-
if (ingredient != null) {
346-
PSProtectBlock options = ProtectionStones.getBlockOptions(ingredient);
347-
if (options != null && !options.allowUseInCrafting) {
348-
e.setResult(new ItemStack(Material.AIR));
349-
e.setCancelled(true);
350-
return;
344+
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
345+
public void onCrafterDrag(InventoryDragEvent e) {
346+
if (!(e.getInventory().getHolder() instanceof Crafter)) return;
347+
348+
for (ItemStack item : e.getNewItems().values()) {
349+
if (item != null) {
350+
PSProtectBlock options = ProtectionStones.getBlockOptions(item);
351+
if (options != null && !options.allowUseInCrafting) {
352+
e.setCancelled(true);
353+
if (e.getWhoClicked() instanceof Player player) {
354+
PSL.msg(player, Component.text("You cannot use ProtectionStones blocks in a Crafter.", NamedTextColor.RED));
351355
}
356+
return;
352357
}
353358
}
354359
}

0 commit comments

Comments
 (0)