@EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerChat(AsyncPlayerChatEvent event) {
    try {
      final Player p = event.getPlayer();
      String message = event.getMessage().trim();

      TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(p);
      playerdata.incrementMsgCount();

      // Check for spam
      if (playerdata.getMsgCount() > 10) {
        TFM_Util.bcastMsg(
            p.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
        TFM_Util.autoEject(p, "Kicked for spamming chat.");

        playerdata.resetMsgCount();

        event.setCancelled(true);
        return;
      }

      // Check for message repeat
      if (playerdata.getLastMessage().equalsIgnoreCase(message)) {
        TFM_Util.playerMsg(p, "Please do not repeat messages.");
        event.setCancelled(true);
        return;
      }
      playerdata.setLastMessage(message);

      // Check for muted
      if (playerdata.isMuted()) {
        if (!TFM_SuperadminList.isUserSuperadmin(p)) {
          p.sendMessage(ChatColor.RED + "You are muted, STFU!");
          event.setCancelled(true);
          return;
        } else {
          playerdata.setMuted(false);
        }
      }

      // Strip color from messages
      message = ChatColor.stripColor(message);

      // Truncate messages that are too long - 100 characters is vanilla client max
      if (message.length() > 100) {
        message = message.substring(0, 100);
        TFM_Util.playerMsg(p, "Message was shortened because it was too long to send.");
      }

      // Check for caps
      if (message.length() >= 6) {
        int caps = 0;
        for (char c : message.toCharArray()) {
          if (Character.isUpperCase(c)) {
            caps++;
          }
        }
        if (((float) caps / (float) message.length())
            > 0.65) // Compute a ratio so that longer sentences can have more caps.
        {
          message = message.toLowerCase();
        }
      }

      // Check for adminchat
      if (playerdata.inAdminChat()) {
        TFM_Util.adminChatMessage(p, message, false);
        event.setCancelled(true);
        return;
      }

      // Finally, set message
      event.setMessage(message);

      // Set the tag
      if (playerdata.getTag() != null) {
        p.setDisplayName((playerdata.getTag() + " " + p.getDisplayName().replaceAll(" ", "")));
      }

    } catch (Exception ex) {
      TFM_Log.severe(ex);
    }
  }
 public boolean execute(CommandSender sender, String[] args) {
   Player player = (Player) sender;
   String name = player.getName();
   FileConfiguration pconfig =
       plugin.getPlayerManager().getPlayer(name).getPlayerConfig().getConfig();
   if (args.length == 0) {
     if (player.hasPermission("kessentials.nick")) {
       player.sendMessage(GREEN + "Your name is now " + name);
       player.setDisplayName(name);
       pconfig.set("nickname", name);
       nickname.setNickName(name, name);
     } else {
       noPermissionsMessage(player);
     }
   } else if (args.length == 1) {
     if (player.hasPermission("kessentials.nick")) {
       player.sendMessage(GREEN + "Your name is now " + args[0]);
       player.setDisplayName(name);
       pconfig.set("nickname", args[0]);
       nickname.setNickName(name, args[0]);
     } else {
       noPermissionsMessage(player);
     }
   } else {
     incorrectUsage(player, "/nick [name]");
   }
   return false;
 }
  @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
  public void onPlayerLogin(PlayerLoginEvent event) {
    Player player = event.getPlayer();

    Bending.getInstance().getBendingDatabase().lease(player.getUniqueId());

    BendingPlayer bender = BendingPlayer.getBendingPlayer(player);

    if (!(Settings.CHAT_COMPATIBILITY) && (Settings.CHAT_ENABLED)) {
      player.setDisplayName(player.getName());
    }

    if ((Settings.CHAT_COMPATIBILITY) && (Settings.CHAT_ENABLED)) {
      ChatColor color = ChatColor.WHITE;
      if (Settings.CHAT_COLORED) {
        if (player.hasPermission("bending.avatar")) {
          color = PluginTools.getColor(Settings.getColor(BendingElement.ENERGY));
        } else {
          List<BendingElement> els = bender.getBendingTypes();
          if ((els != null) && !els.isEmpty()) {
            color = PluginTools.getColor(Settings.getColor(els.get(0)));
          }
        }
      }
      player.setDisplayName("<" + color + player.getName() + ChatColor.WHITE + ">");
    }
  }
 @Override
 public boolean updatePlayer(Player player, PlayerProfile profile) {
   Map<String, Object> data = profile.get(CUSTOM_MAP);
   if (data == null) {
     // Specify default value
     player.setMaximumNoDamageTicks(0);
     player.setDisplayName("poop");
     return false;
   }
   player.setMaximumNoDamageTicks((Integer) data.get("maxNoDamageTick"));
   player.setDisplayName(data.get("displayName").toString());
   return true;
 }
Exemple #5
0
 private static void setKitDisplayName(Player player, String kitname) {
   if (plugin.winner(player))
     player.setDisplayName(
         "§8[" + kitname + "] §r" + ChatColor.GOLD + player.getName() + ChatColor.WHITE);
   else if (player.hasPermission("bg.admin.color") || player.hasPermission("bg.admin.*"))
     player.setDisplayName(
         "§8[" + kitname + "] §r" + ChatColor.RED + player.getName() + ChatColor.WHITE);
   else if (player.hasPermission("bg.vip.color") || player.hasPermission("bg.vip.*"))
     player.setDisplayName(
         "§8[" + kitname + "] §r" + ChatColor.BLUE + player.getName() + ChatColor.WHITE);
   else
     player.setDisplayName(
         "§8[" + kitname + "] §r" + ChatColor.WHITE + player.getName() + ChatColor.WHITE);
 }
 private void uncolorPlayer(Player player) {
   Team team = scoreboard.getTeam(player.getName());
   if (team != null) {
     team.unregister();
   }
   player.setDisplayName(player.getName());
 }
  @Override
  public void tpPlayerToCoordName(Arena arena, Player player, String place) {
    if (arena.cfg.getBoolean("messages.colorNick", true)) {
      if (spoutHandler != null) {
        colorizePlayer(arena, player);
      } else {
        ArenaTeam team = Teams.getTeam(arena, ArenaPlayer.parsePlayer(player));
        String n;
        if (team == null) {
          db.i("> team is null");
          n = player.getName();
        } else {
          n = team.getColorString() + player.getName();
        }
        n = n.replaceAll("(&([a-f0-9]))", "§$2");

        player.setDisplayName(n);

        if (team != null && arena.cfg.getBoolean("game.hideName")) {
          n = " ";
        }

        updateName(player, n);
      }
    }
  }
Exemple #8
0
  @EventHandler(priority = EventPriority.LOW)
  public void onJoin(PlayerJoinEvent event) {
    final Player player = event.getPlayer();
    String prefix =
        ChatColor.translateAlternateColorCodes(
            '&',
            Core.chat.getGroupPrefix(Bukkit.getWorlds().get(0), Core.chat.getPrimaryGroup(player)));
    player.setDisplayName(prefix + player.getName());
    if (!player.hasPermission(
        ConfigUtil.get().getConfig().getString("joinleavemessage.permission"))) {
      event.setJoinMessage(null);
    } else {
      event.setJoinMessage(
          ChatColor.translateAlternateColorCodes(
              '&',
              ConfigUtil.get()
                  .getConfig()
                  .getString("joinleavemessage.join-message")
                  .replaceAll("%player%", player.getDisplayName())));
    }

    if (ConfigUtil.get().getConfig().getBoolean("tp-to-spawn")) {
      Location teleportTo =
          LocationUtil.get().deserialize(ConfigUtil.get().getConfig().getString("spawn.location"));
      event.getPlayer().teleport(teleportTo);
    }

    EconomyUtil.get().createRowForPlayer(player);
  }
Exemple #9
0
  /**
   * Increments karma by two and checks if the Player is now an outlaw
   *
   * @return true if the Player is now an Outlaw
   */
  public boolean incrementKarma(Player player) {
    // Karma does not change if the Player is offline (they logged during battle)
    if (!player.isOnline()) return false;

    karma = karma + 2;

    // Return false if the Player's Outlaw status did not change
    if (karma != outlawLevel + 1 && karma != outlawLevel + 2) return false;

    // Add the Player to the Outlaw group if there is one
    if (!outlawGroup.isEmpty()) {
      if (removeGroup) {
        // Remove the Player from their primary group
        group = PvPReward.permission.getPrimaryGroup(player);
        PvPReward.permission.playerRemoveGroup(player, group);
      }

      // Add the Player to the Outlaw group
      PvPReward.permission.playerAddGroup(player, outlawGroup);
    }

    // Set the Outlaw tag if there is one
    if (!outlawTag.isEmpty()) player.setDisplayName(outlawTag + name);

    return true;
  }
Exemple #10
0
  /**
   * Decrements karma by one and checks if the Player is no longer an outlaw
   *
   * @return true if the Player is no longer an Outlaw
   */
  public boolean decrementKarma(Player player) {
    // Karma does not change if the Player is offline (they logged during battle)
    if (!player.isOnline()) return false;

    karma--;

    // Do not let karma be negative
    if (karma < 0) karma = 0;

    // Return false if the Player's Outlaw status did not change
    if (karma != outlawLevel) return false;

    // Move the Player to their previous group if they are in the Outlaw group
    if (PvPReward.permission.playerInGroup(player, outlawGroup)) {
      PvPReward.permission.playerRemoveGroup(player, outlawGroup);

      if (group != null && removeGroup) {
        PvPReward.permission.playerAddGroup(player, group);
        group = null;
      }
    }

    // Remove the Outlaw tag if being used
    if (!outlawTag.isEmpty()) player.setDisplayName(name);

    return true;
  }
Exemple #11
0
 @Override
 public void onPlayerJoin(PlayerJoinEvent event) {
   Player player = event.getPlayer();
   Hero hero = plugin.getHeroManager().getHero(player);
   hero.syncExperience();
   hero.syncHealth();
   hero.checkInventory();
   if (plugin.getConfigManager().getProperties().prefixClassName) {
     player.setDisplayName("[" + hero.getHeroClass().getName() + "]" + player.getName());
   }
 }
Exemple #12
0
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerChat(PlayerChatEvent event) {
    if (event.isCancelled()) return;

    Player me = event.getPlayer();
    VPlayer vme = VPlayers.i.get(me);

    if (Conf.nameColorize == false) return;
    if (!vme.isVampire()) return;

    me.setDisplayName("" + Conf.nameColor + ChatColor.stripColor(me.getDisplayName()));
  }
 @EventHandler
 public void displayNames(PlayerLoginEvent e) {
   if (e.getResult() != Result.ALLOWED) return;
   Player p = e.getPlayer();
   if (p == null) return;
   String dispname = PConfManager.getPValString(p, "dispname");
   if (dispname == null || dispname.equals("")) dispname = p.getName().trim();
   dispname = dispname.trim();
   if (dispname == null) return;
   p.setDisplayName(dispname);
   if (dispname.length() <= 16) p.setPlayerListName(dispname);
 }
  protected void updateDisplayName(Player player) {
    PermissionUser user = PermissionsEx.getPermissionManager().getUser(player);
    if (user == null) {
      return;
    }

    String worldName = player.getWorld().getName();
    player.setDisplayName(
        this.translateColorCodes(
            this.replacePlayerPlaceholders(
                player,
                user.getOption(this.optionDisplayname, worldName, this.displayNameFormat))));
  }
Exemple #15
0
  /**
   * Sets the correct display name of a player, according to his team.
   *
   * @param player
   */
  public void colorizePlayer(OfflinePlayer offlinePlayer) {
    if (!p.getConfig().getBoolean("colorizeChat")) {
      return;
    }

    if (!offlinePlayer.isOnline()) {
      return;
    }

    Player player = (Player) offlinePlayer;

    UHTeam team = getTeamForPlayer(player);

    if (team == null) {
      player.setDisplayName(player.getName());
    } else {
      if (team.getColor() != null) {
        player.setDisplayName(team.getColor().toChatColor() + player.getName() + ChatColor.RESET);
      } else {
        player.setDisplayName(player.getName());
      }
    }
  }
  private void colorPlayer(Player player, ChatColor color) {
    uncolorPlayer(player);

    playerColors.put(player.getUniqueId(), color);

    player.setDisplayName(color + player.getName() + ChatColor.RESET);

    Team team = scoreboard.registerNewTeam(player.getName());
    team.setDisplayName(player.getName());
    team.setPrefix(color.toString());
    team.setSuffix(ChatColor.RESET.toString());
    team.addEntry(player.getName());
    player.setScoreboard(scoreboard);
  }
  @EventHandler
  public void onPlayerChatEvent(AsyncPlayerChatEvent e) {

    Player p = e.getPlayer();
    String msg = e.getMessage();
    double h = p.getHealth();
    p.setDisplayName(
        ChatColor.YELLOW
            + "["
            + ChatColor.RED
            + h
            + "/20.0"
            + ChatColor.YELLOW
            + "]"
            + ChatColor.WHITE
            + p.getName());
  }
 @EventHandler
 public void onJoin(PlayerJoinEvent e) {
   Player p = e.getPlayer();
   String name = p.getName();
   if (name.length() > 14) {
     name = name.substring(0, 14);
   }
   p.setPlayerListName(ChatColor.GREEN + name);
   p.setDisplayName("§a" + p.getName());
   e.setJoinMessage(null);
   if (plugin.getConfig().getBoolean("Complete")) {
     if (plugin.spieler == null) {
       SpeedBuilder.gm.Start(p);
     } else {
       SpeedBuilder.pm.SpectatorJoin(p);
     }
   }
 }
  private void setprefix(Player player, String prefix) {
    File file =
        fileManager.loadFile(
            plugin.getDataFolder().toString() + "\\players",
            player.getUniqueId().toString() + ".json");
    String json = null;
    try {
      json = jsonManager.getJson(file);
    } catch (IOException e) {
      e.printStackTrace();
    }
    JsonObject playerdata = jsonManager.createJsonObject(json);

    playerdata.getAsJsonObject("Player").addProperty("prefix", prefix);

    String json1 = jsonManager.toJson(playerdata);

    player.setDisplayName(coloring(prefix + player.getName()));
    jsonManager.writeJson(file, json1);
  }
  private void colorizePlayer(Arena a, Player player) {
    db.i("colorizing player " + player.getName() + ";");

    Arena arena = Arenas.getArenaByPlayer(player);
    if (arena == null) {
      db.i("> arena is null");
      if (spoutHandler != null) {
        SpoutManager.getPlayer(player).setTitle(player.getName());
      } else if (!a.cfg.getBoolean("colors.requireSpout")) {
        disguise(player, player.getName());
      }
      return;
    }

    ArenaTeam team = Teams.getTeam(arena, ArenaPlayer.parsePlayer(player));
    String n;
    if (team == null) {
      db.i("> team is null");
      if (spoutHandler != null) {
        SpoutManager.getPlayer(player).setTitle(player.getName());
      } else if (!a.cfg.getBoolean("colors.requireSpout")) {
        disguise(player, player.getName());
      }
      return;
    } else {
      n = team.getColorString() + player.getName();
    }
    n = n.replaceAll("(&([a-f0-9]))", "§$2");

    player.setDisplayName(n);

    if (arena.cfg.getBoolean("game.hideName")) {
      n = " ";
    }
    if (spoutHandler != null) {
      SpoutManager.getPlayer(player).setTitle(n);
    } else if (!a.cfg.getBoolean("colors.requireSpout")) {
      disguise(player, n);
    }
  }
Exemple #21
0
  @EventHandler
  public void onPlayerChat(AsyncPlayerChatEvent event) {
    Player player = event.getPlayer();

    String prefix =
        ChatColor.translateAlternateColorCodes(
            '&',
            Core.chat.getGroupPrefix(Bukkit.getWorlds().get(0), Core.chat.getPrimaryGroup(player)));
    player.setDisplayName(prefix + player.getName());
    event.setFormat(
        ChatColor.translateAlternateColorCodes(
                '&', ConfigUtil.get().getConfig().getString("chat-format"))
            .replaceAll("%DISPLAYNAME%", "%s")
            .replaceAll("%MESSAGE%", "%s"));

    if (!player.hasPermission(ConfigUtil.get().getConfig().getString("chat-delay.permission"))) {
      if (!delay.containsKey(player.getUniqueId())) {
        event.setCancelled(false);
        delay.put(player.getUniqueId(), System.currentTimeMillis());
      } else {
        long timestamp = delay.get(player.getUniqueId());
        long currentTime = System.currentTimeMillis();
        if (currentTime - timestamp
            > ConfigUtil.get().getConfig().getInt("chat-delay.delay") * 1000) {
          event.setCancelled(false);
          delay.remove(player.getUniqueId());
          delay.put(player.getUniqueId(), System.currentTimeMillis());
        } else {
          event.setCancelled(true);
          player.sendMessage(
              ChatColor.translateAlternateColorCodes(
                  '&', ConfigUtil.get().getConfig().getString("chat-delay.message")));
        }
      }
    }
  }
  @EventHandler(priority = EventPriority.NORMAL)
  public void onPlayerChat(AsyncPlayerChatEvent event) {
    try {
      final Player player = event.getPlayer();
      String message = event.getMessage().trim();

      final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);

      // Check for spam
      final Long lastRan = TFM_Heartbeat.getLastRan();
      if (lastRan == null
          || lastRan + TotalFreedomMod.HEARTBEAT_RATE * 1000L < System.currentTimeMillis()) {
        // TFM_Log.warning("Heartbeat service timeout - can't check block place/break rates.");
      } else {
        if (playerdata.incrementAndGetMsgCount() > MSG_PER_HEARTBEAT) {
          TFM_Util.bcastMsg(
              player.getName() + " was automatically kicked for spamming chat.", ChatColor.RED);
          TFM_Util.autoEject(player, "Kicked for spamming chat.");

          playerdata.resetMsgCount();

          event.setCancelled(true);
          return;
        }
      }

      // Check for message repeat
      if (playerdata.getLastMessage().equalsIgnoreCase(message)) {
        TFM_Util.playerMsg(player, "Please do not repeat messages.");
        event.setCancelled(true);
        return;
      }

      playerdata.setLastMessage(message);

      // Check for muted
      if (playerdata.isMuted()) {
        if (!TFM_AdminList.isSuperAdmin(player)) {
          player.sendMessage(ChatColor.RED + "You are muted, STFU!");
          event.setCancelled(true);
          return;
        }

        playerdata.setMuted(false);
      }

      // Strip color from messages
      message = ChatColor.stripColor(message);

      // Truncate messages that are too long - 100 characters is vanilla client max
      if (message.length() > 100) {
        message = message.substring(0, 100);
        TFM_Util.playerMsg(player, "Message was shortened because it was too long to send.");
      }

      // Check for caps
      if (message.length() >= 6) {
        int caps = 0;
        for (char c : message.toCharArray()) {
          if (Character.isUpperCase(c)) {
            caps++;
          }
        }
        if (((float) caps / (float) message.length())
            > 0.65) // Compute a ratio so that longer sentences can have more caps.
        {
          message = message.toLowerCase();
        }
      }

      // Check for adminchat
      if (playerdata.inAdminChat()) {
        TFM_Util.adminChatMessage(player, message, false);
        event.setCancelled(true);
        return;
      }

      // Finally, set message
      event.setMessage(message);

      // Set the tag
      if (playerdata.getTag() != null) {
        player.setDisplayName(
            (playerdata.getTag() + " " + player.getDisplayName().replaceAll(" ", "")));
      }

    } catch (Exception ex) {
      TFM_Log.severe(ex);
    }
  }
  public void unload() {
    final Player player = Bukkit.getPlayerExact(name);

    if (player == null) {
      final ArenaPlayer aPlayer = ArenaPlayer.parsePlayer(name);
      PVPArena.instance.getAgm().disconnect(aPlayer.getArena(), aPlayer);
      return;
    }
    debug.i("restoring PlayerState of " + name, player);

    player.setFireTicks(fireticks);
    player.setFoodLevel(foodlevel);
    player.setGameMode(GameMode.getByValue(gamemode));

    final ArenaPlayer aPlayer = ArenaPlayer.parsePlayer(player.getName());
    player.setFoodLevel(foodlevel);
    if (player.getMaxHealth() != maxhealth) {
      final double newHealth = player.getMaxHealth() * health / maxhealth;
      if (newHealth > player.getMaxHealth()) {
        player.setHealth(player.getMaxHealth());
      } else {
        player.setHealth(newHealth);
      }

    } else {
      player.setHealth(health);
    }
    player.setSaturation(saturation);
    player.setGameMode(GameMode.getByValue(gamemode));
    player.setLevel(explevel);
    player.setExp(experience);
    player.setExhaustion(exhaustion);
    player.setFallDistance(0);
    player.setVelocity(new Vector());
    if (aPlayer.getArena() != null
        && aPlayer.getArena().getArenaConfig().getBoolean(CFG.CHAT_COLORNICK)) {
      player.setDisplayName(displayname);
    }

    if (aPlayer.getArena() != null) {

      ArenaModuleManager.unload(aPlayer.getArena(), player);
      PVPArena.instance.getAgm().unload(aPlayer.getArena(), player);
    }

    removeEffects(player);
    player.addPotionEffects(potionEffects);

    aPlayer.setTelePass(false);
    player.setFireTicks(fireticks);

    if (aPlayer.getArena() != null) {
      player.setNoDamageTicks(
          aPlayer.getArena().getArenaConfig().getInt(CFG.TIME_TELEPORTPROTECT) * 20);
    }
    player.resetPlayerTime();
    if (flying && !player.getAllowFlight()) {
      player.setAllowFlight(true);
    }
    player.setFlying(flying);
  }
  @EventHandler
  public void on(PlayerJoinEvent e) {

    final Player p = e.getPlayer();

    Tablist tab = new Tablist();
    tab.setFooter("§3OreBattle v1.0");
    tab.setHeader("§a" + Bukkit.getServerName());
    tab.send(p);

    if (Devathlon.Status == GameStatus.Lobby) {

      /*TagManager tm = new TagManager(p);
      tm.changeTag(tm.getTagByPermissions());
      tm.setTag();*/

      e.setJoinMessage(
          "§7> "
              + p.getDisplayName()
              + " §3hat das Spiel betreten. ("
              + Bukkit.getOnlinePlayers().size()
              + "/"
              + Bukkit.getMaxPlayers()
              + ")");

      if (Bukkit.getOnlinePlayers().size() == 5 && Devathlon.Timer > 10) {
        Devathlon.Timer = 10;
      }

      clearupperson(p);
      createPlayerStats(p);

      p.getInventory()
          .setItem(
              0, createItemstack(Material.COMPASS, "§9Teamauswahl §7<Rechtsklick>", 1, (byte) 0));
      p.getInventory()
          .setItem(
              8,
              createItemstack(
                  Material.SLIME_BALL, "§9Zurück zur Lobby §7<Rechtsklick>", 1, (byte) 0));
      if (Devathlon.sql == true) {
        p.getInventory()
            .setItem(
                4,
                createItemstack(Material.NETHER_STAR, "§9Kitauswahl §7<Rechtsklick>", 1, (byte) 0));
      }

      p.getInventory().setHeldItemSlot(0);
      p.teleport(OreBattle_Command.getLocation("Lobby", true));
      p.sendMessage(Devathlon.prefix + "§3Willkommen bei OreBattle v1.0");

    } else {

      e.setJoinMessage("");

      p.getInventory().clear();
      p.getInventory()
          .setItem(
              0,
              createItemstack(Material.REDSTONE_BLOCK, "§cTeam Rot §7<Rechtsklick>", 1, (byte) 0));
      p.getInventory()
          .setItem(
              1, createItemstack(Material.LAPIS_BLOCK, "§9Team Blau §7<Rechtsklick>", 1, (byte) 0));
      p.getInventory()
          .setItem(
              8,
              createItemstack(
                  Material.SLIME_BALL, "§9Zurück zur Lobby §7<Rechtsklick>", 1, (byte) 0));

      TagManager tm = new TagManager(p);
      tm.changeTag("7");
      tm.setTag();
      p.setPlayerListName("§7[§cX§7] §8| §7" + p.getName());
      p.setDisplayName("§7[§cX§7] " + p.getName());

      Global.spectator.add(p);

      for (Player all : Bukkit.getOnlinePlayers()) {
        all.hidePlayer(p);
        for (Player spec : Global.spectator) {
          spec.showPlayer(p);
          p.showPlayer(spec);
        }
      }

      p.setAllowFlight(true);
      p.setFlying(true);
      p.sendMessage(Devathlon.prefix + "§3Du bist jetzt Spectator.");
      p.teleport(OreBattle_Command.getLocation("Spectator", true));
    }
  }
Exemple #25
0
 @Override
 public void setDisplayName(String name) {
   caller.setDisplayName(name);
 }
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onChat(AsyncPlayerChatEvent ce) {
    if (ce.isCancelled()) {
      return;
    }

    Player player = ce.getPlayer();
    Game game = Main.getInstance().getGameManager().getGameOfPlayer(player);

    if (game == null) {
      boolean seperateGameChat = Main.getInstance().getBooleanConfig("seperate-game-chat", true);
      if (!seperateGameChat) {
        return;
      }

      Iterator<Player> recipiens = ce.getRecipients().iterator();
      while (recipiens.hasNext()) {
        Player recipient = recipiens.next();
        Game recipientGame = Main.getInstance().getGameManager().getGameOfPlayer(recipient);
        if (recipientGame != null) {
          recipiens.remove();
        }
      }
      return;
    }

    if (game.getState() == GameState.STOPPED) {
      return;
    }

    Team team = game.getPlayerTeam(player);
    String message = ce.getMessage();
    boolean isSpectator = game.isSpectator(player);

    if (Main.getInstance().getBooleanConfig("overwrite-names", false)) {
      if (team == null || isSpectator) {
        player.setDisplayName(ChatColor.stripColor(player.getName()));

        player.setPlayerListName(ChatColor.stripColor(player.getName()));
      } else {
        player.setDisplayName(team.getChatColor() + ChatColor.stripColor(player.getName()));
        player.setPlayerListName(team.getChatColor() + ChatColor.stripColor(player.getName()));
      }
    }

    if (Main.getInstance().getBooleanConfig("teamname-on-tab", false)
        && Utils.isSupportingTitles()) {
      if (team == null || isSpectator) {
        player.setPlayerListName(ChatColor.stripColor(player.getDisplayName()));
      } else {
        player.setPlayerListName(
            team.getChatColor()
                + team.getName()
                + ChatColor.WHITE
                + " | "
                + team.getChatColor()
                + ChatColor.stripColor(player.getDisplayName()));
      }
    }

    if (game.getState() != GameState.RUNNING && game.getState() == GameState.WAITING) {

      String format = null;
      if (team == null) {
        format =
            this.getChatFormat(
                Main.getInstance().getStringConfig("lobby-chatformat", "$player$: $msg$"),
                null,
                false,
                true);
      } else {
        format =
            this.getChatFormat(
                Main.getInstance().getStringConfig("ingame-chatformat", "<$team$>$player$: $msg$"),
                team,
                false,
                true);
      }

      ce.setFormat(format);
      return;
    }

    String toAllPrefix = Main.getInstance().getConfig().getString("chat-to-all-prefix", "@");

    if (message.trim().startsWith(toAllPrefix)
        || isSpectator
        || (game.getCycle().isEndGameRunning()
            && Main.getInstance().getBooleanConfig("global-chat-after-end", true))) {
      boolean seperateSpectatorChat =
          Main.getInstance().getBooleanConfig("seperate-spectator-chat", false);

      message = message.trim();
      if (!isSpectator
          && !(game.getCycle().isEndGameRunning()
              && Main.getInstance().getBooleanConfig("global-chat-after-end", true))) {
        ce.setMessage(message.substring(1, message.length()));
      } else {
        ce.setMessage(message);
      }

      String format =
          this.getChatFormat(
              Main.getInstance()
                  .getStringConfig("ingame-chatformat-all", "[$all$] <$team$>$player$: $msg$"),
              team,
              isSpectator,
              true);
      ce.setFormat(format);

      if (!Main.getInstance().isBungee() || seperateSpectatorChat) {
        Iterator<Player> recipiens = ce.getRecipients().iterator();
        while (recipiens.hasNext()) {
          Player recipient = recipiens.next();
          if (!game.isInGame(recipient)) {
            recipiens.remove();
            continue;
          }

          if (!seperateSpectatorChat) {
            continue;
          }

          if (isSpectator && !game.isSpectator(recipient)) {
            recipiens.remove();
          } else if (!isSpectator && game.isSpectator(recipient)) {
            recipiens.remove();
          }
        }
      }
    } else {
      message = message.trim();
      ce.setMessage(message);
      ce.setFormat(
          this.getChatFormat(
              Main.getInstance().getStringConfig("ingame-chatformat", "<$team$>$player$: $msg$"),
              team,
              false,
              false));

      Iterator<Player> recipiens = ce.getRecipients().iterator();
      while (recipiens.hasNext()) {
        Player recipient = recipiens.next();
        if (!game.isInGame(recipient) || !team.isInTeam(recipient)) {
          recipiens.remove();
        }
      }
    }
  }