Пример #1
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")));
   }
 }
Пример #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);
   }
 }
Пример #3
0
 // Registers a new NPC.
 public static int register(String name, Location loc, String owner, NPCCreateReason reason) {
   int UID = PropertyManager.getBasic().getNewNpcID();
   PropertyManager.getBasic().saveLocation(loc, UID);
   PropertyManager.getBasic().saveLookWhenClose(UID, Settings.getBoolean("DefaultLookAt"));
   PropertyManager.getBasic().saveTalkWhenClose(UID, Settings.getBoolean("DefaultTalkClose"));
   PropertyManager.getBasic().saveName(UID, name);
   register(UID, owner, reason);
   return UID;
 }
Пример #4
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"));
  }
Пример #5
0
 @Override
 public void onSpawn() {
   npc.getInventory()
       .setItemInHand(new ItemStack(weapons[this.random.nextInt(weapons.length)], 1));
   this.health = Settings.getInt("EvilHealth");
   super.onSpawn();
 }
Пример #6
0
  @CommandRequirements()
  @Command(
      aliases = "citizens",
      usage = "reload",
      desc = "reload Citizens",
      modifiers = "reload",
      min = 1,
      max = 1)
  @CommandPermissions("admin.reload")
  @ServerCommand()
  public static void reload(CommandContext args, CommandSender sender, HumanNPC npc) {
    Messaging.log("Reloading configuration settings....");
    if (sender instanceof Player) {
      sender.sendMessage(ChatColor.GREEN + "[" + StringUtils.wrap("Citizens") + "] Reloading....");
    }

    PropertyManager.loadAll();
    Settings.setupVariables();

    Bukkit.getServer().getPluginManager().callEvent(new CitizensReloadEvent());

    Messaging.log("Reloaded.");
    if (sender instanceof Player) {
      sender.sendMessage(ChatColor.GREEN + "[" + StringUtils.wrap("Citizens") + "] Reloaded.");
    }
  }
Пример #7
0
 @CommandRequirements()
 @Command(
     aliases = "citizens",
     usage = "debug",
     desc = "toggle debug mode for Citizens",
     modifiers = "debug",
     min = 1,
     max = 1)
 @ServerCommand()
 @CommandPermissions("admin.debug")
 public static void debug(CommandContext args, CommandSender sender, HumanNPC npc) {
   boolean debug = Settings.getBoolean("DebugMode");
   UtilityProperties.getConfig().setRaw("general.debug-mode", !debug);
   debug = !debug;
   if (debug) {
     Messaging.log("Debug mode is now on.");
     if (sender instanceof Player) {
       Messaging.send(sender, npc, "Debug mode is now " + ChatColor.GREEN + "on");
     }
   } else {
     Messaging.log("Debug mode is now off.");
     if (sender instanceof Player) {
       Messaging.send(sender, npc, "Debug mode is now " + ChatColor.RED + "off");
     }
   }
 }
Пример #8
0
  public void reload() throws NPCLoadException {
    Editor.leaveAll();
    config.reload();
    despawnNPCs();
    saves.loadInto(npcRegistry);

    getServer().getPluginManager().callEvent(new CitizensReloadEvent());
  }
Пример #9
0
  // Spawns a new NPC and registers it.
  public static void register(int UID, String owner, NPCCreateReason reason) {
    Location loc = PropertyManager.getBasic().getLocation(UID);

    ChatColor colour = PropertyManager.getBasic().getColour(UID);
    String name = PropertyManager.getBasic().getName(UID);
    name = ChatColor.stripColor(name);
    if (!Settings.getString("SpaceChar").isEmpty()) {
      name = name.replace(Settings.getString("SpaceChar"), " ");
    }
    String npcName = name;
    if (colour != null && colour != ChatColor.WHITE) {
      npcName = colour + name;
    }
    HumanNPC npc = NPCSpawner.spawnNPC(UID, npcName, loc);

    NPCCreateEvent event = new NPCCreateEvent(npc, reason, loc);
    Bukkit.getServer().getPluginManager().callEvent(event);

    npc.setNPCData(
        new NPCData(
            npcName,
            UID,
            loc,
            colour,
            PropertyManager.getBasic().getItems(UID),
            NPCDataManager.NPCTexts.get(UID),
            PropertyManager.getBasic().isTalk(UID),
            PropertyManager.getBasic().isLookWhenClose(UID),
            PropertyManager.getBasic().isTalkWhenClose(UID),
            owner));
    PropertyManager.getBasic().saveOwner(UID, owner);
    PropertyManager.load(npc);

    registerUID(UID, npcName);
    list.put(UID, npc);
    PropertyManager.save(npc);

    npc.getPlayer().setSleepingIgnored(true); // Fix beds.
  }
Пример #10
0
 // Rotates an NPC.
 public static void faceEntity(HumanNPC npc, Entity entity) {
   if (npc.getWorld() != entity.getWorld()) return;
   if (Settings.getBoolean("RealisticPathing")
       && !npc.getHandle().isInSight(((CraftEntity) entity).getHandle())) return;
   Location loc = npc.getLocation(), pl = entity.getLocation();
   double xDiff = pl.getX() - loc.getX();
   double yDiff = pl.getY() - loc.getY();
   double zDiff = pl.getZ() - loc.getZ();
   double DistanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
   double DistanceY = Math.sqrt(DistanceXZ * DistanceXZ + yDiff * yDiff);
   double yaw = (Math.acos(xDiff / DistanceXZ) * 180 / Math.PI);
   double pitch = (Math.acos(yDiff / DistanceY) * 180 / Math.PI) - 90;
   if (zDiff < 0.0) {
     yaw = yaw + (Math.abs(180 - yaw) * 2);
   }
   npc.getHandle().yaw = (float) yaw - 90;
   npc.getHandle().az = npc.getHandle().yaw;
   npc.getHandle().pitch = (float) pitch;
 }
Пример #11
0
 @Command(
     aliases = "npc",
     usage = "select [id]",
     desc = "select an NPC by its ID",
     modifiers = "select",
     min = 2,
     max = 2)
 @CommandPermissions("basic.use.select")
 @CommandRequirements()
 public static void select(CommandContext args, Player player, HumanNPC npc) {
   npc = NPCManager.get(args.getInteger(1));
   if (npc == null) {
     player.sendMessage(
         ChatColor.RED
             + "No NPC with ID "
             + StringUtils.wrap(args.getString(1), ChatColor.RED)
             + " exists.");
   } else {
     NPCDataManager.selectNPC(player, npc);
     Messaging.send(player, npc, Settings.getString("SelectionMessage"));
   }
 }
Пример #12
0
 @Override
 public void onDeath() {
   ItemStack item = UtilityProperties.getRandomDrop(Settings.getString("EvilDrops"));
   if (item == null) return;
   this.getEntity().getWorld().dropItemNaturally(this.getLocation(), item);
 }