fix(git): correct dependencies
This commit is contained in:
parent
e6e716d951
commit
3185886ead
46 changed files with 23 additions and 15 deletions
|
@ -1,118 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<artifactId>nicko-parent</artifactId>
|
||||
<groupId>net.artelnatif</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>nicko-core</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}/src/main/resources/</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12.4</version>
|
||||
<configuration>
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.3.1-SNAPSHOT</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>net.artelnatif:nicko-*</include>
|
||||
<include>xyz.upperlevel.spigot.book:spigot-book-api</include>
|
||||
<include>net.wesjd:anvilgui</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>xyz.upperlevel.spigot.book</pattern>
|
||||
<shadedPattern>net.artelnatif.bookapi</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>net.wesjd.anvilgui</pattern>
|
||||
<shadedPattern>net.artelnatif.anvilgui</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<minimizeJar>false</minimizeJar>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>bungeecord-repo</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>codemc-snapshots</id>
|
||||
<url>https://repo.codemc.io/repository/maven-snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.18.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.18-R0.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>31.1-jre</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.8.2</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>opentest4j</artifactId>
|
||||
<groupId>org.opentest4j</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>junit-platform-commons</artifactId>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>apiguardian-api</artifactId>
|
||||
<groupId>org.apiguardian</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
</properties>
|
||||
</project>
|
124
core/pom.xml
124
core/pom.xml
|
@ -1,124 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>nicko-core</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>net.artelnatif</groupId>
|
||||
<artifactId>nicko-parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>bungeecord-repo</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>codemc-snapshots</id>
|
||||
<url>https://repo.codemc.io/repository/maven-snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.18.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.18-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>xyz.upperlevel.spigot.book</groupId>
|
||||
<artifactId>spigot-book-api</artifactId>
|
||||
<version>1.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.wesjd</groupId>
|
||||
<artifactId>anvilgui</artifactId>
|
||||
<version>1.5.3-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>31.1-jre</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.8.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12.4</version>
|
||||
<configuration>
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.3.1-SNAPSHOT</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>net.artelnatif:nicko-*</include>
|
||||
<include>xyz.upperlevel.spigot.book:spigot-book-api</include>
|
||||
<include>net.wesjd:anvilgui</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>xyz.upperlevel.spigot.book</pattern>
|
||||
<shadedPattern>net.artelnatif.bookapi</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>net.wesjd.anvilgui</pattern>
|
||||
<shadedPattern>net.artelnatif.anvilgui</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<!-- Prevents breaking AnvilGUI's VersionWrapper. -->
|
||||
<minimizeJar>false</minimizeJar>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<filtering>true</filtering>
|
||||
<directory>${basedir}/src/main/resources/</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
</project>
|
|
@ -1,104 +0,0 @@
|
|||
package com.yoshiplex.rainbow;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class RainbowText {
|
||||
private static final List<String> RAINBOW = Arrays.asList("§4", "§c", "§6", "§a", "§2", "§b", "§3", "§9", "§1", "§5", "§d");
|
||||
private int place;
|
||||
private List<String> rainbowArray = null;
|
||||
// STOPSHIP: 7/28/22 i18n
|
||||
private String text = "You did not provide any text.";
|
||||
private String fancyText = "§4You did not provide any text";
|
||||
private String prefix = "";
|
||||
|
||||
public RainbowText(String text) {
|
||||
this(text, (String) null);
|
||||
}
|
||||
|
||||
public RainbowText(String text, String formatCode) {
|
||||
place = 0;
|
||||
if (text != null) {
|
||||
this.text = text;
|
||||
}
|
||||
if (formatCode != null) {
|
||||
prefix = formatCode;
|
||||
}
|
||||
rainbowArray = RAINBOW;
|
||||
updateFancy();
|
||||
}
|
||||
|
||||
private void updateFancy() {
|
||||
int spot = place;
|
||||
String fancyText = "";
|
||||
for (char l : text.toCharArray()) {
|
||||
String letter = Character.toString(l);
|
||||
String t1 = fancyText;
|
||||
if (!letter.equalsIgnoreCase(" ")) {
|
||||
fancyText = t1 + rainbowArray.get(spot) + prefix + letter;
|
||||
if (spot == rainbowArray.size() - 1) {
|
||||
spot = 0;
|
||||
} else {
|
||||
spot++;
|
||||
}
|
||||
} else {
|
||||
fancyText = t1 + letter;
|
||||
}
|
||||
}
|
||||
this.fancyText = fancyText;
|
||||
}
|
||||
|
||||
public void moveRainbow() {
|
||||
if (rainbowArray.size() - 1 == place) {
|
||||
place = 0;
|
||||
} else {
|
||||
place++;
|
||||
}
|
||||
updateFancy();
|
||||
}
|
||||
|
||||
public void moveRainbowRight() {
|
||||
if (place == 0) {
|
||||
place = rainbowArray.size() - 1;
|
||||
} else {
|
||||
place--;
|
||||
}
|
||||
updateFancy();
|
||||
}
|
||||
|
||||
public String getOrigonalText() {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return this.fancyText;
|
||||
}
|
||||
|
||||
public void setPlace(int place) {
|
||||
if (place > RAINBOW.size() - 1 || place < 0) {
|
||||
return;
|
||||
}
|
||||
this.place = place;
|
||||
updateFancy();
|
||||
}
|
||||
|
||||
public int getPlace() {
|
||||
return this.place;
|
||||
}
|
||||
|
||||
public List<String> getRainbow() {
|
||||
return rainbowArray;
|
||||
}
|
||||
|
||||
public String getFormatPrefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
public void setFormatPrefix(String prefix) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public static List<String> getDefaultRainbow() {
|
||||
return RAINBOW;
|
||||
}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
package net.artelnatif.nicko;
|
||||
|
||||
import net.artelnatif.nicko.bungee.NickoBungee;
|
||||
import net.artelnatif.nicko.command.NickoCommand;
|
||||
import net.artelnatif.nicko.command.NickoTabCompleter;
|
||||
import net.artelnatif.nicko.config.NickoConfiguration;
|
||||
import net.artelnatif.nicko.event.PlayerJoinListener;
|
||||
import net.artelnatif.nicko.event.PlayerQuitListener;
|
||||
import net.artelnatif.nicko.impl.Internals;
|
||||
import net.artelnatif.nicko.impl.InternalsProvider;
|
||||
import net.artelnatif.nicko.mojang.MojangAPI;
|
||||
import net.artelnatif.nicko.pluginchannel.UpdateMessageHandler;
|
||||
import net.artelnatif.nicko.storage.PlayerDataStore;
|
||||
import net.artelnatif.nicko.utils.ServerUtils;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class NickoBukkit extends JavaPlugin {
|
||||
private static NickoBukkit plugin;
|
||||
|
||||
private NickoConfiguration nickoConfiguration;
|
||||
private MojangAPI mojangAPI;
|
||||
private PlayerDataStore dataStore;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
mojangAPI = new MojangAPI();
|
||||
nickoConfiguration = new NickoConfiguration(this);
|
||||
dataStore = new PlayerDataStore(this);
|
||||
|
||||
getLogger().info("Loading internals...");
|
||||
if (getInternals() == null) {
|
||||
getLogger().log(Level.SEVERE, "Nicko could not find a valid implementation for this server version. Is your server supported?");
|
||||
dataStore.getStorage().setError(true);
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
|
||||
if (getServer().getPluginManager().isPluginEnabled(this)) {
|
||||
final PluginCommand command = getCommand("nicko");
|
||||
if (command != null) {
|
||||
command.setExecutor(new NickoCommand());
|
||||
command.setTabCompleter(new NickoTabCompleter());
|
||||
}
|
||||
|
||||
getServer().getPluginManager().registerEvents(new PlayerJoinListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerQuitListener(), this);
|
||||
|
||||
getLogger().info("Loading configuration...");
|
||||
saveDefaultConfig();
|
||||
|
||||
getLogger().info("Loading persistence...");
|
||||
|
||||
if (!dataStore.getStorage().getProvider().init()) {
|
||||
dataStore.getStorage().setError(true);
|
||||
getLogger().warning("Failed to open persistence, data will NOT be saved!");
|
||||
}
|
||||
|
||||
if (nickoConfiguration.isBungeecordEnabled()) {
|
||||
getLogger().info("Enabling Bungeecord support...");
|
||||
if (ServerUtils.checkBungeeCordHook()) {
|
||||
getServer().getMessenger().registerIncomingPluginChannel(this, NickoBungee.NICKO_PLUGIN_CHANNEL_UPDATE, new UpdateMessageHandler());
|
||||
}
|
||||
}
|
||||
|
||||
getLogger().info("Nicko (Bukkit) has been enabled.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (!dataStore.getStorage().isError()) {
|
||||
getLogger().info("Closing persistence...");
|
||||
if (!dataStore.getStorage().getProvider().close()) {
|
||||
getLogger().warning("Failed to close persistence!");
|
||||
}
|
||||
dataStore.getStorage().setError(false);
|
||||
}
|
||||
|
||||
if (nickoConfiguration.isBungeecordEnabled()) {
|
||||
getServer().getMessenger().unregisterIncomingPluginChannel(this);
|
||||
getServer().getMessenger().unregisterOutgoingPluginChannel(this);
|
||||
}
|
||||
|
||||
getLogger().info("Nicko (Bukkit) has been disabled.");
|
||||
}
|
||||
|
||||
public static NickoBukkit getInstance() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public MojangAPI getMojangAPI() {
|
||||
return mojangAPI;
|
||||
}
|
||||
|
||||
public NickoConfiguration getNickoConfig() { return nickoConfiguration; }
|
||||
|
||||
public PlayerDataStore getDataStore() { return dataStore; }
|
||||
|
||||
public Internals getInternals() {
|
||||
return InternalsProvider.getInternals();
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
package net.artelnatif.nicko.anvil;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.AppearanceManager;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import net.artelnatif.nicko.mojang.MojangUtils;
|
||||
import net.wesjd.anvilgui.AnvilGUI;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class AnvilManager {
|
||||
private final Player player;
|
||||
private final NickoProfile profile;
|
||||
private final AppearanceManager appearanceManager;
|
||||
|
||||
public AnvilManager(Player player) {
|
||||
this.player = player;
|
||||
this.appearanceManager = AppearanceManager.get(player);
|
||||
this.profile = appearanceManager.getProfile();
|
||||
}
|
||||
|
||||
public void openNameAndSkinAnvil() {
|
||||
final AnvilGUI.Builder skin = getSkinAnvil();
|
||||
final AnvilGUI.Builder name = new AnvilGUI.Builder()
|
||||
.plugin(NickoBukkit.getInstance())
|
||||
.itemLeft(getLeftItem())
|
||||
.onComplete((anvilPlayer, response) -> {
|
||||
if (MojangUtils.isUsernameInvalid(response)) {
|
||||
return AnvilGUI.Response.text("Invalid username!");
|
||||
} else {
|
||||
profile.setName(response);
|
||||
skin.open(player);
|
||||
return AnvilGUI.Response.close();
|
||||
}
|
||||
})
|
||||
.text("New name...");
|
||||
|
||||
name.open(player);
|
||||
}
|
||||
|
||||
public void openNameAnvil() {
|
||||
new AnvilGUI.Builder()
|
||||
.plugin(NickoBukkit.getInstance())
|
||||
.itemLeft(getLeftItem())
|
||||
.onComplete((anvilPlayer, response) -> {
|
||||
if (MojangUtils.isUsernameInvalid(response)) {
|
||||
return AnvilGUI.Response.text("Invalid username!");
|
||||
} else {
|
||||
appearanceManager.setName(response);
|
||||
appearanceManager.updatePlayer(false);
|
||||
return AnvilGUI.Response.close();
|
||||
}
|
||||
})
|
||||
.text("New name...")
|
||||
.open(player);
|
||||
}
|
||||
|
||||
public void openSkinAnvil() {
|
||||
getSkinAnvil().open(player);
|
||||
}
|
||||
|
||||
private AnvilGUI.Builder getSkinAnvil() {
|
||||
return new AnvilGUI.Builder()
|
||||
.plugin(NickoBukkit.getInstance())
|
||||
.itemLeft(getLeftItem())
|
||||
.onComplete((anvilPlayer, response) -> {
|
||||
if (MojangUtils.isUsernameInvalid(response)) {
|
||||
return AnvilGUI.Response.text("Invalid username!");
|
||||
} else {
|
||||
appearanceManager.setSkin(response);
|
||||
appearanceManager.updatePlayer(true);
|
||||
return AnvilGUI.Response.close();
|
||||
}
|
||||
})
|
||||
.text("New skin...");
|
||||
}
|
||||
|
||||
private ItemStack getLeftItem() {
|
||||
final ItemStack item = new ItemStack(Material.PAPER);
|
||||
final ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName("§0ID");
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package net.artelnatif.nicko.bungee;
|
||||
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
public class NickoBungee extends Plugin {
|
||||
public static final String NICKO_PLUGIN_CHANNEL_BASE = "nicko:";
|
||||
public static final String NICKO_PLUGIN_CHANNEL_FETCH = NICKO_PLUGIN_CHANNEL_BASE + "fetch";
|
||||
public static final String NICKO_PLUGIN_CHANNEL_UPDATE = NICKO_PLUGIN_CHANNEL_BASE + "update";
|
||||
|
||||
private static NickoBungee plugin;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getLogger().info("Registering channels...");
|
||||
getProxy().registerChannel(NICKO_PLUGIN_CHANNEL_FETCH);
|
||||
getProxy().registerChannel(NICKO_PLUGIN_CHANNEL_UPDATE);
|
||||
|
||||
getLogger().info("Nicko (Bungee) has been enabled.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
getLogger().info("Unregistering channels...");
|
||||
getProxy().unregisterChannel(NICKO_PLUGIN_CHANNEL_FETCH);
|
||||
getProxy().unregisterChannel(NICKO_PLUGIN_CHANNEL_UPDATE);
|
||||
|
||||
getLogger().info("Nicko (Bungee) has been disabled.");
|
||||
}
|
||||
|
||||
public static NickoBungee getInstance() {
|
||||
return plugin;
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package net.artelnatif.nicko.bungee.event;
|
||||
|
||||
import net.artelnatif.nicko.bungee.NickoBungee;
|
||||
import net.artelnatif.nicko.bungee.pluginchannel.PluginChannelHelper;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
import net.md_5.bungee.api.event.ServerSwitchEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
public class ServerSwitchListener implements Listener {
|
||||
|
||||
/*
|
||||
* Nicko Message Format
|
||||
* FETCH: nicko:skin/fetch
|
||||
* - UUID
|
||||
*
|
||||
* UPDATE: nicko:skin/update
|
||||
* - UUID
|
||||
* - Skin
|
||||
* - Name
|
||||
*/
|
||||
|
||||
@EventHandler
|
||||
public void onSwitch(ServerSwitchEvent event) {
|
||||
final ServerInfo from = event.getFrom();
|
||||
final ProxiedPlayer player = event.getPlayer();
|
||||
final Server to = player.getServer();
|
||||
PluginChannelHelper.sendMessage(from, NickoBungee.NICKO_PLUGIN_CHANNEL_FETCH, player.getUniqueId().toString());
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package net.artelnatif.nicko.bungee.pluginchannel;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
|
||||
public class PluginChannelHelper {
|
||||
public static boolean sendMessage(final ServerInfo info, final String channel, final String... data) {
|
||||
final ByteArrayDataOutput output = ByteStreams.newDataOutput();
|
||||
output.writeUTF(channel);
|
||||
for (String elt : data) {
|
||||
output.writeUTF(elt);
|
||||
}
|
||||
System.out.printf("(%s) PluginMessage <-> %s", info.getSocketAddress().toString(), output);
|
||||
return info.sendData(channel, output.toByteArray(), false);
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
package net.artelnatif.nicko.command;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.command.sub.NickoCheckSubCmd;
|
||||
import net.artelnatif.nicko.command.sub.NickoDebugSubCmd;
|
||||
import net.artelnatif.nicko.command.sub.NickoDisguiseSubCmd;
|
||||
import net.artelnatif.nicko.command.sub.NickoGUISubCmd;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
|
||||
public class NickoCommand implements CommandExecutor {
|
||||
private final String opPrefix = "§c(OP)";
|
||||
private String helpMessage = """
|
||||
§cNicko §8§o[{version}] §f- §2Help:
|
||||
§6/nicko disguise §f- §7Change your appearance.
|
||||
§6/nicko revert §f- §7Revert your appearance to your default skin and name.
|
||||
§6/nicko help §f- §7Prints this help message.
|
||||
""";
|
||||
private String adminHelpMessage = """
|
||||
{admin} §6/nicko disguise §b<player> §f- §7Change designed player's appearance.
|
||||
{admin} §6/nicko revert §b<player> §f- §7Revert designed player's appearance to their default skin and name.
|
||||
{admin} §6/nicko check §b<player> §f- §7Prints detailed information about designed player's appearance.
|
||||
""".replace("{admin}", opPrefix);
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length >= 1) {
|
||||
switch (args[0]) {
|
||||
case "disguise" -> new NickoDisguiseSubCmd(this).execute(sender);
|
||||
case "debug" -> new NickoDebugSubCmd(this).execute(sender, args);
|
||||
case "check" -> new NickoCheckSubCmd(this).execute(sender, args);
|
||||
case "gui" -> new NickoGUISubCmd(this).execute(sender, args);
|
||||
default -> sendHelpMessages(sender);
|
||||
}
|
||||
} else {
|
||||
sendHelpMessages(sender);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void sendHelpMessages(CommandSender sender) {
|
||||
helpMessage = helpMessage.replace("{version}", NickoBukkit.getInstance().getDescription().getVersion());
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
helpMessage = ChatColor.stripColor(helpMessage);
|
||||
adminHelpMessage = ChatColor.stripColor(adminHelpMessage);
|
||||
}
|
||||
sender.sendMessage(helpMessage);
|
||||
if (sender.isOp()) {
|
||||
sender.sendMessage(adminHelpMessage);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package net.artelnatif.nicko.command;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
|
||||
public class NickoPermissions {
|
||||
|
||||
public static final String NICKO_PERMISSION_BASE = "nicko.";
|
||||
// TODO: 20/06/2022 i18n
|
||||
public static final String NICKO_PERMISSION_MISSING = NickoBukkit.getInstance().getNickoConfig().getPrefix() + "§cMissing permission.";
|
||||
|
||||
public static final class Player {
|
||||
public static final class Command {
|
||||
public static final String NICKO_PERMISSION_PLAYER_COMMAND_USE = NICKO_PERMISSION_BASE + "use";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package net.artelnatif.nicko.command;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class NickoTabCompleter implements TabCompleter {
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
if (args.length == 1) {
|
||||
return List.of("disguise", "revert", "help", "check");
|
||||
} else if (args.length == 2 && !args[0].equalsIgnoreCase("help")) {
|
||||
return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).toList();
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package net.artelnatif.nicko.command.sub;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.command.NickoCommand;
|
||||
import net.artelnatif.nicko.disguise.AppearanceManager;
|
||||
import net.artelnatif.nicko.utils.PlayerUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public class NickoCheckSubCmd extends NickoSubCmd {
|
||||
public NickoCheckSubCmd(NickoCommand nickoCommand) {
|
||||
super(nickoCommand);
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
final String targetName = args[1];
|
||||
final Player target = Bukkit.getPlayerExact(targetName);
|
||||
|
||||
AppearanceManager appearanceManager;
|
||||
if (PlayerUtils.isPlayerOffline(target)) {
|
||||
appearanceManager = AppearanceManager.get(targetName);
|
||||
} else {
|
||||
appearanceManager = AppearanceManager.get(target);
|
||||
}
|
||||
|
||||
final StringJoiner builder = new StringJoiner("\n");
|
||||
builder.add("§c" + NickoBukkit.getInstance().getNickoConfig().getPrefix() + "§f- §6Check for:§f§o" + targetName);
|
||||
if (!appearanceManager.hasData()) {
|
||||
builder.add("§cThis player has not data.");
|
||||
} else {
|
||||
builder.add("§7- §fNicked: " + (appearanceManager.isNicked() ? "§a✔" : "§c❌"));
|
||||
builder.add("§7- §fNickname: §6" + (appearanceManager.getName().equals(targetName) ? "N/A" : appearanceManager.getName()));
|
||||
builder.add("§7- §fSkin: §6" + (appearanceManager.getSkin().equals(targetName) ? "N/A" : appearanceManager.getSkin()));
|
||||
}
|
||||
|
||||
sender.sendMessage(builder.toString());
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package net.artelnatif.nicko.command.sub;
|
||||
|
||||
import com.yoshiplex.rainbow.RainbowText;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.command.NickoCommand;
|
||||
import net.artelnatif.nicko.disguise.AppearanceManager;
|
||||
import net.artelnatif.nicko.mojang.MojangUtils;
|
||||
import net.artelnatif.nicko.utils.PlayerUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class NickoDebugSubCmd extends NickoSubCmd {
|
||||
|
||||
public NickoDebugSubCmd(NickoCommand nickoCommand) {
|
||||
super(nickoCommand);
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
Player target;
|
||||
String name, skin;
|
||||
if (args.length == 3) {
|
||||
target = (Player) sender;
|
||||
name = args[1];
|
||||
skin = args[2];
|
||||
} else {
|
||||
final String playerName = args[1];
|
||||
target = Bukkit.getPlayer(playerName);
|
||||
|
||||
if(args.length < 3) {
|
||||
sender.sendMessage(NickoBukkit.getInstance().getNickoConfig().getPrefix() + "§cMissing argument.");
|
||||
}
|
||||
|
||||
name = args[2];
|
||||
skin = args[3];
|
||||
if (PlayerUtils.isPlayerOffline(target)) {
|
||||
sender.sendMessage(NickoBukkit.getInstance().getNickoConfig().getPrefix() + "§cSpecified player is offline.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final AppearanceManager appearanceManager = AppearanceManager.get(target.getPlayer());
|
||||
|
||||
if (MojangUtils.isUsernameInvalid(name) || MojangUtils.isUsernameInvalid(skin)) {
|
||||
sender.sendMessage(NickoBukkit.getInstance().getNickoConfig().getPrefix() + "§cSpecified username is invalid.");
|
||||
}
|
||||
|
||||
appearanceManager.setNameAndSkin(name, skin);
|
||||
final RainbowText whooshText = new RainbowText("Whoosh!");
|
||||
target.sendMessage(NickoBukkit.getInstance().getNickoConfig().getPrefix() + whooshText.getText());
|
||||
target.playSound(target.getLocation(), Sound.ENTITY_ITEM_FRAME_PLACE, 1, 1);
|
||||
}
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
package net.artelnatif.nicko.command.sub;
|
||||
|
||||
import com.yoshiplex.rainbow.RainbowText;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.command.NickoCommand;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import xyz.upperlevel.spigot.book.BookUtil;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class NickoDisguiseSubCmd extends NickoSubCmd {
|
||||
|
||||
public NickoDisguiseSubCmd(NickoCommand nickoCommand) {
|
||||
super(nickoCommand);
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender) {
|
||||
if (sender instanceof Player player) {
|
||||
final String disguiseBaseCommand = "/nicko gui {player} ";
|
||||
final String disguiseNameCommand = disguiseBaseCommand + "name";
|
||||
final String disguiseSkinCommand = disguiseBaseCommand + "skin";
|
||||
final String disguiseBothCommand = disguiseBaseCommand + "full";
|
||||
|
||||
final RainbowText text = new RainbowText(NickoBukkit.getInstance().getNickoConfig().getDisguiseKitHeader());
|
||||
final int displacement = new Random().nextInt(RainbowText.getDefaultRainbow().size() - 1);
|
||||
text.setPlace(displacement);
|
||||
|
||||
final ItemStack book = BookUtil.writtenBook()
|
||||
.author("Nicko")
|
||||
.title("§6Nicko - Book of magic")
|
||||
.generation(BookMeta.Generation.ORIGINAL)
|
||||
.pages(
|
||||
new BookUtil.PageBuilder()
|
||||
.add(
|
||||
new TextComponent(text.getText())
|
||||
)
|
||||
.newLine()
|
||||
.newLine()
|
||||
.add("§0This disguise kit will help you change your name and skin.")
|
||||
.newLine()
|
||||
.newLine()
|
||||
.add("§0Go through each page until the end or cancel the process at any time by exiting any of the interfaces.")
|
||||
.build(),
|
||||
new BookUtil.PageBuilder()
|
||||
.add(
|
||||
BookUtil.TextBuilder.of("§6> §0Change my skin")
|
||||
.onHover(BookUtil.HoverAction.showText("Clicking this will prompt you a menu to change your skin."))
|
||||
.onClick(BookUtil.ClickAction.runCommand(disguiseSkinCommand.replace("{player}", player.getName())))
|
||||
.build()
|
||||
)
|
||||
.newLine()
|
||||
.newLine()
|
||||
.add(
|
||||
BookUtil.TextBuilder.of("§6> §0Change my name")
|
||||
.onHover(BookUtil.HoverAction.showText("Clicking this will prompt you a menu to change your name."))
|
||||
.onClick(BookUtil.ClickAction.runCommand(disguiseNameCommand.replace("{player}", player.getName())))
|
||||
.build()
|
||||
)
|
||||
.newLine()
|
||||
.newLine()
|
||||
.add(
|
||||
BookUtil.TextBuilder.of("§6> §0Change both")
|
||||
.onHover(BookUtil.HoverAction.showText("Clicking this will prompt you a menu to change both your name and your skin."))
|
||||
.onClick(BookUtil.ClickAction.runCommand(disguiseBothCommand.replace("{player}", player.getName())))
|
||||
.build()
|
||||
)
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
|
||||
BookUtil.openPlayer(player, book);
|
||||
} else {
|
||||
sender.sendMessage(NickoBukkit.getInstance().getNickoConfig().getPrefix() + "This command can only be performed by players!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package net.artelnatif.nicko.command.sub;
|
||||
|
||||
import com.yoshiplex.rainbow.RainbowText;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.anvil.AnvilManager;
|
||||
import net.artelnatif.nicko.command.NickoCommand;
|
||||
import net.artelnatif.nicko.command.NickoPermissions;
|
||||
import net.artelnatif.nicko.utils.PlayerUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class NickoGUISubCmd extends NickoSubCmd {
|
||||
public NickoGUISubCmd(NickoCommand nickoCommand) {
|
||||
super(nickoCommand);
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
Player target;
|
||||
if (args.length < 3) {
|
||||
target = (Player) sender;
|
||||
} else {
|
||||
final String playerName = args[1];
|
||||
target = Bukkit.getPlayerExact(playerName);
|
||||
if (PlayerUtils.isPlayerOffline(target)) {
|
||||
sender.sendMessage(NickoBukkit.getInstance().getNickoConfig().getPrefix() + "§cSpecified player is offline.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission(NickoPermissions.Player.Command.NICKO_PERMISSION_PLAYER_COMMAND_USE)) {
|
||||
sender.sendMessage(NickoPermissions.NICKO_PERMISSION_MISSING);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final AnvilManager manager = new AnvilManager(target);
|
||||
final String arg = args.length < 3 ? args[1] : args[2];
|
||||
switch (arg) {
|
||||
case "name" -> manager.openNameAnvil();
|
||||
case "skin" -> manager.openSkinAnvil();
|
||||
case "full" -> manager.openNameAndSkinAnvil();
|
||||
default ->
|
||||
sender.sendMessage(NickoBukkit.getInstance().getNickoConfig().getPrefix() + "§cInvalid argument.");
|
||||
}
|
||||
|
||||
final RainbowText whooshText = target == sender ? new RainbowText("Success!") : new RainbowText("Success! %player% is now undercover!".replace("%player%", target.getName()));
|
||||
sender.sendMessage(NickoBukkit.getInstance().getNickoConfig().getPrefix() + whooshText.getText());
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package net.artelnatif.nicko.command.sub;
|
||||
|
||||
import net.artelnatif.nicko.command.NickoCommand;
|
||||
|
||||
public class NickoSubCmd {
|
||||
private final NickoCommand nickoCommand;
|
||||
|
||||
public NickoSubCmd(NickoCommand nickoCommand) {
|
||||
this.nickoCommand = nickoCommand;
|
||||
}
|
||||
|
||||
public NickoCommand getMainCommand() {
|
||||
return nickoCommand;
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package net.artelnatif.nicko.config;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class NickoConfiguration {
|
||||
private final NickoBukkit nicko;
|
||||
|
||||
public NickoConfiguration(NickoBukkit nicko) {
|
||||
this.nicko = nicko;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return getConfig().getString("prefix");
|
||||
}
|
||||
|
||||
public String getDisguiseKitHeader() {
|
||||
return getConfig().getString("disguisekit.header");
|
||||
}
|
||||
|
||||
public ConfigurationSection getBungeecordSection() { return getConfig().getConfigurationSection("bungeecord"); }
|
||||
|
||||
public ConfigurationSection getStorageSction() { return getConfig().getConfigurationSection("storage"); }
|
||||
|
||||
public ConfigurationSection getRedisSection() { return getBungeecordSection().getConfigurationSection("redis"); }
|
||||
|
||||
public boolean isLocalStorage() { return getStorageSction().getBoolean("local"); }
|
||||
|
||||
public boolean isBungeecordEnabled() { return getBungeecordSection().getBoolean("enabled"); }
|
||||
|
||||
public String getStorageUsername() { return getStorageSction().getString("username"); }
|
||||
|
||||
public String getStoragePassword() { return getStorageSction().getString("password"); }
|
||||
|
||||
public String getStorageAddress() { return getStorageSction().getString("address"); }
|
||||
|
||||
private FileConfiguration getConfig() {
|
||||
return nicko.getConfig();
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
package net.artelnatif.nicko.disguise;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.storage.PlayerDataStore;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class AppearanceManager {
|
||||
private final NickoProfile profile;
|
||||
private final Player player;
|
||||
private final NickoBukkit instance = NickoBukkit.getInstance();
|
||||
private final PlayerDataStore dataStore = instance.getDataStore();
|
||||
|
||||
private AppearanceManager(UUID uuid) {
|
||||
this.player = Bukkit.getPlayer(uuid);
|
||||
this.profile = dataStore.getData(uuid).orElse(NickoProfile.EMPTY_PROFILE);
|
||||
}
|
||||
|
||||
private AppearanceManager(String name) {
|
||||
this.player = null;
|
||||
this.profile = dataStore.getOfflineData(name).orElse(NickoProfile.EMPTY_PROFILE);
|
||||
}
|
||||
|
||||
public static AppearanceManager get(Player player) {
|
||||
return new AppearanceManager(player.getUniqueId());
|
||||
}
|
||||
|
||||
public static AppearanceManager get(String name) {
|
||||
return new AppearanceManager(name);
|
||||
}
|
||||
|
||||
public boolean hasData() {
|
||||
return !profile.isEmpty();
|
||||
}
|
||||
|
||||
public boolean isNicked() {
|
||||
return hasData() && !profile.getSkin().equals(player.getName()) || !profile.getName().equals(player.getName());
|
||||
}
|
||||
|
||||
public void setSkin(String skin) {
|
||||
profile.setSkin(skin);
|
||||
}
|
||||
|
||||
public String getSkin() {
|
||||
return profile.getSkin();
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
profile.setName(name);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return profile.getName();
|
||||
}
|
||||
|
||||
public NickoProfile getProfile() {
|
||||
return profile;
|
||||
}
|
||||
|
||||
public void setNameAndSkin(String name, String skin) {
|
||||
this.profile.setName(name);
|
||||
this.profile.setSkin(skin);
|
||||
updatePlayer(true);
|
||||
}
|
||||
|
||||
public void updatePlayer(boolean skinChange) {
|
||||
NickoBukkit.getInstance().getInternals().updateProfile(player, profile, skinChange);
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package net.artelnatif.nicko.disguise;
|
||||
|
||||
public class NickoProfile {
|
||||
public static final NickoProfile EMPTY_PROFILE = new NickoProfile(null, null);
|
||||
|
||||
private String name;
|
||||
private String skin;
|
||||
|
||||
public NickoProfile(String name, String skin) {
|
||||
this.name = name;
|
||||
this.skin = skin;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this != NickoProfile.EMPTY_PROFILE || (name == null && skin == null);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSkin() {
|
||||
return skin;
|
||||
}
|
||||
|
||||
public void setSkin(String skin) {
|
||||
this.skin = skin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NickoProfile{" +
|
||||
"name='" + name + '\'' +
|
||||
", skin='" + skin + '\'' +
|
||||
", empty='" + isEmpty() + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package net.artelnatif.nicko.event;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.AppearanceManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class PlayerJoinListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
Bukkit.getScheduler().runTaskLater(NickoBukkit.getInstance(), () -> {
|
||||
final AppearanceManager appearanceManager = AppearanceManager.get(player);
|
||||
|
||||
if (appearanceManager.hasData()) {
|
||||
final boolean skinChange = !player.getName().equals(appearanceManager.getSkin());
|
||||
appearanceManager.updatePlayer(skinChange);
|
||||
}
|
||||
}, 20L);
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package net.artelnatif.nicko.event;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class PlayerQuitListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
NickoBukkit.getInstance().getDataStore().saveData(player);
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package net.artelnatif.nicko.i18n;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
|
||||
public class I18N {
|
||||
public static final class Message {
|
||||
public static final String BASE = NickoBukkit.getInstance().getNickoConfig().getPrefix() + " ";
|
||||
|
||||
public static final class Command {
|
||||
public static final String TARGET_OFFLINE = BASE + "§cSpecified player is offline. Try again.";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package net.artelnatif.nicko.impl;
|
||||
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface Internals {
|
||||
void updateSelf(Player player);
|
||||
void updateOthers(Player player);
|
||||
void updateProfile(Player player, NickoProfile profile, boolean skinChange);
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package net.artelnatif.nicko.impl;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class InternalsProvider {
|
||||
private static Internals internals;
|
||||
|
||||
static {
|
||||
try {
|
||||
final String packageName = Internals.class.getPackage().getName();
|
||||
final String bukkitVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
final String fullClassName = packageName + "." + bukkitVersion;
|
||||
System.out.println("[DEBUG] packageName = " + packageName);
|
||||
System.out.println("[DEBUG] bukkitVersion = " + bukkitVersion);
|
||||
System.out.println("[DEBUG] Searching for " + fullClassName + "...");
|
||||
internals = (Internals) Class.forName(fullClassName).getConstructors()[0].newInstance();
|
||||
} catch (InvocationTargetException | ClassNotFoundException | InstantiationException | IllegalAccessException |
|
||||
ClassCastException exception) {
|
||||
internals = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Internals getInternals() {
|
||||
return internals;
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
package net.artelnatif.nicko.mojang;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class MojangAPI {
|
||||
public static final String URL_NAME = "https://api.mojang.com/users/profiles/minecraft/{name}";
|
||||
public static final String URL_SKIN = "https://sessionserver.mojang.com/session/minecraft/profile/{uuid}?unsigned=false";
|
||||
|
||||
private final CacheLoader<String, Optional<MojangSkin>> loader = new CacheLoader<>() {
|
||||
@Nonnull
|
||||
public Optional<MojangSkin> load(@Nonnull String uuid) throws Exception {
|
||||
return getSkinFromMojang(uuid);
|
||||
}
|
||||
};
|
||||
private final LoadingCache<String, Optional<MojangSkin>> cache = CacheBuilder
|
||||
.newBuilder()
|
||||
.expireAfterWrite(120, TimeUnit.MINUTES)
|
||||
.build(loader);
|
||||
|
||||
public Optional<MojangSkin> getSkin(String uuid) throws IOException, ExecutionException {
|
||||
return cache.get(uuid);
|
||||
}
|
||||
|
||||
public Optional<String> getUUID(String name) throws IOException {
|
||||
final String parametrizedUrl = URL_NAME.replace("{name}", name);
|
||||
final JsonObject object = getRequestToUrl(parametrizedUrl);
|
||||
if (hasNoError(object)) {
|
||||
return Optional.of(object.get("id").getAsString());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private Optional<MojangSkin> getSkinFromMojang(String uuid) throws IOException {
|
||||
final String parametrizedUrl = URL_SKIN.replace("{uuid}", uuid);
|
||||
final JsonObject object = getRequestToUrl(parametrizedUrl);
|
||||
if (hasNoError(object)) {
|
||||
final MojangSkin skin = MojangSkin.buildFromJson(object);
|
||||
return Optional.of(skin);
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
private JsonObject getRequestToUrl(String parametrizedUrl) throws IOException {
|
||||
final URL url = new URL(parametrizedUrl);
|
||||
final HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
|
||||
con.setDoInput(true);
|
||||
con.setRequestMethod("GET");
|
||||
|
||||
final BufferedReader input = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
String line;
|
||||
while ((line = input.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
|
||||
try {
|
||||
final JsonElement jsonElt = JsonParser.parseString(builder.toString());
|
||||
return jsonElt.getAsJsonObject();
|
||||
} catch (JsonParseException | IllegalStateException exception) {
|
||||
System.out.println("Failed to parse request (" + parametrizedUrl + ")! Does the username exists?");
|
||||
return getErrorObject();
|
||||
}
|
||||
}
|
||||
|
||||
private JsonObject getErrorObject() {
|
||||
final JsonObject errorObject = new JsonObject();
|
||||
errorObject.addProperty("error", "An error occurred.");
|
||||
return errorObject;
|
||||
}
|
||||
|
||||
private boolean hasNoError(JsonObject object) {
|
||||
return object.get("error") == null;
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package net.artelnatif.nicko.mojang;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public record MojangSkin(String name, String value, String signature) {
|
||||
public static MojangSkin buildFromJson(JsonObject object) {
|
||||
final String name = object.get("name").getAsString();
|
||||
final JsonObject properties = object.get("properties").getAsJsonArray().get(0).getAsJsonObject();
|
||||
final String value = properties.get("value").getAsString();
|
||||
final String signature = properties.get("signature").getAsString();
|
||||
return new MojangSkin(name, value, signature);
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package net.artelnatif.nicko.mojang;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class MojangUtils {
|
||||
public static boolean isUsernameInvalid(String username) {
|
||||
return !Pattern.matches("^\\w{3,16}$", username);
|
||||
}
|
||||
|
||||
public static UUID fromTrimmed(String trimmedUUID) throws IllegalArgumentException {
|
||||
if (trimmedUUID == null) throw new IllegalArgumentException();
|
||||
StringBuilder builder = new StringBuilder(trimmedUUID.trim());
|
||||
/* Backwards adding to avoid index adjustments */
|
||||
try {
|
||||
builder.insert(20, "-");
|
||||
builder.insert(16, "-");
|
||||
builder.insert(12, "-");
|
||||
builder.insert(8, "-");
|
||||
} catch (StringIndexOutOfBoundsException e) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
return UUID.fromString(builder.toString());
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package net.artelnatif.nicko.pluginchannel;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.artelnatif.nicko.bungee.NickoBungee;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||
|
||||
public class UpdateMessageHandler implements PluginMessageListener {
|
||||
@Override
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||
if(!channel.equals(NickoBungee.NICKO_PLUGIN_CHANNEL_UPDATE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ByteArrayDataInput in = ByteStreams.newDataInput(message);
|
||||
final String subchannel = in.readUTF();
|
||||
if(subchannel.equals(NickoBungee.NICKO_PLUGIN_CHANNEL_UPDATE)) {
|
||||
// TODO: 10/20/22 update player
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
package net.artelnatif.nicko.storage;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import net.artelnatif.nicko.mojang.MojangUtils;
|
||||
import net.artelnatif.nicko.storage.json.JSONStorage;
|
||||
import net.artelnatif.nicko.storage.sql.SQLStorage;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerDataStore {
|
||||
private final Storage storage;
|
||||
|
||||
public PlayerDataStore(NickoBukkit instance) {
|
||||
this.storage = instance.getNickoConfig().isLocalStorage() ? new JSONStorage() : new SQLStorage(instance);
|
||||
}
|
||||
|
||||
public static final HashMap<UUID, NickoProfile> PROFILES = new HashMap<>();
|
||||
|
||||
public Optional<NickoProfile> getData(UUID uuid) {
|
||||
if(storage.isError()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
if (PROFILES.containsKey(uuid)) {
|
||||
return Optional.of(PROFILES.get(uuid));
|
||||
} else if (storage.isStored(uuid)) {
|
||||
Optional<NickoProfile> retrievedProfile = storage.retrieve(uuid);
|
||||
retrievedProfile.ifPresent(profile -> PROFILES.put(uuid, profile));
|
||||
return retrievedProfile;
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<NickoProfile> getOfflineData(String name) {
|
||||
if(storage.isError()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
try {
|
||||
final Optional<String> uuidTrimmed = NickoBukkit.getInstance().getMojangAPI().getUUID(name);
|
||||
if (uuidTrimmed.isPresent()) {
|
||||
final UUID uuid = MojangUtils.fromTrimmed(uuidTrimmed.get());
|
||||
return getData(uuid);
|
||||
}
|
||||
return Optional.empty();
|
||||
} catch (IOException e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveData(Player player) {
|
||||
if(storage.isError()) {
|
||||
return;
|
||||
}
|
||||
|
||||
storage.store(player.getUniqueId(), PROFILES.get(player.getUniqueId()));
|
||||
PROFILES.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
public Storage getStorage() {
|
||||
return storage;
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package net.artelnatif.nicko.storage;
|
||||
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class Storage {
|
||||
private boolean error = false;
|
||||
|
||||
public abstract StorageProvider getProvider();
|
||||
|
||||
public abstract void store(UUID uuid, NickoProfile profile);
|
||||
|
||||
public abstract boolean isStored(UUID uuid);
|
||||
|
||||
public abstract Optional<NickoProfile> retrieve(UUID uuid);
|
||||
|
||||
public boolean isError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public void setError(boolean error) {
|
||||
this.error = error;
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package net.artelnatif.nicko.storage;
|
||||
|
||||
public interface StorageProvider {
|
||||
boolean init();
|
||||
|
||||
boolean close();
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
package net.artelnatif.nicko.storage.json;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import net.artelnatif.nicko.storage.Storage;
|
||||
import net.artelnatif.nicko.storage.StorageProvider;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class JSONStorage extends Storage {
|
||||
final Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().create();
|
||||
final File directory = new File(NickoBukkit.getInstance().getDataFolder() + "/players/");
|
||||
|
||||
@Override
|
||||
public StorageProvider getProvider() { return new JSONStorageProvider(directory); }
|
||||
|
||||
@Override
|
||||
public void store(UUID uuid, NickoProfile profile) {
|
||||
final String profileToJson = gson.toJson(profile);
|
||||
final File file = new File(directory, uuid.toString() + ".json");
|
||||
|
||||
try {
|
||||
if (checkFileExists(file)) {
|
||||
try (FileWriter fileWriter = new FileWriter(file)) {
|
||||
try (BufferedWriter writer = new BufferedWriter(fileWriter)) {
|
||||
writer.write(profileToJson);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("Could not write to file.");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("Could not create file.");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStored(UUID uuid) {
|
||||
final File directory = new File(NickoBukkit.getInstance().getDataFolder() + "/players/");
|
||||
final File file = new File(directory, uuid.toString() + ".json");
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<NickoProfile> retrieve(UUID uuid) {
|
||||
final File directory = new File(NickoBukkit.getInstance().getDataFolder() + "/players/");
|
||||
final File file = new File(directory, uuid.toString() + ".json");
|
||||
try (FileReader fileReader = new FileReader(file)) {
|
||||
try (BufferedReader reader = new BufferedReader(fileReader)) {
|
||||
NickoProfile value = gson.fromJson(reader, NickoProfile.class);
|
||||
return Optional.of(value);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkFileExists(File file) throws IOException {
|
||||
if (!file.exists()) {
|
||||
return file.createNewFile();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package net.artelnatif.nicko.storage.json;
|
||||
|
||||
import net.artelnatif.nicko.storage.StorageProvider;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class JSONStorageProvider implements StorageProvider {
|
||||
private final File directory;
|
||||
|
||||
public JSONStorageProvider(File directory) {
|
||||
this.directory = directory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean init()
|
||||
{
|
||||
return directory.exists() || directory.mkdirs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean close() { return true; }
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package net.artelnatif.nicko.storage.sql;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import net.artelnatif.nicko.storage.Storage;
|
||||
import net.artelnatif.nicko.storage.StorageProvider;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SQLStorage extends Storage {
|
||||
private final NickoBukkit instance;
|
||||
|
||||
public SQLStorage(NickoBukkit instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageProvider getProvider() {
|
||||
return new SQLStorageProvider(instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(UUID uuid, NickoProfile profile) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStored(UUID uuid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<NickoProfile> retrieve(UUID uuid) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package net.artelnatif.nicko.storage.sql;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.config.NickoConfiguration;
|
||||
import net.artelnatif.nicko.storage.StorageProvider;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class SQLStorageProvider implements StorageProvider {
|
||||
private final NickoBukkit instance;
|
||||
private Connection connection;
|
||||
|
||||
public SQLStorageProvider(NickoBukkit instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean init() {
|
||||
try {
|
||||
final NickoConfiguration config = instance.getNickoConfig();
|
||||
connection = DriverManager.getConnection("jdbc://" + config.getStorageAddress(), config.getStorageUsername(), config.getStoragePassword());
|
||||
return !connection.isClosed() && connection != null;
|
||||
} catch (SQLException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean close() {
|
||||
try {
|
||||
connection.close();
|
||||
return connection.isClosed();
|
||||
} catch (SQLException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package net.artelnatif.nicko.utils;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerUtils {
|
||||
public static boolean isPlayerOffline(Player player) {
|
||||
return player == null || !player.isOnline();
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package net.artelnatif.nicko.utils;
|
||||
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class ServerUtils {
|
||||
public static boolean checkBungeeCordHook() {
|
||||
final NickoBukkit instance = NickoBukkit.getInstance();
|
||||
final Server server = instance.getServer();
|
||||
final YamlConfiguration config = server.spigot().getConfig();
|
||||
if (!config.getConfigurationSection("settings").getBoolean("settings.bungeecord")) {
|
||||
instance.getLogger().severe("Hummm. You have enabled BungeeCord support inside Nicko,");
|
||||
instance.getLogger().severe("but it seems that your server is not hooked to your BungeeCord instance.");
|
||||
instance.getLogger().severe("If the server is already hooked to BungeeCord, please enable it into your spigot.yml aswell.");
|
||||
instance.getLogger().severe("The plugin will not continue.");
|
||||
instance.getServer().getPluginManager().disablePlugin(instance);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
name: ${project.parent.name}
|
||||
main: net.artelnatif.nicko.bungee.NickoBungee
|
||||
version: ${project.version}
|
||||
author: Aro
|
|
@ -1,28 +0,0 @@
|
|||
# Nicko ${project.version} - Config:
|
||||
|
||||
prefix: "§8[§6Nicko§8] "
|
||||
|
||||
bungeecord:
|
||||
# Enables Bungeecord support, switching through servers will keep player's skins.
|
||||
enabled: false
|
||||
redis:
|
||||
username: ""
|
||||
password: ""
|
||||
# Time To Live, the time the data will be stored on a player-by-player basis.
|
||||
ttl: -1
|
||||
|
||||
|
||||
disguisekit:
|
||||
# The rainbow header text in the book.
|
||||
header: "Nicko's Disguise Kit"
|
||||
|
||||
storage:
|
||||
# Indicates wherever the data will be stored
|
||||
# locally through a .json file or a (My)SQL database.
|
||||
local: true
|
||||
# SQL database's address
|
||||
address: "localhost"
|
||||
# SQL database's username.
|
||||
username: ""
|
||||
# SQL database's password.
|
||||
password: ""
|
|
@ -1,7 +0,0 @@
|
|||
name: ${project.parent.name}
|
||||
main: net.artelnatif.nicko.NickoBukkit
|
||||
version: ${project.version}
|
||||
author: Aro
|
||||
api-version: 1.18
|
||||
commands:
|
||||
nicko:
|
|
@ -1,87 +0,0 @@
|
|||
package net.artelnatif.nicko.test;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.artelnatif.nicko.mojang.MojangAPI;
|
||||
import net.artelnatif.nicko.mojang.MojangSkin;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class MojangAPITest {
|
||||
public static final String NAME = "Notch";
|
||||
public static final String URL_NAME = "https://api.mojang.com/users/profiles/minecraft/{name}";
|
||||
public static final String URL_SKIN = "https://sessionserver.mojang.com/session/minecraft/profile/{uuid}?unsigned=false";
|
||||
|
||||
public static JsonObject object = null;
|
||||
|
||||
@Test
|
||||
@DisplayName("MojangAPI - GET - Name")
|
||||
public void testGetMojangAPIName() throws IOException {
|
||||
final URL url = new URL(URL_NAME.replace("{name}", NAME));
|
||||
final HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
|
||||
urlConnection.setRequestMethod("GET");
|
||||
urlConnection.setDoOutput(true);
|
||||
|
||||
//DataOutputStream output = new DataOutputStream(urlConnection.getOutputStream());
|
||||
//output.writeBytes();
|
||||
//output.flush();
|
||||
//output.close();
|
||||
|
||||
final BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
|
||||
final StringBuilder response = new StringBuilder();
|
||||
String inputLine;
|
||||
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
object = JsonParser.parseString(response.toString()).getAsJsonObject();
|
||||
Assertions.assertEquals(NAME, object.get("name").getAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("MojangAPI - GET - Skin")
|
||||
public void testGetMojangAPISkin() throws IOException {
|
||||
final URL url = new URL(URL_SKIN.replace("{uuid}", object.get("id").getAsString().replaceAll("-", "")));
|
||||
final HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
|
||||
urlConnection.setRequestMethod("GET");
|
||||
urlConnection.setDoOutput(true);
|
||||
|
||||
final BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
|
||||
final StringBuilder response = new StringBuilder();
|
||||
String inputLine;
|
||||
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
response.append(inputLine);
|
||||
}
|
||||
in.close();
|
||||
System.out.println(response);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("MojangAPI - New Methods")
|
||||
public void testNewMojangAPIMethods() throws IOException {
|
||||
final MojangAPI mojangAPI = new MojangAPI();
|
||||
final Optional<String> uuid = mojangAPI.getUUID(NAME);
|
||||
Assertions.assertTrue(uuid.isPresent());
|
||||
|
||||
final Optional<MojangSkin> skin;
|
||||
try {
|
||||
skin = mojangAPI.getSkin(uuid.get());
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Assertions.assertTrue(skin.isPresent());
|
||||
Assertions.assertDoesNotThrow(this::testNewMojangAPIMethods);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue