feat: random skin on join

This commit is contained in:
ineanto 2023-12-22 14:57:24 +01:00
parent 153d666b78
commit 30803363ba
3 changed files with 54 additions and 63 deletions

View file

@ -2,11 +2,10 @@ plugins {
id("java")
id("io.github.goooler.shadow") version "8.1.2"
id("xyz.jpenilla.run-paper") version "2.2.2"
id("jvm-test-suite")
}
group = "xyz.ineanto"
version = "1.1.0-RC1"
version = "1.1.1-RC1"
val shadowImplementation: Configuration by configurations.creating
configurations["implementation"].extendsFrom(shadowImplementation)
@ -55,7 +54,7 @@ dependencies {
shadowImplementation("com.github.jsixface:yamlconfig:1.2")
shadowImplementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml: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("redis.clients:jedis:4.4.3")
shadowImplementation("com.google.code.gson:gson:2.10.1")
@ -80,7 +79,6 @@ tasks {
}
shadowJar {
mustRunAfter(test)
configurations = listOf(shadowImplementation)
// NAMING
@ -127,42 +125,20 @@ tasks {
}
}
jar {
enabled = false
}
test {
useJUnitPlatform()
}
runServer {
downloadPlugins {
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")
}
// 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")
}
}
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")
}
}
}
} */
}

View file

@ -6,6 +6,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
import xyz.ineanto.nicko.appearance.random.RandomNameFetcher;
import xyz.ineanto.nicko.command.NickoCommand;
import xyz.ineanto.nicko.config.Configuration;
import xyz.ineanto.nicko.config.ConfigurationManager;
@ -38,6 +39,7 @@ public class NickoBukkit extends JavaPlugin {
private Configuration configuration;
private LocaleFileManager localeFileManager;
private PlayerNameStore nameStore;
private RandomNameFetcher nameFetcher;
private Metrics metrics;
public NickoBukkit() {
@ -63,6 +65,7 @@ public class NickoBukkit extends JavaPlugin {
mojangAPI = new MojangAPI();
dataStore = new PlayerDataStore(mojangAPI, getNickoConfig());
nameStore = new PlayerNameStore();
nameFetcher = new RandomNameFetcher(this);
if (!Bukkit.getOnlineMode()) {
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() {
return dataStore;
}

View file

@ -1,5 +1,6 @@
package xyz.ineanto.nicko.event;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -34,37 +35,44 @@ public class PlayerJoinListener implements Listener {
final I18N i18n = new I18N(player);
final PlayerNameStore nameStore = instance.getNameStore();
final PlayerDataStore dataStore = instance.getDataStore();
nameStore.storeName(player);
Bukkit.getScheduler().runTaskLater(instance, () -> {
final Optional<NickoProfile> optionalProfile = dataStore.getData(player.getUniqueId());
optionalProfile.ifPresent(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())));
}
final Optional<NickoProfile> optionalProfile = dataStore.getData(player.getUniqueId());
optionalProfile.ifPresent(profile -> {
// Random Skin on connection feature
if (profile.isRandomSkin()) {
Bukkit.broadcast(Component.text("§c[ELITE DEBUG] §fJoined with Random Skin."));
final String name = instance.getNameFetcher().getRandomUsername();
final String skin = instance.getNameFetcher().getRandomUsername();
profile.setName(name);
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();
viewers.forEach(uuid -> {