3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-05 02:50:05 +01:00

Added initial support for plugin channels with WECUI

Dieser Commit ist enthalten in:
zml2008 2012-03-27 22:52:48 -07:00
Ursprung bbda908093
Commit a4895cbd5d
10 geänderte Dateien mit 123 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -129,19 +129,24 @@ public class BukkitPlayer extends LocalPlayer {
@Override @Override
public void dispatchCUIEvent(CUIEvent event) { public void dispatchCUIEvent(CUIEvent event) {
String[] params = event.getParameters(); String[] params = event.getParameters();
String send = event.getTypeId();
if (params.length > 0) { if (params.length > 0) {
player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75" + event.getTypeId() send = send + "|" + StringUtil.joinString(params, "|");
+ "|" + StringUtil.joinString(params, "|")); }
if (plugin.hasPluginChannelCUI(getName())) {
player.sendPluginMessage(plugin, WorldEditPlugin.CUI_PLUGIN_CHANNEL, send.getBytes(CUIChannelListener.UTF_8_CHARSET));
} else { } else {
player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75" + event.getTypeId()); player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75" + send);
} }
} }
@Override @Override
public void dispatchCUIHandshake() { public void dispatchCUIHandshake() {
player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75"); if (!plugin.hasPluginChannelCUI(getName())) {
player.sendRawMessage("\u00A74\u00A75\u00A73\u00A74"); player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75");
player.sendRawMessage("\u00A74\u00A75\u00A73\u00A74");
}
} }
public Player getPlayer() { public Player getPlayer() {

Datei anzeigen

@ -0,0 +1,57 @@
/*
* WorldEdit
* Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
*
* 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 com.sk89q.worldedit.LocalSession;
import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener;
import java.nio.charset.Charset;
/**
* Handles incoming WorldEditCui init message
* @author zml2008
*/
public class CUIChannelListener implements PluginMessageListener {
public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
private final WorldEditPlugin plugin;
public CUIChannelListener(WorldEditPlugin plugin) {
this.plugin = plugin;
}
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
LocalSession session = plugin.getSession(player);
if (session.hasCUISupport()) { // Already initialized
return;
}
String[] text = new String(message, UTF_8_CHARSET).split("\\|");
if (text.length > 1 && text[0].equalsIgnoreCase("v")) { // enough fields and right message
plugin.setPluginChannelCUI(player.getName(), true);
session.setCUISupport(true);
try {
session.setCUIVersion(Integer.parseInt(text[1]));
} catch (NumberFormatException e) {
plugin.getLogger().warning("Error while reading CUI init message: " + e.getMessage());
}
}
}
}

Datei anzeigen

@ -23,6 +23,7 @@ package com.sk89q.worldedit.bukkit;
import com.sk89q.util.StringUtil; import com.sk89q.util.StringUtil;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Result; import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -66,7 +67,16 @@ public class WorldEditListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
plugin.wrapPlayer(event.getPlayer()).dispatchCUIHandshake(); final Player player = event.getPlayer();
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
if (player.isOnline()) {
plugin.wrapPlayer(player).dispatchCUIHandshake();
}
}
}, 20 * 2);
} }
/** /**
@ -77,6 +87,7 @@ public class WorldEditListener implements Listener {
@EventHandler @EventHandler
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
plugin.getWorldEdit().markExpire(plugin.wrapPlayer(event.getPlayer())); plugin.getWorldEdit().markExpire(plugin.wrapPlayer(event.getPlayer()));
plugin.setPluginChannelCUI(event.getPlayer().getName(), false);
} }
/** /**
@ -177,7 +188,7 @@ public class WorldEditListener implements Listener {
} }
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true) // TODO: Remove this in a bit
public void onPlayerChat(PlayerChatEvent event) { public void onPlayerChat(PlayerChatEvent event) {
Matcher matcher = cuipattern.matcher(event.getMessage()); Matcher matcher = cuipattern.matcher(event.getMessage());
if (matcher.find()) { if (matcher.find()) {

Datei anzeigen

@ -24,6 +24,8 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
@ -45,6 +47,12 @@ import com.sk89q.worldedit.regions.*;
* @author sk89q * @author sk89q
*/ */
public class WorldEditPlugin extends JavaPlugin { public class WorldEditPlugin extends JavaPlugin {
/**
* The name of the CUI's plugin channel registration
*/
public static final String CUI_PLUGIN_CHANNEL = "WECUI";
/** /**
* WorldEdit messages get sent here. * WorldEdit messages get sent here.
*/ */
@ -68,6 +76,11 @@ public class WorldEditPlugin extends JavaPlugin {
*/ */
private BukkitConfiguration config; private BukkitConfiguration config;
/**
* Stores players who are using plugin channels for the cui
*/
private final Map<String, Boolean> pluginChannelCui = new HashMap<String, Boolean>();
/** /**
* Called on plugin enable. * Called on plugin enable.
*/ */
@ -97,6 +110,8 @@ public class WorldEditPlugin extends JavaPlugin {
server = new BukkitServerInterface(this, getServer()); server = new BukkitServerInterface(this, getServer());
controller = new WorldEdit(server, config); controller = new WorldEdit(server, config);
api = new WorldEditAPI(this); api = new WorldEditAPI(this);
getServer().getMessenger().registerIncomingPluginChannel(this, CUI_PLUGIN_CHANNEL, new CUIChannelListener(this));
getServer().getMessenger().registerOutgoingPluginChannel(this, CUI_PLUGIN_CHANNEL);
// Now we can register events! // Now we can register events!
getServer().getPluginManager().registerEvents(new WorldEditListener(this), this); getServer().getPluginManager().registerEvents(new WorldEditListener(this), this);
@ -381,4 +396,17 @@ public class WorldEditPlugin extends JavaPlugin {
session.setRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()), sel); session.setRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()), sel);
session.dispatchCUISelection(wrapPlayer(player)); session.dispatchCUISelection(wrapPlayer(player));
} }
public void setPluginChannelCUI(String name, boolean value) {
pluginChannelCui.put(name, value);
}
public boolean hasPluginChannelCUI(String name) {
Boolean val = pluginChannelCui.get(name);
if (val == null) {
return false;
} else {
return val;
}
}
} }

