mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-12-30 18:08:24 +01:00
Fix FAWE logging on newer builds (#528)
* Fix FAWE logging on newer builds * fix regular WE logging * Fix registering of FAWE for event bus * Remove jcenter * Add missing `replaceBlocks` method * Remove FAWE toggle entirely * oops, i can't do it that way --------- Co-authored-by: Intelli <6790859+Intelli@users.noreply.github.com>
This commit is contained in:
parent
dbb44ab5b9
commit
42af5dc7a1
12
build.gradle
12
build.gradle
@ -2,7 +2,7 @@ import org.apache.tools.ant.filters.ReplaceTokens
|
||||
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'com.github.johnrengelman.shadow' version '7.1.2'
|
||||
id 'com.github.johnrengelman.shadow' version '8.1.1'
|
||||
id 'com.palantir.git-version' version '0.13.0'
|
||||
}
|
||||
|
||||
@ -23,17 +23,15 @@ if (System.getenv("BUILD_NUMBER") != null) {
|
||||
logger.info("Building version $version")
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
maven { url = 'https://hub.spigotmc.org/nexus/content/groups/public/' }
|
||||
maven { url = 'https://papermc.io/repo/repository/maven-public/' }
|
||||
maven { url = 'https://repo.papermc.io/repository/maven-public/' }
|
||||
maven { url = 'https://repo.codemc.org/repository/maven-public/' }
|
||||
maven { url = 'https://maven.enginehub.org/repo/' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly('com.sk89q.worldedit:worldedit-bukkit:7.0.0-SNAPSHOT') {
|
||||
exclude group: 'org.bukkit'
|
||||
}
|
||||
implementation(platform("com.intellectualsites.bom:bom-newest:1.44")) // Ref: https://github.com/IntellectualSites/bom
|
||||
compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Core")
|
||||
compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit")
|
||||
compileOnly 'io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT'
|
||||
implementation 'org.bstats:bstats-bukkit-lite:1.8'
|
||||
implementation 'com.zaxxer:HikariCP:5.0.1'
|
||||
|
29
pom.xml
29
pom.xml
@ -88,11 +88,18 @@
|
||||
<id>codemc-repo</id>
|
||||
<url>https://repo.codemc.org/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>enginehub-repo</id>
|
||||
<url>https://maven.enginehub.org/repo/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.intellectualsites.bom</groupId>
|
||||
<artifactId>bom-newest</artifactId> <!-- Ref: https://github.com/IntellectualSites/bom -->
|
||||
<version>1.44</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<dependencies>
|
||||
<!--
|
||||
paper-api: io.papermc.paper
|
||||
@ -113,14 +120,18 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sk89q.worldedit</groupId>
|
||||
<artifactId>worldedit-bukkit</artifactId>
|
||||
<version>7.0.0-SNAPSHOT</version>
|
||||
<groupId>com.fastasyncworldedit</groupId>
|
||||
<artifactId>FastAsyncWorldEdit-Core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fastasyncworldedit</groupId>
|
||||
<artifactId>FastAsyncWorldEdit-Bukkit</artifactId>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<artifactId>FastAsyncWorldEdit-Core</artifactId>
|
||||
<groupId>*</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
@ -41,7 +41,6 @@ public class Config extends Language {
|
||||
public String MYSQL_USERNAME;
|
||||
public String MYSQL_PASSWORD;
|
||||
public String LANGUAGE;
|
||||
public boolean ENABLE_AWE;
|
||||
public boolean ENABLE_SSL;
|
||||
public boolean DISABLE_WAL;
|
||||
public boolean HOVER_EVENTS;
|
||||
@ -189,7 +188,6 @@ public class Config extends Language {
|
||||
}
|
||||
|
||||
private void readValues() {
|
||||
this.ENABLE_AWE = this.getBoolean("enable-awe", false);
|
||||
this.ENABLE_SSL = this.getBoolean("enable-ssl", false);
|
||||
this.DISABLE_WAL = this.getBoolean("disable-wal", false);
|
||||
this.HOVER_EVENTS = this.getBoolean("hover-events", true);
|
||||
|
@ -1,90 +1,99 @@
|
||||
package net.coreprotect.worldedit;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.sk89q.worldedit.EditSession.Stage;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.event.extent.EditSessionEvent;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.util.eventbus.Subscribe;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import net.coreprotect.CoreProtect;
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.language.Phrase;
|
||||
import net.coreprotect.language.Selector;
|
||||
import net.coreprotect.thread.Scheduler;
|
||||
import net.coreprotect.utility.Chat;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class CoreProtectEditSessionEvent {
|
||||
|
||||
public class CoreProtectEditSessionEvent
|
||||
{
|
||||
private static boolean initialized = false;
|
||||
private static boolean isFAWE = false;
|
||||
private static CoreProtectEditSessionEvent event = new CoreProtectEditSessionEvent();
|
||||
|
||||
public static boolean isInitialized() {
|
||||
public static boolean isInitialized()
|
||||
{
|
||||
return initialized;
|
||||
}
|
||||
|
||||
public static boolean isFAWE() {
|
||||
public static boolean isFAWE()
|
||||
{
|
||||
return isFAWE;
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
if (isInitialized()) {
|
||||
public static void register()
|
||||
{
|
||||
if (isInitialized())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("AsyncWorldEdit") == null || Config.getGlobal().ENABLE_AWE) {
|
||||
WorldEdit.getInstance().getEventBus().register(event);
|
||||
initialized = true;
|
||||
ConfigHandler.worldeditEnabled = true;
|
||||
isFAWE = (Bukkit.getServer().getPluginManager().getPlugin("FastAsyncWorldEdit") != null);
|
||||
}
|
||||
try
|
||||
{
|
||||
WorldEdit.getInstance().getEventBus().register(new Object()
|
||||
{
|
||||
@Subscribe
|
||||
public void onEditSessionEvent(EditSessionEvent event)
|
||||
{
|
||||
if (event.getActor() != null && event.getStage() == Stage.BEFORE_CHANGE)
|
||||
{
|
||||
event.setExtent(new CoreProtectLogger(event.getActor(), event.getWorld(), event.getExtent()));
|
||||
}
|
||||
}
|
||||
});
|
||||
initialized = true;
|
||||
ConfigHandler.worldeditEnabled = true;
|
||||
isFAWE = (Bukkit.getServer().getPluginManager().getPlugin("FastAsyncWorldEdit") != null);
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception e)
|
||||
{
|
||||
// Failed to initialize WorldEdit logging
|
||||
}
|
||||
|
||||
Scheduler.runTask(CoreProtect.getInstance(), () -> {
|
||||
try {
|
||||
if (isInitialized()) {
|
||||
Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, "WorldEdit", Selector.FIRST));
|
||||
Scheduler.runTask(CoreProtect.getInstance(), () ->
|
||||
{
|
||||
try
|
||||
{
|
||||
if (isInitialized())
|
||||
{
|
||||
Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.FIRST));
|
||||
}
|
||||
else {
|
||||
Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, "WorldEdit", Selector.FIRST));
|
||||
else
|
||||
{
|
||||
Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.FIRST));
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void unregister() {
|
||||
if (!isInitialized()) {
|
||||
public static void unregister()
|
||||
{
|
||||
if (!isInitialized())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
WorldEdit.getInstance().getEventBus().unregister(event);
|
||||
initialized = false;
|
||||
ConfigHandler.worldeditEnabled = false;
|
||||
Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, "WorldEdit", Selector.SECOND));
|
||||
Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.SECOND));
|
||||
}
|
||||
catch (Exception e) {
|
||||
Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, "WorldEdit", Selector.SECOND));
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void wrapForLogging(EditSessionEvent event) {
|
||||
Actor actor = event.getActor();
|
||||
World world = event.getWorld();
|
||||
if (actor != null && event.getStage() == (isFAWE ? Stage.BEFORE_HISTORY : Stage.BEFORE_CHANGE)) {
|
||||
event.setExtent(new CoreProtectLogger(actor, world, event.getExtent()));
|
||||
catch (Exception e)
|
||||
{
|
||||
Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.SECOND));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,30 +1,33 @@
|
||||
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.WorldEditException;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import net.coreprotect.config.Config;
|
||||
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 World eventWorld;
|
||||
private final Extent eventExtent;
|
||||
|
||||
protected CoreProtectLogger(Actor actor, World world, Extent extent) {
|
||||
protected CoreProtectLogger(Actor actor, World world, Extent extent)
|
||||
{
|
||||
super(extent);
|
||||
this.eventActor = actor;
|
||||
this.eventWorld = world;
|
||||
@ -32,10 +35,19 @@ public class CoreProtectLogger extends AbstractDelegateExtent {
|
||||
}
|
||||
|
||||
@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);
|
||||
if (!Config.getConfig(world).WORLDEDIT) {
|
||||
return eventExtent.setBlock(position, block);
|
||||
if (!Config.getConfig(world).WORLDEDIT)
|
||||
{
|
||||
if (CoreProtectEditSessionEvent.isFAWE())
|
||||
{
|
||||
return eventExtent.setBlock(position.getX(), position.getY(), position.getZ(), block);
|
||||
}
|
||||
else
|
||||
{
|
||||
return eventExtent.setBlock(position, block);
|
||||
}
|
||||
}
|
||||
|
||||
BlockState oldBlock = eventExtent.getBlock(position);
|
||||
@ -48,16 +60,70 @@ public class CoreProtectLogger extends AbstractDelegateExtent {
|
||||
// e.g. BaseBlock block = eventWorld.getBlock(position);
|
||||
ItemStack[] containerData = CoreProtectEditSessionEvent.isFAWE() ? null : Util.getContainerContents(oldType, null, location);
|
||||
|
||||
if (eventExtent.setBlock(position, block)) {
|
||||
WorldEditLogger.postProcess(eventExtent, eventActor, position, location, block, baseBlock, oldType, oldBlock, containerData);
|
||||
return true;
|
||||
if (CoreProtectEditSessionEvent.isFAWE())
|
||||
{
|
||||
if (eventExtent.setBlock(position.getX(), position.getY(), position.getZ(), block))
|
||||
{
|
||||
WorldEditLogger.postProcess(eventExtent, eventActor, position, location, block, baseBlock, oldType, oldBlock, containerData);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (eventExtent.setBlock(position, block))
|
||||
{
|
||||
WorldEditLogger.postProcess(eventExtent, eventActor, position, location, block, baseBlock, oldType, oldBlock, containerData);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block) throws WorldEditException {
|
||||
return setBlock(BlockVector3.at(x,y,z), block);
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public int replaceBlocks(final Region region, final Mask mask, final Pattern pattern) throws MaxChangedBlocksException
|
||||
{
|
||||
org.bukkit.World world = BukkitAdapter.adapt(eventWorld);
|
||||
if (!Config.getConfig(world).WORLDEDIT)
|
||||
{
|
||||
return eventExtent.replaceBlocks(region, mask, pattern);
|
||||
}
|
||||
processPatternToBlocks(world, region, pattern);
|
||||
return eventExtent.replaceBlocks(region, mask, pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException
|
||||
{
|
||||
org.bukkit.World world = BukkitAdapter.adapt(eventWorld);
|
||||
if (!Config.getConfig(world).WORLDEDIT)
|
||||
{
|
||||
return eventExtent.setBlocks(region, pattern);
|
||||
}
|
||||
processPatternToBlocks(world, region, pattern);
|
||||
return eventExtent.setBlocks(region, pattern);
|
||||
}
|
||||
|
||||
private void processPatternToBlocks(org.bukkit.World world, Region region, Pattern pattern)
|
||||
{
|
||||
for (BlockVector3 position : region.clone())
|
||||
{
|
||||
BlockState oldBlock = eventExtent.getBlock(position);
|
||||
Material oldType = BukkitAdapter.adapt(oldBlock.getBlockType());
|
||||
Location location = new Location(world, position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
BaseBlock baseBlock = WorldEditLogger.getBaseBlock(eventExtent, position, location, oldType, oldBlock);
|
||||
|
||||
// No clear way to get container content data from within the WorldEdit API
|
||||
// Data may be available by converting oldBlock.toBaseBlock().getNbtData()
|
||||
// e.g. BaseBlock block = eventWorld.getBlock(position);
|
||||
ItemStack[] containerData = CoreProtectEditSessionEvent.isFAWE() ? null : Util.getContainerContents(oldType, null, location);
|
||||
WorldEditLogger.postProcess(eventExtent, eventActor, position, location, pattern.applyBlock(position), baseBlock, oldType, oldBlock, containerData);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user