/
PaperModule.java
78 lines (67 loc) · 4 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
package com.denizenscript.denizen.paper;
import com.denizenscript.denizen.Denizen;
import com.denizenscript.denizen.objects.EntityTag;
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.denizen.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...");
// Events
ScriptEvent.registerScriptEvent(new AreaEnterExitScriptEventPaperImpl());
ScriptEvent.registerScriptEvent(new EntityKnocksbackEntityScriptEvent());
ScriptEvent.registerScriptEvent(new EntityLoadCrossbowScriptEvent());
ScriptEvent.registerScriptEvent(new EntityPathfindScriptEvent());
ScriptEvent.registerScriptEvent(new ExperienceOrbMergeScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerAbsorbsExperienceScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerBeaconEffectScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerClicksFakeEntityScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerClicksInRecipeBookScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerEquipsArmorScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerJumpsScriptEventPaperImpl());
ScriptEvent.registerScriptEvent(new PlayerSpectatesEntityScriptEvent());
ScriptEvent.registerScriptEvent(new PlayerStopsSpectatingScriptEvent());
ScriptEvent.registerScriptEvent(new PreEntitySpawnScriptEvent());
ScriptEvent.registerScriptEvent(new ProjectileCollideScriptEvent());
ScriptEvent.registerScriptEvent(new ServerListPingScriptEventPaperImpl());
ScriptEvent.registerScriptEvent(new TNTPrimesScriptEvent());
ScriptEvent.registerScriptEvent(new UnknownCommandScriptEvent());
// Properties
PropertyParser.registerProperty(EntityCanTick.class, EntityTag.class);
PropertyParser.registerProperty(EntityExperienceOrb.class, EntityTag.class);
PropertyParser.registerProperty(EntityFromSpawner.class, EntityTag.class);
PropertyParser.registerProperty(EntitySpawnLocation.class, EntityTag.class);
PropertyParser.registerProperty(WorldViewDistance.class, WorldTag.class);
PropertyParser.registerProperty(PlayerAffectsMonsterSpawning.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) {
return jsonToComponent(ComponentSerializer.toString(FormattedTextHelper.parse(text, baseColor)));
}
public static String stringifyComponent(Component component, ChatColor baseColor) {
return FormattedTextHelper.stringify(ComponentSerializer.parse(componentToJson(component)), baseColor);
}
public static Component jsonToComponent(String json) {
return GsonComponentSerializer.gson().deserialize(json);
}
public static String componentToJson(Component component) {
return GsonComponentSerializer.gson().serialize(component);
}
}