|
28 | 28 | import org.bukkit.entity.Player; |
29 | 29 | import org.jetbrains.annotations.NotNull; |
30 | 30 | import org.jetbrains.annotations.Nullable; |
31 | | -import org.prism_mc.prism.api.activities.Activity; |
32 | 31 | import org.prism_mc.prism.api.activities.ActivityQuery; |
33 | 32 | import org.prism_mc.prism.paper.api.PrismPaperApi; |
34 | 33 | import org.prism_mc.prism.paper.api.activities.PaperActivityQuery; |
@@ -99,24 +98,28 @@ protected Component execute(@NotNull CommandSender sender, @Nullable Player play |
99 | 98 | if (plugin.getPrismHook() != null && plugin.getPrismHook().hasPrism()) |
100 | 99 | { |
101 | 100 | PrismPaperApi prism = plugin.getPrismHook().getPrism(); |
102 | | - Bukkit.getAsyncScheduler().runNow(plugin, task -> |
103 | | - { |
104 | | - try |
105 | | - { |
106 | | - ActivityQuery query = PaperActivityQuery.builder() |
107 | | - .actionTypeKeys(Arrays.asList("block-place", "block-break", "block-burn", "entity-spawn", "entity-kill", "entity-explode")) |
108 | | - .causePlayerName(plexPlayer.getName()) |
109 | | - .before(Instant.now().getEpochSecond()) |
110 | | - .rollback() |
111 | | - .build(); |
112 | | - |
113 | | - List<Activity> activities = prism.storageAdapter().queryActivities(query); |
114 | | - PlexLog.debug("{0} activities have been rollback", activities.size()); |
| 101 | + ActivityQuery query = PaperActivityQuery.builder() |
| 102 | + .actionTypeKeys(Arrays.asList("block-place", "block-break", "block-burn", "entity-spawn", "entity-kill", "entity-explode")) |
| 103 | + .causePlayerName(plexPlayer.getName()) |
| 104 | + .before(Instant.now().getEpochSecond()) |
| 105 | + .rollback() |
| 106 | + .build(); |
| 107 | + prism.rollback(sender, query).whenCompleteAsync((result, error) -> { |
| 108 | + if (error != null) { |
| 109 | + send(sender, messageComponent("prismRollbackError", error.getMessage())); |
| 110 | + PlexLog.error("Unable to rollback: {0}", error); |
| 111 | + return; |
115 | 112 | } |
116 | | - catch (Exception ex) |
117 | | - { |
118 | | - PlexLog.error("Unable to query activities: {0}", ex); |
| 113 | + |
| 114 | + int count = result.applied(); |
| 115 | + if (count == 0) { |
| 116 | + send(sender, messageComponent("prismNoResult", count)); |
| 117 | + PlexLog.debug("No activities are available to rollback"); |
| 118 | + return; |
119 | 119 | } |
| 120 | + |
| 121 | + send(sender, messageComponent("prismRollbackMessage", count)); |
| 122 | + PlexLog.debug("Rolled back {0} activities", count); |
120 | 123 | }); |
121 | 124 | } |
122 | 125 | else if (plugin.getCoreProtectHook() != null && plugin.getCoreProtectHook().hasCoreProtect()) |
|
0 commit comments