Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = net.earthmc.emcapi
version = 3.1.0-SNAPSHOT
version = 4.0.0-SNAPSHOT
description = EMCAPI

org.gradle.configuration-cache=true
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/net/earthmc/emcapi/EMCAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import jakarta.servlet.http.HttpServletResponse;
import net.earthmc.emcapi.integration.Integrations;
import net.earthmc.emcapi.manager.EndpointManager;
import net.earthmc.emcapi.manager.LegacyEndpointManager;
import net.earthmc.emcapi.sse.SSEManager;
import net.earthmc.emcapi.sse.listeners.ShopSSEListener;
import net.earthmc.emcapi.sse.listeners.TownySSEListener;
Expand Down Expand Up @@ -47,8 +48,10 @@ public void onEnable() {
this.pluginIntegrations = new Integrations(this);
getServer().getPluginManager().registerEvents(this.pluginIntegrations, this);

EndpointManager endpointManager = new EndpointManager(this);
endpointManager.loadEndpoints();
if (getConfig().getBoolean("behavior.load_legacy")) {
new LegacyEndpointManager(this).loadEndpoints(); // Load retired endpoints and still serve current endpoints at /v3/aurora/
}
new EndpointManager(this).loadEndpoints();

PluginCommand apiCommand = getCommand("api");
if (apiCommand == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.earthmc.emcapi.util.EndpointUtils;
import net.earthmc.emcapi.util.HttpExceptions;
import net.earthmc.emcapi.util.JSONUtil;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;
import java.util.regex.Matcher;
Expand All @@ -21,7 +22,7 @@ public class DiscordEndpoint extends PostEndpoint<DiscordContext> {
private static final BadRequestResponse INVALID_TYPE_TARGET = new BadRequestResponse("Your JSON query has an invalid type or target");

@Override
public DiscordContext getObjectOrNull(JsonElement element) {
public DiscordContext getObjectOrNull(JsonElement element, @Nullable UUID key) {
JsonObject jsonObject = JSONUtil.getJsonElementAsJsonObjectOrNull(element);
if (jsonObject == null) {
throw HttpExceptions.NOT_A_JSON_OBJECT;
Expand Down Expand Up @@ -60,7 +61,7 @@ public DiscordContext getObjectOrNull(JsonElement element) {
}

@Override
public JsonElement getJsonElement(DiscordContext context) {
public JsonElement getJsonElement(DiscordContext context, @Nullable UUID key) {
DiscordType type = context.getType();
String target = context.getTarget();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
import net.earthmc.emcapi.util.JSONUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;

public class LocationEndpoint extends PostEndpoint<Pair<Integer, Integer>> {

@Override
public Pair<Integer, Integer> getObjectOrNull(JsonElement element) {
public Pair<Integer, Integer> getObjectOrNull(JsonElement element, @Nullable UUID key) {
JsonArray jsonArray = JSONUtil.getJsonElementAsJsonArrayOrNull(element);
if (jsonArray == null) throw new BadRequestResponse("Your query contains a value that is not a JSON array");

Expand All @@ -40,7 +43,7 @@ public Pair<Integer, Integer> getObjectOrNull(JsonElement element) {
}

@Override
public JsonElement getJsonElement(Pair<Integer, Integer> pair) {
public JsonElement getJsonElement(Pair<Integer, Integer> pair, @Nullable UUID key) {
int x = pair.getFirst();
int z = pair.getSecond();

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/net/earthmc/emcapi/endpoint/NearbyEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
import net.earthmc.emcapi.util.JSONUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class NearbyEndpoint extends PostEndpoint<NearbyContext> {

@Override
public NearbyContext getObjectOrNull(JsonElement element) {
public NearbyContext getObjectOrNull(JsonElement element, @Nullable UUID key) {
JsonObject jsonObject = JSONUtil.getJsonElementAsJsonObjectOrNull(element);
if (jsonObject == null) throw new BadRequestResponse("Your query contains a value that is not a JSON object");

Expand Down Expand Up @@ -64,7 +66,7 @@ public NearbyContext getObjectOrNull(JsonElement element) {
}

@Override
public JsonElement getJsonElement(NearbyContext context) {
public JsonElement getJsonElement(NearbyContext context, @Nullable UUID key) {
NearbyType targetType = context.getTargetType();
int radius = context.getRadius();
switch (targetType) {
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/net/earthmc/emcapi/endpoint/ShopEndpoint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package net.earthmc.emcapi.endpoint;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.javalin.http.BadRequestResponse;
import net.earthmc.emcapi.EMCAPI;
import net.earthmc.emcapi.integration.QuickShopIntegration;
import net.earthmc.emcapi.object.endpoint.PostEndpoint;
import net.earthmc.emcapi.util.EndpointUtils;
import net.earthmc.emcapi.util.JSONUtil;
import org.jetbrains.annotations.Nullable;
import org.maxgamer.quickshop.api.shop.Shop;

import java.util.List;
import java.util.UUID;

public class ShopEndpoint extends PostEndpoint<List<Shop>> {
private final QuickShopIntegration integration;

public ShopEndpoint(EMCAPI plugin) {
this.integration = plugin.integrations().quickShopIntegration();
}

@Override
public List<Shop> getObjectOrNull(JsonElement element, @Nullable UUID key) {
String string = JSONUtil.getJsonElementAsStringOrNull(element);
if (string == null) throw new BadRequestResponse("Your query contains a value that is not a string");

UUID player;
try {
player = UUID.fromString(string);
} catch (IllegalArgumentException ignored) {
return null;
}

integration.throwIfDisabled();
return integration.getPlayerShops(player, key);
}

@Override
public JsonElement getJsonElement(List<Shop> object, @Nullable UUID key) {
JsonObject shopsObject = new JsonObject();
int counter = 1;
UUID keyOwner = EndpointUtils.getKeyOwner(key);
for (Shop shop : object) {
if (!shop.getOwner().equals(keyOwner)) continue;
shopsObject.add(String.valueOf(counter++), EndpointUtils.getShopObject(shop));
}

return shopsObject;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.earthmc.emcapi.endpoint;
package net.earthmc.emcapi.endpoint.legacy;

import com.google.gson.JsonObject;
import net.earthmc.emcapi.object.endpoint.GetEndpoint;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.earthmc.emcapi.endpoint;
package net.earthmc.emcapi.endpoint.legacy;

public class MudkipEndpoint {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.earthmc.emcapi.endpoint;
package net.earthmc.emcapi.endpoint.legacy;

import com.google.gson.JsonObject;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
Expand All @@ -16,7 +16,6 @@
import java.nio.file.StandardOpenOption;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class PlayerStatsEndpoint {
private final EMCAPI plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
import net.earthmc.emcapi.object.endpoint.PostEndpoint;
import net.earthmc.emcapi.util.EndpointUtils;
import net.earthmc.emcapi.util.JSONUtil;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.UUID;

public class NationsEndpoint extends PostEndpoint<Nation> {

@Override
public Nation getObjectOrNull(JsonElement element) {
public Nation getObjectOrNull(JsonElement element, @Nullable UUID key) {
String string = JSONUtil.getJsonElementAsStringOrNull(element);
if (string == null) throw new BadRequestResponse("Your query contains a value that is not a string");

Expand All @@ -34,7 +35,7 @@ public Nation getObjectOrNull(JsonElement element) {
}

@Override
public JsonElement getJsonElement(Nation nation) {
public JsonElement getJsonElement(Nation nation, @Nullable UUID key) {
JsonObject nationObject = new JsonObject();

nationObject.addProperty("name", nation.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
import net.earthmc.emcapi.object.endpoint.PostEndpoint;
import net.earthmc.emcapi.util.EndpointUtils;
import net.earthmc.emcapi.util.JSONUtil;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.UUID;

public class PlayersEndpoint extends PostEndpoint<Resident> {

@Override
public Resident getObjectOrNull(JsonElement element) {
public Resident getObjectOrNull(JsonElement element, @Nullable UUID key) {
String string = JSONUtil.getJsonElementAsStringOrNull(element);
if (string == null) throw new BadRequestResponse("Your query contains a value that is not a string");

Expand All @@ -28,15 +29,17 @@ public Resident getObjectOrNull(JsonElement element) {
resident = TownyAPI.getInstance().getResident(string);
}

if (resident != null && EndpointUtils.playerOptedOut(resident.getUUID())) {
if (resident != null && EndpointUtils.playerOptedOut(resident.getUUID())
&& !resident.getUUID().equals(EndpointUtils.getKeyOwner(key))
) {
return null;
}

return resident;
}

@Override
public JsonElement getJsonElement(Resident resident) {
public JsonElement getJsonElement(Resident resident, @Nullable UUID key) {
JsonObject playerObject = new JsonObject();

playerObject.addProperty("name", resident.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
import net.earthmc.emcapi.util.EndpointUtils;
import net.earthmc.emcapi.util.JSONUtil;
import org.bukkit.Location;
import org.jetbrains.annotations.Nullable;

import java.awt.*;
import java.util.UUID;

public class QuartersEndpoint extends PostEndpoint<Quarter> {

@Override
public Quarter getObjectOrNull(JsonElement element) {
public Quarter getObjectOrNull(JsonElement element, @Nullable UUID key) {
String string = JSONUtil.getJsonElementAsStringOrNull(element);
if (string == null) throw new BadRequestResponse("Your query contains a value that is not a string");

Expand All @@ -33,7 +34,7 @@ public Quarter getObjectOrNull(JsonElement element) {
}

@Override
public JsonElement getJsonElement(Quarter quarter) {
public JsonElement getJsonElement(Quarter quarter, @Nullable UUID key) {
JsonObject quarterObject = new JsonObject();

quarterObject.addProperty("name", quarter.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.earthmc.emcapi.object.endpoint.PostEndpoint;
import net.earthmc.emcapi.util.EndpointUtils;
import net.earthmc.emcapi.util.JSONUtil;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;

Expand All @@ -26,7 +27,7 @@ public TownsEndpoint(EMCAPI plugin) {
}

@Override
public Town getObjectOrNull(JsonElement element) {
public Town getObjectOrNull(JsonElement element, @Nullable UUID key) {
String string = JSONUtil.getJsonElementAsStringOrNull(element);
if (string == null) throw new BadRequestResponse("Your query contains a value that is not a string");

Expand All @@ -41,7 +42,7 @@ public Town getObjectOrNull(JsonElement element) {
}

@Override
public JsonElement getJsonElement(Town town) {
public JsonElement getJsonElement(Town town, @Nullable UUID key) {
JsonObject townObject = new JsonObject();

townObject.addProperty("name", town.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Integrations implements Listener {
private final QuartersIntegration quartersIntegration;
private final SuperbVoteIntegration superbVoteIntegration;
private final MysteryMasterIntegration mysteryMasterIntegration;
private final QuickShopIntegration quickShopIntegration;

public Integrations(final EMCAPI plugin) {
this.plugin = plugin;
Expand All @@ -25,6 +26,7 @@ public Integrations(final EMCAPI plugin) {
this.quartersIntegration = addIntegration(new QuartersIntegration());
this.superbVoteIntegration = addIntegration(new SuperbVoteIntegration());
this.mysteryMasterIntegration = addIntegration(new MysteryMasterIntegration());
this.quickShopIntegration = addIntegration(new QuickShopIntegration());
}

private <T extends Integration> T addIntegration(final T integration) {
Expand All @@ -50,6 +52,10 @@ public MysteryMasterIntegration mysteryMasterIntegration() {
return this.mysteryMasterIntegration;
}

public QuickShopIntegration quickShopIntegration() {
return quickShopIntegration;
}

@EventHandler
public void onPluginEnable(final PluginEnableEvent event) {
final Integration integration = integrations.get(event.getPlugin().getName());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.earthmc.emcapi.integration;

import net.earthmc.emcapi.util.EndpointUtils;
import org.maxgamer.quickshop.QuickShop;
import org.maxgamer.quickshop.api.shop.Shop;

import java.util.List;
import java.util.UUID;

public class QuickShopIntegration extends Integration {

public QuickShopIntegration() {
super("QuickShop");
}

public List<Shop> getPlayerShops(UUID player, UUID key) {
if (!isEnabled()) {
return List.of();
}
if (!player.equals(EndpointUtils.getKeyOwner(key))) {
return List.of();
}
return QuickShop.getInstance().getShopManager().getPlayerAllShops(player);
}
}
Loading