mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-12-01 13:23:26 +01:00
Cleanup
This commit is contained in:
parent
42af5dc7a1
commit
5a49ef8447
@ -1,49 +1,42 @@
|
|||||||
package net.coreprotect.worldedit;
|
package net.coreprotect.worldedit;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import com.sk89q.worldedit.EditSession.Stage;
|
import com.sk89q.worldedit.EditSession.Stage;
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import com.sk89q.worldedit.event.extent.EditSessionEvent;
|
import com.sk89q.worldedit.event.extent.EditSessionEvent;
|
||||||
import com.sk89q.worldedit.util.eventbus.Subscribe;
|
import com.sk89q.worldedit.util.eventbus.Subscribe;
|
||||||
|
|
||||||
import net.coreprotect.CoreProtect;
|
import net.coreprotect.CoreProtect;
|
||||||
import net.coreprotect.config.ConfigHandler;
|
import net.coreprotect.config.ConfigHandler;
|
||||||
import net.coreprotect.language.Phrase;
|
import net.coreprotect.language.Phrase;
|
||||||
import net.coreprotect.language.Selector;
|
import net.coreprotect.language.Selector;
|
||||||
import net.coreprotect.thread.Scheduler;
|
import net.coreprotect.thread.Scheduler;
|
||||||
import net.coreprotect.utility.Chat;
|
import net.coreprotect.utility.Chat;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
public class CoreProtectEditSessionEvent
|
public class CoreProtectEditSessionEvent {
|
||||||
{
|
|
||||||
private static boolean initialized = false;
|
private static boolean initialized = false;
|
||||||
private static boolean isFAWE = false;
|
private static boolean isFAWE = false;
|
||||||
private static CoreProtectEditSessionEvent event = new CoreProtectEditSessionEvent();
|
private static CoreProtectEditSessionEvent event = new CoreProtectEditSessionEvent();
|
||||||
|
|
||||||
public static boolean isInitialized()
|
public static boolean isInitialized() {
|
||||||
{
|
|
||||||
return initialized;
|
return initialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isFAWE()
|
public static boolean isFAWE() {
|
||||||
{
|
|
||||||
return isFAWE;
|
return isFAWE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void register()
|
public static void register() {
|
||||||
{
|
if (isInitialized()) {
|
||||||
if (isInitialized())
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
WorldEdit.getInstance().getEventBus().register(new Object() {
|
||||||
WorldEdit.getInstance().getEventBus().register(new Object()
|
|
||||||
{
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onEditSessionEvent(EditSessionEvent event)
|
public void onEditSessionEvent(EditSessionEvent event) {
|
||||||
{
|
if (event.getActor() != null && event.getStage() == Stage.BEFORE_CHANGE) {
|
||||||
if (event.getActor() != null && event.getStage() == Stage.BEFORE_CHANGE)
|
|
||||||
{
|
|
||||||
event.setExtent(new CoreProtectLogger(event.getActor(), event.getWorld(), event.getExtent()));
|
event.setExtent(new CoreProtectLogger(event.getActor(), event.getWorld(), event.getExtent()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,47 +45,37 @@ public class CoreProtectEditSessionEvent
|
|||||||
ConfigHandler.worldeditEnabled = true;
|
ConfigHandler.worldeditEnabled = true;
|
||||||
isFAWE = (Bukkit.getServer().getPluginManager().getPlugin("FastAsyncWorldEdit") != null);
|
isFAWE = (Bukkit.getServer().getPluginManager().getPlugin("FastAsyncWorldEdit") != null);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e) {
|
||||||
{
|
|
||||||
// Failed to initialize WorldEdit logging
|
// Failed to initialize WorldEdit logging
|
||||||
}
|
}
|
||||||
|
|
||||||
Scheduler.runTask(CoreProtect.getInstance(), () ->
|
Scheduler.runTask(CoreProtect.getInstance(), () -> {
|
||||||
{
|
try {
|
||||||
try
|
if (isInitialized()) {
|
||||||
{
|
|
||||||
if (isInitialized())
|
|
||||||
{
|
|
||||||
Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.FIRST));
|
Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.FIRST));
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.FIRST));
|
Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.FIRST));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e) {
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void unregister()
|
public static void unregister() {
|
||||||
{
|
if (!isInitialized()) {
|
||||||
if (!isInitialized())
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.SECOND));
|
Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.SECOND));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e) {
|
||||||
{
|
|
||||||
Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.SECOND));
|
Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.SECOND));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package net.coreprotect.worldedit;
|
package net.coreprotect.worldedit;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
@ -14,20 +18,16 @@ import com.sk89q.worldedit.world.World;
|
|||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
|
|
||||||
import net.coreprotect.config.Config;
|
import net.coreprotect.config.Config;
|
||||||
import net.coreprotect.utility.Util;
|
import net.coreprotect.utility.Util;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
public class CoreProtectLogger extends AbstractDelegateExtent
|
public class CoreProtectLogger extends AbstractDelegateExtent {
|
||||||
{
|
|
||||||
private final Actor eventActor;
|
private final Actor eventActor;
|
||||||
private final World eventWorld;
|
private final World eventWorld;
|
||||||
private final Extent eventExtent;
|
private final Extent eventExtent;
|
||||||
|
|
||||||
protected CoreProtectLogger(Actor actor, World world, Extent extent)
|
protected CoreProtectLogger(Actor actor, World world, Extent extent) {
|
||||||
{
|
|
||||||
super(extent);
|
super(extent);
|
||||||
this.eventActor = actor;
|
this.eventActor = actor;
|
||||||
this.eventWorld = world;
|
this.eventWorld = world;
|
||||||
@ -35,17 +35,13 @@ 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 {
|
||||||
{
|
|
||||||
org.bukkit.World world = BukkitAdapter.adapt(eventWorld);
|
org.bukkit.World world = BukkitAdapter.adapt(eventWorld);
|
||||||
if (!Config.getConfig(world).WORLDEDIT)
|
if (!Config.getConfig(world).WORLDEDIT) {
|
||||||
{
|
if (CoreProtectEditSessionEvent.isFAWE()) {
|
||||||
if (CoreProtectEditSessionEvent.isFAWE())
|
|
||||||
{
|
|
||||||
return eventExtent.setBlock(position.getX(), position.getY(), position.getZ(), block);
|
return eventExtent.setBlock(position.getX(), position.getY(), position.getZ(), block);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
return eventExtent.setBlock(position, block);
|
return eventExtent.setBlock(position, block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,18 +56,14 @@ public class CoreProtectLogger extends AbstractDelegateExtent
|
|||||||
// e.g. BaseBlock block = eventWorld.getBlock(position);
|
// e.g. BaseBlock block = eventWorld.getBlock(position);
|
||||||
ItemStack[] containerData = CoreProtectEditSessionEvent.isFAWE() ? null : Util.getContainerContents(oldType, null, location);
|
ItemStack[] containerData = CoreProtectEditSessionEvent.isFAWE() ? null : Util.getContainerContents(oldType, null, location);
|
||||||
|
|
||||||
if (CoreProtectEditSessionEvent.isFAWE())
|
if (CoreProtectEditSessionEvent.isFAWE()) {
|
||||||
{
|
if (eventExtent.setBlock(position.getX(), position.getY(), position.getZ(), block)) {
|
||||||
if (eventExtent.setBlock(position.getX(), position.getY(), position.getZ(), block))
|
|
||||||
{
|
|
||||||
WorldEditLogger.postProcess(eventExtent, eventActor, position, location, block, baseBlock, oldType, oldBlock, containerData);
|
WorldEditLogger.postProcess(eventExtent, eventActor, position, location, block, baseBlock, oldType, oldBlock, containerData);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
if (eventExtent.setBlock(position, block)) {
|
||||||
if (eventExtent.setBlock(position, block))
|
|
||||||
{
|
|
||||||
WorldEditLogger.postProcess(eventExtent, eventActor, position, location, block, baseBlock, oldType, oldBlock, containerData);
|
WorldEditLogger.postProcess(eventExtent, eventActor, position, location, block, baseBlock, oldType, oldBlock, containerData);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -81,17 +73,14 @@ public class CoreProtectLogger extends AbstractDelegateExtent
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block) throws WorldEditException
|
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block) throws WorldEditException {
|
||||||
{
|
|
||||||
return this.setBlock(BlockVector3.at(x, y, z), block);
|
return this.setBlock(BlockVector3.at(x, y, z), block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int replaceBlocks(final Region region, final Mask mask, final Pattern pattern) throws MaxChangedBlocksException
|
public int replaceBlocks(final Region region, final Mask mask, final Pattern pattern) throws MaxChangedBlocksException {
|
||||||
{
|
|
||||||
org.bukkit.World world = BukkitAdapter.adapt(eventWorld);
|
org.bukkit.World world = BukkitAdapter.adapt(eventWorld);
|
||||||
if (!Config.getConfig(world).WORLDEDIT)
|
if (!Config.getConfig(world).WORLDEDIT) {
|
||||||
{
|
|
||||||
return eventExtent.replaceBlocks(region, mask, pattern);
|
return eventExtent.replaceBlocks(region, mask, pattern);
|
||||||
}
|
}
|
||||||
processPatternToBlocks(world, region, pattern);
|
processPatternToBlocks(world, region, pattern);
|
||||||
@ -99,21 +88,17 @@ public class CoreProtectLogger extends AbstractDelegateExtent
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException
|
public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
||||||
{
|
|
||||||
org.bukkit.World world = BukkitAdapter.adapt(eventWorld);
|
org.bukkit.World world = BukkitAdapter.adapt(eventWorld);
|
||||||
if (!Config.getConfig(world).WORLDEDIT)
|
if (!Config.getConfig(world).WORLDEDIT) {
|
||||||
{
|
|
||||||
return eventExtent.setBlocks(region, pattern);
|
return eventExtent.setBlocks(region, pattern);
|
||||||
}
|
}
|
||||||
processPatternToBlocks(world, region, pattern);
|
processPatternToBlocks(world, region, pattern);
|
||||||
return eventExtent.setBlocks(region, pattern);
|
return eventExtent.setBlocks(region, pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processPatternToBlocks(org.bukkit.World world, Region region, Pattern pattern)
|
private void processPatternToBlocks(org.bukkit.World world, Region region, Pattern pattern) {
|
||||||
{
|
for (BlockVector3 position : region.clone()) {
|
||||||
for (BlockVector3 position : region.clone())
|
|
||||||
{
|
|
||||||
BlockState oldBlock = eventExtent.getBlock(position);
|
BlockState oldBlock = eventExtent.getBlock(position);
|
||||||
Material oldType = BukkitAdapter.adapt(oldBlock.getBlockType());
|
Material oldType = BukkitAdapter.adapt(oldBlock.getBlockType());
|
||||||
Location location = new Location(world, position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
Location location = new Location(world, position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||||
|
Loading…
Reference in New Issue
Block a user