Skip to content

Commit 681372c

Browse files
committed
v4.0.1 - Update freeze feature for 1.16.2.
1 parent 15c6f88 commit 681372c

File tree

6 files changed

+73
-24
lines changed

6 files changed

+73
-24
lines changed

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
github: dscalzi
2+
patreon: dscalzi
3+
custom: ['https://www.paypal.me/dscalzi']

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
SkyChanger is a light-weight plugin for Spigot and Sponge. The main function of this plugin is to change the color of the sky for yourself, a specific player, a specific world, or everyone. This plugin functions by sending packets with a specified value to the target player(s).
66

7+
*Like the project? Leave a ⭐ on the repository!*
8+
79
***
810

911
# Feature List

SkyChanger-Bukkit/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repositories {
1111
}
1212

1313
dependencies {
14-
compileOnly 'org.spigotmc:spigot-api:1.16.1-R0.1-SNAPSHOT'
14+
compileOnly 'org.spigotmc:spigot-api:1.16.2-R0.1-SNAPSHOT'
1515

1616
api project(':SkyChanger-Core')
1717
implementation 'org.bstats:bstats-bukkit:1.7'

SkyChanger-Bukkit/src/main/java/com/dscalzi/skychanger/bukkit/internal/ReflectionUtil.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public final class ReflectionUtil {
3636
private static String version;
3737
private static int major;
3838
private static int minor;
39+
private static int r; // Bukkit R version, not revision.
3940

4041
private final static Map<String, Class<?>> nmsClasses;
4142
private final static Map<String, Class<?>> ocbClasses;
@@ -53,10 +54,12 @@ public final class ReflectionUtil {
5354
public static String getVersion() {
5455
if (version == null) {
5556
String declaration = Bukkit.getServer().getClass().getPackage().getName();
56-
version = declaration.substring(declaration.lastIndexOf('.') + 1) + ".";
57+
version = declaration.substring(declaration.lastIndexOf('.') + 1);
5758
String[] pts = version.substring(1).split("_");
5859
major = Integer.parseInt(pts[0]);
5960
minor = Integer.parseInt(pts[1]);
61+
r = Integer.parseInt(pts[2].substring(1));
62+
version += '.';
6063
}
6164
return version;
6265
}
@@ -75,6 +78,13 @@ public static int getMinor() {
7578
return minor;
7679
}
7780

81+
public static int getR() {
82+
if(version == null) {
83+
getVersion();
84+
}
85+
return r;
86+
}
87+
7888
public static Class<?> getNMSClass(String localPackage) {
7989

8090
if (nmsClasses.containsKey(localPackage))

SkyChanger-Bukkit/src/main/java/com/dscalzi/skychanger/bukkit/internal/SkyChangeImpl.java

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ private Object getTypeKey(Class<?> WorldClass, Object world) throws InvocationTa
139139
return getTypeKey.invoke(world);
140140
}
141141

142+
private Object getDimensionManager1162Plus(Class<?> WorldClass, Object world) throws InvocationTargetException, IllegalAccessException {
143+
Method getDimensionManager = Objects.requireNonNull(ReflectionUtil.getMethod(WorldClass, "getDimensionManager"));
144+
return getDimensionManager.invoke(world);
145+
}
146+
142147
// 1.16+
143148
private Object getDimensionKey(Class<?> WorldClass, Object world) throws InvocationTargetException, IllegalAccessException {
144149
Method getDimensionKey = Objects.requireNonNull(ReflectionUtil.getMethod(WorldClass, "getDimensionKey"));
@@ -195,7 +200,7 @@ private Object getEnumDifficulty(Class<?> EnumDifficultyClass, Player player) th
195200

196201
protected boolean sendFreezePacket(Player player) {
197202

198-
int major = ReflectionUtil.getMajor(), minor = ReflectionUtil.getMinor();
203+
int major = ReflectionUtil.getMajor(), minor = ReflectionUtil.getMinor(), r = ReflectionUtil.getR();
199204

200205
if(FREEZE_UNSUPPORTED.contains(major + "." + minor)) {
201206
MessageManager.getInstance().featureUnsupported(SkyChanger.wrapPlayer(player), FREEZE_UNSUPPORTED.toString());
@@ -216,32 +221,61 @@ protected boolean sendFreezePacket(Player player) {
216221
// Works sometimes so let's just say it works.
217222

218223
Class<?> EnumGamemodeClass = ReflectionUtil.getNMSClass("EnumGamemode");
219-
220224
Object worldServer = getWorldServer(player);
221225
Object gameMode = getEnumGamemode(EnumGamemodeClass, player);
222226

223227
Class<?> WorldClass = ReflectionUtil.getNMSClass("World");
224228
Class<?> ResourceKeyClass = ReflectionUtil.getNMSClass("ResourceKey");
225229

226-
Constructor<?> packetConstructor = ClientboundRespawnPacket.getConstructor(
227-
ResourceKeyClass, // DimensionType
228-
ResourceKeyClass, // DimensionKey
229-
long.class, // Seed
230-
EnumGamemodeClass, // gameType
231-
EnumGamemodeClass, // previousGameType
232-
boolean.class, // isDebug
233-
boolean.class, // isFlat
234-
boolean.class); // keepAllPlayerData
235-
packet = packetConstructor.newInstance(
236-
getTypeKey(WorldClass, worldServer),
237-
getDimensionKey(WorldClass, worldServer),
238-
player.getWorld().getSeed(),
239-
gameMode,
240-
gameMode,
241-
false,
242-
false,
243-
true);
230+
if(r >= 2) {
231+
232+
// 1.16.2+
233+
234+
Class<?> DimensionManagerClass = ReflectionUtil.getNMSClass("DimensionManager");
235+
236+
Constructor<?> packetConstructor = ClientboundRespawnPacket.getConstructor(
237+
DimensionManagerClass, // DimensionManager
238+
ResourceKeyClass, // DimensionKey
239+
long.class, // Seed
240+
EnumGamemodeClass, // gameType
241+
EnumGamemodeClass, // previousGameType
242+
boolean.class, // isDebug
243+
boolean.class, // isFlat
244+
boolean.class); // keepAllPlayerData
245+
packet = packetConstructor.newInstance(
246+
getDimensionManager1162Plus(WorldClass, worldServer),
247+
getDimensionKey(WorldClass, worldServer),
248+
player.getWorld().getSeed(),
249+
gameMode,
250+
gameMode,
251+
false,
252+
false,
253+
true);
244254

255+
} else {
256+
257+
// 1.16.1
258+
259+
Constructor<?> packetConstructor = ClientboundRespawnPacket.getConstructor(
260+
ResourceKeyClass, // DimensionType
261+
ResourceKeyClass, // DimensionKey
262+
long.class, // Seed
263+
EnumGamemodeClass, // gameType
264+
EnumGamemodeClass, // previousGameType
265+
boolean.class, // isDebug
266+
boolean.class, // isFlat
267+
boolean.class); // keepAllPlayerData
268+
packet = packetConstructor.newInstance(
269+
getTypeKey(WorldClass, worldServer),
270+
getDimensionKey(WorldClass, worldServer),
271+
player.getWorld().getSeed(),
272+
gameMode,
273+
gameMode,
274+
false,
275+
false,
276+
true);
277+
278+
}
245279

246280
} else if (minor >= 13) {
247281

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ subprojects {
3131

3232
def major = '4'
3333
def minor = '0'
34-
def spongeRevision = '0'
35-
def bukkitRevision = '0'
34+
def spongeRevision = '1'
35+
def bukkitRevision = '1'
3636

3737
def rev
3838

0 commit comments

Comments
 (0)