Skip to content

Commit bf26958

Browse files
author
twisti
committed
Update dependencies and adjust code for compatibility
The codebase has been updated to use new versions of dependencies, including a switch from 'commandapi-bukkit-core' to 'commandapi-bukkit-shade' and from 'net.kyori', 'adventure-nbt' to 'com.saicone.rtag', 'rtag' and 'rtag-entity'. Accordingly, parts of the code dealing with these dependencies, especially nbt-related operations in commands, have been adjusted for compatibility with the new libraries. In addition, the list of server dependencies in 'paper-plugin.yml' has been expanded.
1 parent 7f85a68 commit bf26958

File tree

6 files changed

+86
-38
lines changed

6 files changed

+86
-38
lines changed

pom.xml

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,28 @@
8787

8888
<dependency>
8989
<groupId>dev.jorel</groupId>
90-
<artifactId>commandapi-bukkit-core</artifactId>
90+
<artifactId>commandapi-bukkit-shade</artifactId>
91+
<scope>compile</scope>
9192
<version>9.4.1</version>
9293
</dependency>
9394
<dependency>
94-
<groupId>dev.jorel</groupId>
95-
<artifactId>commandapi-bukkit-plugin</artifactId>
96-
<version>9.4.1</version>
95+
<groupId>com.saicone.rtag</groupId>
96+
<artifactId>rtag</artifactId>
97+
<version>1.5.3</version>
98+
<scope>provided</scope>
9799
</dependency>
98100
<dependency>
99-
<groupId>de.tr7zw</groupId>
100-
<artifactId>item-nbt-api-plugin</artifactId>
101-
<version>2.12.4</version>
101+
<groupId>com.saicone.rtag</groupId>
102+
<artifactId>rtag-entity</artifactId>
103+
<version>1.5.3</version>
104+
<scope>provided</scope>
102105
</dependency>
103106

104107
<dependency>
105108
<groupId>com.github.retrooper.packetevents</groupId>
106109
<artifactId>spigot</artifactId>
107110
<version>2.3.0</version>
108-
<scope>provided</scope>
111+
<scope>compile</scope>
109112
</dependency>
110113

111114
<dependency>
@@ -343,10 +346,13 @@
343346
<configuration>
344347

345348
<createDependencyReducedPom>false</createDependencyReducedPom>
349+
<minimizeJar>true</minimizeJar>
346350

347351
<artifactSet>
348352
<includes>
349353
<include>com.github.stefvanschie.inventoryframework</include>
354+
<include>dev.jorel</include>
355+
<include>com.github.retrooper.packetevents</include>
350356
</includes>
351357
</artifactSet>
352358

@@ -355,6 +361,18 @@
355361
<pattern>com.github.stefvanschie.inventoryframework</pattern>
356362
<shadedPattern>dev.slne.surf.essentials.libs.inventoryframework</shadedPattern>
357363
</relocation>
364+
<relocation>
365+
<pattern>dev.jorel.commandapi</pattern>
366+
<shadedPattern>dev.slne.surf.essentials.libs.commandapi</shadedPattern>
367+
</relocation>
368+
<relocation>
369+
<pattern>com.github.retrooper.packetevents</pattern>
370+
<shadedPattern>dev.slne.surf.essentials.libs.packetevents.api</shadedPattern>
371+
</relocation>
372+
<relocation>
373+
<pattern>io.github.retrooper.packetevents</pattern>
374+
<shadedPattern>dev.slne.surf.essentials.libs.packetevents.impl</shadedPattern>
375+
</relocation>
358376
</relocations>
359377
</configuration>
360378

src/main/java/dev/slne/surf/essentials/SurfEssentials.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package dev.slne.surf.essentials;
22

33
import com.github.retrooper.packetevents.PacketEvents;
4+
import dev.jorel.commandapi.CommandAPI;
5+
import dev.jorel.commandapi.CommandAPIBukkitConfig;
46
import dev.slne.surf.essentials.commands.BrigadierCommands;
57
import dev.slne.surf.essentials.listener.ListenerManager;
68
import dev.slne.surf.essentials.utils.EssentialsUtil;
@@ -21,6 +23,7 @@
2123
import org.jetbrains.annotations.Nullable;
2224

