geforkt von Mirrors/FastAsyncWorldEdit
Remove chat-based WECUI protocol. Everybody running a modern (1.2.5 or newer) WECUI should be fine.
This has a bonus of allowing us to stay far far away from that smelly PlayerChatEvent guy who's always late (or early, or both).
Dieser Commit ist enthalten in:
Ursprung
ce20f33425
Commit
fe445a7ec9
123
perworldperms.diff
Normale Datei
123
perworldperms.diff
Normale Datei
@ -0,0 +1,123 @@
|
|||||||
|
diff --git a/src/main/java/com/sk89q/wepif/DinnerPermsResolver.java b/src/main/java/com/sk89q/wepif/DinnerPermsResolver.java
|
||||||
|
index 96256af..ab414ad 100644
|
||||||
|
--- a/src/main/java/com/sk89q/wepif/DinnerPermsResolver.java
|
||||||
|
+++ b/src/main/java/com/sk89q/wepif/DinnerPermsResolver.java
|
||||||
|
@@ -20,15 +20,22 @@
|
||||||
|
package com.sk89q.wepif;
|
||||||
|
|
||||||
|
import com.sk89q.util.yaml.YAMLProcessor;
|
||||||
|
+import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
+import org.bukkit.World;
|
||||||
|
+import org.bukkit.permissions.GlobalPermissionsContext;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.permissions.Permissible;
|
||||||
|
import org.bukkit.permissions.Permission;
|
||||||
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
|
+import org.bukkit.permissions.PermissionsContext;
|
||||||
|
+import org.bukkit.permissions.WorldPermissionsContext;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
+import java.util.Map;
|
||||||
|
+import java.util.WeakHashMap;
|
||||||
|
|
||||||
|
public class DinnerPermsResolver implements PermissionsResolver {
|
||||||
|
|
||||||
|
@@ -87,7 +94,27 @@ public class DinnerPermsResolver implements PermissionsResolver {
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
||||||
|
- return hasPermission(player, permission); // no per-world ability to check permissions in dinnerperms
|
||||||
|
+ Permissible perms = getPermissible(player);
|
||||||
|
+ if (perms == null) {
|
||||||
|
+ return false;
|
||||||
|
+ }
|
||||||
|
+ switch (internalHasPermission(perms, permission, worldName)) {
|
||||||
|
+ case -1:
|
||||||
|
+ return false;
|
||||||
|
+ case 1:
|
||||||
|
+ return true;
|
||||||
|
+ }
|
||||||
|
+ int dotPos = permission.lastIndexOf(".");
|
||||||
|
+ while (dotPos > -1) {
|
||||||
|
+ switch (internalHasPermission(perms, permission.substring(0, dotPos + 1) + "*", worldName)) {
|
||||||
|
+ case -1:
|
||||||
|
+ return false;
|
||||||
|
+ case 1:
|
||||||
|
+ return true;
|
||||||
|
+ }
|
||||||
|
+ dotPos = permission.lastIndexOf(".", dotPos - 1);
|
||||||
|
+ }
|
||||||
|
+ return internalHasPermission(perms, "*", worldName) == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean inGroup(OfflinePlayer player, String group) {
|
||||||
|
@@ -126,18 +153,29 @@ public class DinnerPermsResolver implements PermissionsResolver {
|
||||||
|
return perm;
|
||||||
|
}
|
||||||
|
|
||||||
|
- /**
|
||||||
|
- * Checks the permission from dinnerperms
|
||||||
|
- * @param perms Permissible to check for
|
||||||
|
- * @param permission The permission to check
|
||||||
|
- * @return -1 if the permission is explicitly denied, 1 if the permission is allowed,
|
||||||
|
- * 0 if the permission is denied by a default.
|
||||||
|
- */
|
||||||
|
- public int internalHasPermission(Permissible perms, String permission) {
|
||||||
|
- if (perms.isPermissionSet(permission)) {
|
||||||
|
- return perms.hasPermission(permission) ? 1 : -1;
|
||||||
|
+ public int internalHasPermission(Permissible perms, String name) {
|
||||||
|
+ name = name.toLowerCase();
|
||||||
|
+ if (perms.isPermissionSet(name)) {
|
||||||
|
+ return perms.hasPermission(name) ? 1 : 0;
|
||||||
|
+ }
|
||||||
|
+ Permission perm = Bukkit.getServer().getPluginManager().getPermission(name);
|
||||||
|
+ if (perm != null) {
|
||||||
|
+ return perm.getDefault().getValue(perms.isOp()) ? 1 : 0;
|
||||||
|
} else {
|
||||||
|
- Permission perm = server.getPluginManager().getPermission(permission);
|
||||||
|
+ return 0;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public int internalHasPermission(Permissible perms, String name, String contextName) {
|
||||||
|
+
|
||||||
|
+ name = name.toLowerCase();
|
||||||
|
+ PermissionsContext context = getPermissionsContext(contextName);
|
||||||
|
+ // More specific overrides less specific
|
||||||
|
+ if (perms.isPermissionSet(name, context) || perms.isPermissionSet(name, GlobalPermissionsContext.GLOBAL_CONTEXT)) {
|
||||||
|
+ return perms.hasPermission(name, context) ? 1 : -1;
|
||||||
|
+ } else {
|
||||||
|
+ Permission perm = server.getPluginManager().getPermission(name);
|
||||||
|
+
|
||||||
|
if (perm != null) {
|
||||||
|
return perm.getDefault().getValue(perms.isOp()) ? 1 : 0;
|
||||||
|
} else {
|
||||||
|
@@ -146,6 +184,25 @@ public class DinnerPermsResolver implements PermissionsResolver {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
+ private Map<String, PermissionsContext> contextLookup = new WeakHashMap<String, PermissionsContext>();
|
||||||
|
+ public PermissionsContext getPermissionsContext(String name) {
|
||||||
|
+ PermissionsContext context = contextLookup.get(name);
|
||||||
|
+ if (context == null) {
|
||||||
|
+ if (name == null || name.equalsIgnoreCase("global")) {
|
||||||
|
+ context = GlobalPermissionsContext.GLOBAL_CONTEXT;
|
||||||
|
+ } else {
|
||||||
|
+ World world = server.getWorld(name);
|
||||||
|
+ if (world != null) {
|
||||||
|
+ context = world.getPermissionsContext();
|
||||||
|
+ } else {
|
||||||
|
+ context = new WorldPermissionsContext(name);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ contextLookup.put(name, context);
|
||||||
|
+ }
|
||||||
|
+ return context;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
public String getDetectionMessage() {
|
||||||
|
return "Using the Bukkit Permissions API.";
|
||||||
|
}
|
@ -78,7 +78,6 @@ public abstract class LocalConfiguration {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public boolean profile = false;
|
public boolean profile = false;
|
||||||
public boolean enableWECUI = true;
|
|
||||||
public Set<Integer> disallowedBlocks = new HashSet<Integer>();
|
public Set<Integer> disallowedBlocks = new HashSet<Integer>();
|
||||||
public int defaultChangeLimit = -1;
|
public int defaultChangeLimit = -1;
|
||||||
public int maxChangeLimit = -1;
|
public int maxChangeLimit = -1;
|
||||||
|
@ -623,7 +623,9 @@ public abstract class LocalPlayer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Send the CUI handshake.
|
* Send the CUI handshake.
|
||||||
|
* @deprecated Not used anymore; The CUI begins the handshake
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public void dispatchCUIHandshake() {
|
public void dispatchCUIHandshake() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -602,6 +602,22 @@ public class LocalSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void handleCUIInitializationMessage(String text) {
|
||||||
|
if (hasCUISupport()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] split = text.split("\\|");
|
||||||
|
if (split.length > 1 && split[0].equalsIgnoreCase("v")) { // enough fields and right message
|
||||||
|
setCUISupport(true);
|
||||||
|
try {
|
||||||
|
setCUIVersion(Integer.parseInt(split[1]));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
WorldEdit.logger.warning("Error while reading CUI init message: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the status of CUI support.
|
* Gets the status of CUI support.
|
||||||
*
|
*
|
||||||
@ -617,7 +633,7 @@ public class LocalSession {
|
|||||||
* @param support
|
* @param support
|
||||||
*/
|
*/
|
||||||
public void setCUISupport(boolean support) {
|
public void setCUISupport(boolean support) {
|
||||||
hasCUISupport = true;
|
hasCUISupport = support;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -133,22 +133,7 @@ public class BukkitPlayer extends LocalPlayer {
|
|||||||
if (params.length > 0) {
|
if (params.length > 0) {
|
||||||
send = send + "|" + StringUtil.joinString(params, "|");
|
send = send + "|" + StringUtil.joinString(params, "|");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.hasPluginChannelCUI(getName())) {
|
|
||||||
player.sendPluginMessage(plugin, WorldEditPlugin.CUI_PLUGIN_CHANNEL, send.getBytes(CUIChannelListener.UTF_8_CHARSET));
|
player.sendPluginMessage(plugin, WorldEditPlugin.CUI_PLUGIN_CHANNEL, send.getBytes(CUIChannelListener.UTF_8_CHARSET));
|
||||||
} else {
|
|
||||||
if (plugin.getLocalConfiguration().enableWECUI) {
|
|
||||||
player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75" + send);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dispatchCUIHandshake() {
|
|
||||||
if (!plugin.hasPluginChannelCUI(getName()) && plugin.getLocalConfiguration().enableWECUI) {
|
|
||||||
player.sendRawMessage("\u00A75\u00A76\u00A74\u00A75");
|
|
||||||
player.sendRawMessage("\u00A74\u00A75\u00A73\u00A74");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
|
@ -39,19 +39,11 @@ public class CUIChannelListener implements PluginMessageListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||||
LocalSession session = plugin.getSession(player);
|
LocalSession session = plugin.getSession(player);
|
||||||
if (session.hasCUISupport() && plugin.hasPluginChannelCUI(player.getName())) { // Already initialized
|
if (session.hasCUISupport()) { // Already initialized
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] text = new String(message, UTF_8_CHARSET).split("\\|");
|
String text = new String(message, UTF_8_CHARSET);
|
||||||
if (text.length > 1 && text[0].equalsIgnoreCase("v")) { // enough fields and right message
|
session.handleCUIInitializationMessage(text);
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,23 +23,18 @@ 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;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.Action;
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.player.PlayerChatEvent;
|
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import com.sk89q.worldedit.LocalPlayer;
|
import com.sk89q.worldedit.LocalPlayer;
|
||||||
import com.sk89q.worldedit.LocalWorld;
|
import com.sk89q.worldedit.LocalWorld;
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import com.sk89q.worldedit.WorldVector;
|
import com.sk89q.worldedit.WorldVector;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles all events thrown in relation to a Player
|
* Handles all events thrown in relation to a Player
|
||||||
@ -48,7 +43,6 @@ public class WorldEditListener implements Listener {
|
|||||||
|
|
||||||
private WorldEditPlugin plugin;
|
private WorldEditPlugin plugin;
|
||||||
private boolean ignoreLeftClickAir = false;
|
private boolean ignoreLeftClickAir = false;
|
||||||
private final static Pattern cuipattern = Pattern.compile("u00a74u00a75u00a73u00a74([^\\|]*)\\|?(.*)");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player plays an animation, such as an arm swing
|
* Called when a player plays an animation, such as an arm swing
|
||||||
@ -65,20 +59,6 @@ public class WorldEditListener implements Listener {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player leaves a server
|
* Called when a player leaves a server
|
||||||
*
|
*
|
||||||
@ -87,7 +67,6 @@ 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -187,22 +166,4 @@ public class WorldEditListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true) // TODO: Remove this in a bit
|
|
||||||
public void onPlayerChat(PlayerChatEvent event) {
|
|
||||||
Matcher matcher = cuipattern.matcher(event.getMessage());
|
|
||||||
if (matcher.find()) {
|
|
||||||
String type = matcher.group(1);
|
|
||||||
String args = matcher.group(2);
|
|
||||||
|
|
||||||
if( type.equals("v") ) {
|
|
||||||
try {
|
|
||||||
plugin.getSession(event.getPlayer()).setCUIVersion(Integer.parseInt(args));
|
|
||||||
event.setCancelled(true);
|
|
||||||
} catch(NumberFormatException ignore) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -70,11 +70,6 @@ public class WorldEditPlugin extends JavaPlugin {
|
|||||||
*/
|
*/
|
||||||
private BukkitConfiguration config;
|
private BukkitConfiguration config;
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores players who are using plugin channels for the cui
|
|
||||||
*/
|
|
||||||
private final Set<String> pluginChannelCui = new HashSet<String>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called on plugin enable.
|
* Called on plugin enable.
|
||||||
*/
|
*/
|
||||||
@ -389,16 +384,4 @@ 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) {
|
|
||||||
if (value) {
|
|
||||||
pluginChannelCui.add(name);
|
|
||||||
} else {
|
|
||||||
pluginChannelCui.remove(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasPluginChannelCUI(String name) {
|
|
||||||
return pluginChannelCui.contains(name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -39,14 +39,6 @@ public class WorldEditCUIMessageHandler extends MessageHandler<WorldEditCUIMessa
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] text = message.getMessage().split("\\|");
|
localSession.handleCUIInitializationMessage(message.getMessage());
|
||||||
if (text.length > 1 && text[0].equalsIgnoreCase("v")) { // enough fields and right message
|
|
||||||
localSession.setCUISupport(true);
|
|
||||||
try {
|
|
||||||
localSession.setCUIVersion(Integer.parseInt(text[1]));
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
plugin.getLogger().warning("Error while reading CUI init message: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,11 +64,6 @@ public class WorldEditListener implements Listener {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(order = Order.EARLIEST)
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
|
||||||
plugin.wrapPlayer(event.getPlayer()).dispatchCUIHandshake();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player leaves a server
|
* Called when a player leaves a server
|
||||||
*
|
*
|
||||||
|
@ -77,7 +77,6 @@ public class PropertiesConfiguration extends LocalConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
profile = getBool("profile", profile);
|
profile = getBool("profile", profile);
|
||||||
enableWECUI = getBool("enable-wecui-handshake", enableWECUI);
|
|
||||||
disallowedBlocks = getIntSet("disallowed-blocks", defaultDisallowedBlocks);
|
disallowedBlocks = getIntSet("disallowed-blocks", defaultDisallowedBlocks);
|
||||||
defaultChangeLimit = getInt("default-max-changed-blocks", defaultChangeLimit);
|
defaultChangeLimit = getInt("default-max-changed-blocks", defaultChangeLimit);
|
||||||
maxChangeLimit = getInt("max-changed-blocks", maxChangeLimit);
|
maxChangeLimit = getInt("max-changed-blocks", maxChangeLimit);
|
||||||
|
@ -59,7 +59,6 @@ public class YAMLConfiguration extends LocalConfiguration {
|
|||||||
showFirstUseVersion = false;
|
showFirstUseVersion = false;
|
||||||
|
|
||||||
profile = config.getBoolean("debug", profile);
|
profile = config.getBoolean("debug", profile);
|
||||||
enableWECUI = config.getBoolean("enable-wecui-handshake", enableWECUI);
|
|
||||||
wandItem = config.getInt("wand-item", wandItem);
|
wandItem = config.getInt("wand-item", wandItem);
|
||||||
defaultChangeLimit = Math.max(-1, config.getInt(
|
defaultChangeLimit = Math.max(-1, config.getInt(
|
||||||
"limits.max-blocks-changed.default", defaultChangeLimit));
|
"limits.max-blocks-changed.default", defaultChangeLimit));
|
||||||
|
@ -65,4 +65,3 @@ shell-save-type:
|
|||||||
no-double-slash: false
|
no-double-slash: false
|
||||||
no-op-permissions: false
|
no-op-permissions: false
|
||||||
debug: false
|
debug: false
|
||||||
enable-wecui-handshake: true
|
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren