diff --git a/src/main/java/kamkeel/npcs/command/CommandKamkeel.java b/src/main/java/kamkeel/npcs/command/CommandKamkeel.java index 51d34efd1..67d7e7288 100644 --- a/src/main/java/kamkeel/npcs/command/CommandKamkeel.java +++ b/src/main/java/kamkeel/npcs/command/CommandKamkeel.java @@ -6,13 +6,12 @@ import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.server.MinecraftServer; import noppes.npcs.CustomNpcsPermissions; +import noppes.npcs.attribute.AttributeController; +import noppes.npcs.attribute.AttributeDefinition; import noppes.npcs.scripted.CustomNPCsException; import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class CommandKamkeel extends CommandBase{ @@ -112,6 +111,13 @@ public class CommandKamkeel extends CommandBase{ if(usage.equals("") || usage.equals("[player]")) { return CommandBase.getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames()); } + else if(usage.equals("")) { + List keys = new ArrayList<>(); + for (AttributeDefinition def : AttributeController.getAllAttributes()) { + keys.add(def.getKey()); + } + return CommandBase.getListOfStringsMatchingLastWord(args, keys.toArray(new String[keys.size()])); + } } } return command.addTabCompletionOptions(sender, Arrays.copyOfRange(args, 1, args.length)); diff --git a/src/main/java/kamkeel/npcs/command/HelpCommand.java b/src/main/java/kamkeel/npcs/command/HelpCommand.java index 18423a975..c5c3948d2 100644 --- a/src/main/java/kamkeel/npcs/command/HelpCommand.java +++ b/src/main/java/kamkeel/npcs/command/HelpCommand.java @@ -45,7 +45,7 @@ public class HelpCommand extends CommandKamkeelBase{ } if(command.subcommands.isEmpty()){ - sender.addChatMessage(new ChatComponentTranslation(command.getCommandUsage(sender))); + sendMessage(sender, (command.getCommandUsage(sender))); return; } @@ -57,17 +57,17 @@ public class HelpCommand extends CommandKamkeelBase{ sendMessage(sender, "\u00A78------ \u00A7a" + command.getCommandName().toUpperCase() + " SubCommands \u00A78------"); sendMessage(sender, "\u00A77Usage: \u00A76" + command.getUsage()); for(Entry entry : command.subcommands.entrySet()){ - sender.addChatMessage(new ChatComponentTranslation("\u00A77> " + "\u00A7e" + entry.getKey() + "\u00A78: \u00A77" + entry.getValue().getAnnotation(SubCommand.class).desc())); + sendMessage(sender, ("\u00A77> " + "\u00A7e" + entry.getKey() + "\u00A78: \u00A77" + entry.getValue().getAnnotation(SubCommand.class).desc())); } - sender.addChatMessage(new ChatComponentTranslation("\u00A78Permission:\u00A77 " + CommandKamkeel.getCommandPermission(command.getCommandName()))); + sendMessage(sender, ("\u00A78Permission:\u00A77 " + CommandKamkeel.getCommandPermission(command.getCommandName()))); } else{ sendMessage(sender, "\u00A78------ \u00A7b" + command.getCommandName().toUpperCase() + "." + args[1].toUpperCase() + " Command \u00A78------"); SubCommand sc = m.getAnnotation(SubCommand.class); - sender.addChatMessage(new ChatComponentTranslation("\u00A77" + sc.desc())); + sendMessage(sender, ("\u00A77" + sc.desc())); if(!sc.usage().isEmpty()) - sender.addChatMessage(new ChatComponentTranslation("\u00A77Usage: \u00A76" + sc.usage())); - sender.addChatMessage(new ChatComponentTranslation("\u00A78Permission:\u00A77 " + getSubCommandPermission(args[1]))); + sendMessage(sender, ("\u00A77Usage: \u00A76" + sc.usage())); + sendMessage(sender, ("\u00A78Permission:\u00A77 " + getSubCommandPermission(args[1]))); } } } diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandHelpProfile.java b/src/main/java/kamkeel/npcs/command/profile/CommandHelpProfile.java index a03d30ea0..acba768f5 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandHelpProfile.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandHelpProfile.java @@ -47,7 +47,7 @@ public class CommandHelpProfile extends CommandProfileBase { } if(command.subcommands.isEmpty()){ - sender.addChatMessage(new ChatComponentTranslation(command.getCommandUsage(sender))); + sendMessage(sender, (command.getCommandUsage(sender))); return; } @@ -63,7 +63,7 @@ public class CommandHelpProfile extends CommandProfileBase { SubCommand sc = entry.getValue().getAnnotation(SubCommand.class); // For players, only list subcommands if they have permission; for console, show all. if(!(sender instanceof EntityPlayer) || command.canSendCommand(sender, sc, entry.getKey())){ - sender.addChatMessage(new ChatComponentTranslation("\u00A77> " + sendMessage(sender, ("\u00A77> " + "\u00A7e" + entry.getKey() + "\u00A78: \u00A77" + sc.desc())); } @@ -71,7 +71,7 @@ public class CommandHelpProfile extends CommandProfileBase { // Show permission node only if sender is console or has permission. if(!(sender instanceof EntityPlayer) || CustomNpcsPermissions.hasPermission((EntityPlayer)sender, CustomNpcsPermissions.PROFILE_ADMIN)){ - sender.addChatMessage(new ChatComponentTranslation("\u00A78Permission:\u00A77 " + sendMessage(sender, ("\u00A78Permission:\u00A77 " + CommandProfile.getCommandPermission(command.getCommandName()))); } } @@ -79,13 +79,13 @@ public class CommandHelpProfile extends CommandProfileBase { sendMessage(sender, "\u00A78------ \u00A7b" + command.getCommandName().toUpperCase() + "." + args[1].toUpperCase() + " Command \u00A78------"); SubCommand sc = m.getAnnotation(SubCommand.class); - sender.addChatMessage(new ChatComponentTranslation("\u00A77" + sc.desc())); + sendMessage(sender, ("\u00A77" + sc.desc())); if(!sc.usage().isEmpty()){ - sender.addChatMessage(new ChatComponentTranslation("\u00A77Usage: \u00A76" + sc.usage())); + sendMessage(sender, ("\u00A77Usage: \u00A76" + sc.usage())); } if(!(sender instanceof EntityPlayer) || CustomNpcsPermissions.hasPermission((EntityPlayer)sender, CustomNpcsPermissions.PROFILE_ADMIN)){ - sender.addChatMessage(new ChatComponentTranslation("\u00A78Permission:\u00A77 " + sendMessage(sender, ("\u00A78Permission:\u00A77 " + getSubCommandPermission(args[1]))); } } diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index 699117a03..856a98b39 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -27,6 +27,7 @@ import net.minecraft.server.MinecraftServer; import net.minecraftforge.common.ForgeChunkManager; import net.minecraftforge.common.MinecraftForge; import nikedemos.markovnames.generators.*; +import noppes.npcs.attribute.AttributeController; import noppes.npcs.compat.PixelmonHelper; import noppes.npcs.config.ConfigMain; import noppes.npcs.config.LoadConfiguration; @@ -218,6 +219,8 @@ public class CustomNpcs { new ProfileController(); ProfileController.registerProfileType(new CNPCData()); + new AttributeController(); + ScriptController.Instance.loadStoredData(); ScriptController.Instance.loadForgeScripts(); ScriptController.Instance.loadGlobalNPCScripts(); diff --git a/src/main/java/noppes/npcs/attribute/AttributeController.java b/src/main/java/noppes/npcs/attribute/AttributeController.java index 505062895..1cb762a6f 100644 --- a/src/main/java/noppes/npcs/attribute/AttributeController.java +++ b/src/main/java/noppes/npcs/attribute/AttributeController.java @@ -9,8 +9,19 @@ import java.util.Map; * It ensures that keys are unique. */ public class AttributeController { + + public AttributeController Instance; + public ModAttributes attributes; + private static final Map definitions = new HashMap<>(); + public AttributeController(){ + this.Instance = this; + definitions.clear(); + attributes = new ModAttributes(); + } + + public static AttributeDefinition registerAttribute(String key, String displayName, AttributeValueType valueType) { if (definitions.containsKey(key)) { throw new IllegalArgumentException("Attribute already registered with key: " + key); diff --git a/src/main/java/noppes/npcs/attribute/ModAttributes.java b/src/main/java/noppes/npcs/attribute/ModAttributes.java index d780b88bf..1c1d6ae62 100644 --- a/src/main/java/noppes/npcs/attribute/ModAttributes.java +++ b/src/main/java/noppes/npcs/attribute/ModAttributes.java @@ -4,18 +4,18 @@ package noppes.npcs.attribute; * ModAttributes registers the core attributes (both non–magic and magic–based). */ public class ModAttributes { - public static final AttributeDefinition MAIN_ATTACK_FLAT; - public static final AttributeDefinition MAIN_ATTACK_PERCENT; - public static final AttributeDefinition HEALTH; - public static final AttributeDefinition CRITICAL_CHANCE_PERCENT; - public static final AttributeDefinition CRITICAL_DAMAGE_FLAT; + public static AttributeDefinition MAIN_ATTACK_FLAT; + public static AttributeDefinition MAIN_ATTACK_PERCENT; + public static AttributeDefinition HEALTH; + public static AttributeDefinition CRITICAL_CHANCE_PERCENT; + public static AttributeDefinition CRITICAL_DAMAGE_FLAT; - public static final AttributeDefinition MAGIC_DAMAGE_FLAT; - public static final AttributeDefinition MAGIC_DAMAGE_PERCENT; - public static final AttributeDefinition MAGIC_DEFENSE_FLAT; - public static final AttributeDefinition MAGIC_RESISTANCE_PERCENT; + public static AttributeDefinition MAGIC_DAMAGE_FLAT; + public static AttributeDefinition MAGIC_DAMAGE_PERCENT; + public static AttributeDefinition MAGIC_DEFENSE_FLAT; + public static AttributeDefinition MAGIC_RESISTANCE_PERCENT; - static { + public ModAttributes(){ MAIN_ATTACK_FLAT = AttributeController.registerAttribute(AttributeKeys.MAIN_ATTACK_FLAT, "Main Attack Damage", AttributeValueType.FLAT); MAIN_ATTACK_PERCENT = AttributeController.registerAttribute(AttributeKeys.MAIN_ATTACK_PERCENT, "Main Attack Damage (%)", AttributeValueType.PERCENT); HEALTH = AttributeController.registerAttribute(AttributeKeys.HEALTH, "Health", AttributeValueType.FLAT);