mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-11 20:13:55 +00:00
Further BaseBlock modernisation
This commit is contained in:
@ -48,7 +48,7 @@ class BukkitBiomeRegistry implements BiomeRegistry {
|
||||
public List<BaseBiome> getBiomes() {
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
if (adapter != null) {
|
||||
List<BaseBiome> biomes = new ArrayList<BaseBiome>();
|
||||
List<BaseBiome> biomes = new ArrayList<>();
|
||||
for (Biome biome : Biome.values()) {
|
||||
int biomeId = adapter.getBiomeId(biome);
|
||||
biomes.add(new BaseBiome(biomeId));
|
||||
@ -65,12 +65,7 @@ class BukkitBiomeRegistry implements BiomeRegistry {
|
||||
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
|
||||
if (adapter != null) {
|
||||
final Biome bukkitBiome = adapter.getBiome(biome.getId());
|
||||
return new BiomeData() {
|
||||
@Override
|
||||
public String getName() {
|
||||
return bukkitBiome.name();
|
||||
}
|
||||
};
|
||||
return bukkitBiome::name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ class BukkitEntity implements Entity {
|
||||
*/
|
||||
BukkitEntity(org.bukkit.entity.Entity entity) {
|
||||
checkNotNull(entity);
|
||||
this.entityRef = new WeakReference<org.bukkit.entity.Entity>(entity);
|
||||
this.entityRef = new WeakReference<>(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -78,8 +78,8 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveItem(int type, int amt) {
|
||||
player.getInventory().addItem(new ItemStack(type, amt));
|
||||
public void giveItem(BaseItemStack itemStack) {
|
||||
player.getInventory().addItem(new ItemStack(itemStack.getLegacyId(), itemStack.getAmount()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,7 +21,8 @@ package com.sk89q.worldedit.bukkit;
|
||||
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.blocks.type.ItemType;
|
||||
import com.sk89q.worldedit.blocks.type.ItemTypes;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
||||
import com.sk89q.worldedit.extent.inventory.BlockBagException;
|
||||
import com.sk89q.worldedit.extent.inventory.OutOfBlocksException;
|
||||
@ -64,13 +65,11 @@ public class BukkitPlayerBlockBag extends BlockBag {
|
||||
|
||||
@Override
|
||||
public void fetchItem(BaseItem item) throws BlockBagException {
|
||||
final int id = item.getLegacyId();
|
||||
final int damage = item.getData();
|
||||
final ItemType id = item.getType();
|
||||
int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
|
||||
assert(amount == 1);
|
||||
boolean usesDamageValue = true;// TODO ItemType.usesDamageValue(id);
|
||||
|
||||
if (id == BlockID.AIR) {
|
||||
if (id == ItemTypes.AIR) {
|
||||
throw new IllegalArgumentException("Can't fetch air block");
|
||||
}
|
||||
|
||||
@ -85,16 +84,12 @@ public class BukkitPlayerBlockBag extends BlockBag {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bukkitItem.getTypeId() != id) {
|
||||
if (bukkitItem.getTypeId() != id.getLegacyId()) {
|
||||
// TODO Fix when bukkit gets not awful
|
||||
// Type id doesn't fit
|
||||
continue;
|
||||
}
|
||||
|
||||
if (usesDamageValue && bukkitItem.getDurability() != damage) {
|
||||
// Damage value doesn't fit.
|
||||
continue;
|
||||
}
|
||||
|
||||
int currentAmount = bukkitItem.getAmount();
|
||||
if (currentAmount < 0) {
|
||||
// Unlimited
|
||||
@ -119,13 +114,11 @@ public class BukkitPlayerBlockBag extends BlockBag {
|
||||
|
||||
@Override
|
||||
public void storeItem(BaseItem item) throws BlockBagException {
|
||||
final int id = item.getLegacyId();
|
||||
final int damage = item.getData();
|
||||
final ItemType id = item.getType();
|
||||
int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
|
||||
assert(amount <= 64);
|
||||
boolean usesDamageValue = true; //TODO ItemType.usesDamageValue(id);
|
||||
|
||||
if (id == BlockID.AIR) {
|
||||
if (id == ItemTypes.AIR) {
|
||||
throw new IllegalArgumentException("Can't store air block");
|
||||
}
|
||||
|
||||
@ -146,16 +139,12 @@ public class BukkitPlayerBlockBag extends BlockBag {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bukkitItem.getTypeId() != id) {
|
||||
if (bukkitItem.getTypeId() != id.getLegacyId()) {
|
||||
// TODO Fix when bukkit gets not terrible
|
||||
// Type id doesn't fit
|
||||
continue;
|
||||
}
|
||||
|
||||
if (usesDamageValue && bukkitItem.getDurability() != damage) {
|
||||
// Damage value doesn't fit.
|
||||
continue;
|
||||
}
|
||||
|
||||
int currentAmount = bukkitItem.getAmount();
|
||||
if (currentAmount < 0) {
|
||||
// Unlimited
|
||||
@ -177,7 +166,7 @@ public class BukkitPlayerBlockBag extends BlockBag {
|
||||
}
|
||||
|
||||
if (freeSlot > -1) {
|
||||
items[freeSlot] = new ItemStack(id, amount);
|
||||
items[freeSlot] = new ItemStack(id.getLegacyId(), amount); // TODO Ditto
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -20,14 +20,13 @@
|
||||
package com.sk89q.worldedit.bukkit;
|
||||
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.NotABlockException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.blocks.BlockID;
|
||||
import com.sk89q.worldedit.blocks.BlockType;
|
||||
import com.sk89q.worldedit.blocks.ItemID;
|
||||
import com.sk89q.worldedit.blocks.type.BlockTypes;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import org.bukkit.DyeColor;
|
||||
@ -131,7 +130,7 @@ public final class BukkitUtil {
|
||||
case ItemID.INK_SACK:
|
||||
final Dye materialData = (Dye) itemStack.getData();
|
||||
if (materialData.getColor() == DyeColor.BROWN) {
|
||||
return new BaseBlock(BlockID.COCOA_PLANT, -1);
|
||||
return new BaseBlock(BlockTypes.COCOA);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -143,11 +142,7 @@ public final class BukkitUtil {
|
||||
break;
|
||||
}
|
||||
|
||||
if (world.isValidBlockType(typeId)) {
|
||||
return new BaseBlock(typeId, -1);
|
||||
}
|
||||
|
||||
throw new NotABlockException(typeId);
|
||||
return new BaseBlock(typeId, -1);
|
||||
}
|
||||
|
||||
public static BaseItemStack toBaseItemStack(ItemStack itemStack) {
|
||||
|
@ -248,36 +248,6 @@ public class BukkitWorld extends AbstractWorld {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean generateTree(EditSession editSession, Vector pt) {
|
||||
return generateTree(TreeGenerator.TreeType.TREE, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean generateBigTree(EditSession editSession, Vector pt) {
|
||||
return generateTree(TreeGenerator.TreeType.BIG_TREE, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean generateBirchTree(EditSession editSession, Vector pt) {
|
||||
return generateTree(TreeGenerator.TreeType.BIRCH, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean generateRedwoodTree(EditSession editSession, Vector pt) {
|
||||
return generateTree(TreeGenerator.TreeType.REDWOOD, editSession, pt);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean generateTallRedwoodTree(EditSession editSession, Vector pt) {
|
||||
return generateTree(TreeGenerator.TreeType.TALL_REDWOOD, editSession, pt);
|
||||
}
|
||||
|
||||
/**
|
||||
* An EnumMap that stores which WorldEdit TreeTypes apply to which Bukkit TreeTypes
|
||||
*/
|
||||
@ -323,16 +293,10 @@ public class BukkitWorld extends AbstractWorld {
|
||||
@Override
|
||||
public void dropItem(Vector pt, BaseItemStack item) {
|
||||
World world = getWorld();
|
||||
ItemStack bukkitItem = new ItemStack(item.getLegacyId(), item.getAmount(),
|
||||
item.getData());
|
||||
ItemStack bukkitItem = new ItemStack(item.getLegacyId(), item.getAmount()); // TODO Add data.
|
||||
world.dropItemNaturally(BukkitUtil.toLocation(world, pt), bukkitItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidBlockType(int type) {
|
||||
return Material.getMaterial(type) != null && Material.getMaterial(type).isBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkLoadedChunk(Vector pt) {
|
||||
World world = getWorld();
|
||||
@ -415,7 +379,7 @@ public class BukkitWorld extends AbstractWorld {
|
||||
return adapter.setBlock(BukkitAdapter.adapt(getWorld(), position), block, notifyAndLight);
|
||||
} else {
|
||||
Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
return bukkitBlock.setTypeIdAndData(block.getType().getLegacyId(), (byte) block.getData(), notifyAndLight);
|
||||
return bukkitBlock.setTypeIdAndData(block.getBlockType().getLegacyId(), (byte) block.getData(), notifyAndLight);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user