forked from bootswithdefer/LogBlock
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated for WorldEdit 6.0 #542
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
78 changes: 0 additions & 78 deletions
78
src/main/java/de/diddiz/worldedit/LogBlockEditSession.java
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
src/main/java/de/diddiz/worldedit/LogBlockEditSessionFactory.java
This file was deleted.
Oops, something went wrong.
89 changes: 89 additions & 0 deletions
89
src/main/java/de/diddiz/worldedit/WorldEditLoggingHook.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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package de.diddiz.worldedit; | ||
|
||
import com.sk89q.worldedit.EditSession; | ||
import com.sk89q.worldedit.Vector; | ||
import com.sk89q.worldedit.WorldEdit; | ||
import com.sk89q.worldedit.blocks.BaseBlock; | ||
import com.sk89q.worldedit.entity.Player; | ||
import com.sk89q.worldedit.event.extent.EditSessionEvent; | ||
import com.sk89q.worldedit.extension.platform.Actor; | ||
import com.sk89q.worldedit.extent.logging.AbstractLoggingExtent; | ||
import com.sk89q.worldedit.util.eventbus.Subscribe; | ||
import de.diddiz.LogBlock.LogBlock; | ||
import de.diddiz.LogBlock.Logging; | ||
import de.diddiz.LogBlock.config.Config; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.Location; | ||
import org.bukkit.Material; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.block.BlockState; | ||
import org.bukkit.block.Sign; | ||
|
||
public class WorldEditLoggingHook { | ||
|
||
private LogBlock plugin; | ||
|
||
public WorldEditLoggingHook(LogBlock plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
public void hook() { | ||
WorldEdit.getInstance().getEventBus().register(new Object() { | ||
@Subscribe | ||
public void wrapForLogging(final EditSessionEvent event) { | ||
final Actor actor = event.getActor(); | ||
if (actor == null || !(actor instanceof Player)) return; | ||
|
||
// Check to ensure the world should be logged | ||
String worldName = event.getWorld().getName(); | ||
// If config becomes reloadable, this check should be moved | ||
if (!(Config.isLogging(worldName, Logging.WORLDEDIT))) { | ||
return; | ||
} | ||
|
||
final org.bukkit.World bukkitWorld = Bukkit.getWorld(worldName); | ||
if (bukkitWorld == null) { | ||
return; | ||
} | ||
|
||
event.setExtent(new AbstractLoggingExtent(event.getExtent()) { | ||
@Override | ||
protected void onBlockChange(Vector pt, BaseBlock block) { | ||
|
||
if (event.getStage() != EditSession.Stage.BEFORE_CHANGE) { | ||
return; | ||
} | ||
|
||
Location location = new Location(bukkitWorld, pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); | ||
|
||
Block origin = location.getBlock(); | ||
int typeBefore = origin.getTypeId(); | ||
byte dataBefore = origin.getData(); | ||
// If we're dealing with a sign, store the block state to read the text off | ||
BlockState stateBefore = null; | ||
if (typeBefore == Material.SIGN_POST.getId() || typeBefore == Material.SIGN.getId()) { | ||
stateBefore = origin.getState(); | ||
} | ||
|
||
// Check to see if we've broken a sign | ||
if (Config.isLogging(location.getWorld().getName(), Logging.SIGNTEXT) && (typeBefore == Material.SIGN_POST.getId() || typeBefore == Material.SIGN.getId())) { | ||
plugin.getConsumer().queueSignBreak(actor.getName(), (Sign) stateBefore); | ||
if (block.getType() != Material.AIR.getId()) { | ||
plugin.getConsumer().queueBlockPlace(actor.getName(), location, block.getType(), (byte) block.getData()); | ||
} | ||
} else { | ||
if (dataBefore != 0) { | ||
plugin.getConsumer().queueBlockBreak(actor.getName(), location, typeBefore, dataBefore); | ||
if (block.getType() != Material.AIR.getId()) { | ||
plugin.getConsumer().queueBlockPlace(actor.getName(), location, block.getType(), (byte) block.getData()); | ||
} | ||
} else { | ||
plugin.getConsumer().queueBlock(actor.getName(), location, typeBefore, block.getType(), (byte) block.getData()); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate pull :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mkay :p