Skip to content

Commit

Permalink
Update to 1.16.1, API breaking changes.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dscalzi committed Jun 25, 2020
1 parent b18df2d commit 15c6f88
Show file tree
Hide file tree
Showing 28 changed files with 344 additions and 265 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

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

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![# Header](http://i.imgur.com/6TxDQ3W.png?1)

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

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

Expand Down Expand Up @@ -102,15 +102,15 @@ public void skychangerTests(Player player) {

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

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

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

if(result2) {
player.sendMessage("Why did the sky turn light blue?");
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.15.2-R0.1-SNAPSHOT'
compileOnly 'org.spigotmc:spigot-api:1.16.1-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 @@ -39,12 +39,14 @@ public final class ReflectionUtil {

private final static Map<String, Class<?>> nmsClasses;
private final static Map<String, Class<?>> ocbClasses;
private final static Map<Class<?>, Map<String, Class<?>>> declaredClasses;

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

static {
nmsClasses = new HashMap<>();
ocbClasses = new HashMap<>();
declaredClasses = new HashMap<>();
cachedMethods = new HashMap<>();
}

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

public static Class<?> getDeclaredClass(Class<?> origin, String className) {
if (!declaredClasses.containsKey(origin))
declaredClasses.put(origin, new HashMap<>());

Map<String, Class<?>> classMap = declaredClasses.get(origin);

if (classMap.containsKey(className))
return classMap.get(className);

for(Class<?> clazz : origin.getDeclaredClasses()) {
if(clazz.getSimpleName().equals(className)) {
classMap.put(className, clazz);
declaredClasses.put(origin, classMap);
return clazz;
}
}

classMap.put(className, null);
declaredClasses.put(origin, classMap);
return null;
}

public static Method getMethod(Class<?> clazz, String methodName, Class<?>... params) {
if (!cachedMethods.containsKey(clazz))
cachedMethods.put(clazz, new HashMap<String, Method>());
cachedMethods.put(clazz, new HashMap<>());

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

Expand Down
Loading

0 comments on commit 15c6f88

Please sign in to comment.