示例#1
0
  /** @param event */
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerJoin(final PlayerJoinEvent event) {
    final Player player = event.getPlayer();
    final UUID playerUUID = player.getUniqueId();
    // Check language permission
    if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.lang")) {
      // Get language
      String language = getLanguage(player);
      // plugin.getLogger().info("DEBUG: language = " + language);
      // Check if we have this language
      if (plugin.getResource("locale/" + language + ".yml") != null) {
        if (plugin.getPlayers().getLocale(playerUUID).isEmpty()) {
          plugin.getPlayers().setLocale(playerUUID, language);
        }
      }
    } else {
      // Default locale
      plugin.getPlayers().setLocale(playerUUID, "");
    }
    if (players == null) {
      plugin.getLogger().severe("players is NULL");
    }
    // Load any messages for the player
    // plugin.getLogger().info("DEBUG: Checking messages for " +
    // player.getName());
    final List<String> messages = plugin.getMessages().getMessages(playerUUID);
    if (messages != null) {
      // plugin.getLogger().info("DEBUG: Messages waiting!");
      plugin
          .getServer()
          .getScheduler()
          .runTaskLater(
              plugin,
              new Runnable() {
                @Override
                public void run() {
                  player.sendMessage(ChatColor.AQUA + plugin.myLocale(playerUUID).newsHeadline);
                  int i = 1;
                  for (String message : messages) {
                    player.sendMessage(i++ + ": " + message);
                  }
                  // Clear the messages
                  plugin.getMessages().clearMessages(playerUUID);
                }
              },
              40L);
    } // else {
    // plugin.getLogger().info("no messages");
    // }

    // Set the player's name (it may have changed), but only if it isn't empty
    if (!player.getName().isEmpty()) {
      players.setPlayerName(playerUUID, player.getName());
      // Add to tinyDB
      plugin.getTinyDB().savePlayerName(player.getName(), playerUUID);
    } else {
      plugin
          .getLogger()
          .warning("Player that just logged in has no name! " + playerUUID.toString());
    }
    players.save(playerUUID);
    if (Settings.logInRemoveMobs) {
      plugin.getGrid().removeMobs(player.getLocation());
    }
  }
示例#2
0
 @EventHandler(priority = EventPriority.NORMAL)
 public void onPlayerQuit(final PlayerQuitEvent event) {
   players.removeOnlinePlayer(event.getPlayer().getUniqueId());
 }