geforkt von Mirrors/Velocity
Merge branch 'master' into merged
Dieser Commit ist enthalten in:
Commit
50316f2f1c
@ -101,9 +101,6 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
|
|||||||
queryResponse.writeByte(QUERY_TYPE_STAT);
|
queryResponse.writeByte(QUERY_TYPE_STAT);
|
||||||
queryResponse.writeInt(sessionId);
|
queryResponse.writeInt(sessionId);
|
||||||
|
|
||||||
// Fetch information
|
|
||||||
Collection<Player> players = server.getAllPlayers();
|
|
||||||
|
|
||||||
// Start writing the response
|
// Start writing the response
|
||||||
ResponseWriter responseWriter = new ResponseWriter(queryResponse, queryMessage.readableBytes() == 0);
|
ResponseWriter responseWriter = new ResponseWriter(queryResponse, queryMessage.readableBytes() == 0);
|
||||||
responseWriter.write("hostname", ComponentSerializers.PLAIN.serialize(server.getConfiguration().getMotdComponent()));
|
responseWriter.write("hostname", ComponentSerializers.PLAIN.serialize(server.getConfiguration().getMotdComponent()));
|
||||||
@ -114,12 +111,14 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
|
|||||||
responseWriter.write("plugins", "");
|
responseWriter.write("plugins", "");
|
||||||
|
|
||||||
responseWriter.write("map", "Velocity");
|
responseWriter.write("map", "Velocity");
|
||||||
responseWriter.write("numplayers", players.size());
|
responseWriter.write("numplayers", server.getPlayerCount());
|
||||||
responseWriter.write("maxplayers", server.getConfiguration().getShowMaxPlayers());
|
responseWriter.write("maxplayers", server.getConfiguration().getShowMaxPlayers());
|
||||||
responseWriter.write("hostport", server.getConfiguration().getBind().getPort());
|
responseWriter.write("hostport", server.getConfiguration().getBind().getPort());
|
||||||
responseWriter.write("hostip", server.getConfiguration().getBind().getHostString());
|
responseWriter.write("hostip", server.getConfiguration().getBind().getHostString());
|
||||||
|
|
||||||
responseWriter.writePlayers(players);
|
if (!responseWriter.isBasic) {
|
||||||
|
responseWriter.writePlayers(server.getAllPlayers());
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,6 +131,8 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
|
|||||||
ctx.writeAndFlush(responsePacket);
|
ctx.writeAndFlush(responsePacket);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.warn("Error while trying to handle a query packet from {}", msg.sender(), e);
|
logger.warn("Error while trying to handle a query packet from {}", msg.sender(), e);
|
||||||
|
// NB: Only need to explicitly release upon exception, writing the response out will decrement the reference
|
||||||
|
// count.
|
||||||
responsePacket.release();
|
responsePacket.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,69 +91,17 @@ public class VelocityScheduler implements Scheduler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ScheduledTask schedule() {
|
public ScheduledTask schedule() {
|
||||||
if (delay == 0 && repeat == 0) {
|
|
||||||
// A special purpose, simplified implementation
|
|
||||||
VelocityImmediatelyScheduledTask task = new VelocityImmediatelyScheduledTask(plugin, runnable);
|
|
||||||
tasksByPlugin.put(plugin, task);
|
|
||||||
taskService.execute(task);
|
|
||||||
return task;
|
|
||||||
} else {
|
|
||||||
VelocityTask task = new VelocityTask(plugin, runnable, delay, repeat);
|
VelocityTask task = new VelocityTask(plugin, runnable, delay, repeat);
|
||||||
tasksByPlugin.put(plugin, task);
|
tasksByPlugin.put(plugin, task);
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private class VelocityImmediatelyScheduledTask implements ScheduledTask, Runnable {
|
|
||||||
private final Object plugin;
|
|
||||||
private final Runnable runnable;
|
|
||||||
private final AtomicReference<TaskStatus> status;
|
|
||||||
private Thread taskThread;
|
|
||||||
|
|
||||||
private VelocityImmediatelyScheduledTask(Object plugin, Runnable runnable) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.runnable = runnable;
|
|
||||||
this.status = new AtomicReference<>(TaskStatus.SCHEDULED);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object plugin() {
|
|
||||||
return plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TaskStatus status() {
|
|
||||||
return status.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cancel() {
|
|
||||||
if (status.compareAndSet(TaskStatus.SCHEDULED, TaskStatus.CANCELLED)) {
|
|
||||||
if (taskThread != null) {
|
|
||||||
taskThread.interrupt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
taskThread = Thread.currentThread();
|
|
||||||
try {
|
|
||||||
runnable.run();
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.logger.error("Exception in task {} by plugin {}", runnable, plugin);
|
|
||||||
}
|
|
||||||
status.compareAndSet(TaskStatus.SCHEDULED, TaskStatus.FINISHED);
|
|
||||||
taskThread = null;
|
|
||||||
tasksByPlugin.remove(plugin, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class VelocityTask implements Runnable, ScheduledTask {
|
private class VelocityTask implements Runnable, ScheduledTask {
|
||||||
private final Object plugin;
|
private final Object plugin;
|
||||||
private final Runnable runnable;
|
private final Runnable runnable;
|
||||||
private ScheduledFuture<?> future;
|
private ScheduledFuture<?> future;
|
||||||
|
private volatile Thread currentTaskThread;
|
||||||
|
|
||||||
private VelocityTask(Object plugin, Runnable runnable, long delay, long repeat) {
|
private VelocityTask(Object plugin, Runnable runnable, long delay, long repeat) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -191,6 +139,12 @@ public class VelocityScheduler implements Scheduler {
|
|||||||
public void cancel() {
|
public void cancel() {
|
||||||
if (future != null) {
|
if (future != null) {
|
||||||
future.cancel(false);
|
future.cancel(false);
|
||||||
|
|
||||||
|
Thread cur = currentTaskThread;
|
||||||
|
if (cur != null) {
|
||||||
|
cur.interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
onFinish();
|
onFinish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -198,6 +152,7 @@ public class VelocityScheduler implements Scheduler {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
taskService.execute(() -> {
|
taskService.execute(() -> {
|
||||||
|
currentTaskThread = Thread.currentThread();
|
||||||
try {
|
try {
|
||||||
runnable.run();
|
runnable.run();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -208,6 +163,7 @@ public class VelocityScheduler implements Scheduler {
|
|||||||
Log.logger.error("Exception in task {} by plugin {}", runnable, plugin);
|
Log.logger.error("Exception in task {} by plugin {}", runnable, plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
currentTaskThread = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren