Example #1
0
 @CommandRequirements()
 @Command(
     aliases = "npc",
     usage = "setowner [name]",
     desc = "set the owner of an NPC",
     modifiers = "setowner",
     min = 2,
     max = 2)
 public static void setOwner(CommandContext args, Player player, HumanNPC npc) {
   if ((!NPCManager.isOwner(player, npc.getUID())
           && PermissionManager.hasPermission(player, "citizens.admin.override.setowner"))
       || (NPCManager.isOwner(player, npc.getUID())
           && PermissionManager.hasPermission(player, "citizens.basic.modify.setowner"))) {
     player.sendMessage(
         ChatColor.GREEN
             + "The owner of "
             + StringUtils.wrap(npc.getName())
             + " is now "
             + StringUtils.wrap(args.getString(1))
             + ".");
     npc.getNPCData().setOwner(args.getString(1));
     return;
   }
   Messaging.sendError(player, MessageUtils.noPermissionsMessage);
 }
Example #2
0
 @Override
 public void onRightClick(Player player, HumanNPC npc) {
   if (PermissionManager.hasPermission(player, "citizens.wizard.use.interact")) {
     if (UtilityProperties.isHoldingTool("WizardInteractItem", player)) {
       WizardManager.handleRightClick(player, npc, "wizard." + mode.toString());
     } else if (UtilityProperties.isHoldingTool("WizardManaRegenItem", player)) {
       String msg = StringUtils.wrap(npc.getName() + "'s");
       int mana = 0;
       if (mana + 10 < Settings.getInt("WizardMaxMana")) {
         mana = mana + 10;
         msg += " mana has been increased to " + StringUtils.wrap(mana) + ".";
       } else if (mana + 10 == Settings.getInt("WizardMaxMana")) {
         mana = Settings.getInt("WizardMaxMana");
         msg += " mana has been fully replenished.";
       } else {
         msg += " mana cannot be regenerated with that item any further.";
         return;
       }
       InventoryUtils.decreaseItemInHand(player);
       player.sendMessage(msg);
       this.mana = mana;
     }
   } else {
     player.sendMessage(MessageUtils.noPermissionsMessage);
   }
 }
Example #3
0
 @Override
 public void onLeftClick(Player player, HumanNPC npc) {
   if (PermissionManager.hasPermission(player, "citizens.wizard.use.interact")) {
     if (UtilityProperties.isHoldingTool("WizardInteractItem", player)) {
       String msg = ChatColor.GREEN.toString();
       switch (mode) {
         case TELEPORT:
           if (locations.size() > 0) {
             cycle();
             msg += "Location set to " + StringUtils.wrap(getCurrentLocationName());
           } else {
             msg += ChatColor.RED + npc.getName() + " has no locations.";
           }
           break;
         case SPAWN:
           cycle();
           msg += "Mob to spawn set to " + StringUtils.wrap(StringUtils.format(mob));
           break;
         case TIME:
           cycle();
           msg += "Time setting set to " + StringUtils.wrap(time);
           break;
         case WEATHER:
           return;
         default:
           msg = ChatColor.RED + "No valid mode selected.";
       }
       player.sendMessage(msg);
     }
   } else {
     player.sendMessage(MessageUtils.noPermissionsMessage);
   }
 }
Example #4
0
 @Override
 public void doTick() {
   if (isTame) return;
   EntityHuman closest = getClosestPlayer(this.range);
   if (!hasTarget() && closest != null) {
     if (!PermissionManager.hasPermission(
         (Player) closest.getBukkitEntity(), "citizens.evils.immune")) {
       targetClosestPlayer(true, this.range);
     }
   }
   super.doTick();
 }
Example #5
0
 @CommandRequirements()
 @Command(
     aliases = "npc",
     usage = "remove (all)",
     desc = "remove NPCs",
     modifiers = "remove",
     min = 1,
     max = 2)
 public static void remove(CommandContext args, Player player, HumanNPC npc) {
   if (args.argsLength() == 2 && args.getString(1).equalsIgnoreCase("all")) {
     if (PermissionManager.hasPermission(player, "citizens.basic.modify.remove.all")) {
       if (NPCManager.GlobalUIDs.size() == 0) {
         Messaging.sendError(player, "There are no NPCs to remove.");
         return;
       }
       NPCManager.removeAll(NPCRemoveReason.COMMAND);
       NPCDataManager.deselectNPC(player);
       player.sendMessage(ChatColor.GRAY + "The NPC(s) disappeared.");
     } else {
       Messaging.sendError(player, MessageUtils.noPermissionsMessage);
     }
     return;
   }
   if (npc == null) {
     player.sendMessage(MessageUtils.mustHaveNPCSelectedMessage);
     return;
   }
   if ((!NPCManager.isOwner(player, npc.getUID())
           && PermissionManager.hasPermission(player, "citizens.admin.override.remove"))
       || (NPCManager.isOwner(player, npc.getUID())
           && PermissionManager.hasPermission(player, "citizens.basic.modify.remove"))) {
     NPCManager.remove(npc.getUID(), NPCRemoveReason.COMMAND);
     NPCDataManager.deselectNPC(player);
     player.sendMessage(StringUtils.wrap(npc.getName(), ChatColor.GRAY) + " disappeared.");
     return;
   }
   Messaging.sendError(player, MessageUtils.noPermissionsMessage);
 }
Example #6
0
 @Command(
     aliases = "npc",
     usage = "move",
     desc = "move an NPC",
     modifiers = "move",
     min = 1,
     max = 1)
 @CommandPermissions("basic.modify.move")
 public static void move(CommandContext args, Player player, HumanNPC npc) {
   if (npc.getWorld() != player.getWorld()
       && !PermissionManager.hasPermission(player, "citizens.basic.modify.move.multiworld")) {
     player.sendMessage(ChatColor.GRAY + "You don't have permission to move NPCs between worlds.");
     return;
   }
   player.sendMessage(StringUtils.wrap(npc.getName()) + " is en route to your location!");
   npc.teleport(player.getLocation());
   npc.getNPCData().setLocation(player.getLocation());
 }
Example #7
0
 @Command(
     aliases = "npc",
     usage = "money (give|take) (amount)",
     desc = "control an npc's balance",
     modifiers = "money",
     min = 1,
     max = 3)
 public static void money(CommandContext args, Player player, HumanNPC npc) {
   switch (args.argsLength()) {
     case 1:
       if (PermissionManager.hasPermission(player, "citizens.basic.use.showmoney")) {
         player.sendMessage(
             StringUtils.wrap(npc.getName())
                 + " has "
                 + StringUtils.wrap(Economy.format(npc.getBalance()))
                 + ".");
       } else {
         player.sendMessage(MessageUtils.noPermissionsMessage);
       }
       break;
     case 3:
       if (!PermissionManager.hasPermission(player, "citizens.basic.modify.money")) {
         player.sendMessage(MessageUtils.noPermissionsMessage);
         return;
       }
       double amount;
       try {
         amount = Double.parseDouble(args.getString(2));
       } catch (NumberFormatException e) {
         Messaging.sendError(player, "Invalid balance change amount entered.");
         return;
       }
       String keyword = "Took ";
       if (args.getString(1).contains("g")) {
         if (Economy.hasEnough(player, amount)) {
           keyword = "Gave ";
           Economy.pay(npc, -amount);
           Economy.pay(player, amount);
         } else {
           player.sendMessage(
               ChatColor.RED
                   + "You don't have enough money for that! Need "
                   + StringUtils.wrap(
                       Economy.format(amount - Economy.getBalance(player.getName())),
                       ChatColor.RED)
                   + " more.");
           return;
         }
       } else if (args.getString(1).contains("t")) {
         if (Economy.hasEnough(npc, amount)) {
           Economy.pay(npc, amount);
           Economy.pay(player, -amount);
         } else {
           player.sendMessage(
               ChatColor.RED
                   + "The npc doesn't have enough money for that! It needs "
                   + StringUtils.wrap(Economy.format(amount - npc.getBalance()), ChatColor.RED)
                   + " more in its balance.");
           return;
         }
       } else {
         player.sendMessage(
             ChatColor.RED
                 + "Invalid argument type "
                 + StringUtils.wrap(args.getString(1), ChatColor.RED)
                 + ".");
         return;
       }
       player.sendMessage(
           ChatColor.GREEN
               + keyword
               + StringUtils.wrap(Economy.format(amount))
               + " to "
               + StringUtils.wrap(npc.getName())
               + ". Your balance is now "
               + StringUtils.wrap(Economy.getFormattedBalance(player.getName()))
               + ".");
       break;
     default:
       Messaging.sendError(player, "Incorrect syntax. See /npc help");
       break;
   }
 }