53 lines
1.9 KiB
Java
53 lines
1.9 KiB
Java
package party._2a03.mc.command;
|
|
|
|
import com.mojang.brigadier.CommandDispatcher;
|
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|
import net.minecraft.server.command.CommandManager;
|
|
import net.minecraft.server.command.ServerCommandSource;
|
|
import net.minecraft.server.network.ServerPlayerEntity;
|
|
import net.minecraft.text.Text;
|
|
import party._2a03.mc.util.Database;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.InputStreamReader;
|
|
import java.io.IOException;
|
|
import java.net.URL;
|
|
import java.util.UUID;
|
|
|
|
public class SkinCommand {
|
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
|
LiteralArgumentBuilder literalargumentbuilder = CommandManager.literal("skin");
|
|
|
|
literalargumentbuilder.then(CommandManager.literal("assign")
|
|
.requires(ctx -> { return ctx.hasPermissionLevel(2); })
|
|
.then(CommandManager.argument("UUID", StringArgumentType.word())
|
|
.then(CommandManager.argument("url", StringArgumentType.greedyString())
|
|
.executes(ctx -> {
|
|
ServerCommandSource source = ctx.getSource();
|
|
String magic, skinval, skinsig;
|
|
try {
|
|
URL url = new URL(StringArgumentType.getString(ctx, "url"));
|
|
BufferedReader read = new BufferedReader(new InputStreamReader(url.openStream()));
|
|
magic = read.readLine();
|
|
skinval = read.readLine();
|
|
skinsig = read.readLine();
|
|
read.close();
|
|
} catch (IOException e) {
|
|
source.sendFeedback(() -> Text.of("Failed to access skin"), false);
|
|
return 1;
|
|
}
|
|
if (!magic.equals("SKIN:1") || skinval == null || skinsig == null) {
|
|
source.sendFeedback(() -> Text.of("Invalid skin"), false);
|
|
return 1;
|
|
}
|
|
UUID uuid = UUID.fromString(StringArgumentType.getString(ctx, "UUID"));
|
|
Database.getPlayer(uuid).setTextures(skinval, skinsig);
|
|
source.sendFeedback(() -> Text.of("User's skin has been updated (" + uuid.toString() + ")"), true);
|
|
return 1;
|
|
}))));
|
|
|
|
dispatcher.register(literalargumentbuilder);
|
|
}
|
|
}
|