Update for recent SpoutAPI changes

This commit is contained in:
zml2008 2012-03-23 21:37:59 -07:00
parent 97c370549f
commit 54eed713ab
14 changed files with 134 additions and 53 deletions

View File

@ -1,7 +1,6 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010, 2011 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -15,7 +14,10 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;

View File

@ -1,3 +1,21 @@
/*
* WorldEdit
* Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;
import org.spout.api.generator.biome.BiomeType; import org.spout.api.generator.biome.BiomeType;

View File

@ -1,3 +1,21 @@
/*
* WorldEdit
* Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,7 +1,6 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -15,7 +14,10 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;

View File

@ -1,7 +1,6 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -15,7 +14,10 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;
@ -31,7 +33,8 @@ import com.sk89q.worldedit.cui.CUIEvent;
import org.spout.api.entity.Entity; import org.spout.api.entity.Entity;
import org.spout.api.geo.discrete.Point; import org.spout.api.geo.discrete.Point;
import org.spout.api.inventory.ItemStack; import org.spout.api.inventory.ItemStack;
import org.spout.api.material.MaterialData; import org.spout.api.material.MaterialRegistry;
import org.spout.api.material.source.MaterialData;
import org.spout.api.player.Player; import org.spout.api.player.Player;
public class SpoutPlayer extends LocalPlayer { public class SpoutPlayer extends LocalPlayer {
@ -75,7 +78,7 @@ public class SpoutPlayer extends LocalPlayer {
@Override @Override
public void giveItem(int type, int amt) { public void giveItem(int type, int amt) {
player.getEntity().getInventory().addItem(new ItemStack(MaterialData.getMaterial((short)type), amt)); player.getEntity().getInventory().addItem(new ItemStack(MaterialRegistry.get((short) type), amt));
} }
@Override @Override

View File

@ -1,7 +1,6 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -15,7 +14,10 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;
@ -30,7 +32,7 @@ import com.sk89q.worldedit.blocks.BlockID;
import org.spout.api.inventory.Inventory; import org.spout.api.inventory.Inventory;
import org.spout.api.inventory.ItemStack; import org.spout.api.inventory.ItemStack;
import org.spout.api.material.Material; import org.spout.api.material.Material;
import org.spout.api.material.MaterialData; import org.spout.api.material.MaterialRegistry;
import org.spout.api.player.Player; import org.spout.api.player.Player;
public class SpoutPlayerBlockBag extends BlockBag { public class SpoutPlayerBlockBag extends BlockBag {
@ -81,7 +83,10 @@ public class SpoutPlayerBlockBag extends BlockBag {
final short damage = item.getDamage(); final short damage = item.getDamage();
int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1; int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
assert(amount == 1); assert(amount == 1);
final Material mat = MaterialData.getMaterial(id, damage); Material mat = MaterialRegistry.get(id);
if (mat.hasSubMaterials()) {
mat = mat.getSubMaterial(damage);
}
if (id == BlockID.AIR) { if (id == BlockID.AIR) {
throw new IllegalArgumentException("Can't fetch air block"); throw new IllegalArgumentException("Can't fetch air block");
@ -132,9 +137,12 @@ public class SpoutPlayerBlockBag extends BlockBag {
*/ */
@Override @Override
public void storeItem(BaseItem item) throws BlockBagException { public void storeItem(BaseItem item) throws BlockBagException {
final int id = item.getType(); final short id = (short) item.getType();
final short damage = item.getDamage(); final short damage = item.getDamage();
final Material mat = MaterialData.getMaterial((short) id, damage); Material mat = MaterialRegistry.get(id);
if (mat.hasSubMaterials()) {
mat = mat.getSubMaterial(damage);
}
int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1; int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
assert(amount <= mat.getMaxStackSize()); assert(amount <= mat.getMaxStackSize());

View File

@ -1,7 +1,6 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -15,7 +14,10 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;
@ -29,7 +31,7 @@ import org.spout.api.Game;
import org.spout.api.Spout; import org.spout.api.Spout;
import org.spout.api.geo.World; import org.spout.api.geo.World;
import org.spout.api.material.Material; import org.spout.api.material.Material;
import org.spout.api.material.MaterialData; import org.spout.api.material.MaterialRegistry;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
@ -51,7 +53,7 @@ public class SpoutServerInterface extends ServerInterface {
@Override @Override
public int resolveItem(String name) { public int resolveItem(String name) {
Material mat = MaterialData.getMaterial(name); Material mat = MaterialRegistry.get(name);
return mat == null ? 0 : mat.getId(); return mat == null ? 0 : mat.getId();
} }

View File

@ -1,7 +1,6 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -15,7 +14,10 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;

View File

@ -1,7 +1,6 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -15,7 +14,10 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;
@ -37,7 +39,9 @@ import org.spout.api.generator.biome.BiomeGenerator;
import org.spout.api.geo.World; import org.spout.api.geo.World;
import org.spout.api.geo.cuboid.Chunk; import org.spout.api.geo.cuboid.Chunk;
import org.spout.api.inventory.ItemStack; import org.spout.api.inventory.ItemStack;
import org.spout.api.material.MaterialData; import org.spout.api.material.BlockMaterial;
import org.spout.api.material.Material;
import org.spout.api.material.MaterialRegistry;
import org.spout.api.math.Vector3; import org.spout.api.math.Vector3;
import org.spout.vanilla.controller.object.Item; import org.spout.vanilla.controller.object.Item;
import org.spout.vanilla.controller.object.falling.PrimedTnt; import org.spout.vanilla.controller.object.falling.PrimedTnt;
@ -84,7 +88,11 @@ public class SpoutWorld extends LocalWorld {
*/ */
@Override @Override
public boolean setBlockType(Vector pt, int type) { public boolean setBlockType(Vector pt, int type) {
return world.setBlockId(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), (short) type, WorldEditPlugin.getInstance()); Material mat = MaterialRegistry.get((short) type);
if (mat != null && mat instanceof BlockMaterial) {
return world.setBlockMaterial(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), (BlockMaterial) mat, (short)0, true, WorldEditPlugin.getInstance());
}
return false;
} }
/** /**
@ -108,7 +116,11 @@ public class SpoutWorld extends LocalWorld {
*/ */
@Override @Override
public boolean setTypeIdAndData(Vector pt, int type, int data) { public boolean setTypeIdAndData(Vector pt, int type, int data) {
return world.setBlockIdAndData(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), (short) type, (short) data, WorldEditPlugin.getInstance()); Material mat = MaterialRegistry.get((short) type);
if (mat != null && mat instanceof BlockMaterial) {
return world.setBlockMaterial(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), (BlockMaterial) mat, (short)data, true, WorldEditPlugin.getInstance());
}
return false;
} }
/** /**
@ -132,7 +144,7 @@ public class SpoutWorld extends LocalWorld {
*/ */
@Override @Override
public int getBlockType(Vector pt) { public int getBlockType(Vector pt) {
return world.getBlockId(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); return world.getBlockMaterial(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getId();
} }
/** /**
@ -143,7 +155,7 @@ public class SpoutWorld extends LocalWorld {
*/ */
@Override @Override
public void setBlockData(Vector pt, int data) { public void setBlockData(Vector pt, int data) {
setTypeIdAndData(pt, world.getBlockId(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()), data); world.setBlockData(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ(), (short) data, true, WorldEditPlugin.getInstance());
} }
/** /**
@ -414,7 +426,11 @@ public class SpoutWorld extends LocalWorld {
*/ */
@Override @Override
public void dropItem(Vector pt, BaseItemStack item) { public void dropItem(Vector pt, BaseItemStack item) {
ItemStack bukkitItem = new ItemStack(MaterialData.getMaterial((short)item.getType(), item.getDamage()), item.getAmount(), item.getDamage()); Material mat = MaterialRegistry.get((short) item.getType());
if (mat.hasSubMaterials()) {
mat = mat.getSubMaterial(item.getDamage());
}
ItemStack bukkitItem = new ItemStack(mat, item.getDamage(), item.getAmount());
world.createAndSpawnEntity(SpoutUtil.toPoint(world, pt), new Item(bukkitItem, new Vector3(pt.getX(), pt.getY(), pt.getZ()))); world.createAndSpawnEntity(SpoutUtil.toPoint(world, pt), new Item(bukkitItem, new Vector3(pt.getX(), pt.getY(), pt.getZ())));
} }
@ -662,7 +678,7 @@ public class SpoutWorld extends LocalWorld {
*/ */
@Override @Override
public boolean isValidBlockType(int type) { public boolean isValidBlockType(int type) {
return MaterialData.getBlock((short)type) != null; return MaterialRegistry.get((short)type) instanceof BlockMaterial;
} }
@Override @Override

View File

@ -1,7 +1,6 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -15,7 +14,10 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;

View File

@ -1,7 +1,6 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -15,7 +14,10 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout; package com.sk89q.worldedit.spout;

View File

@ -1,4 +1,3 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
@ -17,6 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout.selections; package com.sk89q.worldedit.spout.selections;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;

View File

@ -1,4 +1,3 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
@ -17,6 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout.selections; package com.sk89q.worldedit.spout.selections;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;

View File

@ -1,4 +1,3 @@
// $Id$
/* /*
* WorldEdit * WorldEdit
* Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2012 sk89q <http://www.sk89q.com> and contributors
@ -17,6 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
// $Id$
package com.sk89q.worldedit.spout.selections; package com.sk89q.worldedit.spout.selections;
import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector;
@ -27,49 +29,49 @@ import org.spout.api.geo.discrete.Point;
public interface Selection { public interface Selection {
/** /**
* Get the lower point of a region. * Get the lower point of a region.
* *
* @return min. point * @return min. point
*/ */
public Point getMinimumPoint(); public Point getMinimumPoint();
/** /**
* Get the lower point of a region. * Get the lower point of a region.
* *
* @return min. point * @return min. point
*/ */
public Vector getNativeMinimumPoint(); public Vector getNativeMinimumPoint();
/** /**
* Get the upper point of a region. * Get the upper point of a region.
* *
* @return max. point * @return max. point
*/ */
public Point getMaximumPoint(); public Point getMaximumPoint();
/** /**
* Get the upper point of a region. * Get the upper point of a region.
* *
* @return max. point * @return max. point
*/ */
public Vector getNativeMaximumPoint(); public Vector getNativeMaximumPoint();
/** /**
* Get the region selector. This is for internal use. * Get the region selector. This is for internal use.
* *
* @return * @return
*/ */
public RegionSelector getRegionSelector(); public RegionSelector getRegionSelector();
/** /**
* Get the world. * Get the world.
* *
* @return * @return
*/ */
public World getWorld(); public World getWorld();
/** /**
* Get the number of blocks in the region. * Get the number of blocks in the region.
* *
* @return number of blocks * @return number of blocks
*/ */
public int getArea(); public int getArea();
@ -99,7 +101,7 @@ 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 pt
* @return * @return
*/ */
public boolean contains(Point pt); public boolean contains(Point pt);
} }