feat: random skin on join
This commit is contained in:
parent
153d666b78
commit
30803363ba
3 changed files with 54 additions and 63 deletions
|
@ -2,11 +2,10 @@ plugins {
|
||||||
id("java")
|
id("java")
|
||||||
id("io.github.goooler.shadow") version "8.1.2"
|
id("io.github.goooler.shadow") version "8.1.2"
|
||||||
id("xyz.jpenilla.run-paper") version "2.2.2"
|
id("xyz.jpenilla.run-paper") version "2.2.2"
|
||||||
id("jvm-test-suite")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "xyz.ineanto"
|
group = "xyz.ineanto"
|
||||||
version = "1.1.0-RC1"
|
version = "1.1.1-RC1"
|
||||||
|
|
||||||
val shadowImplementation: Configuration by configurations.creating
|
val shadowImplementation: Configuration by configurations.creating
|
||||||
configurations["implementation"].extendsFrom(shadowImplementation)
|
configurations["implementation"].extendsFrom(shadowImplementation)
|
||||||
|
@ -55,7 +54,7 @@ dependencies {
|
||||||
shadowImplementation("com.github.jsixface:yamlconfig:1.2")
|
shadowImplementation("com.github.jsixface:yamlconfig:1.2")
|
||||||
shadowImplementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.15.2")
|
shadowImplementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.15.2")
|
||||||
shadowImplementation("com.fasterxml.jackson.core:jackson-core:2.15.2")
|
shadowImplementation("com.fasterxml.jackson.core:jackson-core:2.15.2")
|
||||||
shadowImplementation("com.mysql:mysql-connector-j:8.1.0")
|
shadowImplementation("com.mysql:mysql-connector-j:8.2.0")
|
||||||
shadowImplementation("org.mariadb.jdbc:mariadb-java-client:3.3.1")
|
shadowImplementation("org.mariadb.jdbc:mariadb-java-client:3.3.1")
|
||||||
shadowImplementation("redis.clients:jedis:4.4.3")
|
shadowImplementation("redis.clients:jedis:4.4.3")
|
||||||
shadowImplementation("com.google.code.gson:gson:2.10.1")
|
shadowImplementation("com.google.code.gson:gson:2.10.1")
|
||||||
|
@ -80,7 +79,6 @@ tasks {
|
||||||
}
|
}
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
mustRunAfter(test)
|
|
||||||
configurations = listOf(shadowImplementation)
|
configurations = listOf(shadowImplementation)
|
||||||
|
|
||||||
// NAMING
|
// NAMING
|
||||||
|
@ -127,42 +125,20 @@ tasks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
|
||||||
runServer {
|
runServer {
|
||||||
downloadPlugins {
|
downloadPlugins {
|
||||||
url("https://download.luckperms.net/1526/bukkit/loader/LuckPerms-Bukkit-5.4.113.jar")
|
url("https://download.luckperms.net/1526/bukkit/loader/LuckPerms-Bukkit-5.4.113.jar")
|
||||||
url("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/build/libs/ProtocolLib.jar")
|
url("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/build/libs/ProtocolLib.jar")
|
||||||
}
|
}
|
||||||
// Configure the Minecraft version for our task.
|
|
||||||
// This is the only required configuration besides applying the plugin.
|
|
||||||
// Your plugin's jar (or shadowJar if present) will be used automatically.
|
|
||||||
minecraftVersion("1.20.2")
|
minecraftVersion("1.20.2")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named("jar").configure {
|
|
||||||
enabled = false
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.test {
|
|
||||||
useJUnitPlatform()
|
|
||||||
}
|
|
||||||
|
|
||||||
// For when Gradle 9.0 releases.
|
|
||||||
/**
|
|
||||||
testing {
|
|
||||||
suites {
|
|
||||||
val test by getting(JvmTestSuite::class) {
|
|
||||||
targets {
|
|
||||||
useJUnitJupiter()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation(project())
|
|
||||||
implementation("com.github.seeseemelk:MockBukkit-v1.20:3.58.0")
|
|
||||||
implementation("org.junit.jupiter:junit-jupiter-api:5.10.1")
|
|
||||||
implementation("org.junit.jupiter:junit-jupiter-engine:5.10.1")
|
|
||||||
implementation("org.junit.jupiter:junit-jupiter:5.10.1")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} */
|
|
|
@ -6,6 +6,7 @@ import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import xyz.ineanto.nicko.appearance.random.RandomNameFetcher;
|
||||||
import xyz.ineanto.nicko.command.NickoCommand;
|
import xyz.ineanto.nicko.command.NickoCommand;
|
||||||
import xyz.ineanto.nicko.config.Configuration;
|
import xyz.ineanto.nicko.config.Configuration;
|
||||||
import xyz.ineanto.nicko.config.ConfigurationManager;
|
import xyz.ineanto.nicko.config.ConfigurationManager;
|
||||||
|
@ -38,6 +39,7 @@ public class NickoBukkit extends JavaPlugin {
|
||||||
private Configuration configuration;
|
private Configuration configuration;
|
||||||
private LocaleFileManager localeFileManager;
|
private LocaleFileManager localeFileManager;
|
||||||
private PlayerNameStore nameStore;
|
private PlayerNameStore nameStore;
|
||||||
|
private RandomNameFetcher nameFetcher;
|
||||||
private Metrics metrics;
|
private Metrics metrics;
|
||||||
|
|
||||||
public NickoBukkit() {
|
public NickoBukkit() {
|
||||||
|
@ -63,6 +65,7 @@ public class NickoBukkit extends JavaPlugin {
|
||||||
mojangAPI = new MojangAPI();
|
mojangAPI = new MojangAPI();
|
||||||
dataStore = new PlayerDataStore(mojangAPI, getNickoConfig());
|
dataStore = new PlayerDataStore(mojangAPI, getNickoConfig());
|
||||||
nameStore = new PlayerNameStore();
|
nameStore = new PlayerNameStore();
|
||||||
|
nameFetcher = new RandomNameFetcher(this);
|
||||||
|
|
||||||
if (!Bukkit.getOnlineMode()) {
|
if (!Bukkit.getOnlineMode()) {
|
||||||
getLogger().warning("Nicko has not been tested using offline mode!");
|
getLogger().warning("Nicko has not been tested using offline mode!");
|
||||||
|
@ -178,6 +181,10 @@ public class NickoBukkit extends JavaPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RandomNameFetcher getNameFetcher() {
|
||||||
|
return nameFetcher;
|
||||||
|
}
|
||||||
|
|
||||||
public PlayerDataStore getDataStore() {
|
public PlayerDataStore getDataStore() {
|
||||||
return dataStore;
|
return dataStore;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package xyz.ineanto.nicko.event;
|
package xyz.ineanto.nicko.event;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
@ -34,37 +35,44 @@ public class PlayerJoinListener implements Listener {
|
||||||
final I18N i18n = new I18N(player);
|
final I18N i18n = new I18N(player);
|
||||||
final PlayerNameStore nameStore = instance.getNameStore();
|
final PlayerNameStore nameStore = instance.getNameStore();
|
||||||
final PlayerDataStore dataStore = instance.getDataStore();
|
final PlayerDataStore dataStore = instance.getDataStore();
|
||||||
|
|
||||||
nameStore.storeName(player);
|
nameStore.storeName(player);
|
||||||
Bukkit.getScheduler().runTaskLater(instance, () -> {
|
|
||||||
final Optional<NickoProfile> optionalProfile = dataStore.getData(player.getUniqueId());
|
|
||||||
|
|
||||||
optionalProfile.ifPresent(profile -> {
|
final Optional<NickoProfile> optionalProfile = dataStore.getData(player.getUniqueId());
|
||||||
if (profile.hasData()) {
|
optionalProfile.ifPresent(profile -> {
|
||||||
final AppearanceManager appearanceManager = new AppearanceManager(player);
|
// Random Skin on connection feature
|
||||||
final boolean needsASkinChange = profile.getSkin() != null && !profile.getSkin().equals(player.getName());
|
if (profile.isRandomSkin()) {
|
||||||
final ActionResult actionResult = appearanceManager.updatePlayer(needsASkinChange, false);
|
Bukkit.broadcast(Component.text("§c[ELITE DEBUG] §fJoined with Random Skin."));
|
||||||
if (!actionResult.isError()) {
|
final String name = instance.getNameFetcher().getRandomUsername();
|
||||||
player.sendMessage(i18n.translateString(I18NDict.Event.Appearance.Restore.OK));
|
final String skin = instance.getNameFetcher().getRandomUsername();
|
||||||
} else {
|
profile.setName(name);
|
||||||
player.sendMessage(i18n.translateString(I18NDict.Event.Appearance.Restore.ERROR, i18n.translateStringWithoutPrefix(actionResult.getErrorKey())));
|
profile.setSkin(skin);
|
||||||
}
|
dataStore.updateCache(player.getUniqueId(), profile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (profile.hasData()) {
|
||||||
|
final AppearanceManager appearanceManager = new AppearanceManager(player);
|
||||||
|
final boolean needsASkinChange = profile.getSkin() != null && !profile.getSkin().equals(player.getName());
|
||||||
|
final ActionResult actionResult = appearanceManager.updatePlayer(needsASkinChange, false);
|
||||||
|
if (!actionResult.isError()) {
|
||||||
|
player.sendMessage(i18n.translateString(I18NDict.Event.Appearance.Restore.OK));
|
||||||
|
} else {
|
||||||
|
player.sendMessage(i18n.translateString(I18NDict.Event.Appearance.Restore.ERROR, i18n.translateStringWithoutPrefix(actionResult.getErrorKey())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (Player online : Bukkit.getOnlinePlayers().stream().filter(op -> op.getUniqueId() != player.getUniqueId()).toList()) {
|
||||||
|
final Optional<NickoProfile> optionalOnlinePlayerProfile = dataStore.getData(online.getUniqueId());
|
||||||
|
|
||||||
|
optionalOnlinePlayerProfile.ifPresent(profile -> {
|
||||||
|
final AppearanceManager appearanceManager = new AppearanceManager(online);
|
||||||
|
final boolean needsASkinChange = profile.getSkin() != null && !profile.getSkin().equals(online.getName());
|
||||||
|
final ActionResult actionResult = appearanceManager.updateForOthers(needsASkinChange, false);
|
||||||
|
if (actionResult.isError()) {
|
||||||
|
logger.warning("Something wrong happened while updating players to joining player (" + actionResult.getErrorKey() + ")");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
for (Player online : Bukkit.getOnlinePlayers().stream().filter(op -> op.getUniqueId() != player.getUniqueId()).toList()) {
|
|
||||||
final Optional<NickoProfile> optionalOnlinePlayerProfile = dataStore.getData(online.getUniqueId());
|
|
||||||
|
|
||||||
optionalOnlinePlayerProfile.ifPresent(profile -> {
|
|
||||||
final AppearanceManager appearanceManager = new AppearanceManager(online);
|
|
||||||
final boolean needsASkinChange = profile.getSkin() != null && !profile.getSkin().equals(online.getName());
|
|
||||||
final ActionResult actionResult = appearanceManager.updateForOthers(needsASkinChange, false);
|
|
||||||
if (actionResult.isError()) {
|
|
||||||
logger.warning("Something wrong happened while updating players to joining player (" + actionResult.getErrorKey() + ")");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, 20L);
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked") final ArrayList<UUID> viewers = (ArrayList<UUID>) PlayerCheckGUIData.VIEWERS.clone();
|
@SuppressWarnings("unchecked") final ArrayList<UUID> viewers = (ArrayList<UUID>) PlayerCheckGUIData.VIEWERS.clone();
|
||||||
viewers.forEach(uuid -> {
|
viewers.forEach(uuid -> {
|
||||||
|
|
Loading…
Reference in a new issue