public static String getEntityName(Entity entity) {

    String entityName = null;
    if (!EpicSystem.useCitizens()) {
      if (entity instanceof Villager) entityName = ((Villager) entity).getCustomName();
    } else {
      if (CitizensAPI.getNPCRegistry().isNPC(entity)) {
        NPC citizensNPC = CitizensAPI.getNPCRegistry().getNPC(entity);
        entityName = ChatColor.stripColor(citizensNPC.getName());
      }
    }
    if (entityName == null) entityName = entity.getType().toString();
    return entityName;
  }
 @Override
 protected Prompt acceptValidatedInput(ConversationContext context, Number input) {
   boolean found = false;
   for (NPC npc : choices) {
     if (input.intValue() == npc.getId()) {
       found = true;
       break;
     }
   }
   CommandSender sender = (CommandSender) context.getForWhom();
   if (!found) {
     Messaging.sendErrorTr(sender, Messages.SELECTION_PROMPT_INVALID_CHOICE, input);
     return this;
   }
   NPC toSelect = CitizensAPI.getNPCRegistry().getById(input.intValue());
   try {
     callback.run(toSelect);
   } catch (ServerCommandException ex) {
     Messaging.sendTr(sender, CommandMessages.MUST_BE_INGAME);
   } catch (CommandUsageException ex) {
     Messaging.sendError(sender, ex.getMessage());
     Messaging.sendError(sender, ex.getUsage());
   } catch (UnhandledCommandException ex) {
     ex.printStackTrace();
   } catch (WrappedCommandException ex) {
     ex.getCause().printStackTrace();
   } catch (CommandException ex) {
     Messaging.sendError(sender, ex.getMessage());
   } catch (NumberFormatException ex) {
     Messaging.sendErrorTr(sender, CommandMessages.INVALID_NUMBER);
   }
   return null;
 }
Beispiel #3
0
 public NPC getCitizen() {
   NPC npc = CitizensAPI.getNPCRegistry().getById(npcid);
   if (npc == null)
     dB.log(
         "Uh oh! Denizen has encountered an NPE while trying to fetch a NPC. Has this NPC been removed?");
   return npc;
 }
 public static void start(Callback callback, Conversable player, List<NPC> possible) {
   final Conversation conversation =
       new ConversationFactory(CitizensAPI.getPlugin())
           .withLocalEcho(false)
           .withEscapeSequence("exit")
           .withModality(false)
           .withFirstPrompt(new NPCCommandSelector(callback, possible))
           .buildConversation(player);
   conversation.begin();
 }
Beispiel #5
0
  @Override
  public void onEnable() {
    // Disable if the server is not using the compatible Minecraft version
    String mcVersion = ((CraftServer) getServer()).getServer().getVersion();
    compatible = mcVersion.startsWith(COMPATIBLE_MC_VERSION);
    if (!compatible) {
      Messaging.severeTr(Messages.CITIZENS_INCOMPATIBLE, getDescription().getVersion(), mcVersion);
      getServer().getPluginManager().disablePlugin(this);
      return;
    }
    config = new Settings(getDataFolder());
    setupTranslator();
    registerScriptHelpers();

    saves = NPCDataStore.create(getDataFolder());
    if (saves == null) {
      Messaging.severeTr(Messages.FAILED_LOAD_SAVES);
      getServer().getPluginManager().disablePlugin(this);
      return;
    }

    npcRegistry = new CitizensNPCRegistry(saves);
    traitFactory = new CitizensTraitFactory();
    selector = new NPCSelector(this);
    CitizensAPI.setImplementation(this);

    getServer().getPluginManager().registerEvents(new EventListen(), this);

    if (Setting.NPC_COST.asDouble() > 0) setupEconomy();

    registerCommands();
    enableSubPlugins();
    Messaging.logTr(Messages.CITIZENS_ENABLED, getDescription().getVersion());

    // Setup NPCs after all plugins have been enabled (allows for multiworld
    // support and for NPCs to properly register external settings)
    if (getServer()
            .getScheduler()
            .scheduleSyncDelayedTask(
                this,
                new Runnable() {
                  @Override
                  public void run() {
                    saves.loadInto(npcRegistry);
                    startMetrics();
                    scheduleSaveTask(Setting.SAVE_TASK_DELAY.asInt());
                    Bukkit.getPluginManager().callEvent(new CitizensEnableEvent());
                  }
                },
                1)
        == -1) {
      Messaging.severeTr(Messages.LOAD_TASK_NOT_SCHEDULED);
      getServer().getPluginManager().disablePlugin(this);
    }
  }
  @EventHandler
  public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    if (!npc.isSpawned()
        || !event.getPlayer().equals(player)
        || !npc.equals(CitizensAPI.getNPCRegistry().getNPC(event.getRightClicked()))) return;

    Equipper equipper = EQUIPPERS.get(npc.getEntity().getType());
    if (equipper == null) equipper = new GenericEquipper();
    equipper.equip(event.getPlayer(), npc);
    event.setCancelled(true);
  }
 public void call(Player p, String[] args) {
   List<NPCStatistic> npcs =
       Managers.getStatisticManager().getAllStatistics(p.getName(), NPCStatistic.class);
   for (NPCStatistic n : npcs) {
     NPC npc = CitizensAPI.getNPCRegistry().getById(n.getNpcid());
     if (npc == null) continue;
     if (MQAddonCitizens.descriptionManager.activeNPCs.contains(npc.getId())) {
       Frontend.openFrontend(p, npc);
       return;
     }
   }
   p.sendMessage("No such contact!");
 }
Beispiel #8
0
  @Override
  public void onDisable() {
    Bukkit.getPluginManager().callEvent(new CitizensDisableEvent());
    Editor.leaveAll();
    CitizensAPI.shutdown();

    tearDownScripting();
    // Don't bother with this part if MC versions are not compatible
    if (compatible) {
      saves.storeAll(npcRegistry);
      saves.saveToDiskImmediate();
      despawnNPCs();
      npcRegistry = null;
    }

    Messaging.logTr(Messages.CITIZENS_DISABLED, getDescription().getVersion());
  }
 @Override
 public void noOptionSpecified(CommandSender p, String[] args) {
   List<String> tosend = new ArrayList<String>();
   tosend.add(ChatUtils.formatHeader("Active Contacts"));
   List<NPCStatistic> npcs =
       Managers.getStatisticManager().getAllStatistics(p.getName(), NPCStatistic.class);
   for (NPCStatistic n : npcs) {
     NPC npc = CitizensAPI.getNPCRegistry().getById(n.getNpcid());
     if (npc == null) continue;
     tosend.add(
         formatNPC(npc.getName(), npc.getBukkitEntity().getLocation().getWorld().getName()));
   }
   tosend.add(ChatUtils.formatHeader("To call a contact, use /contacts call <name>"));
   for (String s : tosend) {
     p.sendMessage(s);
   }
 }
 private void updateAllNPCs(MarkerSet npcset) {
   Iterable<NPCRegistry> reg = CitizensAPI.getNPCRegistries();
   HashSet<String> toremove = new HashSet<String>(existingnpcs);
   if (reg != null) {
     for (NPCRegistry r : reg) {
       for (NPC npc : r) {
         processNPC(npcset, npc, toremove);
       }
     }
   }
   for (String s : toremove) {
     Marker m = npcset.findMarker(s);
     if (m != null) {
       m.deleteMarker();
     }
     existingnpcs.remove(s);
   }
 }
 @Override
 public void die(DamageSource damagesource) {
   // players that die are not normally removed from the world. when the
   // NPC dies, we are done with the instance and it should be removed.
   if (dead) {
     return;
   }
   super.die(damagesource);
   Bukkit.getScheduler()
       .runTaskLater(
           CitizensAPI.getPlugin(),
           new Runnable() {
             @Override
             public void run() {
               world.removeEntity(EntityHumanNPC.this);
             }
           },
           35); // give enough time for death and smoke animation
 }
 @Override
 public boolean damageEntity(DamageSource damagesource, float f) {
   // knock back velocity is cancelled and sent to client for handling when
   // the entity is a player. there is no client so make this happen
   // manually.
   boolean damaged = super.damageEntity(damagesource, f);
   if (damaged && velocityChanged) {
     velocityChanged = false;
     Bukkit.getScheduler()
         .runTask(
             CitizensAPI.getPlugin(),
             new Runnable() {
               @Override
               public void run() {
                 EntityHumanNPC.this.velocityChanged = true;
               }
             });
   }
   return damaged;
 }
