public static TextComponent createMessage(
     String message, HoverEvent hoverEvent, ClickEvent clickEvent) {
   TextComponent component = new TextComponent(message);
   component.setHoverEvent(hoverEvent);
   component.setClickEvent(clickEvent);
   return component;
 }
Пример #2
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)));
   }
 }
Пример #3
0
  public void sendPlayer(Player p) {
    if (p == null) {
      return;
    }
    TextComponent formattedtitle = (TextComponent) this.title.duplicate();
    formattedtitle.setText(StringUtils.center(this.title.getText(), CHAT_SIZE, '-'));
    p.spigot().sendMessage(formattedtitle);

    if (!subTitle.equals("")) {
      p.spigot().sendMessage(subTitle);
    }

    TextComponent message = new TextComponent("");
    int counter = CHAT_SIZE;
    for (int i = 0; i < parts.size(); i++) {
      message.addExtra("[");
      message.addExtra(parts.get(i));
      message.addExtra("] ");
      counter -= (parts.get(i).getText().length() + 2);
      if (i + 1 != parts.size()) {
        if (counter < parts.get(i + 1).getText().length() + 2) {
          p.spigot().sendMessage(message);
          message = new TextComponent("");
          counter = CHAT_SIZE;
        }
      } else {
        p.spigot().sendMessage(message);
      }
    }

    p.spigot().sendMessage(formattedtitle);
  }
Пример #4
0
  @EventHandler
  public void onJoin(final PostLoginEvent e) {
    final ProxiedPlayer p = e.getPlayer();
    ProxyServer.getInstance()
        .getScheduler()
        .runAsync(
            plugin,
            () -> {
              TextComponent welcome = new TextComponent("Bienvenue, " + p.getName() + " !");
              welcome.setColor(ChatColor.GOLD);

              String key = "rejoinlist:" + e.getPlayer().getUniqueId().toString();
              Jedis cache = plugin.getConnector().getBungeeResource();
              String srv = cache.get(key);
              cache.close();
              if (srv != null) {
                final ServerInfo server = ProxyServer.getInstance().getServerInfo(srv);
                if (server != null)
                  ProxyServer.getInstance()
                      .getScheduler()
                      .schedule(
                          plugin,
                          () ->
                              e.getPlayer()
                                  .connect(
                                      server,
                                      (aBoolean, throwable) -> {
                                        if (aBoolean) {
                                          p.sendMessage(
                                              new ComponentBuilder("")
                                                  .color(ChatColor.GREEN)
                                                  .append("Vous avez été remis en jeu.")
                                                  .create());
                                        }
                                      }),
                          200L,
                          TimeUnit.MILLISECONDS);
              }
            });
  }
Пример #5
0
 @Override
 public void sendMessage(ChatMessageType position, BaseComponent message) {
   // Action bar doesn't display the new JSON formattings, legacy works - send it using this for
   // now
   if (position == ChatMessageType.ACTION_BAR
       && pendingConnection.getVersion() >= ProtocolConstants.MINECRAFT_1_8) {
     sendMessage(
         position,
         ComponentSerializer.toString(new TextComponent(TextComponent.toLegacyText(message))));
   } else {
     sendMessage(position, ComponentSerializer.toString(message));
   }
 }
Пример #6
0
 public void addTranslatedExtra(String text) {
   super.addExtra(I18n.getTranslation(text));
 }
Пример #7
0
 public void setTranslatedText(String text) {
   super.setText(I18n.getTranslation(text));
 }
Пример #8
0
 @Override
 public void sendMessage(String message) {
   sendMessage(TextComponent.fromLegacyText(message));
 }
Пример #9
0
 @Override
 public void disconnect(String reason) {
   disconnect0(TextComponent.fromLegacyText(reason));
 }
Пример #10
0
 public static BaseComponent[] __(final String message) {
   return TextComponent.fromLegacyText(
       ChatColor.translateAlternateColorCodes('&', prefix + message));
 }
 @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>"));
   }
 }