Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-13 22:50:06 +01:00
Added basic support for CUI.
Dieser Commit ist enthalten in:
Ursprung
ce445ce419
Commit
5ac8c5adf7
@ -22,6 +22,7 @@ package com.sk89q.worldedit;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import com.sk89q.worldedit.bags.BlockBag;
|
import com.sk89q.worldedit.bags.BlockBag;
|
||||||
import com.sk89q.worldedit.blocks.BlockType;
|
import com.sk89q.worldedit.blocks.BlockType;
|
||||||
|
import com.sk89q.worldedit.cui.CUIEvent;
|
||||||
import com.sk89q.worldedit.util.TargetBlock;
|
import com.sk89q.worldedit.util.TargetBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -575,6 +576,20 @@ public abstract class LocalPlayer {
|
|||||||
return hasPermission("worldedit.override.bedrock");
|
return hasPermission("worldedit.override.bedrock");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a CUI event.
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
public void dispatchCUIEvent(CUIEvent event) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the CUI handshake.
|
||||||
|
*/
|
||||||
|
public void dispatchCUIHandshake() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if equal.
|
* Returns true if equal.
|
||||||
*
|
*
|
||||||
|
@ -28,6 +28,10 @@ import com.sk89q.worldedit.tools.SinglePickaxe;
|
|||||||
import com.sk89q.worldedit.tools.BlockTool;
|
import com.sk89q.worldedit.tools.BlockTool;
|
||||||
import com.sk89q.worldedit.tools.Tool;
|
import com.sk89q.worldedit.tools.Tool;
|
||||||
import com.sk89q.worldedit.bags.BlockBag;
|
import com.sk89q.worldedit.bags.BlockBag;
|
||||||
|
import com.sk89q.worldedit.cui.CUIPointBasedRegion;
|
||||||
|
import com.sk89q.worldedit.cui.CUIEvent;
|
||||||
|
import com.sk89q.worldedit.cui.SelectionPointEvent;
|
||||||
|
import com.sk89q.worldedit.cui.SelectionShapeEvent;
|
||||||
import com.sk89q.worldedit.regions.CuboidRegionSelector;
|
import com.sk89q.worldedit.regions.CuboidRegionSelector;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.regions.RegionSelector;
|
import com.sk89q.worldedit.regions.RegionSelector;
|
||||||
@ -53,7 +57,7 @@ public class LocalSession {
|
|||||||
private LocalConfiguration config;
|
private LocalConfiguration config;
|
||||||
|
|
||||||
private LocalWorld selectionWorld;
|
private LocalWorld selectionWorld;
|
||||||
private RegionSelector regionSelector = new CuboidRegionSelector();
|
private RegionSelector selector = new CuboidRegionSelector();
|
||||||
private boolean placeAtPos1 = false;
|
private boolean placeAtPos1 = false;
|
||||||
private LinkedList<EditSession> history = new LinkedList<EditSession>();
|
private LinkedList<EditSession> history = new LinkedList<EditSession>();
|
||||||
private int historyPointer = 0;
|
private int historyPointer = 0;
|
||||||
@ -69,6 +73,7 @@ public class LocalSession {
|
|||||||
private String lastScript;
|
private String lastScript;
|
||||||
private CompassMode compassMode = CompassMode.JUMPTO;
|
private CompassMode compassMode = CompassMode.JUMPTO;
|
||||||
private boolean beenToldVersion = false;
|
private boolean beenToldVersion = false;
|
||||||
|
private boolean hasCUISupport = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the object.
|
* Construct the object.
|
||||||
@ -159,9 +164,9 @@ public class LocalSession {
|
|||||||
selectionWorld = world;
|
selectionWorld = world;
|
||||||
} else if (!selectionWorld.equals(world)) {
|
} else if (!selectionWorld.equals(world)) {
|
||||||
selectionWorld = world;
|
selectionWorld = world;
|
||||||
regionSelector.clear();
|
selector.clear();
|
||||||
}
|
}
|
||||||
return regionSelector;
|
return selector;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -171,7 +176,7 @@ public class LocalSession {
|
|||||||
* @return position
|
* @return position
|
||||||
*/
|
*/
|
||||||
public RegionSelector getRegionSelector() {
|
public RegionSelector getRegionSelector() {
|
||||||
return regionSelector;
|
return selector;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -182,7 +187,7 @@ public class LocalSession {
|
|||||||
*/
|
*/
|
||||||
public void setRegionSelector(LocalWorld world, RegionSelector selector) {
|
public void setRegionSelector(LocalWorld world, RegionSelector selector) {
|
||||||
selectionWorld = world;
|
selectionWorld = world;
|
||||||
regionSelector = selector;
|
this.selector = selector;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -192,7 +197,7 @@ public class LocalSession {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean isRegionDefined() {
|
public boolean isRegionDefined() {
|
||||||
return regionSelector.isDefined();
|
return selector.isDefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -205,7 +210,7 @@ public class LocalSession {
|
|||||||
if (selectionWorld == null || !selectionWorld.equals(world)) {
|
if (selectionWorld == null || !selectionWorld.equals(world)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return regionSelector.isDefined();
|
return selector.isDefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -216,7 +221,7 @@ public class LocalSession {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Region getRegion() throws IncompleteRegionException {
|
public Region getRegion() throws IncompleteRegionException {
|
||||||
return regionSelector.getRegion();
|
return selector.getRegion();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -233,7 +238,7 @@ public class LocalSession {
|
|||||||
if (selectionWorld == null || !selectionWorld.equals(world)) {
|
if (selectionWorld == null || !selectionWorld.equals(world)) {
|
||||||
throw new IncompleteRegionException();
|
throw new IncompleteRegionException();
|
||||||
}
|
}
|
||||||
return regionSelector.getRegion();
|
return selector.getRegion();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -340,7 +345,7 @@ public class LocalSession {
|
|||||||
return player.getBlockIn();
|
return player.getBlockIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
return regionSelector.getPrimaryPosition();
|
return selector.getPrimaryPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -519,4 +524,55 @@ public class LocalSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatch a CUI event but only if the player has CUI support.
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
public void dispatchCUIEvent(LocalPlayer player, CUIEvent event) {
|
||||||
|
if (hasCUISupport) {
|
||||||
|
player.dispatchCUIEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatch the initial setup CUI messages.
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
*/
|
||||||
|
public void dispatchCUISetup(LocalPlayer player) {
|
||||||
|
if (!hasCUISupport) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selector != null) {
|
||||||
|
player.dispatchCUIEvent(
|
||||||
|
new SelectionShapeEvent(selector.getTypeId()));
|
||||||
|
|
||||||
|
if (selector instanceof CUIPointBasedRegion) {
|
||||||
|
Vector[] points = ((CUIPointBasedRegion) selector).getCUIPoints();
|
||||||
|
int size = selector.getArea();
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for (Vector pt : points) {
|
||||||
|
if (pt != null) {
|
||||||
|
player.dispatchCUIEvent(
|
||||||
|
new SelectionPointEvent(i, pt, size));
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the status of CUI support.
|
||||||
|
*
|
||||||
|
* @param support
|
||||||
|
*/
|
||||||
|
public void setCUISupport(boolean support) {
|
||||||
|
hasCUISupport = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -820,7 +820,7 @@ public class WorldEdit {
|
|||||||
&& player.hasPermission("worldedit.selection.pos")) {
|
&& player.hasPermission("worldedit.selection.pos")) {
|
||||||
RegionSelector selector = session.getRegionSelector(player.getWorld());
|
RegionSelector selector = session.getRegionSelector(player.getWorld());
|
||||||
if (selector.selectSecondary(clicked)) {
|
if (selector.selectSecondary(clicked)) {
|
||||||
selector.explainSecondarySelection(player, clicked);
|
selector.explainSecondarySelection(player, session, clicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -857,7 +857,7 @@ public class WorldEdit {
|
|||||||
|
|
||||||
RegionSelector selector = session.getRegionSelector(player.getWorld());
|
RegionSelector selector = session.getRegionSelector(player.getWorld());
|
||||||
if (selector.selectPrimary(clicked)) {
|
if (selector.selectPrimary(clicked)) {
|
||||||
selector.explainPrimarySelection(player, clicked);
|
selector.explainPrimarySelection(player, session, clicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -22,8 +22,10 @@ package com.sk89q.worldedit.bukkit;
|
|||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import com.sk89q.util.StringUtil;
|
||||||
import com.sk89q.worldedit.*;
|
import com.sk89q.worldedit.*;
|
||||||
import com.sk89q.worldedit.bags.BlockBag;
|
import com.sk89q.worldedit.bags.BlockBag;
|
||||||
|
import com.sk89q.worldedit.cui.CUIEvent;
|
||||||
|
|
||||||
public class BukkitPlayer extends LocalPlayer {
|
public class BukkitPlayer extends LocalPlayer {
|
||||||
private Player player;
|
private Player player;
|
||||||
@ -114,4 +116,21 @@ public class BukkitPlayer extends LocalPlayer {
|
|||||||
public LocalWorld getWorld() {
|
public LocalWorld getWorld() {
|
||||||
return new BukkitWorld(player.getWorld());
|
return new BukkitWorld(player.getWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispatchCUIEvent(CUIEvent event) {
|
||||||
|
String[] params = event.getParameters();
|
||||||
|
|
||||||
|
if (params.length > 0) {
|
||||||
|
printRaw("\u00A75\u00A76\u00A74\u00A75" + event.getTypeId()
|
||||||
|
+ "|" + StringUtil.joinString(params, "|"));
|
||||||
|
} else {
|
||||||
|
printRaw("\u00A75\u00A76\u00A74\u00A75" + event.getTypeId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispatchCUIHandshake() {
|
||||||
|
printRaw("\u00A75\u00A76\u00A74\u00A75");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
57
src/com/sk89q/worldedit/bukkit/WorldEditCriticalPlayerListener.java
Normale Datei
57
src/com/sk89q/worldedit/bukkit/WorldEditCriticalPlayerListener.java
Normale Datei
@ -0,0 +1,57 @@
|
|||||||
|
// $Id$
|
||||||
|
/*
|
||||||
|
* WorldEdit
|
||||||
|
* Copyright (C) 2010 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.bukkit;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
|
import org.bukkit.event.player.PlayerListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles all events thrown in relation to a Player
|
||||||
|
*/
|
||||||
|
public class WorldEditCriticalPlayerListener extends PlayerListener {
|
||||||
|
/**
|
||||||
|
* Plugin.
|
||||||
|
*/
|
||||||
|
private WorldEditPlugin plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the object;
|
||||||
|
*
|
||||||
|
* @param plugin
|
||||||
|
*/
|
||||||
|
public WorldEditCriticalPlayerListener(WorldEditPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a player joins a server
|
||||||
|
*
|
||||||
|
* @param event Relevant event details
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onPlayerJoin(PlayerEvent event) {
|
||||||
|
wrapPlayer(event.getPlayer()).dispatchCUIHandshake();
|
||||||
|
}
|
||||||
|
|
||||||
|
private BukkitPlayer wrapPlayer(Player player) {
|
||||||
|
return new BukkitPlayer(plugin, plugin.server, player);
|
||||||
|
}
|
||||||
|
}
|
@ -123,6 +123,7 @@ public class WorldEditPlugin extends JavaPlugin {
|
|||||||
*/
|
*/
|
||||||
protected void registerEvents() {
|
protected void registerEvents() {
|
||||||
PlayerListener playerListener = new WorldEditPlayerListener(this);
|
PlayerListener playerListener = new WorldEditPlayerListener(this);
|
||||||
|
PlayerListener criticalPlayerListener = new WorldEditCriticalPlayerListener(this);
|
||||||
BlockListener blockListener = new WorldEditBlockListener(this);
|
BlockListener blockListener = new WorldEditBlockListener(this);
|
||||||
|
|
||||||
registerEvent(Event.Type.PLAYER_QUIT, playerListener);
|
registerEvent(Event.Type.PLAYER_QUIT, playerListener);
|
||||||
@ -131,6 +132,7 @@ public class WorldEditPlugin extends JavaPlugin {
|
|||||||
registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener);
|
registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener);
|
||||||
registerEvent(Event.Type.BLOCK_DAMAGED, blockListener);
|
registerEvent(Event.Type.BLOCK_DAMAGED, blockListener);
|
||||||
registerEvent(Event.Type.BLOCK_RIGHTCLICKED, blockListener);
|
registerEvent(Event.Type.BLOCK_RIGHTCLICKED, blockListener);
|
||||||
|
registerEvent(Event.Type.PLAYER_JOIN, criticalPlayerListener, Priority.Lowest);
|
||||||
|
|
||||||
// The permissions resolver has some hooks of its own
|
// The permissions resolver has some hooks of its own
|
||||||
(new PermissionsResolverServerListener(perms)).register(this);
|
(new PermissionsResolverServerListener(perms)).register(this);
|
||||||
|
@ -58,7 +58,7 @@ public class SelectionCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
session.getRegionSelector(player.getWorld())
|
session.getRegionSelector(player.getWorld())
|
||||||
.explainPrimarySelection(player, player.getBlockIn());
|
.explainPrimarySelection(player, session, player.getBlockIn());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
@ -81,7 +81,7 @@ public class SelectionCommands {
|
|||||||
|
|
||||||
|
|
||||||
session.getRegionSelector(player.getWorld())
|
session.getRegionSelector(player.getWorld())
|
||||||
.explainSecondarySelection(player, player.getBlockIn());
|
.explainSecondarySelection(player, session, player.getBlockIn());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
@ -106,7 +106,7 @@ public class SelectionCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
session.getRegionSelector(player.getWorld())
|
session.getRegionSelector(player.getWorld())
|
||||||
.explainPrimarySelection(player, pos);
|
.explainPrimarySelection(player, session, pos);
|
||||||
} else {
|
} else {
|
||||||
player.printError("No block in sight!");
|
player.printError("No block in sight!");
|
||||||
}
|
}
|
||||||
@ -134,7 +134,7 @@ public class SelectionCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
session.getRegionSelector(player.getWorld())
|
session.getRegionSelector(player.getWorld())
|
||||||
.explainSecondarySelection(player, pos);
|
.explainSecondarySelection(player, session, pos);
|
||||||
} else {
|
} else {
|
||||||
player.printError("No block in sight!");
|
player.printError("No block in sight!");
|
||||||
}
|
}
|
||||||
|
@ -59,4 +59,18 @@ public class WorldEditCommands {
|
|||||||
we.getServer().reload();
|
we.getServer().reload();
|
||||||
player.print("Configuration reloaded!");
|
player.print("Configuration reloaded!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Command(
|
||||||
|
aliases = {"cui"},
|
||||||
|
usage = "",
|
||||||
|
desc = "Complete CUI handshake",
|
||||||
|
min = 0,
|
||||||
|
max = 0
|
||||||
|
)
|
||||||
|
public static void cui(CommandContext args, WorldEdit we,
|
||||||
|
LocalSession session, LocalPlayer player, EditSession editSession)
|
||||||
|
throws WorldEditException {
|
||||||
|
session.setCUISupport(true);
|
||||||
|
session.dispatchCUISetup(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
25
src/com/sk89q/worldedit/cui/CUIEvent.java
Normale Datei
25
src/com/sk89q/worldedit/cui/CUIEvent.java
Normale Datei
@ -0,0 +1,25 @@
|
|||||||
|
// $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.cui;
|
||||||
|
|
||||||
|
public interface CUIEvent {
|
||||||
|
public String getTypeId();
|
||||||
|
public String[] getParameters();
|
||||||
|
}
|
26
src/com/sk89q/worldedit/cui/CUIPointBasedRegion.java
Normale Datei
26
src/com/sk89q/worldedit/cui/CUIPointBasedRegion.java
Normale Datei
@ -0,0 +1,26 @@
|
|||||||
|
// $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.cui;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.Vector;
|
||||||
|
|
||||||
|
public interface CUIPointBasedRegion {
|
||||||
|
public Vector[] getCUIPoints();
|
||||||
|
}
|
52
src/com/sk89q/worldedit/cui/SelectionPointEvent.java
Normale Datei
52
src/com/sk89q/worldedit/cui/SelectionPointEvent.java
Normale Datei
@ -0,0 +1,52 @@
|
|||||||
|
// $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.cui;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.Vector;
|
||||||
|
|
||||||
|
public class SelectionPointEvent implements CUIEvent {
|
||||||
|
|
||||||
|
protected int id;
|
||||||
|
protected Vector pos;
|
||||||
|
protected int area;
|
||||||
|
|
||||||
|
public SelectionPointEvent(int id, Vector pos, int area) {
|
||||||
|
this.id = id;
|
||||||
|
this.pos = pos;
|
||||||
|
this.area = area;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTypeId() {
|
||||||
|
return "p";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getParameters() {
|
||||||
|
return new String[] {
|
||||||
|
String.valueOf(id),
|
||||||
|
String.valueOf(pos.getBlockX()),
|
||||||
|
String.valueOf(pos.getBlockY()),
|
||||||
|
String.valueOf(pos.getBlockZ()),
|
||||||
|
String.valueOf(area)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
40
src/com/sk89q/worldedit/cui/SelectionShapeEvent.java
Normale Datei
40
src/com/sk89q/worldedit/cui/SelectionShapeEvent.java
Normale Datei
@ -0,0 +1,40 @@
|
|||||||
|
// $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.cui;
|
||||||
|
|
||||||
|
public class SelectionShapeEvent implements CUIEvent {
|
||||||
|
|
||||||
|
protected String shapeName;
|
||||||
|
|
||||||
|
public SelectionShapeEvent(String shapeName) {
|
||||||
|
this.shapeName = shapeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTypeId() {
|
||||||
|
return "s";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getParameters() {
|
||||||
|
return new String[] { shapeName };
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -24,14 +24,17 @@ import java.util.List;
|
|||||||
import com.sk89q.worldedit.BlockVector;
|
import com.sk89q.worldedit.BlockVector;
|
||||||
import com.sk89q.worldedit.IncompleteRegionException;
|
import com.sk89q.worldedit.IncompleteRegionException;
|
||||||
import com.sk89q.worldedit.LocalPlayer;
|
import com.sk89q.worldedit.LocalPlayer;
|
||||||
|
import com.sk89q.worldedit.LocalSession;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
|
import com.sk89q.worldedit.cui.CUIPointBasedRegion;
|
||||||
|
import com.sk89q.worldedit.cui.SelectionPointEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selector for cuboids.
|
* Selector for cuboids.
|
||||||
*
|
*
|
||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class CuboidRegionSelector implements RegionSelector {
|
public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion {
|
||||||
protected BlockVector pos1;
|
protected BlockVector pos1;
|
||||||
protected BlockVector pos2;
|
protected BlockVector pos2;
|
||||||
protected CuboidRegion region = new CuboidRegion(new Vector(), new Vector());
|
protected CuboidRegion region = new CuboidRegion(new Vector(), new Vector());
|
||||||
@ -54,22 +57,30 @@ public class CuboidRegionSelector implements RegionSelector {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void explainPrimarySelection(LocalPlayer player, Vector pos) {
|
public void explainPrimarySelection(LocalPlayer player,
|
||||||
|
LocalSession session, Vector pos) {
|
||||||
if (pos1 != null && pos2 != null) {
|
if (pos1 != null && pos2 != null) {
|
||||||
player.print("First position set to " + pos1
|
player.print("First position set to " + pos1
|
||||||
+ " (" + region.getArea() + ").");
|
+ " (" + region.getArea() + ").");
|
||||||
} else {
|
} else {
|
||||||
player.print("First position set to " + pos1 + ".");
|
player.print("First position set to " + pos1 + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
session.dispatchCUIEvent(player,
|
||||||
|
new SelectionPointEvent(0, pos, getArea()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void explainSecondarySelection(LocalPlayer player, Vector pos) {
|
public void explainSecondarySelection(LocalPlayer player,
|
||||||
|
LocalSession session, Vector pos) {
|
||||||
if (pos1 != null && pos2 != null) {
|
if (pos1 != null && pos2 != null) {
|
||||||
player.print("Second position set to " + pos2
|
player.print("Second position set to " + pos2
|
||||||
+ " (" + region.getArea() + ").");
|
+ " (" + region.getArea() + ").");
|
||||||
} else {
|
} else {
|
||||||
player.print("Second position set to " + pos2 + ".");
|
player.print("Second position set to " + pos2 + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
session.dispatchCUIEvent(player,
|
||||||
|
new SelectionPointEvent(1, pos, getArea()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockVector getPrimaryPosition() throws IncompleteRegionException {
|
public BlockVector getPrimaryPosition() throws IncompleteRegionException {
|
||||||
@ -119,4 +130,20 @@ public class CuboidRegionSelector implements RegionSelector {
|
|||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTypeId() {
|
||||||
|
return "cuboid";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector[] getCUIPoints() {
|
||||||
|
return new Vector[] { pos1, pos2 };
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getArea() {
|
||||||
|
if (pos1 != null && pos2 != null) {
|
||||||
|
return region.getArea();
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ import com.sk89q.worldedit.BlockVector;
|
|||||||
import com.sk89q.worldedit.BlockVector2D;
|
import com.sk89q.worldedit.BlockVector2D;
|
||||||
import com.sk89q.worldedit.IncompleteRegionException;
|
import com.sk89q.worldedit.IncompleteRegionException;
|
||||||
import com.sk89q.worldedit.LocalPlayer;
|
import com.sk89q.worldedit.LocalPlayer;
|
||||||
|
import com.sk89q.worldedit.LocalSession;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,11 +67,13 @@ public class Polygonal2DRegionSelector implements RegionSelector {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void explainPrimarySelection(LocalPlayer player, Vector pos) {
|
public void explainPrimarySelection(LocalPlayer player,
|
||||||
|
LocalSession session, Vector pos) {
|
||||||
player.print("Starting a new polygon at " + pos + ".");
|
player.print("Starting a new polygon at " + pos + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void explainSecondarySelection(LocalPlayer player, Vector pos) {
|
public void explainSecondarySelection(LocalPlayer player,
|
||||||
|
LocalSession session, Vector pos) {
|
||||||
player.print("Added point #" + region.size() + " at " + pos + ".");
|
player.print("Added point #" + region.size() + " at " + pos + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,4 +114,12 @@ public class Polygonal2DRegionSelector implements RegionSelector {
|
|||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTypeId() {
|
||||||
|
return "polygon2d";
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getArea() {
|
||||||
|
return region.getArea();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import java.util.List;
|
|||||||
import com.sk89q.worldedit.BlockVector;
|
import com.sk89q.worldedit.BlockVector;
|
||||||
import com.sk89q.worldedit.IncompleteRegionException;
|
import com.sk89q.worldedit.IncompleteRegionException;
|
||||||
import com.sk89q.worldedit.LocalPlayer;
|
import com.sk89q.worldedit.LocalPlayer;
|
||||||
|
import com.sk89q.worldedit.LocalSession;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,17 +52,21 @@ public interface RegionSelector {
|
|||||||
* Tell the player information about his/her primary selection.
|
* Tell the player information about his/her primary selection.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
|
* @param session
|
||||||
* @param pos
|
* @param pos
|
||||||
*/
|
*/
|
||||||
public void explainPrimarySelection(LocalPlayer player, Vector pos);
|
public void explainPrimarySelection(LocalPlayer player,
|
||||||
|
LocalSession session, Vector pos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tell the player information about his/her secondary selection.
|
* Tell the player information about his/her secondary selection.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
|
* @param session
|
||||||
* @param pos
|
* @param pos
|
||||||
*/
|
*/
|
||||||
public void explainSecondarySelection(LocalPlayer player, Vector pos);
|
public void explainSecondarySelection(LocalPlayer player,
|
||||||
|
LocalSession session, Vector pos);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the primary position.
|
* Get the primary position.
|
||||||
@ -86,6 +91,13 @@ public interface RegionSelector {
|
|||||||
*/
|
*/
|
||||||
public boolean isDefined();
|
public boolean isDefined();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of blocks inside the region.
|
||||||
|
*
|
||||||
|
* @return number of blocks or -1 if undefined
|
||||||
|
*/
|
||||||
|
public int getArea();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the selector with changes to the region.
|
* Update the selector with changes to the region.
|
||||||
*/
|
*/
|
||||||
@ -103,6 +115,13 @@ public interface RegionSelector {
|
|||||||
*/
|
*/
|
||||||
public String getTypeName();
|
public String getTypeName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a lowecase space-less ID.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getTypeId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get lines of information about the selection.
|
* Get lines of information about the selection.
|
||||||
*
|
*
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren