/
PaperWorldProperties.java
139 lines (124 loc) · 5.14 KB
/
PaperWorldProperties.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.denizenscript.denizen.paper.properties;
import com.denizenscript.denizen.objects.WorldTag;
import com.denizenscript.denizen.utilities.BukkitImplDeprecations;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
public class PaperWorldProperties implements Property {
public static boolean describes(ObjectTag world) {
return world instanceof WorldTag;
}
public static PaperWorldProperties getFrom(ObjectTag world) {
if (!describes(world)) {
return null;
}
return new PaperWorldProperties((WorldTag) world);
}
public static final String[] handledMechs = new String[] {
"view_distance", "simulation_distance", "no_tick_view_distance"
};
private PaperWorldProperties(WorldTag world) {
this.world = world;
}
WorldTag world;
@Override
public String getPropertyString() {
return null;
}
@Override
public String getPropertyId() {
return "PaperWorldProperties";
}
public static void register() {
// <--[tag]
// @attribute <WorldTag.no_tick_view_distance>
// @returns ElementTag(Number)
// @mechanism WorldTag.no_tick_view_distance
// @group properties
// @deprecated replaced by Minecraft's simulation_distance and view_distance config pairing
// @Plugin Paper
// @description
// Deprecated: replaced by Minecraft's simulation_distance and view_distance config pairing
// -->
PropertyParser.registerTag(PaperWorldProperties.class, ElementTag.class, "no_tick_view_distance", (attribute, world) -> {
BukkitImplDeprecations.paperNoTickViewDistance.warn(attribute.context);
return new ElementTag(world.world.getWorld().getNoTickViewDistance());
});
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object WorldTag
// @name view_distance
// @input ElementTag(Number)
// @Plugin Paper
// @description
// Sets this world's view distance. All chunks within this radius of a player will be visible to that player.
// Input should be a number from 2 to 32.
// See also <@link mechanism WorldTag.simulation_distance>
// @tags
// <WorldTag.view_distance>
// <server.view_distance>
// -->
if (mechanism.matches("view_distance") && mechanism.requireInteger()) {
int distance = mechanism.getValue().asInt();
if (distance < 2 || distance > 32) {
Debug.echoError("View distance must be a number from 2 to 32!");
}
else {
world.getWorld().setViewDistance(distance);
}
}
// <--[mechanism]
// @object WorldTag
// @name simulation_distance
// @input ElementTag(Number)
// @Plugin Paper
// @description
// Sets this world's view distance. All chunks within this radius will be tracked by the server.
// Input should be a number from 2 to 32.
// See also <@link mechanism WorldTag.view_distance>
// @tags
// <WorldTag.view_distance>
// <server.view_distance>
// -->
if (mechanism.matches("simulation_distance") && mechanism.requireInteger()) {
int distance = mechanism.getValue().asInt();
if (distance < 2 || distance > 32) {
Debug.echoError("View distance must be a number from 2 to 32!");
}
else {
world.getWorld().setSimulationDistance(distance);
}
}
// <--[mechanism]
// @object WorldTag
// @name no_tick_view_distance
// @input ElementTag(Number)
// @Plugin Paper
// @deprecated replaced by Minecraft's simulation_distance and view_distance config pairing
// @description
// Deprecated: replaced by Minecraft's simulation_distance and view_distance config pairing
// @tags
// <WorldTag.no_tick_view_distance>
// -->
if (mechanism.matches("no_tick_view_distance")) {
BukkitImplDeprecations.paperNoTickViewDistance.warn(mechanism.context);
if (!mechanism.hasValue()) {
world.getWorld().setNoTickViewDistance(-1);
}
else if (mechanism.requireInteger()) {
int distance = mechanism.getValue().asInt();
if (distance < 2 || distance > 32) {
Debug.echoError("View distance must be a number from 2 to 32!");
}
else {
world.getWorld().setNoTickViewDistance(distance);
}
}
}
}
}