Merge pull request #293 from sk89q/visitor

Merge in WorldEdit 6.x branch -- contains breaking API changes
Dieser Commit ist enthalten in:
Albert Pham 2014-04-03 19:21:17 -07:00
Commit 8badc52a77
407 geänderte Dateien mit 31918 neuen und 24199 gelöschten Zeilen

367
pom.xml
Datei anzeigen

@ -1,17 +1,27 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sk89q</groupId>
<artifactId>worldedit</artifactId>
<version>5.7-SNAPSHOT</version>
<version>6.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<!-- Project information -->
<!-- Fix encoding warnings -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!--
=====================================
Project Information
=====================================
-->
<name>WorldEdit</name>
<inceptionYear>2010</inceptionYear>
<url>http://wiki.sk89q.com/wiki/WorldEdit</url>
<description>A voxel map editor for Minecraft with tools for adventure map designers,
server administrators, and anyone who enjoys building massive structures.</description>
<description>An in-game voxel map editor for Minecraft.</description>
<licenses>
<license>
<name>GNU General Public License 2.0</name>
@ -26,36 +36,44 @@
<comments>License on all new contributions</comments>
</license>
</licenses>
<issueManagement>
<system>YouTrack</system>
<url>http://youtrack.sk89q.com</url>
</issueManagement>
<ciManagement>
<system>Jenkins</system>
<url>http://build.sk89q.com</url>
<system>TeamCity</system>
<url>http://builds.enginehub.org</url>
</ciManagement>
<scm>
<connection>scm:git:git://github.com/sk89q/worldedit.git</connection>
<developerConnection>scm:git:git@github.com:sk89q/worldedit.git</developerConnection>
<url>https://github.com/sk89q/worldedit</url>
<tag>master</tag>
</scm>
<mailingLists>
<mailingList>
<name>Developer Discussion</name>
<archive>https://groups.google.com/d/forum/sk-dev-discuss</archive>
</mailingList>
</mailingLists>
<!--
=====================================
Distribution Management
=====================================
-->
<distributionManagement>
<site>
<id>sk89q-docs-upload</id>
<url>ftp://sk89q-maven-deploy/worldedit/</url>
</site>
<!-- The CI server uses these -->
<repository>
<id>maven.sk89q.com</id>
<url>http://maven.sk89q.com/artifactory/libs-release-local</url>
@ -65,91 +83,89 @@
<url>http://maven.sk89q.com/artifactory/libs-snapshot-local</url>
</snapshotRepository>
</distributionManagement>
<properties> <!-- Fix encoding warnings -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!--
=====================================
Dependencies
=====================================
-->
<repositories>
<repository>
<id>sk89q-repo</id>
<id>maven.sk89q.com</id>
<url>http://maven.sk89q.com/repo/</url>
</repository>
<repository>
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public</url>
</repository>
</repositories>
<dependencies>
<dependency> <!-- Used for snapshots -->
<!-- Used for snapshots -->
<dependency>
<groupId>de.schlichtherle</groupId>
<artifactId>truezip</artifactId>
<version>6.8.3</version>
<scope>compile</scope>
<scope>compile</scope> <!-- optional runtime dependency -->
<type>jar</type>
</dependency>
<dependency> <!-- Used for CraftScripts -->
<!-- Used for scripting -->
<dependency>
<groupId>rhino</groupId>
<artifactId>js</artifactId>
<version>1.7R2</version>
<scope>compile</scope>
<scope>compile</scope> <!-- optional runtime dependency -->
<type>jar</type>
</dependency>
<dependency> <!-- Time format detection -->
<groupId>com.sk89q</groupId>
<artifactId>jchronic</artifactId> <!-- not original library -->
<version>0.2.4a</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<!-- Used for Permissions support (this version has both the legacy API
and the new Permissions API to compile against -->
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>dummypermscompat</artifactId>
<version>1.7</version>
<scope>compile</scope>
<type>jar</type>
<optional>true</optional> <!-- Don't export -->
</dependency>
<dependency> <!-- Bukkit implementation -->
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.7.2-R0.2</version>
<scope>compile</scope>
<!-- YAML processing -->
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.9</version>
<type>jar</type>
<scope>compile</scope> <!-- optional runtime dependency -->
<optional>true</optional>
</dependency>
<dependency> <!-- NMS blocks -->
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.7.5-R0.1-SNAPSHOT</version>
<scope>compile</scope>
<!-- It's Guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>10.0.1</version> <!-- Bukkit only bundles 10.0.1 -->
<scope>compile</scope> <!-- required runtime dependency -->
<type>jar</type>
<optional>true</optional>
</dependency>
<dependency> <!-- Unit tests -->
<!-- Used for time operations -->
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>jchronic</artifactId> <!-- not the original library -->
<version>0.2.4a</version>
<scope>compile</scope> <!-- shaded -->
<type>jar</type>
</dependency>
<!-- Unit tests -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.0-rc1</version>
<scope>test</scope>
<type>jar</type>
</dependency>
</dependencies>
<!--
=====================================
Build
=====================================
-->
<build>
<defaultGoal>install</defaultGoal>
<sourceDirectory>${basedir}/src/main/java/</sourceDirectory>
<extensions> <!-- Used for uploading the docs -->
<!-- Used for uploading the docs -->
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
@ -157,34 +173,29 @@
</extension>
</extensions>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources/</directory>
<includes>
<include>plugin.yml</include>
</includes>
</resource>
<resource>
<targetPath>defaults/</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources/</directory>
<includes>
<include>config.yml</include>
</includes>
</resource>
<resource> <!-- NMS support in Bukkit -->
<targetPath>nmsblocks/</targetPath>
<filtering>false</filtering>
<directory>${basedir}/src/main/resources/nmsblocks/</directory>
<includes>
<include>*.class</include>
</includes>
</resource>
</resources>
<plugins>
<!-- Add source folder -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/src/legacy/java/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<!-- Compiler -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
@ -195,6 +206,7 @@
</configuration>
</plugin>
<!-- JAR plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
@ -216,6 +228,7 @@
</configuration>
</plugin>
<!-- Assembly builds .zip, etc. -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-2</version>
@ -233,6 +246,7 @@
</executions>
</plugin>
<!-- Shades -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
@ -254,6 +268,7 @@
</executions>
</plugin>
<!-- Release plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
@ -265,6 +280,7 @@
</configuration>
</plugin>
<!-- Test runner -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@ -276,12 +292,14 @@
</configuration>
</plugin>
<!-- Site builder -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.1</version>
<configuration>
<reportPlugins>
<!-- Project information -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
@ -295,7 +313,8 @@
</reportSet>
</reportSets>
</plugin>
<!-- Javadocs -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
@ -306,9 +325,141 @@
</plugin>
</plugins>
</build>
<!--
=====================================
Profiles
=====================================
-->
<profiles>
<!-- Build WorldEdit for MC-Forge -->
<!--
=====================================
Bukkit
=====================================
-->
<profile>
<id>bukkit</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public</url>
</repository>
</repositories>
<dependencies>
<!-- Used for Permissions support (this version has both the legacy API
and the new Permissions API to compile against -->
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>dummypermscompat</artifactId>
<version>1.7</version>
<scope>compile</scope>
<type>jar</type>
<optional>true</optional>
</dependency>
<!-- Bukkit implementation -->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.7.2-R0.2</version>
<scope>compile</scope>
<type>jar</type>
<optional>true</optional>
</dependency>
<!-- NMS blocks -->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.7.5-R0.1-SNAPSHOT</version>
<scope>compile</scope>
<type>jar</type>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<resources>
<!-- Bukkit plugin.yml -->
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/bukkit/resources/</directory>
<includes>
<include>plugin.yml</include>
</includes>
</resource>
<!-- Default files -->
<resource>
<targetPath>defaults/</targetPath>
<filtering>true</filtering>
<directory>${basedir}/src/bukkit/resources/</directory>
<includes>
<include>config.yml</include>
</includes>
</resource>
<!-- NMS support in Bukkit -->
<resource>
<targetPath>nmsblocks/</targetPath>
<filtering>false</filtering>
<directory>${basedir}/src/bukkit/resources/nmsblocks/</directory>
<includes>
<include>*.class</include>
</includes>
</resource>
</resources>
<plugins>
<!-- Add source folder -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-bukkit-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/src/bukkit/java/</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-bukkit-test-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/src/bukkit-test/java/</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!--
=====================================
Forge
=====================================
-->
<profile>
<id>forge</id>
<build>
@ -341,10 +492,14 @@
</build>
</profile>
<!-- Attach javadocs and source .jars -->
<!--
=====================================
Attach docs and source
=====================================
-->
<profile>
<id>attach-docs</id>
<build>
<plugins>
<plugin>
@ -360,7 +515,7 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
@ -377,18 +532,22 @@
</plugins>
</build>
</profile>
<!-- Build Spout, disabled by default because it always breaks -->
<!--
=====================================
Spout (BROKEN)
=====================================
-->
<profile>
<id>spout</id>
<repositories>
<repository> <!-- WARNING: This breaks all the time -->
<id>spout-repo</id>
<url>http://nexus.spout.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spout</groupId>
@ -422,7 +581,7 @@
<version>1.5</version>
<executions>
<execution>
<id>add-sources</id>
<id>add-spout-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>

Datei anzeigen

@ -1,170 +1,170 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.wepif;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.sk89q.util.yaml.YAMLNode;
import com.sk89q.util.yaml.YAMLProcessor;
import org.bukkit.OfflinePlayer;
public class ConfigurationPermissionsResolver implements PermissionsResolver {
private YAMLProcessor config;
private Map<String, Set<String>> userPermissionsCache;
private Set<String> defaultPermissionsCache;
private Map<String, Set<String>> userGroups;
public ConfigurationPermissionsResolver(YAMLProcessor config) {
this.config = config;
}
public static YAMLNode generateDefaultPerms(YAMLNode section) {
section.setProperty("groups.default.permissions", new String[] {
"worldedit.reload",
"worldedit.selection",
"worlds.creative.worldedit.region"});
section.setProperty("groups.admins.permissions", new String[] { "*" });
section.setProperty("users.sk89q.permissions", new String[] { "worldedit" });
section.setProperty("users.sk89q.groups", new String[] { "admins" });
return section;
}
public void load() {
userGroups = new HashMap<String, Set<String>>();
userPermissionsCache = new HashMap<String, Set<String>>();
defaultPermissionsCache = new HashSet<String>();
Map<String, Set<String>> userGroupPermissions = new HashMap<String, Set<String>>();
List<String> groupKeys = config.getStringList("permissions.groups", null);
if (groupKeys != null) {
for (String key : groupKeys) {
List<String> permissions =
config.getStringList("permissions.groups." + key + ".permissions", null);
if (permissions.size() > 0) {
Set<String> groupPerms = new HashSet<String>(permissions);
userGroupPermissions.put(key, groupPerms);
if (key.equals("default")) {
defaultPermissionsCache.addAll(permissions);
}
}
}
}
List<String> userKeys = config.getStringList("permissions.users", null);
if (userKeys != null) {
for (String key : userKeys) {
Set<String> permsCache = new HashSet<String>();
List<String> permissions =
config.getStringList("permissions.users." + key + ".permissions", null);
if (permissions.size() > 0) {
permsCache.addAll(permissions);
}
List<String> groups =
config.getStringList("permissions.users." + key + ".groups", null);
groups.add("default");
if (groups.size() > 0) {
for (String group : groups) {
Set<String> groupPerms = userGroupPermissions.get(group);
if (groupPerms != null) {
permsCache.addAll(groupPerms);
}
}
}
userPermissionsCache.put(key.toLowerCase(), permsCache);
userGroups.put(key.toLowerCase(), new HashSet<String>(groups));
}
}
}
public boolean hasPermission(String player, String permission) {
int dotPos = permission.lastIndexOf(".");
if (dotPos > -1) {
if (hasPermission(player, permission.substring(0, dotPos))) {
return true;
}
}
Set<String> perms = userPermissionsCache.get(player.toLowerCase());
if (perms == null) {
return defaultPermissionsCache.contains(permission)
|| defaultPermissionsCache.contains("*");
}
return perms.contains("*") || perms.contains(permission);
}
public boolean hasPermission(String worldName, String player, String permission) {
return hasPermission(player, "worlds." + worldName + "." + permission)
|| hasPermission(player, permission);
}
public boolean inGroup(String player, String group) {
Set<String> groups = userGroups.get(player.toLowerCase());
if (groups == null) {
return false;
}
return groups.contains(group);
}
public String[] getGroups(String player) {
Set<String> groups = userGroups.get(player.toLowerCase());
if (groups == null) {
return new String[0];
}
return groups.toArray(new String[groups.size()]);
}
public boolean hasPermission(OfflinePlayer player, String permission) {
return hasPermission(player.getName(), permission);
}
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
return hasPermission(worldName, player.getName(), permission);
}
public boolean inGroup(OfflinePlayer player, String group) {
return inGroup(player.getName(), group);
}
public String[] getGroups(OfflinePlayer player) {
return getGroups(player.getName());
}
public String getDetectionMessage() {
return "No known permissions plugin detected. Using configuration file for permissions.";
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.wepif;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.sk89q.util.yaml.YAMLNode;
import com.sk89q.util.yaml.YAMLProcessor;
import org.bukkit.OfflinePlayer;
public class ConfigurationPermissionsResolver implements PermissionsResolver {
private YAMLProcessor config;
private Map<String, Set<String>> userPermissionsCache;
private Set<String> defaultPermissionsCache;
private Map<String, Set<String>> userGroups;
public ConfigurationPermissionsResolver(YAMLProcessor config) {
this.config = config;
}
public static YAMLNode generateDefaultPerms(YAMLNode section) {
section.setProperty("groups.default.permissions", new String[] {
"worldedit.reload",
"worldedit.selection",
"worlds.creative.worldedit.region"});
section.setProperty("groups.admins.permissions", new String[] { "*" });
section.setProperty("users.sk89q.permissions", new String[] { "worldedit" });
section.setProperty("users.sk89q.groups", new String[] { "admins" });
return section;
}
public void load() {
userGroups = new HashMap<String, Set<String>>();
userPermissionsCache = new HashMap<String, Set<String>>();
defaultPermissionsCache = new HashSet<String>();
Map<String, Set<String>> userGroupPermissions = new HashMap<String, Set<String>>();
List<String> groupKeys = config.getStringList("permissions.groups", null);
if (groupKeys != null) {
for (String key : groupKeys) {
List<String> permissions =
config.getStringList("permissions.groups." + key + ".permissions", null);
if (permissions.size() > 0) {
Set<String> groupPerms = new HashSet<String>(permissions);
userGroupPermissions.put(key, groupPerms);
if (key.equals("default")) {
defaultPermissionsCache.addAll(permissions);
}
}
}
}
List<String> userKeys = config.getStringList("permissions.users", null);
if (userKeys != null) {
for (String key : userKeys) {
Set<String> permsCache = new HashSet<String>();
List<String> permissions =
config.getStringList("permissions.users." + key + ".permissions", null);
if (permissions.size() > 0) {
permsCache.addAll(permissions);
}
List<String> groups =
config.getStringList("permissions.users." + key + ".groups", null);
groups.add("default");
if (groups.size() > 0) {
for (String group : groups) {
Set<String> groupPerms = userGroupPermissions.get(group);
if (groupPerms != null) {
permsCache.addAll(groupPerms);
}
}
}
userPermissionsCache.put(key.toLowerCase(), permsCache);
userGroups.put(key.toLowerCase(), new HashSet<String>(groups));
}
}
}
public boolean hasPermission(String player, String permission) {
int dotPos = permission.lastIndexOf(".");
if (dotPos > -1) {
if (hasPermission(player, permission.substring(0, dotPos))) {
return true;
}
}
Set<String> perms = userPermissionsCache.get(player.toLowerCase());
if (perms == null) {
return defaultPermissionsCache.contains(permission)
|| defaultPermissionsCache.contains("*");
}
return perms.contains("*") || perms.contains(permission);
}
public boolean hasPermission(String worldName, String player, String permission) {
return hasPermission(player, "worlds." + worldName + "." + permission)
|| hasPermission(player, permission);
}
public boolean inGroup(String player, String group) {
Set<String> groups = userGroups.get(player.toLowerCase());
if (groups == null) {
return false;
}
return groups.contains(group);
}
public String[] getGroups(String player) {
Set<String> groups = userGroups.get(player.toLowerCase());
if (groups == null) {
return new String[0];
}
return groups.toArray(new String[groups.size()]);
}
public boolean hasPermission(OfflinePlayer player, String permission) {
return hasPermission(player.getName(), permission);
}
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
return hasPermission(worldName, player.getName(), permission);
}
public boolean inGroup(OfflinePlayer player, String group) {
return inGroup(player.getName(), group);
}
public String[] getGroups(OfflinePlayer player) {
return getGroups(player.getName());
}
public String getDetectionMessage() {
return "No known permissions plugin detected. Using configuration file for permissions.";
}
}

Datei anzeigen

@ -1,237 +1,237 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.wepif;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.HashMap;
import com.sk89q.util.yaml.YAMLProcessor;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
public class FlatFilePermissionsResolver implements PermissionsResolver {
private Map<String, Set<String>> userPermissionsCache;
private Set<String> defaultPermissionsCache;
private Map<String, Set<String>> userGroups;
protected File groupFile;
protected File userFile;
public static PermissionsResolver factory(Server server, YAMLProcessor config) {
File groups = new File("perms_groups.txt");
File users = new File("perms_users.txt");
if (!groups.exists() || !users.exists()) {
return null;
}
return new FlatFilePermissionsResolver(groups, users);
}
public FlatFilePermissionsResolver() {
this(new File("perms_groups.txt"), new File("perms_users.txt"));
}
public FlatFilePermissionsResolver(File groupFile, File userFile) {
this.groupFile = groupFile;
this.userFile = userFile;
}
@Deprecated
public static boolean filesExists() {
return (new File("perms_groups.txt")).exists() && (new File("perms_users.txt")).exists();
}
public Map<String, Set<String>> loadGroupPermissions() {
Map<String, Set<String>> userGroupPermissions = new HashMap<String, Set<String>>();
BufferedReader buff = null;
try {
FileReader input = new FileReader(this.groupFile);
buff = new BufferedReader(input);
String line;
while ((line = buff.readLine()) != null) {
line = line.trim();
// Blank line
if (line.length() == 0) {
continue;
} else if (line.charAt(0) == ';' || line.charAt(0) == '#') {
continue;
}
String[] parts = line.split(":");
String key = parts[0];
if (parts.length > 1) {
String[] perms = parts[1].split(",");
Set<String> groupPerms = new HashSet<String>(Arrays.asList(perms));
userGroupPermissions.put(key, groupPerms);
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (buff != null) {
buff.close();
}
} catch (IOException e2) {
}
}
return userGroupPermissions;
}
public void load() {
userGroups = new HashMap<String, Set<String>>();
userPermissionsCache = new HashMap<String, Set<String>>();
defaultPermissionsCache = new HashSet<String>();
Map<String, Set<String>> userGroupPermissions = loadGroupPermissions();
if (userGroupPermissions.containsKey("default")) {
defaultPermissionsCache = userGroupPermissions.get("default");
}
BufferedReader buff = null;
try {
FileReader input = new FileReader(this.userFile);
buff = new BufferedReader(input);
String line;
while ((line = buff.readLine()) != null) {
Set<String> permsCache = new HashSet<String>();
line = line.trim();
// Blank line
if (line.length() == 0) {
continue;
} else if (line.charAt(0) == ';' || line.charAt(0) == '#') {
continue;
}
String[] parts = line.split(":");
String key = parts[0];
if (parts.length > 1) {
String[] groups = (parts[1] + ",default").split(",");
String[] perms = parts.length > 2 ? parts[2].split(",") : new String[0];
permsCache.addAll(Arrays.asList(perms));
for (String group : groups) {
Set<String> groupPerms = userGroupPermissions.get(group);
if (groupPerms != null) {
permsCache.addAll(groupPerms);
}
}
userPermissionsCache.put(key.toLowerCase(), permsCache);
userGroups.put(key.toLowerCase(), new HashSet<String>(Arrays.asList(groups)));
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (buff != null) {
buff.close();
}
} catch (IOException e2) {
}
}
}
public boolean hasPermission(String player, String permission) {
int dotPos = permission.lastIndexOf(".");
if (dotPos > -1) {
if (hasPermission(player, permission.substring(0, dotPos))) {
return true;
}
}
Set<String> perms = userPermissionsCache.get(player.toLowerCase());
if (perms == null) {
return defaultPermissionsCache.contains(permission)
|| defaultPermissionsCache.contains("*");
}
return perms.contains("*") || perms.contains(permission);
}
public boolean hasPermission(String worldName, String player, String permission) {
return hasPermission(player, "worlds." + worldName + "." + permission)
|| hasPermission(player, permission);
}
public boolean inGroup(String player, String group) {
Set<String> groups = userGroups.get(player.toLowerCase());
if (groups == null) {
return false;
}
return groups.contains(group);
}
public String[] getGroups(String player) {
Set<String> groups = userGroups.get(player.toLowerCase());
if (groups == null) {
return new String[0];
}
return groups.toArray(new String[groups.size()]);
}
public boolean hasPermission(OfflinePlayer player, String permission) {
return hasPermission(player.getName(), permission);
}
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
return hasPermission(worldName, player.getName(), permission);
}
public boolean inGroup(OfflinePlayer player, String group) {
return inGroup(player.getName(), group);
}
public String[] getGroups(OfflinePlayer player) {
return getGroups(player.getName());
}
public String getDetectionMessage() {
return "perms_groups.txt and perms_users.txt detected! Using flat file permissions.";
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.wepif;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.HashMap;
import com.sk89q.util.yaml.YAMLProcessor;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
public class FlatFilePermissionsResolver implements PermissionsResolver {
private Map<String, Set<String>> userPermissionsCache;
private Set<String> defaultPermissionsCache;
private Map<String, Set<String>> userGroups;
protected File groupFile;
protected File userFile;
public static PermissionsResolver factory(Server server, YAMLProcessor config) {
File groups = new File("perms_groups.txt");
File users = new File("perms_users.txt");
if (!groups.exists() || !users.exists()) {
return null;
}
return new FlatFilePermissionsResolver(groups, users);
}
public FlatFilePermissionsResolver() {
this(new File("perms_groups.txt"), new File("perms_users.txt"));
}
public FlatFilePermissionsResolver(File groupFile, File userFile) {
this.groupFile = groupFile;
this.userFile = userFile;
}
@Deprecated
public static boolean filesExists() {
return (new File("perms_groups.txt")).exists() && (new File("perms_users.txt")).exists();
}
public Map<String, Set<String>> loadGroupPermissions() {
Map<String, Set<String>> userGroupPermissions = new HashMap<String, Set<String>>();
BufferedReader buff = null;
try {
FileReader input = new FileReader(this.groupFile);
buff = new BufferedReader(input);
String line;
while ((line = buff.readLine()) != null) {
line = line.trim();
// Blank line
if (line.length() == 0) {
continue;
} else if (line.charAt(0) == ';' || line.charAt(0) == '#') {
continue;
}
String[] parts = line.split(":");
String key = parts[0];
if (parts.length > 1) {
String[] perms = parts[1].split(",");
Set<String> groupPerms = new HashSet<String>(Arrays.asList(perms));
userGroupPermissions.put(key, groupPerms);
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (buff != null) {
buff.close();
}
} catch (IOException e2) {
}
}
return userGroupPermissions;
}
public void load() {
userGroups = new HashMap<String, Set<String>>();
userPermissionsCache = new HashMap<String, Set<String>>();
defaultPermissionsCache = new HashSet<String>();
Map<String, Set<String>> userGroupPermissions = loadGroupPermissions();
if (userGroupPermissions.containsKey("default")) {
defaultPermissionsCache = userGroupPermissions.get("default");
}
BufferedReader buff = null;
try {
FileReader input = new FileReader(this.userFile);
buff = new BufferedReader(input);
String line;
while ((line = buff.readLine()) != null) {
Set<String> permsCache = new HashSet<String>();
line = line.trim();
// Blank line
if (line.length() == 0) {
continue;
} else if (line.charAt(0) == ';' || line.charAt(0) == '#') {
continue;
}
String[] parts = line.split(":");
String key = parts[0];
if (parts.length > 1) {
String[] groups = (parts[1] + ",default").split(",");
String[] perms = parts.length > 2 ? parts[2].split(",") : new String[0];
permsCache.addAll(Arrays.asList(perms));
for (String group : groups) {
Set<String> groupPerms = userGroupPermissions.get(group);
if (groupPerms != null) {
permsCache.addAll(groupPerms);
}
}
userPermissionsCache.put(key.toLowerCase(), permsCache);
userGroups.put(key.toLowerCase(), new HashSet<String>(Arrays.asList(groups)));
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (buff != null) {
buff.close();
}
} catch (IOException e2) {
}
}
}
public boolean hasPermission(String player, String permission) {
int dotPos = permission.lastIndexOf(".");
if (dotPos > -1) {
if (hasPermission(player, permission.substring(0, dotPos))) {
return true;
}
}
Set<String> perms = userPermissionsCache.get(player.toLowerCase());
if (perms == null) {
return defaultPermissionsCache.contains(permission)
|| defaultPermissionsCache.contains("*");
}
return perms.contains("*") || perms.contains(permission);
}
public boolean hasPermission(String worldName, String player, String permission) {
return hasPermission(player, "worlds." + worldName + "." + permission)
|| hasPermission(player, permission);
}
public boolean inGroup(String player, String group) {
Set<String> groups = userGroups.get(player.toLowerCase());
if (groups == null) {
return false;
}
return groups.contains(group);
}
public String[] getGroups(String player) {
Set<String> groups = userGroups.get(player.toLowerCase());
if (groups == null) {
return new String[0];
}
return groups.toArray(new String[groups.size()]);
}
public boolean hasPermission(OfflinePlayer player, String permission) {
return hasPermission(player.getName(), permission);
}
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
return hasPermission(worldName, player.getName(), permission);
}
public boolean inGroup(OfflinePlayer player, String group) {
return inGroup(player.getName(), group);
}
public String[] getGroups(OfflinePlayer player) {
return getGroups(player.getName());
}
public String getDetectionMessage() {
return "perms_groups.txt and perms_users.txt detected! Using flat file permissions.";
}
}

Datei anzeigen

@ -1,161 +1,161 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.wepif;
import com.sk89q.util.yaml.YAMLProcessor;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import com.nijikokun.bukkit.Permissions.Permissions;
public class NijiPermissionsResolver implements PermissionsResolver {
private Server server;
private Permissions api;
public static PermissionsResolver factory(Server server, YAMLProcessor config) {
PluginManager pluginManager = server.getPluginManager();
try {
Class.forName("com.nijikokun.bukkit.Permissions.Permissions");
} catch (ClassNotFoundException e) {
return null;
}
Plugin plugin = pluginManager.getPlugin("Permissions");
// Check if plugin is loaded and has Permissions interface
if (plugin == null || !(plugin instanceof Permissions)) {
return null;
}
// Check for fake permissions
if (config.getBoolean("ignore-nijiperms-bridges", true) && isFakeNijiPerms(plugin)) {
return null;
}
return new NijiPermissionsResolver(server, (Permissions) plugin);
}
public void load() {
}
public NijiPermissionsResolver(Server server, Permissions plugin) {
this.server = server;
this.api = plugin;
}
@SuppressWarnings("static-access")
public boolean hasPermission(String name, String permission) {
try {
Player player = server.getPlayerExact(name);
if (player == null) return false;
try {
return api.getHandler().has(player, permission);
} catch (Throwable t) {
return api.Security.permission(player, permission);
}
} catch (Throwable t) {
t.printStackTrace();
return false;
}
}
public boolean hasPermission(String worldName, String name, String permission) {
try {
try {
return api.getHandler().has(worldName, name, permission);
} catch (Throwable t) {
return api.getHandler().has(server.getPlayerExact(name), permission);
}
} catch (Throwable t) {
t.printStackTrace();
return false;
}
}
@SuppressWarnings("static-access")
public boolean inGroup(String name, String group) {
try {
Player player = server.getPlayerExact(name);
if (player == null) return false;
try {
return api.getHandler().inGroup(player.getWorld().getName(), name, group);
} catch (Throwable t) {
return api.Security.inGroup(name, group);
}
} catch (Throwable t) {
t.printStackTrace();
return false;
}
}
@SuppressWarnings("static-access")
public String[] getGroups(String name) {
try {
Player player = server.getPlayerExact(name);
if (player == null) return new String[0];
String[] groups = null;
try {
groups = api.getHandler().getGroups(player.getWorld().getName(), player.getName());
} catch (Throwable t) {
String group = api.Security.getGroup(player.getWorld().getName(), player.getName());
if (group != null) groups = new String[] { group };
}
if (groups == null) {
return new String[0];
} else {
return groups;
}
} catch (Throwable t) {
t.printStackTrace();
return new String[0];
}
}
public boolean hasPermission(OfflinePlayer player, String permission) {
return hasPermission(player.getName(), permission);
}
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
return hasPermission(worldName, player.getName(), permission);
}
public boolean inGroup(OfflinePlayer player, String group) {
return inGroup(player.getName(), group);
}
public String[] getGroups(OfflinePlayer player) {
return getGroups(player.getName());
}
public static boolean isFakeNijiPerms(Plugin plugin) {
PluginCommand permsCommand = Bukkit.getServer().getPluginCommand("permissions");
return permsCommand == null || !(permsCommand.getPlugin().equals(plugin));
}
public String getDetectionMessage() {
return "Permissions plugin detected! Using Permissions plugin for permissions.";
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.wepif;
import com.sk89q.util.yaml.YAMLProcessor;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import com.nijikokun.bukkit.Permissions.Permissions;
public class NijiPermissionsResolver implements PermissionsResolver {
private Server server;
private Permissions api;
public static PermissionsResolver factory(Server server, YAMLProcessor config) {
PluginManager pluginManager = server.getPluginManager();
try {
Class.forName("com.nijikokun.bukkit.Permissions.Permissions");
} catch (ClassNotFoundException e) {
return null;
}
Plugin plugin = pluginManager.getPlugin("Permissions");
// Check if plugin is loaded and has Permissions interface
if (plugin == null || !(plugin instanceof Permissions)) {
return null;
}
// Check for fake permissions
if (config.getBoolean("ignore-nijiperms-bridges", true) && isFakeNijiPerms(plugin)) {
return null;
}
return new NijiPermissionsResolver(server, (Permissions) plugin);
}
public void load() {
}
public NijiPermissionsResolver(Server server, Permissions plugin) {
this.server = server;
this.api = plugin;
}
@SuppressWarnings("static-access")
public boolean hasPermission(String name, String permission) {
try {
Player player = server.getPlayerExact(name);
if (player == null) return false;
try {
return api.getHandler().has(player, permission);
} catch (Throwable t) {
return api.Security.permission(player, permission);
}
} catch (Throwable t) {
t.printStackTrace();
return false;
}
}
public boolean hasPermission(String worldName, String name, String permission) {
try {
try {
return api.getHandler().has(worldName, name, permission);
} catch (Throwable t) {
return api.getHandler().has(server.getPlayerExact(name), permission);
}
} catch (Throwable t) {
t.printStackTrace();
return false;
}
}
@SuppressWarnings("static-access")
public boolean inGroup(String name, String group) {
try {
Player player = server.getPlayerExact(name);
if (player == null) return false;
try {
return api.getHandler().inGroup(player.getWorld().getName(), name, group);
} catch (Throwable t) {
return api.Security.inGroup(name, group);
}
} catch (Throwable t) {
t.printStackTrace();
return false;
}
}
@SuppressWarnings("static-access")
public String[] getGroups(String name) {
try {
Player player = server.getPlayerExact(name);
if (player == null) return new String[0];
String[] groups = null;
try {
groups = api.getHandler().getGroups(player.getWorld().getName(), player.getName());
} catch (Throwable t) {
String group = api.Security.getGroup(player.getWorld().getName(), player.getName());
if (group != null) groups = new String[] { group };
}
if (groups == null) {
return new String[0];
} else {
return groups;
}
} catch (Throwable t) {
t.printStackTrace();
return new String[0];
}
}
public boolean hasPermission(OfflinePlayer player, String permission) {
return hasPermission(player.getName(), permission);
}
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
return hasPermission(worldName, player.getName(), permission);
}
public boolean inGroup(OfflinePlayer player, String group) {
return inGroup(player.getName(), group);
}
public String[] getGroups(OfflinePlayer player) {
return getGroups(player.getName());
}
public static boolean isFakeNijiPerms(Plugin plugin) {
PluginCommand permsCommand = Bukkit.getServer().getPluginCommand("permissions");
return permsCommand == null || !(permsCommand.getPlugin().equals(plugin));
}
public String getDetectionMessage() {
return "Permissions plugin detected! Using Permissions plugin for permissions.";
}
}

Datei anzeigen

@ -1,40 +1,40 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.wepif;
import org.bukkit.OfflinePlayer;
public interface PermissionsProvider {
public boolean hasPermission(String name, String permission);
public boolean hasPermission(String worldName, String name, String permission);
public boolean inGroup(String player, String group);
public String[] getGroups(String player);
public boolean hasPermission(OfflinePlayer player, String permission);
public boolean hasPermission(String worldName, OfflinePlayer player, String permission);
public boolean inGroup(OfflinePlayer player, String group);
public String[] getGroups(OfflinePlayer player);
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.wepif;
import org.bukkit.OfflinePlayer;
public interface PermissionsProvider {
public boolean hasPermission(String name, String permission);
public boolean hasPermission(String worldName, String name, String permission);
public boolean inGroup(String player, String group);
public String[] getGroups(String player);
public boolean hasPermission(OfflinePlayer player, String permission);
public boolean hasPermission(String worldName, OfflinePlayer player, String permission);
public boolean inGroup(OfflinePlayer player, String group);
public String[] getGroups(OfflinePlayer player);
}

Datei anzeigen

@ -1,26 +1,26 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.wepif;
public interface PermissionsResolver extends PermissionsProvider {
public void load();
public String getDetectionMessage();
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.wepif;
public interface PermissionsResolver extends PermissionsProvider {
public void load();
public String getDetectionMessage();
}

Datei anzeigen

@ -1,298 +1,298 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.wepif;
import com.sk89q.util.yaml.YAMLFormat;
import com.sk89q.util.yaml.YAMLProcessor;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.event.EventHandler;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.plugin.Plugin;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;
public class PermissionsResolverManager implements PermissionsResolver {
private static final String CONFIG_HEADER = "#\r\n" +
"# WEPIF Configuration File\r\n" +
"#\r\n" +
"# This file handles permissions configuration for every plugin using WEPIF\r\n" +
"#\r\n" +
"# About editing this file:\r\n" +
"# - DO NOT USE TABS. You MUST use spaces or Bukkit will complain. If\r\n" +
"# you use an editor like Notepad++ (recommended for Windows users), you\r\n" +
"# must configure it to \"replace tabs with spaces.\" In Notepad++, this can\r\n" +
"# be changed in Settings > Preferences > Language Menu.\r\n" +
"# - Don't get rid of the indents. They are indented so some entries are\r\n" +
"# in categories (like \"enforce-single-session\" is in the \"protection\"\r\n" +
"# category.\r\n" +
"# - If you want to check the format of this file before putting it\r\n" +
"# into WEPIF, paste it into http://yaml-online-parser.appspot.com/\r\n" +
"# and see if it gives \"ERROR:\".\r\n" +
"# - Lines starting with # are comments and so they are ignored.\r\n" +
"#\r\n" +
"# About Configuration Permissions\r\n" +
"# - See http://wiki.sk89q.com/wiki/WorldEdit/Permissions/Bukkit\r\n" +
"# - Now with multiworld support (see example)\r\n" +
"\r\n";
private static PermissionsResolverManager instance;
public static void initialize(Plugin plugin) {
if (!isInitialized()) {
instance = new PermissionsResolverManager(plugin);
}
}
public static boolean isInitialized() {
return instance != null;
}
public static PermissionsResolverManager getInstance() {
if (!isInitialized()) {
throw new WEPIFRuntimeException("WEPIF has not yet been initialized!");
}
return instance;
}
private Server server;
private PermissionsResolver permissionResolver;
private YAMLProcessor config;
private Logger logger = Logger.getLogger(getClass().getCanonicalName());
private List<Class<? extends PermissionsResolver>> enabledResolvers = new ArrayList<Class<? extends PermissionsResolver>>();
@SuppressWarnings("unchecked")
protected Class<? extends PermissionsResolver>[] availableResolvers = new Class[] {
PluginPermissionsResolver.class,
PermissionsExResolver.class,
bPermissionsResolver.class,
GroupManagerResolver.class,
NijiPermissionsResolver.class,
DinnerPermsResolver.class,
FlatFilePermissionsResolver.class
};
protected PermissionsResolverManager(Plugin plugin) {
this.server = plugin.getServer();
(new ServerListener()).register(plugin); // Register the events
loadConfig(new File("wepif.yml"));
findResolver();
}
public void findResolver() {
for (Class<? extends PermissionsResolver> resolverClass : enabledResolvers) {
try {
Method factoryMethod = resolverClass.getMethod("factory", Server.class, YAMLProcessor.class);
this.permissionResolver = (PermissionsResolver) factoryMethod.invoke(null, this.server, this.config);
if (this.permissionResolver != null) {
break;
}
} catch (Throwable e) {
logger.warning("Error in factory method for " + resolverClass.getSimpleName() + ": " + e);
e.printStackTrace();
continue;
}
}
if (permissionResolver == null) {
permissionResolver = new ConfigurationPermissionsResolver(config);
}
permissionResolver.load();
logger.info("WEPIF: " + permissionResolver.getDetectionMessage());
}
public void setPluginPermissionsResolver(Plugin plugin) {
if (!(plugin instanceof PermissionsProvider)) {
return;
}
permissionResolver = new PluginPermissionsResolver((PermissionsProvider) plugin, plugin);
logger.info("WEPIF: " + permissionResolver.getDetectionMessage());
}
public void load() {
findResolver();
}
public boolean hasPermission(String name, String permission) {
return permissionResolver.hasPermission(name, permission);
}
public boolean hasPermission(String worldName, String name, String permission) {
return permissionResolver.hasPermission(worldName, name, permission);
}
public boolean inGroup(String player, String group) {
return permissionResolver.inGroup(player, group);
}
public String[] getGroups(String player) {
return permissionResolver.getGroups(player);
}
public boolean hasPermission(OfflinePlayer player, String permission) {
return permissionResolver.hasPermission(player, permission);
}
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
return permissionResolver.hasPermission(worldName, player, permission);
}
public boolean inGroup(OfflinePlayer player, String group) {
return permissionResolver.inGroup(player, group);
}
public String[] getGroups(OfflinePlayer player) {
return permissionResolver.getGroups(player);
}
public String getDetectionMessage() {
return "Using WEPIF for permissions";
}
private boolean loadConfig(File file) {
boolean isUpdated = false;
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
config = new YAMLProcessor(file, false, YAMLFormat.EXTENDED);
try {
config.load();
} catch (IOException e) {
logger.severe("Error loading WEPIF Config: " + e);
e.printStackTrace();
}
List<String> keys = config.getKeys(null);
config.setHeader(CONFIG_HEADER);
if (!keys.contains("ignore-nijiperms-bridges")) {
config.setProperty("ignore-nijiperms-bridges", true);
isUpdated = true;
}
if (!keys.contains("resolvers")) {
//List<String> resolverKeys = config.getKeys("resolvers");
List<String> resolvers = new ArrayList<String>();
for (Class<?> clazz : availableResolvers) {
resolvers.add(clazz.getSimpleName());
}
enabledResolvers.addAll(Arrays.asList(availableResolvers));
config.setProperty("resolvers.enabled", resolvers);
isUpdated = true;
} else {
List<String> disabledResolvers = config.getStringList("resolvers.disabled", new ArrayList<String>());
List<String> stagedEnabled = config.getStringList("resolvers.enabled", null);
for (Iterator<String> i = stagedEnabled.iterator(); i.hasNext();) {
String nextName = i.next();
Class<?> next = null;
try {
next = Class.forName(getClass().getPackage().getName() + "." + nextName);
} catch (ClassNotFoundException e) {}
if (next == null || !PermissionsResolver.class.isAssignableFrom(next)) {
logger.warning("WEPIF: Invalid or unknown class found in enabled resolvers: "
+ nextName + ". Moving to disabled resolvers list.");
i.remove();
disabledResolvers.add(nextName);
isUpdated = true;
continue;
}
enabledResolvers.add(next.asSubclass(PermissionsResolver.class));
}
for (Class<?> clazz : availableResolvers) {
if (!stagedEnabled.contains(clazz.getSimpleName()) &&
!disabledResolvers.contains(clazz.getSimpleName())) {
disabledResolvers.add(clazz.getSimpleName());
logger.info("New permissions resolver: "
+ clazz.getSimpleName() + " detected. " +
"Added to disabled resolvers list.");
isUpdated = true;
}
}
config.setProperty("resolvers.disabled", disabledResolvers);
config.setProperty("resolvers.enabled", stagedEnabled);
}
if (keys.contains("dinner-perms") || keys.contains("dinnerperms")) {
config.removeProperty("dinner-perms");
config.removeProperty("dinnerperms");
isUpdated = true;
}
if (!keys.contains("permissions")) {
ConfigurationPermissionsResolver.generateDefaultPerms(
config.addNode("permissions"));
isUpdated = true;
}
if (isUpdated) {
logger.info("WEPIF: Updated config file");
config.save();
}
return isUpdated;
}
public static class MissingPluginException extends Exception {
private static final long serialVersionUID = 7044832912491608706L;
}
class ServerListener implements org.bukkit.event.Listener {
@EventHandler
public void onPluginEnable(PluginEnableEvent event) {
Plugin plugin = event.getPlugin();
String name = plugin.getDescription().getName();
if (plugin instanceof PermissionsProvider) {
setPluginPermissionsResolver(plugin);
} else if ("permissions".equalsIgnoreCase(name) || "permissionsex".equalsIgnoreCase(name)
|| "bpermissions".equalsIgnoreCase(name) || "groupmanager".equalsIgnoreCase(name)) {
load();
}
}
@EventHandler
public void onPluginDisable(PluginDisableEvent event) {
String name = event.getPlugin().getDescription().getName();
if (event.getPlugin() instanceof PermissionsProvider
|| "permissions".equalsIgnoreCase(name) || "permissionsex".equalsIgnoreCase(name)
|| "bpermissions".equalsIgnoreCase(name) || "groupmanager".equalsIgnoreCase(name)) {
load();
}
}
void register(Plugin plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.wepif;
import com.sk89q.util.yaml.YAMLFormat;
import com.sk89q.util.yaml.YAMLProcessor;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.event.EventHandler;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.plugin.Plugin;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;
public class PermissionsResolverManager implements PermissionsResolver {
private static final String CONFIG_HEADER = "#\r\n" +
"# WEPIF Configuration File\r\n" +
"#\r\n" +
"# This file handles permissions configuration for every plugin using WEPIF\r\n" +
"#\r\n" +
"# About editing this file:\r\n" +
"# - DO NOT USE TABS. You MUST use spaces or Bukkit will complain. If\r\n" +
"# you use an editor like Notepad++ (recommended for Windows users), you\r\n" +
"# must configure it to \"replace tabs with spaces.\" In Notepad++, this can\r\n" +
"# be changed in Settings > Preferences > Language Menu.\r\n" +
"# - Don't get rid of the indents. They are indented so some entries are\r\n" +
"# in categories (like \"enforce-single-session\" is in the \"protection\"\r\n" +
"# category.\r\n" +
"# - If you want to check the format of this file before putting it\r\n" +
"# into WEPIF, paste it into http://yaml-online-parser.appspot.com/\r\n" +
"# and see if it gives \"ERROR:\".\r\n" +
"# - Lines starting with # are comments and so they are ignored.\r\n" +
"#\r\n" +
"# About Configuration Permissions\r\n" +
"# - See http://wiki.sk89q.com/wiki/WorldEdit/Permissions/Bukkit\r\n" +
"# - Now with multiworld support (see example)\r\n" +
"\r\n";
private static PermissionsResolverManager instance;
public static void initialize(Plugin plugin) {
if (!isInitialized()) {
instance = new PermissionsResolverManager(plugin);
}
}
public static boolean isInitialized() {
return instance != null;
}
public static PermissionsResolverManager getInstance() {
if (!isInitialized()) {
throw new WEPIFRuntimeException("WEPIF has not yet been initialized!");
}
return instance;
}
private Server server;
private PermissionsResolver permissionResolver;
private YAMLProcessor config;
private Logger logger = Logger.getLogger(getClass().getCanonicalName());
private List<Class<? extends PermissionsResolver>> enabledResolvers = new ArrayList<Class<? extends PermissionsResolver>>();
@SuppressWarnings("unchecked")
protected Class<? extends PermissionsResolver>[] availableResolvers = new Class[] {
PluginPermissionsResolver.class,
PermissionsExResolver.class,
bPermissionsResolver.class,
GroupManagerResolver.class,
NijiPermissionsResolver.class,
DinnerPermsResolver.class,
FlatFilePermissionsResolver.class
};
protected PermissionsResolverManager(Plugin plugin) {
this.server = plugin.getServer();
(new ServerListener()).register(plugin); // Register the events
loadConfig(new File("wepif.yml"));
findResolver();
}
public void findResolver() {
for (Class<? extends PermissionsResolver> resolverClass : enabledResolvers) {
try {
Method factoryMethod = resolverClass.getMethod("factory", Server.class, YAMLProcessor.class);
this.permissionResolver = (PermissionsResolver) factoryMethod.invoke(null, this.server, this.config);
if (this.permissionResolver != null) {
break;
}
} catch (Throwable e) {
logger.warning("Error in factory method for " + resolverClass.getSimpleName() + ": " + e);
e.printStackTrace();
continue;
}
}
if (permissionResolver == null) {
permissionResolver = new ConfigurationPermissionsResolver(config);
}
permissionResolver.load();
logger.info("WEPIF: " + permissionResolver.getDetectionMessage());
}
public void setPluginPermissionsResolver(Plugin plugin) {
if (!(plugin instanceof PermissionsProvider)) {
return;
}
permissionResolver = new PluginPermissionsResolver((PermissionsProvider) plugin, plugin);
logger.info("WEPIF: " + permissionResolver.getDetectionMessage());
}
public void load() {
findResolver();
}
public boolean hasPermission(String name, String permission) {
return permissionResolver.hasPermission(name, permission);
}
public boolean hasPermission(String worldName, String name, String permission) {
return permissionResolver.hasPermission(worldName, name, permission);
}
public boolean inGroup(String player, String group) {
return permissionResolver.inGroup(player, group);
}
public String[] getGroups(String player) {
return permissionResolver.getGroups(player);
}
public boolean hasPermission(OfflinePlayer player, String permission) {
return permissionResolver.hasPermission(player, permission);
}
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
return permissionResolver.hasPermission(worldName, player, permission);
}
public boolean inGroup(OfflinePlayer player, String group) {
return permissionResolver.inGroup(player, group);
}
public String[] getGroups(OfflinePlayer player) {
return permissionResolver.getGroups(player);
}
public String getDetectionMessage() {
return "Using WEPIF for permissions";
}
private boolean loadConfig(File file) {
boolean isUpdated = false;
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
config = new YAMLProcessor(file, false, YAMLFormat.EXTENDED);
try {
config.load();
} catch (IOException e) {
logger.severe("Error loading WEPIF Config: " + e);
e.printStackTrace();
}
List<String> keys = config.getKeys(null);
config.setHeader(CONFIG_HEADER);
if (!keys.contains("ignore-nijiperms-bridges")) {
config.setProperty("ignore-nijiperms-bridges", true);
isUpdated = true;
}
if (!keys.contains("resolvers")) {
//List<String> resolverKeys = config.getKeys("resolvers");
List<String> resolvers = new ArrayList<String>();
for (Class<?> clazz : availableResolvers) {
resolvers.add(clazz.getSimpleName());
}
enabledResolvers.addAll(Arrays.asList(availableResolvers));
config.setProperty("resolvers.enabled", resolvers);
isUpdated = true;
} else {
List<String> disabledResolvers = config.getStringList("resolvers.disabled", new ArrayList<String>());
List<String> stagedEnabled = config.getStringList("resolvers.enabled", null);
for (Iterator<String> i = stagedEnabled.iterator(); i.hasNext();) {
String nextName = i.next();
Class<?> next = null;
try {
next = Class.forName(getClass().getPackage().getName() + "." + nextName);
} catch (ClassNotFoundException e) {}
if (next == null || !PermissionsResolver.class.isAssignableFrom(next)) {
logger.warning("WEPIF: Invalid or unknown class found in enabled resolvers: "
+ nextName + ". Moving to disabled resolvers list.");
i.remove();
disabledResolvers.add(nextName);
isUpdated = true;
continue;
}
enabledResolvers.add(next.asSubclass(PermissionsResolver.class));
}
for (Class<?> clazz : availableResolvers) {
if (!stagedEnabled.contains(clazz.getSimpleName()) &&
!disabledResolvers.contains(clazz.getSimpleName())) {
disabledResolvers.add(clazz.getSimpleName());
logger.info("New permissions resolver: "
+ clazz.getSimpleName() + " detected. " +
"Added to disabled resolvers list.");
isUpdated = true;
}
}
config.setProperty("resolvers.disabled", disabledResolvers);
config.setProperty("resolvers.enabled", stagedEnabled);
}
if (keys.contains("dinner-perms") || keys.contains("dinnerperms")) {
config.removeProperty("dinner-perms");
config.removeProperty("dinnerperms");
isUpdated = true;
}
if (!keys.contains("permissions")) {
ConfigurationPermissionsResolver.generateDefaultPerms(
config.addNode("permissions"));
isUpdated = true;
}
if (isUpdated) {
logger.info("WEPIF: Updated config file");
config.save();
}
return isUpdated;
}
public static class MissingPluginException extends Exception {
private static final long serialVersionUID = 7044832912491608706L;
}
class ServerListener implements org.bukkit.event.Listener {
@EventHandler
public void onPluginEnable(PluginEnableEvent event) {
Plugin plugin = event.getPlugin();
String name = plugin.getDescription().getName();
if (plugin instanceof PermissionsProvider) {
setPluginPermissionsResolver(plugin);
} else if ("permissions".equalsIgnoreCase(name) || "permissionsex".equalsIgnoreCase(name)
|| "bpermissions".equalsIgnoreCase(name) || "groupmanager".equalsIgnoreCase(name)) {
load();
}
}
@EventHandler
public void onPluginDisable(PluginDisableEvent event) {
String name = event.getPlugin().getDescription().getName();
if (event.getPlugin() instanceof PermissionsProvider
|| "permissions".equalsIgnoreCase(name) || "permissionsex".equalsIgnoreCase(name)
|| "bpermissions".equalsIgnoreCase(name) || "groupmanager".equalsIgnoreCase(name)) {
load();
}
}
void register(Plugin plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
}
}

Datei anzeigen

@ -1,95 +1,95 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.wepif;
import com.sk89q.util.yaml.YAMLProcessor;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
public class PluginPermissionsResolver implements PermissionsResolver {
protected PermissionsProvider resolver;
protected Plugin plugin;
public static PermissionsResolver factory(Server server, YAMLProcessor config) {
// Looking for service
RegisteredServiceProvider<PermissionsProvider> serviceProvider = server.getServicesManager().getRegistration(PermissionsProvider.class);
if (serviceProvider != null) {
return new PluginPermissionsResolver(serviceProvider.getProvider(), serviceProvider.getPlugin());
}
// Looking for plugin
for (Plugin plugin : server.getPluginManager().getPlugins()) {
if (plugin instanceof PermissionsProvider) {
return new PluginPermissionsResolver((PermissionsProvider) plugin, plugin);
}
}
return null;
}
public PluginPermissionsResolver(PermissionsProvider resolver, Plugin permissionsPlugin) {
this.resolver = resolver;
this.plugin = permissionsPlugin;
}
public void load() {
}
public boolean hasPermission(String name, String permission) {
return resolver.hasPermission(name, permission);
}
public boolean hasPermission(String worldName, String name, String permission) {
return resolver.hasPermission(worldName, name, permission);
}
public boolean inGroup(String player, String group) {
return resolver.inGroup(player, group);
}
public String[] getGroups(String player) {
return resolver.getGroups(player);
}
public boolean hasPermission(OfflinePlayer player, String permission) {
return resolver.hasPermission(player, permission);
}
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
return resolver.hasPermission(worldName, player, permission);
}
public boolean inGroup(OfflinePlayer player, String group) {
return resolver.inGroup(player, group);
}
public String[] getGroups(OfflinePlayer player) {
return resolver.getGroups(player);
}
public String getDetectionMessage() {
return "Using plugin '" + this.plugin.getDescription().getName() + "' for permissions.";
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.wepif;
import com.sk89q.util.yaml.YAMLProcessor;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
public class PluginPermissionsResolver implements PermissionsResolver {
protected PermissionsProvider resolver;
protected Plugin plugin;
public static PermissionsResolver factory(Server server, YAMLProcessor config) {
// Looking for service
RegisteredServiceProvider<PermissionsProvider> serviceProvider = server.getServicesManager().getRegistration(PermissionsProvider.class);
if (serviceProvider != null) {
return new PluginPermissionsResolver(serviceProvider.getProvider(), serviceProvider.getPlugin());
}
// Looking for plugin
for (Plugin plugin : server.getPluginManager().getPlugins()) {
if (plugin instanceof PermissionsProvider) {
return new PluginPermissionsResolver((PermissionsProvider) plugin, plugin);
}
}
return null;
}
public PluginPermissionsResolver(PermissionsProvider resolver, Plugin permissionsPlugin) {
this.resolver = resolver;
this.plugin = permissionsPlugin;
}
public void load() {
}
public boolean hasPermission(String name, String permission) {
return resolver.hasPermission(name, permission);
}
public boolean hasPermission(String worldName, String name, String permission) {
return resolver.hasPermission(worldName, name, permission);
}
public boolean inGroup(String player, String group) {
return resolver.inGroup(player, group);
}
public String[] getGroups(String player) {
return resolver.getGroups(player);
}
public boolean hasPermission(OfflinePlayer player, String permission) {
return resolver.hasPermission(player, permission);
}
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
return resolver.hasPermission(worldName, player, permission);
}
public boolean inGroup(OfflinePlayer player, String group) {
return resolver.inGroup(player, group);
}
public String[] getGroups(OfflinePlayer player) {
return resolver.getGroups(player);
}
public String getDetectionMessage() {
return "Using plugin '" + this.plugin.getDescription().getName() + "' for permissions.";
}
}

Datei anzeigen

@ -1,31 +1,31 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.wepif;
/**
* @author zml2008
*/
public class WEPIFRuntimeException extends RuntimeException {
private static final long serialVersionUID = 5092745960439109699L;
public WEPIFRuntimeException(String message) {
super(message);
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.wepif;
/**
* @author zml2008
*/
public class WEPIFRuntimeException extends RuntimeException {
private static final long serialVersionUID = 5092745960439109699L;
public WEPIFRuntimeException(String message) {
super(message);
}
}

Datei anzeigen

@ -1,134 +1,134 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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 org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.PlayerNeededException;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.bags.BlockBag;
public class BukkitCommandSender extends LocalPlayer {
private CommandSender sender;
private WorldEditPlugin plugin;
public BukkitCommandSender(WorldEditPlugin plugin, ServerInterface server, CommandSender sender) {
super(server);
this.plugin = plugin;
this.sender = sender;
}
@Override
public String getName() {
return sender.getName();
}
@Override
public void printRaw(String msg) {
for (String part : msg.split("\n")) {
sender.sendMessage(part);
}
}
@Override
public void print(String msg) {
for (String part : msg.split("\n")) {
sender.sendMessage("\u00A7d" + part);
}
}
@Override
public void printDebug(String msg) {
for (String part : msg.split("\n")) {
sender.sendMessage("\u00A77" + part);
}
}
@Override
public void printError(String msg) {
for (String part : msg.split("\n")) {
sender.sendMessage("\u00A7c" + part);
}
}
@Override
public String[] getGroups() {
return new String[0];
}
@Override
public boolean hasPermission(String perm) {
if (!plugin.getLocalConfiguration().noOpPermissions && sender.isOp()) {
return true;
}
return plugin.getPermissionsResolver().hasPermission(null, sender.getName(), perm);
}
@Override
public boolean isPlayer() {
return sender instanceof Player;
}
@Override
public int getItemInHand() {
throw new PlayerNeededException();
}
@Override
public WorldVector getPosition() {
throw new PlayerNeededException();
}
@Override
public LocalWorld getWorld() {
throw new PlayerNeededException();
}
@Override
public double getPitch() {
throw new PlayerNeededException();
}
@Override
public double getYaw() {
throw new PlayerNeededException();
}
@Override
public void giveItem(int type, int amt) {
throw new PlayerNeededException();
}
@Override
public void setPosition(Vector pos, float pitch, float yaw) {
throw new PlayerNeededException();
}
@Override
public BlockBag getInventoryBlockBag() {
throw new PlayerNeededException();
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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 org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.PlayerNeededException;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.extent.inventory.BlockBag;
public class BukkitCommandSender extends LocalPlayer {
private CommandSender sender;
private WorldEditPlugin plugin;
public BukkitCommandSender(WorldEditPlugin plugin, ServerInterface server, CommandSender sender) {
super(server);
this.plugin = plugin;
this.sender = sender;
}
@Override
public String getName() {
return sender.getName();
}
@Override
public void printRaw(String msg) {
for (String part : msg.split("\n")) {
sender.sendMessage(part);
}
}
@Override
public void print(String msg) {
for (String part : msg.split("\n")) {
sender.sendMessage("\u00A7d" + part);
}
}
@Override
public void printDebug(String msg) {
for (String part : msg.split("\n")) {
sender.sendMessage("\u00A77" + part);
}
}
@Override
public void printError(String msg) {
for (String part : msg.split("\n")) {
sender.sendMessage("\u00A7c" + part);
}
}
@Override
public String[] getGroups() {
return new String[0];
}
@Override
public boolean hasPermission(String perm) {
if (!plugin.getLocalConfiguration().noOpPermissions && sender.isOp()) {
return true;
}
return plugin.getPermissionsResolver().hasPermission(null, sender.getName(), perm);
}
@Override
public boolean isPlayer() {
return sender instanceof Player;
}
@Override
public int getItemInHand() {
throw new PlayerNeededException();
}
@Override
public WorldVector getPosition() {
throw new PlayerNeededException();
}
@Override
public LocalWorld getWorld() {
throw new PlayerNeededException();
}
@Override
public double getPitch() {
throw new PlayerNeededException();
}
@Override
public double getYaw() {
throw new PlayerNeededException();
}
@Override
public void giveItem(int type, int amt) {
throw new PlayerNeededException();
}
@Override
public void setPosition(Vector pos, float pitch, float yaw) {
throw new PlayerNeededException();
}
@Override
public BlockBag getInventoryBlockBag() {
throw new PlayerNeededException();
}
}

Datei anzeigen

@ -1,171 +1,171 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.cui.CUIEvent;
public class BukkitPlayer extends LocalPlayer {
private Player player;
private WorldEditPlugin plugin;
public BukkitPlayer(WorldEditPlugin plugin, ServerInterface server, Player player) {
super(server);
this.plugin = plugin;
this.player = player;
}
@Override
public int getItemInHand() {
ItemStack itemStack = player.getItemInHand();
return itemStack != null ? itemStack.getTypeId() : 0;
}
public BaseBlock getBlockInHand() throws WorldEditException {
ItemStack itemStack = player.getItemInHand();
return BukkitUtil.toBlock(getWorld(), itemStack);
}
@Override
public String getName() {
return player.getName();
}
@Override
public WorldVector getPosition() {
Location loc = player.getLocation();
return new WorldVector(BukkitUtil.getLocalWorld(loc.getWorld()),
loc.getX(), loc.getY(), loc.getZ());
}
@Override
public double getPitch() {
return player.getLocation().getPitch();
}
@Override
public double getYaw() {
return player.getLocation().getYaw();
}
@Override
public void giveItem(int type, int amt) {
player.getInventory().addItem(new ItemStack(type, amt));
}
@Override
public void printRaw(String msg) {
for (String part : msg.split("\n")) {
player.sendMessage(part);
}
}
@Override
public void print(String msg) {
for (String part : msg.split("\n")) {
player.sendMessage("\u00A7d" + part);
}
}
@Override
public void printDebug(String msg) {
for (String part : msg.split("\n")) {
player.sendMessage("\u00A77" + part);
}
}
@Override
public void printError(String msg) {
for (String part : msg.split("\n")) {
player.sendMessage("\u00A7c" + part);
}
}
@Override
public void setPosition(Vector pos, float pitch, float yaw) {
player.teleport(new Location(player.getWorld(), pos.getX(), pos.getY(),
pos.getZ(), yaw, pitch));
}
@Override
public String[] getGroups() {
return plugin.getPermissionsResolver().getGroups(player);
}
@Override
public BlockBag getInventoryBlockBag() {
return new BukkitPlayerBlockBag(player);
}
@Override
public boolean hasPermission(String perm) {
return (!plugin.getLocalConfiguration().noOpPermissions && player.isOp())
|| plugin.getPermissionsResolver().hasPermission(
player.getWorld().getName(), player, perm);
}
@Override
public LocalWorld getWorld() {
return BukkitUtil.getLocalWorld(player.getWorld());
}
@Override
public void dispatchCUIEvent(CUIEvent event) {
String[] params = event.getParameters();
String send = event.getTypeId();
if (params.length > 0) {
send = send + "|" + StringUtil.joinString(params, "|");
}
player.sendPluginMessage(plugin, WorldEditPlugin.CUI_PLUGIN_CHANNEL, send.getBytes(CUIChannelListener.UTF_8_CHARSET));
}
public Player getPlayer() {
return player;
}
@Override
public boolean hasCreativeMode() {
return player.getGameMode() == GameMode.CREATIVE;
}
@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
if (alwaysGlass || !player.getAllowFlight()) {
super.floatAt(x, y, z, alwaysGlass);
return;
}
setPosition(new Vector(x + 0.5, y, z + 0.5));
player.setFlying(true);
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.cui.CUIEvent;
public class BukkitPlayer extends LocalPlayer {
private Player player;
private WorldEditPlugin plugin;
public BukkitPlayer(WorldEditPlugin plugin, ServerInterface server, Player player) {
super(server);
this.plugin = plugin;
this.player = player;
}
@Override
public int getItemInHand() {
ItemStack itemStack = player.getItemInHand();
return itemStack != null ? itemStack.getTypeId() : 0;
}
public BaseBlock getBlockInHand() throws WorldEditException {
ItemStack itemStack = player.getItemInHand();
return BukkitUtil.toBlock(getWorld(), itemStack);
}
@Override
public String getName() {
return player.getName();
}
@Override
public WorldVector getPosition() {
Location loc = player.getLocation();
return new WorldVector(BukkitUtil.getLocalWorld(loc.getWorld()),
loc.getX(), loc.getY(), loc.getZ());
}
@Override
public double getPitch() {
return player.getLocation().getPitch();
}
@Override
public double getYaw() {
return player.getLocation().getYaw();
}
@Override
public void giveItem(int type, int amt) {
player.getInventory().addItem(new ItemStack(type, amt));
}
@Override
public void printRaw(String msg) {
for (String part : msg.split("\n")) {
player.sendMessage(part);
}
}
@Override
public void print(String msg) {
for (String part : msg.split("\n")) {
player.sendMessage("\u00A7d" + part);
}
}
@Override
public void printDebug(String msg) {
for (String part : msg.split("\n")) {
player.sendMessage("\u00A77" + part);
}
}
@Override
public void printError(String msg) {
for (String part : msg.split("\n")) {
player.sendMessage("\u00A7c" + part);
}
}
@Override
public void setPosition(Vector pos, float pitch, float yaw) {
player.teleport(new Location(player.getWorld(), pos.getX(), pos.getY(),
pos.getZ(), yaw, pitch));
}
@Override
public String[] getGroups() {
return plugin.getPermissionsResolver().getGroups(player);
}
@Override
public BlockBag getInventoryBlockBag() {
return new BukkitPlayerBlockBag(player);
}
@Override
public boolean hasPermission(String perm) {
return (!plugin.getLocalConfiguration().noOpPermissions && player.isOp())
|| plugin.getPermissionsResolver().hasPermission(
player.getWorld().getName(), player, perm);
}
@Override
public LocalWorld getWorld() {
return BukkitUtil.getLocalWorld(player.getWorld());
}
@Override
public void dispatchCUIEvent(CUIEvent event) {
String[] params = event.getParameters();
String send = event.getTypeId();
if (params.length > 0) {
send = send + "|" + StringUtil.joinString(params, "|");
}
player.sendPluginMessage(plugin, WorldEditPlugin.CUI_PLUGIN_CHANNEL, send.getBytes(CUIChannelListener.UTF_8_CHARSET));
}
public Player getPlayer() {
return player;
}
@Override
public boolean hasCreativeMode() {
return player.getGameMode() == GameMode.CREATIVE;
}
@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
if (alwaysGlass || !player.getAllowFlight()) {
super.floatAt(x, y, z, alwaysGlass);
return;
}
setPosition(new Vector(x + 0.5, y, z + 0.5));
player.setFlying(true);
}
}

Datei anzeigen

@ -1,228 +1,228 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.WorldVector;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.sk89q.worldedit.bags.*;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.ItemType;
public class BukkitPlayerBlockBag extends BlockBag {
/**
* Player instance.
*/
private Player player;
/**
* The player's inventory;
*/
private ItemStack[] items;
/**
* Construct the object.
*
* @param player
*/
public BukkitPlayerBlockBag(Player player) {
this.player = player;
}
/**
* Loads inventory on first use.
*/
private void loadInventory() {
if (items == null) {
items = player.getInventory().getContents();
}
}
/**
* Get the player.
*
* @return
*/
public Player getPlayer() {
return player;
}
/**
* Get a block.
*
* @param id
*/
@Override
public void fetchItem(BaseItem item) throws BlockBagException {
final int id = item.getType();
final int damage = item.getData();
int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
assert(amount == 1);
boolean usesDamageValue = ItemType.usesDamageValue(id);
if (id == BlockID.AIR) {
throw new IllegalArgumentException("Can't fetch air block");
}
loadInventory();
boolean found = false;
for (int slot = 0; slot < items.length; ++slot) {
ItemStack bukkitItem = items[slot];
if (bukkitItem == null) {
continue;
}
if (bukkitItem.getTypeId() != id) {
// Type id doesn't fit
continue;
}
if (usesDamageValue && bukkitItem.getDurability() != damage) {
// Damage value doesn't fit.
continue;
}
int currentAmount = bukkitItem.getAmount();
if (currentAmount < 0) {
// Unlimited
return;
}
if (currentAmount > 1) {
bukkitItem.setAmount(currentAmount - 1);
found = true;
} else {
items[slot] = null;
found = true;
}
break;
}
if (!found) {
throw new OutOfBlocksException();
}
}
/**
* Store a block.
*
* @param id
*/
@Override
public void storeItem(BaseItem item) throws BlockBagException {
final int id = item.getType();
final int damage = item.getData();
int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
assert(amount <= 64);
boolean usesDamageValue = ItemType.usesDamageValue(id);
if (id == BlockID.AIR) {
throw new IllegalArgumentException("Can't store air block");
}
loadInventory();
int freeSlot = -1;
for (int slot = 0; slot < items.length; ++slot) {
ItemStack bukkitItem = items[slot];
if (bukkitItem == null) {
// Delay using up a free slot until we know there are no stacks
// of this item to merge into
if (freeSlot == -1) {
freeSlot = slot;
}
continue;
}
if (bukkitItem.getTypeId() != id) {
// Type id doesn't fit
continue;
}
if (usesDamageValue && bukkitItem.getDurability() != damage) {
// Damage value doesn't fit.
continue;
}
int currentAmount = bukkitItem.getAmount();
if (currentAmount < 0) {
// Unlimited
return;
}
if (currentAmount >= 64) {
// Full stack
continue;
}
int spaceLeft = 64 - currentAmount;
if (spaceLeft >= amount) {
bukkitItem.setAmount(currentAmount + amount);
return;
}
bukkitItem.setAmount(64);
amount -= spaceLeft;
}
if (freeSlot > -1) {
items[freeSlot] = new ItemStack(id, amount);
return;
}
throw new OutOfSpaceException(id);
}
/**
* Flush any changes. This is called at the end.
*/
@Override
public void flushChanges() {
if (items != null) {
player.getInventory().setContents(items);
items = null;
}
}
/**
* Adds a position to be used a source.
*
* @param pos
*/
@Override
public void addSourcePosition(WorldVector pos) {
}
/**
* Adds a position to be used a source.
*
* @param pos
*/
@Override
public void addSingleSourcePosition(WorldVector pos) {
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.WorldVector;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.sk89q.worldedit.extent.inventory.*;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.ItemType;
public class BukkitPlayerBlockBag extends BlockBag {
/**
* Player instance.
*/
private Player player;
/**
* The player's inventory;
*/
private ItemStack[] items;
/**
* Construct the object.
*
* @param player
*/
public BukkitPlayerBlockBag(Player player) {
this.player = player;
}
/**
* Loads inventory on first use.
*/
private void loadInventory() {
if (items == null) {
items = player.getInventory().getContents();
}
}
/**
* Get the player.
*
* @return
*/
public Player getPlayer() {
return player;
}
/**
* Get a block.
*
* @param id
*/
@Override
public void fetchItem(BaseItem item) throws BlockBagException {
final int id = item.getType();
final int damage = item.getData();
int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
assert(amount == 1);
boolean usesDamageValue = ItemType.usesDamageValue(id);
if (id == BlockID.AIR) {
throw new IllegalArgumentException("Can't fetch air block");
}
loadInventory();
boolean found = false;
for (int slot = 0; slot < items.length; ++slot) {
ItemStack bukkitItem = items[slot];
if (bukkitItem == null) {
continue;
}
if (bukkitItem.getTypeId() != id) {
// Type id doesn't fit
continue;
}
if (usesDamageValue && bukkitItem.getDurability() != damage) {
// Damage value doesn't fit.
continue;
}
int currentAmount = bukkitItem.getAmount();
if (currentAmount < 0) {
// Unlimited
return;
}
if (currentAmount > 1) {
bukkitItem.setAmount(currentAmount - 1);
found = true;
} else {
items[slot] = null;
found = true;
}
break;
}
if (!found) {
throw new OutOfBlocksException();
}
}
/**
* Store a block.
*
* @param id
*/
@Override
public void storeItem(BaseItem item) throws BlockBagException {
final int id = item.getType();
final int damage = item.getData();
int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
assert(amount <= 64);
boolean usesDamageValue = ItemType.usesDamageValue(id);
if (id == BlockID.AIR) {
throw new IllegalArgumentException("Can't store air block");
}
loadInventory();
int freeSlot = -1;
for (int slot = 0; slot < items.length; ++slot) {
ItemStack bukkitItem = items[slot];
if (bukkitItem == null) {
// Delay using up a free slot until we know there are no stacks
// of this item to merge into
if (freeSlot == -1) {
freeSlot = slot;
}
continue;
}
if (bukkitItem.getTypeId() != id) {
// Type id doesn't fit
continue;
}
if (usesDamageValue && bukkitItem.getDurability() != damage) {
// Damage value doesn't fit.
continue;
}
int currentAmount = bukkitItem.getAmount();
if (currentAmount < 0) {
// Unlimited
return;
}
if (currentAmount >= 64) {
// Full stack
continue;
}
int spaceLeft = 64 - currentAmount;
if (spaceLeft >= amount) {
bukkitItem.setAmount(currentAmount + amount);
return;
}
bukkitItem.setAmount(64);
amount -= spaceLeft;
}
if (freeSlot > -1) {
items[freeSlot] = new ItemStack(id, amount);
return;
}
throw new OutOfSpaceException(id);
}
/**
* Flush any changes. This is called at the end.
*/
@Override
public void flushChanges() {
if (items != null) {
player.getInventory().setContents(items);
items = null;
}
}
/**
* Adds a position to be used a source.
*
* @param pos
*/
@Override
public void addSourcePosition(WorldVector pos) {
}
/**
* Adds a position to be used a source.
*
* @param pos
*/
@Override
public void addSingleSourcePosition(WorldVector pos) {
}
}

Datei anzeigen

@ -1,125 +1,125 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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 java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.sk89q.bukkit.util.CommandInfo;
import com.sk89q.bukkit.util.CommandRegistration;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.CommandsManager;
import com.sk89q.worldedit.LocalPlayer;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import com.sk89q.worldedit.BiomeTypes;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
public class BukkitServerInterface extends ServerInterface {
public Server server;
public WorldEditPlugin plugin;
private CommandRegistration dynamicCommands;
private BukkitBiomeTypes biomes;
public BukkitServerInterface(WorldEditPlugin plugin, Server server) {
this.plugin = plugin;
this.server = server;
this.biomes = new BukkitBiomeTypes();
dynamicCommands = new CommandRegistration(plugin);
}
@Override
public int resolveItem(String name) {
Material mat = Material.matchMaterial(name);
return mat == null ? 0 : mat.getId();
}
@Override
public boolean isValidMobType(String type) {
final EntityType entityType = EntityType.fromName(type);
return entityType != null && entityType.isAlive();
}
@Override
public void reload() {
plugin.loadConfiguration();
}
@Override
public BiomeTypes getBiomes() {
return biomes;
}
@Override
public int schedule(long delay, long period, Runnable task) {
return Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay, period);
}
@Override
public List<LocalWorld> getWorlds() {
List<World> worlds = server.getWorlds();
List<LocalWorld> ret = new ArrayList<LocalWorld>(worlds.size());
for (World world : worlds) {
ret.add(BukkitUtil.getLocalWorld(world));
}
return ret;
}
@Override
public void onCommandRegistration(List<Command> commands, CommandsManager<LocalPlayer> manager) {
List<CommandInfo> toRegister = new ArrayList<CommandInfo>();
for (Command command : commands) {
List<String> permissions = null;
Method cmdMethod = manager.getMethods().get(null).get(command.aliases()[0]);
Map<String, Method> childMethods = manager.getMethods().get(cmdMethod);
if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) {
permissions = Arrays.asList(cmdMethod.getAnnotation(CommandPermissions.class).value());
} else if (cmdMethod != null && childMethods != null && childMethods.size() > 0) {
permissions = new ArrayList<String>();
for (Method m : childMethods.values()) {
if (m.isAnnotationPresent(CommandPermissions.class)) {
permissions.addAll(Arrays.asList(m.getAnnotation(CommandPermissions.class).value()));
}
}
}
toRegister.add(new CommandInfo(command.usage(), command.desc(), command.aliases(), commands, permissions == null ? null : permissions.toArray(new String[permissions.size()])));
}
dynamicCommands.register(toRegister);
}
public void unregisterCommands() {
dynamicCommands.unregisterCommands();
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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 java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.sk89q.bukkit.util.CommandInfo;
import com.sk89q.bukkit.util.CommandRegistration;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.CommandsManager;
import com.sk89q.worldedit.LocalPlayer;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
import com.sk89q.worldedit.BiomeTypes;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.ServerInterface;
public class BukkitServerInterface extends ServerInterface {
public Server server;
public WorldEditPlugin plugin;
private CommandRegistration dynamicCommands;
private BukkitBiomeTypes biomes;
public BukkitServerInterface(WorldEditPlugin plugin, Server server) {
this.plugin = plugin;
this.server = server;
this.biomes = new BukkitBiomeTypes();
dynamicCommands = new CommandRegistration(plugin);
}
@Override
public int resolveItem(String name) {
Material mat = Material.matchMaterial(name);
return mat == null ? 0 : mat.getId();
}
@Override
public boolean isValidMobType(String type) {
final EntityType entityType = EntityType.fromName(type);
return entityType != null && entityType.isAlive();
}
@Override
public void reload() {
plugin.loadConfiguration();
}
@Override
public BiomeTypes getBiomes() {
return biomes;
}
@Override
public int schedule(long delay, long period, Runnable task) {
return Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, delay, period);
}
@Override
public List<LocalWorld> getWorlds() {
List<World> worlds = server.getWorlds();
List<LocalWorld> ret = new ArrayList<LocalWorld>(worlds.size());
for (World world : worlds) {
ret.add(BukkitUtil.getLocalWorld(world));
}
return ret;
}
@Override
public void onCommandRegistration(List<Command> commands, CommandsManager<LocalPlayer> manager) {
List<CommandInfo> toRegister = new ArrayList<CommandInfo>();
for (Command command : commands) {
List<String> permissions = null;
Method cmdMethod = manager.getMethods().get(null).get(command.aliases()[0]);
Map<String, Method> childMethods = manager.getMethods().get(cmdMethod);
if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) {
permissions = Arrays.asList(cmdMethod.getAnnotation(CommandPermissions.class).value());
} else if (cmdMethod != null && childMethods != null && childMethods.size() > 0) {
permissions = new ArrayList<String>();
for (Method m : childMethods.values()) {
if (m.isAnnotationPresent(CommandPermissions.class)) {
permissions.addAll(Arrays.asList(m.getAnnotation(CommandPermissions.class).value()));
}
}
}
toRegister.add(new CommandInfo(command.usage(), command.desc(), command.aliases(), commands, permissions == null ? null : permissions.toArray(new String[permissions.size()])));
}
dynamicCommands.register(toRegister);
}
public void unregisterCommands() {
dynamicCommands.unregisterCommands();
}
}

Datei anzeigen

@ -1,195 +1,195 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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 java.util.List;
import com.sk89q.worldedit.NotABlockException;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.blocks.ItemID;
import com.sk89q.worldedit.blocks.SkullBlock;
import org.bukkit.DyeColor;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Item;
import org.bukkit.entity.Painting;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockWorldVector;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Location;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.bukkit.entity.BukkitEntity;
import com.sk89q.worldedit.bukkit.entity.BukkitExpOrb;
import com.sk89q.worldedit.bukkit.entity.BukkitItem;
import com.sk89q.worldedit.bukkit.entity.BukkitPainting;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Dye;
public class BukkitUtil {
private BukkitUtil() {
}
public static LocalWorld getLocalWorld(World w) {
return new BukkitWorld(w);
}
public static BlockVector toVector(Block block) {
return new BlockVector(block.getX(), block.getY(), block.getZ());
}
public static BlockVector toVector(BlockFace face) {
return new BlockVector(face.getModX(), face.getModY(), face.getModZ());
}
public static BlockWorldVector toWorldVector(Block block) {
return new BlockWorldVector(getLocalWorld(block.getWorld()), block.getX(), block.getY(), block.getZ());
}
public static Vector toVector(org.bukkit.Location loc) {
return new Vector(loc.getX(), loc.getY(), loc.getZ());
}
public static Location toLocation(org.bukkit.Location loc) {
return new Location(
getLocalWorld(loc.getWorld()),
new Vector(loc.getX(), loc.getY(), loc.getZ()),
loc.getYaw(), loc.getPitch()
);
}
public static Vector toVector(org.bukkit.util.Vector vector) {
return new Vector(vector.getX(), vector.getY(), vector.getZ());
}
public static org.bukkit.Location toLocation(WorldVector pt) {
return new org.bukkit.Location(toWorld(pt), pt.getX(), pt.getY(), pt.getZ());
}
public static org.bukkit.Location toLocation(World world, Vector pt) {
return new org.bukkit.Location(world, pt.getX(), pt.getY(), pt.getZ());
}
public static org.bukkit.Location center(org.bukkit.Location loc) {
return new org.bukkit.Location(
loc.getWorld(),
loc.getBlockX() + 0.5,
loc.getBlockY() + 0.5,
loc.getBlockZ() + 0.5,
loc.getPitch(),
loc.getYaw()
);
}
public static Player matchSinglePlayer(Server server, String name) {
List<Player> players = server.matchPlayer(name);
if (players.size() == 0) {
return null;
}
return players.get(0);
}
public static Block toBlock(BlockWorldVector pt) {
return toWorld(pt).getBlockAt(toLocation(pt));
}
public static World toWorld(WorldVector pt) {
return ((BukkitWorld) pt.getWorld()).getWorld();
}
/**
* Bukkit's Location class has serious problems with floating point
* precision.
*/
@SuppressWarnings("RedundantIfStatement")
public static boolean equals(org.bukkit.Location a, org.bukkit.Location b) {
if (Math.abs(a.getX() - b.getX()) > EQUALS_PRECISION) return false;
if (Math.abs(a.getY() - b.getY()) > EQUALS_PRECISION) return false;
if (Math.abs(a.getZ() - b.getZ()) > EQUALS_PRECISION) return false;
return true;
}
public static final double EQUALS_PRECISION = 0.0001;
public static org.bukkit.Location toLocation(Location location) {
Vector pt = location.getPosition();
return new org.bukkit.Location(
toWorld(location.getWorld()),
pt.getX(), pt.getY(), pt.getZ(),
location.getYaw(), location.getPitch()
);
}
public static World toWorld(final LocalWorld world) {
return ((BukkitWorld) world).getWorld();
}
public static BukkitEntity toLocalEntity(Entity e) {
switch (e.getType()) {
case EXPERIENCE_ORB:
return new BukkitExpOrb(toLocation(e.getLocation()), e.getUniqueId(), ((ExperienceOrb)e).getExperience());
case PAINTING:
Painting paint = (Painting) e;
return new BukkitPainting(toLocation(e.getLocation()), paint.getArt(), paint.getFacing(), e.getUniqueId());
case DROPPED_ITEM:
return new BukkitItem(toLocation(e.getLocation()), ((Item)e).getItemStack(), e.getUniqueId());
default:
return new BukkitEntity(toLocation(e.getLocation()), e.getType(), e.getUniqueId());
}
}
public static BaseBlock toBlock(LocalWorld world, ItemStack itemStack) throws WorldEditException {
final int typeId = itemStack.getTypeId();
switch (typeId) {
case ItemID.INK_SACK:
final Dye materialData = (Dye) itemStack.getData();
if (materialData.getColor() == DyeColor.BROWN) {
return new BaseBlock(BlockID.COCOA_PLANT, -1);
}
break;
case ItemID.HEAD:
return new SkullBlock(0, (byte) itemStack.getDurability());
default:
final BaseBlock baseBlock = BlockType.getBlockForItem(typeId, itemStack.getDurability());
if (baseBlock != null) {
return baseBlock;
}
break;
}
if (world.isValidBlockType(typeId)) {
return new BaseBlock(typeId, -1);
}
throw new NotABlockException(typeId);
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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 java.util.List;
import com.sk89q.worldedit.NotABlockException;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.blocks.ItemID;
import com.sk89q.worldedit.blocks.SkullBlock;
import org.bukkit.DyeColor;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Item;
import org.bukkit.entity.Painting;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.BlockVector;
import com.sk89q.worldedit.BlockWorldVector;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Location;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.bukkit.entity.BukkitEntity;
import com.sk89q.worldedit.bukkit.entity.BukkitExpOrb;
import com.sk89q.worldedit.bukkit.entity.BukkitItem;
import com.sk89q.worldedit.bukkit.entity.BukkitPainting;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Dye;
public class BukkitUtil {
private BukkitUtil() {
}
public static LocalWorld getLocalWorld(World w) {
return new BukkitWorld(w);
}
public static BlockVector toVector(Block block) {
return new BlockVector(block.getX(), block.getY(), block.getZ());
}
public static BlockVector toVector(BlockFace face) {
return new BlockVector(face.getModX(), face.getModY(), face.getModZ());
}
public static BlockWorldVector toWorldVector(Block block) {
return new BlockWorldVector(getLocalWorld(block.getWorld()), block.getX(), block.getY(), block.getZ());
}
public static Vector toVector(org.bukkit.Location loc) {
return new Vector(loc.getX(), loc.getY(), loc.getZ());
}
public static Location toLocation(org.bukkit.Location loc) {
return new Location(
getLocalWorld(loc.getWorld()),
new Vector(loc.getX(), loc.getY(), loc.getZ()),
loc.getYaw(), loc.getPitch()
);
}
public static Vector toVector(org.bukkit.util.Vector vector) {
return new Vector(vector.getX(), vector.getY(), vector.getZ());
}
public static org.bukkit.Location toLocation(WorldVector pt) {
return new org.bukkit.Location(toWorld(pt), pt.getX(), pt.getY(), pt.getZ());
}
public static org.bukkit.Location toLocation(World world, Vector pt) {
return new org.bukkit.Location(world, pt.getX(), pt.getY(), pt.getZ());
}
public static org.bukkit.Location center(org.bukkit.Location loc) {
return new org.bukkit.Location(
loc.getWorld(),
loc.getBlockX() + 0.5,
loc.getBlockY() + 0.5,
loc.getBlockZ() + 0.5,
loc.getPitch(),
loc.getYaw()
);
}
public static Player matchSinglePlayer(Server server, String name) {
List<Player> players = server.matchPlayer(name);
if (players.size() == 0) {
return null;
}
return players.get(0);
}
public static Block toBlock(BlockWorldVector pt) {
return toWorld(pt).getBlockAt(toLocation(pt));
}
public static World toWorld(WorldVector pt) {
return ((BukkitWorld) pt.getWorld()).getWorld();
}
/**
* Bukkit's Location class has serious problems with floating point
* precision.
*/
@SuppressWarnings("RedundantIfStatement")
public static boolean equals(org.bukkit.Location a, org.bukkit.Location b) {
if (Math.abs(a.getX() - b.getX()) > EQUALS_PRECISION) return false;
if (Math.abs(a.getY() - b.getY()) > EQUALS_PRECISION) return false;
if (Math.abs(a.getZ() - b.getZ()) > EQUALS_PRECISION) return false;
return true;
}
public static final double EQUALS_PRECISION = 0.0001;
public static org.bukkit.Location toLocation(Location location) {
Vector pt = location.getPosition();
return new org.bukkit.Location(
toWorld(location.getWorld()),
pt.getX(), pt.getY(), pt.getZ(),
location.getYaw(), location.getPitch()
);
}
public static World toWorld(final LocalWorld world) {
return ((BukkitWorld) world).getWorld();
}
public static BukkitEntity toLocalEntity(Entity e) {
switch (e.getType()) {
case EXPERIENCE_ORB:
return new BukkitExpOrb(toLocation(e.getLocation()), e.getUniqueId(), ((ExperienceOrb)e).getExperience());
case PAINTING:
Painting paint = (Painting) e;
return new BukkitPainting(toLocation(e.getLocation()), paint.getArt(), paint.getFacing(), e.getUniqueId());
case DROPPED_ITEM:
return new BukkitItem(toLocation(e.getLocation()), ((Item)e).getItemStack(), e.getUniqueId());
default:
return new BukkitEntity(toLocation(e.getLocation()), e.getType(), e.getUniqueId());
}
}
public static BaseBlock toBlock(LocalWorld world, ItemStack itemStack) throws WorldEditException {
final int typeId = itemStack.getTypeId();
switch (typeId) {
case ItemID.INK_SACK:
final Dye materialData = (Dye) itemStack.getData();
if (materialData.getColor() == DyeColor.BROWN) {
return new BaseBlock(BlockID.COCOA_PLANT, -1);
}
break;
case ItemID.HEAD:
return new SkullBlock(0, (byte) itemStack.getDurability());
default:
final BaseBlock baseBlock = BlockType.getBlockForItem(typeId, itemStack.getDurability());
if (baseBlock != null) {
return baseBlock;
}
break;
}
if (world.isValidBlockType(typeId)) {
return new BaseBlock(typeId, -1);
}
throw new NotABlockException(typeId);
}
}

Datei anzeigen

@ -1,436 +1,436 @@
package com.sk89q.worldedit.bukkit;
// $Id$
/*
* This file is a part of WorldEdit.
* Copyright (c) sk89q <http://www.sk89q.com>
* Copyright (c) the WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* (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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
import com.sk89q.jnbt.*;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.TileEntityBlock;
import com.sk89q.worldedit.data.DataException;
import com.sk89q.worldedit.foundation.Block;
import net.minecraft.server.v1_7_R2.*;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_7_R2.CraftWorld;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
import java.util.logging.Logger;
/**
* A blind handler of blocks with TileEntity data that directly access Minecraft's
* classes through CraftBukkit.
* </p>
* Usage of this class may break terribly in the future, and therefore usage should
* be trapped in a handler for {@link Throwable}.
*/
public class DefaultNmsBlock extends NmsBlock {
private static final Logger logger = WorldEdit.logger;
private static Field compoundMapField;
private static final Field nmsBlock_isTileEntityField; // The field is deobfuscated but the method isn't. No idea why.
private NBTTagCompound nbtData = null;
static {
Field field;
try {
field = net.minecraft.server.v1_7_R2.Block.class.getDeclaredField("isTileEntity");
field.setAccessible(true);
} catch (NoSuchFieldException e) {
// logger.severe("Could not find NMS block tile entity field!");
field = null;
}
nmsBlock_isTileEntityField = field;
}
public static boolean verify() {
return nmsBlock_isTileEntityField != null;
}
/**
* Create a new instance with a given type ID, data value, and previous
* {@link TileEntityBlock}-implementing object.
*
* @param type block type ID
* @param data data value
* @param tileEntityBlock tile entity block
*/
public DefaultNmsBlock(int type, int data, TileEntityBlock tileEntityBlock) {
super(type, data);
nbtData = (NBTTagCompound) fromNative(tileEntityBlock.getNbtData());
}
/**
* Create a new instance with a given type ID, data value, and raw
* {@link NBTTagCompound} copy.
*
* @param type block type ID
* @param data data value
* @param nbtData raw NBT data
*/
public DefaultNmsBlock(int type, int data, NBTTagCompound nbtData) {
super(type, data);
this.nbtData = nbtData;
}
/**
* Build a {@link NBTTagCompound} that has valid coordinates.
*
* @param pt coordinates to set
* @return the tag compound
*/
private NBTTagCompound getNmsData(Vector pt) {
if (nbtData == null) {
return null;
}
nbtData.set("x", new NBTTagInt(pt.getBlockX()));
nbtData.set("y", new NBTTagInt(pt.getBlockY()));
nbtData.set("z", new NBTTagInt(pt.getBlockZ()));
return nbtData;
}
@Override
public boolean hasNbtData() {
return nbtData != null;
}
@Override
public String getNbtId() {
if (nbtData == null) {
return "";
}
return nbtData.getString("id");
}
@Override
public CompoundTag getNbtData() {
if (nbtData == null) {
return new CompoundTag(getNbtId(),
new HashMap<String, Tag>());
}
return (CompoundTag) toNative(nbtData);
}
@Override
public void setNbtData(CompoundTag tag) throws DataException {
if (tag == null) {
this.nbtData = null;
}
this.nbtData = (NBTTagCompound) fromNative(tag);
}
/**
* Build an instance from the given information.
*
* @param world world to get the block from
* @param position position to get the block at
* @param type type ID of block
* @param data data value of block
* @return the block, or null
*/
public static DefaultNmsBlock get(World world, Vector position, int type, int data) {
if (!hasTileEntity(type)) {
return null;
}
TileEntity te = ((CraftWorld) world).getHandle().getTileEntity(
position.getBlockX(), position.getBlockY(), position.getBlockZ());
if (te != null) {
NBTTagCompound tag = new NBTTagCompound();
te.b(tag); // Load data
return new DefaultNmsBlock(type, data, tag);
}
return null;
}
/**
* Set an instance or a {@link TileEntityBlock} to the given position.
*
* @param world world to set the block in
* @param position position to set the block at
* @param block the block to set
* @return true if tile entity data was copied to the world
*/
public static boolean set(World world, Vector position, BaseBlock block) {
NBTTagCompound data = null;
if (!hasTileEntity(world.getBlockTypeIdAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()))) {
return false;
}
if (block instanceof DefaultNmsBlock) {
DefaultNmsBlock nmsProxyBlock = (DefaultNmsBlock) block;
data = nmsProxyBlock.getNmsData(position);
} else if (block instanceof TileEntityBlock) {
DefaultNmsBlock nmsProxyBlock = new DefaultNmsBlock(
block.getId(), block.getData(), block);
data = nmsProxyBlock.getNmsData(position);
}
if (data != null) {
TileEntity te = ((CraftWorld) world).getHandle().getTileEntity(
position.getBlockX(), position.getBlockY(), position.getBlockZ());
if (te != null) {
te.a(data); // Load data
return true;
}
}
return false;
}
/**
* Tries to set a block 'safely', as in setting the block data to the location, and
* then triggering physics only at the end.
*
* @param world world to set the block in
* @param position position to set the block at
* @param block the block to set
* @param notifyAdjacent true to notify physics and what not
* @return true if block id or data was changed
*/
public static boolean setSafely(BukkitWorld world, Vector position,
Block block, boolean notifyAdjacent) {
int x = position.getBlockX();
int y = position.getBlockY();
int z = position.getBlockZ();
CraftWorld craftWorld = ((CraftWorld) world.getWorld());
// TileEntity te = craftWorld.getHandle().getTileEntity(x, y, z);
// craftWorld.getHandle().tileEntityList.remove(te);
boolean changed = craftWorld.getHandle().setTypeAndData(x, y, z, getNmsBlock(block.getId()), block.getData(), 0);
if (block instanceof BaseBlock) {
world.copyToWorld(position, (BaseBlock) block);
}
changed = craftWorld.getHandle().setData(x, y, z, block.getData(), 0) || changed;
if (changed && notifyAdjacent) {
craftWorld.getHandle().notify(x, y, z);
craftWorld.getHandle().update(x, y, z, getNmsBlock(block.getId()));
}
return changed;
}
public static boolean hasTileEntity(int type) {
net.minecraft.server.v1_7_R2.Block nmsBlock = getNmsBlock(type);
if (nmsBlock == null) {
return false;
}
try {
return nmsBlock_isTileEntityField.getBoolean(nmsBlock); // Once we have the field stord, gets are fast
} catch (IllegalAccessException e) {
return false;
}
}
public static net.minecraft.server.v1_7_R2.Block getNmsBlock(int type) {
return net.minecraft.server.v1_7_R2.Block.e(type);
}
/**
* Converts from a non-native NMS NBT structure to a native WorldEdit NBT
* structure.
*
* @param foreign non-native NMS NBT structure
* @return native WorldEdit NBT structure
*/
private static Tag toNative(NBTBase foreign) {
// temporary fix since mojang removed names from tags
// our nbt spec will need to be updated to theirs
return toNative(NBTBase.getTagName(foreign.getTypeId()), foreign);
}
/**
* Converts from a non-native NMS NBT structure to a native WorldEdit NBT
* structure.
*
* @param foreign non-native NMS NBT structure
* @param name name for the tag, if it has one
* @return native WorldEdit NBT structure
*/
@SuppressWarnings("unchecked")
private static Tag toNative(String name, NBTBase foreign) {
if (foreign == null) {
return null;
}
if (foreign instanceof NBTTagCompound) {
Map<String, Tag> values = new HashMap<String, Tag>();
Collection<Object> foreignKeys = null;
if (compoundMapField == null) {
try {
// Method name may change!
foreignKeys = ((NBTTagCompound) foreign).c();
} catch (Throwable t) {
try {
logger.warning("WorldEdit: Couldn't get NBTTagCompound.c(), " +
"so we're going to try to get at the 'map' field directly from now on");
if (compoundMapField == null) {
compoundMapField = NBTTagCompound.class.getDeclaredField("map");
compoundMapField.setAccessible(true);
}
} catch (Throwable e) {
// Can't do much beyond this
throw new RuntimeException(e);
}
}
}
if (compoundMapField != null) {
try {
foreignKeys = ((HashMap<Object, Object>) compoundMapField.get(foreign)).keySet();
} catch (Throwable e) {
// Can't do much beyond this
throw new RuntimeException(e);
}
}
for (Object obj : foreignKeys) {
String key = (String) obj;
NBTBase base = (NBTBase) ((NBTTagCompound) foreign).get(key);
values.put(key, toNative(key, base));
}
return new CompoundTag(name, values);
} else if (foreign instanceof NBTTagByte) {
return new ByteTag(name, ((NBTTagByte) foreign).f()); // getByte
} else if (foreign instanceof NBTTagByteArray) {
return new ByteArrayTag(name,
((NBTTagByteArray) foreign).c()); // data
} else if (foreign instanceof NBTTagDouble) {
return new DoubleTag(name,
((NBTTagDouble) foreign).g()); // getDouble
} else if (foreign instanceof NBTTagFloat) {
return new FloatTag(name, ((NBTTagFloat) foreign).h()); // getFloat
} else if (foreign instanceof NBTTagInt) {
return new IntTag(name, ((NBTTagInt) foreign).d()); // getInt
} else if (foreign instanceof NBTTagIntArray) {
return new IntArrayTag(name,
((NBTTagIntArray) foreign).c()); // data
} else if (foreign instanceof NBTTagList) {
try {
return transmorgifyList(name, (NBTTagList) foreign);
} catch (NoSuchFieldException e) {
} catch (SecurityException e) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {}
return new ListTag(name, ByteTag.class, new ArrayList<ByteTag>());
} else if (foreign instanceof NBTTagLong) {
return new LongTag(name, ((NBTTagLong) foreign).c()); // getLong
} else if (foreign instanceof NBTTagShort) {
return new ShortTag(name, ((NBTTagShort) foreign).e()); // getShort
} else if (foreign instanceof NBTTagString) {
return new StringTag(name,
((NBTTagString) foreign).a_()); // data
} else if (foreign instanceof NBTTagEnd) {
return new EndTag();
} else {
throw new IllegalArgumentException("Don't know how to make native "
+ foreign.getClass().getCanonicalName());
}
}
private static ListTag transmorgifyList(String name, NBTTagList foreign)
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
List<Tag> values = new ArrayList<Tag>();
int type = foreign.d();
Field listField = NBTTagList.class.getDeclaredField("list");
listField.setAccessible(true);
List foreignList;
foreignList = (List) listField.get(foreign);
for (int i = 0; i < foreign.size(); i++) {
NBTBase element = (NBTBase) foreignList.get(i);
values.add(toNative(null, element)); // list elements shouldn't have names
}
Class<? extends Tag> cls = NBTConstants.getClassFromType(type);
return new ListTag(name, cls, values);
}
/**
* Converts a WorldEdit-native NBT structure to a NMS structure.
*
* @param foreign structure to convert
* @return non-native structure
*/
private static NBTBase fromNative(Tag foreign) {
if (foreign == null) {
return null;
}
if (foreign instanceof CompoundTag) {
NBTTagCompound tag = new NBTTagCompound();
for (Map.Entry<String, Tag> entry : ((CompoundTag) foreign)
.getValue().entrySet()) {
tag.set(entry.getKey(), fromNative(entry.getValue()));
}
return tag;
} else if (foreign instanceof ByteTag) {
return new NBTTagByte(((ByteTag) foreign).getValue());
} else if (foreign instanceof ByteArrayTag) {
return new NBTTagByteArray(((ByteArrayTag) foreign).getValue());
} else if (foreign instanceof DoubleTag) {
return new NBTTagDouble(((DoubleTag) foreign).getValue());
} else if (foreign instanceof FloatTag) {
return new NBTTagFloat(((FloatTag) foreign).getValue());
} else if (foreign instanceof IntTag) {
return new NBTTagInt(((IntTag) foreign).getValue());
} else if (foreign instanceof IntArrayTag) {
return new NBTTagIntArray(((IntArrayTag) foreign).getValue());
} else if (foreign instanceof ListTag) {
NBTTagList tag = new NBTTagList();
ListTag foreignList = (ListTag) foreign;
for (Tag t : foreignList.getValue()) {
tag.add(fromNative(t));
}
return tag;
} else if (foreign instanceof LongTag) {
return new NBTTagLong(((LongTag) foreign).getValue());
} else if (foreign instanceof ShortTag) {
return new NBTTagShort(((ShortTag) foreign).getValue());
} else if (foreign instanceof StringTag) {
return new NBTTagString(((StringTag) foreign).getValue());
} else if (foreign instanceof EndTag) {
try {
Method tagMaker = NBTBase.class.getDeclaredMethod("createTag", byte.class);
tagMaker.setAccessible(true);
return (NBTBase) tagMaker.invoke(null, (byte) 0);
} catch (Exception e) {
return null;
}
} else {
throw new IllegalArgumentException("Don't know how to make NMS "
+ foreign.getClass().getCanonicalName());
}
}
public static boolean isValidBlockType(int type) throws NoClassDefFoundError {
return type == 0 || (type >= 1 && net.minecraft.server.v1_7_R2.Block.e(type) != null);
}
}
package com.sk89q.worldedit.bukkit;
// $Id$
/*
* This file is a part of WorldEdit.
* Copyright (c) sk89q <http://www.sk89q.com>
* Copyright (c) the WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* (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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
import com.sk89q.jnbt.*;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.TileEntityBlock;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.foundation.Block;
import net.minecraft.server.v1_7_R2.*;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_7_R2.CraftWorld;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
import java.util.logging.Logger;
/**
* A blind handler of blocks with TileEntity data that directly access Minecraft's
* classes through CraftBukkit.
* </p>
* Usage of this class may break terribly in the future, and therefore usage should
* be trapped in a handler for {@link Throwable}.
*/
public class DefaultNmsBlock extends NmsBlock {
private static final Logger logger = WorldEdit.logger;
private static Field compoundMapField;
private static final Field nmsBlock_isTileEntityField; // The field is deobfuscated but the method isn't. No idea why.
private NBTTagCompound nbtData = null;
static {
Field field;
try {
field = net.minecraft.server.v1_7_R2.Block.class.getDeclaredField("isTileEntity");
field.setAccessible(true);
} catch (NoSuchFieldException e) {
// logger.severe("Could not find NMS block tile entity field!");
field = null;
}
nmsBlock_isTileEntityField = field;
}
public static boolean verify() {
return nmsBlock_isTileEntityField != null;
}
/**
* Create a new instance with a given type ID, data value, and previous
* {@link TileEntityBlock}-implementing object.
*
* @param type block type ID
* @param data data value
* @param tileEntityBlock tile entity block
*/
public DefaultNmsBlock(int type, int data, TileEntityBlock tileEntityBlock) {
super(type, data);
nbtData = (NBTTagCompound) fromNative(tileEntityBlock.getNbtData());
}
/**
* Create a new instance with a given type ID, data value, and raw
* {@link NBTTagCompound} copy.
*
* @param type block type ID
* @param data data value
* @param nbtData raw NBT data
*/
public DefaultNmsBlock(int type, int data, NBTTagCompound nbtData) {
super(type, data);
this.nbtData = nbtData;
}
/**
* Build a {@link NBTTagCompound} that has valid coordinates.
*
* @param pt coordinates to set
* @return the tag compound
*/
private NBTTagCompound getNmsData(Vector pt) {
if (nbtData == null) {
return null;
}
nbtData.set("x", new NBTTagInt(pt.getBlockX()));
nbtData.set("y", new NBTTagInt(pt.getBlockY()));
nbtData.set("z", new NBTTagInt(pt.getBlockZ()));
return nbtData;
}
@Override
public boolean hasNbtData() {
return nbtData != null;
}
@Override
public String getNbtId() {
if (nbtData == null) {
return "";
}
return nbtData.getString("id");
}
@Override
public CompoundTag getNbtData() {
if (nbtData == null) {
return new CompoundTag(getNbtId(),
new HashMap<String, Tag>());
}
return (CompoundTag) toNative(nbtData);
}
@Override
public void setNbtData(CompoundTag tag) throws DataException {
if (tag == null) {
this.nbtData = null;
}
this.nbtData = (NBTTagCompound) fromNative(tag);
}
/**
* Build an instance from the given information.
*
* @param world world to get the block from
* @param position position to get the block at
* @param type type ID of block
* @param data data value of block
* @return the block, or null
*/
public static DefaultNmsBlock get(World world, Vector position, int type, int data) {
if (!hasTileEntity(type)) {
return null;
}
TileEntity te = ((CraftWorld) world).getHandle().getTileEntity(
position.getBlockX(), position.getBlockY(), position.getBlockZ());
if (te != null) {
NBTTagCompound tag = new NBTTagCompound();
te.b(tag); // Load data
return new DefaultNmsBlock(type, data, tag);
}
return null;
}
/**
* Set an instance or a {@link TileEntityBlock} to the given position.
*
* @param world world to set the block in
* @param position position to set the block at
* @param block the block to set
* @return true if tile entity data was copied to the world
*/
public static boolean set(World world, Vector position, BaseBlock block) {
NBTTagCompound data = null;
if (!hasTileEntity(world.getBlockTypeIdAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()))) {
return false;
}
if (block instanceof DefaultNmsBlock) {
DefaultNmsBlock nmsProxyBlock = (DefaultNmsBlock) block;
data = nmsProxyBlock.getNmsData(position);
} else if (block instanceof TileEntityBlock) {
DefaultNmsBlock nmsProxyBlock = new DefaultNmsBlock(
block.getId(), block.getData(), block);
data = nmsProxyBlock.getNmsData(position);
}
if (data != null) {
TileEntity te = ((CraftWorld) world).getHandle().getTileEntity(
position.getBlockX(), position.getBlockY(), position.getBlockZ());
if (te != null) {
te.a(data); // Load data
return true;
}
}
return false;
}
/**
* Tries to set a block 'safely', as in setting the block data to the location, and
* then triggering physics only at the end.
*
* @param world world to set the block in
* @param position position to set the block at
* @param block the block to set
* @param notifyAdjacent true to notify physics and what not
* @return true if block id or data was changed
*/
public static boolean setSafely(BukkitWorld world, Vector position,
Block block, boolean notifyAdjacent) {
int x = position.getBlockX();
int y = position.getBlockY();
int z = position.getBlockZ();
CraftWorld craftWorld = ((CraftWorld) world.getWorld());
// TileEntity te = craftWorld.getHandle().getTileEntity(x, y, z);
// craftWorld.getHandle().tileEntityList.remove(te);
boolean changed = craftWorld.getHandle().setTypeAndData(x, y, z, getNmsBlock(block.getId()), block.getData(), 0);
if (block instanceof BaseBlock) {
world.copyToWorld(position, (BaseBlock) block);
}
changed = craftWorld.getHandle().setData(x, y, z, block.getData(), 0) || changed;
if (changed && notifyAdjacent) {
craftWorld.getHandle().notify(x, y, z);
craftWorld.getHandle().update(x, y, z, getNmsBlock(block.getId()));
}
return changed;
}
public static boolean hasTileEntity(int type) {
net.minecraft.server.v1_7_R2.Block nmsBlock = getNmsBlock(type);
if (nmsBlock == null) {
return false;
}
try {
return nmsBlock_isTileEntityField.getBoolean(nmsBlock); // Once we have the field stord, gets are fast
} catch (IllegalAccessException e) {
return false;
}
}
public static net.minecraft.server.v1_7_R2.Block getNmsBlock(int type) {
return net.minecraft.server.v1_7_R2.Block.e(type);
}
/**
* Converts from a non-native NMS NBT structure to a native WorldEdit NBT
* structure.
*
* @param foreign non-native NMS NBT structure
* @return native WorldEdit NBT structure
*/
private static Tag toNative(NBTBase foreign) {
// temporary fix since mojang removed names from tags
// our nbt spec will need to be updated to theirs
return toNative(NBTBase.getTagName(foreign.getTypeId()), foreign);
}
/**
* Converts from a non-native NMS NBT structure to a native WorldEdit NBT
* structure.
*
* @param foreign non-native NMS NBT structure
* @param name name for the tag, if it has one
* @return native WorldEdit NBT structure
*/
@SuppressWarnings("unchecked")
private static Tag toNative(String name, NBTBase foreign) {
if (foreign == null) {
return null;
}
if (foreign instanceof NBTTagCompound) {
Map<String, Tag> values = new HashMap<String, Tag>();
Collection<Object> foreignKeys = null;
if (compoundMapField == null) {
try {
// Method name may change!
foreignKeys = ((NBTTagCompound) foreign).c();
} catch (Throwable t) {
try {
logger.warning("WorldEdit: Couldn't get NBTTagCompound.c(), " +
"so we're going to try to get at the 'map' field directly from now on");
if (compoundMapField == null) {
compoundMapField = NBTTagCompound.class.getDeclaredField("map");
compoundMapField.setAccessible(true);
}
} catch (Throwable e) {
// Can't do much beyond this
throw new RuntimeException(e);
}
}
}
if (compoundMapField != null) {
try {
foreignKeys = ((HashMap<Object, Object>) compoundMapField.get(foreign)).keySet();
} catch (Throwable e) {
// Can't do much beyond this
throw new RuntimeException(e);
}
}
for (Object obj : foreignKeys) {
String key = (String) obj;
NBTBase base = (NBTBase) ((NBTTagCompound) foreign).get(key);
values.put(key, toNative(key, base));
}
return new CompoundTag(name, values);
} else if (foreign instanceof NBTTagByte) {
return new ByteTag(name, ((NBTTagByte) foreign).f()); // getByte
} else if (foreign instanceof NBTTagByteArray) {
return new ByteArrayTag(name,
((NBTTagByteArray) foreign).c()); // data
} else if (foreign instanceof NBTTagDouble) {
return new DoubleTag(name,
((NBTTagDouble) foreign).g()); // getDouble
} else if (foreign instanceof NBTTagFloat) {
return new FloatTag(name, ((NBTTagFloat) foreign).h()); // getFloat
} else if (foreign instanceof NBTTagInt) {
return new IntTag(name, ((NBTTagInt) foreign).d()); // getInt
} else if (foreign instanceof NBTTagIntArray) {
return new IntArrayTag(name,
((NBTTagIntArray) foreign).c()); // data
} else if (foreign instanceof NBTTagList) {
try {
return transmorgifyList(name, (NBTTagList) foreign);
} catch (NoSuchFieldException e) {
} catch (SecurityException e) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {}
return new ListTag(name, ByteTag.class, new ArrayList<ByteTag>());
} else if (foreign instanceof NBTTagLong) {
return new LongTag(name, ((NBTTagLong) foreign).c()); // getLong
} else if (foreign instanceof NBTTagShort) {
return new ShortTag(name, ((NBTTagShort) foreign).e()); // getShort
} else if (foreign instanceof NBTTagString) {
return new StringTag(name,
((NBTTagString) foreign).a_()); // data
} else if (foreign instanceof NBTTagEnd) {
return new EndTag();
} else {
throw new IllegalArgumentException("Don't know how to make native "
+ foreign.getClass().getCanonicalName());
}
}
private static ListTag transmorgifyList(String name, NBTTagList foreign)
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
List<Tag> values = new ArrayList<Tag>();
int type = foreign.d();
Field listField = NBTTagList.class.getDeclaredField("list");
listField.setAccessible(true);
List foreignList;
foreignList = (List) listField.get(foreign);
for (int i = 0; i < foreign.size(); i++) {
NBTBase element = (NBTBase) foreignList.get(i);
values.add(toNative(null, element)); // list elements shouldn't have names
}
Class<? extends Tag> cls = NBTConstants.getClassFromType(type);
return new ListTag(name, cls, values);
}
/**
* Converts a WorldEdit-native NBT structure to a NMS structure.
*
* @param foreign structure to convert
* @return non-native structure
*/
private static NBTBase fromNative(Tag foreign) {
if (foreign == null) {
return null;
}
if (foreign instanceof CompoundTag) {
NBTTagCompound tag = new NBTTagCompound();
for (Map.Entry<String, Tag> entry : ((CompoundTag) foreign)
.getValue().entrySet()) {
tag.set(entry.getKey(), fromNative(entry.getValue()));
}
return tag;
} else if (foreign instanceof ByteTag) {
return new NBTTagByte(((ByteTag) foreign).getValue());
} else if (foreign instanceof ByteArrayTag) {
return new NBTTagByteArray(((ByteArrayTag) foreign).getValue());
} else if (foreign instanceof DoubleTag) {
return new NBTTagDouble(((DoubleTag) foreign).getValue());
} else if (foreign instanceof FloatTag) {
return new NBTTagFloat(((FloatTag) foreign).getValue());
} else if (foreign instanceof IntTag) {
return new NBTTagInt(((IntTag) foreign).getValue());
} else if (foreign instanceof IntArrayTag) {
return new NBTTagIntArray(((IntArrayTag) foreign).getValue());
} else if (foreign instanceof ListTag) {
NBTTagList tag = new NBTTagList();
ListTag foreignList = (ListTag) foreign;
for (Tag t : foreignList.getValue()) {
tag.add(fromNative(t));
}
return tag;
} else if (foreign instanceof LongTag) {
return new NBTTagLong(((LongTag) foreign).getValue());
} else if (foreign instanceof ShortTag) {
return new NBTTagShort(((ShortTag) foreign).getValue());
} else if (foreign instanceof StringTag) {
return new NBTTagString(((StringTag) foreign).getValue());
} else if (foreign instanceof EndTag) {
try {
Method tagMaker = NBTBase.class.getDeclaredMethod("createTag", byte.class);
tagMaker.setAccessible(true);
return (NBTBase) tagMaker.invoke(null, (byte) 0);
} catch (Exception e) {
return null;
}
} else {
throw new IllegalArgumentException("Don't know how to make NMS "
+ foreign.getClass().getCanonicalName());
}
}
public static boolean isValidBlockType(int type) throws NoClassDefFoundError {
return type == 0 || (type >= 1 && net.minecraft.server.v1_7_R2.Block.e(type) != null);
}
}

Datei anzeigen

@ -1,76 +1,76 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.blocks.BlockID;
import org.bukkit.BlockChangeDelegate;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* Proxy class to catch calls to set blocks.
*
* @author sk89q
*/
public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
private EditSession editSession;
public EditSessionBlockChangeDelegate(EditSession editSession) {
this.editSession = editSession;
}
public boolean setRawTypeId(int x, int y, int z, int typeId) {
try {
return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId));
} catch (MaxChangedBlocksException ex) {
return false;
}
}
public boolean setRawTypeIdAndData(int x, int y, int z, int typeId, int data) {
try {
return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId, data));
} catch (MaxChangedBlocksException ex) {
return false;
}
}
public boolean setTypeId(int x, int y, int z, int typeId) {
return setRawTypeId(x, y, z, typeId);
}
public boolean setTypeIdAndData(int x, int y, int z, int typeId, int data) {
return setRawTypeIdAndData(x, y, z, typeId, data);
}
public int getTypeId(int x, int y, int z) {
return editSession.getBlockType(new Vector(x, y, z));
}
public int getHeight() {
return editSession.getWorld().getMaxY() + 1;
}
public boolean isEmpty(int x, int y, int z) {
return editSession.getBlockType(new Vector(x, y, z)) == BlockID.AIR;
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.blocks.BlockID;
import org.bukkit.BlockChangeDelegate;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* Proxy class to catch calls to set blocks.
*
* @author sk89q
*/
public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
private EditSession editSession;
public EditSessionBlockChangeDelegate(EditSession editSession) {
this.editSession = editSession;
}
public boolean setRawTypeId(int x, int y, int z, int typeId) {
try {
return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId));
} catch (MaxChangedBlocksException ex) {
return false;
}
}
public boolean setRawTypeIdAndData(int x, int y, int z, int typeId, int data) {
try {
return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId, data));
} catch (MaxChangedBlocksException ex) {
return false;
}
}
public boolean setTypeId(int x, int y, int z, int typeId) {
return setRawTypeId(x, y, z, typeId);
}
public boolean setTypeIdAndData(int x, int y, int z, int typeId, int data) {
return setRawTypeIdAndData(x, y, z, typeId, data);
}
public int getTypeId(int x, int y, int z) {
return editSession.getBlockType(new Vector(x, y, z));
}
public int getHeight() {
return editSession.getWorld().getMaxY() + 1;
}
public boolean isEmpty(int x, int y, int z) {
return editSession.getBlockType(new Vector(x, y, z)) == BlockID.AIR;
}
}

Datei anzeigen

@ -1,42 +1,42 @@
package com.sk89q.worldedit.bukkit;
import org.bukkit.World;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.foundation.Block;
public abstract class NmsBlock extends BaseBlock {
protected NmsBlock(int type) {
super(type);
}
protected NmsBlock(int type, int data) {
super(type, data);
}
public static boolean verify() {
return false;
}
public static NmsBlock get(World world, Vector vector, int type, int data) {
return null;
}
public static boolean set(World world, Vector vector, Block block) {
return false;
}
public static boolean setSafely(World world, Vector vector, Block block, boolean notify) {
return false;
}
public static boolean hasTileEntity(int type) {
return false;
}
public static boolean isValidBlockType(int type) {
return false;
}
package com.sk89q.worldedit.bukkit;
import org.bukkit.World;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.foundation.Block;
public abstract class NmsBlock extends BaseBlock {
protected NmsBlock(int type) {
super(type);
}
protected NmsBlock(int type, int data) {
super(type, data);
}
public static boolean verify() {
return false;
}
public static NmsBlock get(World world, Vector vector, int type, int data) {
return null;
}
public static boolean set(World world, Vector vector, Block block) {
return false;
}
public static boolean setSafely(World world, Vector vector, Block block, boolean notify) {
return false;
}
public static boolean hasTileEntity(int type) {
return false;
}
public static boolean isValidBlockType(int type) {
return false;
}
}

Datei anzeigen

@ -1,51 +1,51 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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 org.bukkit.Server;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.SessionCheck;
import com.sk89q.worldedit.WorldEdit;
/**
* Used to remove expired sessions in Bukkit.
*
* @author sk89q
*/
public class SessionTimer implements Runnable {
private WorldEdit worldEdit;
private SessionCheck checker;
public SessionTimer(WorldEdit worldEdit, final Server server) {
this.worldEdit = worldEdit;
this.checker = new SessionCheck() {
public boolean isOnlinePlayer(String name) {
Player player = server.getPlayer(name);
return player != null && player.isOnline();
}
};
}
public void run() {
worldEdit.flushExpiredSessions(checker);
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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 org.bukkit.Server;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.SessionCheck;
import com.sk89q.worldedit.WorldEdit;
/**
* Used to remove expired sessions in Bukkit.
*
* @author sk89q
*/
public class SessionTimer implements Runnable {
private WorldEdit worldEdit;
private SessionCheck checker;
public SessionTimer(WorldEdit worldEdit, final Server server) {
this.worldEdit = worldEdit;
this.checker = new SessionCheck() {
public boolean isOnlinePlayer(String name) {
Player player = server.getPlayer(name);
return player != null && player.isOnline();
}
};
}
public void run() {
worldEdit.flushExpiredSessions(checker);
}
}

Datei anzeigen

@ -1,42 +1,42 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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 org.bukkit.entity.Player;
import com.sk89q.worldedit.LocalSession;
public class WorldEditAPI {
private WorldEditPlugin plugin;
public WorldEditAPI(WorldEditPlugin plugin) {
this.plugin = plugin;
}
/**
* Get the session for a player.
*
* @param player
* @return
*/
public LocalSession getSession(Player player) {
return plugin.getWorldEdit().getSession(
new BukkitPlayer(plugin, plugin.getServerInterface(), player));
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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 org.bukkit.entity.Player;
import com.sk89q.worldedit.LocalSession;
public class WorldEditAPI {
private WorldEditPlugin plugin;
public WorldEditAPI(WorldEditPlugin plugin) {
this.plugin = plugin;
}
/**
* Get the session for a player.
*
* @param player
* @return
*/
public LocalSession getSession(Player player) {
return plugin.getWorldEdit().getSession(
new BukkitPlayer(plugin, plugin.getServerInterface(), player));
}
}

Datei anzeigen

@ -1,178 +1,178 @@
/*
* WorldEdit
* Copyright (C) 2012 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/>.
*/
// $Id$
package com.sk89q.worldedit.bukkit;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldVector;
/**
* Handles all events thrown in relation to a Player
*/
public class WorldEditListener implements Listener {
private WorldEditPlugin plugin;
private boolean ignoreLeftClickAir = false;
/**
* Called when a player plays an animation, such as an arm swing
*
* @param event Relevant event details
*/
/**
* Construct the object;
*
* @param plugin
*/
public WorldEditListener(WorldEditPlugin plugin) {
this.plugin = plugin;
}
/**
* Called when a player leaves a server
*
* @param event Relevant event details
*/
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
plugin.getWorldEdit().markExpire(plugin.wrapPlayer(event.getPlayer()));
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onGamemode(PlayerGameModeChangeEvent event) {
// this will automatically refresh their sesssion, we don't have to do anything
WorldEdit.getInstance().getSession(plugin.wrapPlayer(event.getPlayer()));
}
/**
* Called when a player attempts to use a command
*
* @param event Relevant event details
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
String[] split = event.getMessage().split(" ");
if (split.length > 0) {
split = plugin.getWorldEdit().commandDetection(split);
split[0] = "/" + split[0];
}
final String newMessage = StringUtil.joinString(split, " ");
if (!newMessage.equals(event.getMessage())) {
event.setMessage(newMessage);
plugin.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
if (event.getMessage().length() > 0) {
plugin.getServer().dispatchCommand(event.getPlayer(),
event.getMessage().substring(1));
}
event.setCancelled(true);
}
}
}
/**
* Called when a player interacts
*
* @param event Relevant event details
*/
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.useItemInHand() == Result.DENY) {
return;
}
final LocalPlayer player = plugin.wrapPlayer(event.getPlayer());
final LocalWorld world = player.getWorld();
final WorldEdit we = plugin.getWorldEdit();
Action action = event.getAction();
if (action == Action.LEFT_CLICK_BLOCK) {
final Block clickedBlock = event.getClickedBlock();
final WorldVector pos = new WorldVector(world, clickedBlock.getX(),
clickedBlock.getY(), clickedBlock.getZ());
if (we.handleBlockLeftClick(player, pos)) {
event.setCancelled(true);
}
if (we.handleArmSwing(player)) {
event.setCancelled(true);
}
if (!ignoreLeftClickAir) {
final int taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
ignoreLeftClickAir = false;
}
}, 2);
if (taskId != -1) {
ignoreLeftClickAir = true;
}
}
} else if (action == Action.LEFT_CLICK_AIR) {
if (ignoreLeftClickAir) {
return;
}
if (we.handleArmSwing(player)) {
event.setCancelled(true);
}
} else if (action == Action.RIGHT_CLICK_BLOCK) {
final Block clickedBlock = event.getClickedBlock();
final WorldVector pos = new WorldVector(world, clickedBlock.getX(),
clickedBlock.getY(), clickedBlock.getZ());
if (we.handleBlockRightClick(player, pos)) {
event.setCancelled(true);
}
if (we.handleRightClick(player)) {
event.setCancelled(true);
}
} else if (action == Action.RIGHT_CLICK_AIR) {
if (we.handleRightClick(player)) {
event.setCancelled(true);
}
}
}
}
/*
* WorldEdit
* Copyright (C) 2012 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/>.
*/
// $Id$
package com.sk89q.worldedit.bukkit;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import com.sk89q.util.StringUtil;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldVector;
/**
* Handles all events thrown in relation to a Player
*/
public class WorldEditListener implements Listener {
private WorldEditPlugin plugin;
private boolean ignoreLeftClickAir = false;
/**
* Called when a player plays an animation, such as an arm swing
*
* @param event Relevant event details
*/
/**
* Construct the object;
*
* @param plugin
*/
public WorldEditListener(WorldEditPlugin plugin) {
this.plugin = plugin;
}
/**
* Called when a player leaves a server
*
* @param event Relevant event details
*/
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
plugin.getWorldEdit().markExpire(plugin.wrapPlayer(event.getPlayer()));
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onGamemode(PlayerGameModeChangeEvent event) {
// this will automatically refresh their sesssion, we don't have to do anything
WorldEdit.getInstance().getSession(plugin.wrapPlayer(event.getPlayer()));
}
/**
* Called when a player attempts to use a command
*
* @param event Relevant event details
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
String[] split = event.getMessage().split(" ");
if (split.length > 0) {
split = plugin.getWorldEdit().commandDetection(split);
split[0] = "/" + split[0];
}
final String newMessage = StringUtil.joinString(split, " ");
if (!newMessage.equals(event.getMessage())) {
event.setMessage(newMessage);
plugin.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
if (event.getMessage().length() > 0) {
plugin.getServer().dispatchCommand(event.getPlayer(),
event.getMessage().substring(1));
}
event.setCancelled(true);
}
}
}
/**
* Called when a player interacts
*
* @param event Relevant event details
*/
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if (event.useItemInHand() == Result.DENY) {
return;
}
final LocalPlayer player = plugin.wrapPlayer(event.getPlayer());
final LocalWorld world = player.getWorld();
final WorldEdit we = plugin.getWorldEdit();
Action action = event.getAction();
if (action == Action.LEFT_CLICK_BLOCK) {
final Block clickedBlock = event.getClickedBlock();
final WorldVector pos = new WorldVector(world, clickedBlock.getX(),
clickedBlock.getY(), clickedBlock.getZ());
if (we.handleBlockLeftClick(player, pos)) {
event.setCancelled(true);
}
if (we.handleArmSwing(player)) {
event.setCancelled(true);
}
if (!ignoreLeftClickAir) {
final int taskId = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
ignoreLeftClickAir = false;
}
}, 2);
if (taskId != -1) {
ignoreLeftClickAir = true;
}
}
} else if (action == Action.LEFT_CLICK_AIR) {
if (ignoreLeftClickAir) {
return;
}
if (we.handleArmSwing(player)) {
event.setCancelled(true);
}
} else if (action == Action.RIGHT_CLICK_BLOCK) {
final Block clickedBlock = event.getClickedBlock();
final WorldVector pos = new WorldVector(world, clickedBlock.getX(),
clickedBlock.getY(), clickedBlock.getZ());
if (we.handleBlockRightClick(player, pos)) {
event.setCancelled(true);
}
if (we.handleRightClick(player)) {
event.setCancelled(true);
}
} else if (action == Action.RIGHT_CLICK_AIR) {
if (we.handleRightClick(player)) {
event.setCancelled(true);
}
}
}
}

Datei anzeigen

@ -1,430 +1,419 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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 java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Handler;
import java.util.zip.ZipEntry;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.sk89q.util.yaml.YAMLProcessor;
import com.sk89q.wepif.PermissionsResolverManager;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.ServerInterface;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditOperation;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Polygonal2DRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
/**
* Plugin for Bukkit.
*
* @author sk89q
*/
public class WorldEditPlugin extends JavaPlugin {
/**
* The name of the CUI's plugin channel registration
*/
public static final String CUI_PLUGIN_CHANNEL = "WECUI";
/**
* The server interface that all server-related API goes through.
*/
private BukkitServerInterface server;
/**
* Main WorldEdit instance.
*/
private WorldEdit controller;
/**
* Deprecated API.
*/
private WorldEditAPI api;
/**
* Holds the configuration for WorldEdit.
*/
private BukkitConfiguration config;
/**
* Called on plugin enable.
*/
@Override
public void onEnable() {
final String pluginYmlVersion = getDescription().getVersion();
final String manifestVersion = WorldEdit.getVersion();
if (!manifestVersion.equalsIgnoreCase(pluginYmlVersion)) {
WorldEdit.setVersion(manifestVersion + " (" + pluginYmlVersion + ")");
}
// Make the data folders that WorldEdit uses
getDataFolder().mkdirs();
File targetDir = new File(getDataFolder() + File.separator + "nmsblocks");
targetDir.mkdir();
copyNmsBlockClasses(targetDir);
// Create the default configuration file
createDefaultConfiguration("config.yml");
// Set up configuration and such, including the permissions
// resolver
config = new BukkitConfiguration(new YAMLProcessor(new File(getDataFolder(), "config.yml"), true), this);
PermissionsResolverManager.initialize(this);
// Load the configuration
config.load();
// Setup interfaces
server = new BukkitServerInterface(this, getServer());
controller = new WorldEdit(server, config);
WorldEdit.logger.setParent(Bukkit.getLogger());
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!
getServer().getPluginManager().registerEvents(new WorldEditListener(this), this);
getServer().getScheduler().runTaskTimerAsynchronously(this,
new SessionTimer(controller, getServer()), 120, 120);
}
private void copyNmsBlockClasses(File target) {
try {
JarFile jar = new JarFile(getFile());
@SuppressWarnings("rawtypes")
Enumeration entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry jarEntry = (JarEntry) entries.nextElement();
if (!jarEntry.getName().startsWith("nmsblocks") || jarEntry.isDirectory()) continue;
File file = new File(target + File.separator + jarEntry.getName().replace("nmsblocks", ""));
if (file.exists()) continue;
InputStream is = jar.getInputStream(jarEntry);
FileOutputStream fos = new FileOutputStream(file);
fos = new FileOutputStream(file);
byte[] buf = new byte[8192];
int length = 0;
while ((length = is.read(buf)) > 0) {
fos.write(buf, 0, length);
}
fos.close();
is.close();
}
} catch (Throwable e) {}
}
/**
* Called on plugin disable.
*/
@Override
public void onDisable() {
controller.clearSessions();
for (Handler h : controller.commandLogger.getHandlers()) {
h.close();
}
config.unload();
server.unregisterCommands();
this.getServer().getScheduler().cancelTasks(this);
}
/**
* Loads and reloads all configuration.
*/
protected void loadConfiguration() {
config.unload();
config.load();
getPermissionsResolver().load();
}
/**
* Create a default configuration file from the .jar.
*
* @param name
*/
protected void createDefaultConfiguration(String name) {
File actual = new File(getDataFolder(), name);
if (!actual.exists()) {
InputStream input =
null;
try {
JarFile file = new JarFile(getFile());
ZipEntry copy = file.getEntry("defaults/" + name);
if (copy == null) throw new FileNotFoundException();
input = file.getInputStream(copy);
} catch (IOException e) {
getLogger().severe("Unable to read default configuration: " + name);
}
if (input != null) {
FileOutputStream output = null;
try {
output = new FileOutputStream(actual);
byte[] buf = new byte[8192];
int length = 0;
while ((length = input.read(buf)) > 0) {
output.write(buf, 0, length);
}
getLogger().info("Default configuration file written: " + name);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (input != null) {
input.close();
}
} catch (IOException e) {}
try {
if (output != null) {
output.close();
}
} catch (IOException e) {}
}
}
}
}
/**
* Called on WorldEdit command.
*/
@Override
public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd,
String commandLabel, String[] args) {
// Add the command to the array because the underlying command handling
// code of WorldEdit expects it
String[] split = new String[args.length + 1];
System.arraycopy(args, 0, split, 1, args.length);
split[0] = "/" + cmd.getName();
controller.handleCommand(wrapCommandSender(sender), split);
return true;
}
/**
* Gets the session for the player.
*
* @param player
* @return
*/
public LocalSession getSession(Player player) {
return controller.getSession(wrapPlayer(player));
}
/**
* Gets the session for the player.
*
* @param player
* @return
*/
public EditSession createEditSession(Player player) {
LocalPlayer wePlayer = wrapPlayer(player);
LocalSession session = controller.getSession(wePlayer);
BlockBag blockBag = session.getBlockBag(wePlayer);
EditSession editSession = controller.getEditSessionFactory()
.getEditSession(wePlayer.getWorld(), session.getBlockChangeLimit(), blockBag, wePlayer);
editSession.enableQueue();
return editSession;
}
/**
* Remember an edit session.
*
* @param player
* @param editSession
*/
public void remember(Player player, EditSession editSession) {
LocalPlayer wePlayer = wrapPlayer(player);
LocalSession session = controller.getSession(wePlayer);
session.remember(editSession);
editSession.flushQueue();
controller.flushBlockBag(wePlayer, editSession);
}
/**
* Wrap an operation into an EditSession.
*
* @param player
* @param op
* @throws Throwable
*/
public void perform(Player player, WorldEditOperation op)
throws Throwable {
LocalPlayer wePlayer = wrapPlayer(player);
LocalSession session = controller.getSession(wePlayer);
EditSession editSession = createEditSession(player);
try {
op.run(session, wePlayer, editSession);
} finally {
remember(player, editSession);
}
}
/**
* Get the API.
*
* @return
*/
@Deprecated
public WorldEditAPI getAPI() {
return api;
}
/**
* Returns the configuration used by WorldEdit.
*
* @return
*/
public BukkitConfiguration getLocalConfiguration() {
return config;
}
/**
* Get the permissions resolver in use.
*
* @return
*/
public PermissionsResolverManager getPermissionsResolver() {
return PermissionsResolverManager.getInstance();
}
/**
* Used to wrap a Bukkit Player as a LocalPlayer.
*
* @param player
* @return
*/
public BukkitPlayer wrapPlayer(Player player) {
return new BukkitPlayer(this, this.server, player);
}
public LocalPlayer wrapCommandSender(CommandSender sender) {
if (sender instanceof Player) {
return wrapPlayer((Player) sender);
}
return new BukkitCommandSender(this, this.server, sender);
}
/**
* Get the server interface.
*
* @return
*/
public ServerInterface getServerInterface() {
return server;
}
/**
* Get WorldEdit.
*
* @return
*/
public WorldEdit getWorldEdit() {
return controller;
}
/**
* Gets the region selection for the player.
*
* @param player
* @return the selection or null if there was none
*/
public Selection getSelection(Player player) {
if (player == null) {
throw new IllegalArgumentException("Null player not allowed");
}
if (!player.isOnline()) {
throw new IllegalArgumentException("Offline player not allowed");
}
LocalSession session = controller.getSession(wrapPlayer(player));
RegionSelector selector = session.getRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()));
try {
Region region = selector.getRegion();
World world = ((BukkitWorld) session.getSelectionWorld()).getWorld();
if (region instanceof CuboidRegion) {
return new CuboidSelection(world, selector, (CuboidRegion) region);
} else if (region instanceof Polygonal2DRegion) {
return new Polygonal2DSelection(world, selector, (Polygonal2DRegion) region);
} else {
return null;
}
} catch (IncompleteRegionException e) {
return null;
}
}
/**
* Sets the region selection for a player.
*
* @param player
* @param selection
*/
public void setSelection(Player player, Selection selection) {
if (player == null) {
throw new IllegalArgumentException("Null player not allowed");
}
if (!player.isOnline()) {
throw new IllegalArgumentException("Offline player not allowed");
}
if (selection == null) {
throw new IllegalArgumentException("Null selection not allowed");
}
LocalSession session = controller.getSession(wrapPlayer(player));
RegionSelector sel = selection.getRegionSelector();
session.setRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()), sel);
session.dispatchCUISelection(wrapPlayer(player));
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.util.yaml.YAMLProcessor;
import com.sk89q.wepif.PermissionsResolverManager;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Polygonal2DRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.selector.RegionSelector;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.*;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Handler;
import java.util.zip.ZipEntry;
/**
* Plugin for Bukkit.
*
* @author sk89q
*/
public class WorldEditPlugin extends JavaPlugin {
/**
* The name of the CUI's plugin channel registration
*/
public static final String CUI_PLUGIN_CHANNEL = "WECUI";
/**
* The server interface that all server-related API goes through.
*/
private BukkitServerInterface server;
/**
* Main WorldEdit instance.
*/
private WorldEdit controller;
/**
* Deprecated API.
*/
private WorldEditAPI api;
/**
* Holds the configuration for WorldEdit.
*/
private BukkitConfiguration config;
/**
* Called on plugin enable.
*/
@Override
public void onEnable() {
final String pluginYmlVersion = getDescription().getVersion();
final String manifestVersion = WorldEdit.getVersion();
if (!manifestVersion.equalsIgnoreCase(pluginYmlVersion)) {
WorldEdit.setVersion(manifestVersion + " (" + pluginYmlVersion + ")");
}
// Make the data folders that WorldEdit uses
getDataFolder().mkdirs();
File targetDir = new File(getDataFolder() + File.separator + "nmsblocks");
targetDir.mkdir();
copyNmsBlockClasses(targetDir);
// Create the default configuration file
createDefaultConfiguration("config.yml");
// Set up configuration and such, including the permissions
// resolver
config = new BukkitConfiguration(new YAMLProcessor(new File(getDataFolder(), "config.yml"), true), this);
PermissionsResolverManager.initialize(this);
// Load the configuration
config.load();
// Setup interfaces
server = new BukkitServerInterface(this, getServer());
controller = new WorldEdit(server, config);
WorldEdit.logger.setParent(Bukkit.getLogger());
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!
getServer().getPluginManager().registerEvents(new WorldEditListener(this), this);
getServer().getScheduler().runTaskTimerAsynchronously(this,
new SessionTimer(controller, getServer()), 120, 120);
}
private void copyNmsBlockClasses(File target) {
try {
JarFile jar = new JarFile(getFile());
@SuppressWarnings("rawtypes")
Enumeration entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry jarEntry = (JarEntry) entries.nextElement();
if (!jarEntry.getName().startsWith("nmsblocks") || jarEntry.isDirectory()) continue;
File file = new File(target + File.separator + jarEntry.getName().replace("nmsblocks", ""));
if (file.exists()) continue;
InputStream is = jar.getInputStream(jarEntry);
FileOutputStream fos = new FileOutputStream(file);
fos = new FileOutputStream(file);
byte[] buf = new byte[8192];
int length = 0;
while ((length = is.read(buf)) > 0) {
fos.write(buf, 0, length);
}
fos.close();
is.close();
}
} catch (Throwable e) {}
}
/**
* Called on plugin disable.
*/
@Override
public void onDisable() {
controller.clearSessions();
for (Handler h : controller.commandLogger.getHandlers()) {
h.close();
}
config.unload();
server.unregisterCommands();
this.getServer().getScheduler().cancelTasks(this);
}
/**
* Loads and reloads all configuration.
*/
protected void loadConfiguration() {
config.unload();
config.load();
getPermissionsResolver().load();
}
/**
* Create a default configuration file from the .jar.
*
* @param name
*/
protected void createDefaultConfiguration(String name) {
File actual = new File(getDataFolder(), name);
if (!actual.exists()) {
InputStream input =
null;
try {
JarFile file = new JarFile(getFile());
ZipEntry copy = file.getEntry("defaults/" + name);
if (copy == null) throw new FileNotFoundException();
input = file.getInputStream(copy);
} catch (IOException e) {
getLogger().severe("Unable to read default configuration: " + name);
}
if (input != null) {
FileOutputStream output = null;
try {
output = new FileOutputStream(actual);
byte[] buf = new byte[8192];
int length = 0;
while ((length = input.read(buf)) > 0) {
output.write(buf, 0, length);
}
getLogger().info("Default configuration file written: " + name);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (input != null) {
input.close();
}
} catch (IOException e) {}
try {
if (output != null) {
output.close();
}
} catch (IOException e) {}
}
}
}
}
/**
* Called on WorldEdit command.
*/
@Override
public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd,
String commandLabel, String[] args) {
// Add the command to the array because the underlying command handling
// code of WorldEdit expects it
String[] split = new String[args.length + 1];
System.arraycopy(args, 0, split, 1, args.length);
split[0] = "/" + cmd.getName();
controller.handleCommand(wrapCommandSender(sender), split);
return true;
}
/**
* Gets the session for the player.
*
* @param player
* @return
*/
public LocalSession getSession(Player player) {
return controller.getSession(wrapPlayer(player));
}
/**
* Gets the session for the player.
*
* @param player
* @return
*/
public EditSession createEditSession(Player player) {
LocalPlayer wePlayer = wrapPlayer(player);
LocalSession session = controller.getSession(wePlayer);
BlockBag blockBag = session.getBlockBag(wePlayer);
EditSession editSession = controller.getEditSessionFactory()
.getEditSession(wePlayer.getWorld(), session.getBlockChangeLimit(), blockBag, wePlayer);
editSession.enableQueue();
return editSession;
}
/**
* Remember an edit session.
*
* @param player
* @param editSession
*/
public void remember(Player player, EditSession editSession) {
LocalPlayer wePlayer = wrapPlayer(player);
LocalSession session = controller.getSession(wePlayer);
session.remember(editSession);
editSession.flushQueue();
controller.flushBlockBag(wePlayer, editSession);
}
/**
* Wrap an operation into an EditSession.
*
* @param player
* @param op
* @throws Throwable
*/
public void perform(Player player, WorldEditOperation op)
throws Throwable {
LocalPlayer wePlayer = wrapPlayer(player);
LocalSession session = controller.getSession(wePlayer);
EditSession editSession = createEditSession(player);
try {
op.run(session, wePlayer, editSession);
} finally {
remember(player, editSession);
}
}
/**
* Get the API.
*
* @return
*/
@Deprecated
public WorldEditAPI getAPI() {
return api;
}
/**
* Returns the configuration used by WorldEdit.
*
* @return
*/
public BukkitConfiguration getLocalConfiguration() {
return config;
}
/**
* Get the permissions resolver in use.
*
* @return
*/
public PermissionsResolverManager getPermissionsResolver() {
return PermissionsResolverManager.getInstance();
}
/**
* Used to wrap a Bukkit Player as a LocalPlayer.
*
* @param player
* @return
*/
public BukkitPlayer wrapPlayer(Player player) {
return new BukkitPlayer(this, this.server, player);
}
public LocalPlayer wrapCommandSender(CommandSender sender) {
if (sender instanceof Player) {
return wrapPlayer((Player) sender);
}
return new BukkitCommandSender(this, this.server, sender);
}
/**
* Get the server interface.
*
* @return
*/
public ServerInterface getServerInterface() {
return server;
}
/**
* Get WorldEdit.
*
* @return
*/
public WorldEdit getWorldEdit() {
return controller;
}
/**
* Gets the region selection for the player.
*
* @param player
* @return the selection or null if there was none
*/
public Selection getSelection(Player player) {
if (player == null) {
throw new IllegalArgumentException("Null player not allowed");
}
if (!player.isOnline()) {
throw new IllegalArgumentException("Offline player not allowed");
}
LocalSession session = controller.getSession(wrapPlayer(player));
RegionSelector selector = session.getRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()));
try {
Region region = selector.getRegion();
World world = ((BukkitWorld) session.getSelectionWorld()).getWorld();
if (region instanceof CuboidRegion) {
return new CuboidSelection(world, selector, (CuboidRegion) region);
} else if (region instanceof Polygonal2DRegion) {
return new Polygonal2DSelection(world, selector, (Polygonal2DRegion) region);
} else {
return null;
}
} catch (IncompleteRegionException e) {
return null;
}
}
/**
* Sets the region selection for a player.
*
* @param player
* @param selection
*/
public void setSelection(Player player, Selection selection) {
if (player == null) {
throw new IllegalArgumentException("Null player not allowed");
}
if (!player.isOnline()) {
throw new IllegalArgumentException("Offline player not allowed");
}
if (selection == null) {
throw new IllegalArgumentException("Null selection not allowed");
}
LocalSession session = controller.getSession(wrapPlayer(player));
RegionSelector sel = selection.getRegionSelector();
session.setRegionSelector(BukkitUtil.getLocalWorld(player.getWorld()), sel);
session.dispatchCUISelection(wrapPlayer(player));
}
}

Datei anzeigen

@ -1,67 +1,69 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.selections;
import org.bukkit.Location;
import org.bukkit.World;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.regions.*;
public class CuboidSelection extends RegionSelection {
protected CuboidRegion cuboid;
public CuboidSelection(World world, Location pt1, Location pt2) {
this(world, BukkitUtil.toVector(pt1), BukkitUtil.toVector(pt2));
}
public CuboidSelection(World world, Vector pt1, Vector pt2) {
super(world);
// Validate input
if (pt1 == null) {
throw new IllegalArgumentException("Null point 1 not permitted");
}
if (pt2 == null) {
throw new IllegalArgumentException("Null point 2 not permitted");
}
// Create new selector
CuboidRegionSelector sel = new CuboidRegionSelector(BukkitUtil.getLocalWorld(world));
// set up selector
sel.selectPrimary(pt1);
sel.selectSecondary(pt2);
// set up CuboidSelection
cuboid = sel.getIncompleteRegion();
// set up RegionSelection
setRegionSelector(sel);
setRegion(cuboid);
}
public CuboidSelection(World world, RegionSelector sel, CuboidRegion region) {
super(world, sel, region);
this.cuboid = region;
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.selections;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.regions.selector.RegionSelector;
import org.bukkit.Location;
import org.bukkit.World;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.regions.*;
public class CuboidSelection extends RegionSelection {
protected CuboidRegion cuboid;
public CuboidSelection(World world, Location pt1, Location pt2) {
this(world, BukkitUtil.toVector(pt1), BukkitUtil.toVector(pt2));
}
public CuboidSelection(World world, Vector pt1, Vector pt2) {
super(world);
// Validate input
if (pt1 == null) {
throw new IllegalArgumentException("Null point 1 not permitted");
}
if (pt2 == null) {
throw new IllegalArgumentException("Null point 2 not permitted");
}
// Create new selector
CuboidRegionSelector sel = new CuboidRegionSelector(BukkitUtil.getLocalWorld(world));
// set up selector
sel.selectPrimary(pt1);
sel.selectSecondary(pt2);
// set up CuboidSelection
cuboid = sel.getIncompleteRegion();
// set up RegionSelection
setRegionSelector(sel);
setRegion(cuboid);
}
public CuboidSelection(World world, RegionSelector sel, CuboidRegion region) {
super(world, sel, region);
this.cuboid = region;
}
}

Datei anzeigen

@ -1,62 +1,64 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.selections;
import java.util.Collections;
import java.util.List;
import com.sk89q.worldedit.LocalWorld;
import org.bukkit.World;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.regions.*;
public class Polygonal2DSelection extends RegionSelection {
protected Polygonal2DRegion poly2d;
public Polygonal2DSelection(World world, RegionSelector sel, Polygonal2DRegion region) {
super(world, sel, region);
this.poly2d = region;
}
public Polygonal2DSelection(World world, List<BlockVector2D> points, int minY, int maxY) {
super(world);
LocalWorld lWorld = BukkitUtil.getLocalWorld(world);
// Validate input
minY = Math.min(Math.max(0, minY), world.getMaxHeight());
maxY = Math.min(Math.max(0, maxY), world.getMaxHeight());
// Create and set up new selector
Polygonal2DRegionSelector sel = new Polygonal2DRegionSelector(lWorld, points, minY, maxY);
// set up CuboidSelection
poly2d = sel.getIncompleteRegion();
// set up RegionSelection
setRegionSelector(sel);
setRegion(poly2d);
}
public List<BlockVector2D> getNativePoints() {
return Collections.unmodifiableList(poly2d.getPoints());
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.selections;
import java.util.Collections;
import java.util.List;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
import com.sk89q.worldedit.regions.selector.RegionSelector;
import org.bukkit.World;
import com.sk89q.worldedit.BlockVector2D;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.regions.*;
public class Polygonal2DSelection extends RegionSelection {
protected Polygonal2DRegion poly2d;
public Polygonal2DSelection(World world, RegionSelector sel, Polygonal2DRegion region) {
super(world, sel, region);
this.poly2d = region;
}
public Polygonal2DSelection(World world, List<BlockVector2D> points, int minY, int maxY) {
super(world);
LocalWorld lWorld = BukkitUtil.getLocalWorld(world);
// Validate input
minY = Math.min(Math.max(0, minY), world.getMaxHeight());
maxY = Math.min(Math.max(0, maxY), world.getMaxHeight());
// Create and set up new selector
Polygonal2DRegionSelector sel = new Polygonal2DRegionSelector(lWorld, points, minY, maxY);
// set up CuboidSelection
poly2d = sel.getIncompleteRegion();
// set up RegionSelection
setRegionSelector(sel);
setRegion(poly2d);
}
public List<BlockVector2D> getNativePoints() {
return Collections.unmodifiableList(poly2d.getPoints());
}
}

Datei anzeigen

@ -1,106 +1,107 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.selections;
import static com.sk89q.worldedit.bukkit.BukkitUtil.toLocation;
import static com.sk89q.worldedit.bukkit.BukkitUtil.toVector;
import org.bukkit.Location;
import org.bukkit.World;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
public abstract class RegionSelection implements Selection {
private World world;
private RegionSelector selector;
private Region region;
public RegionSelection(World world) {
this.world = world;
}
public RegionSelection(World world, RegionSelector selector, Region region) {
this.world = world;
this.region = region;
this.selector = selector;
}
protected Region getRegion() {
return region;
}
protected void setRegion(Region region) {
this.region = region;
}
public RegionSelector getRegionSelector() {
return selector;
}
protected void setRegionSelector(RegionSelector selector) {
this.selector = selector;
}
public Location getMinimumPoint() {
return toLocation(world, region.getMinimumPoint());
}
public Vector getNativeMinimumPoint() {
return region.getMinimumPoint();
}
public Location getMaximumPoint() {
return toLocation(world, region.getMaximumPoint());
}
public Vector getNativeMaximumPoint() {
return region.getMaximumPoint();
}
public World getWorld() {
return world;
}
public int getArea() {
return region.getArea();
}
public int getWidth() {
return region.getWidth();
}
public int getHeight() {
return region.getHeight();
}
public int getLength() {
return region.getLength();
}
public boolean contains(Location pt) {
if (!pt.getWorld().equals(world)) {
return false;
}
return region.contains(toVector(pt));
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.selections;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.selector.RegionSelector;
import org.bukkit.Location;
import org.bukkit.World;
import static com.sk89q.worldedit.bukkit.BukkitUtil.toLocation;
import static com.sk89q.worldedit.bukkit.BukkitUtil.toVector;
public abstract class RegionSelection implements Selection {
private World world;
private RegionSelector selector;
private Region region;
public RegionSelection(World world) {
this.world = world;
}
public RegionSelection(World world, RegionSelector selector, Region region) {
this.world = world;
this.region = region;
this.selector = selector;
}
protected Region getRegion() {
return region;
}
protected void setRegion(Region region) {
this.region = region;
}
public RegionSelector getRegionSelector() {
return selector;
}
protected void setRegionSelector(RegionSelector selector) {
this.selector = selector;
}
public Location getMinimumPoint() {
return toLocation(world, region.getMinimumPoint());
}
public Vector getNativeMinimumPoint() {
return region.getMinimumPoint();
}
public Location getMaximumPoint() {
return toLocation(world, region.getMaximumPoint());
}
public Vector getNativeMaximumPoint() {
return region.getMaximumPoint();
}
public World getWorld() {
return world;
}
public int getArea() {
return region.getArea();
}
public int getWidth() {
return region.getWidth();
}
public int getHeight() {
return region.getHeight();
}
public int getLength() {
return region.getLength();
}
public boolean contains(Location pt) {
if (!pt.getWorld().equals(world)) {
return false;
}
return region.contains(toVector(pt));
}
}

Datei anzeigen

@ -1,105 +1,105 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.selections;
import org.bukkit.Location;
import org.bukkit.World;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.RegionSelector;
public interface Selection {
/**
* Get the lower point of a region.
*
* @return min. point
*/
public Location getMinimumPoint();
/**
* Get the lower point of a region.
*
* @return min. point
*/
public Vector getNativeMinimumPoint();
/**
* Get the upper point of a region.
*
* @return max. point
*/
public Location getMaximumPoint();
/**
* Get the upper point of a region.
*
* @return max. point
*/
public Vector getNativeMaximumPoint();
/**
* Get the region selector. This is for internal use.
*
* @return
*/
public RegionSelector getRegionSelector();
/**
* Get the world.
*
* @return
*/
public World getWorld();
/**
* Get the number of blocks in the region.
*
* @return number of blocks
*/
public int getArea();
/**
* Get X-size.
*
* @return width
*/
public int getWidth();
/**
* Get Y-size.
*
* @return height
*/
public int getHeight();
/**
* Get Z-size.
*
* @return length
*/
public int getLength();
/**
* Returns true based on whether the region contains the point,
*
* @param pt
* @return
*/
public boolean contains(Location pt);
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.selections;
import org.bukkit.Location;
import org.bukkit.World;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.selector.RegionSelector;
public interface Selection {
/**
* Get the lower point of a region.
*
* @return min. point
*/
public Location getMinimumPoint();
/**
* Get the lower point of a region.
*
* @return min. point
*/
public Vector getNativeMinimumPoint();
/**
* Get the upper point of a region.
*
* @return max. point
*/
public Location getMaximumPoint();
/**
* Get the upper point of a region.
*
* @return max. point
*/
public Vector getNativeMaximumPoint();
/**
* Get the region selector. This is for internal use.
*
* @return
*/
public RegionSelector getRegionSelector();
/**
* Get the world.
*
* @return
*/
public World getWorld();
/**
* Get the number of blocks in the region.
*
* @return number of blocks
*/
public int getArea();
/**
* Get X-size.
*
* @return width
*/
public int getWidth();
/**
* Get Y-size.
*
* @return height
*/
public int getHeight();
/**
* Get Z-size.
*
* @return length
*/
public int getLength();
/**
* Returns true based on whether the region contains the point,
*
* @param pt
* @return
*/
public boolean contains(Location pt);
}

Datei anzeigen

@ -1,72 +1,72 @@
#
# WorldEdit's configuration file
#
# About editing this file:
# - DO NOT USE TABS. You MUST use spaces or Bukkit will complain. If
# you use an editor like Notepad++ (recommended for Windows users), you
# must configure it to "replace tabs with spaces." In Notepad++, this can
# be changed in Settings > Preferences > Language Menu.
# - Don't get rid of the indents. They are indented so some entries are
# in categories (like "max-blocks-changed" is in the "limits"
# category.
# - If you want to check the format of this file before putting it
# into WorldEdit, paste it into http://yaml-online-parser.appspot.com/
# and see if it gives "ERROR:".
# - Lines starting with # are commentsand so they are ignored.
#
limits:
allow-extra-data-values: false
max-blocks-changed:
default: -1
maximum: -1
max-polygonal-points:
default: -1
maximum: 20
max-radius: -1
max-super-pickaxe-size: 5
max-brush-radius: 5
butcher-radius:
default: -1
maximum: -1
disallowed-blocks: [6, 7, 14, 15, 16, 26, 27, 28, 29, 39, 31, 32, 33, 34, 36, 37, 38, 39, 40, 46, 50, 51, 56, 59, 69, 73, 74, 75, 76, 77, 81, 83]
use-inventory:
enable: false
allow-override: true
creative-mode-overrides: false
logging:
log-commands: false
file: worldedit.log
super-pickaxe:
drop-items: true
many-drop-items: false
snapshots:
directory:
navigation-wand:
item: 345
max-distance: 100
scripting:
timeout: 3000
dir: craftscripts
saving:
dir: schematics
files:
allow-symbolic-links: false
history:
size: 15
expiration: 10
wand-item: 271
shell-save-type:
no-double-slash: false
no-op-permissions: false
debug: false
#
# WorldEdit's configuration file
#
# About editing this file:
# - DO NOT USE TABS. You MUST use spaces or Bukkit will complain. If
# you use an editor like Notepad++ (recommended for Windows users), you
# must configure it to "replace tabs with spaces." In Notepad++, this can
# be changed in Settings > Preferences > Language Menu.
# - Don't get rid of the indents. They are indented so some entries are
# in categories (like "max-blocks-changed" is in the "limits"
# category.
# - If you want to check the format of this file before putting it
# into WorldEdit, paste it into http://yaml-online-parser.appspot.com/
# and see if it gives "ERROR:".
# - Lines starting with # are commentsand so they are ignored.
#
limits:
allow-extra-data-values: false
max-blocks-changed:
default: -1
maximum: -1
max-polygonal-points:
default: -1
maximum: 20
max-radius: -1
max-super-pickaxe-size: 5
max-brush-radius: 5
butcher-radius:
default: -1
maximum: -1
disallowed-blocks: [6, 7, 14, 15, 16, 26, 27, 28, 29, 39, 31, 32, 33, 34, 36, 37, 38, 39, 40, 46, 50, 51, 56, 59, 69, 73, 74, 75, 76, 77, 81, 83]
use-inventory:
enable: false
allow-override: true
creative-mode-overrides: false
logging:
log-commands: false
file: worldedit.log
super-pickaxe:
drop-items: true
many-drop-items: false
snapshots:
directory:
navigation-wand:
item: 345
max-distance: 100
scripting:
timeout: 3000
dir: craftscripts
saving:
dir: schematics
files:
allow-symbolic-links: false
history:
size: 15
expiration: 10
wand-item: 271
shell-save-type:
no-double-slash: false
no-op-permissions: false
debug: false

Datei anzeigen

@ -10,8 +10,8 @@ import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldVector;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.cui.CUIEvent;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.cui.CUIEvent;
public class ForgePlayer extends LocalPlayer {
private EntityPlayerMP player;

Datei anzeigen

@ -6,8 +6,8 @@ import com.sk89q.worldedit.Location;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.forge.WorldEditMod;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.CuboidRegionSelector;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.regions.selector.RegionSelector;
public class CuboidSelection extends RegionSelection {
protected CuboidRegion cuboid;

Datei anzeigen

@ -8,8 +8,8 @@ import net.minecraft.world.World;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.forge.WorldEditMod;
import com.sk89q.worldedit.regions.Polygonal2DRegion;
import com.sk89q.worldedit.regions.Polygonal2DRegionSelector;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
import com.sk89q.worldedit.regions.selector.RegionSelector;
public class Polygonal2DSelection extends RegionSelection {
protected Polygonal2DRegion poly2d;

Datei anzeigen

@ -8,7 +8,7 @@ import com.sk89q.worldedit.Location;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.forge.WorldEditMod;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.RegionSelector;
public abstract class RegionSelection implements Selection {
private WeakReference<World> world;

Datei anzeigen

@ -4,7 +4,7 @@ import net.minecraft.world.World;
import com.sk89q.worldedit.Location;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.RegionSelector;
public abstract interface Selection {
public abstract Location getMinimumPoint();

Datei anzeigen

@ -0,0 +1,27 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team 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.data;
/**
* @deprecated Switch to {@link com.sk89q.worldedit.world.DataException}
*/
@Deprecated
public class DataException extends com.sk89q.worldedit.world.DataException {
}

Datei anzeigen

@ -0,0 +1,41 @@
// $Id$
/*
* This file is a part of WorldEdit.
* Copyright (c) sk89q <http://www.sk89q.com>
* Copyright (c) the WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
* (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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.foundation;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* @deprecated Use {@link BaseBlock}
*/
@Deprecated
public abstract class Block {
public abstract int getId();
public abstract void setId(int id);
public abstract int getData();
public abstract void setData(int data);
public abstract void setIdAndData(int id, int data);
public abstract boolean hasWildcardData();
}

Datei anzeigen

@ -1,11 +1,16 @@
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
public abstract class AbstractMask implements Mask {
@Override
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
}
}
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
/**
* @deprecated Switch to {@link com.sk89q.worldedit.function.mask.AbstractMask}
*/
@Deprecated
public abstract class AbstractMask implements Mask {
@Override
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
}
}

Datei anzeigen

@ -1,14 +1,19 @@
package com.sk89q.worldedit.masks;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/**
* @deprecated Use {@link com.sk89q.worldedit.function.mask.BlockMask}
*/
@Deprecated
public class BlockMask extends AbstractMask {
private final Set<BaseBlock> blocks;
public BlockMask() {
@ -19,6 +24,13 @@ public class BlockMask extends AbstractMask {
this.blocks = types;
}
public BlockMask(BaseBlock... block) {
blocks = new HashSet<BaseBlock>();
for (BaseBlock b : block) {
add(b);
}
}
public BlockMask(BaseBlock block) {
this();
add(block);
@ -35,7 +47,8 @@ public class BlockMask extends AbstractMask {
@Override
public boolean matches(EditSession editSession, Vector pos) {
BaseBlock block = editSession.getBlock(pos);
return blocks.contains(block)
return blocks.contains(block)
|| blocks.contains(new BaseBlock(block.getType(), -1));
}
}
}

Datei anzeigen

@ -1,52 +1,52 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.masks;
import java.util.Set;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* A filter that matches blocks based on block types.
*
* @deprecated replaced by {@link #BlockMask}
* @author sk89q
*/
@Deprecated
public class BlockTypeMask extends BlockMask {
public BlockTypeMask() {
super();
}
public BlockTypeMask(Set<Integer> types) {
super();
for (int type : types) {
add(type);
}
}
public BlockTypeMask(int type) {
this();
add(type);
}
public void add(int type) {
add(new BaseBlock(type));
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.masks;
import java.util.Set;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* A filter that matches blocks based on block types.
*
* @deprecated replaced by {@link #BlockMask}
* @author sk89q
*/
@Deprecated
public class BlockTypeMask extends BlockMask {
public BlockTypeMask() {
super();
}
public BlockTypeMask(Set<Integer> types) {
super();
for (int type : types) {
add(type);
}
}
public BlockTypeMask(int type) {
this();
add(type);
}
public void add(int type) {
add(new BaseBlock(type));
}
}

Datei anzeigen

@ -1,72 +1,84 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.masks;
import java.util.ArrayList;
import java.util.List;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
public class CombinedMask extends AbstractMask {
private final List<Mask> masks = new ArrayList<Mask>();
public CombinedMask() {
}
public CombinedMask(Mask mask) {
masks.add(mask);
}
public CombinedMask(List<Mask> masks) {
this.masks.addAll(masks);
}
public void add(Mask mask) {
masks.add(mask);
}
public boolean remove(Mask mask) {
return masks.remove(mask);
}
public boolean has(Mask mask) {
return masks.contains(mask);
}
@Override
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
for (Mask mask : masks) {
mask.prepare(session, player, target);
}
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
for (Mask mask : masks) {
if (!mask.matches(editSession, pos)) {
return false;
}
}
return true;
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.function.mask.MaskIntersection;
import java.util.ArrayList;
import java.util.List;
/**
* @deprecated See {@link MaskIntersection}
*/
@Deprecated
public class CombinedMask extends AbstractMask {
private final List<Mask> masks = new ArrayList<Mask>();
public CombinedMask() {
}
public CombinedMask(Mask mask) {
add(mask);
}
public CombinedMask(Mask ...mask) {
for (Mask m : mask) {
add(m);
}
}
public CombinedMask(List<Mask> masks) {
this.masks.addAll(masks);
}
public void add(Mask mask) {
masks.add(mask);
}
public boolean remove(Mask mask) {
return masks.remove(mask);
}
public boolean has(Mask mask) {
return masks.contains(mask);
}
@Override
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
for (Mask mask : masks) {
mask.prepare(session, player, target);
}
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
for (Mask mask : masks) {
if (!mask.matches(editSession, pos)) {
return false;
}
}
return true;
}
}

Datei anzeigen

@ -1,13 +1,14 @@
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.session.request.RequestSelection;
public class DynamicRegionMask implements Mask {
/**
* @deprecated Use {@link RequestSelection} with {@link com.sk89q.worldedit.function.mask.RegionMask}
*/
@Deprecated
public class DynamicRegionMask extends AbstractMask {
private Region region;
@Override

Datei anzeigen

@ -1,31 +1,35 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockID;
public class ExistingBlockMask extends AbstractMask {
@Override
public boolean matches(EditSession editSession, Vector pos) {
return editSession.getBlockType(pos) != BlockID.AIR;
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockID;
/**
* @deprecated See {@link com.sk89q.worldedit.function.mask.ExistingBlockMask}
*/
@Deprecated
public class ExistingBlockMask extends AbstractMask {
@Override
public boolean matches(EditSession editSession, Vector pos) {
return editSession.getBlockType(pos) != BlockID.AIR;
}
}

Datei anzeigen

@ -0,0 +1,64 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team 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.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import java.util.HashSet;
import java.util.Set;
/**
* @deprecated See {@link com.sk89q.worldedit.function.mask.FuzzyBlockMask}
*/
@Deprecated
public class FuzzyBlockMask extends AbstractMask {
private final Set<BaseBlock> filter;
/**
* Create a new fuzzy block mask.
*
* @param filter a list of block types to match
*/
public FuzzyBlockMask(Set<BaseBlock> filter) {
this.filter = filter;
}
/**
* Create a new fuzzy block mask.
*
* @param block a list of block types to match
*/
public FuzzyBlockMask(BaseBlock... block) {
Set<BaseBlock> filter = new HashSet<BaseBlock>();
for (BaseBlock b : block) {
filter.add(b);
}
this.filter = filter;
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
BaseBlock compare = new BaseBlock(editSession.getBlockType(pos), editSession.getBlockData(pos));
return BaseBlock.containsFuzzy(filter, compare);
}
}

Datei anzeigen

@ -1,54 +1,54 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.masks;
import java.util.Set;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
/**
* A block type mask that only matches blocks that are not in the list.
*
* @author sk89q
*/
@Deprecated
public class InvertedBlockTypeMask extends BlockTypeMask {
public InvertedBlockTypeMask() {
}
/**
* @param types
*/
public InvertedBlockTypeMask(Set<Integer> types) {
super(types);
}
/**
* @param type
*/
public InvertedBlockTypeMask(int type) {
super(type);
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
return !super.matches(editSession, pos);
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.masks;
import java.util.Set;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
/**
* A block type mask that only matches blocks that are not in the list.
*
* @author sk89q
*/
@Deprecated
public class InvertedBlockTypeMask extends BlockTypeMask {
public InvertedBlockTypeMask() {
}
/**
* @param types
*/
public InvertedBlockTypeMask(Set<Integer> types) {
super(types);
}
/**
* @param type
*/
public InvertedBlockTypeMask(int type) {
super(type);
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
return !super.matches(editSession, pos);
}
}

Datei anzeigen

@ -4,7 +4,12 @@ import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.function.mask.Masks;
/**
* @deprecated See {@link Masks#negate(com.sk89q.worldedit.function.mask.Mask)}
*/
@Deprecated
public class InvertedMask extends AbstractMask {
private final Mask mask;

Datei anzeigen

@ -1,57 +1,53 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
/**
* Base matcher for the block filtering framework. Implementing classes
* can be used to filter blocks to set or replace.
* <p>
* <u>Do NOT</u> implement this interface. Extend {@link AbstractMask} instead.
*
* @author sk89q
*/
public interface Mask {
/**
* Called one time before each edit session.
*
* @param session
* @param player
* @param target target of the brush, null if not a brush mask
*/
void prepare(LocalSession session, LocalPlayer player, Vector target);
/**
* Given a block position, this method returns true if the block at
* that position matches the filter. Block information is not provided
* as getting a BaseBlock has unneeded overhead in most block querying
* situations (enumerating a chest's contents is a waste, for example).
*
* @param editSession
* @param pos
* @return
*/
boolean matches(EditSession editSession, Vector pos);
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
/**
* @deprecated Use {@link com.sk89q.worldedit.function.mask.Mask}
*/
@Deprecated
public interface Mask {
/**
* Called one time before each edit session.
*
* @param session
* @param player
* @param target target of the brush, null if not a brush mask
*/
void prepare(LocalSession session, LocalPlayer player, Vector target);
/**
* Given a block position, this method returns true if the block at
* that position matches the filter. Block information is not provided
* as getting a BaseBlock has unneeded overhead in most block querying
* situations (enumerating a chest's contents is a waste, for example).
*
* @param editSession
* @param pos
* @return
*/
boolean matches(EditSession editSession, Vector pos);
}

Datei anzeigen

@ -2,7 +2,12 @@ package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.function.mask.NoiseFilter;
/**
* @deprecated See {@link NoiseFilter}
*/
@Deprecated
public class RandomMask extends AbstractMask {
private final double ratio;

Datei anzeigen

@ -1,37 +1,41 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.Region;
public class RegionMask extends AbstractMask {
private final Region region;
public RegionMask(Region region) {
this.region = region.clone();
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
return region.contains(pos);
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010, 2011 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.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.regions.Region;
/**
* @deprecated See {@link com.sk89q.worldedit.function.mask.RegionMask}
*/
@Deprecated
public class RegionMask extends AbstractMask {
private final Region region;
public RegionMask(Region region) {
this.region = region.clone();
}
@Override
public boolean matches(EditSession editSession, Vector pos) {
return region.contains(pos);
}
}

Datei anzeigen

@ -1,15 +1,16 @@
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockType;
/**
* Works like {@link ExistingBlockMask}, except also dealing with non-solid non-air blocks the same way as with air.
*/
public class SolidBlockMask extends AbstractMask {
@Override
public boolean matches(EditSession editSession, Vector pos) {
return !BlockType.canPassThrough(editSession.getBlockType(pos), editSession.getBlockData(pos));
}
}
package com.sk89q.worldedit.masks;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BlockType;
/**
* @deprecated See {@link com.sk89q.worldedit.function.mask.SolidBlockMask}
*/
@Deprecated
public class SolidBlockMask extends AbstractMask {
@Override
public boolean matches(EditSession editSession, Vector pos) {
return !BlockType.canPassThrough(editSession.getBlockType(pos), editSession.getBlockData(pos));
}
}

Datei anzeigen

@ -19,18 +19,21 @@
package com.sk89q.worldedit.masks;
import java.util.Set;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalPlayer;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.function.mask.MaskIntersection;
import com.sk89q.worldedit.function.mask.Masks;
import com.sk89q.worldedit.function.mask.OffsetMask;
import java.util.Set;
/**
*
* @author 1337
* @deprecated Use {@link OffsetMask} with {@link MaskIntersection} and {@link Masks#negate(com.sk89q.worldedit.function.mask.Mask)}
*/
@Deprecated
public class UnderOverlayMask extends AbstractMask {
private final int yMod;
private Mask mask;

Datei anzeigen

@ -22,10 +22,9 @@ package com.sk89q.worldedit.patterns;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* Gives a block a chance.
*
* @author sk89q
* @deprecated Will be removed in the future -- there is no replacement
*/
@Deprecated
public class BlockChance {
/**
* Block.

Datei anzeigen

@ -1,75 +1,75 @@
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.patterns;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* Pattern that repeats the clipboard.
*
* @author sk89q
*/
public class ClipboardPattern implements Pattern {
/**
* Clipboard.
*/
private CuboidClipboard clipboard;
/**
* Size of the clipboard.
*/
private Vector size;
/**
* Construct the object.
*
* @param clipboard
*/
public ClipboardPattern(CuboidClipboard clipboard) {
this.clipboard = clipboard;
this.size = clipboard.getSize();
}
/**
* Get next block.
*
* @param pos
* @return
*/
public BaseBlock next(Vector pos) {
return next(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
}
/**
* Get next block.
*
* @param x
* @param y
* @param z
* @return
*/
public BaseBlock next(int x, int y, int z) {
int xp = Math.abs(x) % size.getBlockX();
int yp = Math.abs(y) % size.getBlockY();
int zp = Math.abs(z) % size.getBlockZ();
return clipboard.getPoint(new Vector(xp, yp, zp));
}
}
// $Id$
/*
* WorldEdit
* Copyright (C) 2010 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.patterns;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* Pattern that repeats the clipboard.
*
* @author sk89q
*/
public class ClipboardPattern implements Pattern {
/**
* Clipboard.
*/
private CuboidClipboard clipboard;
/**
* Size of the clipboard.
*/
private Vector size;
/**
* Construct the object.
*
* @param clipboard
*/
public ClipboardPattern(CuboidClipboard clipboard) {
this.clipboard = clipboard;
this.size = clipboard.getSize();
}
/**
* Get next block.
*
* @param pos
* @return
*/
public BaseBlock next(Vector pos) {
return next(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
}
/**
* Get next block.
*
* @param x
* @param y
* @param z
* @return
*/
public BaseBlock next(int x, int y, int z) {
int xp = Math.abs(x) % size.getBlockX();
int yp = Math.abs(y) % size.getBlockY();
int zp = Math.abs(z) % size.getBlockZ();
return clipboard.getPoint(new Vector(xp, yp, zp));
}
}

Datei anzeigen

@ -23,11 +23,9 @@ import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
/**
* Used to get the block to set. This can be used to implement a pattern
* for when setting a region with blocks.
*
* @author sk89q
* @deprecated See {@link com.sk89q.worldedit.function.pattern.Pattern}
*/
@Deprecated
public interface Pattern {
/**
* Get a block for a position. This return value of this method does

Datei anzeigen

@ -19,17 +19,18 @@
package com.sk89q.worldedit.patterns;
import java.util.Random;
import java.util.List;
import java.util.ArrayList;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.function.pattern.RandomPattern;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* Pattern proportionally fills.
*
* @author sk89q
* @deprecated See {@link RandomPattern}
*/
@Deprecated
public class RandomFillPattern implements Pattern {
/**
* Random number generator.

Datei anzeigen

@ -21,12 +21,12 @@ package com.sk89q.worldedit.patterns;
import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.function.pattern.BlockPattern;
/**
* Always returns the same block type.
*
* @author sk89q
* @deprecated See {@link BlockPattern}
*/
@Deprecated
public class SingleBlockPattern implements Pattern {
/**
* Block type.

Datei anzeigen

@ -2,20 +2,7 @@ package com.sk89q.jnbt;
import java.util.Map;
import com.sk89q.jnbt.ByteArrayTag;
import com.sk89q.jnbt.ByteTag;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.DoubleTag;
import com.sk89q.jnbt.EndTag;
import com.sk89q.jnbt.FloatTag;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.LongTag;
import com.sk89q.jnbt.NBTConstants;
import com.sk89q.jnbt.ShortTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.data.InvalidFormatException;
import com.sk89q.worldedit.world.storage.InvalidFormatException;
/*
* JNBT License

Datei anzeigen

@ -30,9 +30,10 @@ import java.util.Map;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.data.DataException;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.schematic.SchematicFormat;
import com.sk89q.worldedit.util.Countable;
/**
* The clipboard remembers the state of a cuboid region.

Datei-Diff unterdrückt, da er zu groß ist Diff laden

Datei anzeigen

@ -1,51 +1,75 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team 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;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
import com.sk89q.worldedit.extent.inventory.BlockBag;
/**
* @deprecated To wrap {@link EditSession}s, please hook into {@link EditSessionEvent}
*/
@Deprecated
public class EditSessionFactory {
/**
* Construct an edit session with a maximum number of blocks.
*
* @param world
* @param maxBlocks
* @param world the world
* @param maxBlocks the maximum number of blocks that can be changed, or -1 to use no limit
*/
public EditSession getEditSession(LocalWorld world, int maxBlocks) {
return new EditSession(world, maxBlocks);
throw new IllegalArgumentException("This class is being removed");
}
/**
* Construct an edit session with a maximum number of blocks.
*
* @param world
* @param maxBlocks
* @param player
* @param world the world
* @param maxBlocks the maximum number of blocks that can be changed, or -1 to use no limit
* @param player the player that the {@link EditSession} is for
*/
public EditSession getEditSession(LocalWorld world, int maxBlocks, LocalPlayer player) {
return this.getEditSession(world, maxBlocks);
throw new IllegalArgumentException("This class is being removed");
}
/**
* Construct an edit session with a maximum number of blocks and a block bag.
*
* @param world
* @param maxBlocks
* @param blockBag
* @param world the world
* @param maxBlocks the maximum number of blocks that can be changed, or -1 to use no limit
* @param blockBag an optional {@link BlockBag} to use, otherwise null
*/
public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag) {
return new EditSession(world, maxBlocks, blockBag);
throw new IllegalArgumentException("This class is being removed");
}
/**
* Construct an edit session with a maximum number of blocks and a block bag.
*
* @param world
* @param maxBlocks
* @param blockBag
* @param player
* @param world the world
* @param maxBlocks the maximum number of blocks that can be changed, or -1 to use no limit
* @param blockBag an optional {@link BlockBag} to use, otherwise null
* @param player the player that the {@link EditSession} is for
*/
public EditSession getEditSession(LocalWorld world, int maxBlocks, BlockBag blockBag, LocalPlayer player) {
return this.getEditSession(world, maxBlocks, blockBag);
throw new IllegalArgumentException("This class is being removed");
}
}

Datei anzeigen

@ -25,7 +25,7 @@ import java.util.Set;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.ItemID;
import com.sk89q.worldedit.snapshots.SnapshotRepository;
import com.sk89q.worldedit.world.snapshot.SnapshotRepository;
/**
* Represents WorldEdit's configuration.

Datei anzeigen

@ -21,12 +21,12 @@ package com.sk89q.worldedit;
import java.io.File;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.blocks.ItemID;
import com.sk89q.worldedit.cui.CUIEvent;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.util.TargetBlock;
/**

Datei anzeigen

@ -19,28 +19,26 @@
package com.sk89q.worldedit;
import java.util.Calendar;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.TimeZone;
import com.sk89q.jchronic.Chronic;
import com.sk89q.jchronic.Options;
import com.sk89q.jchronic.utils.Span;
import com.sk89q.jchronic.utils.Time;
import com.sk89q.worldedit.snapshots.Snapshot;
import com.sk89q.worldedit.tools.BrushTool;
import com.sk89q.worldedit.tools.SinglePickaxe;
import com.sk89q.worldedit.tools.BlockTool;
import com.sk89q.worldedit.tools.Tool;
import com.sk89q.worldedit.bags.BlockBag;
import com.sk89q.worldedit.cui.CUIRegion;
import com.sk89q.worldedit.cui.CUIEvent;
import com.sk89q.worldedit.cui.SelectionShapeEvent;
import com.sk89q.worldedit.command.tool.BlockTool;
import com.sk89q.worldedit.command.tool.BrushTool;
import com.sk89q.worldedit.command.tool.SinglePickaxe;
import com.sk89q.worldedit.command.tool.Tool;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.internal.cui.CUIRegion;
import com.sk89q.worldedit.internal.cui.SelectionShapeEvent;
import com.sk89q.worldedit.masks.Mask;
import com.sk89q.worldedit.regions.CuboidRegionSelector;
import com.sk89q.worldedit.regions.selector.CuboidRegionSelector;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.regions.RegionSelector;
import com.sk89q.worldedit.regions.selector.RegionSelector;
import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.world.snapshot.Snapshot;
import java.util.*;
/**
* An instance of this represents the WorldEdit session of a user. A session
@ -704,6 +702,7 @@ public class LocalSession {
.getEditSession(player.isPlayer() ? player.getWorld() : null,
getBlockChangeLimit(), blockBag, player);
editSession.setFastMode(fastMode);
Request.request().setEditSession(editSession);
if (mask != null) {
mask.prepare(this, player, null);
}

Datei anzeigen

@ -19,31 +19,26 @@
package com.sk89q.worldedit;
import java.util.PriorityQueue;
import java.util.Random;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.BlockType;
import com.sk89q.worldedit.blocks.ChestBlock;
import com.sk89q.worldedit.blocks.DispenserBlock;
import com.sk89q.worldedit.blocks.FurnaceBlock;
import com.sk89q.worldedit.blocks.MobSpawnerBlock;
import com.sk89q.worldedit.blocks.NoteBlock;
import com.sk89q.worldedit.blocks.SignBlock;
import com.sk89q.worldedit.blocks.SkullBlock;
import com.sk89q.worldedit.foundation.Block;
import com.sk89q.worldedit.foundation.World;
import com.sk89q.worldedit.blocks.*;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.TreeGenerator;
import javax.annotation.Nullable;
import java.util.PriorityQueue;
import java.util.Random;
/**
* Represents a world.
*
* @author sk89q
*/
public abstract class LocalWorld implements World {
public abstract class LocalWorld implements World, Extent {
/**
* Named flags to use as parameters to {@link LocalWorld#killMobs(Vector, double, int)}
*/
@ -97,6 +92,7 @@ public abstract class LocalWorld implements World {
* @param pt
* @return
*/
@Deprecated
public abstract int getBlockType(Vector pt);
/**
@ -166,6 +162,7 @@ public abstract class LocalWorld implements World {
* @param pt
* @return
*/
@Deprecated
public abstract int getBlockData(Vector pt);
/**
@ -528,9 +525,14 @@ public abstract class LocalWorld implements World {
public int killEntities(LocalEntity... entities) {
return 0;
}
@Override
public boolean setBlock(Vector pt, BaseBlock block) {
return setBlock(pt, block, true);
}
@Override
public boolean setBlock(Vector pt, Block block, boolean notifyAdjacent) {
public boolean setBlock(Vector pt, BaseBlock block, boolean notifyAdjacent) {
boolean successful;
// Default implementation will call the old deprecated methods
@ -547,6 +549,11 @@ public abstract class LocalWorld implements World {
return successful;
}
@Override
public BaseBlock getLazyBlock(Vector position) {
return getBlock(position);
}
@Override
public BaseBlock getBlock(Vector pt) {
checkLoadedChunk(pt);
@ -603,4 +610,34 @@ public abstract class LocalWorld implements World {
return new BaseBlock(type, data);
}
}
/**
* Create a mask that matches all liquids.
* </p>
* Implementations should override this so that custom liquids are supported.
*
* @return a mask
*/
public Mask createLiquidMask() {
return new BlockMask(this,
new BaseBlock(BlockID.STATIONARY_LAVA, -1),
new BaseBlock(BlockID.LAVA, -1),
new BaseBlock(BlockID.STATIONARY_WATER, -1),
new BaseBlock(BlockID.WATER, -1));
}
@Override
public Vector getMaximumPoint() {
return new Vector(30000000, 30000000, 30000000);
}
@Override
public Vector getMinimumPoint() {
return new Vector(-30000000, -30000000, -30000000);
}
@Override
public @Nullable Operation commit() {
return null;
}
}

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden Mehr anzeigen