-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
dbb44ab
commit 42af5dc
Showing
5 changed files
with
159 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 51 additions & 42 deletions
93
src/main/java/net/coreprotect/worldedit/CoreProtectEditSessionEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
catch (Exception e) { | ||
Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, "WorldEdit", Selector.SECOND)); | ||
Chat.console(Phrase.build(Phrase.INTEGRATION_SUCCESS, 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())); | ||
catch (Exception e) | ||
{ | ||
Chat.console(Phrase.build(Phrase.INTEGRATION_ERROR, isFAWE() ? "FastAsyncWorldEdit" : "WorldEdit", Selector.SECOND)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters