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:
Telesphoreo 2024-05-12 12:43:36 -05:00 committed by GitHub
parent dbb44ab5b9
commit 42af5dc7a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 159 additions and 77 deletions

View File

@ -2,7 +2,7 @@ import org.apache.tools.ant.filters.ReplaceTokens
plugins { plugins {
id 'java' 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' id 'com.palantir.git-version' version '0.13.0'
} }
@ -23,17 +23,15 @@ if (System.getenv("BUILD_NUMBER") != null) {
logger.info("Building version $version") logger.info("Building version $version")
repositories { repositories {
jcenter()
maven { url = 'https://hub.spigotmc.org/nexus/content/groups/public/' } 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://repo.codemc.org/repository/maven-public/' }
maven { url = 'https://maven.enginehub.org/repo/' }
} }
dependencies { dependencies {
compileOnly('com.sk89q.worldedit:worldedit-bukkit:7.0.0-SNAPSHOT') { implementation(platform("com.intellectualsites.bom:bom-newest:1.44")) // Ref: https://github.com/IntellectualSites/bom
exclude group: 'org.bukkit' compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Core")
} compileOnly("com.fastasyncworldedit:FastAsyncWorldEdit-Bukkit")
compileOnly 'io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT' compileOnly 'io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT'
implementation 'org.bstats:bstats-bukkit-lite:1.8' implementation 'org.bstats:bstats-bukkit-lite:1.8'
implementation 'com.zaxxer:HikariCP:5.0.1' implementation 'com.zaxxer:HikariCP:5.0.1'

29
pom.xml
View File

@ -88,11 +88,18 @@
<id>codemc-repo</id> <id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public/</url> <url>https://repo.codemc.org/repository/maven-public/</url>
</repository> </repository>
<repository>
<id>enginehub-repo</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
</repositories> </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> <dependencies>
<!-- <!--
paper-api: io.papermc.paper paper-api: io.papermc.paper
@ -113,14 +120,18 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sk89q.worldedit</groupId> <groupId>com.fastasyncworldedit</groupId>
<artifactId>worldedit-bukkit</artifactId> <artifactId>FastAsyncWorldEdit-Core</artifactId>
<version>7.0.0-SNAPSHOT</version> <scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fastasyncworldedit</groupId>
<artifactId>FastAsyncWorldEdit-Bukkit</artifactId>
<scope>provided</scope> <scope>provided</scope>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>org.bukkit</groupId> <artifactId>FastAsyncWorldEdit-Core</artifactId>
<artifactId>bukkit</artifactId> <groupId>*</groupId>
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>

View File

@ -41,7 +41,6 @@ public class Config extends Language {
public String MYSQL_USERNAME; public String MYSQL_USERNAME;
public String MYSQL_PASSWORD; public String MYSQL_PASSWORD;
public String LANGUAGE; public String LANGUAGE;
public boolean ENABLE_AWE;
public boolean ENABLE_SSL; public boolean ENABLE_SSL;
public boolean DISABLE_WAL; public boolean DISABLE_WAL;
public boolean HOVER_EVENTS; public boolean HOVER_EVENTS;
@ -189,7 +188,6 @@ public class Config extends Language {
} }
private void readValues() { private void readValues() {
this.ENABLE_AWE = this.getBoolean("enable-awe", false);
this.ENABLE_SSL = this.getBoolean("enable-ssl", false); this.ENABLE_SSL = this.getBoolean("enable-ssl", false);
this.DISABLE_WAL = this.getBoolean("disable-wal", false); this.DISABLE_WAL = this.getBoolean("disable-wal", false);
this.HOVER_EVENTS = this.getBoolean("hover-events", true); this.HOVER_EVENTS = this.getBoolean("hover-events", true);

View File

@ -1,90 +1,99 @@
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.extension.platform.Actor;
import com.sk89q.worldedit.util.eventbus.Subscribe; import com.sk89q.worldedit.util.eventbus.Subscribe;
import com.sk89q.worldedit.world.World;
import net.coreprotect.CoreProtect; import net.coreprotect.CoreProtect;
import net.coreprotect.config.Config;
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
if (Bukkit.getServer().getPluginManager().getPlugin("AsyncWorldEdit") == null || Config.getGlobal().ENABLE_AWE) { {
WorldEdit.getInstance().getEventBus().register(event); WorldEdit.getInstance().getEventBus().register(new Object()
initialized = true; {
ConfigHandler.worldeditEnabled = true; @Subscribe
isFAWE = (Bukkit.getServer().getPluginManager().getPlugin("FastAsyncWorldEdit") != null); 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 // Failed to initialize WorldEdit logging
} }
Scheduler.runTask(CoreProtect.getInstance(), () -> { Scheduler.runTask(CoreProtect.getInstance(), () ->
try { {
if (isInitialized()) { try
Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, "WorldEdit", Selector.FIRST)); {
if (isInitialized())
{
Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.FIRST));
} }
else { else
Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, "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, "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, "WorldEdit", Selector.SECOND)); {
} Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, isFAWE() ? "FastAsyncWorldEdit" : "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()));
} }
} }
} }

View File

@ -1,30 +1,33 @@
package net.coreprotect.worldedit; package net.coreprotect.worldedit;
import org.bukkit.Location; import com.sk89q.worldedit.MaxChangedBlocksException;
import org.bukkit.Material;
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.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;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.World; 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;
@ -32,10 +35,19 @@ 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)
return eventExtent.setBlock(position, block); {
if (CoreProtectEditSessionEvent.isFAWE())
{
return eventExtent.setBlock(position.getX(), position.getY(), position.getZ(), block);
}
else
{
return eventExtent.setBlock(position, block);
}
} }
BlockState oldBlock = eventExtent.getBlock(position); BlockState oldBlock = eventExtent.getBlock(position);
@ -48,16 +60,70 @@ 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 (eventExtent.setBlock(position, block)) { if (CoreProtectEditSessionEvent.isFAWE())
WorldEditLogger.postProcess(eventExtent, eventActor, position, location, block, baseBlock, oldType, oldBlock, containerData); {
return true; 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; return false;
} }
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block) throws WorldEditException { @Override
return setBlock(BlockVector3.at(x,y,z), block); 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);
}
}
}