Command system rewrite using Drink and Maven support.
This commit is contained in:
36
.gitignore
vendored
Normal file
36
.gitignore
vendored
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Mobile Tools for Java (J2ME)
|
||||||
|
.mtj.tmp/
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
.idea/
|
||||||
|
target/
|
||||||
|
pom.xml.tag
|
||||||
|
pom.xml.releaseBackup
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
pom.xml.next
|
||||||
|
release.properties
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
buildNumber.properties
|
||||||
|
.mvn/timing.properties
|
||||||
|
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
|
||||||
|
.mvn/wrapper/maven-wrapper.jar
|
||||||
63
pom.xml
Normal file
63
pom.xml
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>me.horsenuggets</groupId>
|
||||||
|
<artifactId>PlayerAI</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<name>PlayerAI</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>8</source>
|
||||||
|
<target>8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||||
|
<shadedClassifierName>shaded</shadedClassifierName>
|
||||||
|
<transformers>
|
||||||
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
|
||||||
|
</transformers>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot</artifactId>
|
||||||
|
<version>1.16.4-R0.1-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.jonahseguin</groupId>
|
||||||
|
<artifactId>drink</artifactId>
|
||||||
|
<version>1.0.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
54
src/main/java/net/nuggetmc/ai/PlayerAI.java
Normal file
54
src/main/java/net/nuggetmc/ai/PlayerAI.java
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
package net.nuggetmc.ai;
|
||||||
|
|
||||||
|
import net.nuggetmc.ai.commands.CommandHandler;
|
||||||
|
import net.nuggetmc.ai.npc.NPCManager;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public class PlayerAI extends JavaPlugin {
|
||||||
|
|
||||||
|
public static final double VERSION = 1.0;
|
||||||
|
|
||||||
|
private static PlayerAI instance;
|
||||||
|
|
||||||
|
private CommandHandler handler;
|
||||||
|
private NPCManager manager;
|
||||||
|
|
||||||
|
public static PlayerAI getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandHandler getHandler() {
|
||||||
|
return handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NPCManager getManager() {
|
||||||
|
return manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
instance = this;
|
||||||
|
|
||||||
|
// Create Instances
|
||||||
|
this.handler = new CommandHandler();
|
||||||
|
this.manager = new NPCManager(this);
|
||||||
|
|
||||||
|
// Register all the things
|
||||||
|
this.registerEvents();
|
||||||
|
|
||||||
|
// Create Netty injections
|
||||||
|
manager.connectAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
manager.reset();
|
||||||
|
manager.disconnectAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerEvents() {
|
||||||
|
getServer().getPluginManager().registerEvents(manager, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
45
src/main/java/net/nuggetmc/ai/commands/CommandHandler.java
Normal file
45
src/main/java/net/nuggetmc/ai/commands/CommandHandler.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package net.nuggetmc.ai.commands;
|
||||||
|
|
||||||
|
import com.jonahseguin.drink.CommandService;
|
||||||
|
import com.jonahseguin.drink.Drink;
|
||||||
|
import com.jonahseguin.drink.annotation.Command;
|
||||||
|
import com.jonahseguin.drink.command.DrinkCommandContainer;
|
||||||
|
import com.jonahseguin.drink.command.DrinkCommandService;
|
||||||
|
import net.nuggetmc.ai.PlayerAI;
|
||||||
|
import net.nuggetmc.ai.commands.commands.PlayerAICommand;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class CommandHandler {
|
||||||
|
|
||||||
|
private final DrinkCommandService drink;
|
||||||
|
|
||||||
|
public CommandHandler() {
|
||||||
|
drink = (DrinkCommandService) Drink.get(PlayerAI.getInstance());
|
||||||
|
drink.register(new PlayerAICommand(this), "playerai", "pai");
|
||||||
|
drink.registerCommands();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getUsage(Class<? extends CommandInstance> clazz) {
|
||||||
|
return getSubCommands(clazz).stream().map(c -> {
|
||||||
|
Command command = c.getAnnotation(Command.class);
|
||||||
|
return ChatColor.GRAY + " ▪ " + ChatColor.YELLOW + "/" + getRootName(clazz) + (command.name().isEmpty() ? "" : " " + command.name()) + ChatColor.GRAY + " ▪ "
|
||||||
|
+ ChatColor.RESET + command.desc();
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRootName(Class<? extends CommandInstance> clazz) {
|
||||||
|
return drink.getCommands().entrySet().stream()
|
||||||
|
.filter(c -> c.getValue().getObject().getClass().isAssignableFrom(clazz)).map(Map.Entry::getKey).findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Method> getSubCommands(Class<? extends CommandInstance> clazz) {
|
||||||
|
return Arrays.stream(clazz.getDeclaredMethods()).filter(m -> m.isAnnotationPresent(Command.class)).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
14
src/main/java/net/nuggetmc/ai/commands/CommandInstance.java
Normal file
14
src/main/java/net/nuggetmc/ai/commands/CommandInstance.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package net.nuggetmc.ai.commands;
|
||||||
|
|
||||||
|
public abstract class CommandInstance {
|
||||||
|
|
||||||
|
private final CommandHandler commandHandler;
|
||||||
|
|
||||||
|
public CommandInstance(CommandHandler commandHandler) {
|
||||||
|
this.commandHandler = commandHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandHandler getCommandHandler() {
|
||||||
|
return commandHandler;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package net.nuggetmc.ai.commands.commands;
|
||||||
|
|
||||||
|
import com.jonahseguin.drink.annotation.Command;
|
||||||
|
import com.jonahseguin.drink.annotation.OptArg;
|
||||||
|
import com.jonahseguin.drink.annotation.Sender;
|
||||||
|
import com.jonahseguin.drink.annotation.Text;
|
||||||
|
import net.nuggetmc.ai.PlayerAI;
|
||||||
|
import net.nuggetmc.ai.commands.CommandHandler;
|
||||||
|
import net.nuggetmc.ai.commands.CommandInstance;
|
||||||
|
import net.nuggetmc.ai.npc.NPC;
|
||||||
|
import net.nuggetmc.ai.npc.NPCManager;
|
||||||
|
import net.nuggetmc.ai.utils.ChatUtils;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class PlayerAICommand extends CommandInstance {
|
||||||
|
|
||||||
|
public PlayerAICommand(CommandHandler commandHandler) {
|
||||||
|
super(commandHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command(name = "", desc = "Test Description")
|
||||||
|
public void rootCommand(@Sender Player sender) {
|
||||||
|
sender.sendMessage(ChatUtils.LINE);
|
||||||
|
sender.sendMessage(ChatColor.GOLD + "PlayerAI" + ChatColor.GRAY + " [" + ChatColor.RED + "v" + PlayerAI.VERSION + ChatColor.GRAY + "]");
|
||||||
|
|
||||||
|
for (String s : this.getCommandHandler().getUsage(PlayerAICommand.class)) {
|
||||||
|
sender.sendMessage(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(ChatUtils.LINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command(name = "create", desc = "Create bots.", usage = "<name> [skin]")
|
||||||
|
public void createBotCommand(@Sender Player sender, String name, @OptArg() String skin) {
|
||||||
|
NPC.createNPC(name, sender.getLocation(), skin.isEmpty() ? name : skin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command(name = "debug", desc = "Debug bot stats.")
|
||||||
|
public void debugCommand(@Sender Player sender) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command(name = "info", desc = "Information about loaded bots.")
|
||||||
|
public void infoCommand(@Sender Player sender) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command(name = "reset", desc = "Remove all loaded bots.")
|
||||||
|
public void resetCommand(@Sender Player sender) {
|
||||||
|
sender.sendMessage("Removing every bot...");
|
||||||
|
NPCManager manager = PlayerAI.getInstance().getManager();
|
||||||
|
int size = manager.fetch().size();
|
||||||
|
manager.reset();
|
||||||
|
String formatted = NumberFormat.getNumberInstance(Locale.US).format(size);
|
||||||
|
sender.sendMessage("Removed " + ChatColor.RED + formatted + ChatColor.RESET + " entit" + (size == 1 ? "y" : "ies") + ".");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
24
src/main/java/net/nuggetmc/ai/utils/MojangAPI.java
Normal file
24
src/main/java/net/nuggetmc/ai/utils/MojangAPI.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package net.nuggetmc.ai.utils;
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class MojangAPI {
|
||||||
|
|
||||||
|
public static String[] getSkin(String name) {
|
||||||
|
try {
|
||||||
|
String uuid = new JsonParser().parse(new InputStreamReader(new URL("https://api.mojang.com/users/profiles/minecraft/" + name)
|
||||||
|
.openStream())).getAsJsonObject().get("id").getAsString();
|
||||||
|
JsonObject property = new JsonParser()
|
||||||
|
.parse(new InputStreamReader(new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false")
|
||||||
|
.openStream())).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject();
|
||||||
|
return new String[] {property.get("value").getAsString(), property.get("signature").getAsString()};
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,12 +3,7 @@ main: net.nuggetmc.ai.PlayerAI
|
|||||||
version: 1.0
|
version: 1.0
|
||||||
api-version: 1.16
|
api-version: 1.16
|
||||||
author: HorseNuggets
|
author: HorseNuggets
|
||||||
commands:
|
|
||||||
playerai:
|
|
||||||
description: The PlayerAI base command.
|
|
||||||
permission: playerai.manage
|
|
||||||
usage: /playerai
|
|
||||||
aliases: [bot, pai, ai, npc]
|
|
||||||
permissions:
|
permissions:
|
||||||
playerai.*:
|
playerai.*:
|
||||||
description: PlayerAI parent permission.
|
description: PlayerAI parent permission.
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
package net.nuggetmc.ai;
|
|
||||||
|
|
||||||
import net.nuggetmc.ai.cmd.CommandHandler;
|
|
||||||
import net.nuggetmc.ai.cmd.CommandInterface;
|
|
||||||
import net.nuggetmc.ai.cmd.commands.CreateCommand;
|
|
||||||
import net.nuggetmc.ai.cmd.commands.DebugCommand;
|
|
||||||
import net.nuggetmc.ai.cmd.commands.InfoCommand;
|
|
||||||
import net.nuggetmc.ai.cmd.commands.ResetCommand;
|
|
||||||
import net.nuggetmc.ai.npc.NPCManager;
|
|
||||||
import org.bukkit.command.PluginCommand;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
public class PlayerAI extends JavaPlugin {
|
|
||||||
|
|
||||||
private static PlayerAI instance;
|
|
||||||
|
|
||||||
private final CommandHandler handler;
|
|
||||||
private final NPCManager manager;
|
|
||||||
|
|
||||||
public PlayerAI() {
|
|
||||||
instance = this;
|
|
||||||
|
|
||||||
this.handler = new CommandHandler();
|
|
||||||
this.manager = new NPCManager(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PlayerAI getInstance() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommandHandler getHandler() {
|
|
||||||
return handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NPCManager getManager() {
|
|
||||||
return manager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
|
||||||
getServer().getPluginManager().registerEvents(manager, this);
|
|
||||||
registerCommands();
|
|
||||||
|
|
||||||
manager.connectAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDisable() {
|
|
||||||
manager.reset();
|
|
||||||
manager.disconnectAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerCommands() {
|
|
||||||
handler.register(new CommandInterface[] {
|
|
||||||
new CreateCommand(),
|
|
||||||
new InfoCommand(),
|
|
||||||
new DebugCommand(),
|
|
||||||
new ResetCommand()
|
|
||||||
});
|
|
||||||
|
|
||||||
PluginCommand command = getCommand("playerai");
|
|
||||||
|
|
||||||
if (command != null) {
|
|
||||||
command.setExecutor(handler);
|
|
||||||
command.setTabCompleter(handler);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
package net.nuggetmc.ai.cmd;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.nuggetmc.ai.utils.ChatUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.command.TabCompleter;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class CommandHandler implements CommandExecutor, TabCompleter {
|
|
||||||
|
|
||||||
private final Map<String, CommandInterface> commands = new HashMap<>();
|
|
||||||
|
|
||||||
private final String prefix = "bot";
|
|
||||||
|
|
||||||
public void register(CommandInterface[] subCmds) {
|
|
||||||
for (CommandInterface cmd : subCmds) {
|
|
||||||
commands.put(cmd.getName(), cmd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String fetchName(CommandInterface subCmd) {
|
|
||||||
String name = subCmd.getClass().getSimpleName();
|
|
||||||
return name.substring(0, name.length() - 7).toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean exists(String name) {
|
|
||||||
return commands.containsKey(name.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
private CommandInterface getExecutor(String name) {
|
|
||||||
return commands.get(name.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String nonPlayerMsg() {
|
|
||||||
return ChatColor.RED + "You must be a player to execute this command!";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String usageMsg(CommandInterface subCmd) {
|
|
||||||
return ChatColor.RED + "Invalid arguments!\nUsage: /" + prefix + " " + subCmd.getName() + " " + subCmd.getUsage();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendCmdInfo(CommandSender sender) {
|
|
||||||
sender.sendMessage(ChatUtils.LINE);
|
|
||||||
sender.sendMessage(ChatColor.GOLD + "PlayerAI" + ChatColor.GRAY + " [" + ChatColor.RED + "v1.0" + ChatColor.GRAY + "]");
|
|
||||||
|
|
||||||
for (Map.Entry<String, CommandInterface> entry : commands.entrySet()) {
|
|
||||||
sender.sendMessage(ChatColor.GRAY + " ▪ " + ChatColor.YELLOW + "/" + prefix + " " + entry.getKey() + ChatColor.GRAY + " ▪ "
|
|
||||||
+ ChatColor.RESET + entry.getValue().getDescription());
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage(ChatUtils.LINE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (args.length == 0 || !exists(args[0])) {
|
|
||||||
sendCmdInfo(sender);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
getExecutor(args[0]).onCommand(sender, cmd, label, Arrays.copyOfRange(args, 1, args.length));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (!cmd.getName().equals("playerai")) return null;
|
|
||||||
|
|
||||||
List<String> groupnames;
|
|
||||||
int n = args.length;
|
|
||||||
|
|
||||||
switch (n) {
|
|
||||||
case 1:
|
|
||||||
groupnames = new ArrayList<>(commands.keySet());
|
|
||||||
String arg = args[n - 1];
|
|
||||||
|
|
||||||
if (!isEmptyTab(arg)) {
|
|
||||||
return autofill(groupnames, arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return groupnames;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isEmptyTab(String s) {
|
|
||||||
return s == null || s.equals("") || s.equals(" ") || s.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> autofill(List<String> groupnames, String input) {
|
|
||||||
List<String> list = new ArrayList<>();
|
|
||||||
|
|
||||||
for (String entry : groupnames) {
|
|
||||||
if (entry.length() >= input.length()) {
|
|
||||||
if (input.equalsIgnoreCase(entry.substring(0, input.length()))) {
|
|
||||||
list.add(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
|
||||||
return groupnames;
|
|
||||||
}
|
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package net.nuggetmc.ai.cmd;
|
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
public interface CommandInterface {
|
|
||||||
String getName();
|
|
||||||
String getDescription();
|
|
||||||
String getUsage();
|
|
||||||
|
|
||||||
void onCommand(CommandSender sender, Command cmd, String label, String[] args);
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
package net.nuggetmc.ai.cmd.commands;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.nuggetmc.ai.PlayerAI;
|
|
||||||
import net.nuggetmc.ai.cmd.CommandHandler;
|
|
||||||
import net.nuggetmc.ai.cmd.CommandInterface;
|
|
||||||
import net.nuggetmc.ai.npc.NPC;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class CreateCommand implements CommandInterface {
|
|
||||||
|
|
||||||
private final CommandHandler HANDLER;
|
|
||||||
|
|
||||||
private final String NAME;
|
|
||||||
private final String DESCRIPTION = "Create bots.";
|
|
||||||
private final String CMD_ARGS = "<name> [skin]";
|
|
||||||
|
|
||||||
public CreateCommand() {
|
|
||||||
this.HANDLER = PlayerAI.getInstance().getHandler();
|
|
||||||
this.NAME = HANDLER.fetchName(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return NAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDescription() {
|
|
||||||
return DESCRIPTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUsage() {
|
|
||||||
return CMD_ARGS;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
if (!(sender instanceof Player)) {
|
|
||||||
sender.sendMessage(HANDLER.nonPlayerMsg());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.length == 0) {
|
|
||||||
sender.sendMessage(HANDLER.usageMsg(this));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String skin;
|
|
||||||
|
|
||||||
if (args.length > 1) {
|
|
||||||
skin = args[1];
|
|
||||||
} else {
|
|
||||||
skin = args[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
Player player = (Player) sender;
|
|
||||||
NPC npc = NPC.createNPC(args[0], player.getLocation(), skin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
package net.nuggetmc.ai.cmd.commands;
|
|
||||||
|
|
||||||
import net.nuggetmc.ai.PlayerAI;
|
|
||||||
import net.nuggetmc.ai.cmd.CommandHandler;
|
|
||||||
import net.nuggetmc.ai.cmd.CommandInterface;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class DebugCommand implements CommandInterface {
|
|
||||||
|
|
||||||
private final CommandHandler handler;
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
private final String description = "Debug bot stats.";
|
|
||||||
private final String cmdArgs = "";
|
|
||||||
|
|
||||||
public DebugCommand() {
|
|
||||||
this.handler = PlayerAI.getInstance().getHandler();
|
|
||||||
this.name = handler.fetchName(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUsage() {
|
|
||||||
return cmdArgs;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean active = false;
|
|
||||||
|
|
||||||
private Set<BukkitRunnable> tasks = new HashSet<>();
|
|
||||||
|
|
||||||
private double round2Dec(double n) {
|
|
||||||
return Math.round(n * 100) / 100.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package net.nuggetmc.ai.cmd.commands;
|
|
||||||
|
|
||||||
import net.nuggetmc.ai.PlayerAI;
|
|
||||||
import net.nuggetmc.ai.cmd.CommandHandler;
|
|
||||||
import net.nuggetmc.ai.cmd.CommandInterface;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
public class InfoCommand implements CommandInterface {
|
|
||||||
|
|
||||||
private final CommandHandler handler;
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
private final String description = "Information about loaded bots.";
|
|
||||||
private final String cmdArgs = "";
|
|
||||||
|
|
||||||
public InfoCommand() {
|
|
||||||
this.handler = PlayerAI.getInstance().getHandler();
|
|
||||||
this.name = handler.fetchName(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUsage() {
|
|
||||||
return cmdArgs;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
package net.nuggetmc.ai.cmd.commands;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.nuggetmc.ai.PlayerAI;
|
|
||||||
import net.nuggetmc.ai.cmd.CommandHandler;
|
|
||||||
import net.nuggetmc.ai.cmd.CommandInterface;
|
|
||||||
import net.nuggetmc.ai.npc.NPCManager;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import java.text.NumberFormat;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public class ResetCommand implements CommandInterface {
|
|
||||||
|
|
||||||
private final PlayerAI plugin;
|
|
||||||
|
|
||||||
private final CommandHandler handler;
|
|
||||||
private final NPCManager manager;
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
private final String description = "Remove all loaded bots.";
|
|
||||||
private final String cmdArgs = "";
|
|
||||||
|
|
||||||
public ResetCommand() {
|
|
||||||
this.plugin = PlayerAI.getInstance();
|
|
||||||
this.handler = plugin.getHandler();
|
|
||||||
this.manager = plugin.getManager();
|
|
||||||
this.name = handler.fetchName(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getUsage() {
|
|
||||||
return cmdArgs;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
|
||||||
sender.sendMessage("Removing every bot...");
|
|
||||||
int size = manager.fetch().size();
|
|
||||||
|
|
||||||
manager.reset();
|
|
||||||
|
|
||||||
String en;
|
|
||||||
if (size == 1) {
|
|
||||||
en = "y";
|
|
||||||
} else {
|
|
||||||
en = "ies";
|
|
||||||
}
|
|
||||||
|
|
||||||
String formatted = NumberFormat.getNumberInstance(Locale.US).format(size);
|
|
||||||
sender.sendMessage("Removed " + ChatColor.RED + formatted + ChatColor.RESET + " entit" + en + ".");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package net.nuggetmc.ai.utils;
|
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
public class MojangAPI {
|
|
||||||
|
|
||||||
public static String[] getSkin(String name) {
|
|
||||||
try {
|
|
||||||
URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + name);
|
|
||||||
InputStreamReader reader = new InputStreamReader(url.openStream());
|
|
||||||
String uuid = new JsonParser().parse(reader).getAsJsonObject().get("id").getAsString();
|
|
||||||
|
|
||||||
URL url2 = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false");
|
|
||||||
InputStreamReader reader2 = new InputStreamReader(url2.openStream());
|
|
||||||
JsonObject property = new JsonParser().parse(reader2).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject();
|
|
||||||
String texture = property.get("value").getAsString();
|
|
||||||
String signature = property.get("signature").getAsString();
|
|
||||||
|
|
||||||
return new String[] {texture, signature};
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user