/
PaperModule.java
111 lines (99 loc) · 5.63 KB
/
PaperModule.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package com.denizenscript.denizen.paper;
import com.denizenscript.denizen.Denizen;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.NMSVersion;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizen.objects.WorldTag;
import com.denizenscript.denizen.paper.events.*;
import com.denizenscript.denizen.paper.properties.*;
import com.denizenscript.denizen.paper.tags.PaperTagBase;
import com.denizenscript.denizen.paper.utilities.PaperAdvancedTextImpl;
import com.denizenscript.denizen.utilities.FormattedTextHelper;
import com.denizenscript.denizen.utilities.AdvancedTextImpl;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizencore.events.ScriptEvent;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.chat.ComponentSerializer;
import org.bukkit.Bukkit;
public class PaperModule {
public static void init() {
Debug.log("Loading Paper support module...");
ScriptEvent.notNameParts.add(0, "PaperImpl");
// Events
ScriptEvent.registerScriptEvent(AnvilBlockDamagedScriptEvent.class);
ScriptEvent.registerScriptEvent(AreaEnterExitScriptEventPaperImpl.class);
ScriptEvent.registerScriptEvent(BellRingScriptEvent.class);
ScriptEvent.registerScriptEvent(CreeperIgnitesScriptEvent.class);
ScriptEvent.registerScriptEvent(EntityAddToWorldScriptEvent.class);
ScriptEvent.registerScriptEvent(EntityKnocksbackEntityScriptEvent.class);
ScriptEvent.registerScriptEvent(EntityLoadCrossbowScriptEvent.class);
ScriptEvent.registerScriptEvent(EntityPathfindScriptEvent.class);
ScriptEvent.registerScriptEvent(ExperienceOrbMergeScriptEvent.class);
ScriptEvent.registerScriptEvent(PlayerAbsorbsExperienceScriptEvent.class);
ScriptEvent.registerScriptEvent(PlayerBeaconEffectScriptEvent.class);
ScriptEvent.registerScriptEvent(PlayerClicksFakeEntityScriptEvent.class);
ScriptEvent.registerScriptEvent(PlayerClicksInRecipeBookScriptEvent.class);
ScriptEvent.registerScriptEvent(PlayerCompletesAdvancementScriptEventPaperImpl.class);
ScriptEvent.registerScriptEvent(PlayerElytraBoostScriptEvent.class);
ScriptEvent.registerScriptEvent(PlayerEquipsArmorScriptEvent.class);
ScriptEvent.registerScriptEvent(PlayerJumpsScriptEventPaperImpl.class);
ScriptEvent.registerScriptEvent(PlayerSpectatesEntityScriptEvent.class);
ScriptEvent.registerScriptEvent(PlayerStopsSpectatingScriptEvent.class);
ScriptEvent.registerScriptEvent(PlayerTradesWithMerchantScriptEvent.class);
ScriptEvent.registerScriptEvent(PreEntitySpawnScriptEvent.class);
ScriptEvent.registerScriptEvent(ProjectileCollideScriptEvent.class);
ScriptEvent.registerScriptEvent(ServerListPingScriptEventPaperImpl.class);
ScriptEvent.registerScriptEvent(ServerResourcesReloadedScriptEvent.class);
ScriptEvent.registerScriptEvent(TNTPrimesScriptEvent.class);
ScriptEvent.registerScriptEvent(UnknownCommandScriptEvent.class);
// Properties
PropertyParser.registerProperty(EntityArmsRaised.class, EntityTag.class);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_18)) {
PropertyParser.registerProperty(EntityAutoExpire.class, EntityTag.class);
}
PropertyParser.registerProperty(EntityCanTick.class, EntityTag.class);
PropertyParser.registerProperty(EntityCarryingEgg.class, EntityTag.class);
PropertyParser.registerProperty(EntityDrinkingPotion.class, EntityTag.class);
PropertyParser.registerProperty(EntityWitherInvulnerable.class, EntityTag.class);
PropertyParser.registerProperty(ItemArmorStand.class, ItemTag.class);
// Paper extension properties
PropertyParser.registerProperty(PaperEntityProperties.class, EntityTag.class);
PropertyParser.registerProperty(PaperItemTagProperties.class, ItemTag.class);
PropertyParser.registerProperty(PaperWorldProperties.class, WorldTag.class);
PropertyParser.registerProperty(PaperPlayerProperties.class, PlayerTag.class);
// Paper Tags
new PaperTagBase();
// Other helpers
Bukkit.getPluginManager().registerEvents(new PaperEventHelpers(), Denizen.getInstance());
AdvancedTextImpl.instance = new PaperAdvancedTextImpl();
}
public static Component parseFormattedText(String text, ChatColor baseColor) {
if (text == null) {
return null;
}
return jsonToComponent(ComponentSerializer.toString(FormattedTextHelper.parse(text, baseColor)));
}
public static String stringifyComponent(Component component, ChatColor baseColor) {
if (component == null) {
return null;
}
return FormattedTextHelper.stringify(ComponentSerializer.parse(componentToJson(component)), baseColor);
}
public static Component jsonToComponent(String json) {
if (json == null) {
return null;
}
return GsonComponentSerializer.gson().deserialize(json);
}
public static String componentToJson(Component component) {
if (component == null) {
return null;
}
return GsonComponentSerializer.gson().serialize(component);
}
}