Skip to content
Open
11 changes: 11 additions & 0 deletions src/main/java/pw/kaboom/extras/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,23 @@
import pw.kaboom.extras.modules.entity.EntityKnockback;
import pw.kaboom.extras.modules.entity.EntitySpawn;
import pw.kaboom.extras.modules.player.*;
import pw.kaboom.extras.modules.player.skin.SkinManager;
import pw.kaboom.extras.modules.server.ServerCommand;
import pw.kaboom.extras.modules.server.ServerGameRule;
import pw.kaboom.extras.modules.server.ServerTabComplete;

import java.io.File;

public final class Main extends JavaPlugin {
public static Main PLUGIN;

private File prefixConfigFile;
private FileConfiguration prefixConfig;

public Main() {
PLUGIN = this;
}

@Override
public void onLoad() {
/* Load missing config.yml defaults */
Expand Down Expand Up @@ -79,6 +86,10 @@ public void onEnable() {
this.getServer().getPluginManager().registerEvents(new PlayerTeleport(), this);
this.getServer().getPluginManager().registerEvents(new PlayerPrefix(), this);

final var skinManager = new SkinManager();
this.getServer().getPluginManager().registerEvents(skinManager, this);
skinManager.start();

/* Server-related modules */
ServerGameRule.init(this);

Expand Down
23 changes: 3 additions & 20 deletions src/main/java/pw/kaboom/extras/commands/CommandSkin.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@
import pw.kaboom.extras.modules.player.skin.SkinManager;

import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.Map;

public final class CommandSkin implements CommandExecutor {
private final Map<Player, Long> lastUsedMillis = new HashMap<>();

@Override
public boolean onCommand(final @Nonnull CommandSender sender,
final @Nonnull Command command,
Expand All @@ -26,41 +22,28 @@ public boolean onCommand(final @Nonnull CommandSender sender,
return true;
}

final long millis = lastUsedMillis.getOrDefault(player, 0L);
final long millisDifference = System.currentTimeMillis() - millis;

if (args.length == 0) {
player.sendMessage(Component
.text("Usage: /" + label + " <username>\n/" + label + " off",
NamedTextColor.RED));
return true;
}

if (millisDifference <= 2000) {
player.sendMessage(Component
.text("Please wait a few seconds before changing your skin"));
return true;
}

lastUsedMillis.put(player, System.currentTimeMillis());

final String name = args[0];

if (name.equalsIgnoreCase("off") || name.equalsIgnoreCase("remove")
|| name.equalsIgnoreCase("disable")) {
SkinManager.resetSkin(player, true);
SkinManager.removeSkin(player, true);
return true;
}

if (name.equalsIgnoreCase("auto") || name.equalsIgnoreCase("default")
|| name.equalsIgnoreCase("reset")) {
SkinManager.applySkin(player, player.getName(), true);
SkinManager.requestSkin(player, player.getName(), true);
return true;
}

final boolean shouldSendMessage = true;

SkinManager.applySkin(player, name, shouldSendMessage);
SkinManager.requestSkin(player, name, true);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@

import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent;
import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent;
import org.bukkit.plugin.java.JavaPlugin;
import pw.kaboom.extras.Main;
import pw.kaboom.extras.util.Utility;

public final class EntitySpawn implements Listener {
private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig();
private static final FileConfiguration CONFIG = Main.PLUGIN.getConfig();

private static final int MAX_ENTITIES_PER_CHUNK = CONFIG.getInt("maxEntitiesPerChunk");
public static final int MAX_ENTITIES_PER_WORLD = CONFIG.getInt("maxEntitiesPerWorld");
Expand Down
31 changes: 11 additions & 20 deletions src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
import net.kyori.adventure.title.Title;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.*;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.plugin.java.JavaPlugin;
import pw.kaboom.extras.Main;
import pw.kaboom.extras.modules.server.ServerTabComplete;
import pw.kaboom.extras.modules.player.skin.SkinManager;
Expand All @@ -28,7 +27,7 @@
import java.util.concurrent.ThreadLocalRandom;

public final class PlayerConnection implements Listener {
private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig();
private static final FileConfiguration CONFIG = Main.PLUGIN.getConfig();
private static final Component TITLE =
LegacyComponentSerializer.legacySection()
.deserialize(
Expand Down Expand Up @@ -83,19 +82,18 @@ void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) {
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER,
Component.text("A player with that username is already logged in"));
}
}

/*try {
final PlayerProfile profile = event.getPlayerProfile();
UUID offlineUUID = UUID.nameUUIDFromBytes(
("OfflinePlayer:" + event.getName()).getBytes(Charsets.UTF_8));
@EventHandler(priority = EventPriority.LOWEST)
void onEarlyPlayerJoin(final PlayerJoinEvent event) {
final var player = event.getPlayer();

profile.setId(offlineUUID);
// Must be done in the PlayerJoinEvent instead of PlayerLoginEvent otherwise skins may fetch
// after the player joins
final var serverConfig = Bukkit.getServer().getServerConfig();

SkinDownloader skinDownloader = new SkinDownloader();
skinDownloader.fillJoinProfile(profile, event.getName(), event.getUniqueId());
} catch (Exception ignored) {
}*/
if (!serverConfig.isProxyOnlineMode())
SkinManager.requestSkin(player, player.getName(), false);
}

@EventHandler
Expand Down Expand Up @@ -144,13 +142,6 @@ void onPlayerLogin(final PlayerLoginEvent event) {
if (OP_ON_JOIN && !player.isOp()) {
player.setOp(true);
}

final Server server = Bukkit.getServer();


if (!server.getOnlineMode()) {
SkinManager.applySkin(player, player.getName(), false);
}
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;
import org.jetbrains.annotations.Nullable;
import pw.kaboom.extras.Main;

import java.io.File;
import java.io.IOException;
Expand All @@ -23,8 +21,9 @@
import java.util.Map;
import java.util.UUID;

import static pw.kaboom.extras.Main.PLUGIN;

public final class PlayerPrefix implements Listener {
private static final Main PLUGIN = JavaPlugin.getPlugin(Main.class);
private static final File PREFIX_CONFIG_FILE = PLUGIN.getPrefixConfigFile();
private static final FileConfiguration PREFIX_CONFIG = PLUGIN.getPrefixConfig();
private static final FileConfiguration PLUGIN_CONFIGURATION = PLUGIN.getConfig();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
package pw.kaboom.extras.modules.player.skin;

public record SkinData(String texture, String signature) {

}
public record SkinData(String texture, String signature) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package pw.kaboom.extras.modules.player.skin;

import org.bukkit.entity.Player;
import org.jspecify.annotations.Nullable;

import java.util.UUID;
import java.util.function.BiConsumer;

public record SkinFillRequest(UUID fromPlayer, String toUser,
BiConsumer<Player, @Nullable SkinData> resultConsumer) {

}
Loading
Loading