-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor tests & universal SkinsRestorer integration
- Loading branch information
1 parent
b1fcbdb
commit cca5cc3
Showing
21 changed files
with
291 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 5 additions & 26 deletions
31
bukkit/src/main/java/com/azuriom/azlink/bukkit/integrations/SkinsRestorerIntegration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,23 @@ | ||
package com.azuriom.azlink.bukkit.integrations; | ||
|
||
import com.azuriom.azlink.bukkit.AzLinkBukkitPlugin; | ||
import net.skinsrestorer.api.SkinsRestorer; | ||
import net.skinsrestorer.api.SkinsRestorerProvider; | ||
import net.skinsrestorer.api.connections.model.MineSkinResponse; | ||
import net.skinsrestorer.api.exception.DataRequestException; | ||
import net.skinsrestorer.api.exception.MineSkinException; | ||
import com.azuriom.azlink.common.integrations.BaseSkinsRestorer; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerJoinEvent; | ||
|
||
public class SkinsRestorerIntegration implements Listener { | ||
|
||
private final AzLinkBukkitPlugin plugin; | ||
public class SkinsRestorerIntegration | ||
extends BaseSkinsRestorer<Player> implements Listener { | ||
|
||
public SkinsRestorerIntegration(AzLinkBukkitPlugin plugin) { | ||
this.plugin = plugin; | ||
|
||
this.plugin.getLoggerAdapter().info("SkinsRestorer integration enabled."); | ||
super(plugin.getPlugin(), Player.class); | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerJoin(PlayerJoinEvent e) { | ||
Player player = e.getPlayer(); | ||
String baseUrl = this.plugin.getPlugin().getConfig().getSiteUrl(); | ||
|
||
|
||
if (baseUrl == null) { | ||
return; | ||
} | ||
|
||
try { | ||
String url = baseUrl + "/api/skin-api/skins/" + player.getName(); | ||
SkinsRestorer skins = SkinsRestorerProvider.get(); | ||
MineSkinResponse res = skins.getMineSkinAPI().genSkin(url, null); | ||
|
||
skins.getSkinApplier(Player.class).applySkin(player, res.getProperty()); | ||
} catch (DataRequestException | MineSkinException ex) { | ||
this.plugin.getLoggerAdapter().warn("Unable to apply skin for " + player.getName() + ": " + ex.getMessage()); | ||
} | ||
handleJoin(player.getName(), player); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
bungee/src/main/java/com/azuriom/azlink/bungee/integrations/SkinsRestorerIntegration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.azuriom.azlink.bungee.integrations; | ||
|
||
import com.azuriom.azlink.bungee.AzLinkBungeePlugin; | ||
import com.azuriom.azlink.common.integrations.BaseSkinsRestorer; | ||
import net.md_5.bungee.api.connection.ProxiedPlayer; | ||
import net.md_5.bungee.api.event.PostLoginEvent; | ||
import net.md_5.bungee.api.plugin.Listener; | ||
import net.md_5.bungee.event.EventHandler; | ||
|
||
public class SkinsRestorerIntegration | ||
extends BaseSkinsRestorer<ProxiedPlayer> implements Listener { | ||
|
||
public SkinsRestorerIntegration(AzLinkBungeePlugin plugin) { | ||
super(plugin.getPlugin(), ProxiedPlayer.class); | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerJoin(PostLoginEvent event) { | ||
ProxiedPlayer player = event.getPlayer(); | ||
|
||
handleJoin(player.getName(), player); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# When enabled, if SkinsRestorer is installed, and the SkinAPI plugin is present on the website, | ||
# the player's skin will be updated to the website's skin | ||
skinsrestorer-integration: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
common/src/main/java/com/azuriom/azlink/common/integrations/BaseSkinsRestorer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.azuriom.azlink.common.integrations; | ||
|
||
import com.azuriom.azlink.common.AzLinkPlugin; | ||
import net.skinsrestorer.api.SkinsRestorer; | ||
import net.skinsrestorer.api.SkinsRestorerProvider; | ||
import net.skinsrestorer.api.connections.model.MineSkinResponse; | ||
import net.skinsrestorer.api.exception.DataRequestException; | ||
import net.skinsrestorer.api.exception.MineSkinException; | ||
|
||
public class BaseSkinsRestorer<P> { | ||
|
||
private final Class<P> playerClass; | ||
protected final AzLinkPlugin plugin; | ||
|
||
public BaseSkinsRestorer(AzLinkPlugin plugin, Class<P> playerClass) { | ||
this.plugin = plugin; | ||
this.playerClass = playerClass; | ||
|
||
this.plugin.getLogger().info("SkinsRestorer integration enabled."); | ||
} | ||
|
||
protected void handleJoin(String playerName, P player) { | ||
String baseUrl = this.plugin.getConfig().getSiteUrl(); | ||
|
||
if (baseUrl == null) { | ||
return; | ||
} | ||
|
||
try { | ||
String url = baseUrl + "/api/skin-api/skins/" + playerName; | ||
SkinsRestorer skins = SkinsRestorerProvider.get(); | ||
MineSkinResponse res = skins.getMineSkinAPI().genSkin(url, null); | ||
|
||
skins.getSkinApplier(this.playerClass).applySkin(player, res.getProperty()); | ||
} catch (DataRequestException | MineSkinException ex) { | ||
this.plugin.getLogger().warn("Unable to apply skin for " + playerName + ": " + ex.getMessage()); | ||
} | ||
} | ||
} |
78 changes: 40 additions & 38 deletions
78
common/src/test/java/com/azuriom/azlink/common/HashTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,54 @@ | ||
package com.azuriom.azlink.common; | ||
|
||
import com.azuriom.azlink.common.utils.Hash; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class HashTest { | ||
import java.util.stream.Stream; | ||
|
||
private static final String VALUE_1 = "H5vBfLcF3vqaCo8"; | ||
private static final String VALUE_2 = "YCJLMo7uX5t7WxG"; | ||
private static final String VALUE_3 = "g3kmfbpwfHdDFQL"; | ||
|
||
@Test | ||
public void testSha256() { | ||
Hash hash = Hash.SHA_256; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
String expected1 = "e936363862ca96e0866afaa51ce622959a626938b1328a6a03921941989922fb"; | ||
String expected2 = "35d729f6ab4c9abe9409bbdca2896eba1bc4608dab2e0f80fece72a67002866b"; | ||
String expected3 = "cfa211834f280d238965a6d4afa15c8851b3286ee0cec146dd6a598e389568e3"; | ||
class HashTest { | ||
|
||
assertEquals(expected1, hash.hash(VALUE_1)); | ||
assertEquals(expected2, hash.hash(VALUE_2)); | ||
assertEquals(expected3, hash.hash(VALUE_3)); | ||
@ParameterizedTest | ||
@MethodSource("hashTestData") | ||
void testSha256(String[] data) { | ||
assertEquals(data[1], Hash.SHA_256.hash(data[0])); | ||
} | ||
|
||
@Test | ||
public void testSha384() { | ||
Hash hash = Hash.SHA_384; | ||
|
||
String expected1 = "ad7e3d46584ebcfff0c420e0b7e40b1c612f0f46d94054af2dcbf0f65a148ec47e56461ec93073f6b35c24aafd8906dc"; | ||
String expected2 = "1e49c84bc3b4d827fafef3fe7ef34966d5884ebe1bf814d6ec71d05cb530889fe196ed8a184c82377b566c8bfd95ebdd"; | ||
String expected3 = "96b714d99c039829328275f3b90fa5abe304e4d78ed8114292ab0d16e9c1e636c57d763aae11f8490b2cd8216c5b64c2"; | ||
|
||
assertEquals(expected1, hash.hash(VALUE_1)); | ||
assertEquals(expected2, hash.hash(VALUE_2)); | ||
assertEquals(expected3, hash.hash(VALUE_3)); | ||
@ParameterizedTest | ||
@MethodSource("hashTestData") | ||
void testSha384(String[] data) { | ||
assertEquals(data[2], Hash.SHA_384.hash(data[0])); | ||
} | ||
|
||
@Test | ||
public void testSha512() { | ||
Hash hash = Hash.SHA_512; | ||
|
||
String expected1 = "754d79ec450e8f1090aba4b0c25e9a0602d351561cb6f39c902ad3a9e779dbaf2d7ae194dde3d35492530f77566fc90d0137027f3fdf8fa560c8d19ed73767ec"; | ||
String expected2 = "c4c940c69bf0cbd24057d409be393373e26593d5b0ac8117c49c929a17131defe321dea2589664e75c438e0bf0635074a91ee3f4fbb3d3e3b211f9771587fdee"; | ||
String expected3 = "370ca5636ecbabe0f992dae196fe79cadeddea736a712a3cca5c9417bdffc252e26636e6e1d0a08c35ee10f28f5c88fa165935e0d5bc8ce480a14ee6b8950f61"; | ||
@ParameterizedTest | ||
@MethodSource("hashTestData") | ||
void testSha512(String[] data) { | ||
assertEquals(data[3], Hash.SHA_512.hash(data[0])); | ||
} | ||
|
||
assertEquals(expected1, hash.hash(VALUE_1)); | ||
assertEquals(expected2, hash.hash(VALUE_2)); | ||
assertEquals(expected3, hash.hash(VALUE_3)); | ||
private static Stream<Arguments> hashTestData() { | ||
String[] test1 = { | ||
"H5vBfLcF3vqaCo8", | ||
"e936363862ca96e0866afaa51ce622959a626938b1328a6a03921941989922fb", | ||
"ad7e3d46584ebcfff0c420e0b7e40b1c612f0f46d94054af2dcbf0f65a148ec47e56461ec93073f6b35c24aafd8906dc", | ||
"754d79ec450e8f1090aba4b0c25e9a0602d351561cb6f39c902ad3a9e779dbaf2d7ae194dde3d35492530f77566fc90d0137027f3fdf8fa560c8d19ed73767ec", | ||
}; | ||
String[] test2 = { | ||
"YCJLMo7uX5t7WxG", | ||
"35d729f6ab4c9abe9409bbdca2896eba1bc4608dab2e0f80fece72a67002866b", | ||
"1e49c84bc3b4d827fafef3fe7ef34966d5884ebe1bf814d6ec71d05cb530889fe196ed8a184c82377b566c8bfd95ebdd", | ||
"c4c940c69bf0cbd24057d409be393373e26593d5b0ac8117c49c929a17131defe321dea2589664e75c438e0bf0635074a91ee3f4fbb3d3e3b211f9771587fdee", | ||
}; | ||
String[] test3 = { | ||
"g3kmfbpwfHdDFQL", | ||
"cfa211834f280d238965a6d4afa15c8851b3286ee0cec146dd6a598e389568e3", | ||
"96b714d99c039829328275f3b90fa5abe304e4d78ed8114292ab0d16e9c1e636c57d763aae11f8490b2cd8216c5b64c2", | ||
"370ca5636ecbabe0f992dae196fe79cadeddea736a712a3cca5c9417bdffc252e26636e6e1d0a08c35ee10f28f5c88fa165935e0d5bc8ce480a14ee6b8950f61", | ||
}; | ||
|
||
return Stream.of(test1, test2, test3).map(s -> Arguments.of((Object) s)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 17 additions & 13 deletions
30
common/src/test/java/com/azuriom/azlink/common/UpdateCheckerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
package com.azuriom.azlink.common; | ||
|
||
import com.azuriom.azlink.common.utils.UpdateChecker; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class UpdateCheckerTest { | ||
class UpdateCheckerTest { | ||
|
||
@Test | ||
public void testCompareVersions() { | ||
assertEquals(0, UpdateChecker.compareVersions("1.2", "1.2.0")); | ||
assertEquals(0, UpdateChecker.compareVersions("1.2.1", "1.2.1")); | ||
assertEquals(1, UpdateChecker.compareVersions("1.2.1", "1.2.0")); | ||
assertEquals(1, UpdateChecker.compareVersions("1.2.1", "1.2")); | ||
assertEquals(1, UpdateChecker.compareVersions("1.2.1", "0.8.1")); | ||
assertEquals(-1, UpdateChecker.compareVersions("0.9", "1.0.1")); | ||
assertEquals(-1, UpdateChecker.compareVersions("1.0.1", "1.10")); | ||
assertEquals(-1, UpdateChecker.compareVersions("1.0.1", "1.10.0")); | ||
assertEquals(-1, UpdateChecker.compareVersions("1.1.2", "1.2.0")); | ||
@ParameterizedTest | ||
@CsvSource({ | ||
"0, 1.2, 1.2.0", | ||
"0, 1.2.1, 1.2.1", | ||
"1, 1.2.1, 1.2.0", | ||
"1, 1.2.1, 1.2", | ||
"1, 1.2.1, 0.8.1", | ||
"-1, 0.9, 1.0.1", | ||
"-1, 1.0.1, 1.10.0", | ||
"-1, 1.0.1, 1.10.0", | ||
"-1, 1.1.2, 1.2.0", | ||
}) | ||
void testCompareVersions(int expected, String ver1, String ver2) { | ||
assertEquals(expected, UpdateChecker.compareVersions(ver1, ver2)); | ||
} | ||
} |
Oops, something went wrong.