Skip to content

Commit 714c2c6

Browse files
committed
- Display changes - performance, stability and bugfixes
- Updated library for Anvil text searching - Updated Core's default API from 1.20.6 to 1.21.1 - `/ds info` command QoL changes, now you can click the author and see their GitHub profile (if Paper is present) Signed-off-by: petulikan1 <petulikan@gmail.com> Took 4 hours 22 minutes
1 parent b0eae7a commit 714c2c6

8 files changed

Lines changed: 127 additions & 53 deletions

File tree

Core/src/main/java/xzot1k/plugins/ds/DisplayShops.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ public void onEnable() {
155155
try {
156156
setup();
157157
} catch (ClassNotFoundException e) {
158+
e.printStackTrace();
158159
throw new RuntimeException("Plugin is not compatible with this server version! Your server version: "+Ref.serverVersion());
159160
}
160161

@@ -857,21 +858,29 @@ private void setup() throws ClassNotFoundException {
857858
if(!version.startsWith("v"))
858859
version="v"+version;
859860

860-
861861
Class<?> vUtilClass = Class.forName("xzot1k.plugins.ds.nms." + version + ".VUtil");
862862
versionUtil = (VersionUtil) vUtilClass.getDeclaredConstructor().newInstance();
863863
displayPacketClass = Class.forName("xzot1k.plugins.ds.nms." + version + ".DPacket");
864-
} catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
865-
866-
/*this.versionUtil = new xzot1k.plugins.ds.nms.v1_21_R1.VUtil();
867-
displayPacketClass = xzot1k.plugins.ds.nms.v1_21_R1.DPacket.class;*/
864+
} catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException | ClassNotFoundException e) {
865+
String version = Ref.serverVersion().replace(".","_");
866+
if(!version.startsWith("v"))
867+
version="v"+version;
868+
String[] split = version.split("_");
868869

870+
version=split[0]+"_"+split[1]+"_R"+split[2];
871+
try {
872+
Class<?> vUtilClass = Class.forName("xzot1k.plugins.ds.nms." + version + ".VUtil");
873+
versionUtil = (VersionUtil) vUtilClass.getDeclaredConstructor().newInstance();
874+
displayPacketClass = Class.forName("xzot1k.plugins.ds.nms." + version + ".DPacket");
875+
} catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e2) {
876+
e2.printStackTrace();
877+
}
869878
}
870879

871-
// this.craftPlayerClass = Class.forName("org.bukkit.craftbukkit." + getVersionPackageName() + ".entity.CraftPlayer");
872-
// this.packetOpenWindowClass = Class.forName("net.minecraft.server." + getVersionPackageName() + ".PacketPlayOutOpenWindow");
873880
}
874881

882+
883+
875884
public String toString(@NotNull ItemStack itemStack) {
876885
YamlConfiguration itemConfig = new YamlConfiguration();
877886
itemConfig.set("item", itemStack);
@@ -1221,7 +1230,8 @@ public void killCurrentShopPacket(@NotNull Player player) {
12211230
public void removeDisplayPacket(@NotNull Shop shop, @NotNull Player player) {
12221231
if (!getDisplayPacketMap().isEmpty() && getDisplayPacketMap().containsKey(player.getUniqueId())) {
12231232
HashMap<UUID, DisplayPacket> packetMap = getDisplayPacketMap().getOrDefault(player.getUniqueId(), null);
1224-
if (packetMap != null) packetMap.remove(shop.getShopId());
1233+
if (packetMap != null)
1234+
packetMap.remove(shop.getShopId());
12251235
}
12261236
}
12271237

Core/src/main/java/xzot1k/plugins/ds/core/Commands.java

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
package xzot1k.plugins.ds.core;
66

77
import me.devtec.shared.Ref;
8+
import me.devtec.shared.utility.StringUtils;
9+
import net.kyori.adventure.text.Component;
10+
import net.kyori.adventure.text.minimessage.MiniMessage;
11+
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
812
import net.md_5.bungee.api.chat.ClickEvent;
913
import net.md_5.bungee.api.chat.HoverEvent;
1014
import net.md_5.bungee.api.chat.ItemTag;
@@ -1097,7 +1101,8 @@ private void runReset(CommandSender commandSender, String marketRegionId) {
10971101
marketRegion.reset();
10981102

10991103
final String message = getPluginInstance().getLangConfig().getString("market-region-reset");
1100-
if (message != null) getPluginInstance().getManager().sendMessage(player, message.replace("{id}", marketRegion.getMarketId()));
1104+
if (message != null)
1105+
getPluginInstance().getManager().sendMessage(player, message.replace("{id}", marketRegion.getMarketId()));
11011106
return;
11021107
}
11031108

@@ -1187,8 +1192,10 @@ private void runAppearanceAccess(CommandSender commandSender, boolean isUnlock,
11871192
if (message != null && !message.equalsIgnoreCase("")) {
11881193
String status = getPluginInstance().getLangConfig().getString(isUnlock ? "unlocked" : "locked");
11891194
if (status != null) message = message.replace("{status}", status);
1190-
if (isPlayer) getPluginInstance().getManager().sendMessage((Player) commandSender, message.replace("{player}", player.getName()));
1191-
else commandSender.sendMessage(getPluginInstance().getManager().color(message.replace("{player}", player.getName())));
1195+
if (isPlayer)
1196+
getPluginInstance().getManager().sendMessage((Player) commandSender, message.replace("{player}", player.getName()));
1197+
else
1198+
commandSender.sendMessage(getPluginInstance().getManager().color(message.replace("{player}", player.getName())));
11921199
}
11931200
} else {
11941201
Appearance appearance = Appearance.getAppearance(args[2]);
@@ -1211,8 +1218,10 @@ private void runAppearanceAccess(CommandSender commandSender, boolean isUnlock,
12111218
if (message != null && !message.equalsIgnoreCase("")) {
12121219
String status = getPluginInstance().getLangConfig().getString(isUnlock ? "unlocked" : "locked");
12131220
if (status != null) message = message.replace("{status}", status);
1214-
if (isPlayer) getPluginInstance().getManager().sendMessage((Player) commandSender, message.replace("{player}", player.getName()));
1215-
else commandSender.sendMessage(getPluginInstance().getManager().color(message.replace("{player}", player.getName())));
1221+
if (isPlayer)
1222+
getPluginInstance().getManager().sendMessage((Player) commandSender, message.replace("{player}", player.getName()));
1223+
else
1224+
commandSender.sendMessage(getPluginInstance().getManager().color(message.replace("{player}", player.getName())));
12161225
}
12171226
}
12181227
}
@@ -1527,6 +1536,22 @@ private void runCleanUp(CommandSender commandSender) {
15271536
.replace("{count}", getPluginInstance().getManager().formatNumber(cleanCount, false))));
15281537
}
15291538

