Example #1
0
  public static void sendTitle(
      Player player, Integer fadeIn, Integer stay, Integer fadeOut, String title, String subtitle) {
    PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
    PacketPlayOutTitle packetPlayOutTimes =
        new PacketPlayOutTitle(
            PacketPlayOutTitle.EnumTitleAction.TIMES,
            null,
            fadeIn.intValue(),
            stay.intValue(),
            fadeOut.intValue());
    connection.sendPacket(packetPlayOutTimes);

    if (subtitle != null) {
      subtitle = subtitle.replaceAll("%player%", player.getDisplayName());
      subtitle = ChatColor.translateAlternateColorCodes((char) '&', (String) subtitle);
      IChatBaseComponent titleSub =
          IChatBaseComponent.ChatSerializer.a((String) ("{\"text\": \"" + subtitle + "\"}"));
      PacketPlayOutTitle packetPlayOutSubTitle =
          new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, titleSub);
      connection.sendPacket(packetPlayOutSubTitle);
    }

    if (title != null) {
      title = title.replaceAll("%player%", player.getDisplayName());
      title = ChatColor.translateAlternateColorCodes((char) '&', (String) title);
      IChatBaseComponent titleMain =
          IChatBaseComponent.ChatSerializer.a((String) ("{\"text\": \"" + title + "\"}"));
      PacketPlayOutTitle packetPlayOutTitle =
          new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, titleMain);
      connection.sendPacket(packetPlayOutTitle);
    }
  }
Example #2
0
  public static void sendTabTitle(Player player, String header, String footer) {
    if (header == null) {
      header = "";
    }

    header = ChatColor.translateAlternateColorCodes((char) '&', (String) header);

    if (footer == null) {
      footer = "";
    }

    footer = ChatColor.translateAlternateColorCodes((char) '&', (String) footer);
    header = header.replaceAll("%player%", player.getDisplayName());
    footer = footer.replaceAll("%player%", player.getDisplayName());
    PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
    IChatBaseComponent tabTitle =
        IChatBaseComponent.ChatSerializer.a((String) ("{\"text\": \"" + header + "\"}"));
    IChatBaseComponent tabFoot =
        IChatBaseComponent.ChatSerializer.a((String) ("{\"text\": \"" + footer + "\"}"));
    PacketPlayOutPlayerListHeaderFooter headerPacket =
        new PacketPlayOutPlayerListHeaderFooter(tabTitle);

    try {
      Field field = headerPacket.getClass().getDeclaredField("b");
      field.setAccessible(true);
      field.set((Object) headerPacket, (Object) tabFoot);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      connection.sendPacket(headerPacket);
    }
  }
Example #3
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);
  }
Example #4
0
 /**
  * Kick a player from the proxy for a specified reason
  *
  * @param player
  * @param reason
  */
 public static void kick(final ProxiedPlayer player, final String reason) {
   if (reason == null || reason.equals("")) {
     player.disconnect(TextComponent.fromLegacyText("You have been disconnected of the server."));
   } else {
     player.disconnect(
         TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', reason)));
   }
 }
Example #5
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onProxyPing(ProxyPingEvent e) {
    if (e.getResponse().getPlayers().getMax() == 0) return;

    e.setResponse(
        new ServerPing(
            e.getResponse().getVersion(),
            e.getResponse().getPlayers(),
            ChatColor.translateAlternateColorCodes(
                '&', AMCBungee.getRandomModt(e.getConnection().getAddress().getAddress())),
            AMCBungee.getRandomFavicon()));
  }
Example #6
0
  @EventHandler
  public void onInventroyClick(InventoryClickEvent event) {
    if (!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Offical MD Links"))
      ;
    return;

    Player player = (Player) event.getWhoClicked();
    event.setCancelled(true);

    if (event.getCurrentItem() == null
        || event.getCurrentItem().getType() == Material.AIR
        || !event.getCurrentItem().hasItemMeta()) {
      player.closeInventory();
      return;
    }

    switch (event.getCurrentItem().getType()) {
      case BEACON:
        player.closeInventory();
        player.sendMessage("&6&lClick to submit a application: http://magicaldreams.us/apply/");
        break;

      case ANVIL:
        player.closeInventory();
        player.sendMessage("&6&lClick to submit a application: http://magicaldreams.us/apply/");
        break;

      case MINECART:
        player.closeInventory();
        player.sendMessage("&6&lClick to submit a application: http://magicaldreams.us/apply/");
        break;

      case DIAMOND:
        player.closeInventory();
        player.sendMessage("&6&lClick to submit a application: http://magicaldreams.us/apply/");
        break;

      case WOOL:
        player.closeInventory();
        player.sendMessage("&6&lClick to submit a application: http://magicaldreams.us/apply/");
        break;

      case COMPASS:
        player.closeInventory();
        player.sendMessage("&6&lClick to submit a application: http://magicaldreams.us/apply/");
        break;
      default:
        player.closeInventory();
        break;
    }
  }
Example #7
0
 @EventHandler
 public void onLogin(PlayerLoginEvent event) {
   Player player = event.getPlayer();
   if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL) {
     if (player.hasPermission(ConfigUtil.get().getConfig().getString("joinleave.permission"))) {
       event.setResult(PlayerLoginEvent.Result.ALLOWED);
     } else {
       event.setResult(PlayerLoginEvent.Result.KICK_FULL);
       event.setKickMessage(
           ChatColor.translateAlternateColorCodes(
               '&', ConfigUtil.get().getConfig().getString("joinleave.kick-message")));
     }
   }
 }
Example #8
0
  @Override
  @SuppressWarnings("unchecked")
  public Collection<ListenerInfo> getListeners() {
    Collection<Map<String, Object>> base =
        get("listeners", (Collection) Arrays.asList(new Map[] {new HashMap()}));
    Map<String, String> forcedDef = new HashMap<>();
    forcedDef.put("pvp.md-5.net", "pvp");

    Collection<ListenerInfo> ret = new HashSet<>();

    for (Map<String, Object> val : base) {
      String motd = get("motd", "Another Bungee server", val);
      motd = ChatColor.translateAlternateColorCodes('&', motd);

      int maxPlayers = get("max_players", 1, val);
      String defaultServer = get("default_server", "lobby", val);
      String fallbackServer = get("fallback_server", defaultServer, val);
      boolean forceDefault = get("force_default_server", false, val);
      String host = get("host", "0.0.0.0:25577", val);
      int tabListSize = get("tab_size", 60, val);
      InetSocketAddress address = Util.getAddr(host);
      Map<String, String> forced = new CaseInsensitiveMap<>(get("forced_hosts", forcedDef, val));
      String textureURL = get("texture_url", null, val);
      int textureSize = get("texture_size", 16, val);
      TexturePackInfo texture =
          (textureURL == null) ? null : new TexturePackInfo(textureURL, textureSize);
      String tabListName = get("tab_list", "GLOBAL_PING", val);
      DefaultTabList value = DefaultTabList.valueOf(tabListName.toUpperCase());
      if (value == null) {
        value = DefaultTabList.GLOBAL_PING;
      }

      ListenerInfo info =
          new ListenerInfo(
              address,
              motd,
              maxPlayers,
              tabListSize,
              defaultServer,
              fallbackServer,
              forceDefault,
              forced,
              texture,
              value.clazz);
      ret.add(info);
    }

    return ret;
  }
Example #9
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")));
        }
      }
    }
  }
Example #10
0
 @EventHandler
 public void onLeave(PlayerQuitEvent event) {
   Player player = event.getPlayer();
   if (!player.hasPermission(
       ConfigUtil.get().getConfig().getString("joinleavemessage.permission"))) {
     event.setQuitMessage(null);
   } else {
     event.setQuitMessage(
         ChatColor.translateAlternateColorCodes(
             '&',
             ConfigUtil.get()
                 .getConfig()
                 .getString("joinleavemessage.quit-message")
                 .replaceAll("%player%", player.getDisplayName())));
   }
 }
Example #11
0
 @EventHandler
 public void onPlayerFillBucket(PlayerBucketFillEvent PBF) {
   Player PBFP = PBF.getPlayer();
   if (!Authentication.config.getBoolean("Authentication.Events.BlockBreak.Allowed") == true) {
     if (!Authentication.instance.hasPlayerAccepted(PBFP)) {
       PBF.setCancelled(true);
       if (Authentication.instance.RulesMessage == true) {
         PBFP.performCommand("serverrules");
       }
       if (Authentication.instance.EventMessage == true) {
         PBFP.sendMessage(
             ChatColor.translateAlternateColorCodes(
                 '&',
                 Authentication.config.getString("Authentication.Events.BlockBreak.Message")));
       }
     }
   }
 }
Example #12
0
 @EventHandler
 public void onPlayerPlaceBlock(BlockPlaceEvent BP) {
   Player BPP = BP.getPlayer();
   if (!Authentication.config.getBoolean("Authentication.Events.BlockPlace.Allowed") == true) {
     if (!Authentication.instance.hasPlayerAccepted(BPP)) {
       BP.setCancelled(true);
       if (Authentication.instance.RulesMessage == true) {
         BPP.performCommand("serverrules");
       }
       if (Authentication.instance.EventMessage == true) {
         BPP.sendMessage(
             ChatColor.translateAlternateColorCodes(
                 '&',
                 Authentication.config.getString("Authentication.Events.BlockPlace.Message")));
       }
     }
   }
 }
Example #13
0
 public static void noRedisBroadcast(final String message, final String perm) {
   final BaseComponent[] bsMsg = __(message);
   for (final ProxiedPlayer p : ProxyServer.getInstance().getPlayers()) {
     if (p.hasPermission(perm) || p.hasPermission("bat.admin")) {
       p.sendMessage(bsMsg);
     }
     // If he has a grantall permission, he will have the broadcast on all the servers
     else {
       for (final String playerPerm : Core.getCommandSenderPermission(p)) {
         if (playerPerm.startsWith("bat.grantall.")) {
           p.sendMessage(bsMsg);
           break;
         }
       }
     }
   }
   getInstance().getLogger().info(ChatColor.translateAlternateColorCodes('&', message));
 }
Example #14
0
  public static String getHeader(String title) {
    String insert = ChatColor.GOLD + "[" + ChatColor.AQUA + title + ChatColor.GOLD + "]";

    int insertLength = ChatColor.stripColor(insert).length();
    int s = (53 - insertLength);
    int ta = Math.round((s / 2));

    String o = "";

    for (int i = 0; i < ta; i++) {
      o = o + "-";
    }

    return ChatColor.DARK_AQUA
        + ""
        + ChatColor.STRIKETHROUGH
        + o
        + insert
        + ChatColor.DARK_AQUA
        + ""
        + ChatColor.STRIKETHROUGH
        + o;
  }
Example #15
0
 private ItemStack generateIcon() {
   ItemStack i = icon;
   if (i == null) i = helmet;
   if (i == null) i = helmet;
   if (i == null) i = chest;
   if (i == null) i = boots;
   if (i == null && items.size() > 0) i = items.get(0);
   if (i == null) {
     i = new ItemStack(Material.LEATHER_HELMET);
     LeatherArmorMeta meta = (LeatherArmorMeta) i.getItemMeta();
     int r = (name.hashCode() & 0xFF0000) >> 16;
     int g = (name.hashCode() & 0x00FF00) >> 8;
     int b = name.hashCode() & 0x0000FF;
     meta.setColor(Color.fromRGB(r, g, b));
     i.setItemMeta(meta);
   }
   ItemMeta meta = i.getItemMeta();
   if (!meta.hasDisplayName()) {
     meta.setDisplayName(ChatColor.YELLOW + ChatColor.translateAlternateColorCodes('&', name));
     i.setItemMeta(meta);
   }
   generatedIcon = i;
   return generatedIcon;
 }
Example #16
0
 public static BaseComponent[] __(final String message) {
   return TextComponent.fromLegacyText(
       ChatColor.translateAlternateColorCodes('&', prefix + message));
 }
Example #17
0
 public static String translateToColorCode(String msg) {
   return ChatColor.translateAlternateColorCodes('&', msg);
 }
