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

Added permissions and configuration support.

Dieser Commit ist enthalten in:
sk89q 2011-01-16 13:19:29 -08:00
Ursprung 94b2b4713e
Commit e6c101a307
7 geänderte Dateien mit 171 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -104,4 +104,13 @@ public class ConfigurationPermissionsResolver {
return groups.contains(group);
}
public String[] getGroups(String player) {
Set<String> groups = userGroups.get(player.toLowerCase());
if (groups == null) {
return new String[0];
}
return (String[])groups.toArray();
}
}

Datei anzeigen

@ -0,0 +1,103 @@
// $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 java.io.IOException;
import java.util.HashSet;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.util.config.Configuration;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LogFormat;
import com.sk89q.worldedit.snapshots.SnapshotRepository;
public class BukkitConfiguration extends LocalConfiguration {
private Configuration config;
private Logger logger;
public BukkitConfiguration(Configuration config, Logger logger) {
this.config = config;
this.logger = logger;
}
@Override
public void load() {
profile = config.getBoolean("debug", profile);
wandItem = config.getInt("wand-item", wandItem);
defaultChangeLimit = Math.max(-1, config.getInt(
"limits.max-blocks-changed.default", defaultChangeLimit));
maxChangeLimit = Math.max(-1,
config.getInt("limits.max-blocks-changed.maximum", maxChangeLimit));
maxRadius = Math.max(-1, config.getInt("limits.max-radius", maxRadius));
maxSuperPickaxeSize = Math.max(1, config.getInt(
"limits.max-super-pickaxe-size", maxSuperPickaxeSize));
registerHelp = true;
logComands = config.getBoolean("logging.log-commands", logComands);
superPickaxeDrop = config.getBoolean("super-pickaxe.drop-items",
superPickaxeDrop);
superPickaxeManyDrop = config.getBoolean(
"super-pickaxe.many-drop-items", superPickaxeManyDrop);
noDoubleSlash = config.getBoolean("no-double-slash", noDoubleSlash);
useInventory = config.getBoolean("use-inventory.enable", useInventory);
useInventoryOverride = config.getBoolean("use-inventory.allow-override",
useInventoryOverride);
maxBrushRadius = config.getInt("limits.max-brush-radius", maxBrushRadius);
// Get disallowed blocks
disallowedBlocks = new HashSet<Integer>();
String defdisallowedBlocks = StringUtil.joinString(defaultDisallowedBlocks, ",", 0);
for (String b : config.getString("limits.disallowed-blocks",
defdisallowedBlocks).split(",")) {
try {
disallowedBlocks.add(Integer.parseInt(b));
} catch (NumberFormatException e) {
}
}
String snapshotsDir = config.getString("snapshots.directry", "");
if (!snapshotsDir.trim().equals("")) {
snapshotRepo = new SnapshotRepository(snapshotsDir);
} else {
snapshotRepo = null;
}
String type = config.getString("shell-save-type", "").trim();
shellSaveType = type.equals("") ? null : type;
String logFile = config.getString("logging.file", "");
if (!logFile.equals("")) {
try {
FileHandler handler = new FileHandler(logFile, true);
handler.setFormatter(new LogFormat());
logger.addHandler(handler);
} catch (IOException e) {
logger.log(Level.WARNING, "Could not use log file " + logFile + ": "
+ e.getMessage());
}
} else {
for (Handler handler : logger.getHandlers()) {
logger.removeHandler(handler);
}
}
}
}

Datei anzeigen

