mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 05:45:03 +00:00
Register Item Attribute Controller
This commit is contained in:
1 parent
d41311147c
commit
c3573d5d2c
6 files changed
+46
-26
No files matched your search
@@ -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("<player>") || usage.equals("[player]")) {
|
||||
return CommandBase.getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames());
|
||||
}
|
||||
else if(usage.equals("<attribute>")) {
|
||||
List<String> 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));
|
||||
|
||||
@@ -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<String, Method> 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])));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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])));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<String, AttributeDefinition> 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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user