Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-10 05:20:04 +01:00
Cleaned up code.
Dieser Commit ist enthalten in:
Ursprung
dffd3682b2
Commit
19deb404ee
@ -19,13 +19,7 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit;
|
package com.sk89q.worldedit;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import javax.script.ScriptException;
|
import javax.script.ScriptException;
|
||||||
@ -37,13 +31,8 @@ import com.sk89q.worldedit.blocks.*;
|
|||||||
import com.sk89q.worldedit.commands.*;
|
import com.sk89q.worldedit.commands.*;
|
||||||
import com.sk89q.worldedit.regions.RegionSelector;
|
import com.sk89q.worldedit.regions.RegionSelector;
|
||||||
import com.sk89q.worldedit.scripting.*;
|
import com.sk89q.worldedit.scripting.*;
|
||||||
import com.sk89q.worldedit.tools.BlockTool;
|
import com.sk89q.worldedit.tools.*;
|
||||||
import com.sk89q.worldedit.tools.Tool;
|
import com.sk89q.worldedit.masks.*;
|
||||||
import com.sk89q.worldedit.tools.TraceTool;
|
|
||||||
import com.sk89q.worldedit.masks.BlockTypeMask;
|
|
||||||
import com.sk89q.worldedit.masks.ExistingBlockMask;
|
|
||||||
import com.sk89q.worldedit.masks.InvertedBlockTypeMask;
|
|
||||||
import com.sk89q.worldedit.masks.Mask;
|
|
||||||
import com.sk89q.worldedit.patterns.*;
|
import com.sk89q.worldedit.patterns.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,7 +44,14 @@ import com.sk89q.worldedit.patterns.*;
|
|||||||
* @author sk89q
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class WorldEdit {
|
public class WorldEdit {
|
||||||
|
/**
|
||||||
|
* Logger for debugging.
|
||||||
|
*/
|
||||||
public static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
public static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds WorldEdit's version.
|
||||||
|
*/
|
||||||
private static String version;
|
private static String version;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -881,7 +877,7 @@ public class WorldEdit {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (config.logCommands) {
|
if (config.logCommands) {
|
||||||
logger.log(Level.INFO, "WorldEdit: " + player.getName() + ": "
|
logger.info("WorldEdit: " + player.getName() + ": "
|
||||||
+ StringUtil.joinString(split, " "));
|
+ StringUtil.joinString(split, " "));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ public class BukkitPlayer extends LocalPlayer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getGroups() {
|
public String[] getGroups() {
|
||||||
return plugin.getGroups(player);
|
return plugin.getPermissionsResolver().getGroups(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -106,7 +106,8 @@ public class BukkitPlayer extends LocalPlayer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(String perm) {
|
public boolean hasPermission(String perm) {
|
||||||
return plugin.hasPermission(player, perm);
|
return (!plugin.getLocalConfiguration().noOpPermissions && player.isOp())
|
||||||
|
|| plugin.getPermissionsResolver().hasPermission(player.getName(), perm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,6 +29,9 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event.Priority;
|
import org.bukkit.event.Event.Priority;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.BlockListener;
|
||||||
|
import org.bukkit.event.player.PlayerListener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import com.sk89q.bukkit.migration.PermissionsResolverManager;
|
import com.sk89q.bukkit.migration.PermissionsResolverManager;
|
||||||
import com.sk89q.bukkit.migration.PermissionsResolverServerListener;
|
import com.sk89q.bukkit.migration.PermissionsResolverServerListener;
|
||||||
@ -39,71 +42,134 @@ import com.sk89q.worldedit.regions.Region;
|
|||||||
/**
|
/**
|
||||||
* Plugin for Bukkit.
|
* Plugin for Bukkit.
|
||||||
*
|
*
|
||||||
* @author sk89qs
|
* @author sk89q
|
||||||
*/
|
*/
|
||||||
public class WorldEditPlugin extends JavaPlugin {
|
public class WorldEditPlugin extends JavaPlugin {
|
||||||
|
/**
|
||||||
|
* WorldEdit messages get sent here.
|
||||||
|
*/
|
||||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
||||||
|
|
||||||
ServerInterface server;
|
/**
|
||||||
WorldEdit controller;
|
* The server interface that all server-related API goes through.
|
||||||
WorldEditAPI api;
|
*/
|
||||||
|
protected ServerInterface server;
|
||||||
|
/**
|
||||||
|
* Main WorldEdit instance.
|
||||||
|
*/
|
||||||
|
protected WorldEdit controller;
|
||||||
|
/**
|
||||||
|
* Deprecated API.
|
||||||
|
*/
|
||||||
|
protected WorldEditAPI api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds the configuration for WorldEdit.
|
||||||
|
*/
|
||||||
private BukkitConfiguration config;
|
private BukkitConfiguration config;
|
||||||
|
/**
|
||||||
|
* The permissions resolver in use.
|
||||||
|
*/
|
||||||
private PermissionsResolverManager perms;
|
private PermissionsResolverManager perms;
|
||||||
|
|
||||||
private WorldEditPlayerListener playerListener =
|
|
||||||
new WorldEditPlayerListener(this);
|
|
||||||
private WorldEditBlockListener blockListener =
|
|
||||||
new WorldEditBlockListener(this);
|
|
||||||
private PermissionsResolverServerListener permsListener;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called on plugin enable.
|
||||||
|
*/
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
logger.info("WorldEdit " + getDescription().getVersion() + " loaded.");
|
logger.info("WorldEdit " + getDescription().getVersion() + " enabled.");
|
||||||
|
|
||||||
|
// Make the data folders that WorldEdit uses
|
||||||
getDataFolder().mkdirs();
|
getDataFolder().mkdirs();
|
||||||
|
|
||||||
|
// Create the default configuration file
|
||||||
createDefaultConfiguration("config.yml");
|
createDefaultConfiguration("config.yml");
|
||||||
|
|
||||||
|
// Set up configuration and such, including the permissions
|
||||||
|
// resolver
|
||||||
config = new BukkitConfiguration(getConfiguration(), logger);
|
config = new BukkitConfiguration(getConfiguration(), logger);
|
||||||
perms = new PermissionsResolverManager(getConfiguration(), getServer(),
|
perms = new PermissionsResolverManager(
|
||||||
"WorldEdit", logger);
|
getConfiguration(), getServer(), "WorldEdit", logger);
|
||||||
permsListener = new PermissionsResolverServerListener(perms);
|
|
||||||
|
// Load the configuration
|
||||||
loadConfiguration();
|
loadConfiguration();
|
||||||
|
|
||||||
|
// Setup interfaces
|
||||||
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);
|
||||||
|
|
||||||
|
// Now we can register events!
|
||||||
registerEvents();
|
registerEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called on plugin disable.
|
||||||
|
*/
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
controller.clearSessions();
|
controller.clearSessions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads and reloads all configuration.
|
||||||
|
*/
|
||||||
|
protected void loadConfiguration() {
|
||||||
|
getConfiguration().load();
|
||||||
|
config.load();
|
||||||
|
perms.load();
|
||||||
|
}
|
||||||
|
|
||||||
private void registerEvents() {
|
/**
|
||||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT,
|
* Register the events used by WorldEdit.
|
||||||
playerListener, Priority.Normal, this);
|
*/
|
||||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_ANIMATION,
|
protected void registerEvents() {
|
||||||
playerListener, Priority.Normal, this);
|
PlayerListener playerListener = new WorldEditPlayerListener(this);
|
||||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_ITEM,
|
BlockListener blockListener = new WorldEditBlockListener(this);
|
||||||
playerListener, Priority.Normal, this);
|
|
||||||
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS,
|
|
||||||
playerListener, Priority.Normal, this);
|
|
||||||
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_DAMAGED,
|
|
||||||
blockListener, Priority.Normal, this);
|
|
||||||
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_RIGHTCLICKED,
|
|
||||||
blockListener, Priority.Normal, this);
|
|
||||||
|
|
||||||
permsListener.register(this);
|
registerEvent(Event.Type.PLAYER_QUIT, playerListener);
|
||||||
|
registerEvent(Event.Type.PLAYER_ANIMATION, playerListener);
|
||||||
|
registerEvent(Event.Type.PLAYER_ITEM, playerListener);
|
||||||
|
registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener);
|
||||||
|
registerEvent(Event.Type.BLOCK_DAMAGED, blockListener);
|
||||||
|
registerEvent(Event.Type.BLOCK_RIGHTCLICKED, blockListener);
|
||||||
|
|
||||||
|
// The permissions resolver has some hooks of its own
|
||||||
|
(new PermissionsResolverServerListener(perms)).register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createDefaultConfiguration(String name) {
|
/**
|
||||||
|
* Register an event.
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param listener
|
||||||
|
* @param priority
|
||||||
|
*/
|
||||||
|
protected void registerEvent(Event.Type type, Listener listener, Priority priority) {
|
||||||
|
getServer().getPluginManager()
|
||||||
|
.registerEvent(type, listener, priority, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register an event at normal priority.
|
||||||
|
*
|
||||||
|
* @param type
|
||||||
|
* @param listener
|
||||||
|
*/
|
||||||
|
protected void registerEvent(Event.Type type, Listener listener) {
|
||||||
|
getServer().getPluginManager()
|
||||||
|
.registerEvent(type, listener, Priority.Normal, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a default configuration file from the .jar.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*/
|
||||||
|
protected void createDefaultConfiguration(String name) {
|
||||||
File actual = new File(getDataFolder(), name);
|
File actual = new File(getDataFolder(), name);
|
||||||
if (!actual.exists()) {
|
if (!actual.exists()) {
|
||||||
|
|
||||||
InputStream input =
|
InputStream input =
|
||||||
WorldEditPlugin.class.getResourceAsStream("/defaults/" + name);
|
this.getClass().getResourceAsStream("/defaults/" + name);
|
||||||
if (input != null) {
|
if (input != null) {
|
||||||
FileOutputStream output = null;
|
FileOutputStream output = null;
|
||||||
|
|
||||||
@ -115,8 +181,8 @@ public class WorldEditPlugin extends JavaPlugin {
|
|||||||
output.write(buf, 0, length);
|
output.write(buf, 0, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("WorldEdit: Default configuration file written: "
|
logger.info(getDescription().getName()
|
||||||
+ name);
|
+ ": Default configuration file written: " + name);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
@ -133,35 +199,23 @@ public class WorldEditPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadConfiguration() {
|
|
||||||
getConfiguration().load();
|
|
||||||
config.load();
|
|
||||||
perms.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called on WorldEdit command.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmd,
|
public boolean onCommand(CommandSender sender, Command cmd,
|
||||||
String commandLabel, String[] args) {
|
String commandLabel, String[] args) {
|
||||||
|
// Since WorldEdit is primarily made for use in-game, we're going
|
||||||
|
// to ignore the situation where the command sender is not aplayer.
|
||||||
if (!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player)sender;
|
Player player = (Player)sender;
|
||||||
|
|
||||||
if (cmd.getName().equalsIgnoreCase("reloadwe")
|
// Add the command to the array because the underlying command handling
|
||||||
&& hasPermission(player, "worldedit.reload")) {
|
// code of WorldEdit expects it
|
||||||
try {
|
|
||||||
loadConfiguration();
|
|
||||||
player.sendMessage("WorldEdit configuration reloaded.");
|
|
||||||
} catch (Throwable t) {
|
|
||||||
player.sendMessage("Error while reloading: "
|
|
||||||
+ t.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] split = new String[args.length + 1];
|
String[] split = new String[args.length + 1];
|
||||||
System.arraycopy(args, 0, split, 1, args.length);
|
System.arraycopy(args, 0, split, 1, args.length);
|
||||||
split[0] = "/" + cmd.getName();
|
split[0] = "/" + cmd.getName();
|
||||||
@ -258,25 +312,41 @@ public class WorldEditPlugin extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the API.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public WorldEditAPI getAPI() {
|
public WorldEditAPI getAPI() {
|
||||||
return api;
|
return api;
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] getGroups(Player player) {
|
/**
|
||||||
return perms.getGroups(player.getName());
|
* Returns the configuration used by WorldEdit.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public BukkitConfiguration getLocalConfiguration() {
|
||||||
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean inGroup(Player player, String group) {
|
/**
|
||||||
return perms.inGroup(player.getName(), group);
|
* Get the permissions resolver in use.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public PermissionsResolverManager getPermissionsResolver() {
|
||||||
|
return perms;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasPermission(Player player, String perm) {
|
/**
|
||||||
return (!config.noOpPermissions && player.isOp())
|
* Used to wrap a Bukkit Player as a LocalPlayer.
|
||||||
|| perms.hasPermission(player.getName(), perm);
|
*
|
||||||
}
|
* @param player
|
||||||
|
* @return
|
||||||
BukkitPlayer wrapPlayer(Player player) {
|
*/
|
||||||
|
public BukkitPlayer wrapPlayer(Player player) {
|
||||||
return new BukkitPlayer(this, this.server, player);
|
return new BukkitPlayer(this, this.server, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren