mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2024-11-28 05:35:37 +01:00
Functional WorldEdit for MCPE
This commit is contained in:
parent
e68530e8f8
commit
c4c7e1a091
@ -1,6 +1,10 @@
|
|||||||
|
repositories {
|
||||||
|
flatDir {dirs 'lib'}
|
||||||
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(':core')
|
compile project(':core')
|
||||||
compile 'cn.nukkit:nukkit:1.0-SNAPSHOT'
|
compile 'cn.nukkit:nukkit:1.0-SNAPSHOT'
|
||||||
|
compile name: 'worldedit-core-6.1.4-SNAPSHOT-dist'
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
@ -18,10 +22,17 @@ apply plugin: 'com.github.johnrengelman.shadow'
|
|||||||
jar.enabled = false
|
jar.enabled = false
|
||||||
shadowJar {
|
shadowJar {
|
||||||
dependencies {
|
dependencies {
|
||||||
include(dependency(':core'))
|
include(dependency(name: 'worldedit-core-6.1.4-SNAPSHOT-dist'))
|
||||||
|
include(dependency('com.google.code.gson:gson:2.2.4'))
|
||||||
|
include(dependency('org.yaml:snakeyaml:1.16'))
|
||||||
|
include(dependency('com.google.guava:guava:17.0'))
|
||||||
}
|
}
|
||||||
archiveName = "${parent.name}-${project.name}-${parent.version}.jar"
|
archiveName = "${parent.name}-${project.name}-${parent.version}.jar"
|
||||||
destinationDir = file '../target'
|
destinationDir = file '../target'
|
||||||
|
|
||||||
|
relocate('com.google.gson', 'com.sk89q.worldedit.internal.gson')
|
||||||
|
relocate 'org.yaml.snakeyaml', 'com.boydti.fawe.yaml'
|
||||||
|
relocate 'com.google.common', 'com.sk89q.worldedit.internal.common'
|
||||||
}
|
}
|
||||||
shadowJar.doLast {
|
shadowJar.doLast {
|
||||||
task ->
|
task ->
|
||||||
|
BIN
nukkit/lib/worldedit-core-6.1.4-SNAPSHOT-dist.jar
Normal file
BIN
nukkit/lib/worldedit-core-6.1.4-SNAPSHOT-dist.jar
Normal file
Binary file not shown.
84
nukkit/src/main/java/com/boydti/fawe/nukkit/FaweNukkit.java
Normal file
84
nukkit/src/main/java/com/boydti/fawe/nukkit/FaweNukkit.java
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
package com.boydti.fawe.nukkit;
|
||||||
|
|
||||||
|
import com.boydti.fawe.IFawe;
|
||||||
|
import com.boydti.fawe.object.FaweCommand;
|
||||||
|
import com.boydti.fawe.object.FawePlayer;
|
||||||
|
import com.boydti.fawe.object.FaweQueue;
|
||||||
|
import com.boydti.fawe.regions.FaweMaskManager;
|
||||||
|
import com.boydti.fawe.util.TaskManager;
|
||||||
|
import com.sk89q.worldedit.world.World;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class FaweNukkit implements IFawe {
|
||||||
|
@Override
|
||||||
|
public void debug(String s) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getDirectory() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setupCommand(String label, FaweCommand cmd) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FawePlayer wrap(Object obj) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setupVault() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TaskManager getTaskManager() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FaweQueue getNewQueue(String world, boolean fast) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getWorldName(World world) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<FaweMaskManager> getMaskManagers() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startMetrics() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPlatform() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID getUUID(String name) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName(UUID uuid) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getBlocksHubApi() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -21,7 +21,9 @@ public class NukkitCommandManager {
|
|||||||
executor,
|
executor,
|
||||||
plugin);
|
plugin);
|
||||||
cmd.setPermissions(command.getPermissions());
|
cmd.setPermissions(command.getPermissions());
|
||||||
commandMap.register(plugin.getDescription().getName(), cmd);
|
for (String alias : command.getAliases()) {
|
||||||
|
commandMap.register(alias, cmd);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,156 @@
|
|||||||
|
/*
|
||||||
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.boydti.fawe.nukkit.core;
|
||||||
|
|
||||||
|
import cn.nukkit.Player;
|
||||||
|
import cn.nukkit.command.CommandSender;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
|
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
||||||
|
import com.sk89q.worldedit.session.SessionKey;
|
||||||
|
import com.sk89q.worldedit.util.auth.AuthorizationException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.UUID;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
public class NukkitCommandSender implements Actor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One time generated ID.
|
||||||
|
*/
|
||||||
|
private static final UUID DEFAULT_ID = UUID.fromString("a233eb4b-4cab-42cd-9fd9-7e7b9a3f74be");
|
||||||
|
|
||||||
|
private CommandSender sender;
|
||||||
|
private NukkitWorldEdit plugin;
|
||||||
|
|
||||||
|
public NukkitCommandSender(NukkitWorldEdit plugin, CommandSender sender) {
|
||||||
|
checkNotNull(plugin);
|
||||||
|
checkNotNull(sender);
|
||||||
|
checkArgument(!(sender instanceof Player), "Cannot wrap a player");
|
||||||
|
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.sender = sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID getUniqueId() {
|
||||||
|
return DEFAULT_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return sender.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void printRaw(String msg) {
|
||||||
|
for (String part : msg.split("\n")) {
|
||||||
|
sender.sendMessage(part);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void print(String msg) {
|
||||||
|
for (String part : msg.split("\n")) {
|
||||||
|
sender.sendMessage("\u00A7d" + part);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void printDebug(String msg) {
|
||||||
|
for (String part : msg.split("\n")) {
|
||||||
|
sender.sendMessage("\u00A77" + part);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void printError(String msg) {
|
||||||
|
for (String part : msg.split("\n")) {
|
||||||
|
sender.sendMessage("\u00A7c" + part);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canDestroyBedrock() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getGroups() {
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(String perm) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkPermission(String permission) throws AuthorizationException {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPlayer() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File openFileOpenDialog(String[] extensions) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File openFileSaveDialog(String[] extensions) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispatchCUIEvent(CUIEvent event) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SessionKey getSessionKey() {
|
||||||
|
return new SessionKey() {
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActive() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPersistent() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID getUniqueId() {
|
||||||
|
return DEFAULT_ID;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -1,17 +1,16 @@
|
|||||||
package com.boydti.fawe.nukkit.core;
|
package com.boydti.fawe.nukkit.core;
|
||||||
|
|
||||||
import com.sk89q.util.yaml.YAMLProcessor;
|
import com.sk89q.util.yaml.YAMLProcessor;
|
||||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
|
||||||
import com.sk89q.worldedit.util.YAMLConfiguration;
|
import com.sk89q.worldedit.util.YAMLConfiguration;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class NukkitConfiguration extends YAMLConfiguration {
|
public class NukkitConfiguration extends YAMLConfiguration {
|
||||||
|
|
||||||
public boolean noOpPermissions = false;
|
public boolean noOpPermissions = false;
|
||||||
private final WorldEditPlugin plugin;
|
private final NukkitWorldEdit plugin;
|
||||||
|
|
||||||
public NukkitConfiguration(YAMLProcessor config, WorldEditPlugin plugin) {
|
public NukkitConfiguration(YAMLProcessor config, NukkitWorldEdit plugin) {
|
||||||
super(config, plugin.getLogger());
|
super(config, plugin.getWELogger());
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ package com.boydti.fawe.nukkit.core;
|
|||||||
|
|
||||||
import cn.nukkit.item.Item;
|
import cn.nukkit.item.Item;
|
||||||
import cn.nukkit.level.Level;
|
import cn.nukkit.level.Level;
|
||||||
import com.boydti.fawe.util.TaskManager;
|
|
||||||
import com.sk89q.worldedit.entity.Player;
|
import com.sk89q.worldedit.entity.Player;
|
||||||
import com.sk89q.worldedit.extension.platform.AbstractPlatform;
|
import com.sk89q.worldedit.extension.platform.AbstractPlatform;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
@ -43,12 +42,14 @@ import javax.annotation.Nullable;
|
|||||||
class NukkitPlatform extends AbstractPlatform implements MultiUserPlatform {
|
class NukkitPlatform extends AbstractPlatform implements MultiUserPlatform {
|
||||||
|
|
||||||
private final NukkitWorldEdit mod;
|
private final NukkitWorldEdit mod;
|
||||||
|
private final NukkitTaskManager taskManager;
|
||||||
private boolean hookingEvents = false;
|
private boolean hookingEvents = false;
|
||||||
private NukkitCommandManager commandManager;
|
private NukkitCommandManager commandManager;
|
||||||
|
|
||||||
NukkitPlatform(NukkitWorldEdit mod) {
|
NukkitPlatform(NukkitWorldEdit mod) {
|
||||||
this.mod = mod;
|
this.mod = mod;
|
||||||
this.commandManager = new NukkitCommandManager(mod.getServer().getCommandMap());
|
this.commandManager = new NukkitCommandManager(mod.getServer().getCommandMap());
|
||||||
|
this.taskManager = new NukkitTaskManager(mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isHookingEvents() {
|
boolean isHookingEvents() {
|
||||||
@ -78,7 +79,7 @@ class NukkitPlatform extends AbstractPlatform implements MultiUserPlatform {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int schedule(long delay, long period, Runnable task) {
|
public int schedule(long delay, long period, Runnable task) {
|
||||||
TaskManager.IMP.repeat(task, (int) period);
|
this.taskManager.repeat(task, (int) period);
|
||||||
return 0; // TODO This isn't right, but we only check for -1 values
|
return 0; // TODO This isn't right, but we only check for -1 values
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,6 +192,7 @@ public class NukkitPlayerBlockBag extends BlockBag {
|
|||||||
if (items != null) {
|
if (items != null) {
|
||||||
player.getInventory().setContents(items);
|
player.getInventory().setContents(items);
|
||||||
items = null;
|
items = null;
|
||||||
|
player.getInventory().sendContents(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,11 +2,10 @@ package com.boydti.fawe.nukkit.core;
|
|||||||
|
|
||||||
import cn.nukkit.plugin.Plugin;
|
import cn.nukkit.plugin.Plugin;
|
||||||
import cn.nukkit.scheduler.TaskHandler;
|
import cn.nukkit.scheduler.TaskHandler;
|
||||||
import com.boydti.fawe.util.TaskManager;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import org.apache.commons.lang.mutable.MutableInt;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class NukkitTaskManager extends TaskManager {
|
public class NukkitTaskManager {
|
||||||
|
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
|
|
||||||
@ -14,22 +13,19 @@ public class NukkitTaskManager extends TaskManager {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int repeat(final Runnable r, final int interval) {
|
public int repeat(final Runnable r, final int interval) {
|
||||||
TaskHandler task = this.plugin.getServer().getScheduler().scheduleRepeatingTask(r, interval, false);
|
TaskHandler task = this.plugin.getServer().getScheduler().scheduleRepeatingTask(r, interval, false);
|
||||||
return task.getTaskId();
|
return task.getTaskId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int repeatAsync(final Runnable r, final int interval) {
|
public int repeatAsync(final Runnable r, final int interval) {
|
||||||
TaskHandler task = this.plugin.getServer().getScheduler().scheduleRepeatingTask(r, interval, true);
|
TaskHandler task = this.plugin.getServer().getScheduler().scheduleRepeatingTask(r, interval, true);
|
||||||
return task.getTaskId();
|
return task.getTaskId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutableInt index = new MutableInt(0);
|
public AtomicInteger index = new AtomicInteger(0);
|
||||||
public HashMap<Integer, Integer> tasks = new HashMap<>();
|
public HashMap<Integer, Integer> tasks = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
|
||||||
public void async(final Runnable r) {
|
public void async(final Runnable r) {
|
||||||
if (r == null) {
|
if (r == null) {
|
||||||
return;
|
return;
|
||||||
@ -37,7 +33,6 @@ public class NukkitTaskManager extends TaskManager {
|
|||||||
this.plugin.getServer().getScheduler().scheduleTask(r, true);
|
this.plugin.getServer().getScheduler().scheduleTask(r, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void task(final Runnable r) {
|
public void task(final Runnable r) {
|
||||||
if (r == null) {
|
if (r == null) {
|
||||||
return;
|
return;
|
||||||
@ -45,7 +40,6 @@ public class NukkitTaskManager extends TaskManager {
|
|||||||
this.plugin.getServer().getScheduler().scheduleTask(r, false);
|
this.plugin.getServer().getScheduler().scheduleTask(r, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void later(final Runnable r, final int delay) {
|
public void later(final Runnable r, final int delay) {
|
||||||
if (r == null) {
|
if (r == null) {
|
||||||
return;
|
return;
|
||||||
@ -53,12 +47,10 @@ public class NukkitTaskManager extends TaskManager {
|
|||||||
this.plugin.getServer().getScheduler().scheduleDelayedTask(r, delay);
|
this.plugin.getServer().getScheduler().scheduleDelayedTask(r, delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void laterAsync(final Runnable r, final int delay) {
|
public void laterAsync(final Runnable r, final int delay) {
|
||||||
this.plugin.getServer().getScheduler().scheduleDelayedTask(r, delay, true);
|
this.plugin.getServer().getScheduler().scheduleDelayedTask(r, delay, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cancel(final int task) {
|
public void cancel(final int task) {
|
||||||
if (task != -1) {
|
if (task != -1) {
|
||||||
this.plugin.getServer().getScheduler().cancelTask(task);
|
this.plugin.getServer().getScheduler().cancelTask(task);
|
||||||
|
@ -28,11 +28,11 @@ import cn.nukkit.math.Vector3;
|
|||||||
import com.sk89q.worldedit.BlockVector;
|
import com.sk89q.worldedit.BlockVector;
|
||||||
import com.sk89q.worldedit.BlockWorldVector;
|
import com.sk89q.worldedit.BlockWorldVector;
|
||||||
import com.sk89q.worldedit.LocalWorld;
|
import com.sk89q.worldedit.LocalWorld;
|
||||||
|
import com.sk89q.worldedit.Vector;
|
||||||
|
import com.sk89q.worldedit.WorldVector;
|
||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
import com.sk89q.worldedit.entity.BaseEntity;
|
import com.sk89q.worldedit.entity.BaseEntity;
|
||||||
import com.sk89q.worldedit.util.Location;
|
import com.sk89q.worldedit.util.Location;
|
||||||
import com.sk89q.worldedit.Vector;
|
|
||||||
import com.sk89q.worldedit.WorldVector;
|
|
||||||
|
|
||||||
public final class NukkitUtil {
|
public final class NukkitUtil {
|
||||||
|
|
||||||
@ -125,15 +125,27 @@ public final class NukkitUtil {
|
|||||||
return new NukkitEntity(e);
|
return new NukkitEntity(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static com.sk89q.worldedit.entity.Entity createEntity(Location location, BaseEntity entity) {
|
public static com.sk89q.worldedit.entity.Entity createEntity(Level level, Location location, BaseEntity entity) {
|
||||||
|
// TODO
|
||||||
|
System.out.print("TODO create entity");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BaseBlock getBlock(Level level, Vector position) {
|
public static BaseBlock getBlock(Level level, Vector position) {
|
||||||
return null;
|
Vector3 pos = new Vector3(position.getX(), position.getY(), position.getZ());
|
||||||
|
Block block = level.getBlock(pos);
|
||||||
|
int id = block.getId();
|
||||||
|
int data = block.getDamage();
|
||||||
|
return new BaseBlock(id, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean setBlock(Level level, Vector position, BaseBlock block) {
|
public static boolean setBlock(Level level, Vector pos, BaseBlock block) {
|
||||||
return false;
|
int x = pos.getBlockX();
|
||||||
|
int y = pos.getBlockY();
|
||||||
|
int z = pos.getBlockZ();
|
||||||
|
level.setBlockIdAt(x, y, z, block.getId());
|
||||||
|
level.setBlockDataAt(x, y, z, block.getData());
|
||||||
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package com.boydti.fawe.nukkit.core;
|
package com.boydti.fawe.nukkit.core;
|
||||||
|
|
||||||
import cn.nukkit.block.Block;
|
|
||||||
import cn.nukkit.blockentity.BlockEntity;
|
import cn.nukkit.blockentity.BlockEntity;
|
||||||
import cn.nukkit.blockentity.BlockEntityChest;
|
import cn.nukkit.blockentity.BlockEntityChest;
|
||||||
import cn.nukkit.entity.Entity;
|
import cn.nukkit.entity.Entity;
|
||||||
@ -26,7 +25,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.bukkit.Material;
|
|
||||||
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
@ -80,7 +78,7 @@ public class NukkitWorld extends LocalWorld {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public com.sk89q.worldedit.entity.Entity createEntity(com.sk89q.worldedit.util.Location location, BaseEntity entity) {
|
public com.sk89q.worldedit.entity.Entity createEntity(com.sk89q.worldedit.util.Location location, BaseEntity entity) {
|
||||||
return NukkitUtil.createEntity(location, entity);
|
return NukkitUtil.createEntity(getLevel(), location, entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,13 +21,20 @@ package com.boydti.fawe.nukkit.core;
|
|||||||
|
|
||||||
import cn.nukkit.Nukkit;
|
import cn.nukkit.Nukkit;
|
||||||
import cn.nukkit.Player;
|
import cn.nukkit.Player;
|
||||||
|
import cn.nukkit.command.Command;
|
||||||
|
import cn.nukkit.command.CommandSender;
|
||||||
import cn.nukkit.plugin.PluginBase;
|
import cn.nukkit.plugin.PluginBase;
|
||||||
import cn.nukkit.utils.Logger;
|
import com.google.common.base.Joiner;
|
||||||
|
import com.sk89q.util.yaml.YAMLProcessor;
|
||||||
import com.sk89q.worldedit.LocalSession;
|
import com.sk89q.worldedit.LocalSession;
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
|
import com.sk89q.worldedit.event.platform.CommandEvent;
|
||||||
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
|
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
|
||||||
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.extension.platform.Platform;
|
import com.sk89q.worldedit.extension.platform.Platform;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
@ -57,12 +64,24 @@ public class NukkitWorldEdit extends PluginBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
// TODO load FAWE
|
try {
|
||||||
config.load();
|
// TODO load FAWE
|
||||||
this.platform = new NukkitPlatform(this);
|
logger = Logger.getLogger(NukkitWorldEdit.class.getCanonicalName());
|
||||||
WorldEdit.getInstance().getPlatformManager().register(platform);
|
File file = new File(getDataFolder(), "config.yml");
|
||||||
logger.info("WorldEdit for Nukkit (version " + getInternalVersion() + ") is loaded");
|
if (!file.exists()) {
|
||||||
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent());
|
file.getParentFile().mkdirs();
|
||||||
|
file.createNewFile();
|
||||||
|
}
|
||||||
|
config = new NukkitConfiguration(new YAMLProcessor(file, true), this);
|
||||||
|
config.load();
|
||||||
|
this.platform = new NukkitPlatform(this);
|
||||||
|
getServer().getPluginManager().registerEvents(new WorldEditListener(this), this);
|
||||||
|
WorldEdit.getInstance().getPlatformManager().register(platform);
|
||||||
|
logger.info("WorldEdit for Nukkit (version " + getInternalVersion() + ") is loaded");
|
||||||
|
WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent());
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -70,6 +89,28 @@ public class NukkitWorldEdit extends PluginBase {
|
|||||||
WorldEdit.getInstance().getPlatformManager().unregister(platform);
|
WorldEdit.getInstance().getPlatformManager().unregister(platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||||
|
// Add the command to the array because the underlying command handling
|
||||||
|
// code of WorldEdit expects it
|
||||||
|
String[] split = new String[args.length + 1];
|
||||||
|
System.arraycopy(args, 0, split, 1, args.length);
|
||||||
|
split[0] = cmd.getName();
|
||||||
|
|
||||||
|
CommandEvent event = new CommandEvent(wrapCommandSender(sender), Joiner.on(" ").join(Arrays.asList(split)));
|
||||||
|
WorldEdit.getInstance().getEventBus().post(event);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Actor wrapCommandSender(CommandSender sender) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
return wrapPlayer((Player) sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new NukkitCommandSender(this, sender);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the configuration.
|
* Get the configuration.
|
||||||
*
|
*
|
||||||
@ -79,6 +120,10 @@ public class NukkitWorldEdit extends PluginBase {
|
|||||||
return this.config;
|
return this.config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Logger getWELogger() {
|
||||||
|
return logger;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the WorldEdit proxy for the given player.
|
* Get the WorldEdit proxy for the given player.
|
||||||
*
|
*
|
||||||
|
@ -26,6 +26,7 @@ import cn.nukkit.block.Block;
|
|||||||
import cn.nukkit.event.EventHandler;
|
import cn.nukkit.event.EventHandler;
|
||||||
import cn.nukkit.event.EventPriority;
|
import cn.nukkit.event.EventPriority;
|
||||||
import cn.nukkit.event.Listener;
|
import cn.nukkit.event.Listener;
|
||||||
|
import cn.nukkit.event.block.BlockBreakEvent;
|
||||||
import cn.nukkit.event.player.PlayerCommandPreprocessEvent;
|
import cn.nukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import cn.nukkit.event.player.PlayerGameModeChangeEvent;
|
import cn.nukkit.event.player.PlayerGameModeChangeEvent;
|
||||||
import cn.nukkit.event.player.PlayerInteractEvent;
|
import cn.nukkit.event.player.PlayerInteractEvent;
|
||||||
@ -93,12 +94,28 @@ public class WorldEditListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
|
final LocalPlayer player = plugin.wrapPlayer(event.getPlayer());
|
||||||
|
final World world = player.getWorld();
|
||||||
|
final WorldEdit we = WorldEdit.getInstance();
|
||||||
|
final Block clickedBlock = event.getBlock();
|
||||||
|
final WorldVector pos = new WorldVector(LocalWorldAdapter.adapt(world), clickedBlock.getX(), clickedBlock.getY(), clickedBlock.getZ());
|
||||||
|
if (we.handleBlockLeftClick(player, pos)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
if (we.handleArmSwing(player)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player interacts
|
* Called when a player interacts
|
||||||
*
|
*
|
||||||
* @param event Relevant event details
|
* @param event Relevant event details
|
||||||
*/
|
*/
|
||||||
@EventHandler(ignoreCancelled = true,priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
final LocalPlayer player = plugin.wrapPlayer(event.getPlayer());
|
final LocalPlayer player = plugin.wrapPlayer(event.getPlayer());
|
||||||
final World world = player.getWorld();
|
final World world = player.getWorld();
|
||||||
|
5
nukkit/src/main/resources/plugin.yml
Normal file
5
nukkit/src/main/resources/plugin.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
name: "${name}"
|
||||||
|
version: "${version}"
|
||||||
|
author: Empire92
|
||||||
|
api: ["1.0.0"]
|
||||||
|
main: com.boydti.fawe.nukkit.core.NukkitWorldEdit
|
Loading…
Reference in New Issue
Block a user