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

TCPShield warnings #1

Merged
merged 1 commit into from
Jul 15, 2021
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
run/
build/
.gradle/

# IntelliJ
.idea/
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Stay Alive

An alternative keepalive implementation. Downloads can be found under releases.

## Use with TCPShield
Stay Alive is entirely **incompatible** with TCPShield. Do not run the two plugins together.
18 changes: 18 additions & 0 deletions src/main/java/co/technove/plugins/ImprovedKeepAlive.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

public class ImprovedKeepAlive extends JavaPlugin {
Expand All @@ -13,11 +14,23 @@ public class ImprovedKeepAlive extends JavaPlugin {
private KeepAlivePacketAdapter keepAlivePacketAdapter;
private ProtocolManager protocolManager;
private long packetInterval;
private boolean isStartupCancel = false;

@Override
public void onEnable() {
saveDefaultConfig();

final PluginManager pluginManager = getServer().getPluginManager();

if (pluginManager.getPlugin("TCPShield") != null) {
isStartupCancel = true;
getLogger().severe(
"ImprovedKeepAlive is incompatible with TCPShield! Automatically disabling."
);
pluginManager.disablePlugin(this);
return;
}

this.packetInterval = getConfig().getLong("interval", 5000L);

this.keepAliveTask = new KeepAliveTask(this);
Expand All @@ -30,6 +43,11 @@ public void onEnable() {

@Override
public void onDisable() {
// If cancelling startup, these things haven't been initialized.
if (isStartupCancel) {
return;
}

this.protocolManager.removePacketListeners(this);
this.keepAliveTask.cancel();
this.keepAlivePacketAdapter.shutdown();
Expand Down