ME1312 / SubServers-2

SubServers – The Minecraft Server Management Platform
Apache License 2.0
91 stars 23 forks source link

Changing ProxyPing & PostLogin Messages if no SubServer is started #39

Closed xXSchrandXx closed 5 years ago

xXSchrandXx commented 5 years ago

What Should Be Added

A option to enable/disable and edit the Ping- and Loginmessage if no SubServer has startet. (Only BungeeCord is running)

Why It Should be Added

More information for the users and a better denymessage. Code:

  private TextComponent ping = new TextComponent('CONFIGTEXT'));
  private ServerPing.Protocol version = new ServerPing.Protocol('CONFIGTEXT', 2);
  private TextComponent login = new TextComponent('CONFIGTEXT'));

  @EventHandler(priority=EventPriority.HIGHEST)
  public void onPing(ProxyPingEvent e) {
    if (!LobbyisOnline()) {
      ServerPing conn = e.getResponse();
      conn.setVersion(version);
      conn.setDescriptionComponent(ping);
      e.setResponse(conn);
    }
  }

  @EventHandler(priority=EventPriority.HIGHEST)
  public void onLogin(PostLoginEvent e) {
    if (!LobbyisOnline()) {
      ProxiedPlayer p = e.getPlayer();
      p.disconnect(login);
    }
  }
  private boolean LobbyisOnline() {
    try {
      for (Server server : SubAPI.getInstance().getServers().values()) {
        if (server.getName().equalsIgnoreCase("lobby")) {
          if (server instanceof SubServer) {
            if (((SubServer) server).isRunning()) {
              return true;
            }
          }
        }
      }
    }
    catch (Exception e) {
      main.getInstance().getLogger().log(Level.WARNING, main.Prefix, e);
    }
    return false;
  }

What's The Alternative

Don't know...

xXSchrandXx commented 5 years ago

Edit the Code because it wasn't checking if the server is running

ME1312 commented 5 years ago

Have you looked through this file for what you're looking for yet? This is the native lang file for BungeeCord internal messages. messages.properties

That aside, it would probably be better to have a separate message in this case.

ME1312 commented 5 years ago

My implementation of this idea is now in the latest commit. You can take a look at the diff if you're interested.