Skip to content

Commit

Permalink
WorldEdit 7 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
bermudalocket committed Sep 16, 2018
1 parent 8ed52bc commit 5385c66
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 24 deletions.
27 changes: 22 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
target/
*.iml
.idea/
*.class

# Eclipse:
.classpath
# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# Eclipse stuff:
.project
.settings
.classpath

# IntelliJ stuff:
.idea

# Build:
/classes/
target/
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@
</plugins>
</pluginManagement>
</build>
</project>
</project>
3 changes: 2 additions & 1 deletion src/nu/nerd/SafeBuckets/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

// ----------------------------------------------------------------------------------------------------------
/**
Expand Down Expand Up @@ -95,7 +96,7 @@ class Configuration {

// ------------------------------------------------------------------------------------------------------
/**
* Constructor.
* Constructor. Called once during {@link JavaPlugin#onEnable()}.
*/
Configuration() {
reload();
Expand Down
6 changes: 3 additions & 3 deletions src/nu/nerd/SafeBuckets/PlayerFlowCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class PlayerFlowCache implements Listener {
Bukkit.getPluginManager().registerEvents(this, SafeBuckets.PLUGIN);
Bukkit.getScheduler().runTaskTimer(SafeBuckets.PLUGIN,
PlayerFlowCache::reviewCache,
1,
1, // delay
SafeBuckets.CONFIG.PLAYER_SELF_FLOW_CACHE_REVIEW_PERIOD);
}

Expand Down Expand Up @@ -102,7 +102,7 @@ private static boolean willExpire(UUID uuid) {
/**
* Forces a player's flow session to expire upon logout.
*/
@EventHandler(priority = EventPriority.NORMAL)
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event) {
forceExpire(event.getPlayer());
}
Expand All @@ -111,7 +111,7 @@ public void onPlayerQuit(PlayerQuitEvent event) {
/**
* Forces a player's flow session to expire upon being kicked.
*/
@EventHandler(priority = EventPriority.NORMAL)
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerKick(PlayerKickEvent event) {
forceExpire(event.getPlayer());
}
Expand Down
3 changes: 2 additions & 1 deletion src/nu/nerd/SafeBuckets/SafeBuckets.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ private void flowLiquidsInSelection(Player player) {
return;
}

if (CONFIG.WORLDEDIT_FLOWSEL_MAX_BLOCKS != 0 && region.getArea() > CONFIG.WORLDEDIT_FLOWSEL_MAX_BLOCKS) {
int regionArea = region.getArea();
if (CONFIG.WORLDEDIT_FLOWSEL_MAX_BLOCKS != 0 && regionArea > CONFIG.WORLDEDIT_FLOWSEL_MAX_BLOCKS) {
Util.Message.WORLDEDIT_FLOWSEL_OVER_MAX.send(player);
return;
}
Expand Down
37 changes: 24 additions & 13 deletions src/nu/nerd/SafeBuckets/SafeBucketsListener.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package nu.nerd.SafeBuckets;

import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.util.eventbus.Subscribe;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import me.sothatsit.usefulsnippets.EnchantGlow;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -38,6 +47,7 @@ public class SafeBucketsListener implements Listener {
*/
SafeBucketsListener() {
Bukkit.getPluginManager().registerEvents(this, SafeBuckets.PLUGIN);
WorldEdit.getInstance().getEventBus().register(this);
}

// ------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -85,27 +95,27 @@ public void onBlockFromTo(BlockFromToEvent event) {
}
}

/*
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
// ------------------------------------------------------------------------------------------------------
/**
* Prevents WorldEdited liquids from flowing.
*/
@Subscribe
public void onWorldEdit(EditSessionEvent event) {
System.out.println("edit session");
event.setExtent(new AbstractDelegateExtent(event.getExtent()) {
@Override
public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException {
System.out.println("caught");
public boolean setBlock(Vector loc, BlockStateHolder block) throws WorldEditException {
Material newMaterial = BukkitAdapter.adapt(block.getBlockType());
if (Liquid.isSupportedType(newMaterial) && event.getWorld() != null) {
World world = BukkitAdapter.adapt(event.getWorld());
Bukkit.getScheduler().runTaskLater(SafeBuckets.PLUGIN, () -> {
Block newBlock = world.getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ());
Block newBlock = world.getBlockAt(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
SafeBuckets.setSafe(newBlock, true);
System.out.println("Set safe after WE: " + newBlock);
}, 1);
}
return super.setBlock(location, block);
return super.setBlock(loc, block);
}
});
}*/
}

// ------------------------------------------------------------------------------------------------------
/**
Expand All @@ -129,7 +139,8 @@ public void onBlockBreak(BlockBreakEvent event) {
Block block = event.getBlock();
FrozenLiquid frozenLiquid = FrozenLiquid.getType(block);
if (frozenLiquid != null && frozenLiquid.meltsWhenBroken()) {
if (!event.getPlayer().getEquipment().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
Player player = event.getPlayer();
if (!player.getEquipment().getItemInMainHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
// make the ice block safe to prevent flowing immediately upon breaking
SafeBuckets.setSafe(block, true);

Expand Down Expand Up @@ -183,9 +194,9 @@ public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {

// replenish
final ItemStack bucket = liquid.getBucket(false);
Bukkit.getScheduler().runTaskLater(SafeBuckets.PLUGIN,
() -> player.getEquipment().setItemInMainHand(bucket),
1);
Bukkit.getScheduler().runTaskLater(SafeBuckets.PLUGIN, () -> {
player.getEquipment().setItemInMainHand(bucket);
}, 1);
} else {
SafeBuckets.setSafe(block, true);
}
Expand Down

0 comments on commit 5385c66

Please sign in to comment.