Esempio n. 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);
 }
Esempio n. 2
0
 @Override
 public void onRightClick(Player player) {
   if (!PermissionManager.canCreate(player)) {
     Messaging.sendError(
         player, "You cannot tame this Evil NPC because you have reached the NPC creation limit.");
     return;
   }
   if (player.getItemInHand().getTypeId() != Settings.getInt("EvilTameItem")) return;
   if (random.nextInt(100) <= Settings.getInt("EvilTameChance")) {
     InventoryUtils.decreaseItemInHand(player);
     isTame = true;
     CreatureTask.despawn(this, NPCRemoveReason.OTHER);
     NPCManager.register(
         npc.getName(), player.getLocation(), player.getName(), NPCCreateReason.RESPAWN);
     player.sendMessage(
         ChatColor.GREEN
             + "You have tamed "
             + StringUtils.wrap(npc.getName())
             + "! You can now toggle it to be any type.");
   } else {
     Messaging.send(
         player,
         this.npc,
         StringUtils.colourise(Settings.getString("ChatFormat").replace("%name%", npc.getName()))
             + ChatColor.WHITE
             + MessageUtils.getRandomMessage(Settings.getString("EvilFailedTameMessages")));
   }
 }
Esempio n. 3
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);
   }
 }
Esempio n. 4
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);
   }
 }
Esempio n. 5
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();
 }
Esempio n. 6
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);
 }
Esempio n. 7
0
  @CommandRequirements()
  @Command(
      aliases = "npc",
      usage = "create [name] (text)",
      desc = "create an NPC",
      modifiers = "create",
      min = 2)
  @CommandPermissions("basic.create")
  public static void create(CommandContext args, Player player, HumanNPC npc) {
    if (!PermissionManager.canCreate(player)) {
      player.sendMessage(MessageUtils.reachedNPCLimitMessage);
      return;
    }
    ArrayDeque<String> texts = new ArrayDeque<String>();
    String firstArg = args.getString(1);
    if (args.argsLength() >= 3) {
      texts.add(args.getJoinedStrings(2));
    }
    if (firstArg.length() > 16) {
      player.sendMessage(
          ChatColor.RED + "The name of this NPC will be truncated - max name length is 16.");
      firstArg = args.getString(1).substring(0, 16);
    }
    if (Economy.useEconPlugin()) {
      if (Economy.hasEnough(player, UtilityProperties.getPrice("basic.creation"))) {
        double paid = Economy.pay(player, UtilityProperties.getPrice("basic.creation"));
        if (paid > 0) {
          player.sendMessage(
              MessageUtils.getPaidMessage(
                  player, "basic", "basic.creation", firstArg.replace("/", " "), false));
        }
      } else {
        player.sendMessage(MessageUtils.getNoMoneyMessage(player, "basic.creation"));
        return;
      }
    }
    int UID =
        NPCManager.register(
            firstArg, player.getLocation(), player.getName(), NPCCreateReason.COMMAND);
    NPCDataManager.setText(UID, texts);

    HumanNPC created = NPCManager.get(UID);
    created.getNPCData().setOwner(player.getName());
    Messaging.send(player, created, Settings.getString("CreationMessage"));

    NPCDataManager.selectNPC(player, NPCManager.get(UID));
    Messaging.send(player, created, Settings.getString("SelectionMessage"));
  }
Esempio n. 8
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());
 }
Esempio n. 9
0
 @Command(
     aliases = "npc",
     usage = "copy",
     desc = "copy an NPC",
     modifiers = "copy",
     min = 1,
     max = 1)
 @CommandPermissions("basic.modify.copy")
 public static void copy(CommandContext args, Player player, HumanNPC npc) {
   if (!PermissionManager.canCreate(player)) {
     player.sendMessage(MessageUtils.reachedNPCLimitMessage);
     return;
   }
   PropertyManager.save(npc);
   int newUID =
       NPCManager.register(
           npc.getName(), player.getLocation(), player.getName(), NPCCreateReason.COMMAND);
   HumanNPC newNPC = NPCManager.get(newUID);
   PropertyManager.copyNPCs(npc.getUID(), newUID);
   PropertyManager.load(newNPC);
   newNPC.teleport(player.getLocation());
   newNPC.getNPCData().setLocation(player.getLocation());
   player.sendMessage(StringUtils.wrap(npc.getName()) + " has been copied at your location.");
 }
Esempio n. 10
0
 @Override
 public void addPermissions() {
   PermissionManager.addPermission("admin.info");
   PermissionManager.addPermission("admin.clean");
   PermissionManager.addPermission("basic.use.help");
   PermissionManager.addPermission("admin.save");
   PermissionManager.addPermission("admin.debug");
   PermissionManager.addPermission("admin.reload");
   PermissionManager.addPermission("basic.modify.move");
   PermissionManager.addPermission("basic.create");
   PermissionManager.addPermission("basic.use.info");
   PermissionManager.addPermission("basic.modify.moveto");
   PermissionManager.addPermission("basic.modify.copy");
   PermissionManager.addPermission("basic.modify.remove");
   PermissionManager.addPermission("basic.modify.remove.all");
   PermissionManager.addPermission("basic.modify.rename");
   PermissionManager.addPermission("basic.modify.color");
   PermissionManager.addPermission("basic.modify.addtext");
   PermissionManager.addPermission("basic.modify.resettext");
   PermissionManager.addPermission("basic.modify.settext");
   PermissionManager.addPermission("basic.modify.equip");
   PermissionManager.addPermission("basic.use.teleport");
   PermissionManager.addPermission("basic.modify.talkclose");
   PermissionManager.addPermission("basic.modify.lookat");
   PermissionManager.addPermission("basic.use.select");
   PermissionManager.addPermission("basic.modify.setowner");
   PermissionManager.addPermission("waypoints.edit");
   PermissionManager.addPermission("basic.use.list");
   PermissionManager.addPermission("admin.override.setowner");
   PermissionManager.addPermission("admin.override.remove");
 }
Esempio n. 11
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;
   }
 }