Skip to content

Commit

Permalink
Fixed an error that could happen when checking if a server is full
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgeiss0702 committed Aug 15, 2022
1 parent 76796b0 commit 4f7a137
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 18 deletions.
Expand Up @@ -134,7 +134,7 @@ public List<? extends AdaptedServer> getServers() {
}
if(found) continue;

serverList.add(new BungeeServer(serverInfo, plugin.getMain()));
serverList.add(new BungeeServer(serverInfo));
}

for(BungeeServer sv : new ArrayList<>(serverList)) {
Expand Down
Expand Up @@ -145,7 +145,7 @@ public void onKick(ServerKickEvent e) {
Component reason = BungeeComponentSerializer.get().deserialize(e.getKickReasonComponent());
main.getEventHandler().onServerKick(
new BungeePlayer(e.getPlayer()),
new BungeeServer(e.getKickedFrom(), main),
new BungeeServer(e.getKickedFrom()),
reason,
false
);
Expand Down
Expand Up @@ -2,12 +2,12 @@

import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import us.ajg0702.queue.api.AjQueueAPI;
import us.ajg0702.queue.api.players.AdaptedPlayer;
import us.ajg0702.queue.api.server.AdaptedServer;
import us.ajg0702.queue.api.server.AdaptedServerInfo;
import us.ajg0702.queue.api.server.AdaptedServerPing;
import us.ajg0702.queue.api.util.QueueLogger;
import us.ajg0702.queue.common.QueueMain;
import us.ajg0702.queue.platforms.bungeecord.players.BungeePlayer;

import java.util.ArrayList;
Expand All @@ -27,12 +27,9 @@ public class BungeeServer implements AdaptedServer {

private int offlineTime = 0;

private final QueueMain main;

public BungeeServer(ServerInfo handle, QueueMain main) {
public BungeeServer(ServerInfo handle) {
this.handle = handle;
serverInfo = new BungeeServerInfo(handle);
this.main = main;
}

@Override
Expand Down Expand Up @@ -113,13 +110,13 @@ public boolean canJoinFull(AdaptedPlayer player) {
player.hasPermission("ajqueue.joinfullserver."+getName()) ||
player.hasPermission("ajqueue.joinfullandbypassserver."+getName()) ||
player.hasPermission("ajqueue.joinfullandbypass") ||
(main.isPremium() && main.getLogic().getPermissionGetter().hasUniqueFullBypass(player, getName()))
(AjQueueAPI.getInstance().isPremium() && AjQueueAPI.getInstance().getLogic().getPermissionGetter().hasUniqueFullBypass(player, getName()))
;
}

@Override
public boolean justWentOnline() {
return System.currentTimeMillis()-lastOffline <= (main.getConfig().getDouble("wait-time")) && isOnline();
return System.currentTimeMillis()-lastOffline <= (AjQueueAPI.getInstance().getConfig().getDouble("wait-time")) && isOnline();
}

@Override
Expand Down
Expand Up @@ -159,7 +159,7 @@ public List<? extends AdaptedServer> getServers() {
if(found) continue;

Debug.info("Added "+registeredServer.getServerInfo().getName());
serverList.add(new VelocityServer(registeredServer, plugin.getMain()));
serverList.add(new VelocityServer(registeredServer));
}

for(VelocityServer sv : new ArrayList<>(serverList)) {
Expand Down
Expand Up @@ -144,7 +144,7 @@ public void onKick(KickedFromServerEvent e) {
Optional<Component> reasonOptional = e.getServerKickReason();
main.getEventHandler().onServerKick(
new VelocityPlayer(e.getPlayer()),
new VelocityServer(e.getServer(), main),
new VelocityServer(e.getServer()),
reasonOptional.orElseGet(() -> Component.text("Proxy lost connection")),
// According to Tux on discord, velocity doesnt give a reason when the proxy loses connection to the connected server
e.kickedDuringServerConnect()
Expand Down
Expand Up @@ -3,12 +3,13 @@
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.proxy.server.ServerPing;
import us.ajg0702.queue.api.AjQueueAPI;
import us.ajg0702.queue.api.players.AdaptedPlayer;
import us.ajg0702.queue.api.server.AdaptedServer;
import us.ajg0702.queue.api.server.AdaptedServerInfo;
import us.ajg0702.queue.api.server.AdaptedServerPing;
import us.ajg0702.queue.api.util.QueueLogger;
import us.ajg0702.queue.common.QueueMain;
import us.ajg0702.queue.common.utils.Debug;
import us.ajg0702.queue.platforms.velocity.players.VelocityPlayer;

import java.util.ArrayList;
Expand All @@ -27,11 +28,8 @@ public class VelocityServer implements AdaptedServer {

private int offlineTime = 0;

private final QueueMain main;

public VelocityServer(RegisteredServer handle, QueueMain main) {
public VelocityServer(RegisteredServer handle) {
this.handle = handle;
this.main = main;
}

@Override
Expand Down Expand Up @@ -112,18 +110,19 @@ public int getOfflineTime() {
@Override
public boolean canJoinFull(AdaptedPlayer player) {
if(player == null) return true;
Debug.info("on "+getName());
return
player.hasPermission("ajqueue.joinfull") ||
player.hasPermission("ajqueue.joinfullserver."+getName()) ||
player.hasPermission("ajqueue.joinfullandbypassserver."+getName()) ||
player.hasPermission("ajqueue.joinfullandbypass") ||
(main.isPremium() && main.getLogic().getPermissionGetter().hasUniqueFullBypass(player, getName()))
(AjQueueAPI.getInstance().isPremium() && AjQueueAPI.getInstance().getLogic().getPermissionGetter().hasUniqueFullBypass(player, getName()))
;
}

@Override
public boolean justWentOnline() {
return System.currentTimeMillis()-lastOffline <= (main.getConfig().getDouble("wait-time")) && isOnline();
return System.currentTimeMillis()-lastOffline <= (AjQueueAPI.getInstance().getConfig().getDouble("wait-time")) && isOnline();
}

@Override
Expand Down

0 comments on commit 4f7a137

Please sign in to comment.