Skip to content

Commit 15c6f88

Browse files
committed
Update to 1.16.1, API breaking changes.
Added support for 1.16.1. Sky color changes working. Freeze partially working. The freeze is only successful randomly. So it works, but not all the time. Refactored Bukkit SkyChangeImpl to contain less duplicate code and have it easier to maintain as new versions roll out. Added a function to ReflectionUtil which can retrieve and cache declared classes. API BREAKING CHANGES Renamed the SkyPacket enums to be more in line with what they actually represent. FADE_VALUE -> RAIN_LEVEL_CHANGE FADE_TIME -> THUNDER_LEVEL_CHANGE. Command usage remains the same.
1 parent b18df2d commit 15c6f88

28 files changed

+344
-265
lines changed

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017-2018 Daniel D. Scalzi
3+
Copyright (c) 2017-2020 Daniel D. Scalzi
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![# Header](http://i.imgur.com/6TxDQ3W.png?1)
22

3-
[<img src="https://ci.appveyor.com/api/projects/status/3j1tc074rvi6a3mr?retina=true" height='20.74px'></img>](https://ci.appveyor.com/project/dscalzi/skychanger) [![](https://pluginbadges.glitch.me/api/v1/dl/Downloads-limegreen.svg?bukkit=skychanger&spigot=skychanger.37524&ore=skychanger&github=dscalzi/SkyChanger&style=flat)](https://github.com/dscalzi/PluginBadges) [![](https://img.shields.io/github/license/dscalzi/SkyChanger.svg)](https://github.com/dscalzi/SkyChanger/blob/master/LICENSE.txt) ![](https://img.shields.io/badge/Spigot-1.8.x--1.15.x-orange.svg) [![](https://discordapp.com/api/guilds/211524927831015424/widget.png)](https://discordapp.com/invite/Fcrh6PT)
3+
[<img src="https://ci.appveyor.com/api/projects/status/3j1tc074rvi6a3mr?retina=true" height='20.74px'></img>](https://ci.appveyor.com/project/dscalzi/skychanger) [![](https://pluginbadges.glitch.me/api/v1/dl/Downloads-limegreen.svg?bukkit=skychanger&spigot=skychanger.37524&ore=skychanger&github=dscalzi/SkyChanger&style=flat)](https://github.com/dscalzi/PluginBadges) [![](https://img.shields.io/github/license/dscalzi/SkyChanger.svg)](https://github.com/dscalzi/SkyChanger/blob/master/LICENSE.txt) ![](https://img.shields.io/badge/Spigot-1.8.x--1.16.x-orange.svg) [![](https://discordapp.com/api/guilds/211524927831015424/widget.png)](https://discordapp.com/invite/Fcrh6PT)
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

@@ -102,15 +102,15 @@ public void skychangerTests(Player player) {
102102

103103
// Change the sky and save the result.
104104
// Equivalent to /SkyChanger 3
105-
boolean result1 = api.changeSky(SkyChanger.wrapPlayer(player), SkyPacket.FADE_VALUE, 3F);
105+
boolean result1 = api.changeSky(SkyChanger.wrapPlayer(player), SkyPacket.RAIN_LEVEL_CHANGE, 3F);
106106

107107
if(result1) {
108108
player.sendMessage("Why did the sky turn red?");
109109
}
110110

111111
// Equivalent to /SkyChanger 4 8
112-
boolean result2 = api.changeSky(SkyChanger.wrapPlayer(player), SkyPacket.FADE_VALUE, 4F)
113-
&& api.changeSky(SkyChanger.wrapPlayer(player), SkyPacket.FADE_TIME, 8F);
112+
boolean result2 = api.changeSky(SkyChanger.wrapPlayer(player), SkyPacket.RAIN_LEVEL_CHANGE, 4F)
113+
&& api.changeSky(SkyChanger.wrapPlayer(player), SkyPacket.THUNDER_LEVEL_CHANGE, 8F);
114114

115115
if(result2) {
116116
player.sendMessage("Why did the sky turn light blue?");

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.15.2-R0.1-SNAPSHOT'
14+
compileOnly 'org.spigotmc:spigot-api:1.16.1-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: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ public final class ReflectionUtil {
3939

4040
private final static Map<String, Class<?>> nmsClasses;
4141
private final static Map<String, Class<?>> ocbClasses;
42+
private final static Map<Class<?>, Map<String, Class<?>>> declaredClasses;
4243

4344
private final static Map<Class<?>, Map<String, Method>> cachedMethods;
4445

4546
static {
4647
nmsClasses = new HashMap<>();
4748
ocbClasses = new HashMap<>();
49+
declaredClasses = new HashMap<>();
4850
cachedMethods = new HashMap<>();
4951
}
5052

@@ -111,9 +113,31 @@ public static Class<?> getOCBClass(String localPackage) {
111113
return clazz;
112114
}
113115

116+
public static Class<?> getDeclaredClass(Class<?> origin, String className) {
117+
if (!declaredClasses.containsKey(origin))
118+
declaredClasses.put(origin, new HashMap<>());
119+
120+
Map<String, Class<?>> classMap = declaredClasses.get(origin);
121+
122+
if (classMap.containsKey(className))
123+
return classMap.get(className);
124+
125+
for(Class<?> clazz : origin.getDeclaredClasses()) {
126+
if(clazz.getSimpleName().equals(className)) {
127+
classMap.put(className, clazz);
128+
declaredClasses.put(origin, classMap);
129+
return clazz;
130+
}
131+
}
132+
133+
classMap.put(className, null);
134+
declaredClasses.put(origin, classMap);
135+
return null;
136+
}
137+
114138
public static Method getMethod(Class<?> clazz, String methodName, Class<?>... params) {
115139
if (!cachedMethods.containsKey(clazz))
116-
cachedMethods.put(clazz, new HashMap<String, Method>());
140+
cachedMethods.put(clazz, new HashMap<>());
117141

118142
Map<String, Method> methods = cachedMethods.get(clazz);
119143

0 commit comments

Comments
 (0)