Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for checking if packetevents is terminated #959

Merged
merged 4 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public LogManager getLogManager() {

public abstract void terminate();

public abstract boolean isTerminated();

public abstract T getPlugin();

public abstract ServerManager getServerManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class PacketEventsSettings {
private boolean debugEnabled = false;
private boolean fullStackTraceEnabled = false;
private boolean kickOnPacketExceptionEnabled = true;
private boolean kickIfTerminated = true;
private Function<String, InputStream> resourceProvider = path -> PacketEventsSettings.class
.getClassLoader()
.getResourceAsStream(path);
Expand Down Expand Up @@ -139,6 +140,18 @@ public PacketEventsSettings kickOnPacketException(boolean kickOnPacketExceptionE
return this;
}

/**
* This decides if PacketEvents should kick the player on join if PacketEvents is terminated.
*
* @param kickIfTerminated Value
* @return Settings instance.
*/
@ApiStatus.Internal
public PacketEventsSettings kickIfTerminated(boolean kickIfTerminated) {
this.kickIfTerminated = kickIfTerminated;
return this;
}

/**
* Some projects may want to implement a CDN with resources like asset mappings
* By default, all resources are retrieved from the ClassLoader
Expand Down Expand Up @@ -219,6 +232,15 @@ public boolean isKickOnPacketExceptionEnabled() {
return kickOnPacketExceptionEnabled;
}

/**
* Should packetevents kick the player on join if PacketEvents is terminated?
*
* @return Getter for {@link #kickIfTerminated}
*/
public boolean isKickIfTerminated() {
return kickIfTerminated;
}

/**
* As described above, this method retrieves the function that acquires the InputStream
* of a desired resource by its path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ protected void log(Level level, @Nullable NamedTextColor color, String message)

private boolean loaded;
private boolean initialized;
private boolean terminated;

@Override
public void load() {
Expand Down Expand Up @@ -127,9 +128,15 @@ public boolean isInitialized() {
public void terminate() {
if (initialized) {
initialized = false;
terminated = true;
}
}

@Override
public boolean isTerminated() {
return terminated;
}

@Override
public Plugin getPlugin() {
return plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ protected void log(Level level, @Nullable NamedTextColor color, String message)
};
private boolean loaded;
private boolean initialized;
private boolean terminated;

@Override
public void load() {
Expand Down Expand Up @@ -247,9 +248,15 @@ public void terminate() {
// Unregister all our listeners
getEventManager().unregisterAllListeners();
initialized = false;
terminated = true;
}
}

@Override
public boolean isTerminated() {
return terminated;
}

@Override
public Plugin getPlugin() {
return plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ protected void log(Level level, @Nullable NamedTextColor color, String message)
};
private boolean loaded;
private boolean initialized;
private boolean terminated;

@Override
public void load() {
Expand Down Expand Up @@ -234,9 +235,15 @@ public void terminate() {
//Unregister all our listeners
getEventManager().unregisterAllListeners();
initialized = false;
terminated = true;
}
}

@Override
public boolean isTerminated() {
return terminated;
}

@Override
public Minecraft getPlugin() {
return Minecraft.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public static PacketEventsAPI<BuildData> buildNoCache(BuildData data, ChannelInj
private final NettyManager nettyManager = new NettyManagerImpl();
private boolean loaded;
private boolean initialized;
private boolean terminated;

@Override
public void load() {
Expand Down Expand Up @@ -136,9 +137,15 @@ public void terminate() {
//Unregister all our listeners
getEventManager().unregisterAllListeners();
initialized = false;
terminated = true;
}
}

@Override
public boolean isTerminated() {
return terminated;
}

@Override
public BuildData getPlugin() {
return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void onJoin(PlayerJoinEvent e) {
//We did not inject this user
Object channel = PacketEvents.getAPI().getPlayerManager().getChannel(player);
//Check if it is a fake connection...
if (!FakeChannelUtil.isFakeChannel(channel)) {
if (!FakeChannelUtil.isFakeChannel(channel) && (!PacketEvents.getAPI().isTerminated() || PacketEvents.getAPI().getSettings().isKickIfTerminated())) {
//Kick them, if they are not a fake player.
FoliaScheduler.getRegionScheduler().runDelayed(plugin, player.getLocation(), (o) -> {
player.kickPlayer("PacketEvents 2.0 failed to inject");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public static PacketEventsAPI<Plugin> buildNoCache(Plugin plugin, PacketEventsSe
private boolean loaded;
private boolean initialized;
private boolean lateBind = false;
private boolean terminated = false;

@Override
public void load() {
Expand Down Expand Up @@ -222,9 +223,15 @@ public void terminate() {
//Unregister all listeners. Because if we attempt to reload, we will end up with duplicate listeners.
getEventManager().unregisterAllListeners();
initialized = false;
terminated = true;
}
}

@Override
public boolean isTerminated() {
return terminated;
}

@Override
public Plugin getPlugin() {
return plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ protected void log(Level level, @Nullable NamedTextColor color, String message)
};
private boolean loaded;
private boolean initialized;
private boolean terminated;

@Override
public void load() {
Expand Down Expand Up @@ -244,9 +245,15 @@ public void terminate() {
// Unregister all our listeners
getEventManager().unregisterAllListeners();
initialized = false;
terminated = true;
}
}

@Override
public boolean isTerminated() {
return terminated;
}

@Override
public LogManager getLogManager() {
return logManager;
Expand Down