Datei anzeigen

@ -23,8 +23,8 @@ import com.sk89q.worldedit.Vector2D;
public class SelectionCylinderEvent implements CUIEvent { public class SelectionCylinderEvent implements CUIEvent {
protected Vector pos; protected final Vector pos;
protected Vector2D radius; protected final Vector2D radius;
public SelectionCylinderEvent(Vector pos, Vector2D radius) { public SelectionCylinderEvent(Vector pos, Vector2D radius) {
this.pos = pos; this.pos = pos;

Datei anzeigen

@ -22,8 +22,8 @@ package com.sk89q.worldedit.cui;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
public class SelectionEllipsoidPointEvent implements CUIEvent { public class SelectionEllipsoidPointEvent implements CUIEvent {
protected int id; protected final int id;
protected Vector pos; protected final Vector pos;
public SelectionEllipsoidPointEvent(int id, Vector pos) { public SelectionEllipsoidPointEvent(int id, Vector pos) {
this.id = id; this.id = id;

Datei anzeigen

@ -21,8 +21,8 @@ package com.sk89q.worldedit.cui;
public class SelectionMinMaxEvent implements CUIEvent { public class SelectionMinMaxEvent implements CUIEvent {
protected int min; protected final int min;
protected int max; protected final int max;
public SelectionMinMaxEvent(int min, int max) { public SelectionMinMaxEvent(int min, int max) {
this.min = min; this.min = min;

Datei anzeigen

@ -24,10 +24,10 @@ import com.sk89q.worldedit.Vector2D;
public class SelectionPoint2DEvent implements CUIEvent { public class SelectionPoint2DEvent implements CUIEvent {
protected int id; protected final int id;
protected int blockx; protected final int blockx;
protected int blockz; protected final int blockz;
protected int area; protected final int area;
public SelectionPoint2DEvent(int id, Vector2D pos, int area) { public SelectionPoint2DEvent(int id, Vector2D pos, int area) {
this.id = id; this.id = id;

Datei anzeigen

@ -23,9 +23,9 @@ import com.sk89q.worldedit.Vector;
public class SelectionPointEvent implements CUIEvent { public class SelectionPointEvent implements CUIEvent {
protected int id; protected final int id;
protected Vector pos; protected final Vector pos;
protected int area; protected final int area;
public SelectionPointEvent(int id, Vector pos, int area) { public SelectionPointEvent(int id, Vector pos, int area) {
this.id = id; this.id = id;

Datei anzeigen

@ -21,7 +21,7 @@ package com.sk89q.worldedit.cui;
public class SelectionShapeEvent implements CUIEvent { public class SelectionShapeEvent implements CUIEvent {
protected String shapeName; protected final String shapeName;
public SelectionShapeEvent(String shapeName) { public SelectionShapeEvent(String shapeName) {
this.shapeName = shapeName; this.shapeName = shapeName;