geforkt von Mirrors/FastAsyncWorldEdit
Added some API methods.
Dieser Commit ist enthalten in:
Ursprung
fed8960045
Commit
abaeaa99ac
30
src/com/sk89q/worldedit/WorldEditOperation.java
Normale Datei
30
src/com/sk89q/worldedit/WorldEditOperation.java
Normale Datei
@ -0,0 +1,30 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldEdit
|
||||
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit;
|
||||
|
||||
/**
|
||||
* Represents a WorldEdit operation.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public abstract class WorldEditOperation {
|
||||
public abstract void run(LocalSession session,
|
||||
LocalPlayer player, EditSession editSession) throws Throwable;
|
||||
}
|
@ -36,6 +36,8 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import com.sk89q.bukkit.migration.PermissionsResolverManager;
|
||||
import com.sk89q.bukkit.migration.PermissionsResolverServerListener;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.bags.BlockBag;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
/**
|
||||
* Plugin for Bukkit.
|
||||
@ -45,9 +47,9 @@ import com.sk89q.worldedit.*;
|
||||
public class WorldEditPlugin extends JavaPlugin {
|
||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
||||
|
||||
public final ServerInterface server;
|
||||
public final WorldEdit controller;
|
||||
public final WorldEditAPI api;
|
||||
private final ServerInterface server;
|
||||
private final WorldEdit controller;
|
||||
private final WorldEditAPI api;
|
||||
|
||||
private final LocalConfiguration config;
|
||||
private final PermissionsResolverManager perms;
|
||||
@ -141,7 +143,7 @@ public class WorldEditPlugin extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public void loadConfiguration() {
|
||||
void loadConfiguration() {
|
||||
getConfiguration().load();
|
||||
config.load();
|
||||
perms.load();
|
||||
@ -178,6 +180,97 @@ public class WorldEditPlugin extends JavaPlugin {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a reference to the WorldEdit object.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public WorldEdit getWorldEdit() {
|
||||
return controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the session for the player.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public LocalSession getSession(Player player) {
|
||||
return controller.getSession(wrapPlayer(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the region selection for the player.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
* @throws IncompleteRegionException
|
||||
*/
|
||||
public Region getPlayerSelection(Player player)
|
||||
throws IncompleteRegionException {
|
||||
return controller.getSession(wrapPlayer(player)).getRegion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the session for the player.
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public EditSession createEditSession(Player player) {
|
||||
LocalPlayer wePlayer = wrapPlayer(player);
|
||||
LocalSession session = controller.getSession(wePlayer);
|
||||
BlockBag blockBag = session.getBlockBag(wePlayer);
|
||||
|
||||
EditSession editSession =
|
||||
new EditSession(wePlayer.getWorld(),
|
||||
session.getBlockChangeLimit(), blockBag);
|
||||
editSession.enableQueue();
|
||||
|
||||
return editSession;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remember an edit session.
|
||||
*
|
||||
* @param player
|
||||
* @param editSession
|
||||
*/
|
||||
public void remember(Player player, EditSession editSession) {
|
||||
LocalPlayer wePlayer = wrapPlayer(player);
|
||||
LocalSession session = controller.getSession(wePlayer);
|
||||
|
||||
session.remember(editSession);
|
||||
editSession.flushQueue();
|
||||
|
||||
controller.flushBlockBag(wePlayer, editSession);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap an operation into an EditSession.
|
||||
*
|
||||
* @param player
|
||||
* @param op
|
||||
* @throws Throwable
|
||||
*/
|
||||
public void perform(Player player, WorldEditOperation op)
|
||||
throws Throwable {
|
||||
LocalPlayer wePlayer = wrapPlayer(player);
|
||||
LocalSession session = controller.getSession(wePlayer);
|
||||
|
||||
EditSession editSession = createEditSession(player);
|
||||
try {
|
||||
op.run(session, wePlayer, editSession);
|
||||
} finally {
|
||||
remember(player, editSession);
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public WorldEditAPI getAPI() {
|
||||
return api;
|
||||
}
|
||||
|
||||
String[] getGroups(Player player) {
|
||||
return perms.getGroups(player.getName());
|
||||
}
|
||||
@ -193,8 +286,4 @@ public class WorldEditPlugin extends JavaPlugin {
|
||||
BukkitPlayer wrapPlayer(Player player) {
|
||||
return new BukkitPlayer(this, this.server, player);
|
||||
}
|
||||
|
||||
public WorldEditAPI getAPI() {
|
||||
return api;
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren