示例#1
0
  public static void addPresetPath(String npcName, PresetPath path, NPCHandler handle) {
    io.read();
    for (SyncWrapper wrap : io.getReadableData()) {
      io.add(wrap.getTag(), wrap.getObject());
    }
    io.add(npcName, path);
    io.write();
    presetNPCs.add(npcName);

    SimpleNPC rem = handle.getSimpleNPCByName(npcName);
    if (rem != null) {
      rem.destroyNPCObject();
    }

    LoadNPCTemplate tmp = new LoadNPCTemplate(npcName);

    tmp.loadProperties();

    SimpleNPC npc =
        tmp.getLoadedNPCTemplate().registerSimpleNPCFixedSpawn(handle, fixedSpawns.get(npcName));

    npc.setPresetPath(path);

    PresetPathsDisplay.updateSoftReference();
  }
示例#2
0
  public static boolean removeFixedNPCSpawn(Player p, String npcName, NPCHandler handle) {
    if (!FileLocator.doesNPCNameExist(npcName)) {
      if (p != null) {
        QuestX.logChat(p, ChatColor.RED + LocaleBundle.getString("no_npc_name"));
      }
      return false;
    } else {
      if (!fixedSpawns.containsKey(npcName)) {
        if (p != null) {
          QuestX.logChat(p, LocaleBundle.getString("no_fixed_spawn"));
        }
        return false;
      } else {
        SimpleNPC rem = handle.getSimpleNPCByName(npcName);
        if (rem != null) {
          rem.destroyNPCObject();
        }

        loader.read();
        loader.clearWriteArray();
        for (SyncWrapper wrap : loader.getReadableData()) {
          // copy all the data read, except the npc to remove
          if (!wrap.getTag().equalsIgnoreCase(npcName)) {
            loader.add(wrap);
          }
        }
        loader.write();
        loader.clearReadArray();
        loader.clearWriteArray();

        fixedSpawns.remove(npcName);

        io.read();
        io.clearWriteArray();
        io.clearReadArray();
        for (SyncWrapper wrap : loader.getReadableData()) {
          // copy all the data read, except the npc to remove
          if (!wrap.getTag().equalsIgnoreCase(npcName)) {
            io.add(wrap);
          }
        }
        io.write();

        if (p != null) {
          QuestX.logChat(
              p, LocaleBundle.getString("t_fs") + npcName + LocaleBundle.getString("was_rem"));
          if (presetNPCs.contains(npcName)) {
            QuestX.logChat(
                p, LocaleBundle.getString("t_pp") + npcName + LocaleBundle.getString("was_rem"));
            presetNPCs.remove(npcName);
          }
        }

        FixedSpawnsDisplay.updateSoftReference();
        PresetPathsDisplay.updateSoftReference();

        return true;
      }
    }
  }
示例#3
0
  public static final void deleteAllFixedSpawns(Player p, NPCHandler handle) {
    File spawn = FileLocator.getNPCFixedSpawnsFile(), pres = FileLocator.getNPCPresetPathingFile();
    if (spawn.canRead() && spawn.canWrite()) {
      if (spawn.exists()) {
        loader.read();
        for (SyncWrapper wrap : loader.getReadableData()) {
          SimpleNPC rem = handle.getSimpleNPCByName(wrap.getTag());
          if (rem != null) {
            rem.destroyNPCObject();
          }
        }
        spawn.delete();
        try {
          spawn.createNewFile();
          loader.add("NPC_COUNT", 0);
          loader.write();
          QuestX.logChat(p, LocaleBundle.getString("all_fxied_spawns_del"));
        } catch (IOException e) {
          QuestX.logChat(p, LocaleBundle.getString("error_del_fs_file"));
          e.printStackTrace();
        }
      } else {
        QuestX.logChat(p, LocaleBundle.getString("no_fs_file"));
      }
    } else {
      QuestX.logChat(p, LocaleBundle.getString("fs_file_locked"));
    }

    presetNPCs.clear();

    if (pres.canRead() && pres.canWrite()) {
      if (pres.exists()) {
        pres.delete();
        try {
          pres.createNewFile();
          io.clearWriteArray();
          io.add("NULL", 0);
          io.write();
          QuestX.logChat(p, LocaleBundle.getString("all_preset_del"));
        } catch (IOException e) {
          QuestX.logChat(p, LocaleBundle.getString("error_del_pp_file"));
          e.printStackTrace();
        }
      } else {
        QuestX.logChat(p, LocaleBundle.getString("no_pp_file"));
      }
    } else {
      QuestX.logChat(p, LocaleBundle.getString("pp_file_locked"));
    }

    FixedSpawnsDisplay.updateSoftReference();
    PresetPathsDisplay.updateSoftReference();
  }
示例#4
0
  public static boolean removePresetPath(Player p, String npcName, NPCHandler handle) {
    if (!FileLocator.doesNPCNameExist(npcName)) {
      if (p != null) {
        QuestX.logChat(p, ChatColor.RED + LocaleBundle.getString("no_npc_name"));
      }
      return false;
    } else {
      if (!fixedSpawns.containsKey(npcName)) {
        if (p != null) {
          QuestX.logChat(p, LocaleBundle.getString("no_fixed_spawn"));
        }
        return false;
      } else {
        if (!presetNPCs.contains(npcName)) {
          QuestX.logChat(p, LocaleBundle.getString("no_preset_path"));
          return false;
        } else {
          io.read();
          io.clearWriteArray();
          io.clearReadArray();
          for (SyncWrapper wrap : loader.getReadableData()) {
            // copy all the data read, except the npc to remove
            if (!wrap.getTag().equalsIgnoreCase(npcName)) {
              io.add(wrap);
            }
          }
          io.write();

          presetNPCs.remove(npcName);

          SimpleNPC rem = handle.getSimpleNPCByName(npcName);
          if (rem != null) {
            rem.destroyNPCObject();
          }

          LoadNPCTemplate tmp = new LoadNPCTemplate(npcName);

          tmp.loadProperties();

          SimpleNPC npc =
              tmp.getLoadedNPCTemplate()
                  .registerSimpleNPCFixedSpawn(handle, fixedSpawns.get(npcName));

          npc.setAllowedToMove(true);

          PresetPathsDisplay.updateSoftReference();
          QuestX.logChat(p, ChatColor.GREEN + "Preset path for NPC " + npcName + " was removed.");
          return true;
        }
      }
    }
  }
示例#5
0
  public static boolean addFixedNPCSpawn(Player p, String npcName, Location l, NPCHandler handle) {
    if (!FileLocator.doesNPCNameExist(npcName)) {
      if (p != null) {
        QuestX.logChat(p, ChatColor.RED + LocaleBundle.getString("no_npc_name"));
      }
      return false;
    } else {
      if (fixedSpawns.containsKey(npcName)) {
        if (p != null) {
          QuestX.logChat(p, LocaleBundle.getString("yes_fixed_spawn"));
        }
        return false;
      }
      SimpleNPC remove = handle.getSimpleNPCByName(npcName);
      if (remove != null) {
        remove.destroyNPCObject();
      }

      LoadNPCTemplate tmp = new LoadNPCTemplate(npcName);

      tmp.loadProperties();

      tmp.getLoadedNPCTemplate().registerSimpleNPCFixedSpawn(handle, l);

      loader.read();
      for (SyncWrapper wrap : loader.getReadableData()) {
        loader.add(wrap.getTag(), wrap.getObject());
      }
      loader.add(npcName, new SyncLocation(l));
      loader.write();
      loader.clearReadArray();
      loader.clearWriteArray();

      fixedSpawns.put(npcName, l);

      FixedSpawnsDisplay.updateSoftReference();

      if (p != null) {
        QuestX.logChat(p, LocaleBundle.getString("fixed_spawn_success") + npcName + "'.");
      }
      return true;
    }
  }
示例#6
0
  public static boolean editFixedNPCSpawn(Player p, String npcName, NPCHandler handle) {
    if (!FileLocator.doesNPCNameExist(npcName)) {
      if (p != null) {
        QuestX.logChat(p, ChatColor.RED + "There is no NPC created with this name!");
      }
      return false;
    } else {
      if (!fixedSpawns.containsKey(npcName)) {
        if (p != null) {
          QuestX.logChat(p, LocaleBundle.getString("no_fixed_spawn"));
        }
        return false;
      } else {

        SimpleNPC rem = handle.getSimpleNPCByName(npcName);
        if (rem != null) {
          rem.destroyNPCObject();
        }

        loader.read();
        io.read();
        loader.clearWriteArray();
        for (SyncWrapper wrap : loader.getReadableData()) {
          // copy all the data read, except the npc to remove, set
          // this to be edited
          if (!wrap.getTag().equalsIgnoreCase(npcName)) {
            loader.add(wrap);
          } else {
            if (p != null) {
              loader.add(wrap.getTag(), new SyncLocation(p.getLocation()));
            }
          }
        }

        loader.write();
        loader.clearReadArray();
        loader.clearWriteArray();

        io.read();
        io.clearWriteArray();
        io.clearReadArray();
        for (SyncWrapper wrap : loader.getReadableData()) {
          // copy all the data read, except the npc to remove
          if (!wrap.getTag().equalsIgnoreCase(npcName)) {
            io.add(wrap);
          }
        }
        io.write();

        if (presetNPCs.contains(npcName)) {
          QuestX.logChat(p, "The preset path for NPC '" + npcName + "' was removed.");
          presetNPCs.remove(npcName);
        }

        LoadNPCTemplate tmp = new LoadNPCTemplate(npcName);

        tmp.loadProperties();

        SimpleNPC npc =
            tmp.getLoadedNPCTemplate().registerSimpleNPCFixedSpawn(handle, p.getLocation());

        npc.setAllowedToMove(true);

        if (p != null) {
          QuestX.logChat(
              p, "The fixed spawn for NPC '" + npcName + "' was changed to your current location.");
        }

        PresetPathsDisplay.updateSoftReference();

        return true;
      }
    }
  }