コード例 #1
1
  public List<Spawner> loadAllSpawnersFromWorld(World w) {
    List<Spawner> list = new ArrayList<Spawner>();

    String ch = File.separator;
    String worldDir = w.getWorldFolder() + ch + "cs_data" + ch;
    String entityDir = worldDir + ch + "entity";
    String spawnerDir = worldDir + ch + "spawner";

    File spawnerFiles = new File(spawnerDir);
    File entityFiles = new File(entityDir);

    if (!spawnerFiles.exists()) spawnerFiles.mkdirs();

    if (!entityFiles.exists()) entityFiles.mkdirs();

    for (File spawnerFile : spawnerFiles.listFiles()) {

      Spawner s = PLUGIN.getFileManager().loadSpawner(spawnerFile);
      List<Integer> sEntsAsIDs = s.getTypeData();
      List<SpawnableEntity> sEnts = new ArrayList<SpawnableEntity>();
      ArrayList<SpawnableEntity> containedEntities = new ArrayList<SpawnableEntity>();

      for (Integer i : sEntsAsIDs) {
        sEnts.add(CustomSpawners.getEntity(i.toString()));
      }

      for (File f : entityFiles.listFiles()) {
        containedEntities.add(PLUGIN.getFileManager().loadEntity(f));
      }

      if (containedEntities.containsAll(sEnts)) list.add(s);
    }

    return list;
  }
コード例 #2
0
  // Load spawners and entities from world files
  public List<Spawner> loadData() {

    Iterator<World> worldItr = PLUGIN.getServer().getWorlds().iterator();
    List<Spawner> loaded = new ArrayList<Spawner>();

    while (worldItr.hasNext()) {
      World w = worldItr.next();

      Iterator<SpawnableEntity> entitiesFromWorld = loadAllEntitiesFromWorld(w).iterator();
      while (entitiesFromWorld.hasNext()) {
        SpawnableEntity e = entitiesFromWorld.next();
        int nextId = PLUGIN.getNextEntityId();
        if (CustomSpawners.entities.containsKey(e.getId())) {
          e = e.cloneWithNewId(nextId);
        }
        CustomSpawners.entities.put(nextId, e);
      }

      Iterator<Spawner> spawnersFromWorld = loadAllSpawnersFromWorld(w).iterator();
      while (spawnersFromWorld.hasNext()) {
        Spawner s = spawnersFromWorld.next();
        boolean sameSpawner = false;

        for (Spawner s1 : CustomSpawners.spawners.values()) {
          if (s1.getLoc().equals(s.getLoc())) {
            sameSpawner = true;
          }
        }

        if (sameSpawner) {
          continue;
        } else {
          int nextId = PLUGIN.getNextSpawnerId();
          Spawner s1 = PLUGIN.cloneWithNewId(s);
          CustomSpawners.spawners.put(nextId, s1);
          loaded.add(s1);
        }
      }
    }

    return loaded;
  }
コード例 #3
0
  @SuppressWarnings("deprecation")
  @Override
  public void run(Spawner spawner, CommandSender sender, String subCommand, String[] args) {

    if (!(sender instanceof Player)) {
      PLUGIN.sendMessage(sender, NO_CONSOLE);
      return;
    }

    Player player = (Player) sender;

    SpawnableEntity entity = null;

    String in = getValue(args, 0, "");

    if (in.isEmpty()) {
      Integer selection = CustomSpawners.entitySelection.get(player);
      if (selection == null) {
        PLUGIN.sendMessage(sender, NO_ID);
        return;
      }
      entity = CustomSpawners.getEntity(selection);
    } else {
      entity = CustomSpawners.getEntity(in);
    }

    if (entity == null) {
      PLUGIN.sendMessage(sender, NO_ID);
      return;
    }

    Block target =
        player.getTargetBlock(CustomSpawners.transparent, CONFIG.getInt("players.maxDistance", 5));

    if (target == null) {
      PLUGIN.sendMessage(
          player, ChatColor.RED + "You must look at a block to make a spawner there.");
      return;
    }

    if (target.getType().equals(Material.AIR)) {
      PLUGIN.sendMessage(
          player, ChatColor.RED + "You must look at a block to make a spawner there.");
      return;
    }

    Spawner newSpawner = PLUGIN.createSpawner(entity, target.getLocation());

    if (CONFIG.getBoolean("data.autosave") && CONFIG.getBoolean("data.saveOnCreate")) {
      PLUGIN.getFileManager().autosave(newSpawner);
    }

    // TODO Add this to wiki.
    Group addTo = null;
    if (sender instanceof Player) {
      Player p = (Player) sender;
      if (CustomSpawners.groupSelection.containsKey(p)) {
        addTo = CustomSpawners.getGroup(CustomSpawners.groupSelection.get(sender));
      }
    } else {
      if (CustomSpawners.consoleGroup != -1) {
        addTo = CustomSpawners.getGroup(CustomSpawners.consoleGroup);
      }
    }

    if (addTo != null
        && CONFIG.getBoolean("players.groupAutoAdd", false)
        && addTo.getType().equals(Group.Type.SPAWNER)) {
      addTo.addItem(newSpawner);
      PLUGIN.sendMessage(
          sender,
          ChatColor.GREEN
              + "Successfully created a new "
              + ChatColor.GOLD
              + in
              + ChatColor.GREEN
              + " spawner with ID number "
              + ChatColor.GOLD
              + newSpawner.getId()
              + ChatColor.GREEN
              + "! This spawner was added to group "
              + ChatColor.GOLD
              + PLUGIN.getFriendlyName(addTo)
              + ChatColor.GREEN
              + ".");
    }

    PLUGIN.sendMessage(
        player,
        ChatColor.GREEN
            + "Successfully created a "
            + ChatColor.GOLD
            + PLUGIN.getFriendlyName(entity)
            + ChatColor.GREEN
            + " spawner with ID "
            + ChatColor.GOLD
            + PLUGIN.getFriendlyName(newSpawner)
            + ChatColor.GREEN
            + "!");
  }