1539+
private final MiniMessage mm = MiniMessage.miniMessage();
1540+
1541+
private Component getAuthors() {
1542+
String authorFormat = "<click:open_url:\"https://github.com/<author>\"><hover:show_text:\"<aqua>Click to see <yellow><author>'s</yellow> Github</aqua>\"><author></hover></click>";
1543+
Component authors = Component.empty();
1544+
int i = 0;
1545+
List<String> authors1 = getPluginInstance().getDescription().getAuthors();
1546+
for (String author : authors1) {
1547+
authors = authors.append(mm.deserialize(authorFormat, Placeholder.parsed("author", author)));
1548+
if (i != authors1.size())
1549+
authors = authors.append(Component.text(", "));
1550+
i++;
1551+
}
1552+
return authors;
1553+
}
1554+
15301555
private void runInfo(CommandSender commandSender) {
15311556
if (!commandSender.hasPermission("displayshops.info")) {
15321557
String message = getPluginInstance().getLangConfig().getString("no-permission");
@@ -1535,13 +1560,28 @@ private void runInfo(CommandSender commandSender) {
15351560
return;
15361561
}
15371562

1538-
commandSender.sendMessage(getPluginInstance().getManager().color("\n&e<&m------------&r&e[ &bDisplayShops &e]&m------------&r&e>\n" +
1563+
String message = "\n<yellow><<st>------------</st>[ <aqua>DisplayShops</aqua> ]<st>------------</st>>\n" +
1564+
"<gray>Current Plugin Version:</gray> <plversion>\n" +
1565+
"<gray>Latest Released Version:</gray> <green><plreleasedver></green>\n" +
1566+
"<gray>Author(s):</gray><aqua> <authors>\n" +
1567+
"<yellow><<st>-------------------------------------</st>>";
1568+
1569+
String pluginVersion = (getPluginInstance().getDescription().getVersion().toLowerCase().contains("build") ? "<red>" : "<green>") + getPluginInstance().getDescription().getVersion();
1570+
String releasedVersion = (getPluginInstance().getDescription().getVersion().toLowerCase().contains("snapshot") ? "<dark_blue>" : "<green>") + getPluginInstance().getLatestVersion();
1571+
if(Ref.serverType()== Ref.ServerType.PAPER) {
1572+
commandSender.sendMessage(mm.deserialize(message
1573+
, Placeholder.parsed("plversion", pluginVersion)
1574+
, Placeholder.parsed("plreleasedver", releasedVersion)
1575+
, Placeholder.component("authors", this::getAuthors)));
1576+
}else {
1577+
commandSender.sendMessage(getPluginInstance().getManager().color("\n&e<&m------------&r&e[ &bDisplayShops &e]&m------------&r&e>\n" +
15391578
"&7Current Plugin Version: " + (getPluginInstance().getDescription().getVersion().toLowerCase().contains("build") ? "&c" : "&a")
15401579
+ getPluginInstance().getDescription().getVersion() + "\n" +
15411580
"&7Latest Release Plugin Version: " + (getPluginInstance().getDescription().getVersion().toLowerCase().contains("snapshot") ? "&1" : "&a")
15421581
+ getPluginInstance().getLatestVersion() + "\n"
1543-
+ "&7Author(s): &bXZot1K\n" +
1582+
+ "&7Author(s): &b" + StringUtils.join(getPluginInstance().getDescription().getAuthors(), ", ") + "\n" +
15441583
"&e<&m-------------------------------------&r&e>\n"));
1584+
}
15451585
}
15461586

15471587
private void runCreateMarket(CommandSender commandSender, String[] args) {

Core/src/main/java/xzot1k/plugins/ds/core/packets/Display.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.bukkit.inventory.ItemStack;
99
import org.bukkit.metadata.FixedMetadataValue;
1010
import org.bukkit.persistence.PersistentDataType;
11+
import org.bukkit.scheduler.BukkitTask;
1112
import org.jetbrains.annotations.NotNull;
1213
import org.joml.Matrix4f;
1314
import xzot1k.plugins.ds.DisplayShops;
@@ -20,6 +21,8 @@ public class Display {
2021
public static NamespacedKey key = new NamespacedKey(DisplayShops.getPluginInstance(), "DisplayShops-Entity");
2122
public static final ItemStack barrier = new ItemStack(Material.BARRIER);
2223

24+
private static final LegacyComponentSerializer SECTION = LegacyComponentSerializer.legacySection();
25+
2326
private final Shop shop;
2427
private Entity textDisplay, itemDisplay, blockDisplay;
2528
private final List<UUID> entityIds = new ArrayList<>();
@@ -192,21 +195,25 @@ private void updateItem(World world, Location baseLocation, float scale, double
192195
getItemHolder().addPassenger(getItem()); // add item as passenger*/
193196
}
194197

195-
/* private void rotateDisplay(ItemDisplay display, Matrix4f mat, float scale, int duration) {
196-
final float rotationIncrement = (float) Math.toRadians(5); // Rotate 5 degrees per tick
197-
final float[] currentAngle = {0}; // Array to hold current angle
198+
private BukkitTask displayTask;
198199

199-
new BukkitRunnable() {
200+
/* private void rotateDisplay(ItemDisplay display, Matrix4f mat, float scale, int duration) {
201+
if(displayTask!=null&& !displayTask.isCancelled()){
202+
return;
203+
}
204+
displayTask=new BukkitRunnable() {
205+
final float rotationIncrement = (float) Math.toRadians(5); // Rotate 5 degrees per tick
206+
float currentAngle = 0F; // Array to hold current angle
200207
@Override
201208
public void run() {
202209
if (display == null || display.isDead() || !display.isValid()) { // display was removed from the world, abort task
203210
cancel();
204211
return;
205212
}
206213
207-
currentAngle[0] += rotationIncrement; // Increment the angle
208-
if (currentAngle[0] >= Math.toRadians(360)) {
209-
currentAngle[0] -= (float) Math.toRadians(360); // Reset the angle if it completes a full rotation
214+
currentAngle += rotationIncrement; // Increment the angle
215+
if (currentAngle >= Math.toRadians(360)) {
216+
currentAngle -= (float) Math.toRadians(360); // Reset the angle if it completes a full rotation
210217
}
211218
212219
ItemStack itemStack = display.getItemStack();
@@ -215,11 +222,11 @@ public void run() {
215222
}
216223
217224
// Update the transformation matrix with the new rotation
218-
display.setTransformationMatrix(mat.identity().scale(scale).rotateY(currentAngle[0]));
225+
display.setTransformationMatrix(mat.identity().scale(scale).rotateY(currentAngle));
219226
display.setInterpolationDelay(0); // no delay to the interpolation
220227
display.setInterpolationDuration(duration); // set the duration of the interpolated rotation
221228
}
222-
}.runTaskTimer(DisplayShops.getPluginInstance(), 15, duration);
229+
}.runTaskTimer(DisplayShops.getPluginInstance(), 10, duration);
223230
}*/
224231

225232
private void updateGlass(World world, Location baseLocation, double[] appearanceOffsets) {
@@ -316,6 +323,8 @@ public String generateText() {
316323
return DisplayShops.getPluginInstance().getManager().color(text.toString());
317324
}
318325

326+
private String prevText="";
327+
319328
private void updateLines(World world, Location baseLocation, String text, double[] appearanceOffsets) {
320329
double x = (0.5 + baseLocation.getX() + (appearanceOffsets != null ? appearanceOffsets[0] : 0)),
321330
y = (1.8 + baseLocation.getY() + (appearanceOffsets != null ? appearanceOffsets[1] : 0)),
@@ -374,7 +383,10 @@ private void updateLines(World world, Location baseLocation, String text, double
374383
if (getEntityIds().contains(entity.getUniqueId())) {getEntityIds().add(entity.getUniqueId());}
375384
});
376385
} else {
377-
((TextDisplay) getTextDisplay()).text(LegacyComponentSerializer.legacySection().deserialize(text));
386+
if(!prevText.equals(text)) {
387+
((TextDisplay) getTextDisplay()).text(SECTION.deserialize(text));
388+
prevText=text;
389+
}
378390
getTextDisplay().teleportAsync(location, PlayerTeleportEvent.TeleportCause.PLUGIN);
379391
}
380392

0 commit comments

Comments
 (0)