39 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package net.knarcraft.blacksmith.command;
 | |
| 
 | |
| import net.citizensnpcs.api.CitizensAPI;
 | |
| import net.citizensnpcs.api.npc.NPC;
 | |
| import net.knarcraft.blacksmith.config.NPCSetting;
 | |
| import net.knarcraft.blacksmith.trait.BlacksmithTrait;
 | |
| import org.bukkit.command.Command;
 | |
| import org.bukkit.command.CommandExecutor;
 | |
| import org.bukkit.command.CommandSender;
 | |
| import org.jetbrains.annotations.NotNull;
 | |
| 
 | |
| public class NPCSettingCommand implements CommandExecutor {
 | |
| 
 | |
|     @Override
 | |
|     public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
 | |
|         NPC npc = CitizensAPI.getDefaultNPCSelector().getSelected(sender);
 | |
|         if (npc == null || !npc.hasTrait(BlacksmithTrait.class)) {
 | |
|             sender.sendMessage("You must select an NPC before running this command");
 | |
|             return true;
 | |
|         }
 | |
|         BlacksmithTrait blacksmithTrait = npc.getTrait(BlacksmithTrait.class);
 | |
| 
 | |
|         for (NPCSetting npcSetting : NPCSetting.values()) {
 | |
|             String commandName = npcSetting.getCommandName();
 | |
|             if (commandName.equalsIgnoreCase(args[0])) {
 | |
|                 if (args.length < 2) {
 | |
|                     sender.sendMessage("Current value of " + commandName + ": " +
 | |
|                             blacksmithTrait.getSettings().getRawValue(npcSetting));
 | |
|                 } else {
 | |
|                     blacksmithTrait.getSettings().changeSetting(npcSetting, args[1]);
 | |
|                 }
 | |
|                 return true;
 | |
|             }
 | |
|         }
 | |
|         return false;
 | |
|     }
 | |
| 
 | |
| }
 |