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() { public static void register() {
try { if (isInitialized()) {
if (isInitialized()) { return;
return; }
}
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> { try {
try { WorldEdit.getInstance().getEventBus().register(event);
WorldEdit.getInstance().getEventBus().register(event); initialized = true;
initialized = true; ConfigHandler.worldeditEnabled = 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);
} }
catch (Exception e) { 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() { public static void unregister() {
try { if (!isInitialized()) {
if (!isInitialized()) { return;
return; }
}
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> { try {
try { WorldEdit.getInstance().getEventBus().unregister(event);
WorldEdit.getInstance().getEventBus().unregister(event); initialized = false;
initialized = false; ConfigHandler.worldeditEnabled = false;
ConfigHandler.worldeditEnabled = false; Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, "WorldEdit", Selector.SECOND));
Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, "WorldEdit", Selector.SECOND));
}
catch (Exception e) {
Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, "WorldEdit", Selector.SECOND));
}
}, 0);
} }
catch (Exception e) { 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) { public void wrapForLogging(EditSessionEvent event) {
Actor actor = event.getActor(); Actor actor = event.getActor();
World world = event.getWorld(); 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())); 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.WorldEditException;
import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
@ -34,10 +33,7 @@ public class CoreProtectLogger extends AbstractDelegateExtent {
@Override @Override
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException { public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException {
if (!(eventWorld instanceof BukkitWorld)) { org.bukkit.World world = BukkitAdapter.adapt(eventWorld);
return eventExtent.setBlock(position, block);
}
org.bukkit.World world = ((BukkitWorld) eventWorld).getWorld();
if (!Config.getConfig(world).WORLDEDIT) { if (!Config.getConfig(world).WORLDEDIT) {
return eventExtent.setBlock(position, block); return eventExtent.setBlock(position, block);
} }