2325
import java.util.Objects;
26+
import java.util.function.Function;
2427

2528
import static net.kyori.adventure.text.Component.text;
2629

@@ -38,6 +41,10 @@ public void onLoad() {
3841
PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
3942
PacketEvents.getAPI().load();
4043

44+
CommandAPI.onLoad(new CommandAPIBukkitConfig(this)
45+
.initializeNBTAPI(Object.class, Function.identity())
46+
.shouldHookPaperReload(true));
47+
4148
recodedCommands = new RecodedCommands();
4249
recodedCommands.unregisterVanillaCommands();
4350
brigadierCommands = new BrigadierCommands();
@@ -49,10 +56,11 @@ public void onLoad() {
4956
@Override
5057
public void onEnable() {
5158
instance = this;
52-
PacketEvents.getAPI().init();
53-
5459
loadMessage();
5560

61+
PacketEvents.getAPI().init();
62+
CommandAPI.onEnable();
63+
5664
EssentialsUtil.setPrefix();
5765
System.err.println("Commands");
5866
brigadierCommands.register();
@@ -74,6 +82,7 @@ public void onEnable() {
7482
public void onDisable() {
7583
brigadierCommands.unregister();
7684
listeners.unregisterListeners();
85+
CommandAPI.onDisable();
7786
logger().info(text("The plugin has stopped!", Colors.INFO));
7887
instance = null;
7988
}

src/main/java/dev/slne/surf/essentials/SurfEssentialsLoader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public SurfEssentialsLoader() {
2020
@Override
2121
public void classloader(@NotNull PluginClasspathBuilder classpathBuilder) {
2222
addDependency("net.kyori", "adventure-nbt", "4.14.0");
23-
addDependency("com.github.retrooper.packetevents", "spigot", "2.3.0");
23+
// addDependency("com.github.retrooper.packetevents", "spigot", "2.3.0");
24+
addDependency("com.saicone.rtag", "rtag", "1.5.3");
25+
addDependency("com.saicone.rtag", "rtag-entity", "1.5.3");
2426

2527
addRepository("papermc", "https://repo.papermc.io/repository/maven-public/");
2628
addRepository("jitpack.io", "https://jitpack.io");

src/main/java/dev/slne/surf/essentials/commands/EssentialsCommand.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package dev.slne.surf.essentials.commands;
22

3-
import de.tr7zw.nbtapi.NBTContainer;
43
import dev.jorel.commandapi.CommandTree;
54
import dev.jorel.commandapi.arguments.*;
65
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
@@ -662,12 +661,12 @@ protected AngleArgument angleArgument(String nodeName) {
662661
/**
663662
* Creates a new nbt compound argument.
664663
* <br>
665-
* When the argument is parsed, it returns a {@link NBTContainer} object.
664+
* When the argument is parsed, it returns an object.
666665
*
667666
* @param nodeName the name of the argument
668667
* @return a new nbt compound argument
669668
*/
670-
protected NBTCompoundArgument<NBTContainer> nbtCompoundArgument(String nodeName) {
669+
protected NBTCompoundArgument<Object> nbtCompoundArgument(String nodeName) {
671670
return new NBTCompoundArgument<>(nodeName);
672671
}
673672

src/main/java/dev/slne/surf/essentials/commands/minecraft/SummonCommand.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dev.slne.surf.essentials.commands.minecraft;
22

3-
import de.tr7zw.nbtapi.NBTContainer;
4-
import de.tr7zw.nbtapi.NBTEntity;
3+
import com.saicone.rtag.Rtag;
4+
import com.saicone.rtag.RtagEntity;
55
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
66
import dev.jorel.commandapi.executors.NativeResultingCommandExecutor;
77
import dev.slne.surf.essentials.commands.EssentialsCommand;
@@ -16,6 +16,7 @@
1616
import org.bukkit.entity.Entity;
1717
import org.bukkit.entity.EntityType;
1818
import org.jetbrains.annotations.NotNull;
19+
import org.jetbrains.annotations.Nullable;
1920

2021
public class SummonCommand extends EssentialsCommand {
2122

@@ -29,15 +30,15 @@ public SummonCommand() {
2930
sender.getCallee(),
3031
args.getUnchecked("entity"),
3132
sender.getLocation(),
32-
new NBTContainer(),
33+
null,
3334
true
3435
))
3536
.then(locationArgument("pos")
3637
.executesNative((NativeResultingCommandExecutor) (sender, args) -> summon(
3738
sender.getCallee(),
3839
args.getUnchecked("entity"),
3940
args.getUnchecked("pos"),
40-
new NBTContainer(),
41+
null,
4142
true
4243
))
4344
.then(nbtCompoundArgument("nbt")
@@ -53,24 +54,27 @@ public SummonCommand() {
5354
);
5455
}
5556

56-
private int summon(CommandSender source, EntityType entityType, Location pos, NBTContainer nbt, boolean initialize) throws WrapperCommandSyntaxException {
57+
private int summon(CommandSender source, EntityType entityType, Location pos, @Nullable Object nbt, boolean initialize) throws WrapperCommandSyntaxException {
5758
val entity = createEntity(entityType, pos, nbt, initialize);
5859
EssentialsUtil.sendSuccess(source, EssentialsUtil.getDisplayName(entity)
5960
.append(Component.text(" wurde gespawnt.", Colors.SUCCESS)));
6061
return 1;
6162
}
6263

63-
public static @NotNull Entity createEntity(EntityType entityType, Location pos, @NotNull NBTContainer nbt, boolean initialize) throws WrapperCommandSyntaxException {
64+
public static @NotNull Entity createEntity(EntityType entityType, Location pos, @Nullable Object nbt, boolean initialize) throws WrapperCommandSyntaxException {
6465
val level = pos.getWorld();
65-
val modifiedTag = new NBTContainer(nbt.getCompound());
6666

6767
if (!EssentialsUtil.isInSpawnableBounds(pos)) throw Exceptions.ERROR_OUT_OF_WORLD;
6868

6969
val spawnedEntity = level.spawnEntity(pos, entityType, initialize);
70-
val nbtEntity = new NBTEntity(spawnedEntity);
7170

72-
modifiedTag.setString("id", entityType.key().asString());
73-
nbtEntity.mergeCompound(modifiedTag);
71+
if (nbt != null) {
72+
val entityTag = Rtag.INSTANCE.newTag(nbt);
73+
RtagEntity.edit(spawnedEntity, rtagEntity -> {
74+
Rtag.INSTANCE.set(entityTag, entityType.key().asString(), "id");
75+
rtagEntity.merge(entityTag, true);
76+
});
77+
}
7478

7579
return spawnedEntity;
7680
}

src/main/resources/paper-plugin.yml

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,36 @@ description: '${project.description}'
55
api-version: '${project.apiVersion}'
66
bootstrapper: ${project.bootstrapper}
77
loader: ${project.loader}
8-
authors: [${project.authors}]
8+
authors: [ ${project.authors} ]
99
website: '${project.url}'
1010

1111
dependencies:
12-
server:
13-
CommandAPI:
14-
load: BEFORE
15-
required: true
16-
join-classpath: true
17-
CoreProtect:
18-
load: BEFORE
19-
required: false
20-
join-classpath: true
21-
NBTAPI:
22-
load: BEFORE
23-
required: true
24-
join-classpath: true
12+
server:
13+
CoreProtect:
14+
load: BEFORE
15+
required: false
16+
join-classpath: true
17+
ProtocolLib:
18+
load: BEFORE
19+
required: false
20+
join-classpath: true
21+
ProtocolSupport:
22+
load: BEFORE
23+
required: false
24+
join-classpath: true
25+
ViaVersion:
26+
load: BEFORE
27+
required: false
28+
join-classpath: true
29+
ViaBackwards:
30+
load: BEFORE
31+
required: false
32+
join-classpath: true
33+
ViaRewind:
34+
load: BEFORE
35+
required: false
36+
join-classpath: true
37+
Geyser-Spigot:
38+
load: BEFORE
39+
required: false
40+
join-classpath: true

0 commit comments

Comments
 (0)