Compare commits

..

3 Commits
master ... post

Author SHA1 Message Date
Etzelia c459ca8066
Add token auth and POST endpoints
Signed-off-by: Etzelia <etzelia@hotmail.com>
2020-10-04 15:52:06 -05:00
Etzelia 055672468d Change QueryAPI to PingAPI and add PluginAPI (#4)
typo

Fix null fields

Signed-off-by: Etzelia <etzelia@hotmail.com>

Change QueryAPI to PingAPI and add PluginAPI

Signed-off-by: Etzelia <etzelia@hotmail.com>

Reviewed-on: https://git.etztech.xyz/Minecraft/ServerAPI/pulls/4
Reviewed-by: ZeroHD <joey@ahines.net>
2020-08-12 02:43:42 +02:00
Etzelia 6f094c6dd4 Fix conflicting name (#3)
Fix conflicting name

Signed-off-by: Etzelia <etzelia@hotmail.com>

Reviewed-on: https://git.etztech.xyz/Minecraft/ServerAPI/pulls/3
2020-08-11 04:04:12 +02:00
9 changed files with 3 additions and 100 deletions

View File

@ -9,7 +9,6 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import xyz.etztech.serverapi.commands.MainCommand;
import xyz.etztech.serverapi.listeners.AsyncPlayerChatListener;
import xyz.etztech.serverapi.token.TokenList;
import xyz.etztech.serverapi.tps.TPS;
import xyz.etztech.serverapi.web.IProvider;
@ -26,8 +25,6 @@ public class ServerAPI extends JavaPlugin implements IProvider {
private Web web = new Web(this);
private final Logger log = Logger.getLogger( "Minecraft" );
private static final List<ChatAPI> chat = new ArrayList<>();
@Override
public void onEnable() {
instance = this;
@ -36,7 +33,6 @@ public class ServerAPI extends JavaPlugin implements IProvider {
reloadConfig();
if (isEnabled()) {
new AsyncPlayerChatListener(this);
new MainCommand(this);
tps = new TPS();
@ -72,10 +68,6 @@ public class ServerAPI extends JavaPlugin implements IProvider {
return tps;
}
public static List<ChatAPI> getChat() {
return chat;
}
@Override
public TPSAPI TPS() {
return new TPSAPI(tps.getHistory());
@ -118,18 +110,11 @@ public class ServerAPI extends JavaPlugin implements IProvider {
return bans;
}
@Override
public List<ChatAPI> chat() {
return chat;
}
@Override
public void kick(BanAPI kick) {
Player player = Bukkit.getPlayerExact(kick.getTarget());
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");
Player player = Bukkit.getPlayerExact(ban.getTarget());
if (player != null) {
getServer().getScheduler().runTask(this, () -> {
player.kickPlayer("You have been banned: " + ban.getReason());
});
player.kickPlayer("You have been banned: " + ban.getReason());
}
}

View File

@ -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()
));
}
}

View File

@ -45,9 +45,4 @@ public class GraphQL implements QueryGraphql {
public TPSAPI getTps() {
return provider.TPS();
}
@GraphQLName("chat")
public ChatAPI[] getChat() {
return provider.chat().toArray(new ChatAPI[0]);
}
}

View File

@ -15,7 +15,6 @@ public interface IProvider {
List<WorldAPI> worlds();
WorldAPI world(String name);
List<PluginAPI> plugins();
List<ChatAPI> chat();
// POST
void kick(BanAPI kick);

View File

@ -59,7 +59,6 @@ public class Web {
app.get("/tps", this::tps);
app.get("/worlds", this::worlds);
app.get("/worlds/:name", this::world);
app.get("/chat", this::chat);
app.post("/kick", this::kick);
app.post("/ban", this::ban);
@ -136,10 +135,6 @@ public class Web {
ctx.json(provider.world(ctx.pathParam("name")));
}
public void chat(Context ctx) {
ctx.json(provider.chat());
}
public void players(Context ctx) {
ctx.json(provider.players());
}

View File

@ -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;
}
}

View File

@ -1,9 +1,6 @@
# The port to run on
port: 8080
# Number of chat logs to retain
chat: 100
# Authentication
auth:
# Protect GET routes. If false, GET routes are public.

View File

@ -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
public void log(String message) {
System.out.println(message);

View File

@ -5,6 +5,7 @@ import xyz.etztech.serverapi.token.TokenList;
import xyz.etztech.serverapi.token.TokenScope;
import xyz.etztech.serverapi.web.Web;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;