forked from kaboomserver/extras
Rate limit skin command
This commit is contained in:
parent
72bc93b970
commit
44e3d0fbb6
4 changed files with 18 additions and 33 deletions
|
@ -10,6 +10,8 @@ import org.bukkit.entity.Player;
|
|||
import pw.kaboom.extras.helpers.SkinDownloader;
|
||||
|
||||
public final class CommandSkin implements CommandExecutor {
|
||||
public static long millis;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
|
@ -17,16 +19,20 @@ public final class CommandSkin implements CommandExecutor {
|
|||
} else {
|
||||
final Player player = (Player) sender;
|
||||
|
||||
final long millisDifference = System.currentTimeMillis() - millis;
|
||||
|
||||
if (args.length == 0) {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>");
|
||||
} else if (!SkinDownloader.skinInProgress.contains(player.getUniqueId())) {
|
||||
} else if (millisDifference <= 2000) {
|
||||
player.sendMessage("Please wait a few seconds before changing your skin");
|
||||
} else {
|
||||
final String name = args[0];
|
||||
final boolean shouldSendMessage = true;
|
||||
|
||||
SkinDownloader skinDownloader = new SkinDownloader();
|
||||
skinDownloader.applySkin(player, name, shouldSendMessage);
|
||||
} else {
|
||||
player.sendMessage("You are already applying a skin. Please wait a few seconds.");
|
||||
|
||||
millis = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -7,15 +7,11 @@ import org.bukkit.command.CommandExecutor;
|
|||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
|
||||
import pw.kaboom.extras.Main;
|
||||
|
||||
public final class CommandUsername implements CommandExecutor {
|
||||
public static boolean nameInProgress = false;
|
||||
public static long millis;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
|
||||
|
@ -26,12 +22,16 @@ public final class CommandUsername implements CommandExecutor {
|
|||
|
||||
final String nameColor = ChatColor.translateAlternateColorCodes('&', String.join(" ", args));
|
||||
final String name = nameColor.substring(0, Math.min(16, nameColor.length()));
|
||||
|
||||
final long millisDifference = System.currentTimeMillis() - millis;
|
||||
|
||||
if (args.length == 0) {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>");
|
||||
} else if (nameInProgress) {
|
||||
} else if (name.equals(player.getName())) {
|
||||
player.sendMessage("You already have the username \"" + name + "\"");
|
||||
} else if (millisDifference <= 2000) {
|
||||
player.sendMessage("Please wait a few seconds before changing your username");
|
||||
} else if (!name.equals(player.getName())) {
|
||||
} else {
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (name.equals(onlinePlayer.getName())) {
|
||||
player.sendMessage("A player with that username is already logged in");
|
||||
|
@ -39,8 +39,6 @@ public final class CommandUsername implements CommandExecutor {
|
|||
}
|
||||
}
|
||||
|
||||
nameInProgress = true;
|
||||
|
||||
final PlayerProfile profile = player.getPlayerProfile();
|
||||
|
||||
profile.setName(name);
|
||||
|
@ -48,18 +46,9 @@ public final class CommandUsername implements CommandExecutor {
|
|||
player.setPlayerProfile(profile);
|
||||
player.setOp(true);
|
||||
|
||||
final int tickDelay = 40;
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
nameInProgress = false;
|
||||
}
|
||||
}.runTaskLaterAsynchronously(JavaPlugin.getPlugin(Main.class), tickDelay);
|
||||
millis = System.currentTimeMillis();
|
||||
|
||||
player.sendMessage("Successfully set your username to \"" + name + "\"");
|
||||
} else {
|
||||
player.sendMessage("You already have the username \"" + name + "\"");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -22,7 +22,6 @@ import com.google.gson.JsonParser;
|
|||
import pw.kaboom.extras.Main;
|
||||
|
||||
public final class SkinDownloader {
|
||||
public static HashSet<UUID> skinInProgress = new HashSet<UUID>();
|
||||
public static HashMap<UUID, PlayerProfile> skinProfiles = new HashMap<UUID, PlayerProfile>();
|
||||
|
||||
private HttpsURLConnection skinConnection;
|
||||
|
@ -35,8 +34,6 @@ public final class SkinDownloader {
|
|||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
skinInProgress.add(player.getUniqueId());
|
||||
|
||||
final PlayerProfile profile = player.getPlayerProfile();
|
||||
|
||||
try {
|
||||
|
@ -57,7 +54,6 @@ public final class SkinDownloader {
|
|||
player.sendMessage("A player with that username doesn't exist");
|
||||
}
|
||||
|
||||
skinInProgress.remove(player.getUniqueId());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -68,8 +64,6 @@ public final class SkinDownloader {
|
|||
player.setPlayerProfile(profile);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
skinInProgress.remove(player.getUniqueId());
|
||||
}
|
||||
}.runTask(JavaPlugin.getPlugin(Main.class));
|
||||
}
|
||||
|
|
|
@ -45,8 +45,6 @@ public final class PlayerConnection implements Listener {
|
|||
|
||||
@EventHandler
|
||||
void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) {
|
||||
System.out.println("prelogin");
|
||||
|
||||
if (event.getName().length() > 16) {
|
||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "Your username can't be longer than 16 characters");
|
||||
} else {
|
||||
|
@ -123,8 +121,6 @@ public final class PlayerConnection implements Listener {
|
|||
|
||||
@EventHandler
|
||||
void onPlayerLogin(final PlayerLoginEvent event) {
|
||||
System.out.println("login");
|
||||
|
||||
if (event.getHostname().startsWith("play.flame.ga")
|
||||
&& event.getHostname().endsWith(":25565")) {
|
||||
event.disallow(Result.KICK_OTHER, "You connected to the server using an outdated server address/IP.\nPlease use the following address/IP:\n\nkaboom.pw");
|
||||
|
@ -178,7 +174,7 @@ public final class PlayerConnection implements Listener {
|
|||
void onPlayerQuit(PlayerQuitEvent event) {
|
||||
PlayerCommand.commandMillisList.remove(event.getPlayer().getUniqueId());
|
||||
PlayerInteract.interactMillisList.remove(event.getPlayer().getUniqueId());
|
||||
SkinDownloader.skinInProgress.remove(event.getPlayer().getUniqueId());
|
||||
//SkinDownloader.skinInProgress.remove(event.getPlayer().getUniqueId());
|
||||
|
||||
/*final World world = event.getPlayer().getWorld();
|
||||
|
||||
|
|
Loading…
Reference in a new issue