Add extra brush actions to nukkit

This commit is contained in:
Jesse Boyd 2017-03-10 07:27:29 +11:00
parent 3a2451e551
commit 49702155f8
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
4 changed files with 98 additions and 4 deletions

View File

@ -156,7 +156,6 @@ public class WorldEditListener implements Listener {
} }
} else if (action == PlayerInteractEvent.LEFT_CLICK_AIR) { } else if (action == PlayerInteractEvent.LEFT_CLICK_AIR) {
if (we.handleArmSwing(player)) { if (we.handleArmSwing(player)) {
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -0,0 +1,93 @@
package com.boydti.fawe.nukkit.listener;
import cn.nukkit.Player;
import cn.nukkit.event.EventHandler;
import cn.nukkit.event.EventPriority;
import cn.nukkit.event.Listener;
import cn.nukkit.event.player.PlayerInteractEvent;
import cn.nukkit.event.player.PlayerItemHeldEvent;
import cn.nukkit.event.player.PlayerMoveEvent;
import cn.nukkit.inventory.PlayerInventory;
import cn.nukkit.item.Item;
import cn.nukkit.level.Location;
import cn.nukkit.plugin.Plugin;
import com.boydti.fawe.object.FawePlayer;
import com.boydti.fawe.object.brush.MovableTool;
import com.boydti.fawe.object.brush.ResettableTool;
import com.boydti.fawe.object.brush.scroll.ScrollTool;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.command.tool.Tool;
public class BrushListener implements Listener {
public BrushListener(Plugin plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerItemHoldEvent(final PlayerItemHeldEvent event) {
Player nukkitPlayer = event.getPlayer();
if (nukkitPlayer.isSneaking()) {
return;
}
FawePlayer<Object> fp = FawePlayer.wrap(nukkitPlayer);
com.sk89q.worldedit.entity.Player player = fp.getPlayer();
LocalSession session = fp.getSession();
Tool tool = session.getTool(player);
if (tool instanceof ScrollTool) {
final int slot = event.getInventorySlot();
final int oldSlot = event.getSlot();
final int ri;
if ((((slot - oldSlot) <= 4) && ((slot - oldSlot) > 0)) || (((slot - oldSlot) < -4))) {
ri = 1;
} else {
ri = -1;
}
ScrollTool scrollable = (ScrollTool) tool;
if (scrollable.increment(player, ri)) {
final PlayerInventory inv = nukkitPlayer.getInventory();
final Item item = inv.getItem(slot);
final Item newItem = inv.getItem(oldSlot);
inv.setItem(slot, newItem);
inv.setItem(oldSlot, item);
inv.sendContents(nukkitPlayer);
}
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent event) {
Location from = event.getFrom();
Location to = event.getTo();
if ((from.getYaw() != to.getYaw() && from.getPitch() != to.getPitch()) || from.getFloorX() != to.getFloorX() || from.getFloorZ() != to.getFloorZ() || from.getFloorY() != to.getFloorY()) {
Player nukkitPlayer = event.getPlayer();
FawePlayer<Object> fp = FawePlayer.wrap(nukkitPlayer);
com.sk89q.worldedit.entity.Player player = fp.getPlayer();
LocalSession session = fp.getSession();
Tool tool = session.getTool(player);
if (tool != null) {
if (tool instanceof MovableTool) {
((MovableTool) tool).move(player);
}
}
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteract(final PlayerInteractEvent event) {
Player nukkitPlayer = event.getPlayer();
if (nukkitPlayer.isSneaking()) {
if (event.getAction() == PlayerInteractEvent.PHYSICAL) {
return;
}
FawePlayer<Object> fp = FawePlayer.wrap(nukkitPlayer);
com.sk89q.worldedit.entity.Player player = fp.getPlayer();
LocalSession session = fp.getSession();
Tool tool = session.getTool(player);
if (tool instanceof ResettableTool) {
if (((ResettableTool) tool).reset()) {
event.setCancelled(true);
}
}
}
}
}

View File

@ -9,6 +9,7 @@ import com.boydti.fawe.IFawe;
import com.boydti.fawe.config.Settings; import com.boydti.fawe.config.Settings;
import com.boydti.fawe.nukkit.core.NukkitTaskManager; import com.boydti.fawe.nukkit.core.NukkitTaskManager;
import com.boydti.fawe.nukkit.core.NukkitWorldEdit; import com.boydti.fawe.nukkit.core.NukkitWorldEdit;
import com.boydti.fawe.nukkit.listener.BrushListener;
import com.boydti.fawe.nukkit.optimization.queue.NukkitQueue; import com.boydti.fawe.nukkit.optimization.queue.NukkitQueue;
import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FaweChunk;
import com.boydti.fawe.object.FaweCommand; import com.boydti.fawe.object.FaweCommand;
@ -31,8 +32,9 @@ public class FaweNukkit implements IFawe, Listener {
public FaweNukkit(NukkitWorldEdit mod) { public FaweNukkit(NukkitWorldEdit mod) {
this.plugin = mod; this.plugin = mod;
FaweChunk.HEIGHT = 256; FaweChunk.HEIGHT = 256;
VisualChunk.VISUALIZE_BLOCK = 241 << 4; VisualChunk.VISUALIZE_BLOCK = 20 << 4;
plugin.getServer().getPluginManager().registerEvents(this, plugin); plugin.getServer().getPluginManager().registerEvents(this, plugin);
new BrushListener(mod);
} }
@EventHandler @EventHandler

View File

@ -140,9 +140,9 @@ public class NukkitQueue extends NMSMappedFaweQueue<Level, BaseFullChunk, BaseFu
@Override @Override
public void run(int localX, int y, int localZ, int combined) { public void run(int localX, int y, int localZ, int combined) {
Block block = Block.get(FaweCache.getId(combined), FaweCache.getData(combined)); Block block = Block.get(FaweCache.getId(combined), FaweCache.getData(combined));
block.x = bz + localX; block.x = bx + localX;
block.y = y; block.y = y;
block.z = bx + localZ; block.z = bz + localZ;
blocks.add(block); blocks.add(block);
} }
}); });