Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
Etzelia | c459ca8066 | |
Etzelia | 055672468d | |
Etzelia | 6f094c6dd4 |
|
@ -9,7 +9,6 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import xyz.etztech.serverapi.commands.MainCommand;
|
import xyz.etztech.serverapi.commands.MainCommand;
|
||||||
import xyz.etztech.serverapi.listeners.AsyncPlayerChatListener;
|
|
||||||
import xyz.etztech.serverapi.token.TokenList;
|
import xyz.etztech.serverapi.token.TokenList;
|
||||||
import xyz.etztech.serverapi.tps.TPS;
|
import xyz.etztech.serverapi.tps.TPS;
|
||||||
import xyz.etztech.serverapi.web.IProvider;
|
import xyz.etztech.serverapi.web.IProvider;
|
||||||
|
@ -26,8 +25,6 @@ public class ServerAPI extends JavaPlugin implements IProvider {
|
||||||
private Web web = new Web(this);
|
private Web web = new Web(this);
|
||||||
private final Logger log = Logger.getLogger( "Minecraft" );
|
private final Logger log = Logger.getLogger( "Minecraft" );
|
||||||
|
|
||||||
private static final List<ChatAPI> chat = new ArrayList<>();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
instance = this;
|
||||||
|
@ -36,7 +33,6 @@ public class ServerAPI extends JavaPlugin implements IProvider {
|
||||||
reloadConfig();
|
reloadConfig();
|
||||||
|
|
||||||
if (isEnabled()) {
|
if (isEnabled()) {
|
||||||
new AsyncPlayerChatListener(this);
|
|
||||||
new MainCommand(this);
|
new MainCommand(this);
|
||||||
|
|
||||||
tps = new TPS();
|
tps = new TPS();
|
||||||
|
@ -72,10 +68,6 @@ public class ServerAPI extends JavaPlugin implements IProvider {
|
||||||
return tps;
|
return tps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<ChatAPI> getChat() {
|
|
||||||
return chat;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TPSAPI TPS() {
|
public TPSAPI TPS() {
|
||||||
return new TPSAPI(tps.getHistory());
|
return new TPSAPI(tps.getHistory());
|
||||||
|
@ -118,18 +110,11 @@ public class ServerAPI extends JavaPlugin implements IProvider {
|
||||||
return bans;
|
return bans;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ChatAPI> chat() {
|
|
||||||
return chat;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void kick(BanAPI kick) {
|
public void kick(BanAPI kick) {
|
||||||
Player player = Bukkit.getPlayerExact(kick.getTarget());
|
Player player = Bukkit.getPlayerExact(kick.getTarget());
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
getServer().getScheduler().runTask(this, () -> {
|
player.kickPlayer("You have been kicked: " + kick.getReason());
|
||||||
player.kickPlayer("You have been kicked: " + kick.getReason());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,9 +127,7 @@ public class ServerAPI extends JavaPlugin implements IProvider {
|
||||||
Bukkit.getBanList(BanList.Type.NAME).addBan(ban.getTarget(), ban.getReason(), expires, "ServerAPI");
|
Bukkit.getBanList(BanList.Type.NAME).addBan(ban.getTarget(), ban.getReason(), expires, "ServerAPI");
|
||||||
Player player = Bukkit.getPlayerExact(ban.getTarget());
|
Player player = Bukkit.getPlayerExact(ban.getTarget());
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
getServer().getScheduler().runTask(this, () -> {
|
player.kickPlayer("You have been banned: " + ban.getReason());
|
||||||
player.kickPlayer("You have been banned: " + ban.getReason());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
package xyz.etztech.serverapi.listeners;
|
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
||||||
import xyz.etztech.serverapi.ServerAPI;
|
|
||||||
import xyz.etztech.serverapi.web.api.ChatAPI;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class AsyncPlayerChatListener implements Listener {
|
|
||||||
private final ServerAPI plugin;
|
|
||||||
|
|
||||||
public AsyncPlayerChatListener(ServerAPI plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority= EventPriority.MONITOR, ignoreCancelled=true)
|
|
||||||
public void onChat(AsyncPlayerChatEvent event) {
|
|
||||||
int chatLimit = plugin.getConfig().getInt("chat", 100);
|
|
||||||
if (ServerAPI.getChat().size() >= chatLimit) {
|
|
||||||
ServerAPI.getChat().remove(0);
|
|
||||||
}
|
|
||||||
ServerAPI.getChat().add(new ChatAPI(
|
|
||||||
String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage()),
|
|
||||||
new Date().getTime()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -45,9 +45,4 @@ public class GraphQL implements QueryGraphql {
|
||||||
public TPSAPI getTps() {
|
public TPSAPI getTps() {
|
||||||
return provider.TPS();
|
return provider.TPS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GraphQLName("chat")
|
|
||||||
public ChatAPI[] getChat() {
|
|
||||||
return provider.chat().toArray(new ChatAPI[0]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ public interface IProvider {
|
||||||
List<WorldAPI> worlds();
|
List<WorldAPI> worlds();
|
||||||
WorldAPI world(String name);
|
WorldAPI world(String name);
|
||||||
List<PluginAPI> plugins();
|
List<PluginAPI> plugins();
|
||||||
List<ChatAPI> chat();
|
|
||||||
|
|
||||||
// POST
|
// POST
|
||||||
void kick(BanAPI kick);
|
void kick(BanAPI kick);
|
||||||
|
|
|
@ -59,7 +59,6 @@ public class Web {
|
||||||
app.get("/tps", this::tps);
|
app.get("/tps", this::tps);
|
||||||
app.get("/worlds", this::worlds);
|
app.get("/worlds", this::worlds);
|
||||||
app.get("/worlds/:name", this::world);
|
app.get("/worlds/:name", this::world);
|
||||||
app.get("/chat", this::chat);
|
|
||||||
|
|
||||||
app.post("/kick", this::kick);
|
app.post("/kick", this::kick);
|
||||||
app.post("/ban", this::ban);
|
app.post("/ban", this::ban);
|
||||||
|
@ -136,10 +135,6 @@ public class Web {
|
||||||
ctx.json(provider.world(ctx.pathParam("name")));
|
ctx.json(provider.world(ctx.pathParam("name")));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void chat(Context ctx) {
|
|
||||||
ctx.json(provider.chat());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void players(Context ctx) {
|
public void players(Context ctx) {
|
||||||
ctx.json(provider.players());
|
ctx.json(provider.players());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
package xyz.etztech.serverapi.web.api;
|
|
||||||
|
|
||||||
import com.expediagroup.graphql.annotations.GraphQLDescription;
|
|
||||||
import com.expediagroup.graphql.annotations.GraphQLName;
|
|
||||||
|
|
||||||
@GraphQLName("Chat")
|
|
||||||
@GraphQLDescription("Chat GraphQL")
|
|
||||||
public class ChatAPI {
|
|
||||||
private final String message;
|
|
||||||
private final long timestamp;
|
|
||||||
|
|
||||||
public ChatAPI(String message, long timestamp) {
|
|
||||||
this.message = message;
|
|
||||||
this.timestamp = timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GraphQLName("message")
|
|
||||||
public String getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GraphQLName("timestamp")
|
|
||||||
public long getTimestamp() {
|
|
||||||
return timestamp;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +1,6 @@
|
||||||
# The port to run on
|
# The port to run on
|
||||||
port: 8080
|
port: 8080
|
||||||
|
|
||||||
# Number of chat logs to retain
|
|
||||||
chat: 100
|
|
||||||
|
|
||||||
# Authentication
|
# Authentication
|
||||||
auth:
|
auth:
|
||||||
# Protect GET routes. If false, GET routes are public.
|
# Protect GET routes. If false, GET routes are public.
|
||||||
|
|
|
@ -84,16 +84,6 @@ public class MockProvider implements IProvider {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<ChatAPI> chat() {
|
|
||||||
long now = new Date().getTime();
|
|
||||||
return Arrays.asList(
|
|
||||||
new ChatAPI("message 1", now-2),
|
|
||||||
new ChatAPI("message 2", now-1),
|
|
||||||
new ChatAPI("message 3", now)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void log(String message) {
|
public void log(String message) {
|
||||||
System.out.println(message);
|
System.out.println(message);
|
||||||
|
|
|
@ -5,6 +5,7 @@ import xyz.etztech.serverapi.token.TokenList;
|
||||||
import xyz.etztech.serverapi.token.TokenScope;
|
import xyz.etztech.serverapi.token.TokenScope;
|
||||||
import xyz.etztech.serverapi.web.Web;
|
import xyz.etztech.serverapi.web.Web;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue