Ejemplo n.º 1
0
 @EventHandler(priority = EventPriority.LOWEST)
 public void onPlayerQuit(PlayerQuitEvent e) {
   Managers.log("[Player] Saving details for player " + e.getPlayer().getName());
   Managers.getStatisticManager()
       .saveStatistic(getPlayerDetails(e.getPlayer()), PlayerDetails.class);
   players.remove(e.getPlayer());
 }
Ejemplo n.º 2
0
 public void saveAll() {
   synchronized (players) {
     for (PlayerDetails d : players.values()) {
       Managers.getStatisticManager().saveStatistic(d, PlayerDetails.class);
     }
   }
 }
Ejemplo n.º 3
0
 private void playerAcct(Player p) {
   if (!players.containsKey(p.getName())) {
     List<PlayerDetails> d =
         Managers.getStatisticManager().getAllStatistics(p.getName(), PlayerDetails.class);
     PlayerDetails obj;
     if (d.size() != 0) {
       obj = d.get(0);
       obj.resetupPlayerDetails();
       players.put(p.getName(), obj);
       return;
     }
     obj = new PlayerDetails();
     obj.setupPlayerDetails(p);
     Managers.getStatisticManager().saveStatistic(obj, PlayerDetails.class);
     players.put(p.getName(), obj);
     PlayerRegisterEvent e = new PlayerRegisterEvent(p);
     Bukkit.getPluginManager().callEvent(e);
   }
 }
 public void call(Player p, String[] args) {
   List<NPCStatistic> npcs =
       Managers.getStatisticManager().getAllStatistics(p.getName(), NPCStatistic.class);
   for (NPCStatistic n : npcs) {
     NPC npc = CitizensAPI.getNPCRegistry().getById(n.getNpcid());
     if (npc == null) continue;
     if (MQAddonCitizens.descriptionManager.activeNPCs.contains(npc.getId())) {
       Frontend.openFrontend(p, npc);
       return;
     }
   }
   p.sendMessage("No such contact!");
 }
 @Override
 public void noOptionSpecified(CommandSender p, String[] args) {
   List<String> tosend = new ArrayList<String>();
   tosend.add(ChatUtils.formatHeader("Active Contacts"));
   List<NPCStatistic> npcs =
       Managers.getStatisticManager().getAllStatistics(p.getName(), NPCStatistic.class);
   for (NPCStatistic n : npcs) {
     NPC npc = CitizensAPI.getNPCRegistry().getById(n.getNpcid());
     if (npc == null) continue;
     tosend.add(
         formatNPC(npc.getName(), npc.getBukkitEntity().getLocation().getWorld().getName()));
   }
   tosend.add(ChatUtils.formatHeader("To call a contact, use /contacts call <name>"));
   for (String s : tosend) {
     p.sendMessage(s);
   }
 }
 public static void registerRequirements() {
   RequirementManager r = Managers.getRequirementManager();
   r.register("GroupSizeRequirement", GroupSizeRequirement.class);
   r.register("HasItemRequirement", HasItemRequirement.class);
   r.register("ItemInHandRequirement", ItemInHandRequirement.class);
   r.register("LevelRequirement", LevelRequirement.class);
   r.register("MoneyRequirement", MoneyRequirement.class);
   r.register("NotRepeatableRequirement", NotRepeatableRequirement.class);
   r.register("PermissionRequirement", PermissionRequirement.class);
   r.register("PlayerRequirement", PlayerRequirement.class);
   r.register("QuestCompletedRequirement", QuestCompletedRequirement.class);
   r.register("QuestFailedRequirement", QuestFailedRequirement.class);
   r.register("RealDateRequirement", RealDateRequirement.class);
   r.register("TimeRequirement", TimeRequirement.class);
   r.register("WeatherRequirement", WeatherRequirement.class);
   r.register("WorldRequirement", WorldRequirement.class);
 }
Ejemplo n.º 7
0
 /**
  * Get a list of quests this player can obtain.<br>
  * This follows the content system, in which:<br>
  *
  * <ul>
  *   <li>If the List size is 0, then there are no available quests.
  *   <li>If the List size is greater than 0, then there are quests.
  *   <li>If the List <b>object</b> is <code>null</code>, then there is an active quest given.
  * </ul>
  *
  * @param player Player to lookup
  * @param desc NPC to lookup
  * @return List of quests, or <code>null</code>.
  */
 public static List<String> getAvailableQuests(Player player, NPCDescription desc) {
   List<String> quests = desc.getQuests();
   List<String> availablequests = new ArrayList<String>();
   for (String q : quests) {
     LogStatus l = QuestStatisticUtils.hasQuest(player.getName(), q);
     if (l == LogStatus.GIVEN || l == LogStatus.ACTIVE) {
       availablequests = null;
       break;
     } else if (l == LogStatus.UNKNOWN) {
       availablequests.add(q);
     } else {
       QuestDetails details = Managers.getQuestManager().getDetails(q);
       if (details != null) {
         if (QuestDetailsUtils.getRequirementsMet(details, player)) availablequests.add(q);
       }
     }
   }
   return availablequests;
 }
Ejemplo n.º 8
0
  public PlayerManager() {
    Managers.log("[Player] Starting Manager...");
    players = Collections.synchronizedMap(new LinkedHashMap<String, PlayerDetails>());
    shutdown = false;

    Managers.getStatisticManager().registerStatistic(PlayerDetails.class);

    Bukkit.getScheduler()
        .scheduleSyncRepeatingTask(
            Managers.getActivePlugin(),
            new Runnable() {

              @Override
              public void run() {
                saveAll();
              }
            },
            1200,
            18000);

    Runnable r =
        new Runnable() {

          @Override
          public void run() {
            Random r = new Random();
            while (!shutdown) {
              for (PlayerDetails d : players.values()) {
                if (d.giveMana)
                  d.modifyPowerBy((int) Math.round(1 * d.getLevel() * (Math.random() + 1)));
              }
              try {
                Thread.sleep(r.nextInt(10000) + 5000);
              } catch (InterruptedException e) {
                throw new RuntimeException(e);
              }
            }
          }
        };

    Thread t = new Thread(r);
    t.setDaemon(true);
    t.setName("MineQuest-PlayerMana");
    t.start();

    Runnable run =
        new Runnable() {

          @Override
          public void run() {
            while (!shutdown) {
              synchronized (players) {
                for (PlayerDetails d : players.values()) {
                  try {
                    d.updateMinecraftView();
                  } catch (NullPointerException e) {
                    Managers.log(
                        Level.WARNING,
                        "[Player] Thread NPE! Can't keep up! Did the system time change, is the server overloaded, or has the player changed worlds?");
                  }
                }
              }
              try {
                Thread.sleep(50);
              } catch (InterruptedException e) {
                throw new RuntimeException(e);
              }
            }
          }
        };

    Thread th = new Thread(run);
    th.setDaemon(true);
    th.setName("MineQuest-PlayerUpdateView");
    th.start();
  }
Ejemplo n.º 9
0
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onPlayerJoin(PlayerJoinEvent e) {
   Managers.log("[Player] Retrieving details for player " + e.getPlayer().getName());
   playerAcct(e.getPlayer());
 }