Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Commit

Permalink
Added commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed May 18, 2019
1 parent 7cff787 commit e572070
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 110 deletions.
2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.ishland.bukkit.AsyncKeepAlive</groupId>
<artifactId>AsyncKeepAlive</artifactId>
<version>0.3</version>
<version>0.4-SNAPSHOT</version>
<build>
<plugins>
<plugin>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ public void register(Plugin plugin, boolean debug, AsyncPacketThread packetThrea
object.register(plugin, debug, packetThread, placeHolder);
plugin.getLogger().info("Packet listener started.");
}

public AsyncPacketListener getObject() {
return this.object;
}
}
14 changes: 2 additions & 12 deletions src/main/java/com/ishland/bukkit/AsyncKeepAlive/main/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.bukkit.plugin.java.JavaPlugin;

import com.comphenix.protocol.ProtocolLibrary;
import com.ishland.bukkit.AsyncKeepAlive.detection.LagDetection;
import com.ishland.bukkit.AsyncKeepAlive.command.CommandHandler;
import com.ishland.bukkit.AsyncKeepAlive.launcher.LauncherForPacketListener;
import com.ishland.bukkit.AsyncKeepAlive.launcher.LauncherForPacketThread;

Expand All @@ -30,7 +30,6 @@ public class Launcher extends JavaPlugin {
private Metrics metrics;
private LauncherForPacketThread packetThread;
private LauncherForPacketListener packetListener;
private LagDetection lagDetection;

@Override
public void onEnable() {
Expand All @@ -56,8 +55,7 @@ public void onEnable() {

this.startSendingThread();
this.startPacketListener();
this.lagDetection = new LagDetection(this);

new CommandHandler(this);
getLogger().info("AsyncKeepAlive " + this.getDescription().getVersion() + " enabled in "
+ String.valueOf(System.currentTimeMillis() - startTime) + "ms");
}
Expand Down Expand Up @@ -116,7 +114,6 @@ protected void startPacketListener() {
@Override
public void onDisable() {
long startTime = System.currentTimeMillis();
this.getLagDetection().stopDetection();
getLogger().info("Removing packet listener...");
ProtocolLibrary.getProtocolManager().removePacketListeners(this);
getLogger().info("Stopping packet thread...");
Expand Down Expand Up @@ -203,11 +200,4 @@ public void setPacketListener(LauncherForPacketListener packetListener) {
this.packetListener = packetListener;
}

/**
* @return the lagDetection
*/
public LagDetection getLagDetection() {
return lagDetection;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,23 @@
import com.ishland.bukkit.AsyncKeepAlive.main.PlaceHolderMain;

public class AsyncPacketListener {
private long count = (long) 0;

public void register(Plugin plugin, boolean debug, AsyncPacketThread packetThread, PlaceHolderMain placeHolder) {

}

/**
* @return the count
*/
public long getCount() {
return count;
}

/**
* @param count the count to set
*/
public void setCount(long count) {
this.count = count;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void onPacketReceiving(PacketEvent e) {
if (placeHolder != null)
placeHolder.latency.put(e.getPlayer().getName(), latency);
e.setCancelled(true);
setCount(getCount() + 1);
if (isDebug())
plugin.getLogger().info("[Debug] Got plugin-sent keepalive "
+ String.valueOf(packetValue) + " from " + e.getPlayer().getName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void onPacketReceiving(PacketEvent e) {
+ String.valueOf(packetValue) + " from " + e.getPlayer().getName()
+ " after " + latency.toString() + " ms");
e.setCancelled(true);
setCount(getCount() + 1);
} else {
if (debug)
plugin.getLogger().info("[Debug] Got server-sent keepalive "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Timer;
import java.util.TimerTask;
Expand All @@ -22,6 +21,7 @@ public class AsyncPacketThread {
private Timer timer = new Timer();
private TimerTask mainloop;
protected Long index = (long) 0;
protected Long count = (long) 0;

public void doDebug() {
debug = true;
Expand Down Expand Up @@ -87,23 +87,6 @@ public void run() {
getPlugin().getLogger().info("Packet thread started.");

timer.schedule(mainloop, 1000, this.frequency);
timer.schedule(new TimerTask() {

@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("Nothing, just a new timer");
Map<Thread, StackTraceElement[]> map = Thread.getAllStackTraces();
Iterator<Entry<Thread, StackTraceElement[]>> entries = map.entrySet().iterator();
while (entries.hasNext()) {
Entry<Thread, StackTraceElement[]> entry = entries.next();
Thread thr = entry.getKey();
System.out.println(
"Thread " + thr.getName() + "(" + thr.getId() + ") Status: " + thr.getState().toString());
}
}

}, 10000);
}

public Plugin getPlugin() {
Expand Down Expand Up @@ -155,4 +138,19 @@ public boolean isDebug() {
public HashMap<Long, KeepAlivePacketGarbargeClean> getGarbargeCleanList() {
return garbargeCleanList;
}

/**
* @return the index
*/
public long getIndex() {
return index;
}

/**
* @return the index
*/
public long getCount() {
return count;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.TimerTask;

import org.bukkit.Bukkit;

import com.ishland.bukkit.AsyncKeepAlive.packet.KeepAlivePacket;
import com.ishland.bukkit.AsyncKeepAlive.packet.KeepAlivePacketFor1_12toLatest;
import com.ishland.bukkit.AsyncKeepAlive.packet.KeepAlivePacketGarbargeClean;
Expand All @@ -15,6 +17,7 @@ public void run() {
if (!getPlugin().getServer().getOnlinePlayers().isEmpty())
try {
KeepAlivePacket packet = new KeepAlivePacketFor1_12toLatest(getPlugin());
count += Bukkit.getOnlinePlayers().size();
packet.boardcast();
getPing().put(packet.getBody(), packet);
KeepAlivePacketGarbargeClean gc = new KeepAlivePacketGarbargeClean(getPing(), packet.getBody(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.TimerTask;

import org.bukkit.Bukkit;

import com.ishland.bukkit.AsyncKeepAlive.packet.KeepAlivePacket;
import com.ishland.bukkit.AsyncKeepAlive.packet.KeepAlivePacketFor1_7to1_11;
import com.ishland.bukkit.AsyncKeepAlive.packet.KeepAlivePacketGarbargeClean;
Expand All @@ -15,6 +17,7 @@ public void run() {
if (!getPlugin().getServer().getOnlinePlayers().isEmpty())
try {
KeepAlivePacket packet = new KeepAlivePacketFor1_7to1_11(getPlugin());
count += Bukkit.getOnlinePlayers().size();
packet.boardcast();
getPing().put(packet.getBody(), packet);
KeepAlivePacketGarbargeClean gc = new KeepAlivePacketGarbargeClean(getPing(), packet.getBody(),
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ author: ishland
description: AsyncKeepAlive is a plugin that keep the players' connections alive
depend: [ProtocolLib]
softdepend: [PlaceholderAPI]
commands:
asynckeepalive:
description: "The main command of AsyncKeepAlive"
usage: "[Error] Something went wrong"
aliases: [ak]

0 comments on commit e572070

Please sign in to comment.