@ -27,9 +27,11 @@ import com.sk89q.worldedit.bags.BlockBag;
public class BukkitPlayer extends LocalPlayer {
private Player player;
private WorldEditPlugin plugin;
public BukkitPlayer(ServerInterface server, Player player) {
public BukkitPlayer(WorldEditPlugin plugin, ServerInterface server, Player player) {
super(server);
this.plugin = plugin;
this.player = player;
}
@ -109,8 +111,7 @@ public class BukkitPlayer extends LocalPlayer {
@Override
public String[] getGroups() {
// TODO Auto-generated method stub
return null;
return plugin.getGroups(player);
}
@Override
@ -121,8 +122,7 @@ public class BukkitPlayer extends LocalPlayer {
@Override
public boolean hasPermission(String perm) {
// TODO Auto-generated method stub
return true;
return plugin.hasPermission(player, "/" + perm);
}
@Override

Datei anzeigen

@ -36,6 +36,6 @@ public class WorldEditAPI {
* @return
*/
public LocalSession getSession(Player player) {
return plugin.controller.getSession(new BukkitPlayer(plugin.server, player));
return plugin.controller.getSession(new BukkitPlayer(plugin, plugin.server, player));
}
}

Datei anzeigen

@ -72,6 +72,6 @@ public class WorldEditBlockListener extends BlockListener {
}
private BukkitPlayer wrapPlayer(Player player) {
return new BukkitPlayer(plugin.server, player);
return new BukkitPlayer(plugin, plugin.server, player);
}
}

Datei anzeigen

@ -19,7 +19,6 @@
package com.sk89q.worldedit.bukkit;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerEvent;
@ -58,13 +57,31 @@ public class WorldEditPlayerListener extends PlayerListener {
* @param event Relevant event details
*/
public void onPlayerCommand(PlayerChatEvent event) {
if (plugin.controller.handleCommand(wrapPlayer(event.getPlayer()),
event.getMessage().split(" "))) {
String[] split = event.getMessage().split(" ");
if (split[0].equalsIgnoreCase("/reload")
&& plugin.hasPermission(event.getPlayer(), "/reload")
&& split.length > 1) {
if (split[1].equalsIgnoreCase("WorldEdit")) {
try {
plugin.loadConfiguration();
event.getPlayer().sendMessage("WorldEdit configuration reloaded.");
} catch (Throwable t) {
event.getPlayer().sendMessage("Error while reloading: "
+ t.getMessage());
}
event.setCancelled(true);
return;
}
}
if (plugin.controller.handleCommand(wrapPlayer(event.getPlayer()), split)) {
event.setCancelled(true);
}
}
private BukkitPlayer wrapPlayer(Player player) {
return new BukkitPlayer(plugin.server, player);
return new BukkitPlayer(plugin, plugin.server, player);
}
}

Datei anzeigen

@ -20,13 +20,15 @@
package com.sk89q.worldedit.bukkit;
import java.io.File;
import java.util.HashSet;
import java.util.logging.Logger;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.bukkit.migration.ConfigurationPermissionsResolver;
import com.sk89q.worldedit.*;
/**
@ -35,37 +37,37 @@ import com.sk89q.worldedit.*;
* @author sk89qs
*/
public class WorldEditPlugin extends JavaPlugin {
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
public final ServerInterface server;
public final WorldEditController controller;
public final WorldEditAPI api;
private final LocalConfiguration config;
private final WorldEditPlayerListener playerListener =
new WorldEditPlayerListener(this);
private final WorldEditBlockListener blockListener =
new WorldEditBlockListener(this);
private final ConfigurationPermissionsResolver perms;
public WorldEditPlugin(PluginLoader pluginLoader, Server instance,
PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
super(pluginLoader, instance, desc, folder, plugin, cLoader);
LocalConfiguration config = new LocalConfiguration() {
@Override
public void load() {
// TODO Auto-generated method stub
disallowedBlocks = new HashSet<Integer>();
}
};
logger.info("WorldEdit " + desc.getVersion() + " loaded.");
config = new BukkitConfiguration(getConfiguration(), logger);
perms = new ConfigurationPermissionsResolver(getConfiguration());
loadConfiguration();
server = new BukkitServerInterface(getServer());
controller = new WorldEditController(server, config);
api = new WorldEditAPI(this);
registerEvents();
}
public void onEnable() {
//loadConfiguration();
}
public void onDisable() {
@ -83,6 +85,24 @@ public class WorldEditPlugin extends JavaPlugin {
blockListener, Priority.Normal, this);
}
public void loadConfiguration() {
getConfiguration().load();
config.load();
perms.load();
}
String[] getGroups(Player player) {
return perms.getGroups(player.getName());
}
boolean inGroup(Player player, String group) {
return perms.inGroup(player.getName(), group);
}
boolean hasPermission(Player player, String perm) {
return perms.hasPermission(player.getName(), perm);
}
public WorldEditAPI getAPI() {
return api;
}