mirror of
https://github.com/kaboomserver/extras.git
synced 2025-02-11 11:40:19 +00:00
Command checker improvements
This commit is contained in:
parent
b82c63a3ed
commit
e24206932b
6 changed files with 101 additions and 64 deletions
|
@ -38,25 +38,18 @@ class CommandSkin implements CommandExecutor {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final URL skinUrl = new URL("https://api.ashcon.app/mojang/v2/user/" + name);
|
final URL skinUrl = new URL("https://api.ashcon.app/mojang/v2/user/" + name);
|
||||||
final HttpsURLConnection premiumCheck = (HttpsURLConnection) skinUrl.openConnection();
|
final HttpsURLConnection skinConnection = (HttpsURLConnection) skinUrl.openConnection();
|
||||||
premiumCheck.setConnectTimeout(0);
|
skinConnection.setConnectTimeout(0);
|
||||||
premiumCheck.setRequestMethod("HEAD");
|
skinConnection.setDefaultUseCaches(false);
|
||||||
premiumCheck.setDefaultUseCaches(false);
|
skinConnection.setUseCaches(false);
|
||||||
premiumCheck.setUseCaches(false);
|
|
||||||
|
|
||||||
if (premiumCheck.getResponseCode() == HttpsURLConnection.HTTP_OK) {
|
if (skinConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
|
||||||
final HttpsURLConnection skinConnection = (HttpsURLConnection) skinUrl.openConnection();
|
|
||||||
skinConnection.setConnectTimeout(0);
|
|
||||||
skinConnection.setDefaultUseCaches(false);
|
|
||||||
skinConnection.setUseCaches(false);
|
|
||||||
final InputStreamReader skinStream = new InputStreamReader(skinConnection.getInputStream());
|
final InputStreamReader skinStream = new InputStreamReader(skinConnection.getInputStream());
|
||||||
final JsonObject response = new JsonParser().parse(skinStream).getAsJsonObject();
|
final JsonObject response = new JsonParser().parse(skinStream).getAsJsonObject();
|
||||||
final String uuid = response.get("uuid").getAsString();
|
|
||||||
final JsonObject rawSkin = response.getAsJsonObject("textures").getAsJsonObject("raw");
|
final JsonObject rawSkin = response.getAsJsonObject("textures").getAsJsonObject("raw");
|
||||||
final String texture = rawSkin.get("value").getAsString();
|
final String texture = rawSkin.get("value").getAsString();
|
||||||
final String signature = rawSkin.get("signature").getAsString();
|
final String signature = rawSkin.get("signature").getAsString();
|
||||||
skinStream.close();
|
skinStream.close();
|
||||||
skinConnection.disconnect();
|
|
||||||
|
|
||||||
final PlayerProfile textureProfile = player.getPlayerProfile();
|
final PlayerProfile textureProfile = player.getPlayerProfile();
|
||||||
textureProfile.clearProperties();
|
textureProfile.clearProperties();
|
||||||
|
@ -72,7 +65,7 @@ class CommandSkin implements CommandExecutor {
|
||||||
player.sendMessage("A player with that username doesn't exist");
|
player.sendMessage("A player with that username doesn't exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
premiumCheck.disconnect();
|
skinConnection.disconnect();
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,28 +45,21 @@ class CommandUsername implements CommandExecutor {
|
||||||
final String nameShort = nameColor.substring(0, Math.min(16, nameColor.length()));
|
final String nameShort = nameColor.substring(0, Math.min(16, nameColor.length()));
|
||||||
|
|
||||||
final URL skinUrl = new URL("https://api.ashcon.app/mojang/v2/user/" + nameShort);
|
final URL skinUrl = new URL("https://api.ashcon.app/mojang/v2/user/" + nameShort);
|
||||||
final HttpsURLConnection premiumCheck = (HttpsURLConnection) skinUrl.openConnection();
|
final HttpsURLConnection skinConnection = (HttpsURLConnection) skinUrl.openConnection();
|
||||||
premiumCheck.setConnectTimeout(0);
|
skinConnection.setConnectTimeout(0);
|
||||||
premiumCheck.setRequestMethod("HEAD");
|
skinConnection.setDefaultUseCaches(false);
|
||||||
premiumCheck.setDefaultUseCaches(false);
|
skinConnection.setUseCaches(false);
|
||||||
premiumCheck.setUseCaches(false);
|
|
||||||
|
|
||||||
if (premiumCheck.getResponseCode() == HttpsURLConnection.HTTP_OK) {
|
if (skinConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
|
||||||
final HttpsURLConnection skinConnection = (HttpsURLConnection) skinUrl.openConnection();
|
|
||||||
skinConnection.setConnectTimeout(0);
|
|
||||||
skinConnection.setDefaultUseCaches(false);
|
|
||||||
skinConnection.setUseCaches(false);
|
|
||||||
final InputStreamReader skinStream = new InputStreamReader(skinConnection.getInputStream());
|
final InputStreamReader skinStream = new InputStreamReader(skinConnection.getInputStream());
|
||||||
final JsonObject response = new JsonParser().parse(skinStream).getAsJsonObject();
|
final JsonObject response = new JsonParser().parse(skinStream).getAsJsonObject();
|
||||||
final String uuid = response.get("uuid").getAsString();
|
|
||||||
final JsonObject rawSkin = response.getAsJsonObject("textures").getAsJsonObject("raw");
|
final JsonObject rawSkin = response.getAsJsonObject("textures").getAsJsonObject("raw");
|
||||||
texture = rawSkin.get("value").getAsString();
|
texture = rawSkin.get("value").getAsString();
|
||||||
signature = rawSkin.get("signature").getAsString();
|
signature = rawSkin.get("signature").getAsString();
|
||||||
skinStream.close();
|
skinStream.close();
|
||||||
skinConnection.disconnect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
premiumCheck.disconnect();
|
skinConnection.disconnect();
|
||||||
|
|
||||||
final PlayerProfile profile = player.getPlayerProfile();
|
final PlayerProfile profile = player.getPlayerProfile();
|
||||||
profile.setName(nameShort);
|
profile.setName(nameShort);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package pw.kaboom.extras;
|
package pw.kaboom.extras;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -18,6 +20,21 @@ class PlayerChat implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
|
void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
final UUID playerUuid = event.getPlayer().getUniqueId();
|
||||||
|
|
||||||
|
if (main.commandMillisList.get(playerUuid) != null) {
|
||||||
|
final long millisDifference = System.currentTimeMillis() - main.commandMillisList.get(playerUuid);
|
||||||
|
|
||||||
|
if (millisDifference < 20) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main.commandMillisList.put(playerUuid, System.currentTimeMillis());
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (main.getConfig().getString(player.getUniqueId().toString()) != null) {
|
if (main.getConfig().getString(player.getUniqueId().toString()) != null) {
|
||||||
final String prefix = ChatColor.translateAlternateColorCodes(
|
final String prefix = ChatColor.translateAlternateColorCodes(
|
||||||
|
|
|
@ -42,17 +42,35 @@ class PlayerCommand implements Listener {
|
||||||
if (("/minecraft:execute".equals(arr[0].toLowerCase()) ||
|
if (("/minecraft:execute".equals(arr[0].toLowerCase()) ||
|
||||||
"/execute".equals(arr[0].toLowerCase())) &&
|
"/execute".equals(arr[0].toLowerCase())) &&
|
||||||
arr.length >= 2) {
|
arr.length >= 2) {
|
||||||
final StringBuilder stringBuilder = new StringBuilder();
|
|
||||||
|
|
||||||
for (int i = 1; i < arr.length; i++) {
|
for (int i = 1; i < arr.length; i++) {
|
||||||
stringBuilder.append(arr[i]).append(" ");
|
if ("as".equalsIgnoreCase(arr[i]) ||
|
||||||
}
|
"at".equalsIgnoreCase(arr[i])) {
|
||||||
if (stringBuilder.toString().toLowerCase().contains("run execute") ||
|
for (int i2 = i+1; i2 < arr.length; i2++) {
|
||||||
stringBuilder.toString().toLowerCase().contains("run gamerule randomtickspeed") ||
|
if ("at".equalsIgnoreCase(arr[i2]) ||
|
||||||
stringBuilder.toString().toLowerCase().contains("run particle") ||
|
"as".equalsIgnoreCase(arr[i2])) {
|
||||||
stringBuilder.toString().toLowerCase().contains("run save-off") ||
|
Command.broadcastCommandMessage(event.getPlayer(), "Forbidden execute pattern detected");
|
||||||
stringBuilder.toString().toLowerCase().contains("run stop")) {
|
event.setCancelled(true);
|
||||||
event.setCancelled(true);
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (i+1 < arr.length &&
|
||||||
|
"run".equalsIgnoreCase(arr[i])) {
|
||||||
|
if ("execute".equalsIgnoreCase(arr[i+1]) ||
|
||||||
|
"particle".equalsIgnoreCase(arr[i+1]) ||
|
||||||
|
"save-off".equalsIgnoreCase(arr[i+1]) ||
|
||||||
|
"stop".equalsIgnoreCase(arr[i+1])) {
|
||||||
|
Command.broadcastCommandMessage(event.getPlayer(), "Forbidden execute command detected");
|
||||||
|
event.setCancelled(true);
|
||||||
|
break;
|
||||||
|
} else if (i+3 < arr.length &&
|
||||||
|
"gamerule".equalsIgnoreCase(arr[i+1])) {
|
||||||
|
if ("randomTickSpeed".equalsIgnoreCase(arr[i+2]) &&
|
||||||
|
Double.parseDouble(arr[i+3]) > 6) {
|
||||||
|
event.setMessage(command.replaceFirst("(?i)" + "randomTickSpeed " + arr[i+3], "randomTickSpeed 6"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (("/minecraft:gamerule".equalsIgnoreCase(arr[0]) ||
|
} else if (("/minecraft:gamerule".equalsIgnoreCase(arr[0]) ||
|
||||||
"/gamerule".equalsIgnoreCase(arr[0])) &&
|
"/gamerule".equalsIgnoreCase(arr[0])) &&
|
||||||
|
|
|
@ -50,7 +50,7 @@ class PlayerConnection implements Listener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final World world : Bukkit.getWorlds()) {
|
/*for (final World world : Bukkit.getWorlds()) {
|
||||||
for (final Chunk chunk : world.getLoadedChunks()) {
|
for (final Chunk chunk : world.getLoadedChunks()) {
|
||||||
try {
|
try {
|
||||||
chunk.getTileEntities(false);
|
chunk.getTileEntities(false);
|
||||||
|
@ -62,7 +62,7 @@ class PlayerConnection implements Listener {
|
||||||
}.runTask(main);
|
}.runTask(main);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -127,25 +127,18 @@ class PlayerConnection implements Listener {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
final URL skinUrl = new URL("https://api.ashcon.app/mojang/v2/user/" + player.getName());
|
final URL skinUrl = new URL("https://api.ashcon.app/mojang/v2/user/" + player.getName());
|
||||||
final HttpsURLConnection premiumCheck = (HttpsURLConnection) skinUrl.openConnection();
|
final HttpsURLConnection skinConnection = (HttpsURLConnection) skinUrl.openConnection();
|
||||||
premiumCheck.setConnectTimeout(0);
|
skinConnection.setConnectTimeout(0);
|
||||||
premiumCheck.setRequestMethod("HEAD");
|
skinConnection.setDefaultUseCaches(false);
|
||||||
premiumCheck.setDefaultUseCaches(false);
|
skinConnection.setUseCaches(false);
|
||||||
premiumCheck.setUseCaches(false);
|
|
||||||
|
|
||||||
if (premiumCheck.getResponseCode() == HttpsURLConnection.HTTP_OK) {
|
if (skinConnection.getResponseCode() == HttpsURLConnection.HTTP_OK) {
|
||||||
final HttpsURLConnection skinConnection = (HttpsURLConnection) skinUrl.openConnection();
|
|
||||||
skinConnection.setConnectTimeout(0);
|
|
||||||
skinConnection.setDefaultUseCaches(false);
|
|
||||||
skinConnection.setUseCaches(false);
|
|
||||||
final InputStreamReader skinStream = new InputStreamReader(skinConnection.getInputStream());
|
final InputStreamReader skinStream = new InputStreamReader(skinConnection.getInputStream());
|
||||||
final JsonObject response = new JsonParser().parse(skinStream).getAsJsonObject();
|
final JsonObject response = new JsonParser().parse(skinStream).getAsJsonObject();
|
||||||
final String uuid = response.get("uuid").getAsString();
|
|
||||||
final JsonObject rawSkin = response.getAsJsonObject("textures").getAsJsonObject("raw");
|
final JsonObject rawSkin = response.getAsJsonObject("textures").getAsJsonObject("raw");
|
||||||
final String texture = rawSkin.get("value").getAsString();
|
final String texture = rawSkin.get("value").getAsString();
|
||||||
final String signature = rawSkin.get("signature").getAsString();
|
final String signature = rawSkin.get("signature").getAsString();
|
||||||
skinStream.close();
|
skinStream.close();
|
||||||
skinConnection.disconnect();
|
|
||||||
|
|
||||||
final PlayerProfile textureProfile = player.getPlayerProfile();
|
final PlayerProfile textureProfile = player.getPlayerProfile();
|
||||||
textureProfile.clearProperties();
|
textureProfile.clearProperties();
|
||||||
|
@ -158,7 +151,7 @@ class PlayerConnection implements Listener {
|
||||||
}.runTask(main);
|
}.runTask(main);
|
||||||
}
|
}
|
||||||
|
|
||||||
premiumCheck.disconnect();
|
skinConnection.disconnect();
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.bukkit.command.Command;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import org.bukkit.event.server.RemoteServerCommandEvent;
|
||||||
import org.bukkit.event.server.ServerCommandEvent;
|
import org.bukkit.event.server.ServerCommandEvent;
|
||||||
|
|
||||||
class ServerCommand implements Listener {
|
class ServerCommand implements Listener {
|
||||||
|
@ -21,22 +22,44 @@ class ServerCommand implements Listener {
|
||||||
final String[] arr = event.getCommand().split(" ");
|
final String[] arr = event.getCommand().split(" ");
|
||||||
final String command = event.getCommand();
|
final String command = event.getCommand();
|
||||||
|
|
||||||
if (main.consoleCommandBlacklist.contains(arr[0].toLowerCase())) {
|
if (event.getSender() instanceof BlockCommandSender) {
|
||||||
event.setCancelled(true);
|
if (main.consoleCommandBlacklist.contains(arr[0].toLowerCase())) {
|
||||||
} else if (("minecraft:execute".equals(arr[0].toLowerCase()) ||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (("minecraft:execute".equals(arr[0].toLowerCase()) ||
|
||||||
"execute".equals(arr[0].toLowerCase())) &&
|
"execute".equals(arr[0].toLowerCase())) &&
|
||||||
arr.length >= 2) {
|
arr.length >= 2) {
|
||||||
final StringBuilder stringBuilder = new StringBuilder();
|
|
||||||
|
|
||||||
for (int i = 1; i < arr.length; i++) {
|
for (int i = 1; i < arr.length; i++) {
|
||||||
stringBuilder.append(arr[i]).append(" ");
|
if ("as".equalsIgnoreCase(arr[i]) ||
|
||||||
}
|
"at".equalsIgnoreCase(arr[i])) {
|
||||||
if (stringBuilder.toString().toLowerCase().contains("run execute") ||
|
for (int i2 = i+1; i2 < arr.length; i2++) {
|
||||||
stringBuilder.toString().toLowerCase().contains("run gamerule randomtickspeed") ||
|
if ("at".equalsIgnoreCase(arr[i2]) ||
|
||||||
stringBuilder.toString().toLowerCase().contains("run particle") ||
|
"as".equalsIgnoreCase(arr[i2])) {
|
||||||
stringBuilder.toString().toLowerCase().contains("run save-off") ||
|
Command.broadcastCommandMessage(event.getSender(), "Forbidden execute pattern detected");
|
||||||
stringBuilder.toString().toLowerCase().contains("run stop")) {
|
event.setCancelled(true);
|
||||||
event.setCancelled(true);
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (i+1 < arr.length &&
|
||||||
|
"run".equalsIgnoreCase(arr[i])) {
|
||||||
|
if ("execute".equalsIgnoreCase(arr[i+1]) ||
|
||||||
|
"particle".equalsIgnoreCase(arr[i+1]) ||
|
||||||
|
"save-off".equalsIgnoreCase(arr[i+1]) ||
|
||||||
|
"stop".equalsIgnoreCase(arr[i+1])) {
|
||||||
|
Command.broadcastCommandMessage(event.getSender(), "Forbidden execute command detected");
|
||||||
|
event.setCancelled(true);
|
||||||
|
break;
|
||||||
|
} else if (i+3 < arr.length &&
|
||||||
|
"gamerule".equalsIgnoreCase(arr[i+1])) {
|
||||||
|
if ("randomTickSpeed".equalsIgnoreCase(arr[i+2]) &&
|
||||||
|
Double.parseDouble(arr[i+3]) > 6) {
|
||||||
|
event.setCommand(command.replaceFirst("(?i)" + "randomTickSpeed " + arr[i+3], "randomTickSpeed 6"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (("minecraft:gamerule".equalsIgnoreCase(arr[0]) ||
|
} else if (("minecraft:gamerule".equalsIgnoreCase(arr[0]) ||
|
||||||
"gamerule".equalsIgnoreCase(arr[0])) &&
|
"gamerule".equalsIgnoreCase(arr[0])) &&
|
||||||
|
|
Loading…
Reference in a new issue