geforkt von Mirrors/FastAsyncWorldEdit
Fix Javadocs and code issues.
Dieser Commit ist enthalten in:
Ursprung
8834af7538
Commit
1dc84d2511
@ -36,22 +36,27 @@ public class TestOfflinePermissible implements OfflinePlayer, Permissible {
|
|||||||
|
|
||||||
private final Map<String, Boolean> assignedPermissions = new HashMap<String, Boolean>();
|
private final Map<String, Boolean> assignedPermissions = new HashMap<String, Boolean>();
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isOp() {
|
public boolean isOp() {
|
||||||
return op;
|
return op;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setOp(boolean b) {
|
public void setOp(boolean b) {
|
||||||
this.op = b;
|
this.op = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isPermissionSet(String s) {
|
public boolean isPermissionSet(String s) {
|
||||||
return assignedPermissions.containsKey(s.toLowerCase());
|
return assignedPermissions.containsKey(s.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isPermissionSet(Permission permission) {
|
public boolean isPermissionSet(Permission permission) {
|
||||||
return isPermissionSet(permission.getName());
|
return isPermissionSet(permission.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String s) {
|
public boolean hasPermission(String s) {
|
||||||
if (isPermissionSet(s)) {
|
if (isPermissionSet(s)) {
|
||||||
return assignedPermissions.get(s.toLowerCase());
|
return assignedPermissions.get(s.toLowerCase());
|
||||||
@ -59,34 +64,42 @@ public class TestOfflinePermissible implements OfflinePlayer, Permissible {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(Permission permission) {
|
public boolean hasPermission(Permission permission) {
|
||||||
return hasPermission(permission.getName());
|
return hasPermission(permission.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public PermissionAttachment addAttachment(Plugin plugin, String s, boolean b) {
|
public PermissionAttachment addAttachment(Plugin plugin, String s, boolean b) {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public PermissionAttachment addAttachment(Plugin plugin) {
|
public PermissionAttachment addAttachment(Plugin plugin) {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public PermissionAttachment addAttachment(Plugin plugin, String s, boolean b, int i) {
|
public PermissionAttachment addAttachment(Plugin plugin, String s, boolean b, int i) {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public PermissionAttachment addAttachment(Plugin plugin, int i) {
|
public PermissionAttachment addAttachment(Plugin plugin, int i) {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void removeAttachment(PermissionAttachment permissionAttachment) {
|
public void removeAttachment(PermissionAttachment permissionAttachment) {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void recalculatePermissions() {
|
public void recalculatePermissions() {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
||||||
Set<PermissionAttachmentInfo> ret = new HashSet<PermissionAttachmentInfo>();
|
Set<PermissionAttachmentInfo> ret = new HashSet<PermissionAttachmentInfo>();
|
||||||
for (Map.Entry<String, Boolean> entry : assignedPermissions.entrySet()) {
|
for (Map.Entry<String, Boolean> entry : assignedPermissions.entrySet()) {
|
||||||
@ -109,10 +122,12 @@ public class TestOfflinePermissible implements OfflinePlayer, Permissible {
|
|||||||
|
|
||||||
// -- Unneeded OfflinePlayer methods
|
// -- Unneeded OfflinePlayer methods
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isOnline() {
|
public boolean isOnline() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Tester";
|
return "Tester";
|
||||||
}
|
}
|
||||||
@ -121,42 +136,52 @@ public class TestOfflinePermissible implements OfflinePlayer, Permissible {
|
|||||||
return randomUuid;
|
return randomUuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isBanned() {
|
public boolean isBanned() {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setBanned(boolean b) {
|
public void setBanned(boolean b) {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isWhitelisted() {
|
public boolean isWhitelisted() {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setWhitelisted(boolean b) {
|
public void setWhitelisted(boolean b) {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public long getFirstPlayed() {
|
public long getFirstPlayed() {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public long getLastPlayed() {
|
public long getLastPlayed() {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPlayedBefore() {
|
public boolean hasPlayedBefore() {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Location getBedSpawnLocation() {
|
public Location getBedSpawnLocation() {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Map<String, Object> serialize() {
|
public Map<String, Object> serialize() {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
@ -23,14 +23,13 @@ import com.sk89q.worldedit.util.TreeGenerator;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author zml2008
|
|
||||||
*/
|
|
||||||
public class BukkitWorldTest {
|
public class BukkitWorldTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTreeTypeMapping() {
|
public void testTreeTypeMapping() {
|
||||||
for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) {
|
for (TreeGenerator.TreeType type : TreeGenerator.TreeType.values()) {
|
||||||
Assert.assertFalse("No mapping for: " + type, BukkitWorld.toBukkitTreeType(type) == null);
|
Assert.assertFalse("No mapping for: " + type, BukkitWorld.toBukkitTreeType(type) == null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,8 @@
|
|||||||
|
|
||||||
package com.sk89q.bukkit.util;
|
package com.sk89q.bukkit.util;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author zml2008
|
|
||||||
*/
|
|
||||||
public class CommandInfo {
|
public class CommandInfo {
|
||||||
|
|
||||||
private final String[] aliases;
|
private final String[] aliases;
|
||||||
private final Object registeredWith;
|
private final Object registeredWith;
|
||||||
private final String usage, desc;
|
private final String usage, desc;
|
||||||
@ -63,4 +61,5 @@ public class CommandInfo {
|
|||||||
public Object getRegisteredWith() {
|
public Object getRegisteredWith() {
|
||||||
return registeredWith;
|
return registeredWith;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,6 @@
|
|||||||
|
|
||||||
package com.sk89q.bukkit.util;
|
package com.sk89q.bukkit.util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.sk89q.util.ReflectionUtil;
|
import com.sk89q.util.ReflectionUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
@ -32,9 +26,12 @@ import org.bukkit.command.CommandMap;
|
|||||||
import org.bukkit.command.SimpleCommandMap;
|
import org.bukkit.command.SimpleCommandMap;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
/**
|
import java.util.ArrayList;
|
||||||
* @author zml2008
|
import java.util.Iterator;
|
||||||
*/
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class CommandRegistration {
|
public class CommandRegistration {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@ -109,4 +106,5 @@ public class CommandRegistration {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,10 +31,8 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author zml2008
|
|
||||||
*/
|
|
||||||
public class CommandsManagerRegistration extends CommandRegistration {
|
public class CommandsManagerRegistration extends CommandRegistration {
|
||||||
|
|
||||||
protected CommandsManager<?> commands;
|
protected CommandsManager<?> commands;
|
||||||
|
|
||||||
public CommandsManagerRegistration(Plugin plugin, CommandsManager<?> commands) {
|
public CommandsManagerRegistration(Plugin plugin, CommandsManager<?> commands) {
|
||||||
@ -60,7 +58,7 @@ public class CommandsManagerRegistration extends CommandRegistration {
|
|||||||
|
|
||||||
if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) {
|
if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) {
|
||||||
permissions = Arrays.asList(cmdMethod.getAnnotation(CommandPermissions.class).value());
|
permissions = Arrays.asList(cmdMethod.getAnnotation(CommandPermissions.class).value());
|
||||||
} else if (cmdMethod != null && childMethods != null && childMethods.size() > 0) {
|
} else if (cmdMethod != null && childMethods != null && !childMethods.isEmpty()) {
|
||||||
permissions = new ArrayList<String>();
|
permissions = new ArrayList<String>();
|
||||||
for (Method m : childMethods.values()) {
|
for (Method m : childMethods.values()) {
|
||||||
if (m.isAnnotationPresent(CommandPermissions.class)) {
|
if (m.isAnnotationPresent(CommandPermissions.class)) {
|
||||||
@ -74,4 +72,5 @@ public class CommandsManagerRegistration extends CommandRegistration {
|
|||||||
|
|
||||||
return register(toRegister);
|
return register(toRegister);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,10 +30,8 @@ import org.bukkit.help.HelpTopicFactory;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author zml2008
|
|
||||||
*/
|
|
||||||
public class DynamicPluginCommandHelpTopic extends HelpTopic {
|
public class DynamicPluginCommandHelpTopic extends HelpTopic {
|
||||||
|
|
||||||
private final DynamicPluginCommand cmd;
|
private final DynamicPluginCommand cmd;
|
||||||
|
|
||||||
public DynamicPluginCommandHelpTopic(DynamicPluginCommand cmd) {
|
public DynamicPluginCommandHelpTopic(DynamicPluginCommand cmd) {
|
||||||
@ -140,10 +138,10 @@ public class DynamicPluginCommandHelpTopic extends HelpTopic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class Factory implements HelpTopicFactory<DynamicPluginCommand> {
|
public static class Factory implements HelpTopicFactory<DynamicPluginCommand> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HelpTopic createTopic(DynamicPluginCommand command) {
|
public HelpTopic createTopic(DynamicPluginCommand command) {
|
||||||
return new DynamicPluginCommandHelpTopic(command);
|
return new DynamicPluginCommandHelpTopic(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,6 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author zml2008
|
|
||||||
*/
|
|
||||||
public class FallbackRegistrationListener implements Listener {
|
public class FallbackRegistrationListener implements Listener {
|
||||||
|
|
||||||
private final CommandMap commandRegistration;
|
private final CommandMap commandRegistration;
|
||||||
@ -41,4 +38,5 @@ public class FallbackRegistrationListener implements Listener {
|
|||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
|||||||
return section;
|
return section;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void load() {
|
public void load() {
|
||||||
userGroups = new HashMap<String, Set<String>>();
|
userGroups = new HashMap<String, Set<String>>();
|
||||||
userPermissionsCache = new HashMap<String, Set<String>>();
|
userPermissionsCache = new HashMap<String, Set<String>>();
|
||||||
@ -64,7 +65,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
|||||||
List<String> permissions =
|
List<String> permissions =
|
||||||
config.getStringList("permissions.groups." + key + ".permissions", null);
|
config.getStringList("permissions.groups." + key + ".permissions", null);
|
||||||
|
|
||||||
if (permissions.size() > 0) {
|
if (!permissions.isEmpty()) {
|
||||||
Set<String> groupPerms = new HashSet<String>(permissions);
|
Set<String> groupPerms = new HashSet<String>(permissions);
|
||||||
userGroupPermissions.put(key, groupPerms);
|
userGroupPermissions.put(key, groupPerms);
|
||||||
|
|
||||||
@ -84,7 +85,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
|||||||
List<String> permissions =
|
List<String> permissions =
|
||||||
config.getStringList("permissions.users." + key + ".permissions", null);
|
config.getStringList("permissions.users." + key + ".permissions", null);
|
||||||
|
|
||||||
if (permissions.size() > 0) {
|
if (!permissions.isEmpty()) {
|
||||||
permsCache.addAll(permissions);
|
permsCache.addAll(permissions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +93,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
|||||||
config.getStringList("permissions.users." + key + ".groups", null);
|
config.getStringList("permissions.users." + key + ".groups", null);
|
||||||
groups.add("default");
|
groups.add("default");
|
||||||
|
|
||||||
if (groups.size() > 0) {
|
if (!groups.isEmpty()) {
|
||||||
for (String group : groups) {
|
for (String group : groups) {
|
||||||
Set<String> groupPerms = userGroupPermissions.get(group);
|
Set<String> groupPerms = userGroupPermissions.get(group);
|
||||||
if (groupPerms != null) {
|
if (groupPerms != null) {
|
||||||
@ -107,6 +108,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String player, String permission) {
|
public boolean hasPermission(String player, String permission) {
|
||||||
int dotPos = permission.lastIndexOf(".");
|
int dotPos = permission.lastIndexOf(".");
|
||||||
if (dotPos > -1) {
|
if (dotPos > -1) {
|
||||||
@ -124,11 +126,13 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
|||||||
return perms.contains("*") || perms.contains(permission);
|
return perms.contains("*") || perms.contains(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String worldName, String player, String permission) {
|
public boolean hasPermission(String worldName, String player, String permission) {
|
||||||
return hasPermission(player, "worlds." + worldName + "." + permission)
|
return hasPermission(player, "worlds." + worldName + "." + permission)
|
||||||
|| hasPermission(player, permission);
|
|| hasPermission(player, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean inGroup(String player, String group) {
|
public boolean inGroup(String player, String group) {
|
||||||
Set<String> groups = userGroups.get(player.toLowerCase());
|
Set<String> groups = userGroups.get(player.toLowerCase());
|
||||||
if (groups == null) {
|
if (groups == null) {
|
||||||
@ -138,6 +142,7 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
|||||||
return groups.contains(group);
|
return groups.contains(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getGroups(String player) {
|
public String[] getGroups(String player) {
|
||||||
Set<String> groups = userGroups.get(player.toLowerCase());
|
Set<String> groups = userGroups.get(player.toLowerCase());
|
||||||
if (groups == null) {
|
if (groups == null) {
|
||||||
@ -147,22 +152,27 @@ public class ConfigurationPermissionsResolver implements PermissionsResolver {
|
|||||||
return groups.toArray(new String[groups.size()]);
|
return groups.toArray(new String[groups.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(OfflinePlayer player, String permission) {
|
public boolean hasPermission(OfflinePlayer player, String permission) {
|
||||||
return hasPermission(player.getName(), permission);
|
return hasPermission(player.getName(), permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
||||||
return hasPermission(worldName, player.getName(), permission);
|
return hasPermission(worldName, player.getName(), permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean inGroup(OfflinePlayer player, String group) {
|
public boolean inGroup(OfflinePlayer player, String group) {
|
||||||
return inGroup(player.getName(), group);
|
return inGroup(player.getName(), group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getGroups(OfflinePlayer player) {
|
public String[] getGroups(OfflinePlayer player) {
|
||||||
return getGroups(player.getName());
|
return getGroups(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getDetectionMessage() {
|
public String getDetectionMessage() {
|
||||||
return "No known permissions plugin detected. Using configuration file for permissions.";
|
return "No known permissions plugin detected. Using configuration file for permissions.";
|
||||||
}
|
}
|
||||||
|
@ -43,25 +43,31 @@ public class DinnerPermsResolver implements PermissionsResolver {
|
|||||||
return new DinnerPermsResolver(server);
|
return new DinnerPermsResolver(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void load() {
|
public void load() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String name, String permission) {
|
public boolean hasPermission(String name, String permission) {
|
||||||
return hasPermission(server.getOfflinePlayer(name), permission);
|
return hasPermission(server.getOfflinePlayer(name), permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String worldName, String name, String permission) {
|
public boolean hasPermission(String worldName, String name, String permission) {
|
||||||
return hasPermission(worldName, server.getOfflinePlayer(name), permission);
|
return hasPermission(worldName, server.getOfflinePlayer(name), permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean inGroup(String name, String group) {
|
public boolean inGroup(String name, String group) {
|
||||||
return inGroup(server.getOfflinePlayer(name), group);
|
return inGroup(server.getOfflinePlayer(name), group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getGroups(String name) {
|
public String[] getGroups(String name) {
|
||||||
return getGroups(server.getOfflinePlayer(name));
|
return getGroups(server.getOfflinePlayer(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(OfflinePlayer player, String permission) {
|
public boolean hasPermission(OfflinePlayer player, String permission) {
|
||||||
Permissible perms = getPermissible(player);
|
Permissible perms = getPermissible(player);
|
||||||
if (perms == null) {
|
if (perms == null) {
|
||||||
@ -86,10 +92,12 @@ public class DinnerPermsResolver implements PermissionsResolver {
|
|||||||
return internalHasPermission(perms, "*") == 1;
|
return internalHasPermission(perms, "*") == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
||||||
return hasPermission(player, permission); // no per-world ability to check permissions in dinnerperms
|
return hasPermission(player, permission); // no per-world ability to check permissions in dinnerperms
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean inGroup(OfflinePlayer player, String group) {
|
public boolean inGroup(OfflinePlayer player, String group) {
|
||||||
final Permissible perms = getPermissible(player);
|
final Permissible perms = getPermissible(player);
|
||||||
if (perms == null) {
|
if (perms == null) {
|
||||||
@ -100,6 +108,7 @@ public class DinnerPermsResolver implements PermissionsResolver {
|
|||||||
return perms.isPermissionSet(perm) && perms.hasPermission(perm);
|
return perms.isPermissionSet(perm) && perms.hasPermission(perm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getGroups(OfflinePlayer player) {
|
public String[] getGroups(OfflinePlayer player) {
|
||||||
Permissible perms = getPermissible(player);
|
Permissible perms = getPermissible(player);
|
||||||
if (perms == null) {
|
if (perms == null) {
|
||||||
@ -149,6 +158,7 @@ public class DinnerPermsResolver implements PermissionsResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getDetectionMessage() {
|
public String getDetectionMessage() {
|
||||||
return "Using the Bukkit Permissions API.";
|
return "Using the Bukkit Permissions API.";
|
||||||
}
|
}
|
||||||
|
@ -19,27 +19,32 @@
|
|||||||
|
|
||||||
package com.sk89q.wepif;
|
package com.sk89q.wepif;
|
||||||
|
|
||||||
|
import com.sk89q.util.yaml.YAMLProcessor;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.HashMap;
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import com.sk89q.util.yaml.YAMLProcessor;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
|
|
||||||
public class FlatFilePermissionsResolver implements PermissionsResolver {
|
public class FlatFilePermissionsResolver implements PermissionsResolver {
|
||||||
|
|
||||||
|
private static final Logger log = Logger.getLogger(FlatFilePermissionsResolver.class.getCanonicalName());
|
||||||
|
|
||||||
private Map<String, Set<String>> userPermissionsCache;
|
private Map<String, Set<String>> userPermissionsCache;
|
||||||
private Set<String> defaultPermissionsCache;
|
private Set<String> defaultPermissionsCache;
|
||||||
private Map<String, Set<String>> userGroups;
|
private Map<String, Set<String>> userGroups;
|
||||||
|
|
||||||
protected File groupFile;
|
private final File groupFile;
|
||||||
protected File userFile;
|
private final File userFile;
|
||||||
|
|
||||||
public static PermissionsResolver factory(Server server, YAMLProcessor config) {
|
public static PermissionsResolver factory(Server server, YAMLProcessor config) {
|
||||||
File groups = new File("perms_groups.txt");
|
File groups = new File("perms_groups.txt");
|
||||||
@ -80,7 +85,7 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
|
|||||||
line = line.trim();
|
line = line.trim();
|
||||||
|
|
||||||
// Blank line
|
// Blank line
|
||||||
if (line.length() == 0) {
|
if (line.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
} else if (line.charAt(0) == ';' || line.charAt(0) == '#') {
|
} else if (line.charAt(0) == ';' || line.charAt(0) == '#') {
|
||||||
continue;
|
continue;
|
||||||
@ -98,19 +103,20 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
log.log(Level.WARNING, "Failed to load permissions", e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (buff != null) {
|
if (buff != null) {
|
||||||
buff.close();
|
buff.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e2) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return userGroupPermissions;
|
return userGroupPermissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void load() {
|
public void load() {
|
||||||
userGroups = new HashMap<String, Set<String>>();
|
userGroups = new HashMap<String, Set<String>>();
|
||||||
userPermissionsCache = new HashMap<String, Set<String>>();
|
userPermissionsCache = new HashMap<String, Set<String>>();
|
||||||
@ -135,7 +141,7 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
|
|||||||
line = line.trim();
|
line = line.trim();
|
||||||
|
|
||||||
// Blank line
|
// Blank line
|
||||||
if (line.length() == 0) {
|
if (line.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
} else if (line.charAt(0) == ';' || line.charAt(0) == '#') {
|
} else if (line.charAt(0) == ';' || line.charAt(0) == '#') {
|
||||||
continue;
|
continue;
|
||||||
@ -163,17 +169,18 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
log.log(Level.WARNING, "Failed to load permissions", e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (buff != null) {
|
if (buff != null) {
|
||||||
buff.close();
|
buff.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e2) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String player, String permission) {
|
public boolean hasPermission(String player, String permission) {
|
||||||
int dotPos = permission.lastIndexOf(".");
|
int dotPos = permission.lastIndexOf(".");
|
||||||
if (dotPos > -1) {
|
if (dotPos > -1) {
|
||||||
@ -191,20 +198,19 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
|
|||||||
return perms.contains("*") || perms.contains(permission);
|
return perms.contains("*") || perms.contains(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String worldName, String player, String permission) {
|
public boolean hasPermission(String worldName, String player, String permission) {
|
||||||
return hasPermission(player, "worlds." + worldName + "." + permission)
|
return hasPermission(player, "worlds." + worldName + "." + permission)
|
||||||
|| hasPermission(player, permission);
|
|| hasPermission(player, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean inGroup(String player, String group) {
|
public boolean inGroup(String player, String group) {
|
||||||
Set<String> groups = userGroups.get(player.toLowerCase());
|
Set<String> groups = userGroups.get(player.toLowerCase());
|
||||||
if (groups == null) {
|
return groups != null && groups.contains(group);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return groups.contains(group);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getGroups(String player) {
|
public String[] getGroups(String player) {
|
||||||
Set<String> groups = userGroups.get(player.toLowerCase());
|
Set<String> groups = userGroups.get(player.toLowerCase());
|
||||||
if (groups == null) {
|
if (groups == null) {
|
||||||
@ -214,22 +220,27 @@ public class FlatFilePermissionsResolver implements PermissionsResolver {
|
|||||||
return groups.toArray(new String[groups.size()]);
|
return groups.toArray(new String[groups.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(OfflinePlayer player, String permission) {
|
public boolean hasPermission(OfflinePlayer player, String permission) {
|
||||||
return hasPermission(player.getName(), permission);
|
return hasPermission(player.getName(), permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
||||||
return hasPermission(worldName, player.getName(), permission);
|
return hasPermission(worldName, player.getName(), permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean inGroup(OfflinePlayer player, String group) {
|
public boolean inGroup(OfflinePlayer player, String group) {
|
||||||
return inGroup(player.getName(), group);
|
return inGroup(player.getName(), group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getGroups(OfflinePlayer player) {
|
public String[] getGroups(OfflinePlayer player) {
|
||||||
return getGroups(player.getName());
|
return getGroups(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getDetectionMessage() {
|
public String getDetectionMessage() {
|
||||||
return "perms_groups.txt and perms_users.txt detected! Using flat file permissions.";
|
return "perms_groups.txt and perms_users.txt detected! Using flat file permissions.";
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ public class GroupManagerResolver implements PermissionsResolver {
|
|||||||
this.worldsHolder = worldsHolder;
|
this.worldsHolder = worldsHolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void load() {
|
public void load() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -73,10 +74,12 @@ public class GroupManagerResolver implements PermissionsResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String name, String permission) {
|
public boolean hasPermission(String name, String permission) {
|
||||||
return hasPermission(null, name, permission);
|
return hasPermission(null, name, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String worldName, String name, String permission) {
|
public boolean hasPermission(String worldName, String name, String permission) {
|
||||||
if (permission == null || permission.isEmpty()) {
|
if (permission == null || permission.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
@ -88,6 +91,7 @@ public class GroupManagerResolver implements PermissionsResolver {
|
|||||||
return permissionHandler.permission(name, permission);
|
return permissionHandler.permission(name, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean inGroup(String name, String group) {
|
public boolean inGroup(String name, String group) {
|
||||||
if (group == null || group.isEmpty()) {
|
if (group == null || group.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
@ -99,6 +103,7 @@ public class GroupManagerResolver implements PermissionsResolver {
|
|||||||
return permissionHandler.inGroup(name, group);
|
return permissionHandler.inGroup(name, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getGroups(String name) {
|
public String[] getGroups(String name) {
|
||||||
AnjoPermissionsHandler permissionHandler = getPermissionHandler(name, null);
|
AnjoPermissionsHandler permissionHandler = getPermissionHandler(name, null);
|
||||||
if (permissionHandler == null) {
|
if (permissionHandler == null) {
|
||||||
@ -107,22 +112,27 @@ public class GroupManagerResolver implements PermissionsResolver {
|
|||||||
return permissionHandler.getGroups(name);
|
return permissionHandler.getGroups(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(OfflinePlayer player, String permission) {
|
public boolean hasPermission(OfflinePlayer player, String permission) {
|
||||||
return hasPermission(player.getName(), permission);
|
return hasPermission(player.getName(), permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
||||||
return hasPermission(worldName, player.getName(), permission);
|
return hasPermission(worldName, player.getName(), permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean inGroup(OfflinePlayer player, String group) {
|
public boolean inGroup(OfflinePlayer player, String group) {
|
||||||
return inGroup(player.getName(), group);
|
return inGroup(player.getName(), group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getGroups(OfflinePlayer player) {
|
public String[] getGroups(OfflinePlayer player) {
|
||||||
return getGroups(player.getName());
|
return getGroups(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getDetectionMessage() {
|
public String getDetectionMessage() {
|
||||||
return "GroupManager detected! Using GroupManager for permissions.";
|
return "GroupManager detected! Using GroupManager for permissions.";
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,13 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import com.nijikokun.bukkit.Permissions.Permissions;
|
import com.nijikokun.bukkit.Permissions.Permissions;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class NijiPermissionsResolver implements PermissionsResolver {
|
public class NijiPermissionsResolver implements PermissionsResolver {
|
||||||
|
|
||||||
|
private static final Logger log = Logger.getLogger(NijiPermissionsResolver.class.getCanonicalName());
|
||||||
|
|
||||||
private Server server;
|
private Server server;
|
||||||
private Permissions api;
|
private Permissions api;
|
||||||
|
|
||||||
@ -56,6 +62,7 @@ public class NijiPermissionsResolver implements PermissionsResolver {
|
|||||||
return new NijiPermissionsResolver(server, (Permissions) plugin);
|
return new NijiPermissionsResolver(server, (Permissions) plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void load() {
|
public void load() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -65,6 +72,7 @@ public class NijiPermissionsResolver implements PermissionsResolver {
|
|||||||
this.api = plugin;
|
this.api = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@SuppressWarnings("static-access")
|
@SuppressWarnings("static-access")
|
||||||
public boolean hasPermission(String name, String permission) {
|
public boolean hasPermission(String name, String permission) {
|
||||||
try {
|
try {
|
||||||
@ -76,11 +84,12 @@ public class NijiPermissionsResolver implements PermissionsResolver {
|
|||||||
return api.Security.permission(player, permission);
|
return api.Security.permission(player, permission);
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
log.log(Level.WARNING, "Failed to check permissions", t);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String worldName, String name, String permission) {
|
public boolean hasPermission(String worldName, String name, String permission) {
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
@ -89,11 +98,12 @@ public class NijiPermissionsResolver implements PermissionsResolver {
|
|||||||
return api.getHandler().has(server.getPlayerExact(name), permission);
|
return api.getHandler().has(server.getPlayerExact(name), permission);
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
log.log(Level.WARNING, "Failed to check permissions", t);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@SuppressWarnings("static-access")
|
@SuppressWarnings("static-access")
|
||||||
public boolean inGroup(String name, String group) {
|
public boolean inGroup(String name, String group) {
|
||||||
try {
|
try {
|
||||||
@ -105,11 +115,12 @@ public class NijiPermissionsResolver implements PermissionsResolver {
|
|||||||
return api.Security.inGroup(name, group);
|
return api.Security.inGroup(name, group);
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
log.log(Level.WARNING, "Failed to check groups", t);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@SuppressWarnings("static-access")
|
@SuppressWarnings("static-access")
|
||||||
public String[] getGroups(String name) {
|
public String[] getGroups(String name) {
|
||||||
try {
|
try {
|
||||||
@ -128,23 +139,27 @@ public class NijiPermissionsResolver implements PermissionsResolver {
|
|||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
log.log(Level.WARNING, "Failed to get groups", t);
|
||||||
return new String[0];
|
return new String[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(OfflinePlayer player, String permission) {
|
public boolean hasPermission(OfflinePlayer player, String permission) {
|
||||||
return hasPermission(player.getName(), permission);
|
return hasPermission(player.getName(), permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
||||||
return hasPermission(worldName, player.getName(), permission);
|
return hasPermission(worldName, player.getName(), permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean inGroup(OfflinePlayer player, String group) {
|
public boolean inGroup(OfflinePlayer player, String group) {
|
||||||
return inGroup(player.getName(), group);
|
return inGroup(player.getName(), group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getGroups(OfflinePlayer player) {
|
public String[] getGroups(OfflinePlayer player) {
|
||||||
return getGroups(player.getName());
|
return getGroups(player.getName());
|
||||||
}
|
}
|
||||||
@ -155,7 +170,9 @@ public class NijiPermissionsResolver implements PermissionsResolver {
|
|||||||
return permsCommand == null || !(permsCommand.getPlugin().equals(plugin));
|
return permsCommand == null || !(permsCommand.getPlugin().equals(plugin));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getDetectionMessage() {
|
public String getDetectionMessage() {
|
||||||
return "Permissions plugin detected! Using Permissions plugin for permissions.";
|
return "Permissions plugin detected! Using Permissions plugin for permissions.";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -48,10 +48,12 @@ public class PermissionsExResolver extends DinnerPermsResolver {
|
|||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String worldName, String name, String permission) {
|
public boolean hasPermission(String worldName, String name, String permission) {
|
||||||
return manager.has(name, permission, worldName);
|
return manager.has(name, permission, worldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(OfflinePlayer player, String permission) {
|
public boolean hasPermission(OfflinePlayer player, String permission) {
|
||||||
Permissible permissible = getPermissible(player);
|
Permissible permissible = getPermissible(player);
|
||||||
if (permissible == null) {
|
if (permissible == null) {
|
||||||
@ -61,14 +63,17 @@ public class PermissionsExResolver extends DinnerPermsResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
||||||
return hasPermission(worldName, player.getName(), permission);
|
return hasPermission(worldName, player.getName(), permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean inGroup(OfflinePlayer player, String group) {
|
public boolean inGroup(OfflinePlayer player, String group) {
|
||||||
return super.inGroup(player, group) || manager.getUser(player.getName()).inGroup(group);
|
return super.inGroup(player, group) || manager.getUser(player.getName()).inGroup(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getGroups(OfflinePlayer player) {
|
public String[] getGroups(OfflinePlayer player) {
|
||||||
if (getPermissible(player) == null) {
|
if (getPermissible(player) == null) {
|
||||||
PermissionUser user = manager.getUser(player.getName());
|
PermissionUser user = manager.getUser(player.getName());
|
||||||
@ -81,6 +86,7 @@ public class PermissionsExResolver extends DinnerPermsResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getDetectionMessage() {
|
public String getDetectionMessage() {
|
||||||
return "PermissionsEx detected! Using PermissionsEx for permissions.";
|
return "PermissionsEx detected! Using PermissionsEx for permissions.";
|
||||||
}
|
}
|
||||||
|
@ -35,9 +35,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class PermissionsResolverManager implements PermissionsResolver {
|
public class PermissionsResolverManager implements PermissionsResolver {
|
||||||
|
|
||||||
private static final String CONFIG_HEADER = "#\r\n" +
|
private static final String CONFIG_HEADER = "#\r\n" +
|
||||||
"# WEPIF Configuration File\r\n" +
|
"# WEPIF Configuration File\r\n" +
|
||||||
"#\r\n" +
|
"#\r\n" +
|
||||||
@ -116,8 +118,7 @@ public class PermissionsResolverManager implements PermissionsResolver {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.warning("Error in factory method for " + resolverClass.getSimpleName() + ": " + e);
|
logger.log(Level.WARNING, "Error in factory method for " + resolverClass.getSimpleName(), e);
|
||||||
e.printStackTrace();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,42 +138,52 @@ public class PermissionsResolverManager implements PermissionsResolver {
|
|||||||
logger.info("WEPIF: " + permissionResolver.getDetectionMessage());
|
logger.info("WEPIF: " + permissionResolver.getDetectionMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void load() {
|
public void load() {
|
||||||
findResolver();
|
findResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String name, String permission) {
|
public boolean hasPermission(String name, String permission) {
|
||||||
return permissionResolver.hasPermission(name, permission);
|
return permissionResolver.hasPermission(name, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String worldName, String name, String permission) {
|
public boolean hasPermission(String worldName, String name, String permission) {
|
||||||
return permissionResolver.hasPermission(worldName, name, permission);
|
return permissionResolver.hasPermission(worldName, name, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean inGroup(String player, String group) {
|
public boolean inGroup(String player, String group) {
|
||||||
return permissionResolver.inGroup(player, group);
|
return permissionResolver.inGroup(player, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getGroups(String player) {
|
public String[] getGroups(String player) {
|
||||||
return permissionResolver.getGroups(player);
|
return permissionResolver.getGroups(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(OfflinePlayer player, String permission) {
|
public boolean hasPermission(OfflinePlayer player, String permission) {
|
||||||
return permissionResolver.hasPermission(player, permission);
|
return permissionResolver.hasPermission(player, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
||||||
return permissionResolver.hasPermission(worldName, player, permission);
|
return permissionResolver.hasPermission(worldName, player, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean inGroup(OfflinePlayer player, String group) {
|
public boolean inGroup(OfflinePlayer player, String group) {
|
||||||
return permissionResolver.inGroup(player, group);
|
return permissionResolver.inGroup(player, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getGroups(OfflinePlayer player) {
|
public String[] getGroups(OfflinePlayer player) {
|
||||||
return permissionResolver.getGroups(player);
|
return permissionResolver.getGroups(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getDetectionMessage() {
|
public String getDetectionMessage() {
|
||||||
return "Using WEPIF for permissions";
|
return "Using WEPIF for permissions";
|
||||||
}
|
}
|
||||||
@ -183,15 +194,14 @@ public class PermissionsResolverManager implements PermissionsResolver {
|
|||||||
try {
|
try {
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
logger.log(Level.WARNING, "Failed to create new configuration file", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
config = new YAMLProcessor(file, false, YAMLFormat.EXTENDED);
|
config = new YAMLProcessor(file, false, YAMLFormat.EXTENDED);
|
||||||
try {
|
try {
|
||||||
config.load();
|
config.load();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.severe("Error loading WEPIF Config: " + e);
|
logger.log(Level.WARNING, "Error loading WEPIF configuration", e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
List<String> keys = config.getKeys(null);
|
List<String> keys = config.getKeys(null);
|
||||||
config.setHeader(CONFIG_HEADER);
|
config.setHeader(CONFIG_HEADER);
|
||||||
@ -263,7 +273,6 @@ public class PermissionsResolverManager implements PermissionsResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class MissingPluginException extends Exception {
|
public static class MissingPluginException extends Exception {
|
||||||
private static final long serialVersionUID = 7044832912491608706L;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ServerListener implements org.bukkit.event.Listener {
|
class ServerListener implements org.bukkit.event.Listener {
|
||||||
|
@ -53,41 +53,51 @@ public class PluginPermissionsResolver implements PermissionsResolver {
|
|||||||
this.plugin = permissionsPlugin;
|
this.plugin = permissionsPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void load() {
|
public void load() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String name, String permission) {
|
public boolean hasPermission(String name, String permission) {
|
||||||
return resolver.hasPermission(name, permission);
|
return resolver.hasPermission(name, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String worldName, String name, String permission) {
|
public boolean hasPermission(String worldName, String name, String permission) {
|
||||||
return resolver.hasPermission(worldName, name, permission);
|
return resolver.hasPermission(worldName, name, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean inGroup(String player, String group) {
|
public boolean inGroup(String player, String group) {
|
||||||
return resolver.inGroup(player, group);
|
return resolver.inGroup(player, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getGroups(String player) {
|
public String[] getGroups(String player) {
|
||||||
return resolver.getGroups(player);
|
return resolver.getGroups(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(OfflinePlayer player, String permission) {
|
public boolean hasPermission(OfflinePlayer player, String permission) {
|
||||||
return resolver.hasPermission(player, permission);
|
return resolver.hasPermission(player, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
||||||
return resolver.hasPermission(worldName, player, permission);
|
return resolver.hasPermission(worldName, player, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean inGroup(OfflinePlayer player, String group) {
|
public boolean inGroup(OfflinePlayer player, String group) {
|
||||||
return resolver.inGroup(player, group);
|
return resolver.inGroup(player, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getGroups(OfflinePlayer player) {
|
public String[] getGroups(OfflinePlayer player) {
|
||||||
return resolver.getGroups(player);
|
return resolver.getGroups(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getDetectionMessage() {
|
public String getDetectionMessage() {
|
||||||
return "Using plugin '" + this.plugin.getDescription().getName() + "' for permissions.";
|
return "Using plugin '" + this.plugin.getDescription().getName() + "' for permissions.";
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,10 @@
|
|||||||
|
|
||||||
package com.sk89q.wepif;
|
package com.sk89q.wepif;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author zml2008
|
|
||||||
*/
|
|
||||||
public class WEPIFRuntimeException extends RuntimeException {
|
public class WEPIFRuntimeException extends RuntimeException {
|
||||||
private static final long serialVersionUID = 5092745960439109699L;
|
|
||||||
|
|
||||||
public WEPIFRuntimeException(String message) {
|
public WEPIFRuntimeException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,6 @@ import org.bukkit.OfflinePlayer;
|
|||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author zml2008
|
|
||||||
*/
|
|
||||||
public class bPermissionsResolver implements PermissionsResolver {
|
public class bPermissionsResolver implements PermissionsResolver {
|
||||||
|
|
||||||
public static PermissionsResolver factory(Server server, YAMLProcessor config) {
|
public static PermissionsResolver factory(Server server, YAMLProcessor config) {
|
||||||
@ -47,29 +44,36 @@ public class bPermissionsResolver implements PermissionsResolver {
|
|||||||
this.server = server;
|
this.server = server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void load() {
|
public void load() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getDetectionMessage() {
|
public String getDetectionMessage() {
|
||||||
return "bPermissions detected! Using bPermissions for permissions";
|
return "bPermissions detected! Using bPermissions for permissions";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String name, String permission) {
|
public boolean hasPermission(String name, String permission) {
|
||||||
return hasPermission(server.getOfflinePlayer(name), permission);
|
return hasPermission(server.getOfflinePlayer(name), permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String worldName, String name, String permission) {
|
public boolean hasPermission(String worldName, String name, String permission) {
|
||||||
return ApiLayer.hasPermission(worldName, CalculableType.USER, name, permission);
|
return ApiLayer.hasPermission(worldName, CalculableType.USER, name, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean inGroup(String player, String group) {
|
public boolean inGroup(String player, String group) {
|
||||||
return inGroup(server.getOfflinePlayer(player), group);
|
return inGroup(server.getOfflinePlayer(player), group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getGroups(String player) {
|
public String[] getGroups(String player) {
|
||||||
return getGroups(server.getOfflinePlayer(player));
|
return getGroups(server.getOfflinePlayer(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(OfflinePlayer player, String permission) {
|
public boolean hasPermission(OfflinePlayer player, String permission) {
|
||||||
Player onlinePlayer = player.getPlayer();
|
Player onlinePlayer = player.getPlayer();
|
||||||
if (onlinePlayer == null) {
|
if (onlinePlayer == null) {
|
||||||
@ -79,10 +83,12 @@ public class bPermissionsResolver implements PermissionsResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
public boolean hasPermission(String worldName, OfflinePlayer player, String permission) {
|
||||||
return hasPermission(worldName, player.getName(), permission);
|
return hasPermission(worldName, player.getName(), permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean inGroup(OfflinePlayer player, String group) {
|
public boolean inGroup(OfflinePlayer player, String group) {
|
||||||
Player onlinePlayer = player.getPlayer();
|
Player onlinePlayer = player.getPlayer();
|
||||||
if (onlinePlayer == null) {
|
if (onlinePlayer == null) {
|
||||||
@ -92,6 +98,7 @@ public class bPermissionsResolver implements PermissionsResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String[] getGroups(OfflinePlayer player) {
|
public String[] getGroups(OfflinePlayer player) {
|
||||||
Player onlinePlayer = player.getPlayer();
|
Player onlinePlayer = player.getPlayer();
|
||||||
if (onlinePlayer == null) {
|
if (onlinePlayer == null) {
|
||||||
@ -100,4 +107,5 @@ public class bPermissionsResolver implements PermissionsResolver {
|
|||||||
return ApiLayer.getGroups(onlinePlayer.getWorld().getName(), CalculableType.USER, player.getName());
|
return ApiLayer.getGroups(onlinePlayer.getWorld().getName(), CalculableType.USER, player.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,19 +29,14 @@ import com.sk89q.worldedit.blocks.BlockID;
|
|||||||
import com.sk89q.worldedit.blocks.ItemType;
|
import com.sk89q.worldedit.blocks.ItemType;
|
||||||
|
|
||||||
public class BukkitPlayerBlockBag extends BlockBag {
|
public class BukkitPlayerBlockBag extends BlockBag {
|
||||||
/**
|
|
||||||
* Player instance.
|
|
||||||
*/
|
|
||||||
private Player player;
|
private Player player;
|
||||||
/**
|
|
||||||
* The player's inventory;
|
|
||||||
*/
|
|
||||||
private ItemStack[] items;
|
private ItemStack[] items;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the object.
|
* Construct the object.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player the player
|
||||||
*/
|
*/
|
||||||
public BukkitPlayerBlockBag(Player player) {
|
public BukkitPlayerBlockBag(Player player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
@ -59,17 +54,12 @@ public class BukkitPlayerBlockBag extends BlockBag {
|
|||||||
/**
|
/**
|
||||||
* Get the player.
|
* Get the player.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the player
|
||||||
*/
|
*/
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a block.
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void fetchItem(BaseItem item) throws BlockBagException {
|
public void fetchItem(BaseItem item) throws BlockBagException {
|
||||||
final int id = item.getType();
|
final int id = item.getType();
|
||||||
@ -125,11 +115,6 @@ public class BukkitPlayerBlockBag extends BlockBag {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Store a block.
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void storeItem(BaseItem item) throws BlockBagException {
|
public void storeItem(BaseItem item) throws BlockBagException {
|
||||||
final int id = item.getType();
|
final int id = item.getType();
|
||||||
@ -197,9 +182,6 @@ public class BukkitPlayerBlockBag extends BlockBag {
|
|||||||
throw new OutOfSpaceException(id);
|
throw new OutOfSpaceException(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Flush any changes. This is called at the end.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void flushChanges() {
|
public void flushChanges() {
|
||||||
if (items != null) {
|
if (items != null) {
|
||||||
@ -208,21 +190,12 @@ public class BukkitPlayerBlockBag extends BlockBag {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a position to be used a source.
|
|
||||||
*
|
|
||||||
* @param pos
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void addSourcePosition(WorldVector pos) {
|
public void addSourcePosition(WorldVector pos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a position to be used a source.
|
|
||||||
*
|
|
||||||
* @param pos
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void addSingleSourcePosition(WorldVector pos) {
|
public void addSingleSourcePosition(WorldVector pos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,10 @@ import org.bukkit.plugin.messaging.PluginMessageListener;
|
|||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles incoming WorldEditCui init message
|
* Handles incoming WorldEditCui init message.
|
||||||
* @author zml2008
|
|
||||||
*/
|
*/
|
||||||
public class CUIChannelListener implements PluginMessageListener {
|
public class CUIChannelListener implements PluginMessageListener {
|
||||||
|
|
||||||
public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
|
public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
|
||||||
private final WorldEditPlugin plugin;
|
private final WorldEditPlugin plugin;
|
||||||
|
|
||||||
@ -44,4 +44,5 @@ public class CUIChannelListener implements PluginMessageListener {
|
|||||||
session.handleCUIInitializationMessage(text);
|
session.handleCUIInitializationMessage(text);
|
||||||
session.describeCUI(plugin.wrapPlayer(player));
|
session.describeCUI(plugin.wrapPlayer(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,16 +28,16 @@ import com.sk89q.worldedit.blocks.BaseBlock;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Proxy class to catch calls to set blocks.
|
* Proxy class to catch calls to set blocks.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
|
public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
|
||||||
|
|
||||||
private EditSession editSession;
|
private EditSession editSession;
|
||||||
|
|
||||||
public EditSessionBlockChangeDelegate(EditSession editSession) {
|
public EditSessionBlockChangeDelegate(EditSession editSession) {
|
||||||
this.editSession = editSession;
|
this.editSession = editSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean setRawTypeId(int x, int y, int z, int typeId) {
|
public boolean setRawTypeId(int x, int y, int z, int typeId) {
|
||||||
try {
|
try {
|
||||||
return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId));
|
return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId));
|
||||||
@ -46,6 +46,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean setRawTypeIdAndData(int x, int y, int z, int typeId, int data) {
|
public boolean setRawTypeIdAndData(int x, int y, int z, int typeId, int data) {
|
||||||
try {
|
try {
|
||||||
return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId, data));
|
return editSession.setBlock(new Vector(x, y, z), new BaseBlock(typeId, data));
|
||||||
@ -54,23 +55,29 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean setTypeId(int x, int y, int z, int typeId) {
|
public boolean setTypeId(int x, int y, int z, int typeId) {
|
||||||
return setRawTypeId(x, y, z, typeId);
|
return setRawTypeId(x, y, z, typeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean setTypeIdAndData(int x, int y, int z, int typeId, int data) {
|
public boolean setTypeIdAndData(int x, int y, int z, int typeId, int data) {
|
||||||
return setRawTypeIdAndData(x, y, z, typeId, data);
|
return setRawTypeIdAndData(x, y, z, typeId, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getTypeId(int x, int y, int z) {
|
public int getTypeId(int x, int y, int z) {
|
||||||
return editSession.getBlockType(new Vector(x, y, z));
|
return editSession.getBlockType(new Vector(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getHeight() {
|
public int getHeight() {
|
||||||
return editSession.getWorld().getMaxY() + 1;
|
return editSession.getWorld().getMaxY() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isEmpty(int x, int y, int z) {
|
public boolean isEmpty(int x, int y, int z) {
|
||||||
return editSession.getBlockType(new Vector(x, y, z)) == BlockID.AIR;
|
return editSession.getBlockType(new Vector(x, y, z)) == BlockID.AIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,12 @@ package com.sk89q.worldedit.bukkit;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import com.sk89q.worldedit.LocalSession;
|
import com.sk89q.worldedit.LocalSession;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use the regular API
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public class WorldEditAPI {
|
public class WorldEditAPI {
|
||||||
|
|
||||||
private WorldEditPlugin plugin;
|
private WorldEditPlugin plugin;
|
||||||
|
|
||||||
public WorldEditAPI(WorldEditPlugin plugin) {
|
public WorldEditAPI(WorldEditPlugin plugin) {
|
||||||
@ -32,11 +37,12 @@ public class WorldEditAPI {
|
|||||||
/**
|
/**
|
||||||
* Get the session for a player.
|
* Get the session for a player.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player the player
|
||||||
* @return
|
* @return a session
|
||||||
*/
|
*/
|
||||||
public LocalSession getSession(Player player) {
|
public LocalSession getSession(Player player) {
|
||||||
return plugin.getWorldEdit().getSession(
|
return plugin.getWorldEdit().getSession(
|
||||||
new BukkitPlayer(plugin, plugin.getServerInterface(), player));
|
new BukkitPlayer(plugin, plugin.getServerInterface(), player));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ public class WorldEditListener implements Listener {
|
|||||||
/**
|
/**
|
||||||
* Construct the object;
|
* Construct the object;
|
||||||
*
|
*
|
||||||
* @param plugin
|
* @param plugin the plugin
|
||||||
*/
|
*/
|
||||||
public WorldEditListener(WorldEditPlugin plugin) {
|
public WorldEditListener(WorldEditPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -67,7 +67,7 @@ public class WorldEditListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this will automatically refresh their sesssion, we don't have to do anything
|
// this will automatically refresh their session, we don't have to do anything
|
||||||
WorldEdit.getInstance().getSession(plugin.wrapPlayer(event.getPlayer()));
|
WorldEdit.getInstance().getSession(plugin.wrapPlayer(event.getPlayer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,9 +71,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin for Bukkit.
|
* Plugin for Bukkit.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
||||||
|
|
||||||
private static final Logger log = Logger.getLogger(WorldEditPlugin.class.getCanonicalName());
|
private static final Logger log = Logger.getLogger(WorldEditPlugin.class.getCanonicalName());
|
||||||
@ -88,10 +87,12 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
/**
|
/**
|
||||||
* Called on plugin enable.
|
* Called on plugin enable.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("AccessStaticViaInstance")
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
this.INSTANCE = this;
|
this.INSTANCE = this;
|
||||||
|
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
getDataFolder().mkdirs();
|
getDataFolder().mkdirs();
|
||||||
|
|
||||||
WorldEdit worldEdit = WorldEdit.getInstance();
|
WorldEdit worldEdit = WorldEdit.getInstance();
|
||||||
@ -191,8 +192,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
protected void createDefaultConfiguration(String name) {
|
protected void createDefaultConfiguration(String name) {
|
||||||
File actual = new File(getDataFolder(), name);
|
File actual = new File(getDataFolder(), name);
|
||||||
if (!actual.exists()) {
|
if (!actual.exists()) {
|
||||||
InputStream input =
|
InputStream input = null;
|
||||||
null;
|
|
||||||
try {
|
try {
|
||||||
JarFile file = new JarFile(getFile());
|
JarFile file = new JarFile(getFile());
|
||||||
ZipEntry copy = file.getEntry("defaults/" + name);
|
ZipEntry copy = file.getEntry("defaults/" + name);
|
||||||
@ -207,26 +207,24 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
try {
|
try {
|
||||||
output = new FileOutputStream(actual);
|
output = new FileOutputStream(actual);
|
||||||
byte[] buf = new byte[8192];
|
byte[] buf = new byte[8192];
|
||||||
int length = 0;
|
int length;
|
||||||
while ((length = input.read(buf)) > 0) {
|
while ((length = input.read(buf)) > 0) {
|
||||||
output.write(buf, 0, length);
|
output.write(buf, 0, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogger().info("Default configuration file written: " + name);
|
getLogger().info("Default configuration file written: " + name);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
getLogger().log(Level.WARNING, "Failed to write default config file", e);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (input != null) {
|
|
||||||
input.close();
|
input.close();
|
||||||
}
|
} catch (IOException ignored) {}
|
||||||
} catch (IOException e) {}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (output != null) {
|
if (output != null) {
|
||||||
output.close();
|
output.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {}
|
} catch (IOException ignored) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -262,8 +260,8 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
/**
|
/**
|
||||||
* Gets the session for the player.
|
* Gets the session for the player.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player a player
|
||||||
* @return
|
* @return a session
|
||||||
*/
|
*/
|
||||||
public LocalSession getSession(Player player) {
|
public LocalSession getSession(Player player) {
|
||||||
return WorldEdit.getInstance().getSession(wrapPlayer(player));
|
return WorldEdit.getInstance().getSession(wrapPlayer(player));
|
||||||
@ -272,8 +270,8 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
/**
|
/**
|
||||||
* Gets the session for the player.
|
* Gets the session for the player.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player a player
|
||||||
* @return
|
* @return a session
|
||||||
*/
|
*/
|
||||||
public EditSession createEditSession(Player player) {
|
public EditSession createEditSession(Player player) {
|
||||||
LocalPlayer wePlayer = wrapPlayer(player);
|
LocalPlayer wePlayer = wrapPlayer(player);
|
||||||
@ -290,8 +288,8 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
/**
|
/**
|
||||||
* Remember an edit session.
|
* Remember an edit session.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player a player
|
||||||
* @param editSession
|
* @param editSession an edit session
|
||||||
*/
|
*/
|
||||||
public void remember(Player player, EditSession editSession) {
|
public void remember(Player player, EditSession editSession) {
|
||||||
LocalPlayer wePlayer = wrapPlayer(player);
|
LocalPlayer wePlayer = wrapPlayer(player);
|
||||||
@ -306,10 +304,12 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
/**
|
/**
|
||||||
* Wrap an operation into an EditSession.
|
* Wrap an operation into an EditSession.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player a player
|
||||||
* @param op
|
* @param op the operation
|
||||||
* @throws Throwable
|
* @throws Throwable on any error
|
||||||
|
* @deprecated use the regular API
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public void perform(Player player, WorldEditOperation op) throws Throwable {
|
public void perform(Player player, WorldEditOperation op) throws Throwable {
|
||||||
LocalPlayer wePlayer = wrapPlayer(player);
|
LocalPlayer wePlayer = wrapPlayer(player);
|
||||||
LocalSession session = WorldEdit.getInstance().getSession(wePlayer);
|
LocalSession session = WorldEdit.getInstance().getSession(wePlayer);
|
||||||
@ -325,7 +325,8 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
/**
|
/**
|
||||||
* Get the API.
|
* Get the API.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the API
|
||||||
|
* @deprecated use the regular API
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public WorldEditAPI getAPI() {
|
public WorldEditAPI getAPI() {
|
||||||
@ -335,7 +336,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
/**
|
/**
|
||||||
* Returns the configuration used by WorldEdit.
|
* Returns the configuration used by WorldEdit.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the configuration
|
||||||
*/
|
*/
|
||||||
public BukkitConfiguration getLocalConfiguration() {
|
public BukkitConfiguration getLocalConfiguration() {
|
||||||
return config;
|
return config;
|
||||||
@ -344,7 +345,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
/**
|
/**
|
||||||
* Get the permissions resolver in use.
|
* Get the permissions resolver in use.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the permissions resolver
|
||||||
*/
|
*/
|
||||||
public PermissionsResolverManager getPermissionsResolver() {
|
public PermissionsResolverManager getPermissionsResolver() {
|
||||||
return PermissionsResolverManager.getInstance();
|
return PermissionsResolverManager.getInstance();
|
||||||
@ -353,8 +354,8 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
/**
|
/**
|
||||||
* Used to wrap a Bukkit Player as a LocalPlayer.
|
* Used to wrap a Bukkit Player as a LocalPlayer.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player a player
|
||||||
* @return
|
* @return a wrapped player
|
||||||
*/
|
*/
|
||||||
public BukkitPlayer wrapPlayer(Player player) {
|
public BukkitPlayer wrapPlayer(Player player) {
|
||||||
return new BukkitPlayer(this, this.server, player);
|
return new BukkitPlayer(this, this.server, player);
|
||||||
@ -371,7 +372,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
/**
|
/**
|
||||||
* Get the server interface.
|
* Get the server interface.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the server interface
|
||||||
*/
|
*/
|
||||||
public ServerInterface getServerInterface() {
|
public ServerInterface getServerInterface() {
|
||||||
return server;
|
return server;
|
||||||
@ -384,7 +385,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
/**
|
/**
|
||||||
* Get WorldEdit.
|
* Get WorldEdit.
|
||||||
*
|
*
|
||||||
* @return
|
* @return an instance
|
||||||
*/
|
*/
|
||||||
public WorldEdit getWorldEdit() {
|
public WorldEdit getWorldEdit() {
|
||||||
return WorldEdit.getInstance();
|
return WorldEdit.getInstance();
|
||||||
@ -393,7 +394,7 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
/**
|
/**
|
||||||
* Gets the region selection for the player.
|
* Gets the region selection for the player.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player aplayer
|
||||||
* @return the selection or null if there was none
|
* @return the selection or null if there was none
|
||||||
*/
|
*/
|
||||||
public Selection getSelection(Player player) {
|
public Selection getSelection(Player player) {
|
||||||
@ -428,8 +429,8 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter {
|
|||||||
/**
|
/**
|
||||||
* Sets the region selection for a player.
|
* Sets the region selection for a player.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player the player
|
||||||
* @param selection
|
* @param selection a selection
|
||||||
*/
|
*/
|
||||||
public void setSelection(Player player, Selection selection) {
|
public void setSelection(Player player, Selection selection) {
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
|
@ -26,10 +26,8 @@ import org.bukkit.entity.EntityType;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author zml2008
|
|
||||||
*/
|
|
||||||
public class BukkitEntity extends LocalEntity {
|
public class BukkitEntity extends LocalEntity {
|
||||||
|
|
||||||
private final EntityType type;
|
private final EntityType type;
|
||||||
private final UUID entityId;
|
private final UUID entityId;
|
||||||
|
|
||||||
@ -48,4 +46,5 @@ public class BukkitEntity extends LocalEntity {
|
|||||||
org.bukkit.Location loc = BukkitUtil.toLocation(weLoc);
|
org.bukkit.Location loc = BukkitUtil.toLocation(weLoc);
|
||||||
return loc.getWorld().spawn(loc, type.getEntityClass()) != null;
|
return loc.getWorld().spawn(loc, type.getEntityClass()) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,8 @@ import org.bukkit.entity.ExperienceOrb;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author zml2008
|
|
||||||
*/
|
|
||||||
public class BukkitExpOrb extends BukkitEntity {
|
public class BukkitExpOrb extends BukkitEntity {
|
||||||
|
|
||||||
private final int amount;
|
private final int amount;
|
||||||
|
|
||||||
public BukkitExpOrb(Location loc, UUID entityId, int amount) {
|
public BukkitExpOrb(Location loc, UUID entityId, int amount) {
|
||||||
@ -47,4 +45,5 @@ public class BukkitExpOrb extends BukkitEntity {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,8 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author zml2008
|
|
||||||
*/
|
|
||||||
public class BukkitItem extends BukkitEntity {
|
public class BukkitItem extends BukkitEntity {
|
||||||
|
|
||||||
private final ItemStack stack;
|
private final ItemStack stack;
|
||||||
public BukkitItem(Location loc, ItemStack stack, UUID entityId) {
|
public BukkitItem(Location loc, ItemStack stack, UUID entityId) {
|
||||||
super(loc, EntityType.DROPPED_ITEM, entityId);
|
super(loc, EntityType.DROPPED_ITEM, entityId);
|
||||||
@ -41,4 +39,5 @@ public class BukkitItem extends BukkitEntity {
|
|||||||
org.bukkit.Location loc = BukkitUtil.toLocation(weLoc);
|
org.bukkit.Location loc = BukkitUtil.toLocation(weLoc);
|
||||||
return loc.getWorld().dropItem(loc, stack) != null;
|
return loc.getWorld().dropItem(loc, stack) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,18 +30,20 @@ import org.bukkit.entity.Painting;
|
|||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author zml2008
|
|
||||||
*/
|
|
||||||
public class BukkitPainting extends BukkitEntity {
|
public class BukkitPainting extends BukkitEntity {
|
||||||
|
|
||||||
|
private static final Logger log = Logger.getLogger(BukkitPainting.class.getCanonicalName());
|
||||||
|
|
||||||
private static int spawnTask = -1;
|
private static int spawnTask = -1;
|
||||||
private static final Deque<QueuedPaintingSpawn> spawnQueue = new ArrayDeque<QueuedPaintingSpawn>();
|
private static final Deque<QueuedPaintingSpawn> spawnQueue = new ArrayDeque<QueuedPaintingSpawn>();
|
||||||
|
|
||||||
private class QueuedPaintingSpawn {
|
private class QueuedPaintingSpawn {
|
||||||
private final Location weLoc;
|
private final Location weLoc;
|
||||||
|
|
||||||
public QueuedPaintingSpawn(Location weLoc) {
|
private QueuedPaintingSpawn(Location weLoc) {
|
||||||
this.weLoc = weLoc;
|
this.weLoc = weLoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +51,7 @@ public class BukkitPainting extends BukkitEntity {
|
|||||||
spawnRaw(weLoc);
|
spawnRaw(weLoc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class PaintingSpawnRunnable implements Runnable {
|
private static class PaintingSpawnRunnable implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -58,7 +61,7 @@ public class BukkitPainting extends BukkitEntity {
|
|||||||
try {
|
try {
|
||||||
spawn.spawn();
|
spawn.spawn();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
log.log(Level.WARNING, "Failed to spawn painting", t);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,6 +85,7 @@ public class BukkitPainting extends BukkitEntity {
|
|||||||
* @param weLoc The WorldEdit location
|
* @param weLoc The WorldEdit location
|
||||||
* @return Whether the spawn as successful
|
* @return Whether the spawn as successful
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public boolean spawn(Location weLoc) {
|
public boolean spawn(Location weLoc) {
|
||||||
synchronized (spawnQueue) {
|
synchronized (spawnQueue) {
|
||||||
spawnQueue.add(new QueuedPaintingSpawn(weLoc));
|
spawnQueue.add(new QueuedPaintingSpawn(weLoc));
|
||||||
@ -102,4 +106,5 @@ public class BukkitPainting extends BukkitEntity {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ import java.util.List;
|
|||||||
|
|
||||||
import com.sk89q.worldedit.LocalWorld;
|
import com.sk89q.worldedit.LocalWorld;
|
||||||
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
|
import com.sk89q.worldedit.regions.selector.Polygonal2DRegionSelector;
|
||||||
import com.sk89q.worldedit.regions.RegionSelector;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import com.sk89q.worldedit.BlockVector2D;
|
import com.sk89q.worldedit.BlockVector2D;
|
||||||
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
||||||
|
@ -52,6 +52,7 @@ public abstract class RegionSelection implements Selection {
|
|||||||
this.region = region;
|
this.region = region;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public RegionSelector getRegionSelector() {
|
public RegionSelector getRegionSelector() {
|
||||||
return selector;
|
return selector;
|
||||||
}
|
}
|
||||||
@ -60,48 +61,58 @@ public abstract class RegionSelection implements Selection {
|
|||||||
this.selector = selector;
|
this.selector = selector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Location getMinimumPoint() {
|
public Location getMinimumPoint() {
|
||||||
return toLocation(world, region.getMinimumPoint());
|
return toLocation(world, region.getMinimumPoint());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Vector getNativeMinimumPoint() {
|
public Vector getNativeMinimumPoint() {
|
||||||
return region.getMinimumPoint();
|
return region.getMinimumPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Location getMaximumPoint() {
|
public Location getMaximumPoint() {
|
||||||
return toLocation(world, region.getMaximumPoint());
|
return toLocation(world, region.getMaximumPoint());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Vector getNativeMaximumPoint() {
|
public Vector getNativeMaximumPoint() {
|
||||||
return region.getMaximumPoint();
|
return region.getMaximumPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getArea() {
|
public int getArea() {
|
||||||
return region.getArea();
|
return region.getArea();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
return region.getWidth();
|
return region.getWidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getHeight() {
|
public int getHeight() {
|
||||||
return region.getHeight();
|
return region.getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getLength() {
|
public int getLength() {
|
||||||
return region.getLength();
|
return region.getLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(Location pt) {
|
@Override
|
||||||
if (!pt.getWorld().equals(world)) {
|
public boolean contains(Location position) {
|
||||||
|
if (!position.getWorld().equals(world)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return region.contains(toVector(pt));
|
return region.contains(toVector(position));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,13 @@ import org.bukkit.World;
|
|||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldedit.regions.RegionSelector;
|
import com.sk89q.worldedit.regions.RegionSelector;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An abstraction of WorldEdit regions, which do not use Bukkit objects.
|
||||||
|
*/
|
||||||
public interface Selection {
|
public interface Selection {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the lower point of a region.
|
* Get the lower point of a region.
|
||||||
*
|
*
|
||||||
@ -56,15 +62,16 @@ public interface Selection {
|
|||||||
/**
|
/**
|
||||||
* Get the region selector. This is for internal use.
|
* Get the region selector. This is for internal use.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the region selector
|
||||||
*/
|
*/
|
||||||
public RegionSelector getRegionSelector();
|
public RegionSelector getRegionSelector();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the world.
|
* Get the world.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the world, which may be null
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public World getWorld();
|
public World getWorld();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -98,8 +105,9 @@ public interface Selection {
|
|||||||
/**
|
/**
|
||||||
* Returns true based on whether the region contains the point,
|
* Returns true based on whether the region contains the point,
|
||||||
*
|
*
|
||||||
* @param pt
|
* @param position a vector
|
||||||
* @return
|
* @return true if it is contained
|
||||||
*/
|
*/
|
||||||
public boolean contains(Location pt);
|
public boolean contains(Location position);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,14 +19,12 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.forge;
|
package com.sk89q.worldedit.forge;
|
||||||
|
|
||||||
import java.util.Map;
|
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||||
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
import java.util.Map;
|
||||||
|
|
||||||
import cpw.mods.fml.common.FMLCommonHandler;
|
|
||||||
|
|
||||||
public final class ForgeUtil {
|
public final class ForgeUtil {
|
||||||
|
|
||||||
@ -41,7 +39,7 @@ public final class ForgeUtil {
|
|||||||
public static ItemStack toForgeItemStack(BaseItemStack item) {
|
public static ItemStack toForgeItemStack(BaseItemStack item) {
|
||||||
ItemStack ret = new ItemStack(item.getType(), item.getAmount(), item.getData());
|
ItemStack ret = new ItemStack(item.getType(), item.getAmount(), item.getData());
|
||||||
for (Map.Entry<Integer, Integer> entry : item.getEnchantments().entrySet()) {
|
for (Map.Entry<Integer, Integer> entry : item.getEnchantments().entrySet()) {
|
||||||
ret.addEnchantment(net.minecraft.enchantment.Enchantment.enchantmentsList[((Integer)entry.getKey()).intValue()], ((Integer)entry.getValue()).intValue());
|
ret.addEnchantment(net.minecraft.enchantment.Enchantment.enchantmentsList[((Integer) entry.getKey())], (Integer) entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -33,7 +33,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||||||
/**
|
/**
|
||||||
* Utility methods for setting tile entities in the world.
|
* Utility methods for setting tile entities in the world.
|
||||||
*/
|
*/
|
||||||
class TileEntityUtils {
|
final class TileEntityUtils {
|
||||||
|
|
||||||
private TileEntityUtils() {
|
private TileEntityUtils() {
|
||||||
}
|
}
|
||||||
@ -110,7 +110,8 @@ class TileEntityUtils {
|
|||||||
* @param clazz the class
|
* @param clazz the class
|
||||||
* @return a tile entity (may be null if it failed)
|
* @return a tile entity (may be null if it failed)
|
||||||
*/
|
*/
|
||||||
static @Nullable TileEntity constructTileEntity(World world, Vector position, Class<? extends TileEntity> clazz) {
|
@Nullable
|
||||||
|
static TileEntity constructTileEntity(World world, Vector position, Class<? extends TileEntity> clazz) {
|
||||||
Constructor<? extends TileEntity> baseConstructor;
|
Constructor<? extends TileEntity> baseConstructor;
|
||||||
try {
|
try {
|
||||||
baseConstructor = clazz.getConstructor(); // creates "blank" TE
|
baseConstructor = clazz.getConstructor(); // creates "blank" TE
|
||||||
|
@ -33,6 +33,7 @@ import cpw.mods.fml.common.network.Player;
|
|||||||
public class WECUIPacketHandler implements IPacketHandler {
|
public class WECUIPacketHandler implements IPacketHandler {
|
||||||
public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
|
public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
|
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
|
||||||
if (player instanceof EntityPlayerMP) {
|
if (player instanceof EntityPlayerMP) {
|
||||||
LocalSession session = ForgeWorldEdit.inst.getSession((EntityPlayerMP) player);
|
LocalSession session = ForgeWorldEdit.inst.getSession((EntityPlayerMP) player);
|
||||||
|
@ -25,13 +25,16 @@ import com.sk89q.worldedit.blocks.*;
|
|||||||
/**
|
/**
|
||||||
* @deprecated Block bags are currently not a supported feature of WorldEdit
|
* @deprecated Block bags are currently not a supported feature of WorldEdit
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
|
||||||
public abstract class BlockBag {
|
public abstract class BlockBag {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores a block as if it was mined.
|
* Stores a block as if it was mined.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id the ID of the block
|
||||||
* @throws BlockBagException
|
* @throws BlockBagException thrown on a error
|
||||||
* @deprecated Use {@link BlockBag#storeDroppedBlock(int, int)} instead
|
* @deprecated Use {@link BlockBag#storeDroppedBlock(int, int)} instead
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@ -42,9 +45,9 @@ public abstract class BlockBag {
|
|||||||
/**
|
/**
|
||||||
* Stores a block as if it was mined.
|
* Stores a block as if it was mined.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id the ID of the block
|
||||||
* @param data
|
* @param data the data value of the block
|
||||||
* @throws BlockBagException
|
* @throws BlockBagException thrown on a error
|
||||||
*/
|
*/
|
||||||
public void storeDroppedBlock(int id, int data) throws BlockBagException {
|
public void storeDroppedBlock(int id, int data) throws BlockBagException {
|
||||||
BaseItem dropped = BlockType.getBlockBagItem(id, data);
|
BaseItem dropped = BlockType.getBlockBagItem(id, data);
|
||||||
@ -57,7 +60,7 @@ public abstract class BlockBag {
|
|||||||
/**
|
/**
|
||||||
* Sets a block as if it was placed by hand.
|
* Sets a block as if it was placed by hand.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id the ID of the block
|
||||||
* @throws BlockBagException
|
* @throws BlockBagException
|
||||||
* @deprecated Use {@link #fetchPlacedBlock(int,int)} instead
|
* @deprecated Use {@link #fetchPlacedBlock(int,int)} instead
|
||||||
*/
|
*/
|
||||||
@ -69,8 +72,8 @@ public abstract class BlockBag {
|
|||||||
/**
|
/**
|
||||||
* Sets a block as if it was placed by hand.
|
* Sets a block as if it was placed by hand.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id the ID of the block
|
||||||
* @param data TODO
|
* @param data the data value of the block
|
||||||
* @throws BlockBagException
|
* @throws BlockBagException
|
||||||
*/
|
*/
|
||||||
public void fetchPlacedBlock(int id, int data) throws BlockBagException {
|
public void fetchPlacedBlock(int id, int data) throws BlockBagException {
|
||||||
@ -118,7 +121,7 @@ public abstract class BlockBag {
|
|||||||
*
|
*
|
||||||
* Either this method or fetchItem needs to be overridden
|
* Either this method or fetchItem needs to be overridden
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id the ID of the block
|
||||||
* @throws BlockBagException
|
* @throws BlockBagException
|
||||||
*/
|
*/
|
||||||
public void fetchBlock(int id) throws BlockBagException {
|
public void fetchBlock(int id) throws BlockBagException {
|
||||||
@ -130,7 +133,7 @@ public abstract class BlockBag {
|
|||||||
*
|
*
|
||||||
* Either this method or fetchBlock needs to be overridden
|
* Either this method or fetchBlock needs to be overridden
|
||||||
*
|
*
|
||||||
* @param item
|
* @param item the item
|
||||||
* @throws BlockBagException
|
* @throws BlockBagException
|
||||||
*/
|
*/
|
||||||
public void fetchItem(BaseItem item) throws BlockBagException {
|
public void fetchItem(BaseItem item) throws BlockBagException {
|
||||||
@ -142,7 +145,7 @@ public abstract class BlockBag {
|
|||||||
*
|
*
|
||||||
* Either this method or storeItem needs to be overridden
|
* Either this method or storeItem needs to be overridden
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id the ID of the block
|
||||||
* @throws BlockBagException
|
* @throws BlockBagException
|
||||||
*/
|
*/
|
||||||
public void storeBlock(int id) throws BlockBagException {
|
public void storeBlock(int id) throws BlockBagException {
|
||||||
@ -154,7 +157,7 @@ public abstract class BlockBag {
|
|||||||
*
|
*
|
||||||
* Either this method or storeBlock needs to be overridden
|
* Either this method or storeBlock needs to be overridden
|
||||||
*
|
*
|
||||||
* @param item
|
* @param item the item
|
||||||
* @throws BlockBagException
|
* @throws BlockBagException
|
||||||
*/
|
*/
|
||||||
public void storeItem(BaseItem item) throws BlockBagException {
|
public void storeItem(BaseItem item) throws BlockBagException {
|
||||||
@ -164,7 +167,7 @@ public abstract class BlockBag {
|
|||||||
/**
|
/**
|
||||||
* Checks to see if a block exists without removing it.
|
* Checks to see if a block exists without removing it.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id the ID of the block
|
||||||
* @return whether the block exists
|
* @return whether the block exists
|
||||||
*/
|
*/
|
||||||
public boolean peekBlock(int id) {
|
public boolean peekBlock(int id) {
|
||||||
@ -185,14 +188,15 @@ public abstract class BlockBag {
|
|||||||
/**
|
/**
|
||||||
* Adds a position to be used a source.
|
* Adds a position to be used a source.
|
||||||
*
|
*
|
||||||
* @param pos
|
* @param position the position of the source
|
||||||
*/
|
*/
|
||||||
public abstract void addSourcePosition(WorldVector pos);
|
public abstract void addSourcePosition(WorldVector position);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a position to be used a source.
|
* Adds a position to be used a source.
|
||||||
*
|
*
|
||||||
* @param pos
|
* @param position the position of the source
|
||||||
*/
|
*/
|
||||||
public abstract void addSingleSourcePosition(WorldVector pos);
|
public abstract void addSingleSourcePosition(WorldVector position);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,5 +25,5 @@ package com.sk89q.worldedit.bags;
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class BlockBagException extends Exception {
|
public class BlockBagException extends Exception {
|
||||||
private static final long serialVersionUID = 4672190086028430655L;
|
|
||||||
}
|
}
|
||||||
|
@ -25,5 +25,5 @@ package com.sk89q.worldedit.bags;
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class OutOfBlocksException extends BlockBagException {
|
public class OutOfBlocksException extends BlockBagException {
|
||||||
private static final long serialVersionUID = 7495899825677689509L;
|
|
||||||
}
|
}
|
||||||
|
@ -25,16 +25,13 @@ package com.sk89q.worldedit.bags;
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class OutOfSpaceException extends BlockBagException {
|
public class OutOfSpaceException extends BlockBagException {
|
||||||
private static final long serialVersionUID = -2962840237632916821L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores the block ID.
|
|
||||||
*/
|
|
||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the object.
|
* Construct the object.
|
||||||
* @param id
|
*
|
||||||
|
* @param id the type ID
|
||||||
*/
|
*/
|
||||||
public OutOfSpaceException(int id) {
|
public OutOfSpaceException(int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
@ -25,6 +25,5 @@ package com.sk89q.worldedit.bags;
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class UnplaceableBlockException extends BlockBagException {
|
public class UnplaceableBlockException extends BlockBagException {
|
||||||
private static final long serialVersionUID = 7227883966999843526L;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a chest block.
|
* Represents a chest block.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
public class ChestBlock extends ContainerBlock {
|
public class ChestBlock extends ContainerBlock {
|
||||||
|
|
||||||
@ -109,4 +107,5 @@ public class ChestBlock extends ContainerBlock {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,6 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.blocks;
|
package com.sk89q.worldedit.blocks;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.sk89q.jnbt.ByteTag;
|
import com.sk89q.jnbt.ByteTag;
|
||||||
import com.sk89q.jnbt.CompoundTag;
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
import com.sk89q.jnbt.ListTag;
|
import com.sk89q.jnbt.ListTag;
|
||||||
@ -32,10 +27,13 @@ import com.sk89q.jnbt.ShortTag;
|
|||||||
import com.sk89q.jnbt.Tag;
|
import com.sk89q.jnbt.Tag;
|
||||||
import com.sk89q.worldedit.world.DataException;
|
import com.sk89q.worldedit.world.DataException;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a block that stores items.
|
* Represents a block that stores items.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
public abstract class ContainerBlock extends BaseBlock implements TileEntityBlock {
|
public abstract class ContainerBlock extends BaseBlock implements TileEntityBlock {
|
||||||
|
|
||||||
@ -54,7 +52,7 @@ public abstract class ContainerBlock extends BaseBlock implements TileEntityBloc
|
|||||||
/**
|
/**
|
||||||
* Get the list of items.
|
* Get the list of items.
|
||||||
*
|
*
|
||||||
* @return
|
* @return an array of stored items
|
||||||
*/
|
*/
|
||||||
public BaseItemStack[] getItems() {
|
public BaseItemStack[] getItems() {
|
||||||
return this.items;
|
return this.items;
|
||||||
@ -63,7 +61,7 @@ public abstract class ContainerBlock extends BaseBlock implements TileEntityBloc
|
|||||||
/**
|
/**
|
||||||
* Set the list of items.
|
* Set the list of items.
|
||||||
*
|
*
|
||||||
* @param items
|
* @param items an array of stored items
|
||||||
*/
|
*/
|
||||||
public void setItems(BaseItemStack[] items) {
|
public void setItems(BaseItemStack[] items) {
|
||||||
this.items = items;
|
this.items = items;
|
||||||
@ -79,7 +77,7 @@ public abstract class ContainerBlock extends BaseBlock implements TileEntityBloc
|
|||||||
data.put("id", new ShortTag("id", (short) item.getType()));
|
data.put("id", new ShortTag("id", (short) item.getType()));
|
||||||
data.put("Damage", new ShortTag("Damage", item.getData()));
|
data.put("Damage", new ShortTag("Damage", item.getData()));
|
||||||
data.put("Count", new ByteTag("Count", (byte) item.getAmount()));
|
data.put("Count", new ByteTag("Count", (byte) item.getAmount()));
|
||||||
if (item.getEnchantments().size() > 0) {
|
if (!item.getEnchantments().isEmpty()) {
|
||||||
List<CompoundTag> enchantmentList = new ArrayList<CompoundTag>();
|
List<CompoundTag> enchantmentList = new ArrayList<CompoundTag>();
|
||||||
for(Map.Entry<Integer, Integer> entry : item.getEnchantments().entrySet()) {
|
for(Map.Entry<Integer, Integer> entry : item.getEnchantments().entrySet()) {
|
||||||
Map<String, Tag> enchantment = new HashMap<String, Tag>();
|
Map<String, Tag> enchantment = new HashMap<String, Tag>();
|
||||||
@ -139,4 +137,5 @@ public abstract class ContainerBlock extends BaseBlock implements TileEntityBloc
|
|||||||
}
|
}
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents dispensers.
|
* Represents dispensers.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
public class DispenserBlock extends ContainerBlock {
|
public class DispenserBlock extends ContainerBlock {
|
||||||
|
|
||||||
@ -106,4 +104,5 @@ public class DispenserBlock extends ContainerBlock {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a furnace block.
|
* Represents a furnace block.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
public class FurnaceBlock extends ContainerBlock {
|
public class FurnaceBlock extends ContainerBlock {
|
||||||
|
|
||||||
@ -164,4 +162,5 @@ public class FurnaceBlock extends ContainerBlock {
|
|||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,12 +29,12 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||||||
* A implementation of a lazy block for {@link Extent#getLazyBlock(Vector)}
|
* A implementation of a lazy block for {@link Extent#getLazyBlock(Vector)}
|
||||||
* that takes the block's ID and metadata, but will defer loading of NBT
|
* that takes the block's ID and metadata, but will defer loading of NBT
|
||||||
* data until time of access.
|
* data until time of access.
|
||||||
* </p>
|
*
|
||||||
* NBT data is later loaded using a call to {@link Extent#getBlock(Vector)}
|
* <p>NBT data is later loaded using a call to {@link Extent#getBlock(Vector)}
|
||||||
* with a stored {@link Extent} and location.
|
* with a stored {@link Extent} and location.</p>
|
||||||
* </p>
|
*
|
||||||
* All mutators on this object will throw an
|
* <p>All mutators on this object will throw an
|
||||||
* {@link UnsupportedOperationException}.
|
* {@link UnsupportedOperationException}.</p>
|
||||||
*/
|
*/
|
||||||
public class LazyBlock extends BaseBlock {
|
public class LazyBlock extends BaseBlock {
|
||||||
|
|
||||||
|
@ -33,8 +33,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A mob spawner block.
|
* A mob spawner block.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
public class MobSpawnerBlock extends BaseBlock implements TileEntityBlock {
|
public class MobSpawnerBlock extends BaseBlock implements TileEntityBlock {
|
||||||
|
|
||||||
@ -247,6 +245,6 @@ public class MobSpawnerBlock extends BaseBlock implements TileEntityBlock {
|
|||||||
if (spawnDataTag != null) {
|
if (spawnDataTag != null) {
|
||||||
this.spawnData = new CompoundTag("SpawnData", spawnDataTag.getValue());
|
this.spawnData = new CompoundTag("SpawnData", spawnDataTag.getValue());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -29,8 +29,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A note block.
|
* A note block.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
public class NoteBlock extends BaseBlock implements TileEntityBlock {
|
public class NoteBlock extends BaseBlock implements TileEntityBlock {
|
||||||
|
|
||||||
@ -120,4 +118,5 @@ public class NoteBlock extends BaseBlock implements TileEntityBlock {
|
|||||||
note = ((ByteTag) t).getValue();
|
note = ((ByteTag) t).getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a sign block.
|
* Represents a sign block.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
public class SignBlock extends BaseBlock implements TileEntityBlock {
|
public class SignBlock extends BaseBlock implements TileEntityBlock {
|
||||||
|
|
||||||
@ -139,4 +137,5 @@ public class SignBlock extends BaseBlock implements TileEntityBlock {
|
|||||||
text[3] = ((StringTag) t).getValue();
|
text[3] = ((StringTag) t).getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -64,8 +64,8 @@ public class BlockMask extends AbstractMask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(EditSession editSession, Vector pos) {
|
public boolean matches(EditSession editSession, Vector position) {
|
||||||
BaseBlock block = editSession.getBlock(pos);
|
BaseBlock block = editSession.getBlock(position);
|
||||||
return blocks.contains(block)
|
return blocks.contains(block)
|
||||||
|| blocks.contains(new BaseBlock(block.getType(), -1));
|
|| blocks.contains(new BaseBlock(block.getType(), -1));
|
||||||
}
|
}
|
||||||
|
@ -19,17 +19,18 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.masks;
|
package com.sk89q.worldedit.masks;
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A filter that matches blocks based on block types.
|
* A filter that matches blocks based on block types.
|
||||||
*
|
*
|
||||||
* @deprecated replaced by {@link #BlockMask}
|
* @deprecated replaced by {@link #BlockMask}
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class BlockTypeMask extends BlockMask {
|
public class BlockTypeMask extends BlockMask {
|
||||||
|
|
||||||
public BlockTypeMask() {
|
public BlockTypeMask() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@ -49,4 +50,5 @@ public class BlockTypeMask extends BlockMask {
|
|||||||
public void add(int type) {
|
public void add(int type) {
|
||||||
add(new BaseBlock(type));
|
add(new BaseBlock(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -72,9 +72,9 @@ public class CombinedMask extends AbstractMask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(EditSession editSession, Vector pos) {
|
public boolean matches(EditSession editSession, Vector position) {
|
||||||
for (Mask mask : masks) {
|
for (Mask mask : masks) {
|
||||||
if (!mask.matches(editSession, pos)) {
|
if (!mask.matches(editSession, position)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public class DynamicRegionMask extends AbstractMask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(EditSession editSession, Vector pos) {
|
public boolean matches(EditSession editSession, Vector position) {
|
||||||
return region == null || region.contains(pos);
|
return region == null || region.contains(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ import com.sk89q.worldedit.blocks.BlockID;
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public class ExistingBlockMask extends AbstractMask {
|
public class ExistingBlockMask extends AbstractMask {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(EditSession editSession, Vector pos) {
|
public boolean matches(EditSession editSession, Vector position) {
|
||||||
return editSession.getBlockType(pos) != BlockID.AIR;
|
return editSession.getBlockType(position) != BlockID.AIR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import com.sk89q.worldedit.Vector;
|
|||||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||||
import com.sk89q.worldedit.blocks.Blocks;
|
import com.sk89q.worldedit.blocks.Blocks;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -51,15 +52,13 @@ public class FuzzyBlockMask extends AbstractMask {
|
|||||||
*/
|
*/
|
||||||
public FuzzyBlockMask(BaseBlock... block) {
|
public FuzzyBlockMask(BaseBlock... block) {
|
||||||
Set<BaseBlock> filter = new HashSet<BaseBlock>();
|
Set<BaseBlock> filter = new HashSet<BaseBlock>();
|
||||||
for (BaseBlock b : block) {
|
Collections.addAll(filter, block);
|
||||||
filter.add(b);
|
|
||||||
}
|
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(EditSession editSession, Vector pos) {
|
public boolean matches(EditSession editSession, Vector position) {
|
||||||
BaseBlock compare = new BaseBlock(editSession.getBlockType(pos), editSession.getBlockData(pos));
|
BaseBlock compare = new BaseBlock(editSession.getBlockType(position), editSession.getBlockData(position));
|
||||||
return Blocks.containsFuzzy(filter, compare);
|
return Blocks.containsFuzzy(filter, compare);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,36 +19,31 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.masks;
|
package com.sk89q.worldedit.masks;
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import com.sk89q.worldedit.EditSession;
|
import com.sk89q.worldedit.EditSession;
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A block type mask that only matches blocks that are not in the list.
|
* A block type mask that only matches blocks that are not in the list.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class InvertedBlockTypeMask extends BlockTypeMask {
|
public class InvertedBlockTypeMask extends BlockTypeMask {
|
||||||
|
|
||||||
public InvertedBlockTypeMask() {
|
public InvertedBlockTypeMask() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param types
|
|
||||||
*/
|
|
||||||
public InvertedBlockTypeMask(Set<Integer> types) {
|
public InvertedBlockTypeMask(Set<Integer> types) {
|
||||||
super(types);
|
super(types);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param type
|
|
||||||
*/
|
|
||||||
public InvertedBlockTypeMask(int type) {
|
public InvertedBlockTypeMask(int type) {
|
||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(EditSession editSession, Vector pos) {
|
public boolean matches(EditSession editSession, Vector position) {
|
||||||
return !super.matches(editSession, pos);
|
return !super.matches(editSession, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,13 +36,14 @@ public class InvertedMask extends AbstractMask {
|
|||||||
this.mask = mask;
|
this.mask = mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
|
public void prepare(LocalSession session, LocalPlayer player, Vector target) {
|
||||||
mask.prepare(session, player, target);
|
mask.prepare(session, player, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(EditSession editSession, Vector pos) {
|
public boolean matches(EditSession editSession, Vector position) {
|
||||||
return !mask.matches(editSession, pos);
|
return !mask.matches(editSession, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mask getInvertedMask() {
|
public Mask getInvertedMask() {
|
||||||
|
@ -33,8 +33,8 @@ public interface Mask {
|
|||||||
/**
|
/**
|
||||||
* Called one time before each edit session.
|
* Called one time before each edit session.
|
||||||
*
|
*
|
||||||
* @param session
|
* @param session a session
|
||||||
* @param player
|
* @param player a player
|
||||||
* @param target target of the brush, null if not a brush mask
|
* @param target target of the brush, null if not a brush mask
|
||||||
*/
|
*/
|
||||||
void prepare(LocalSession session, LocalPlayer player, Vector target);
|
void prepare(LocalSession session, LocalPlayer player, Vector target);
|
||||||
@ -45,9 +45,10 @@ public interface Mask {
|
|||||||
* as getting a BaseBlock has unneeded overhead in most block querying
|
* as getting a BaseBlock has unneeded overhead in most block querying
|
||||||
* situations (enumerating a chest's contents is a waste, for example).
|
* situations (enumerating a chest's contents is a waste, for example).
|
||||||
*
|
*
|
||||||
* @param editSession
|
* @param editSession an instance
|
||||||
* @param pos
|
* @param position the position to check
|
||||||
* @return
|
* @return true if it matches
|
||||||
*/
|
*/
|
||||||
boolean matches(EditSession editSession, Vector pos);
|
boolean matches(EditSession editSession, Vector position);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public class RandomMask extends AbstractMask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(EditSession editSession, Vector pos) {
|
public boolean matches(EditSession editSession, Vector position) {
|
||||||
return Math.random() < ratio;
|
return Math.random() < ratio;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public class RegionMask extends AbstractMask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(EditSession editSession, Vector pos) {
|
public boolean matches(EditSession editSession, Vector position) {
|
||||||
return region.contains(pos);
|
return region.contains(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ import com.sk89q.worldedit.blocks.BlockType;
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public class SolidBlockMask extends AbstractMask {
|
public class SolidBlockMask extends AbstractMask {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(EditSession editSession, Vector pos) {
|
public boolean matches(EditSession editSession, Vector position) {
|
||||||
return !BlockType.canPassThrough(editSession.getBlockType(pos), editSession.getBlockData(pos));
|
return !BlockType.canPassThrough(editSession.getBlockType(position), editSession.getBlockData(position));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public class UnderOverlayMask extends AbstractMask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(EditSession editSession, Vector pos) {
|
public boolean matches(EditSession editSession, Vector position) {
|
||||||
return !mask.matches(editSession, pos) && mask.matches(editSession, pos.add(0, yMod, 0));
|
return !mask.matches(editSession, position) && mask.matches(editSession, position.add(0, yMod, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,20 +26,15 @@ import com.sk89q.worldedit.blocks.BaseBlock;
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class BlockChance {
|
public class BlockChance {
|
||||||
/**
|
|
||||||
* Block.
|
|
||||||
*/
|
|
||||||
private BaseBlock block;
|
private BaseBlock block;
|
||||||
/**
|
|
||||||
* Chance. Can be any positive value.
|
|
||||||
*/
|
|
||||||
private double chance;
|
private double chance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the object.
|
* Construct the object.
|
||||||
*
|
*
|
||||||
* @param block
|
* @param block the block
|
||||||
* @param chance
|
* @param chance the probability of the block
|
||||||
*/
|
*/
|
||||||
public BlockChance(BaseBlock block, double chance) {
|
public BlockChance(BaseBlock block, double chance) {
|
||||||
this.block = block;
|
this.block = block;
|
||||||
@ -59,4 +54,5 @@ public class BlockChance {
|
|||||||
public double getChance() {
|
public double getChance() {
|
||||||
return chance;
|
return chance;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,47 +24,28 @@ import com.sk89q.worldedit.blocks.BaseBlock;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Pattern that repeats the clipboard.
|
* Pattern that repeats the clipboard.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
public class ClipboardPattern implements Pattern {
|
public class ClipboardPattern implements Pattern {
|
||||||
/**
|
|
||||||
* Clipboard.
|
|
||||||
*/
|
|
||||||
private CuboidClipboard clipboard;
|
private CuboidClipboard clipboard;
|
||||||
/**
|
|
||||||
* Size of the clipboard.
|
|
||||||
*/
|
|
||||||
private Vector size;
|
private Vector size;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the object.
|
* Construct the object.
|
||||||
*
|
*
|
||||||
* @param clipboard
|
* @param clipboard the clipboard
|
||||||
*/
|
*/
|
||||||
public ClipboardPattern(CuboidClipboard clipboard) {
|
public ClipboardPattern(CuboidClipboard clipboard) {
|
||||||
this.clipboard = clipboard;
|
this.clipboard = clipboard;
|
||||||
this.size = clipboard.getSize();
|
this.size = clipboard.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Get next block.
|
public BaseBlock next(Vector position) {
|
||||||
*
|
return next(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||||
* @param pos
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public BaseBlock next(Vector pos) {
|
|
||||||
return next(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Get next block.
|
|
||||||
*
|
|
||||||
* @param x
|
|
||||||
* @param y
|
|
||||||
* @param z
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public BaseBlock next(int x, int y, int z) {
|
public BaseBlock next(int x, int y, int z) {
|
||||||
int xp = Math.abs(x) % size.getBlockX();
|
int xp = Math.abs(x) % size.getBlockX();
|
||||||
int yp = Math.abs(y) % size.getBlockY();
|
int yp = Math.abs(y) % size.getBlockY();
|
||||||
@ -72,4 +53,5 @@ public class ClipboardPattern implements Pattern {
|
|||||||
|
|
||||||
return clipboard.getPoint(new Vector(xp, yp, zp));
|
return clipboard.getPoint(new Vector(xp, yp, zp));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,21 +27,25 @@ import com.sk89q.worldedit.blocks.BaseBlock;
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public interface Pattern {
|
public interface Pattern {
|
||||||
/**
|
|
||||||
* Get a block for a position. This return value of this method does
|
|
||||||
* not have to be consistent for the same position.
|
|
||||||
*
|
|
||||||
* @param pos
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public BaseBlock next(Vector pos);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a block for a position. This return value of this method does
|
* Get a block for a position. This return value of this method does
|
||||||
* not have to be consistent for the same position.
|
* not have to be consistent for the same position.
|
||||||
*
|
*
|
||||||
* @param pos
|
* @param position the position where a block is needed
|
||||||
* @return
|
* @return a block
|
||||||
|
*/
|
||||||
|
public BaseBlock next(Vector position);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a block for a position. This return value of this method does
|
||||||
|
* not have to be consistent for the same position.
|
||||||
|
*
|
||||||
|
* @param x the X coordinate
|
||||||
|
* @param y the Y coordinate
|
||||||
|
* @param z the Z coordinate
|
||||||
|
* @return a block
|
||||||
*/
|
*/
|
||||||
public BaseBlock next(int x, int y, int z);
|
public BaseBlock next(int x, int y, int z);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,19 +32,14 @@ import java.util.Random;
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class RandomFillPattern implements Pattern {
|
public class RandomFillPattern implements Pattern {
|
||||||
/**
|
|
||||||
* Random number generator.
|
|
||||||
*/
|
|
||||||
private static final Random random = new Random();
|
private static final Random random = new Random();
|
||||||
/**
|
|
||||||
* Blocks and their proportions.
|
|
||||||
*/
|
|
||||||
private List<BlockChance> blocks;
|
private List<BlockChance> blocks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the object.
|
* Construct the object.
|
||||||
*
|
*
|
||||||
* @param blocks
|
* @param blocks a list of blocks
|
||||||
*/
|
*/
|
||||||
public RandomFillPattern(List<BlockChance> blocks) {
|
public RandomFillPattern(List<BlockChance> blocks) {
|
||||||
double max = 0;
|
double max = 0;
|
||||||
@ -66,13 +61,8 @@ public class RandomFillPattern implements Pattern {
|
|||||||
this.blocks = finalBlocks;
|
this.blocks = finalBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Get next block.
|
public BaseBlock next(Vector position) {
|
||||||
*
|
|
||||||
* @param pos
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public BaseBlock next(Vector pos) {
|
|
||||||
double r = random.nextDouble();
|
double r = random.nextDouble();
|
||||||
|
|
||||||
for (BlockChance block : blocks) {
|
for (BlockChance block : blocks) {
|
||||||
@ -84,7 +74,9 @@ public class RandomFillPattern implements Pattern {
|
|||||||
throw new RuntimeException("ProportionalFillPattern");
|
throw new RuntimeException("ProportionalFillPattern");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public BaseBlock next(int x, int y, int z) {
|
public BaseBlock next(int x, int y, int z) {
|
||||||
return next(null);
|
return next(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,40 +28,35 @@ import com.sk89q.worldedit.function.pattern.BlockPattern;
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class SingleBlockPattern implements Pattern {
|
public class SingleBlockPattern implements Pattern {
|
||||||
/**
|
|
||||||
* Block type.
|
|
||||||
*/
|
|
||||||
private BaseBlock block;
|
private BaseBlock block;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the object.
|
* Construct the object.
|
||||||
*
|
*
|
||||||
* @param block
|
* @param block the block
|
||||||
*/
|
*/
|
||||||
public SingleBlockPattern(BaseBlock block) {
|
public SingleBlockPattern(BaseBlock block) {
|
||||||
this.block = block;
|
this.block = block;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get next block.
|
|
||||||
*
|
|
||||||
* @param pos
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public BaseBlock next(Vector pos) {
|
|
||||||
return block;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BaseBlock next(int x, int y, int z) {
|
|
||||||
return block;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the block.
|
* Get the block.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the block
|
||||||
*/
|
*/
|
||||||
public BaseBlock getBlock() {
|
public BaseBlock getBlock() {
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseBlock next(Vector position) {
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseBlock next(int x, int y, int z) {
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,7 @@
|
|||||||
package com.sk89q.jnbt;
|
package com.sk89q.jnbt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <code>TAG_End</code> tag.
|
* The {@code TAG_End} tag.
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class EndTag extends Tag {
|
public final class EndTag extends Tag {
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public final class IntArrayTag extends Tag {
|
|||||||
if (name != null && !name.equals("")) {
|
if (name != null && !name.equals("")) {
|
||||||
append = "(\"" + this.getName() + "\")";
|
append = "(\"" + this.getName() + "\")";
|
||||||
}
|
}
|
||||||
return "TAG_Int_Array" + append + ": " + hex.toString();
|
return "TAG_Int_Array" + append + ": " + hex;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -437,12 +437,9 @@ public final class ListTag extends Tag {
|
|||||||
append = "(\"" + this.getName() + "\")";
|
append = "(\"" + this.getName() + "\")";
|
||||||
}
|
}
|
||||||
StringBuilder bldr = new StringBuilder();
|
StringBuilder bldr = new StringBuilder();
|
||||||
bldr.append("TAG_List" + append + ": " + value.size()
|
bldr.append("TAG_List").append(append).append(": ").append(value.size()).append(" entries of type ").append(NBTUtils.getTypeName(type)).append("\r\n{\r\n");
|
||||||
+ " entries of type " + NBTUtils.getTypeName(type)
|
|
||||||
+ "\r\n{\r\n");
|
|
||||||
for (Tag t : value) {
|
for (Tag t : value) {
|
||||||
bldr.append(" " + t.toString().replaceAll("\r\n", "\r\n ")
|
bldr.append(" ").append(t.toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
|
||||||
+ "\r\n");
|
|
||||||
}
|
}
|
||||||
bldr.append("}");
|
bldr.append("}");
|
||||||
return bldr.toString();
|
return bldr.toString();
|
||||||
|
@ -23,9 +23,6 @@ import java.nio.charset.Charset;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A class which holds constant values.
|
* A class which holds constant values.
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class NBTConstants {
|
public final class NBTConstants {
|
||||||
|
|
||||||
|
@ -29,20 +29,13 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
|
||||||
* This class reads <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
|
* This class reads <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
|
||||||
* streams, and produces an object graph of subclasses of the <code>Tag</code>
|
* streams, and produces an object graph of subclasses of the {@code Tag}
|
||||||
* object.
|
* object.
|
||||||
* </p>
|
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>The NBT format was created by Markus Persson, and the specification may be
|
||||||
* The NBT format was created by Markus Persson, and the specification may be
|
|
||||||
* found at <a href="http://www.minecraft.net/docs/NBT.txt">
|
* found at <a href="http://www.minecraft.net/docs/NBT.txt">
|
||||||
* http://www.minecraft.net/docs/NBT.txt</a>.
|
* http://www.minecraft.net/docs/NBT.txt</a>.</p>
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class NBTInputStream implements Closeable {
|
public final class NBTInputStream implements Closeable {
|
||||||
|
|
||||||
|
@ -26,19 +26,12 @@ import java.io.OutputStream;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
|
||||||
* This class writes <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
|
* This class writes <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
|
||||||
* <code>Tag</code> objects to an underlying <code>OutputStream</code>.
|
* {@code Tag} objects to an underlying {@code OutputStream}.
|
||||||
* </p>
|
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>The NBT format was created by Markus Persson, and the specification may be
|
||||||
* The NBT format was created by Markus Persson, and the specification may be
|
|
||||||
* found at <a href="http://www.minecraft.net/docs/NBT.txt">
|
* found at <a href="http://www.minecraft.net/docs/NBT.txt">
|
||||||
* http://www.minecraft.net/docs/NBT.txt</a>.
|
* http://www.minecraft.net/docs/NBT.txt</a>.</p>
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author Graham Edgecombe
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class NBTOutputStream implements Closeable {
|
public final class NBTOutputStream implements Closeable {
|
||||||
|
|
||||||
@ -48,7 +41,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
private final DataOutputStream os;
|
private final DataOutputStream os;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new <code>NBTOutputStream</code>, which will write data to the
|
* Creates a new {@code NBTOutputStream}, which will write data to the
|
||||||
* specified underlying output stream.
|
* specified underlying output stream.
|
||||||
*
|
*
|
||||||
* @param os
|
* @param os
|
||||||
@ -137,7 +130,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Byte</code> tag.
|
* Writes a {@code TAG_Byte} tag.
|
||||||
*
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* The tag.
|
* The tag.
|
||||||
@ -149,7 +142,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Byte_Array</code> tag.
|
* Writes a {@code TAG_Byte_Array} tag.
|
||||||
*
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* The tag.
|
* The tag.
|
||||||
@ -163,7 +156,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Compound</code> tag.
|
* Writes a {@code TAG_Compound} tag.
|
||||||
*
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* The tag.
|
* The tag.
|
||||||
@ -178,7 +171,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_List</code> tag.
|
* Writes a {@code TAG_List} tag.
|
||||||
*
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* The tag.
|
* The tag.
|
||||||
@ -192,13 +185,13 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
|
|
||||||
os.writeByte(NBTUtils.getTypeCode(clazz));
|
os.writeByte(NBTUtils.getTypeCode(clazz));
|
||||||
os.writeInt(size);
|
os.writeInt(size);
|
||||||
for (int i = 0; i < size; ++i) {
|
for (Tag tag1 : tags) {
|
||||||
writeTagPayload(tags.get(i));
|
writeTagPayload(tag1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_String</code> tag.
|
* Writes a {@code TAG_String} tag.
|
||||||
*
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* The tag.
|
* The tag.
|
||||||
@ -212,7 +205,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Double</code> tag.
|
* Writes a {@code TAG_Double} tag.
|
||||||
*
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* The tag.
|
* The tag.
|
||||||
@ -224,7 +217,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Float</code> tag.
|
* Writes a {@code TAG_Float} tag.
|
||||||
*
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* The tag.
|
* The tag.
|
||||||
@ -236,7 +229,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Long</code> tag.
|
* Writes a {@code TAG_Long} tag.
|
||||||
*
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* The tag.
|
* The tag.
|
||||||
@ -248,7 +241,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Int</code> tag.
|
* Writes a {@code TAG_Int} tag.
|
||||||
*
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* The tag.
|
* The tag.
|
||||||
@ -260,7 +253,7 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Short</code> tag.
|
* Writes a {@code TAG_Short} tag.
|
||||||
*
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* The tag.
|
* The tag.
|
||||||
@ -272,12 +265,9 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a <code>TAG_Empty</code> tag.
|
* Writes a {@code TAG_Empty} tag.
|
||||||
*
|
*
|
||||||
* @param tag
|
* @param tag the tag
|
||||||
* The tag.
|
|
||||||
* @throws IOException
|
|
||||||
* if an I/O error occurs.
|
|
||||||
*/
|
*/
|
||||||
private void writeEndTagPayload(EndTag tag) {
|
private void writeEndTagPayload(EndTag tag) {
|
||||||
/* empty */
|
/* empty */
|
||||||
@ -286,11 +276,12 @@ public final class NBTOutputStream implements Closeable {
|
|||||||
private void writeIntArrayTagPayload(IntArrayTag tag) throws IOException {
|
private void writeIntArrayTagPayload(IntArrayTag tag) throws IOException {
|
||||||
int[] data = tag.getValue();
|
int[] data = tag.getValue();
|
||||||
os.writeInt(data.length);
|
os.writeInt(data.length);
|
||||||
for (int i = 0; i < data.length; i++) {
|
for (int aData : data) {
|
||||||
os.writeInt(data[i]);
|
os.writeInt(aData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
os.close();
|
os.close();
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,6 @@
|
|||||||
package com.sk89q.jnbt;
|
package com.sk89q.jnbt;
|
||||||
|
|
||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldedit.extent.Extent;
|
|
||||||
import com.sk89q.worldedit.util.Location;
|
|
||||||
import com.sk89q.worldedit.world.storage.InvalidFormatException;
|
import com.sk89q.worldedit.world.storage.InvalidFormatException;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -171,14 +169,13 @@ public final class NBTUtils {
|
|||||||
/**
|
/**
|
||||||
* Get child tag of a NBT structure.
|
* Get child tag of a NBT structure.
|
||||||
*
|
*
|
||||||
* @param items
|
* @param items the map to read from
|
||||||
* @param key
|
* @param key the key to look for
|
||||||
* @param expected
|
* @param expected the expected NBT class type
|
||||||
* @return child tag
|
* @return child tag
|
||||||
* @throws InvalidFormatException
|
* @throws InvalidFormatException
|
||||||
*/
|
*/
|
||||||
public static <T extends Tag> T getChildTag(Map<String,Tag> items, String key,
|
public static <T extends Tag> T getChildTag(Map<String, Tag> items, String key, Class<T> expected) throws InvalidFormatException {
|
||||||
Class<T> expected) throws InvalidFormatException {
|
|
||||||
if (!items.containsKey(key)) {
|
if (!items.containsKey(key)) {
|
||||||
throw new InvalidFormatException("Missing a \"" + key + "\" tag");
|
throw new InvalidFormatException("Missing a \"" + key + "\" tag");
|
||||||
}
|
}
|
||||||
|
@ -26,11 +26,10 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
* This annotation indicates a command. Methods should be marked with this
|
* This annotation indicates a command. Methods should be marked with this
|
||||||
* annotation to tell {@link CommandsManager} that the method is a command.
|
* annotation to tell {@link CommandsManager} that the method is a command.
|
||||||
* Note that the method name can actually be anything.
|
* Note that the method name can actually be anything.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface Command {
|
public @interface Command {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of aliases for the command. The first alias is the most
|
* A list of aliases for the command. The first alias is the most
|
||||||
* important -- it is the main name of the command. (The method name
|
* important -- it is the main name of the command. (The method name
|
||||||
@ -42,7 +41,7 @@ public @interface Command {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Usage instruction. Example text for usage could be
|
* Usage instruction. Example text for usage could be
|
||||||
* <code>[-h harps] [name] [message]</code>.
|
* {@code [-h harps] [name] [message]}.
|
||||||
*
|
*
|
||||||
* @return Usage instructions for a command
|
* @return Usage instructions for a command
|
||||||
*/
|
*/
|
||||||
@ -85,9 +84,10 @@ public @interface Command {
|
|||||||
String help() default "";
|
String help() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get whether any flag can be used.
|
||||||
*
|
*
|
||||||
*
|
* @return true if so
|
||||||
* @return Whether any flag can be provided to the command, even if it is not in {@link #flags()}
|
|
||||||
*/
|
*/
|
||||||
boolean anyFlags() default false;
|
boolean anyFlags() default false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,16 +26,15 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
* Any command with this annotation will run the raw command as shown in the
|
* Any command with this annotation will run the raw command as shown in the
|
||||||
* thing, as long as it is registered in the current {@link CommandsManager}.
|
* thing, as long as it is registered in the current {@link CommandsManager}.
|
||||||
* Mostly to move commands around without breaking things.
|
* Mostly to move commands around without breaking things.
|
||||||
*
|
|
||||||
* @author zml2008
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface CommandAlias {
|
public @interface CommandAlias {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Get the raw {@link CommandsManager}-formatted command arg array to run
|
||||||
*
|
*
|
||||||
* @return Raw {@link CommandsManager}-formatted command arg array to run
|
* @return the command
|
||||||
*/
|
*/
|
||||||
String[] value();
|
String[] value();
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ public class CommandContext {
|
|||||||
isHanging = false;
|
isHanging = false;
|
||||||
|
|
||||||
String arg = args[i];
|
String arg = args[i];
|
||||||
if (arg.length() == 0) {
|
if (arg.isEmpty()) {
|
||||||
isHanging = true;
|
isHanging = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ public class CommandContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// In case there is an empty quoted string
|
// In case there is an empty quoted string
|
||||||
if (arg.length() == 0) {
|
if (arg.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// else raise exception about hanging quotes?
|
// else raise exception about hanging quotes?
|
||||||
|
@ -28,7 +28,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||||||
|
|
||||||
public class CommandException extends Exception {
|
public class CommandException extends Exception {
|
||||||
|
|
||||||
private static final long serialVersionUID = 870638193072101739L;
|
|
||||||
private List<String> commandStack = new ArrayList<String>();
|
private List<String> commandStack = new ArrayList<String>();
|
||||||
|
|
||||||
public CommandException() {
|
public CommandException() {
|
||||||
|
@ -24,14 +24,14 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates a list of permissions that should be checked.
|
* Indicates a list of permissions that should be checked.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface CommandPermissions {
|
public @interface CommandPermissions {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of permissions. Only one permission has to be met
|
* A list of permissions. Only one permission has to be met
|
||||||
* for the command to be permitted.
|
* for the command to be permitted.
|
||||||
*/
|
*/
|
||||||
String[] value();
|
String[] value();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,7 @@ package com.sk89q.minecraft.util.commands;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when not enough permissions are satisfied.
|
* Thrown when not enough permissions are satisfied.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
public class CommandPermissionsException extends CommandException {
|
public class CommandPermissionsException extends CommandException {
|
||||||
private static final long serialVersionUID = -602374621030168291L;
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
package com.sk89q.minecraft.util.commands;
|
package com.sk89q.minecraft.util.commands;
|
||||||
|
|
||||||
public class CommandUsageException extends CommandException {
|
public class CommandUsageException extends CommandException {
|
||||||
private static final long serialVersionUID = -6761418114414516542L;
|
|
||||||
|
|
||||||
protected String usage;
|
protected String usage;
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
package com.sk89q.minecraft.util.commands;
|
package com.sk89q.minecraft.util.commands;
|
||||||
|
|
||||||
|
import com.sk89q.util.StringUtil;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
@ -31,16 +33,14 @@ import java.util.Set;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import com.sk89q.util.StringUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Manager for handling commands. This allows you to easily process commands,
|
* Manager for handling commands. This allows you to easily process commands,
|
||||||
* including nested commands, by correctly annotating methods of a class.</p>
|
* including nested commands, by correctly annotating methods of a class.
|
||||||
*
|
*
|
||||||
* <p>To use this, it is merely a matter of registering classes containing
|
* <p>To use this, it is merely a matter of registering classes containing
|
||||||
* the commands (as methods with the proper annotations) with the
|
* the commands (as methods with the proper annotations) with the
|
||||||
* manager. When you want to process a command, use one of the
|
* manager. When you want to process a command, use one of the
|
||||||
* <code>execute</code> methods. If something is wrong, such as incorrect
|
* {@code execute} methods. If something is wrong, such as incorrect
|
||||||
* usage, insufficient permissions, or a missing command altogether, an
|
* usage, insufficient permissions, or a missing command altogether, an
|
||||||
* exception will be raised for upstream handling.</p>
|
* exception will be raised for upstream handling.</p>
|
||||||
*
|
*
|
||||||
@ -57,13 +57,11 @@ import com.sk89q.util.StringUtil;
|
|||||||
* allows for fast command handling. Method invocation still has to be done
|
* allows for fast command handling. Method invocation still has to be done
|
||||||
* with reflection, but this is quite fast in that of itself.</p>
|
* with reflection, but this is quite fast in that of itself.</p>
|
||||||
*
|
*
|
||||||
* @author sk89q
|
|
||||||
* @param <T> command sender class
|
* @param <T> command sender class
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("ProtectedField")
|
||||||
public abstract class CommandsManager<T> {
|
public abstract class CommandsManager<T> {
|
||||||
/**
|
|
||||||
* Logger for general errors.
|
|
||||||
*/
|
|
||||||
protected static final Logger logger =
|
protected static final Logger logger =
|
||||||
Logger.getLogger(CommandsManager.class.getCanonicalName());
|
Logger.getLogger(CommandsManager.class.getCanonicalName());
|
||||||
|
|
||||||
@ -105,7 +103,7 @@ public abstract class CommandsManager<T> {
|
|||||||
* instances will be created of the command classes and methods will
|
* instances will be created of the command classes and methods will
|
||||||
* not be called statically.
|
* not be called statically.
|
||||||
*
|
*
|
||||||
* @param cls
|
* @param cls the class to register
|
||||||
*/
|
*/
|
||||||
public void register(Class<?> cls) {
|
public void register(Class<?> cls) {
|
||||||
registerMethods(cls, null);
|
registerMethods(cls, null);
|
||||||
@ -119,7 +117,7 @@ public abstract class CommandsManager<T> {
|
|||||||
* not be called statically. A List of {@link Command} annotations from
|
* not be called statically. A List of {@link Command} annotations from
|
||||||
* registered commands is returned.
|
* registered commands is returned.
|
||||||
*
|
*
|
||||||
* @param cls
|
* @param cls the class to register
|
||||||
* @return A List of {@link Command} annotations from registered commands,
|
* @return A List of {@link Command} annotations from registered commands,
|
||||||
* for use in eg. a dynamic command registration system.
|
* for use in eg. a dynamic command registration system.
|
||||||
*/
|
*/
|
||||||
@ -131,8 +129,8 @@ public abstract class CommandsManager<T> {
|
|||||||
* Register the methods of a class. This will automatically construct
|
* Register the methods of a class. This will automatically construct
|
||||||
* instances as necessary.
|
* instances as necessary.
|
||||||
*
|
*
|
||||||
* @param cls
|
* @param cls the class to register
|
||||||
* @param parent
|
* @param parent the parent method
|
||||||
* @return Commands Registered
|
* @return Commands Registered
|
||||||
*/
|
*/
|
||||||
public List<Command> registerMethods(Class<?> cls, Method parent) {
|
public List<Command> registerMethods(Class<?> cls, Method parent) {
|
||||||
@ -156,10 +154,10 @@ public abstract class CommandsManager<T> {
|
|||||||
/**
|
/**
|
||||||
* Register the methods of a class.
|
* Register the methods of a class.
|
||||||
*
|
*
|
||||||
* @param cls
|
* @param cls the class to register
|
||||||
* @param parent
|
* @param parent the parent method
|
||||||
* @param obj
|
* @param obj the object whose methods will become commands if they are annotated
|
||||||
* @return
|
* @return a list of commands
|
||||||
*/
|
*/
|
||||||
private List<Command> registerMethods(Class<?> cls, Method parent, Object obj) {
|
private List<Command> registerMethods(Class<?> cls, Method parent, Object obj) {
|
||||||
Map<String, Method> map;
|
Map<String, Method> map;
|
||||||
@ -205,14 +203,14 @@ public abstract class CommandsManager<T> {
|
|||||||
final String desc = cmd.desc();
|
final String desc = cmd.desc();
|
||||||
|
|
||||||
final String usage = cmd.usage();
|
final String usage = cmd.usage();
|
||||||
if (usage.length() == 0) {
|
if (usage.isEmpty()) {
|
||||||
descs.put(commandName, desc);
|
descs.put(commandName, desc);
|
||||||
} else {
|
} else {
|
||||||
descs.put(commandName, usage + " - " + desc);
|
descs.put(commandName, usage + " - " + desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
String help = cmd.help();
|
String help = cmd.help();
|
||||||
if (help.length() == 0) {
|
if (help.isEmpty()) {
|
||||||
help = desc;
|
help = desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,8 +253,8 @@ public abstract class CommandsManager<T> {
|
|||||||
* Checks to see whether there is a command named such at the root level.
|
* Checks to see whether there is a command named such at the root level.
|
||||||
* This will check aliases as well.
|
* This will check aliases as well.
|
||||||
*
|
*
|
||||||
* @param command
|
* @param command the command
|
||||||
* @return
|
* @return true if the command exists
|
||||||
*/
|
*/
|
||||||
public boolean hasCommand(String command) {
|
public boolean hasCommand(String command) {
|
||||||
return commands.get(null).containsKey(command.toLowerCase());
|
return commands.get(null).containsKey(command.toLowerCase());
|
||||||
@ -265,12 +263,17 @@ public abstract class CommandsManager<T> {
|
|||||||
/**
|
/**
|
||||||
* Get a list of command descriptions. This is only for root commands.
|
* Get a list of command descriptions. This is only for root commands.
|
||||||
*
|
*
|
||||||
* @return
|
* @return a map of commands
|
||||||
*/
|
*/
|
||||||
public Map<String, String> getCommands() {
|
public Map<String, String> getCommands() {
|
||||||
return descs;
|
return descs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the mapping of methods under a parent command.
|
||||||
|
*
|
||||||
|
* @return the mapping
|
||||||
|
*/
|
||||||
public Map<Method, Map<String, Method>> getMethods() {
|
public Map<Method, Map<String, Method>> getMethods() {
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
@ -278,7 +281,7 @@ public abstract class CommandsManager<T> {
|
|||||||
/**
|
/**
|
||||||
* Get a map from command name to help message. This is only for root commands.
|
* Get a map from command name to help message. This is only for root commands.
|
||||||
*
|
*
|
||||||
* @return
|
* @return a map of help messages for each command
|
||||||
*/
|
*/
|
||||||
public Map<String, String> getHelpMessages() {
|
public Map<String, String> getHelpMessages() {
|
||||||
return helpMessages;
|
return helpMessages;
|
||||||
@ -287,10 +290,10 @@ public abstract class CommandsManager<T> {
|
|||||||
/**
|
/**
|
||||||
* Get the usage string for a command.
|
* Get the usage string for a command.
|
||||||
*
|
*
|
||||||
* @param args
|
* @param args the arguments
|
||||||
* @param level
|
* @param level the depth of the command
|
||||||
* @param cmd
|
* @param cmd the command annotation
|
||||||
* @return
|
* @return the usage string
|
||||||
*/
|
*/
|
||||||
protected String getUsage(String[] args, int level, Command cmd) {
|
protected String getUsage(String[] args, int level, Command cmd) {
|
||||||
final StringBuilder command = new StringBuilder();
|
final StringBuilder command = new StringBuilder();
|
||||||
@ -304,7 +307,7 @@ public abstract class CommandsManager<T> {
|
|||||||
command.append(getArguments(cmd));
|
command.append(getArguments(cmd));
|
||||||
|
|
||||||
final String help = cmd.help();
|
final String help = cmd.help();
|
||||||
if (help.length() > 0) {
|
if (!help.isEmpty()) {
|
||||||
command.append("\n\n");
|
command.append("\n\n");
|
||||||
command.append(help);
|
command.append(help);
|
||||||
}
|
}
|
||||||
@ -316,9 +319,9 @@ public abstract class CommandsManager<T> {
|
|||||||
final String flags = cmd.flags();
|
final String flags = cmd.flags();
|
||||||
|
|
||||||
final StringBuilder command2 = new StringBuilder();
|
final StringBuilder command2 = new StringBuilder();
|
||||||
if (flags.length() > 0) {
|
if (!flags.isEmpty()) {
|
||||||
String flagString = flags.replaceAll(".:", "");
|
String flagString = flags.replaceAll(".:", "");
|
||||||
if (flagString.length() > 0) {
|
if (!flagString.isEmpty()) {
|
||||||
command2.append("[-");
|
command2.append("[-");
|
||||||
for (int i = 0; i < flagString.length(); ++i) {
|
for (int i = 0; i < flagString.length(); ++i) {
|
||||||
command2.append(flagString.charAt(i));
|
command2.append(flagString.charAt(i));
|
||||||
@ -335,22 +338,20 @@ public abstract class CommandsManager<T> {
|
|||||||
/**
|
/**
|
||||||
* Get the usage string for a nested command.
|
* Get the usage string for a nested command.
|
||||||
*
|
*
|
||||||
* @param args
|
* @param args the arguments
|
||||||
* @param level
|
* @param level the depth of the command
|
||||||
* @param method
|
* @param method the parent method
|
||||||
* @param player
|
* @param player the player
|
||||||
* @return
|
* @return the usage string
|
||||||
* @throws CommandException
|
* @throws CommandException on some error
|
||||||
*/
|
*/
|
||||||
protected String getNestedUsage(String[] args, int level,
|
protected String getNestedUsage(String[] args, int level, Method method, T player) throws CommandException {
|
||||||
Method method, T player) throws CommandException {
|
|
||||||
|
|
||||||
StringBuilder command = new StringBuilder();
|
StringBuilder command = new StringBuilder();
|
||||||
|
|
||||||
command.append("/");
|
command.append("/");
|
||||||
|
|
||||||
for (int i = 0; i <= level; ++i) {
|
for (int i = 0; i <= level; ++i) {
|
||||||
command.append(args[i] + " ");
|
command.append(args[i]).append(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Method> map = commands.get(method);
|
Map<String, Method> map = commands.get(method);
|
||||||
@ -371,7 +372,7 @@ public abstract class CommandsManager<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allowedCommands.size() > 0) {
|
if (!allowedCommands.isEmpty()) {
|
||||||
command.append(StringUtil.joinString(allowedCommands, "|", 0));
|
command.append(StringUtil.joinString(allowedCommands, "|", 0));
|
||||||
} else {
|
} else {
|
||||||
if (!found) {
|
if (!found) {
|
||||||
@ -412,14 +413,12 @@ public abstract class CommandsManager<T> {
|
|||||||
/**
|
/**
|
||||||
* Attempt to execute a command.
|
* Attempt to execute a command.
|
||||||
*
|
*
|
||||||
* @param args
|
* @param args the arguments
|
||||||
* @param player
|
* @param player the player
|
||||||
* @param methodArgs
|
* @param methodArgs the arguments for the method
|
||||||
* @throws CommandException
|
* @throws CommandException thrown on command error
|
||||||
*/
|
*/
|
||||||
public void execute(String[] args, T player,
|
public void execute(String[] args, T player, Object... methodArgs) throws CommandException {
|
||||||
Object... methodArgs) throws CommandException {
|
|
||||||
|
|
||||||
Object[] newMethodArgs = new Object[methodArgs.length + 1];
|
Object[] newMethodArgs = new Object[methodArgs.length + 1];
|
||||||
System.arraycopy(methodArgs, 0, newMethodArgs, 1, methodArgs.length);
|
System.arraycopy(methodArgs, 0, newMethodArgs, 1, methodArgs.length);
|
||||||
executeMethod(null, args, player, newMethodArgs, 0);
|
executeMethod(null, args, player, newMethodArgs, 0);
|
||||||
@ -428,16 +427,14 @@ public abstract class CommandsManager<T> {
|
|||||||
/**
|
/**
|
||||||
* Attempt to execute a command.
|
* Attempt to execute a command.
|
||||||
*
|
*
|
||||||
* @param parent
|
* @param parent the parent method
|
||||||
* @param args
|
* @param args an array of arguments
|
||||||
* @param player
|
* @param player the player
|
||||||
* @param methodArgs
|
* @param methodArgs the array of method arguments
|
||||||
* @param level
|
* @param level the depth of the command
|
||||||
* @throws CommandException
|
* @throws CommandException thrown on a command error
|
||||||
*/
|
*/
|
||||||
public void executeMethod(Method parent, String[] args,
|
public void executeMethod(Method parent, String[] args, T player, Object[] methodArgs, int level) throws CommandException {
|
||||||
T player, Object[] methodArgs, int level) throws CommandException {
|
|
||||||
|
|
||||||
String cmdName = args[level];
|
String cmdName = args[level];
|
||||||
|
|
||||||
Map<String, Method> map = commands.get(parent);
|
Map<String, Method> map = commands.get(parent);
|
||||||
@ -527,8 +524,7 @@ public abstract class CommandsManager<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invokeMethod(Method parent, String[] args, T player, Method method,
|
public void invokeMethod(Method parent, String[] args, T player, Method method, Object instance, Object[] methodArgs, int level) throws CommandException {
|
||||||
Object instance, Object[] methodArgs, int level) throws CommandException {
|
|
||||||
try {
|
try {
|
||||||
method.invoke(instance, methodArgs);
|
method.invoke(instance, methodArgs);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
@ -547,9 +543,9 @@ public abstract class CommandsManager<T> {
|
|||||||
/**
|
/**
|
||||||
* Returns whether a player has access to a command.
|
* Returns whether a player has access to a command.
|
||||||
*
|
*
|
||||||
* @param method
|
* @param method the method
|
||||||
* @param player
|
* @param player the player
|
||||||
* @return
|
* @return true if permission is granted
|
||||||
*/
|
*/
|
||||||
protected boolean hasPermission(Method method, T player) {
|
protected boolean hasPermission(Method method, T player) {
|
||||||
CommandPermissions perms = method.getAnnotation(CommandPermissions.class);
|
CommandPermissions perms = method.getAnnotation(CommandPermissions.class);
|
||||||
@ -569,11 +565,11 @@ public abstract class CommandsManager<T> {
|
|||||||
/**
|
/**
|
||||||
* Returns whether a player permission..
|
* Returns whether a player permission..
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player the player
|
||||||
* @param perm
|
* @param permission the permission
|
||||||
* @return
|
* @return true if permission is granted
|
||||||
*/
|
*/
|
||||||
public abstract boolean hasPermission(T player, String perm);
|
public abstract boolean hasPermission(T player, String permission);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the injector used to create new instances. This can be
|
* Get the injector used to create new instances. This can be
|
||||||
|
@ -24,9 +24,8 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This annotation indicates that a command can be used from the console.
|
* This annotation indicates that a command can be used from the console.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface Console {
|
public @interface Console {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,10 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates how the affected blocks should be hinted at in the log.
|
* Indicates how the affected blocks should be hinted at in the log.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface Logging {
|
public @interface Logging {
|
||||||
|
|
||||||
public enum LogMode {
|
public enum LogMode {
|
||||||
/**
|
/**
|
||||||
* Player position
|
* Player position
|
||||||
@ -63,4 +62,5 @@ public @interface Logging {
|
|||||||
* Log mode. Can be either POSITION, REGION, ORIENTATION_REGION, PLACEMENT or ALL.
|
* Log mode. Can be either POSITION, REGION, ORIENTATION_REGION, PLACEMENT or ALL.
|
||||||
*/
|
*/
|
||||||
LogMode value();
|
LogMode value();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
package com.sk89q.minecraft.util.commands;
|
package com.sk89q.minecraft.util.commands;
|
||||||
|
|
||||||
public class MissingNestedCommandException extends CommandUsageException {
|
public class MissingNestedCommandException extends CommandUsageException {
|
||||||
private static final long serialVersionUID = -4382896182979285355L;
|
|
||||||
|
|
||||||
public MissingNestedCommandException(String message, String usage) {
|
public MissingNestedCommandException(String message, String usage) {
|
||||||
super(message, usage);
|
super(message, usage);
|
||||||
|
@ -29,11 +29,10 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
* will never called. Additionally, not all fields of {@link Command} apply
|
* will never called. Additionally, not all fields of {@link Command} apply
|
||||||
* when it is used in conjunction with this annotation, although both
|
* when it is used in conjunction with this annotation, although both
|
||||||
* are still required.
|
* are still required.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface NestedCommand {
|
public @interface NestedCommand {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of classes with the child commands.
|
* A list of classes with the child commands.
|
||||||
*/
|
*/
|
||||||
@ -43,4 +42,5 @@ public @interface NestedCommand {
|
|||||||
* If set to true it will execute the body of the tagged method.
|
* If set to true it will execute the body of the tagged method.
|
||||||
*/
|
*/
|
||||||
boolean executeBody() default false;
|
boolean executeBody() default false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,10 +21,12 @@ package com.sk89q.minecraft.util.commands;
|
|||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class SimpleInjector implements Injector {
|
public class SimpleInjector implements Injector {
|
||||||
private static final Logger logger = Logger.getLogger(SimpleInjector.class.getCanonicalName());
|
|
||||||
|
private static final Logger log = Logger.getLogger(SimpleInjector.class.getCanonicalName());
|
||||||
private Object[] args;
|
private Object[] args;
|
||||||
private Class<?>[] argClasses;
|
private Class<?>[] argClasses;
|
||||||
|
|
||||||
@ -36,26 +38,23 @@ public class SimpleInjector implements Injector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Object getInstance(Class<?> clazz) {
|
public Object getInstance(Class<?> clazz) {
|
||||||
try {
|
try {
|
||||||
Constructor<?> ctr = clazz.getConstructor(argClasses);
|
Constructor<?> ctr = clazz.getConstructor(argClasses);
|
||||||
ctr.setAccessible(true);
|
ctr.setAccessible(true);
|
||||||
return ctr.newInstance(args);
|
return ctr.newInstance(args);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
logger.severe("Error initializing commands class " + clazz + ": ");
|
log.log(Level.SEVERE, "Error initializing commands class " + clazz, e);
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
return null;
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
logger.severe("Error initializing commands class " + clazz + ": ");
|
log.log(Level.SEVERE, "Error initializing commands class " + clazz, e);
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
return null;
|
||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException e) {
|
||||||
logger.severe("Error initializing commands class " + clazz + ": ");
|
log.log(Level.SEVERE, "Error initializing commands class " + clazz, e);
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
return null;
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
logger.severe("Error initializing commands class " + clazz + ": ");
|
log.log(Level.SEVERE, "Error initializing commands class " + clazz, e);
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,5 @@
|
|||||||
package com.sk89q.minecraft.util.commands;
|
package com.sk89q.minecraft.util.commands;
|
||||||
|
|
||||||
public class UnhandledCommandException extends CommandException {
|
public class UnhandledCommandException extends CommandException {
|
||||||
private static final long serialVersionUID = 3370887306593968091L;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,9 @@
|
|||||||
package com.sk89q.minecraft.util.commands;
|
package com.sk89q.minecraft.util.commands;
|
||||||
|
|
||||||
public class WrappedCommandException extends CommandException {
|
public class WrappedCommandException extends CommandException {
|
||||||
private static final long serialVersionUID = -4075721444847778918L;
|
|
||||||
|
|
||||||
public WrappedCommandException(Throwable t) {
|
public WrappedCommandException(Throwable t) {
|
||||||
super(t);
|
super(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,6 @@ package com.sk89q.util;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author zml2008
|
|
||||||
*/
|
|
||||||
public final class ReflectionUtil {
|
public final class ReflectionUtil {
|
||||||
|
|
||||||
private ReflectionUtil() {
|
private ReflectionUtil() {
|
||||||
@ -37,8 +34,8 @@ public final class ReflectionUtil {
|
|||||||
Field field = checkClass.getDeclaredField(name);
|
Field field = checkClass.getDeclaredField(name);
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
return (T) field.get(from);
|
return (T) field.get(from);
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException ignored) {
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException ignored) {
|
||||||
}
|
}
|
||||||
} while (checkClass.getSuperclass() != Object.class && ((checkClass = checkClass.getSuperclass()) != null));
|
} while (checkClass.getSuperclass() != Object.class && ((checkClass = checkClass.getSuperclass()) != null));
|
||||||
return null;
|
return null;
|
||||||
|
@ -24,8 +24,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* String utilities.
|
* String utilities.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
public final class StringUtil {
|
public final class StringUtil {
|
||||||
|
|
||||||
@ -35,9 +33,9 @@ public final class StringUtil {
|
|||||||
/**
|
/**
|
||||||
* Trim a string if it is longer than a certain length.
|
* Trim a string if it is longer than a certain length.
|
||||||
*
|
*
|
||||||
* @param str
|
* @param str the stirng
|
||||||
* @param len
|
* @param len the length to trim to
|
||||||
* @return
|
* @return a new string
|
||||||
*/
|
*/
|
||||||
public static String trimLength(String str, int len) {
|
public static String trimLength(String str, int len) {
|
||||||
if (str.length() > len) {
|
if (str.length() > len) {
|
||||||
@ -50,13 +48,12 @@ public final class StringUtil {
|
|||||||
/**
|
/**
|
||||||
* Join an array of strings into a string.
|
* Join an array of strings into a string.
|
||||||
*
|
*
|
||||||
* @param str
|
* @param str the string array
|
||||||
* @param delimiter
|
* @param delimiter the delimiter
|
||||||
* @param initialIndex
|
* @param initialIndex the initial index to start form
|
||||||
* @return
|
* @return a new string
|
||||||
*/
|
*/
|
||||||
public static String joinString(String[] str, String delimiter,
|
public static String joinString(String[] str, String delimiter, int initialIndex) {
|
||||||
int initialIndex) {
|
|
||||||
if (str.length == 0) {
|
if (str.length == 0) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -70,11 +67,11 @@ public final class StringUtil {
|
|||||||
/**
|
/**
|
||||||
* Join an array of strings into a string.
|
* Join an array of strings into a string.
|
||||||
*
|
*
|
||||||
* @param str
|
* @param str the string array
|
||||||
* @param delimiter
|
* @param delimiter the delimiter
|
||||||
* @param initialIndex
|
* @param initialIndex the initial index to start form
|
||||||
* @param quote
|
* @param quote the character to put around each entry
|
||||||
* @return
|
* @return a new string
|
||||||
*/
|
*/
|
||||||
public static String joinQuotedString(String[] str, String delimiter,
|
public static String joinQuotedString(String[] str, String delimiter,
|
||||||
int initialIndex, String quote) {
|
int initialIndex, String quote) {
|
||||||
@ -94,9 +91,9 @@ public final class StringUtil {
|
|||||||
/**
|
/**
|
||||||
* Join an array of strings into a string.
|
* Join an array of strings into a string.
|
||||||
*
|
*
|
||||||
* @param str
|
* @param str the string array
|
||||||
* @param delimiter
|
* @param delimiter the delimiter
|
||||||
* @return
|
* @return a new string
|
||||||
*/
|
*/
|
||||||
public static String joinString(String[] str, String delimiter) {
|
public static String joinString(String[] str, String delimiter) {
|
||||||
return joinString(str, delimiter, 0);
|
return joinString(str, delimiter, 0);
|
||||||
@ -105,19 +102,18 @@ public final class StringUtil {
|
|||||||
/**
|
/**
|
||||||
* Join an array of strings into a string.
|
* Join an array of strings into a string.
|
||||||
*
|
*
|
||||||
* @param str
|
* @param str an array of objects
|
||||||
* @param delimiter
|
* @param delimiter the delimiter
|
||||||
* @param initialIndex
|
* @param initialIndex the initial index to start form
|
||||||
* @return
|
* @return a new string
|
||||||
*/
|
*/
|
||||||
public static String joinString(Object[] str, String delimiter,
|
public static String joinString(Object[] str, String delimiter, int initialIndex) {
|
||||||
int initialIndex) {
|
|
||||||
if (str.length == 0) {
|
if (str.length == 0) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
StringBuilder buffer = new StringBuilder(str[initialIndex].toString());
|
StringBuilder buffer = new StringBuilder(str[initialIndex].toString());
|
||||||
for (int i = initialIndex + 1; i < str.length; ++i) {
|
for (int i = initialIndex + 1; i < str.length; ++i) {
|
||||||
buffer.append(delimiter).append(str[i].toString());
|
buffer.append(delimiter).append(str[i]);
|
||||||
}
|
}
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
@ -125,13 +121,12 @@ public final class StringUtil {
|
|||||||
/**
|
/**
|
||||||
* Join an array of strings into a string.
|
* Join an array of strings into a string.
|
||||||
*
|
*
|
||||||
* @param str
|
* @param str a list of integers
|
||||||
* @param delimiter
|
* @param delimiter the delimiter
|
||||||
* @param initialIndex
|
* @param initialIndex the initial index to start form
|
||||||
* @return
|
* @return a new string
|
||||||
*/
|
*/
|
||||||
public static String joinString(int[] str, String delimiter,
|
public static String joinString(int[] str, String delimiter, int initialIndex) {
|
||||||
int initialIndex) {
|
|
||||||
if (str.length == 0) {
|
if (str.length == 0) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -145,14 +140,13 @@ public final class StringUtil {
|
|||||||
/**
|
/**
|
||||||
* Join an list of strings into a string.
|
* Join an list of strings into a string.
|
||||||
*
|
*
|
||||||
* @param str
|
* @param str a list of strings
|
||||||
* @param delimiter
|
* @param delimiter the delimiter
|
||||||
* @param initialIndex
|
* @param initialIndex the initial index to start form
|
||||||
* @return
|
* @return a new string
|
||||||
*/
|
*/
|
||||||
public static String joinString(Collection<?> str, String delimiter,
|
public static String joinString(Collection<?> str, String delimiter,int initialIndex) {
|
||||||
int initialIndex) {
|
if (str.isEmpty()) {
|
||||||
if (str.size() == 0) {
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
StringBuilder buffer = new StringBuilder();
|
StringBuilder buffer = new StringBuilder();
|
||||||
@ -163,7 +157,7 @@ public final class StringUtil {
|
|||||||
buffer.append(delimiter);
|
buffer.append(delimiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.append(o.toString());
|
buffer.append(o);
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
@ -202,7 +196,7 @@ public final class StringUtil {
|
|||||||
* @param s the first String, must not be null
|
* @param s the first String, must not be null
|
||||||
* @param t the second String, must not be null
|
* @param t the second String, must not be null
|
||||||
* @return result distance
|
* @return result distance
|
||||||
* @throws IllegalArgumentException if either String input <code>null</code>
|
* @throws IllegalArgumentException if either String input {@code null}
|
||||||
*/
|
*/
|
||||||
public static int getLevenshteinDistance(String s, String t) {
|
public static int getLevenshteinDistance(String s, String t) {
|
||||||
if (s == null || t == null) {
|
if (s == null || t == null) {
|
||||||
@ -238,9 +232,9 @@ public final class StringUtil {
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
int p[] = new int[n + 1]; // 'previous' cost array, horizontally
|
int[] p = new int[n + 1]; // 'previous' cost array, horizontally
|
||||||
int d[] = new int[n + 1]; // cost array, horizontally
|
int[] d = new int[n + 1]; // cost array, horizontally
|
||||||
int _d[]; // placeholder to assist in swapping p and d
|
int[] _d; // placeholder to assist in swapping p and d
|
||||||
|
|
||||||
// indexes into strings s and t
|
// indexes into strings s and t
|
||||||
int i; // iterates through s
|
int i; // iterates through s
|
||||||
|
@ -23,6 +23,7 @@ import com.sk89q.worldedit.BlockVector2D;
|
|||||||
import com.sk89q.worldedit.Vector;
|
import com.sk89q.worldedit.Vector;
|
||||||
import com.sk89q.worldedit.Vector2D;
|
import com.sk89q.worldedit.Vector2D;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -30,10 +31,9 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a configuration node.
|
* Represents a configuration node.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
public class YAMLNode {
|
public class YAMLNode {
|
||||||
|
|
||||||
protected Map<String, Object> root;
|
protected Map<String, Object> root;
|
||||||
private boolean writeDefaults;
|
private boolean writeDefaults;
|
||||||
|
|
||||||
@ -106,8 +106,8 @@ public class YAMLNode {
|
|||||||
* Prepare a value for serialization, in case it's not a native type
|
* Prepare a value for serialization, in case it's not a native type
|
||||||
* (and we don't want to serialize objects as YAML objects).
|
* (and we don't want to serialize objects as YAML objects).
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value the value to serialize
|
||||||
* @return
|
* @return the new object
|
||||||
*/
|
*/
|
||||||
private Object prepareSerialization(Object value) {
|
private Object prepareSerialization(Object value) {
|
||||||
if (value instanceof Vector) {
|
if (value instanceof Vector) {
|
||||||
@ -126,8 +126,8 @@ public class YAMLNode {
|
|||||||
* Set the property at a location. This will override existing
|
* Set the property at a location. This will override existing
|
||||||
* configuration data to have it conform to key/value mappings.
|
* configuration data to have it conform to key/value mappings.
|
||||||
*
|
*
|
||||||
* @param path
|
* @param path the path
|
||||||
* @param value
|
* @param value the new value
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void setProperty(String path, Object value) {
|
public void setProperty(String path, Object value) {
|
||||||
@ -163,10 +163,10 @@ public class YAMLNode {
|
|||||||
/**
|
/**
|
||||||
* Adds a new node to the given path. The returned object is a reference
|
* Adds a new node to the given path. The returned object is a reference
|
||||||
* to the new node. This method will replace an existing node at
|
* to the new node. This method will replace an existing node at
|
||||||
* the same path. See <code>setProperty</code>.
|
* the same path. See {@code setProperty}.
|
||||||
*
|
*
|
||||||
* @param path
|
* @param path the path
|
||||||
* @return
|
* @return a node for the path
|
||||||
*/
|
*/
|
||||||
public YAMLNode addNode(String path) {
|
public YAMLNode addNode(String path) {
|
||||||
Map<String, Object> map = new LinkedHashMap<String, Object>();
|
Map<String, Object> map = new LinkedHashMap<String, Object>();
|
||||||
@ -557,9 +557,7 @@ public class YAMLNode {
|
|||||||
* @param def default value or null for an empty list as default
|
* @param def default value or null for an empty list as default
|
||||||
* @return list of integers
|
* @return list of integers
|
||||||
*/
|
*/
|
||||||
public List<Vector> getVectorList(
|
public List<Vector> getVectorList(String path, List<Vector> def) {
|
||||||
String path, List<Vector> def) {
|
|
||||||
|
|
||||||
List<YAMLNode> raw = getNodeList(path, null);
|
List<YAMLNode> raw = getNodeList(path, null);
|
||||||
List<Vector> list = new ArrayList<Vector>();
|
List<Vector> list = new ArrayList<Vector>();
|
||||||
|
|
||||||
@ -589,8 +587,7 @@ public class YAMLNode {
|
|||||||
* @param def default value or null for an empty list as default
|
* @param def default value or null for an empty list as default
|
||||||
* @return list of integers
|
* @return list of integers
|
||||||
*/
|
*/
|
||||||
public List<Vector2D> getVector2dList(
|
public List<Vector2D> getVector2dList(String path, List<Vector2D> def) {
|
||||||
String path, List<Vector2D> def) {
|
|
||||||
|
|
||||||
List<YAMLNode> raw = getNodeList(path, null);
|
List<YAMLNode> raw = getNodeList(path, null);
|
||||||
List<Vector2D> list = new ArrayList<Vector2D>();
|
List<Vector2D> list = new ArrayList<Vector2D>();
|
||||||
@ -620,8 +617,7 @@ public class YAMLNode {
|
|||||||
* @param def default value or null for an empty list as default
|
* @param def default value or null for an empty list as default
|
||||||
* @return list of integers
|
* @return list of integers
|
||||||
*/
|
*/
|
||||||
public List<BlockVector2D> getBlockVector2dList(
|
public List<BlockVector2D> getBlockVector2dList(String path, List<BlockVector2D> def) {
|
||||||
String path, List<BlockVector2D> def) {
|
|
||||||
|
|
||||||
List<YAMLNode> raw = getNodeList(path, null);
|
List<YAMLNode> raw = getNodeList(path, null);
|
||||||
List<BlockVector2D> list = new ArrayList<BlockVector2D>();
|
List<BlockVector2D> list = new ArrayList<BlockVector2D>();
|
||||||
@ -674,9 +670,10 @@ public class YAMLNode {
|
|||||||
* path does not lead to a node, null will be returned. A node has
|
* path does not lead to a node, null will be returned. A node has
|
||||||
* key/value mappings.
|
* key/value mappings.
|
||||||
*
|
*
|
||||||
* @param path
|
* @param path the path
|
||||||
* @return node or null
|
* @return node or null
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public YAMLNode getNode(String path) {
|
public YAMLNode getNode(String path) {
|
||||||
Object raw = getProperty(path);
|
Object raw = getProperty(path);
|
||||||
@ -719,9 +716,10 @@ public class YAMLNode {
|
|||||||
/**
|
/**
|
||||||
* Casts a value to an integer. May return null.
|
* Casts a value to an integer. May return null.
|
||||||
*
|
*
|
||||||
* @param o
|
* @param o the object
|
||||||
* @return
|
* @return an integer or null
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
private static Integer castInt(Object o) {
|
private static Integer castInt(Object o) {
|
||||||
if (o == null) {
|
if (o == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -735,9 +733,10 @@ public class YAMLNode {
|
|||||||
/**
|
/**
|
||||||
* Casts a value to a double. May return null.
|
* Casts a value to a double. May return null.
|
||||||
*
|
*
|
||||||
* @param o
|
* @param o the object
|
||||||
* @return
|
* @return a double or null
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
private static Double castDouble(Object o) {
|
private static Double castDouble(Object o) {
|
||||||
if (o == null) {
|
if (o == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -751,9 +750,10 @@ public class YAMLNode {
|
|||||||
/**
|
/**
|
||||||
* Casts a value to a boolean. May return null.
|
* Casts a value to a boolean. May return null.
|
||||||
*
|
*
|
||||||
* @param o
|
* @param o the object
|
||||||
* @return
|
* @return a boolean or null
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
private static Boolean castBoolean(Object o) {
|
private static Boolean castBoolean(Object o) {
|
||||||
if (o == null) {
|
if (o == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -768,7 +768,7 @@ public class YAMLNode {
|
|||||||
* Remove the property at a location. This will override existing
|
* Remove the property at a location. This will override existing
|
||||||
* configuration data to have it conform to key/value mappings.
|
* configuration data to have it conform to key/value mappings.
|
||||||
*
|
*
|
||||||
* @param path
|
* @param path a path
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void removeProperty(String path) {
|
public void removeProperty(String path) {
|
||||||
@ -800,4 +800,5 @@ public class YAMLNode {
|
|||||||
public void setWriteDefaults(boolean writeDefaults) {
|
public void setWriteDefaults(boolean writeDefaults) {
|
||||||
this.writeDefaults = writeDefaults;
|
this.writeDefaults = writeDefaults;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,7 @@ import org.yaml.snakeyaml.representer.Representer;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* YAML configuration loader. To use this class, construct it with path to
|
* YAML configuration loader. To use this class, construct it with path to
|
||||||
@ -58,13 +59,11 @@ import java.util.*;
|
|||||||
* babies: true</pre>
|
* babies: true</pre>
|
||||||
*
|
*
|
||||||
* <p>Calling code could access sturmeh's baby eating state by using
|
* <p>Calling code could access sturmeh's baby eating state by using
|
||||||
* <code>getBoolean("sturmeh.eats.babies", false)</code>. For lists, there are
|
* {@code getBoolean("sturmeh.eats.babies", false)}. For lists, there are
|
||||||
* methods such as <code>getStringList</code> that will return a type safe list.
|
* methods such as {@code getStringList} that will return a type safe list.
|
||||||
*
|
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
public class YAMLProcessor extends YAMLNode {
|
public class YAMLProcessor extends YAMLNode {
|
||||||
|
|
||||||
public static final String LINE_BREAK = DumperOptions.LineBreak.getPlatformLineBreak().getString();
|
public static final String LINE_BREAK = DumperOptions.LineBreak.getPlatformLineBreak().getString();
|
||||||
public static final char COMMENT_CHAR = '#';
|
public static final char COMMENT_CHAR = '#';
|
||||||
protected final Yaml yaml;
|
protected final Yaml yaml;
|
||||||
@ -117,7 +116,7 @@ public class YAMLProcessor extends YAMLNode {
|
|||||||
if (stream != null) {
|
if (stream != null) {
|
||||||
stream.close();
|
stream.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,7 +155,7 @@ public class YAMLProcessor extends YAMLNode {
|
|||||||
/**
|
/**
|
||||||
* Return the set header.
|
* Return the set header.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the header text
|
||||||
*/
|
*/
|
||||||
public String getHeader() {
|
public String getHeader() {
|
||||||
return header;
|
return header;
|
||||||
@ -184,13 +183,11 @@ public class YAMLProcessor extends YAMLNode {
|
|||||||
writer.append(header);
|
writer.append(header);
|
||||||
writer.append(LINE_BREAK);
|
writer.append(LINE_BREAK);
|
||||||
}
|
}
|
||||||
if (comments.size() == 0 || format != YAMLFormat.EXTENDED) {
|
if (comments.isEmpty() || format != YAMLFormat.EXTENDED) {
|
||||||
yaml.dump(root, writer);
|
yaml.dump(root, writer);
|
||||||
} else {
|
} else {
|
||||||
// Iterate over each root-level property and dump
|
// Iterate over each root-level property and dump
|
||||||
for (Iterator<Map.Entry<String, Object>> i = root.entrySet().iterator(); i.hasNext(); ) {
|
for (Entry<String, Object> entry : root.entrySet()) {
|
||||||
Map.Entry<String, Object> entry = i.next();
|
|
||||||
|
|
||||||
// Output comment, if present
|
// Output comment, if present
|
||||||
String comment = comments.get(entry.getKey());
|
String comment = comments.get(entry.getKey());
|
||||||
if (comment != null) {
|
if (comment != null) {
|
||||||
@ -204,13 +201,13 @@ public class YAMLProcessor extends YAMLNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException ignored) {
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
if (stream != null) {
|
if (stream != null) {
|
||||||
stream.close();
|
stream.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {}
|
} catch (IOException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -241,7 +238,7 @@ public class YAMLProcessor extends YAMLNode {
|
|||||||
* Returns a root-level comment.
|
* Returns a root-level comment.
|
||||||
*
|
*
|
||||||
* @param key the property key
|
* @param key the property key
|
||||||
* @return the comment or <code>null</code>
|
* @return the comment or {@code null}
|
||||||
*/
|
*/
|
||||||
public String getComment(String key) {
|
public String getComment(String key) {
|
||||||
return comments.get(key);
|
return comments.get(key);
|
||||||
@ -259,7 +256,7 @@ public class YAMLProcessor extends YAMLNode {
|
|||||||
* Set a root-level comment.
|
* Set a root-level comment.
|
||||||
*
|
*
|
||||||
* @param key the property key
|
* @param key the property key
|
||||||
* @param comment the comment. May be <code>null</code>, in which case the comment
|
* @param comment the comment. May be {@code null}, in which case the comment
|
||||||
* is removed.
|
* is removed.
|
||||||
*/
|
*/
|
||||||
public void setComment(String key, String... comment) {
|
public void setComment(String key, String... comment) {
|
||||||
@ -300,7 +297,8 @@ public class YAMLProcessor extends YAMLNode {
|
|||||||
/**
|
/**
|
||||||
* This method returns an empty ConfigurationNode for using as a
|
* This method returns an empty ConfigurationNode for using as a
|
||||||
* default in methods that select a node from a node list.
|
* default in methods that select a node from a node list.
|
||||||
* @return
|
*
|
||||||
|
* @return a node
|
||||||
*/
|
*/
|
||||||
public static YAMLNode getEmptyNode(boolean writeDefaults) {
|
public static YAMLNode getEmptyNode(boolean writeDefaults) {
|
||||||
return new YAMLNode(new LinkedHashMap<String, Object>(), writeDefaults);
|
return new YAMLNode(new LinkedHashMap<String, Object>(), writeDefaults);
|
||||||
@ -321,12 +319,14 @@ public class YAMLProcessor extends YAMLNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class FancyRepresenter extends Representer {
|
private static class FancyRepresenter extends Representer {
|
||||||
public FancyRepresenter() {
|
private FancyRepresenter() {
|
||||||
this.nullRepresenter = new Represent() {
|
this.nullRepresenter = new Represent() {
|
||||||
|
@Override
|
||||||
public Node representData(Object o) {
|
public Node representData(Object o) {
|
||||||
return representScalar(Tag.NULL, "");
|
return representScalar(Tag.NULL, "");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,8 @@ package com.sk89q.util.yaml;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* YAMLProcessor exception.
|
* YAMLProcessor exception.
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
*/
|
||||||
public class YAMLProcessorException extends Exception {
|
public class YAMLProcessorException extends Exception {
|
||||||
private static final long serialVersionUID = -2442886939908724203L;
|
|
||||||
|
|
||||||
public YAMLProcessorException() {
|
public YAMLProcessorException() {
|
||||||
super();
|
super();
|
||||||
@ -34,4 +31,5 @@ public class YAMLProcessorException extends Exception {
|
|||||||
public YAMLProcessorException(String msg) {
|
public YAMLProcessorException(String msg) {
|
||||||
super(msg);
|
super(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ public class CuboidClipboard {
|
|||||||
final int shiftX = sizeRotated.getX() < 0 ? -sizeRotated.getBlockX() - 1 : 0;
|
final int shiftX = sizeRotated.getX() < 0 ? -sizeRotated.getBlockX() - 1 : 0;
|
||||||
final int shiftZ = sizeRotated.getZ() < 0 ? -sizeRotated.getBlockZ() - 1 : 0;
|
final int shiftZ = sizeRotated.getZ() < 0 ? -sizeRotated.getBlockZ() - 1 : 0;
|
||||||
|
|
||||||
final BaseBlock newData[][][] = new BaseBlock
|
final BaseBlock[][][] newData = new BaseBlock
|
||||||
[Math.abs(sizeRotated.getBlockX())]
|
[Math.abs(sizeRotated.getBlockX())]
|
||||||
[Math.abs(sizeRotated.getBlockY())]
|
[Math.abs(sizeRotated.getBlockY())]
|
||||||
[Math.abs(sizeRotated.getBlockZ())];
|
[Math.abs(sizeRotated.getBlockZ())];
|
||||||
@ -476,8 +476,9 @@ public class CuboidClipboard {
|
|||||||
* @param position the point, relative to the origin of the copy (0, 0, 0) and not to the actual copy origin
|
* @param position the point, relative to the origin of the copy (0, 0, 0) and not to the actual copy origin
|
||||||
* @return air, if this block was outside the (non-cuboid) selection while copying
|
* @return air, if this block was outside the (non-cuboid) selection while copying
|
||||||
* @throws ArrayIndexOutOfBoundsException if the position is outside the bounds of the CuboidClipboard
|
* @throws ArrayIndexOutOfBoundsException if the position is outside the bounds of the CuboidClipboard
|
||||||
* @deprecated Use {@link #getBlock(Vector)} instead
|
* @deprecated use {@link #getBlock(Vector)} instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public BaseBlock getPoint(Vector position) throws ArrayIndexOutOfBoundsException {
|
public BaseBlock getPoint(Vector position) throws ArrayIndexOutOfBoundsException {
|
||||||
final BaseBlock block = getBlock(position);
|
final BaseBlock block = getBlock(position);
|
||||||
if (block == null) {
|
if (block == null) {
|
||||||
|
@ -80,6 +80,8 @@ import com.sk89q.worldedit.world.biome.BaseBiome;
|
|||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
@ -96,6 +98,8 @@ import static com.sk89q.worldedit.regions.Regions.*;
|
|||||||
@SuppressWarnings("FieldCanBeLocal")
|
@SuppressWarnings("FieldCanBeLocal")
|
||||||
public class EditSession implements Extent {
|
public class EditSession implements Extent {
|
||||||
|
|
||||||
|
private static final Logger log = Logger.getLogger(EditSession.class.getCanonicalName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by {@link #setBlock(Vector, BaseBlock, Stage)} to
|
* Used by {@link #setBlock(Vector, BaseBlock, Stage)} to
|
||||||
* determine which {@link Extent}s should be bypassed.
|
* determine which {@link Extent}s should be bypassed.
|
||||||
@ -317,8 +321,9 @@ public class EditSession implements Extent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether fast mode is enabled.
|
* Set whether fast mode is enabled.
|
||||||
* </p>
|
*
|
||||||
* Fast mode may skip lighting checks or adjacent block notification.
|
* <p>Fast mode may skip lighting checks or adjacent block
|
||||||
|
* notification.</p>
|
||||||
*
|
*
|
||||||
* @param enabled true to enable
|
* @param enabled true to enable
|
||||||
*/
|
*/
|
||||||
@ -330,13 +335,14 @@ public class EditSession implements Extent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return fast mode status.
|
* Return fast mode status.
|
||||||
* </p>
|
*
|
||||||
* Fast mode may skip lighting checks or adjacent block notification.
|
* <p>Fast mode may skip lighting checks or adjacent block
|
||||||
|
* notification.</p>
|
||||||
*
|
*
|
||||||
* @return true if enabled
|
* @return true if enabled
|
||||||
*/
|
*/
|
||||||
public boolean hasFastMode() {
|
public boolean hasFastMode() {
|
||||||
return fastModeExtent != null ? fastModeExtent.isEnabled() : false;
|
return fastModeExtent != null && fastModeExtent.isEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -369,8 +375,8 @@ public class EditSession implements Extent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of blocks changed, including repeated block changes.
|
* Get the number of blocks changed, including repeated block changes.
|
||||||
* </p>
|
*
|
||||||
* This number may not be accurate.
|
* <p>This number may not be accurate.</p>
|
||||||
*
|
*
|
||||||
* @return the number of block changes
|
* @return the number of block changes
|
||||||
*/
|
*/
|
||||||
@ -1486,15 +1492,14 @@ public class EditSession implements Extent {
|
|||||||
/**
|
/**
|
||||||
* Makes a pyramid.
|
* Makes a pyramid.
|
||||||
*
|
*
|
||||||
* @param pos
|
* @param position a position
|
||||||
* @param block
|
* @param block a block
|
||||||
* @param size
|
* @param size size of pyramid
|
||||||
* @param filled
|
* @param filled true if filled
|
||||||
* @return number of blocks changed
|
* @return number of blocks changed
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException
|
||||||
*/
|
*/
|
||||||
public int makePyramid(Vector pos, Pattern block, int size,
|
public int makePyramid(Vector position, Pattern block, int size, boolean filled) throws MaxChangedBlocksException {
|
||||||
boolean filled) throws MaxChangedBlocksException {
|
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
|
|
||||||
int height = size;
|
int height = size;
|
||||||
@ -1506,16 +1511,16 @@ public class EditSession implements Extent {
|
|||||||
|
|
||||||
if ((filled && z <= size && x <= size) || z == size || x == size) {
|
if ((filled && z <= size && x <= size) || z == size || x == size) {
|
||||||
|
|
||||||
if (setBlock(pos.add(x, y, z), block)) {
|
if (setBlock(position.add(x, y, z), block)) {
|
||||||
++affected;
|
++affected;
|
||||||
}
|
}
|
||||||
if (setBlock(pos.add(-x, y, z), block)) {
|
if (setBlock(position.add(-x, y, z), block)) {
|
||||||
++affected;
|
++affected;
|
||||||
}
|
}
|
||||||
if (setBlock(pos.add(x, y, -z), block)) {
|
if (setBlock(position.add(x, y, -z), block)) {
|
||||||
++affected;
|
++affected;
|
||||||
}
|
}
|
||||||
if (setBlock(pos.add(-x, y, -z), block)) {
|
if (setBlock(position.add(-x, y, -z), block)) {
|
||||||
++affected;
|
++affected;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1527,21 +1532,21 @@ public class EditSession implements Extent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thaw.
|
* Thaw blocks in a radius.
|
||||||
*
|
*
|
||||||
* @param pos
|
* @param position the position
|
||||||
* @param radius
|
* @param radius the radius
|
||||||
* @return number of blocks affected
|
* @return number of blocks affected
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException
|
||||||
*/
|
*/
|
||||||
public int thaw(Vector pos, double radius)
|
public int thaw(Vector position, double radius)
|
||||||
throws MaxChangedBlocksException {
|
throws MaxChangedBlocksException {
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
double radiusSq = radius * radius;
|
double radiusSq = radius * radius;
|
||||||
|
|
||||||
int ox = pos.getBlockX();
|
int ox = position.getBlockX();
|
||||||
int oy = pos.getBlockY();
|
int oy = position.getBlockY();
|
||||||
int oz = pos.getBlockZ();
|
int oz = position.getBlockZ();
|
||||||
|
|
||||||
BaseBlock air = new BaseBlock(0);
|
BaseBlock air = new BaseBlock(0);
|
||||||
BaseBlock water = new BaseBlock(BlockID.STATIONARY_WATER);
|
BaseBlock water = new BaseBlock(BlockID.STATIONARY_WATER);
|
||||||
@ -1549,7 +1554,7 @@ public class EditSession implements Extent {
|
|||||||
int ceilRadius = (int) Math.ceil(radius);
|
int ceilRadius = (int) Math.ceil(radius);
|
||||||
for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
|
for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
|
||||||
for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
|
for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
|
||||||
if ((new Vector(x, oy, z)).distanceSq(pos) > radiusSq) {
|
if ((new Vector(x, oy, z)).distanceSq(position) > radiusSq) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1586,21 +1591,20 @@ public class EditSession implements Extent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make snow.
|
* Make snow in a radius.
|
||||||
*
|
*
|
||||||
* @param pos
|
* @param position a position
|
||||||
* @param radius
|
* @param radius a radius
|
||||||
* @return number of blocks affected
|
* @return number of blocks affected
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException
|
||||||
*/
|
*/
|
||||||
public int simulateSnow(Vector pos, double radius)
|
public int simulateSnow(Vector position, double radius) throws MaxChangedBlocksException {
|
||||||
throws MaxChangedBlocksException {
|
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
double radiusSq = radius * radius;
|
double radiusSq = radius * radius;
|
||||||
|
|
||||||
int ox = pos.getBlockX();
|
int ox = position.getBlockX();
|
||||||
int oy = pos.getBlockY();
|
int oy = position.getBlockY();
|
||||||
int oz = pos.getBlockZ();
|
int oz = position.getBlockZ();
|
||||||
|
|
||||||
BaseBlock ice = new BaseBlock(BlockID.ICE);
|
BaseBlock ice = new BaseBlock(BlockID.ICE);
|
||||||
BaseBlock snow = new BaseBlock(BlockID.SNOW);
|
BaseBlock snow = new BaseBlock(BlockID.SNOW);
|
||||||
@ -1608,7 +1612,7 @@ public class EditSession implements Extent {
|
|||||||
int ceilRadius = (int) Math.ceil(radius);
|
int ceilRadius = (int) Math.ceil(radius);
|
||||||
for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
|
for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
|
||||||
for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
|
for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
|
||||||
if ((new Vector(x, oy, z)).distanceSq(pos) > radiusSq) {
|
if ((new Vector(x, oy, z)).distanceSq(position) > radiusSq) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1651,44 +1655,43 @@ public class EditSession implements Extent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Green.
|
* Make dirt green.
|
||||||
*
|
*
|
||||||
* @param pos
|
* @param position a position
|
||||||
* @param radius
|
* @param radius a radius
|
||||||
* @return number of blocks affected
|
* @return number of blocks affected
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException
|
||||||
* @deprecated Use {@link #green(Vector, double, boolean)}.
|
* @deprecated Use {@link #green(Vector, double, boolean)}.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public int green(Vector pos, double radius)
|
public int green(Vector position, double radius) throws MaxChangedBlocksException {
|
||||||
throws MaxChangedBlocksException {
|
return green(position, radius, true);
|
||||||
return green(pos, radius, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Green.
|
* Make dirt green.
|
||||||
*
|
*
|
||||||
* @param pos
|
* @param position a position
|
||||||
* @param radius
|
* @param radius a radius
|
||||||
* @param onlyNormalDirt only affect normal dirt (data value 0)
|
* @param onlyNormalDirt only affect normal dirt (data value 0)
|
||||||
* @return number of blocks affected
|
* @return number of blocks affected
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException
|
||||||
*/
|
*/
|
||||||
public int green(Vector pos, double radius, boolean onlyNormalDirt)
|
public int green(Vector position, double radius, boolean onlyNormalDirt)
|
||||||
throws MaxChangedBlocksException {
|
throws MaxChangedBlocksException {
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
final double radiusSq = radius * radius;
|
final double radiusSq = radius * radius;
|
||||||
|
|
||||||
final int ox = pos.getBlockX();
|
final int ox = position.getBlockX();
|
||||||
final int oy = pos.getBlockY();
|
final int oy = position.getBlockY();
|
||||||
final int oz = pos.getBlockZ();
|
final int oz = position.getBlockZ();
|
||||||
|
|
||||||
final BaseBlock grass = new BaseBlock(BlockID.GRASS);
|
final BaseBlock grass = new BaseBlock(BlockID.GRASS);
|
||||||
|
|
||||||
final int ceilRadius = (int) Math.ceil(radius);
|
final int ceilRadius = (int) Math.ceil(radius);
|
||||||
for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
|
for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
|
||||||
for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
|
for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
|
||||||
if ((new Vector(x, oy, z)).distanceSq(pos) > radiusSq) {
|
if ((new Vector(x, oy, z)).distanceSq(position) > radiusSq) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1758,23 +1761,22 @@ public class EditSession implements Extent {
|
|||||||
/**
|
/**
|
||||||
* Makes a forest.
|
* Makes a forest.
|
||||||
*
|
*
|
||||||
* @param basePos
|
* @param basePosition a position
|
||||||
* @param size
|
* @param size a size
|
||||||
* @param density
|
* @param density between 0 and 1, inclusive
|
||||||
* @param treeGenerator
|
* @param treeGenerator the tree genreator
|
||||||
* @return number of trees created
|
* @return number of trees created
|
||||||
* @throws MaxChangedBlocksException
|
* @throws MaxChangedBlocksException
|
||||||
*/
|
*/
|
||||||
public int makeForest(Vector basePos, int size, double density,
|
public int makeForest(Vector basePosition, int size, double density, TreeGenerator treeGenerator) throws MaxChangedBlocksException {
|
||||||
TreeGenerator treeGenerator) throws MaxChangedBlocksException {
|
|
||||||
int affected = 0;
|
int affected = 0;
|
||||||
|
|
||||||
for (int x = basePos.getBlockX() - size; x <= basePos.getBlockX()
|
for (int x = basePosition.getBlockX() - size; x <= basePosition.getBlockX()
|
||||||
+ size; ++x) {
|
+ size; ++x) {
|
||||||
for (int z = basePos.getBlockZ() - size; z <= basePos.getBlockZ()
|
for (int z = basePosition.getBlockZ() - size; z <= basePosition.getBlockZ()
|
||||||
+ size; ++z) {
|
+ size; ++z) {
|
||||||
// Don't want to be in the ground
|
// Don't want to be in the ground
|
||||||
if (!getBlock(new Vector(x, basePos.getBlockY(), z)).isAir()) {
|
if (!getBlock(new Vector(x, basePosition.getBlockY(), z)).isAir()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// The gods don't want a tree here
|
// The gods don't want a tree here
|
||||||
@ -1782,7 +1784,7 @@ public class EditSession implements Extent {
|
|||||||
continue;
|
continue;
|
||||||
} // def 0.05
|
} // def 0.05
|
||||||
|
|
||||||
for (int y = basePos.getBlockY(); y >= basePos.getBlockY() - 10; --y) {
|
for (int y = basePosition.getBlockY(); y >= basePosition.getBlockY() - 10; --y) {
|
||||||
// Check if we hit the ground
|
// Check if we hit the ground
|
||||||
int t = getBlock(new Vector(x, y, z)).getType();
|
int t = getBlock(new Vector(x, y, z)).getType();
|
||||||
if (t == BlockID.GRASS || t == BlockID.DIRT) {
|
if (t == BlockID.GRASS || t == BlockID.DIRT) {
|
||||||
@ -1804,8 +1806,8 @@ public class EditSession implements Extent {
|
|||||||
/**
|
/**
|
||||||
* Get the block distribution inside a region.
|
* Get the block distribution inside a region.
|
||||||
*
|
*
|
||||||
* @param region
|
* @param region a region
|
||||||
* @return
|
* @return the results
|
||||||
*/
|
*/
|
||||||
public List<Countable<Integer>> getBlockDistribution(Region region) {
|
public List<Countable<Integer>> getBlockDistribution(Region region) {
|
||||||
List<Countable<Integer>> distribution = new ArrayList<Countable<Integer>>();
|
List<Countable<Integer>> distribution = new ArrayList<Countable<Integer>>();
|
||||||
@ -1862,8 +1864,8 @@ public class EditSession implements Extent {
|
|||||||
/**
|
/**
|
||||||
* Get the block distribution (with data values) inside a region.
|
* Get the block distribution (with data values) inside a region.
|
||||||
*
|
*
|
||||||
* @param region
|
* @param region a region
|
||||||
* @return
|
* @return the results
|
||||||
*/
|
*/
|
||||||
// TODO reduce code duplication - probably during ops-redux
|
// TODO reduce code duplication - probably during ops-redux
|
||||||
public List<Countable<BaseBlock>> getBlockDistributionWithData(Region region) {
|
public List<Countable<BaseBlock>> getBlockDistributionWithData(Region region) {
|
||||||
@ -1942,7 +1944,7 @@ public class EditSession implements Extent {
|
|||||||
|
|
||||||
return new BaseBlock((int) typeVariable.getValue(), (int) dataVariable.getValue());
|
return new BaseBlock((int) typeVariable.getValue(), (int) dataVariable.getValue());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.log(Level.WARNING, "Failed to create shape", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2161,12 +2163,12 @@ public class EditSession implements Extent {
|
|||||||
throws MaxChangedBlocksException {
|
throws MaxChangedBlocksException {
|
||||||
|
|
||||||
Set<Vector> vset = new HashSet<Vector>();
|
Set<Vector> vset = new HashSet<Vector>();
|
||||||
List<Node> nodes = new ArrayList(nodevectors.size());
|
List<Node> nodes = new ArrayList<Node>(nodevectors.size());
|
||||||
|
|
||||||
Interpolation interpol = new KochanekBartelsInterpolation();
|
Interpolation interpol = new KochanekBartelsInterpolation();
|
||||||
|
|
||||||
for (int loop = 0; loop < nodevectors.size(); loop++) {
|
for (Vector nodevector : nodevectors) {
|
||||||
Node n = new Node(nodevectors.get(loop));
|
Node n = new Node(nodevector);
|
||||||
n.setTension(tension);
|
n.setTension(tension);
|
||||||
n.setBias(bias);
|
n.setBias(bias);
|
||||||
n.setContinuity(continuity);
|
n.setContinuity(continuity);
|
||||||
@ -2285,7 +2287,7 @@ public class EditSession implements Extent {
|
|||||||
// TODO: Allow biome setting via a script variable (needs BiomeType<->int mapping)
|
// TODO: Allow biome setting via a script variable (needs BiomeType<->int mapping)
|
||||||
return defaultBiomeType;
|
return defaultBiomeType;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
log.log(Level.WARNING, "Failed to create shape", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2303,11 +2305,11 @@ public class EditSession implements Extent {
|
|||||||
PlayerDirection.DOWN.vector(),
|
PlayerDirection.DOWN.vector(),
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final double lengthSq(double x, double y, double z) {
|
private static double lengthSq(double x, double y, double z) {
|
||||||
return (x * x) + (y * y) + (z * z);
|
return (x * x) + (y * y) + (z * z);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final double lengthSq(double x, double z) {
|
private static double lengthSq(double x, double z) {
|
||||||
return (x * x) + (z * z);
|
return (x * x) + (z * z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ public class Location {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "World: " + world.getName() + ", Coordinates: " + position.toString()
|
return "World: " + world.getName() + ", Coordinates: " + position
|
||||||
+ ", Yaw: " + yaw + ", Pitch: " + pitch;
|
+ ", Yaw: " + yaw + ", Pitch: " + pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,9 +39,9 @@ public enum PlayerDirection {
|
|||||||
UP(new Vector(0, 1, 0), new Vector(0, 0, 1), true),
|
UP(new Vector(0, 1, 0), new Vector(0, 0, 1), true),
|
||||||
DOWN(new Vector(0, -1, 0), new Vector(0, 0, 1), true);
|
DOWN(new Vector(0, -1, 0), new Vector(0, 0, 1), true);
|
||||||
|
|
||||||
private Vector dir;
|
private final Vector dir;
|
||||||
private Vector leftDir;
|
private final Vector leftDir;
|
||||||
private boolean isOrthogonal;
|
private final boolean isOrthogonal;
|
||||||
|
|
||||||
PlayerDirection(Vector vec, Vector leftDir, boolean isOrthogonal) {
|
PlayerDirection(Vector vec, Vector leftDir, boolean isOrthogonal) {
|
||||||
this.dir = vec;
|
this.dir = vec;
|
||||||
|
@ -49,9 +49,9 @@ public enum VectorFace {
|
|||||||
BELOW_EAST(DOWN, EAST),
|
BELOW_EAST(DOWN, EAST),
|
||||||
SELF(0, 0, 0);
|
SELF(0, 0, 0);
|
||||||
|
|
||||||
private int modX;
|
private final int modX;
|
||||||
private int modY;
|
private final int modY;
|
||||||
private int modZ;
|
private final int modZ;
|
||||||
|
|
||||||
private VectorFace(final int modX, final int modY, final int modZ) {
|
private VectorFace(final int modX, final int modY, final int modZ) {
|
||||||
this.modX = modX;
|
this.modX = modX;
|
||||||
|
@ -62,6 +62,7 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
@ -761,7 +762,7 @@ public class WorldEdit {
|
|||||||
} catch (ScriptException e) {
|
} catch (ScriptException e) {
|
||||||
player.printError("Failed to execute:");
|
player.printError("Failed to execute:");
|
||||||
player.printRaw(e.getMessage());
|
player.printRaw(e.getMessage());
|
||||||
e.printStackTrace();
|
logger.log(Level.WARNING, "Failed to execute script", e);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (WorldEditException e) {
|
} catch (WorldEditException e) {
|
||||||
@ -769,7 +770,7 @@ public class WorldEdit {
|
|||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
player.printError("Failed to execute (see console):");
|
player.printError("Failed to execute (see console):");
|
||||||
player.printRaw(e.getClass().getCanonicalName());
|
player.printRaw(e.getClass().getCanonicalName());
|
||||||
e.printStackTrace();
|
logger.log(Level.WARNING, "Failed to execute script", e);
|
||||||
} finally {
|
} finally {
|
||||||
for (EditSession editSession : scriptContext.getEditSessions()) {
|
for (EditSession editSession : scriptContext.getEditSessions()) {
|
||||||
editSession.flushQueue();
|
editSession.flushQueue();
|
||||||
|
@ -25,20 +25,19 @@ import com.sk89q.worldedit.world.World;
|
|||||||
/**
|
/**
|
||||||
* @deprecated Use {@link com.sk89q.worldedit.util.Location} wherever possible
|
* @deprecated Use {@link com.sk89q.worldedit.util.Location} wherever possible
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class WorldVector extends Vector {
|
public class WorldVector extends Vector {
|
||||||
/**
|
|
||||||
* Represents the world.
|
|
||||||
*/
|
|
||||||
private LocalWorld world;
|
private LocalWorld world;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the Vector object.
|
* Construct the Vector object.
|
||||||
*
|
*
|
||||||
* @param world
|
* @param world a world
|
||||||
* @param x
|
* @param x the X coordinate
|
||||||
* @param y
|
* @param y the Y coordinate
|
||||||
* @param z
|
* @param z the Z coordinate
|
||||||
*/
|
*/
|
||||||
public WorldVector(LocalWorld world, double x, double y, double z) {
|
public WorldVector(LocalWorld world, double x, double y, double z) {
|
||||||
super(x, y, z);
|
super(x, y, z);
|
||||||
@ -48,10 +47,10 @@ public class WorldVector extends Vector {
|
|||||||
/**
|
/**
|
||||||
* Construct the Vector object.
|
* Construct the Vector object.
|
||||||
*
|
*
|
||||||
* @param world
|
* @param world a world
|
||||||
* @param x
|
* @param x the X coordinate
|
||||||
* @param y
|
* @param y the Y coordinate
|
||||||
* @param z
|
* @param z the Z coordinate
|
||||||
*/
|
*/
|
||||||
public WorldVector(LocalWorld world, int x, int y, int z) {
|
public WorldVector(LocalWorld world, int x, int y, int z) {
|
||||||
super(x, y, z);
|
super(x, y, z);
|
||||||
@ -61,10 +60,10 @@ public class WorldVector extends Vector {
|
|||||||
/**
|
/**
|
||||||
* Construct the Vector object.
|
* Construct the Vector object.
|
||||||
*
|
*
|
||||||
* @param world
|
* @param world a world
|
||||||
* @param x
|
* @param x the X coordinate
|
||||||
* @param y
|
* @param y the Y coordinate
|
||||||
* @param z
|
* @param z the Z coordinate
|
||||||
*/
|
*/
|
||||||
public WorldVector(LocalWorld world, float x, float y, float z) {
|
public WorldVector(LocalWorld world, float x, float y, float z) {
|
||||||
super(x, y, z);
|
super(x, y, z);
|
||||||
@ -74,18 +73,18 @@ public class WorldVector extends Vector {
|
|||||||
/**
|
/**
|
||||||
* Construct the Vector object.
|
* Construct the Vector object.
|
||||||
*
|
*
|
||||||
* @param world
|
* @param world a world
|
||||||
* @param pt
|
* @param other the position to copy
|
||||||
*/
|
*/
|
||||||
public WorldVector(LocalWorld world, Vector pt) {
|
public WorldVector(LocalWorld world, Vector other) {
|
||||||
super(pt);
|
super(other);
|
||||||
this.world = world;
|
this.world = world;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the Vector object.
|
* Construct the Vector object.
|
||||||
*
|
*
|
||||||
* @param world
|
* @param world a world
|
||||||
*/
|
*/
|
||||||
public WorldVector(LocalWorld world) {
|
public WorldVector(LocalWorld world) {
|
||||||
super();
|
super();
|
||||||
@ -104,7 +103,7 @@ public class WorldVector extends Vector {
|
|||||||
/**
|
/**
|
||||||
* Get the world.
|
* Get the world.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the world
|
||||||
*/
|
*/
|
||||||
public LocalWorld getWorld() {
|
public LocalWorld getWorld() {
|
||||||
return world;
|
return world;
|
||||||
@ -113,10 +112,10 @@ public class WorldVector extends Vector {
|
|||||||
/**
|
/**
|
||||||
* Get a block point from a point.
|
* Get a block point from a point.
|
||||||
*
|
*
|
||||||
* @param world
|
* @param world a world
|
||||||
* @param x
|
* @param x the X coordinate
|
||||||
* @param y
|
* @param y the Y coordinate
|
||||||
* @param z
|
* @param z the Z coordinate
|
||||||
* @return point
|
* @return point
|
||||||
*/
|
*/
|
||||||
public static WorldVector toBlockPoint(LocalWorld world, double x, double y,
|
public static WorldVector toBlockPoint(LocalWorld world, double x, double y,
|
||||||
@ -136,7 +135,7 @@ public class WorldVector extends Vector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return this object as a new preferred <code>Location</code>
|
* Return this object as a new preferred {@code Location}
|
||||||
* object.
|
* object.
|
||||||
*
|
*
|
||||||
* @return a new location object
|
* @return a new location object
|
||||||
|
@ -56,12 +56,6 @@ public class WorldVector2D extends Vector2D {
|
|||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if another object is equivalent.
|
|
||||||
*
|
|
||||||
* @param obj
|
|
||||||
* @return whether the other object is equivalent
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (!(obj instanceof WorldVector2D)) {
|
if (!(obj instanceof WorldVector2D)) {
|
||||||
|
@ -22,71 +22,32 @@ package com.sk89q.worldedit;
|
|||||||
/**
|
/**
|
||||||
* @deprecated Use {@link com.sk89q.worldedit.util.Location} wherever possible
|
* @deprecated Use {@link com.sk89q.worldedit.util.Location} wherever possible
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class WorldVectorFace extends WorldVector {
|
public class WorldVectorFace extends WorldVector {
|
||||||
|
|
||||||
private VectorFace face;
|
private VectorFace face;
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct the Vector object.
|
|
||||||
*
|
|
||||||
* @param world
|
|
||||||
* @param x
|
|
||||||
* @param y
|
|
||||||
* @param z
|
|
||||||
* @param face
|
|
||||||
*/
|
|
||||||
public WorldVectorFace(LocalWorld world, double x, double y, double z, VectorFace face) {
|
public WorldVectorFace(LocalWorld world, double x, double y, double z, VectorFace face) {
|
||||||
super(world, x, y, z);
|
super(world, x, y, z);
|
||||||
this.face = face;
|
this.face = face;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct the Vector object.
|
|
||||||
*
|
|
||||||
* @param world
|
|
||||||
* @param x
|
|
||||||
* @param y
|
|
||||||
* @param z
|
|
||||||
* @param face
|
|
||||||
*/
|
|
||||||
public WorldVectorFace(LocalWorld world, int x, int y, int z, VectorFace face) {
|
public WorldVectorFace(LocalWorld world, int x, int y, int z, VectorFace face) {
|
||||||
super(world, x, y, z);
|
super(world, x, y, z);
|
||||||
this.face = face;
|
this.face = face;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct the Vector object.
|
|
||||||
*
|
|
||||||
* @param world
|
|
||||||
* @param x
|
|
||||||
* @param y
|
|
||||||
* @param z
|
|
||||||
* @param face
|
|
||||||
*/
|
|
||||||
public WorldVectorFace(LocalWorld world, float x, float y, float z, VectorFace face) {
|
public WorldVectorFace(LocalWorld world, float x, float y, float z, VectorFace face) {
|
||||||
super(world, x, y, z);
|
super(world, x, y, z);
|
||||||
this.face = face;
|
this.face = face;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct the Vector object.
|
|
||||||
*
|
|
||||||
* @param world
|
|
||||||
* @param pt
|
|
||||||
* @param face
|
|
||||||
*/
|
|
||||||
public WorldVectorFace(LocalWorld world, Vector pt, VectorFace face) {
|
public WorldVectorFace(LocalWorld world, Vector pt, VectorFace face) {
|
||||||
super(world, pt);
|
super(world, pt);
|
||||||
this.face = face;
|
this.face = face;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct the Vector object.
|
|
||||||
*
|
|
||||||
* @param world
|
|
||||||
* @param face
|
|
||||||
*/
|
|
||||||
public WorldVectorFace(LocalWorld world, VectorFace face) {
|
public WorldVectorFace(LocalWorld world, VectorFace face) {
|
||||||
super(world);
|
super(world);
|
||||||
this.face = face;
|
this.face = face;
|
||||||
@ -95,7 +56,7 @@ public class WorldVectorFace extends WorldVector {
|
|||||||
/**
|
/**
|
||||||
* Get the face.
|
* Get the face.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the face
|
||||||
*/
|
*/
|
||||||
public VectorFace getFace() {
|
public VectorFace getFace() {
|
||||||
return face;
|
return face;
|
||||||
@ -104,7 +65,7 @@ public class WorldVectorFace extends WorldVector {
|
|||||||
/**
|
/**
|
||||||
* Get the WorldVector adjacent to this WorldVectorFace.
|
* Get the WorldVector adjacent to this WorldVectorFace.
|
||||||
*
|
*
|
||||||
* @return
|
* @return the face vector
|
||||||
*/
|
*/
|
||||||
public WorldVector getFaceVector() {
|
public WorldVector getFaceVector() {
|
||||||
return new WorldVector(getWorld(),
|
return new WorldVector(getWorld(),
|
||||||
@ -120,7 +81,7 @@ public class WorldVectorFace extends WorldVector {
|
|||||||
* @param world the world in which the resulting vector should lie
|
* @param world the world in which the resulting vector should lie
|
||||||
* @param vector the original vector
|
* @param vector the original vector
|
||||||
* @param face the direction in which the face should lie
|
* @param face the direction in which the face should lie
|
||||||
* @return
|
* @return a face
|
||||||
*/
|
*/
|
||||||
public static WorldVectorFace getWorldVectorFace(LocalWorld world, Vector vector, Vector face) {
|
public static WorldVectorFace getWorldVectorFace(LocalWorld world, Vector vector, Vector face) {
|
||||||
if (vector == null || face == null) return null;
|
if (vector == null || face == null) return null;
|
||||||
|
Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden Mehr anzeigen
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren