Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
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"));
  }