Utilise the new Prism API (#101)

* Start changes to use the new Prism API

Currently, the Prism API doesn't support rollback so pushing the changes until such time the API allows you to rollback and/or restore modifications

* Modified the API to use the new modification services

* Only rollback activities that has occurred in previous 24 hours upon ban

* code formatting [skip-ci]
This commit is contained in:
Nathan Curran
2026-05-18 06:03:45 +10:00
committed by GitHub
parent ab26f707d8
commit c4bd65e7e0
4 changed files with 46 additions and 29 deletions
@@ -14,8 +14,10 @@ import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import dev.plex.util.TimeUtils;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -26,6 +28,9 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.prism_mc.prism.api.activities.ActivityQuery;
import org.prism_mc.prism.paper.api.PrismPaperApi;
import org.prism_mc.prism.paper.api.activities.PaperActivityQuery;
@CommandParameters(name = "ban", usage = "/<command> <player> [reason] [-rb]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online")
@CommandPermissions(permission = "plex.ban", source = RequiredCommandSource.ANY)
@@ -90,33 +95,38 @@ public class BanCMD extends PlexCommand
if (rollBack)
{
/*if (plugin.getPrismHook() != null && plugin.getPrismHook().hasPrism())
if (plugin.getPrismHook() != null && plugin.getPrismHook().hasPrism())
{
PrismParameters parameters = plugin.getPrismHook().prismApi().createParameters();
parameters.addActionType("block-place");
parameters.addActionType("block-break");
parameters.addActionType("block-burn");
parameters.addActionType("entity-spawn");
parameters.addActionType("entity-kill");
parameters.addActionType("entity-explode");
parameters.addPlayerName(plexPlayer.getName());
parameters.setBeforeTime(Instant.now().toEpochMilli());
parameters.setProcessType(PrismProcessType.ROLLBACK);
final Future<Result> result = plugin.getPrismHook().prismApi().performLookup(parameters, sender);
Bukkit.getAsyncScheduler().runNow(plugin, scheduledTask ->
PrismPaperApi prism = plugin.getPrismHook().getPrism();
ActivityQuery query = PaperActivityQuery.builder()
.actionTypeKeys(Arrays.asList("block-place", "block-break", "block-burn", "entity-spawn", "entity-kill", "entity-explode"))
.causePlayerName(plexPlayer.getName())
.before(Instant.now().getEpochSecond())
.after(Instant.now().getEpochSecond() - 86400)
.rollback()
.build();
prism.rollback(sender, query).whenCompleteAsync((result, error) ->
{
try
if (error != null)
{
final Result done = result.get();
send(sender, messageComponent("prismRollbackError", error.getMessage()));
PlexLog.error("Unable to rollback: {0}", error);
return;
}
catch (InterruptedException | ExecutionException e)
int count = result.applied();
if (count == 0)
{
throw new RuntimeException(e);
send(sender, messageComponent("prismNoResult", count));
PlexLog.debug("No activities are available to rollback");
return;
}
send(sender, messageComponent("prismRollbackMessage", count));
PlexLog.debug("Rolled back {0} activities", count);
});
}
else */
if (plugin.getCoreProtectHook() != null && plugin.getCoreProtectHook().hasCoreProtect())
else if (plugin.getCoreProtectHook() != null && plugin.getCoreProtectHook().hasCoreProtect())
{
Bukkit.getAsyncScheduler().runNow(plugin, scheduledTask ->
{
@@ -1,12 +1,14 @@
package dev.plex.hook;
import dev.plex.Plex;
import network.darkhelmet.prism.api.PrismApi;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.prism_mc.prism.paper.api.PrismPaperApi;
public class PrismHook
{
private PrismApi prismApi;
private RegisteredServiceProvider<PrismPaperApi> provider;
public PrismHook(Plex plex)
{
@@ -18,18 +20,17 @@ public class PrismHook
return;
}
// Check that the API is enabled
this.prismApi = (PrismApi) plugin;
provider = Bukkit.getServicesManager().getRegistration(PrismPaperApi.class);
}
public boolean hasPrism()
{
return prismApi != null;
return provider != null;
}
public PrismApi prismApi()
public PrismPaperApi getPrism()
{
return prismApi;
return provider.getProvider();
}
}
+6 -1
View File
@@ -279,4 +279,9 @@ reappliedGamerules: "<aqua>All game rules have been re-applied!"
commandNotFound: "<red>That command could not be found!"
# 0 - The command
# 1 - A list of aliases found
commandAliases: "<aqua>Aliases for {0} are: {1}"
commandAliases: "<aqua>Aliases for {0} are: {1}"
# 0 - Number of activities found to rollback
prismRollbackMessage: "<gray>Rolled back {0} activities"
# 0 - Error message returned from Prism
prismRollbackError: "<red>Rollback failed: {0}"
prismNoResult: "<gray>No activities have been rolled back"