Example #18
0
 public static String getLocale(String name) {
   return ChatColor.translateAlternateColorCodes('&', getSection("locale").getString(name));
 }
 public String colorize(String input) {
   return ChatColor.translateAlternateColorCodes('&', input);
 }
 @Override
 public String colorize(String s) {
   return ChatColor.translateAlternateColorCodes('&', s);
 }
 @Override
 public void execute(CommandSender commandSender, String[] strings) {
   if (strings.length < 1) {
     strings = new String[] {"help"};
   }
   switch (strings[0]) {
     case "about":
       commandSender.sendMessage(
           TextComponent.fromLegacyText(
               ChatColor.GOLD
                   + "AdvancedBungeeAnnouncer "
                   + AdvancedBungeeAnnouncer.getPlugin().getDescription().getVersion()
                   + " by tuxed"));
       commandSender.sendMessage(
           TextComponent.fromLegacyText(
               ChatColor.GOLD
                   + "This plugin is freely redistributable under the terms of the WTFPL, see http://www.wtfpl.net for more details."));
       break;
     case "reload":
       AdvancedBungeeAnnouncer.getConfiguration().reloadAnnouncements();
       AdvancedBungeeAnnouncer.getConfiguration().reloadConfiguration();
       commandSender.sendMessage(
           TextComponent.fromLegacyText(
               ChatColor.GREEN + "The plugin was reloaded successfully."));
       break;
     case "create":
       if (strings.length < 4) {
         commandSender.sendMessage(
             TextComponent.fromLegacyText(ChatColor.RED + "Not enough arguments specified."));
         commandSender.sendMessage(
             TextComponent.fromLegacyText(
                 ChatColor.RED + "/announcer create <id> <server(s)> <line 1>"));
         commandSender.sendMessage(
             TextComponent.fromLegacyText(
                 ChatColor.RED
                     + "<server(s)> may be 'global' if the message is going to be sent to all servers."));
         commandSender.sendMessage(
             TextComponent.fromLegacyText(
                 ChatColor.RED
                     + "<server(s)> may have semicolons to separate server names, like hub;pvp."));
         return;
       }
       if (AdvancedBungeeAnnouncer.getConfiguration().getAnnouncements().containsKey(strings[1])) {
         commandSender.sendMessage(
             TextComponent.fromLegacyText(
                 ChatColor.RED + "An announcement with this ID already exists."));
         return;
       }
       String message = Joiner.on(" ").join(Arrays.copyOfRange(strings, 3, strings.length));
       List<String> servers;
       if (strings[2].contains(";")) {
         servers = ImmutableList.copyOf(Splitter.on(";").omitEmptyStrings().split(strings[2]));
       } else {
         servers = Collections.singletonList(strings[2]);
       }
       Announcement announcement = new Announcement(message);
       announcement.getServers().addAll(servers);
       AdvancedBungeeAnnouncer.getConfiguration().getAnnouncements().put(strings[1], announcement);
       commandSender.sendMessage(
           TextComponent.fromLegacyText(ChatColor.GREEN + "New announcement added."));
       break;
     case "remove":
       if (strings.length < 2) {
         commandSender.sendMessage(
             TextComponent.fromLegacyText(ChatColor.RED + "Not enough arguments specified."));
         commandSender.sendMessage(
             TextComponent.fromLegacyText(ChatColor.RED + "/announcer remove <id>"));
         return;
       }
       if (!AdvancedBungeeAnnouncer.getConfiguration()
           .getAnnouncements()
           .containsKey(strings[1])) {
         commandSender.sendMessage(
             TextComponent.fromLegacyText(
                 ChatColor.RED + "An announcement with this ID does not exist."));
         return;
       }
       AdvancedBungeeAnnouncer.getConfiguration().getAnnouncements().remove(strings[1]);
       commandSender.sendMessage(
           TextComponent.fromLegacyText(ChatColor.GREEN + "Announcement removed."));
       break;
     case "list":
       commandSender.sendMessage(
           TextComponent.fromLegacyText(
               ChatColor.YELLOW
                   + "Announcements: "
                   + Joiner.on(", ")
                       .join(
                           AdvancedBungeeAnnouncer.getConfiguration()
                               .getAnnouncements()
                               .keySet())));
       break;
     case "info":
       if (strings.length < 2) {
         commandSender.sendMessage(
             TextComponent.fromLegacyText(ChatColor.RED + "Not enough arguments specified."));
         commandSender.sendMessage(
             TextComponent.fromLegacyText(ChatColor.RED + "/announcer info <id>"));
         return;
       }
       Announcement a =
           AdvancedBungeeAnnouncer.getConfiguration().getAnnouncements().get(strings[1]);
       commandSender.sendMessage(
           TextComponent.fromLegacyText("-------------------------------------"));
       commandSender.sendMessage(
           TextComponent.fromLegacyText(ChatColor.AQUA + "Announcement ID: " + strings[1]));
       commandSender.sendMessage(
           TextComponent.fromLegacyText(ChatColor.AQUA + "Announcement Text:"));
       for (String s : a.getText().split("\n")) {
         commandSender.sendMessage(
             TextComponent.fromLegacyText(
                 ChatColor.AQUA
                     + "-"
                     + ChatColor.RESET
                     + ChatColor.translateAlternateColorCodes('&', s)));
       }
       commandSender.sendMessage(
           TextComponent.fromLegacyText(
               ChatColor.AQUA + "Sent To: " + Joiner.on(", ").join(a.getServers())));
       commandSender.sendMessage(
           TextComponent.fromLegacyText("-------------------------------------"));
       break;
     default:
       commandSender.sendMessage(
           TextComponent.fromLegacyText(
               ChatColor.RED
                   + "/announcer <about|reload|create|remove|{set,add,remove}line|list|info>"));
   }
 }