Improved WorldEdit logging and added compatibility with FAWE

This commit is contained in:
Intelli 2022-02-15 16:47:50 -07:00
parent a2353afd0a
commit d9eea32b19
2 changed files with 33 additions and 38 deletions

View File

@ -25,48 +25,47 @@ public class CoreProtectEditSessionEvent {
}
public static void register() {
try {
if (isInitialized()) {
return;
}
if (isInitialized()) {
return;
}
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
try {
WorldEdit.getInstance().getEventBus().register(event);
initialized = true;
ConfigHandler.worldeditEnabled = true;
Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, "WorldEdit", Selector.FIRST));
}
catch (Exception e) {
Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, "WorldEdit", Selector.FIRST));
}
}, 0);
try {
WorldEdit.getInstance().getEventBus().register(event);
initialized = true;
ConfigHandler.worldeditEnabled = true;
}
catch (Exception e) {
e.printStackTrace();
// Failed to initialize WorldEdit logging
}
Bukkit.getServer().getScheduler().runTask(CoreProtect.getInstance(), () -> {
try {
if (isInitialized()) {
Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, "WorldEdit", Selector.FIRST));
}
else {
Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, "WorldEdit", Selector.FIRST));
}
}
catch (Exception e) {
e.printStackTrace();
}
});
}
public static void unregister() {
try {
if (!isInitialized()) {
return;
}
if (!isInitialized()) {
return;
}
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
try {
WorldEdit.getInstance().getEventBus().unregister(event);
initialized = false;
ConfigHandler.worldeditEnabled = false;
Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, "WorldEdit", Selector.SECOND));
}
catch (Exception e) {
Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, "WorldEdit", Selector.SECOND));
}
}, 0);
try {
WorldEdit.getInstance().getEventBus().unregister(event);
initialized = false;
ConfigHandler.worldeditEnabled = false;
Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, "WorldEdit", Selector.SECOND));
}
catch (Exception e) {
e.printStackTrace();
Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, "WorldEdit", Selector.SECOND));
}
}
@ -74,7 +73,7 @@ public class CoreProtectEditSessionEvent {
public void wrapForLogging(EditSessionEvent event) {
Actor actor = event.getActor();
World world = event.getWorld();
if (actor != null && event.getStage() == Stage.BEFORE_CHANGE) {
if (actor != null && event.getStage() == Stage.BEFORE_HISTORY) {
event.setExtent(new CoreProtectLogger(actor, world, event.getExtent()));
}
}

View File

@ -6,7 +6,6 @@ import org.bukkit.inventory.ItemStack;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
@ -34,10 +33,7 @@ public class CoreProtectLogger extends AbstractDelegateExtent {
@Override
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException {
if (!(eventWorld instanceof BukkitWorld)) {
return eventExtent.setBlock(position, block);
}
org.bukkit.World world = ((BukkitWorld) eventWorld).getWorld();
org.bukkit.World world = BukkitAdapter.adapt(eventWorld);
if (!Config.getConfig(world).WORLDEDIT) {
return eventExtent.setBlock(position, block);
}