Esempio n. 1
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. 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
 // Handle the right-clicking of a wizard
 public static void handleRightClick(Player player, HumanNPC npc, String op) {
   Wizard wizard = npc.getType("wizard");
   String econMsg = "";
   if (EconomyManager.useEconPlugin()) {
     if (EconomyManager.hasEnough(player, UtilityProperties.getPrice(op))) {
       double paid = EconomyManager.pay(player, UtilityProperties.getPrice(op));
       if (paid > 0) {
         econMsg = ChatColor.GREEN + "Paid " + StringUtils.wrap(EconomyManager.format(paid)) + ":";
       }
     } else {
       player.sendMessage(MessageUtils.getNoMoneyMessage(player, op));
       return;
     }
   }
   String msg = StringUtils.wrap(npc.getStrippedName());
   if (op.equals("wizard.teleport")) {
     msg += " teleported you to " + StringUtils.wrap(wizard.getCurrentLocationName()) + ".";
     if (!teleportPlayer(player, npc)) {
       return;
     }
   } else if (op.equals("wizard.spawnmob")) {
     msg +=
         " spawned a "
             + StringUtils.wrap(wizard.getMob().name().toLowerCase().replace("_", " "))
             + ".";
     if (!spawnMob(player, npc)) {
       return;
     }
   } else if (op.equals("wizard.changetime")) {
     msg += " changed the time to " + StringUtils.wrap(wizard.getTime()) + ".";
     if (!changeTime(player, npc)) {
       return;
     }
   } else if (op.equals("wizard.togglestorm")) {
     msg +=
         " toggled a thunderstorm in the world "
             + StringUtils.wrap(player.getWorld().getName())
             + ".";
     if (!toggleStorm(player, npc)) {
       return;
     }
   } else if (op.equals("wizard.executecommand")) {
     msg += " executed the command " + StringUtils.wrap("/" + wizard.getCommand()) + ".";
     if (!executeCommand(player, npc)) {
       return;
     }
     if (!player.performCommand(wizard.getCommand())) {
       return;
     }
   }
   if (EconomyManager.useEconPlugin()) {
     player.sendMessage(econMsg);
   }
   player.sendMessage(msg);
 }
 @Command(
     aliases = "blacksmith",
     usage = "status",
     desc = "view the status of your in-hand item",
     modifiers = "status",
     min = 1,
     max = 1)
 @CommandPermissions("blacksmith.use.status")
 public static void cost(CommandContext args, Player player, HumanNPC npc) {
   ItemStack item = player.getItemInHand();
   String repairType = "";
   if (InventoryUtils.isArmor(item)) {
     repairType = "armorrepair";
   } else if (InventoryUtils.isTool(item)) {
     repairType = "toolrepair";
   }
   if (repairType.isEmpty()) {
     Messaging.sendError(
         player, MessageUtils.getMaterialName(item.getTypeId()) + " is not a repairable item.");
     return;
   }
   if (EconomyManager.useEconPlugin()) {
     double price = BlacksmithManager.getBlacksmithPrice(player, repairType);
     player.sendMessage(
         ChatColor.GREEN
             + "Item: "
             + StringUtils.wrap(MessageUtils.getMaterialName(item.getTypeId())));
     player.sendMessage(
         ChatColor.GREEN + "Cost: " + StringUtils.wrap(EconomyManager.format(price)));
     player.sendMessage(
         ChatColor.GREEN
             + "Durability Remaining: "
             + StringUtils.wrap(
                 Material.getMaterial(item.getTypeId()).getMaxDurability()
                     - item.getDurability()));
   } else {
     Messaging.sendError(player, "This server is not using an economy system.");
   }
 }
Esempio n. 5
0
 @CommandRequirements()
 @Command(
     aliases = "npc",
     usage = "list (name) (page)",
     desc = "view a list of NPCs for a player",
     modifiers = "list",
     min = 1,
     max = 3)
 @CommandPermissions("basic.use.list")
 public static void list(CommandContext args, Player player, HumanNPC npc) {
   switch (args.argsLength()) {
     case 1:
       MessageUtils.displayNPCList(player, player, npc, "1");
       break;
     case 2:
       if (StringUtils.isNumber(args.getString(1))) {
         MessageUtils.displayNPCList(player, player, npc, args.getString(1));
       } else {
         if (ServerUtils.matchPlayer(args.getString(1)) != null) {
           MessageUtils.displayNPCList(
               player, ServerUtils.matchPlayer(args.getString(1)), npc, "1");
         } else {
           player.sendMessage(ChatColor.RED + "Could not match player.");
         }
       }
       break;
     case 3:
       if (ServerUtils.matchPlayer(args.getString(1)) != null) {
         MessageUtils.displayNPCList(
             player, ServerUtils.matchPlayer(args.getString(1)), npc, args.getString(2));
       } else {
         player.sendMessage(ChatColor.RED + "Could not match player.");
       }
       break;
   }
 }