Beispiel #13
0
 private static void createInstance() {
   Locale locale = Locale.getDefault();
   String setting = Setting.LOCALE.asString();
   if (!setting.isEmpty()) {
     String[] parts = setting.split("[\\._]");
     switch (parts.length) {
       case 1:
         locale = new Locale(parts[0]);
         break;
       case 2:
         locale = new Locale(parts[0], parts[1]);
         break;
       case 3:
         locale = new Locale(parts[0], parts[1], parts[2]);
         break;
       default:
         break;
     }
   }
   instance = new Translator(new File(CitizensAPI.getDataFolder(), "lang"), locale);
   Messaging.logTr(Messages.LOCALE_NOTIFICATION, locale);
 }
Beispiel #14
0
 public void onEnable() {
   Bukkit.broadcastMessage("RELOADING TEST FIVE");
   pl = this;
   MySQL = new MySQL((Plugin) this, "localhost", "3306", "RPG", "root", "enter11284");
   MySQL.openConnection();
   connect =
       new BukkitRunnable() {
         public void run() {
           if (!MySQL.checkConnection()) {
             BlackLance.openConnect();
           }
         }
       }.runTaskTimer(this, 20, 60);
   c = MySQL.getConnection();
   try {
     RPGPlayer.createRPGPlayers();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   try {
     ResourceNodes.generateHay();
     ResourceNodes.generateSweetGum();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   File configFile = new File(this.getDataFolder(), "config.yml");
   PluginManager pm = getServer().getPluginManager();
   pm.registerEvents(new CombatListeners(this), this);
   pm.registerEvents(new Horses(), this);
   pm.registerEvents(new PlayerListeners(this, configFile), this);
   pm.registerEvents(new ExperienceListeners(), this);
   pm.registerEvents(new ObjectiveProcessor(this), this);
   pm.registerEvents(new DropListeners(this), this);
   pm.registerEvents(new NPCListeners(this), this);
   pm.registerEvents(new SmeltingListeners(), this);
   pm.registerEvents(new SmithingListeners(), this);
   pm.registerEvents(new HerbloreListeners(), this);
   pm.registerEvents(new BlockListeners(this), this);
   pm.registerEvents(new MenuListeners(this), this);
   pm.registerEvents(new ItemListeners(this), this);
   pm.registerEvents(new ConsumableListener(this), this);
   pm.registerEvents(new TradeListener(), this);
   pm.registerEvents(new Alchemy.MenuListeners(), this);
   getCommand("horse").setExecutor(new CommandParser());
   getCommand("setup").setExecutor(new CommandParser());
   getCommand("blevel").setExecutor(new CommandParser());
   getCommand("blreload").setExecutor(new CommandParser());
   getCommand("lookup").setExecutor(new CommandParser());
   getCommand("resource").setExecutor(new CommandParser());
   net.citizensnpcs.api.CitizensAPI.getTraitFactory()
       .registerTrait(net.citizensnpcs.api.trait.TraitInfo.create(blm.class).withName("blm"));
   HashMap<Location, Material> toRegen = Mine.getRegen();
   Iterable<Location> locar = toRegen.keySet();
   for (locar.iterator(); locar.iterator().hasNext(); ) {
     Location l1 = locar.iterator().next();
     Bukkit.broadcastMessage("Loc: " + l1.getX());
     l1.getBlock().setType(toRegen.get(l1));
   }
   if (!configFile.exists()) {
     this.saveDefaultConfig();
   }
 }
Beispiel #15
0
 private void registerScriptHelpers() {
   setupScripting();
   ScriptCompiler compiler = CitizensAPI.getScriptCompiler();
   compiler.registerGlobalContextProvider(new EventRegistrar(this));
   compiler.registerGlobalContextProvider(new ObjectProvider("plugin", this));
 }
Beispiel #16
0
  public void onEnable() {

    if (getServer().getPluginManager().getPlugin("Citizens") == null
        || getServer().getPluginManager().getPlugin("Citizens").isEnabled() == false) {
      getLogger().log(java.util.logging.Level.SEVERE, "Citizens 2.0 not found or not enabled");
      getServer().getPluginManager().disablePlugin(this);
      return;
    }

    if (getServer().getPluginManager().getPlugin("dynmap") == null
        || getServer().getPluginManager().getPlugin("dynmap").isEnabled() == false) {
      getLogger().log(java.util.logging.Level.SEVERE, "dynmap not found or not enabled");
      getServer().getPluginManager().disablePlugin(this);
    }

    if (getServer().getPluginManager().getPlugin("HyperConomy") == null) {
      getLogger().log(java.util.logging.Level.SEVERE, "Hyperconomoy Not found");
      bHyperConomyExists = false;
    } else {
      for (Plugin oPlug : getServer().getPluginManager().getPlugins()) {
        getLogger().log(java.util.logging.Level.SEVERE, "plugin:" + oPlug.getName());
      }

      if (getServer().getPluginManager().getPlugin("HyperMerchant") == null) {
        getLogger().log(java.util.logging.Level.SEVERE, "HyperMerchant Not found");
        bHyperConomyExists = false;
      } else {
        getLogger()
            .log(java.util.logging.Level.SEVERE, "Hyperconomy / Hypermerchant found. Enabled");
        bHyperConomyExists = true;
      }
    }

    SetupConfig();

    getLogger().log(java.util.logging.Level.INFO, "Connecting to DynMap");

    try {
      SetupDynMap();
    } catch (Exception err) {
      getLogger().log(java.util.logging.Level.INFO, "Errors while connecting to the Dynmap API");
      getServer().getPluginManager().disablePlugin(this);
      cDyn_Plugin = null;
      cDyn_MarkAPI = null;
      cDyn_Markers = null;
      return;
    }

    // Setup the Citizens NPC link
    net.citizensnpcs.api.CitizensAPI.getTraitFactory()
        .registerTrait(
            net.citizensnpcs.api.trait.TraitInfo.create(DynMapNPC_Trait.class)
                .withName("dynmapnpc"));

    // Schedule the main thread to monitor for NPCs
    cProcessing_Task =
        new DynMapNPC_Task(this)
            .runTaskTimer(
                this,
                this.getConfig().getLong("interval", 100L),
                this.getConfig().getLong("interval", 100L));

    if (this.getConfig().getBoolean("mcstats", true)) {
      try {
        MCStatsMetrics metrics = new MCStatsMetrics(this);
        metrics.start();
      } catch (Exception e) {
        // Failed to submit the stats :-(
      }
    }
  }
Beispiel #17
0
  @Override
  public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] inargs) {

    if (inargs.length == 0 || inargs[0].equalsIgnoreCase("help")) {
      sender.sendMessage(
          ChatColor.GOLD
              + "----- DynMapNPC Help ["
              + ChatColor.GREEN
              + "V"
              + this.getDescription().getVersion()
              + ChatColor.GOLD
              + "]-----");
      if (sender.hasPermission("dynmapnpc.info") || sender.isOp()) {
        sender.sendMessage(
            ChatColor.GOLD + "settings " + ChatColor.RED + "-- Display current defaults");
        sender.sendMessage(
            ChatColor.GOLD
                + "npc      "
                + ChatColor.RED
                + "-- Display settings on the selected NPC");
      }
      if (sender.hasPermission("dynmapnpc.settings") || sender.isOp()) {
        sender.sendMessage(
            ChatColor.GOLD
                + "----- DynMapNPC General Commands ["
                + ChatColor.GREEN
                + "/dmnpc"
                + ChatColor.GOLD
                + "] Help -----");

        sender.sendMessage(
            ChatColor.GOLD + "Toggle " + ChatColor.RED + "   -- Toggle showing NPC's on or off ");
        sender.sendMessage(
            ChatColor.GOLD
                + "reload "
                + ChatColor.RED
                + "   -- Reload the config file (-s saves first)");

        sender.sendMessage(
            ChatColor.GOLD
                + "----- DynMapNPC Config Commands ["
                + ChatColor.GREEN
                + "/dmnpcd"
                + ChatColor.GOLD
                + "] Help -----");

        sender.sendMessage(
            ChatColor.GOLD
                + "icon "
                + ChatColor.GREEN
                + "<IconName>  "
                + ChatColor.RED
                + "-- Icon to display ");
        sender.sendMessage(
            ChatColor.GOLD
                + "minzoom "
                + ChatColor.GREEN
                + "<10-0>   "
                + ChatColor.RED
                + "-- Minimum Zoom to show this NPC");
        sender.sendMessage(
            ChatColor.GOLD
                + "maxzoom "
                + ChatColor.GREEN
                + "<10-0>  "
                + ChatColor.RED
                + "-- Maximum Zoom to show this NPC");
        sender.sendMessage(
            ChatColor.GOLD + "showonmap " + ChatColor.RED + "        -- Toggle NPC's Visiblility");
        sender.sendMessage(
            ChatColor.GOLD
                + "showhcinv "
                + ChatColor.RED
                + "        -- Toggle Hyperconomy shop info");
        sender.sendMessage(
            ChatColor.GOLD
                + "----- DynMapNPC NPC Subcommands ["
                + ChatColor.GREEN
                + "/dmnpcn"
                + ChatColor.GOLD
                + "] Help -----");

        sender.sendMessage(
            ChatColor.GOLD
                + "Use  "
                + ChatColor.GREEN
                + "/trait dynmapnpc "
                + ChatColor.GOLD
                + " to attach this to a citizen");
        sender.sendMessage(
            ChatColor.GOLD
                + "icon "
                + ChatColor.GREEN
                + "<IconName>   "
                + ChatColor.RED
                + " -- Icon to display ");
        sender.sendMessage(
            ChatColor.GOLD
                + "name "
                + ChatColor.GREEN
                + "<NPC Name>   "
                + ChatColor.RED
                + " -- Text displayed on map ");
        sender.sendMessage(
            ChatColor.GOLD
                + "desc"
                + ChatColor.GREEN
                + "<Description> "
                + ChatColor.RED
                + " -- Secondary text to show");
        sender.sendMessage(
            ChatColor.GOLD
                + "minzoom "
                + ChatColor.GREEN
                + "<10-0>    "
                + ChatColor.RED
                + " -- Minimum Zoom to show this NPC");
        sender.sendMessage(
            ChatColor.GOLD
                + "maxzoom "
                + ChatColor.GREEN
                + "<10-0>    "
                + ChatColor.RED
                + " -- Maximum Zoom to show this NPC");
        sender.sendMessage(
            ChatColor.GOLD
                + "showonmap "
                + ChatColor.RED
                + "          -- Toggle NPC's Visiblility");
      }
      return true;
    }

    if (cmd.getName().equalsIgnoreCase("dmnpc")) {
      if (inargs[0].equalsIgnoreCase("toggle")) {
        if (!sender.hasPermission("dynmapnpc.settings") && !sender.isOp()) {
          sender.sendMessage(ChatColor.DARK_RED + "You do not have permission");
          return true;
        } else {
          if (cProcessing_Task == null) {
            // Schedule the main thread to monitor for NPCs
            cProcessing_Task =
                new DynMapNPC_Task(this)
                    .runTaskTimer(
                        this,
                        this.getConfig().getLong("interval", 100L),
                        this.getConfig().getLong("interval", 100L));
            sender.sendMessage(
                ChatColor.GREEN + " NPC Processing has been " + ChatColor.YELLOW + "Started");
          } else {
            cProcessing_Task.cancel();
            cProcessing_Task = null;
            sender.sendMessage(
                ChatColor.GREEN + " NPC Processing has been " + ChatColor.RED + "Stopped");
          }
          return true;
        }
      }
      if (inargs[0].equalsIgnoreCase("reload")) {
        if (!sender.hasPermission("dynmapnpc.settings") && !sender.isOp()) {
          sender.sendMessage(ChatColor.DARK_RED + "You do not have permission");
          return true;
        } else {
          if (inargs.length > 1) {
            if (inargs[1].equalsIgnoreCase("-s")) {
              this.saveConfig();
              sender.sendMessage(ChatColor.GREEN + " Config file  " + ChatColor.YELLOW + "Saved");
            }
          }
          this.reloadConfig();

          sender.sendMessage(ChatColor.GREEN + " Config file  " + ChatColor.YELLOW + "reloaded");
          return true;
        }
      }
    }

    if (cmd.getName().equalsIgnoreCase("dmnpcd")) {
      if (inargs[0].equalsIgnoreCase("settings")) {
        if (!sender.hasPermission("dynmapnpc.info") || !sender.isOp()) {
          sender.sendMessage(ChatColor.DARK_RED + "You do not have permission");
          return true;
        } else {
          sender.sendMessage(ChatColor.GOLD + "----- DynMapNPC Default Settings -----");
          sender.sendMessage(
              ChatColor.GREEN
                  + "MarkersetName:   "
                  + ChatColor.YELLOW
                  + " "
                  + this.getConfig().getString("markerset_name", "DynMapNPCs"));
          sender.sendMessage(
              ChatColor.GREEN
                  + "Update Interval: "
                  + ChatColor.YELLOW
                  + " "
                  + this.getConfig().getString("interval", "100"));
          sender.sendMessage(ChatColor.GOLD + "----- DynMapNPC NPC Default Settings -----");
          sender.sendMessage(
              ChatColor.GREEN
                  + "Icon:      "
                  + ChatColor.YELLOW
                  + " "
                  + this.getConfig().getString("defaults.icon", "offlineuser"));
          sender.sendMessage(
              ChatColor.GREEN
                  + "ShowOnMap: "
                  + ChatColor.YELLOW
                  + " "
                  + this.getConfig().getString("defaults.showonmap", "true"));
          sender.sendMessage(
              ChatColor.GREEN
                  + "Min Zoom:  "
                  + ChatColor.YELLOW
                  + " "
                  + this.getConfig().getString("defaults.zoomlevels.min", "10"));
          sender.sendMessage(
              ChatColor.GREEN
                  + "Max Zoom:  "
                  + ChatColor.YELLOW
                  + " "
                  + this.getConfig().getString("defaults.zoomlevels.max", "1"));
          return true;
        }
      }
      if (inargs[0].equalsIgnoreCase("icon")) {
        if (!sender.hasPermission("dynmapnpc.settings") || !sender.isOp()) {
          sender.sendMessage(ChatColor.DARK_RED + "You do not have permission");
          return true;
        } else {
          if (inargs.length == 2) {
            this.getConfig().set("defaults.icon", inargs[1]);
            sender.sendMessage(
                ChatColor.GREEN + "Default Icon: Set to " + ChatColor.YELLOW + inargs[1]);
          } else {
            sender.sendMessage(
                ChatColor.GREEN
                    + " Icon Name needed "
                    + ChatColor.YELLOW
                    + "Usage: "
                    + ChatColor.RED
                    + "/dnpcd icon <icon name>");
          }
          this.saveConfig();
          return true;
        }
      }
      if (inargs[0].equalsIgnoreCase("minzoom")) {
        if (!sender.hasPermission("dynmapnpc.settings") || !sender.isOp()) {
          sender.sendMessage(ChatColor.DARK_RED + "You do not have permission");
          return true;
        } else {
          if (inargs.length == 2) {
            this.getConfig().set("defaults.zoomlevels.min", Integer.parseInt(inargs[1]));
            sender.sendMessage(
                ChatColor.GREEN + "Default MinZoom: Set to " + ChatColor.YELLOW + inargs[1]);
          } else {
            sender.sendMessage(
                ChatColor.GREEN
                    + "Zoom level needed  "
                    + ChatColor.YELLOW
                    + "Usage: "
                    + ChatColor.RED
                    + "/dnpcd minzoom <0-10>");
          }
          this.saveConfig();
          return true;
        }
      }
      if (inargs[0].equalsIgnoreCase("maxzoom")) {
        if (!sender.hasPermission("dynmapnpc.settings") || !sender.isOp()) {
          sender.sendMessage(ChatColor.DARK_RED + "You do not have permission");
          return true;
        } else {
          if (inargs.length == 2) {
            this.getConfig().set("defaults.zoomlevels.max", Integer.parseInt(inargs[1]));
            sender.sendMessage(
                ChatColor.GREEN + "Default MaxZoom: Set to " + ChatColor.YELLOW + inargs[1]);
          } else {
            sender.sendMessage(
                ChatColor.GREEN
                    + "Zoom level needed  "
                    + ChatColor.YELLOW
                    + "Usage: "
                    + ChatColor.RED
                    + "/dnpcd mxnzoom <0-10>");
          }
          this.saveConfig();
          return true;
        }
      }
      if (inargs[0].equalsIgnoreCase("showonmap")) {
        if (!sender.hasPermission("dynmapnpc.settings") || !sender.isOp()) {
          sender.sendMessage(ChatColor.DARK_RED + "You do not have permission");
          return true;
        } else {
          if (this.getConfig().getBoolean("defaults.showonmap", true)) {
            sender.sendMessage(
                ChatColor.GREEN + "Default Showonmap: Set to " + ChatColor.YELLOW + "false");
            this.getConfig().set("defaults.showonmap", false);
          } else {
            sender.sendMessage(
                ChatColor.GREEN + "Default Showonmap: Set to " + ChatColor.YELLOW + "true");
            this.getConfig().set("defaults.showonmap", true);
          }
          this.saveConfig();
          return true;
        }
      }
      if (inargs[0].equalsIgnoreCase("showhcinv")) {
        if (!sender.hasPermission("dynmapnpc.settings") || !sender.isOp()) {
          sender.sendMessage(ChatColor.DARK_RED + "You do not have permission");
          return true;
        } else {
          if (this.getConfig().getBoolean("defaults.showhcinv", true)) {
            sender.sendMessage(
                ChatColor.GREEN + "Default showhcinv: Set to " + ChatColor.YELLOW + "false");
            this.getConfig().set("defaults.showhcinv", false);
          } else {
            sender.sendMessage(
                ChatColor.GREEN + "Default showhcinv: Set to " + ChatColor.YELLOW + "true");
            this.getConfig().set("defaults.showhcinv", true);
          }
          this.saveConfig();
          return true;
        }
      }
    }
    if (!(sender instanceof Player)) {
      sender.sendMessage(
          "The command you used either does not exist, or is not available from the console.");
      return true;
    }

    Player player = (Player) sender;

    // Citizens default code, left mostly intact

    // This block of code will allow your users to specify
    // The first will run the command on the selected NPC, the second on the NPC with npcID #.
    int npcid = -1;
    int i = 0;
    // did player specify a id?
    try {
      npcid = Integer.parseInt(inargs[0]);
      i = 1;
    } catch (Exception e) {
    }
    String[] args = new String[inargs.length - i];
    for (int j = i; j < inargs.length; j++) {
      args[j - i] = inargs[j];
    }

    // Now lets find the NPC this should run on.
    NPC npc;
    if (npcid == -1) {
      npc =
          ((Citizens) this.getServer().getPluginManager().getPlugin("Citizens"))
              .getNPCSelector()
              .getSelected(sender);
      if (npc != null) {
        // Gets NPC Selected for this sender
        npcid = npc.getId();
      } else {
        // no NPC selected.
        sender.sendMessage(ChatColor.RED + "You must have a NPC selected to use this command");
        return true;
      }
    }

    npc = CitizensAPI.getNPCRegistry().getById(npcid);
    if (npc == null) {
      // specified number doesn't exist.
      sender.sendMessage(ChatColor.RED + "NPC with id " + npcid + " not found");
      return true;
    }

    //	If you need access to the instance of MyTrait on the npc, get it like this
    DynMapNPC_Trait trait = null;
    if (!npc.hasTrait(DynMapNPC_Trait.class)) {
      sender.sendMessage(
          ChatColor.RED + "That command must be performed on a npc with trait: DynMapNPC");
      return true;
    } else trait = npc.getTrait(DynMapNPC_Trait.class);

    if (inargs[0].equalsIgnoreCase("npc")) {
      if (!player.hasPermission("dynmapnpc.info")) {
        player.sendMessage(ChatColor.DARK_RED + "You do not have permission");
        return true;
      } else {
        sender.sendMessage(ChatColor.GOLD + "----- DynMapNPC Settings -----");
        sender.sendMessage(
            ChatColor.GREEN + "Icon:        " + ChatColor.YELLOW + " " + trait.markerIcon);
        sender.sendMessage(
            ChatColor.GREEN + "Name:        " + ChatColor.YELLOW + " " + trait.markerName);
        sender.sendMessage(
            ChatColor.GREEN + "Description: " + ChatColor.YELLOW + " " + trait.markerDescription);
        sender.sendMessage(
            ChatColor.GREEN + "Min Zoom:    " + ChatColor.YELLOW + " " + trait.markerMinZoom);
        sender.sendMessage(
            ChatColor.GREEN + "Max Zoom:    " + ChatColor.YELLOW + " " + trait.markerMaxZoom);
        sender.sendMessage(
            ChatColor.GREEN
                + "Visible:     "
                + ChatColor.YELLOW
                + " "
                + (trait.markerShowOnMap ? "Showing on DynMap" : "Not Shown On Map"));
        ;
        return true;
      }
    }

    if (cmd.getName().equalsIgnoreCase("dmnpcn")) {
      if (inargs[0].equalsIgnoreCase("icon")) {
        if (!player.hasPermission("dynmapnpc.settings")) {
          player.sendMessage(ChatColor.DARK_RED + "You do not have permission");
          return true;
        } else {
          if (inargs.length == 2) {
            for (MarkerIcon oMrkrIcon : this.cDyn_MarkAPI.getMarkerIcons()) {
              if (oMrkrIcon.getMarkerIconID().toString().equalsIgnoreCase(inargs[1])) {
                // Found
                trait.markerIcon = inargs[1];
                player.sendMessage(
                    ChatColor.GREEN + "Icon: Set to " + ChatColor.YELLOW + inargs[1]);
                return true;
              }
            }
            player.sendMessage(
                ChatColor.GREEN
                    + "Icon: Icon does not exist in dynmap "
                    + ChatColor.YELLOW
                    + inargs[1]);
            return true;
          } else {
            player.sendMessage(
                ChatColor.GREEN
                    + "con Name needed "
                    + ChatColor.YELLOW
                    + "Usage: "
                    + ChatColor.RED
                    + "/dnpcn icon <icon name>");
          }
          return true;
        }
      }
      if (inargs[0].equalsIgnoreCase("minzoom")) {
        if (!player.hasPermission("dynmapnpc.settings")) {
          player.sendMessage(ChatColor.DARK_RED + "You do not have permission");
          return true;
        } else {
          if (inargs.length == 2) {
            try {
              trait.markerMinZoom = Integer.parseInt(inargs[1]);
              player.sendMessage(
                  ChatColor.GREEN + "MinZoom: Set to " + ChatColor.YELLOW + inargs[1]);
              return true;
            } catch (Exception err) {
            }
          }
          player.sendMessage(
              ChatColor.GREEN
                  + "Zoom level needed  "
                  + ChatColor.YELLOW
                  + "Usage: "
                  + ChatColor.RED
                  + "/dnpcn minzoom <0-10>");
          return true;
        }
      }
      if (inargs[0].equalsIgnoreCase("maxzoom")) {
        if (!player.hasPermission("dynmapnpc.settings")) {
          player.sendMessage(ChatColor.DARK_RED + "You do not have permission");
          return true;
        } else {
          if (inargs.length == 2) {
            try {
              trait.markerMaxZoom = Integer.parseInt(inargs[1]);
              player.sendMessage(
                  ChatColor.GREEN + "MaxZoom: Set to " + ChatColor.YELLOW + inargs[1]);
              return true;
            } catch (Exception err) {
            }
          }
          player.sendMessage(
              ChatColor.GREEN
                  + "Zoom level needed  "
                  + ChatColor.YELLOW
                  + "Usage: "
                  + ChatColor.RED
                  + "/dnpcn maxzoom <0-10>");
          return true;
        }
      }
      if (inargs[0].equalsIgnoreCase("name")) {
        if (!player.hasPermission("dynmapnpc.settings")) {
          player.sendMessage(ChatColor.DARK_RED + "You do not have permission");
          return true;
        } else {
          if (inargs.length == 2) {
            trait.markerName = inargs[1];
            player.sendMessage(ChatColor.GREEN + "Name: Set to " + ChatColor.YELLOW + inargs[1]);
          } else {
            player.sendMessage(
                ChatColor.GREEN
                    + "Name needed "
                    + ChatColor.YELLOW
                    + "Usage: "
                    + ChatColor.RED
                    + "/dnpcn name <Display Name>");
          }
          return true;
        }
      }
      if (inargs[0].equalsIgnoreCase("desc")) {
        if (!player.hasPermission("dynmapnpc.settings")) {
          player.sendMessage(ChatColor.DARK_RED + "You do not have permission");
          return true;
        } else {
          if (inargs.length == 2) {
            trait.markerDescription = inargs[1];
            player.sendMessage(
                ChatColor.GREEN + "Description: Set to " + ChatColor.YELLOW + inargs[1]);
          } else {
            player.sendMessage(
                ChatColor.GREEN
                    + "Name needed "
                    + ChatColor.YELLOW
                    + "Usage: "
                    + ChatColor.RED
                    + "/dnpcn desc <Description>");
          }
          return true;
        }
      }
      if (inargs[0].equalsIgnoreCase("showonmap")) {
        if (!player.hasPermission("dynmapnpc.settings")) {
          player.sendMessage(ChatColor.DARK_RED + "You do not have permission");
          return true;
        } else {
          if (trait.markerShowOnMap) {
            player.sendMessage(ChatColor.GREEN + "Showonmap: Set to " + ChatColor.YELLOW + "false");
          } else {
            player.sendMessage(ChatColor.GREEN + "Showonmap: Set to " + ChatColor.YELLOW + "true");
          }
          trait.markerShowOnMap = !trait.markerShowOnMap;
          return true;
        }
      }
    }

    player.sendMessage(ChatColor.RED + "invalid command. try help");
    return true; // do this if you didn't handle the command.
  }