Skip to content

Commit

Permalink
v4.0.1 - Update freeze feature for 1.16.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
dscalzi committed Aug 13, 2020
1 parent 15c6f88 commit 681372c
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
github: dscalzi
patreon: dscalzi
custom: ['https://www.paypal.me/dscalzi']
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

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).

*Like the project? Leave a ⭐ on the repository!*

***

# Feature List
Expand Down
2 changes: 1 addition & 1 deletion SkyChanger-Bukkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repositories {
}

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

api project(':SkyChanger-Core')
implementation 'org.bstats:bstats-bukkit:1.7'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public final class ReflectionUtil {
private static String version;
private static int major;
private static int minor;
private static int r; // Bukkit R version, not revision.

private final static Map<String, Class<?>> nmsClasses;
private final static Map<String, Class<?>> ocbClasses;
Expand All @@ -53,10 +54,12 @@ public final class ReflectionUtil {
public static String getVersion() {
if (version == null) {
String declaration = Bukkit.getServer().getClass().getPackage().getName();
version = declaration.substring(declaration.lastIndexOf('.') + 1) + ".";
version = declaration.substring(declaration.lastIndexOf('.') + 1);
String[] pts = version.substring(1).split("_");
major = Integer.parseInt(pts[0]);
minor = Integer.parseInt(pts[1]);
r = Integer.parseInt(pts[2].substring(1));
version += '.';
}
return version;
}
Expand All @@ -75,6 +78,13 @@ public static int getMinor() {
return minor;
}

public static int getR() {
if(version == null) {
getVersion();
}
return r;
}

public static Class<?> getNMSClass(String localPackage) {

if (nmsClasses.containsKey(localPackage))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ private Object getTypeKey(Class<?> WorldClass, Object world) throws InvocationTa
return getTypeKey.invoke(world);
}

private Object getDimensionManager1162Plus(Class<?> WorldClass, Object world) throws InvocationTargetException, IllegalAccessException {
Method getDimensionManager = Objects.requireNonNull(ReflectionUtil.getMethod(WorldClass, "getDimensionManager"));
return getDimensionManager.invoke(world);
}

// 1.16+
private Object getDimensionKey(Class<?> WorldClass, Object world) throws InvocationTargetException, IllegalAccessException {
Method getDimensionKey = Objects.requireNonNull(ReflectionUtil.getMethod(WorldClass, "getDimensionKey"));
Expand Down Expand Up @@ -195,7 +200,7 @@ private Object getEnumDifficulty(Class<?> EnumDifficultyClass, Player player) th

protected boolean sendFreezePacket(Player player) {

int major = ReflectionUtil.getMajor(), minor = ReflectionUtil.getMinor();
int major = ReflectionUtil.getMajor(), minor = ReflectionUtil.getMinor(), r = ReflectionUtil.getR();

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

Class<?> EnumGamemodeClass = ReflectionUtil.getNMSClass("EnumGamemode");

Object worldServer = getWorldServer(player);
Object gameMode = getEnumGamemode(EnumGamemodeClass, player);

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

Constructor<?> packetConstructor = ClientboundRespawnPacket.getConstructor(
ResourceKeyClass, // DimensionType
ResourceKeyClass, // DimensionKey
long.class, // Seed
EnumGamemodeClass, // gameType
EnumGamemodeClass, // previousGameType
boolean.class, // isDebug
boolean.class, // isFlat
boolean.class); // keepAllPlayerData
packet = packetConstructor.newInstance(
getTypeKey(WorldClass, worldServer),
getDimensionKey(WorldClass, worldServer),
player.getWorld().getSeed(),
gameMode,
gameMode,
false,
false,
true);
if(r >= 2) {

// 1.16.2+

Class<?> DimensionManagerClass = ReflectionUtil.getNMSClass("DimensionManager");

Constructor<?> packetConstructor = ClientboundRespawnPacket.getConstructor(
DimensionManagerClass, // DimensionManager
ResourceKeyClass, // DimensionKey
long.class, // Seed
EnumGamemodeClass, // gameType
EnumGamemodeClass, // previousGameType
boolean.class, // isDebug
boolean.class, // isFlat
boolean.class); // keepAllPlayerData
packet = packetConstructor.newInstance(
getDimensionManager1162Plus(WorldClass, worldServer),
getDimensionKey(WorldClass, worldServer),
player.getWorld().getSeed(),
gameMode,
gameMode,
false,
false,
true);

} else {

// 1.16.1

Constructor<?> packetConstructor = ClientboundRespawnPacket.getConstructor(
ResourceKeyClass, // DimensionType
ResourceKeyClass, // DimensionKey
long.class, // Seed
EnumGamemodeClass, // gameType
EnumGamemodeClass, // previousGameType
boolean.class, // isDebug
boolean.class, // isFlat
boolean.class); // keepAllPlayerData
packet = packetConstructor.newInstance(
getTypeKey(WorldClass, worldServer),
getDimensionKey(WorldClass, worldServer),
player.getWorld().getSeed(),
gameMode,
gameMode,
false,
false,
true);

}

} else if (minor >= 13) {

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ subprojects {

def major = '4'
def minor = '0'
def spongeRevision = '0'
def bukkitRevision = '0'
def spongeRevision = '1'
def bukkitRevision = '1'

def rev

Expand Down

0 comments on commit 681372c

Please sign in to comment.