mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 02:46:41 +00:00
Added basic entity handling with copy and paste.
Paintings do not currently respawn properly, entity pastes cannot be undone yet, and schematics do not yet store entities @celticminstrel needs to fix painting spawning
This commit is contained in:
@ -23,8 +23,16 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.entity.BukkitEntity;
|
||||
import com.sk89q.worldedit.bukkit.entity.BukkitExpOrb;
|
||||
import com.sk89q.worldedit.bukkit.entity.BukkitItem;
|
||||
import com.sk89q.worldedit.bukkit.entity.BukkitPainting;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Painting;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
@ -139,4 +147,18 @@ public class BukkitUtil {
|
||||
public static World toWorld(final LocalWorld world) {
|
||||
return ((BukkitWorld) world).getWorld();
|
||||
}
|
||||
|
||||
public static BukkitEntity toLocalEntity(Entity e) {
|
||||
switch (e.getType()) {
|
||||
case EXPERIENCE_ORB:
|
||||
return new BukkitExpOrb(toLocation(e.getLocation()), e.getUniqueId(), ((ExperienceOrb)e).getExperience());
|
||||
/*case PAINTING: // TODO: Figure out what celticminstrel broke
|
||||
Painting paint = (Painting) e;
|
||||
return new BukkitPainting(toLocation(e.getLocation()), paint.getArt(), paint.getFacing(), e.getUniqueId());*/
|
||||
case DROPPED_ITEM:
|
||||
return new BukkitItem(toLocation(e.getLocation()), ((Item)e).getItemStack(), e.getUniqueId());
|
||||
default:
|
||||
return new BukkitEntity(toLocation(e.getLocation()), e.getType(), e.getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,11 +19,19 @@
|
||||
|
||||
package com.sk89q.worldedit.bukkit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import com.sk89q.worldedit.LocalEntity;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.bukkit.entity.BukkitEntity;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.Block;
|
||||
@ -892,4 +900,34 @@ public class BukkitWorld extends LocalWorld {
|
||||
public void simulateBlockMine(Vector pt) {
|
||||
world.getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).breakNaturally();
|
||||
}
|
||||
|
||||
public LocalEntity[] getEntities(Region region) {
|
||||
List<BukkitEntity> entities = new ArrayList<BukkitEntity>();
|
||||
for (Vector2D pt : region.getChunks()) {
|
||||
if (world.isChunkLoaded(pt.getBlockX(), pt.getBlockZ())) {
|
||||
Entity[] ents = world.getChunkAt(pt.getBlockX(), pt.getBlockZ()).getEntities();
|
||||
for (Entity ent : ents) {
|
||||
if (region.contains(BukkitUtil.toVector(ent.getLocation()))) {
|
||||
entities.add(BukkitUtil.toLocalEntity(ent));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return entities.toArray(new BukkitEntity[entities.size()]);
|
||||
}
|
||||
|
||||
public int killEntities(LocalEntity... entities) {
|
||||
int amount = 0;
|
||||
Set<UUID> toKill = new HashSet<UUID>();
|
||||
for (LocalEntity entity : entities) {
|
||||
toKill.add(((BukkitEntity) entity).getEntityId());
|
||||
}
|
||||
for (Entity entity : world.getEntities()) {
|
||||
if (toKill.contains(entity.getUniqueId())) {
|
||||
entity.remove();
|
||||
++amount;
|
||||
}
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.bukkit.entity;
|
||||
|
||||
import com.sk89q.worldedit.LocalEntity;
|
||||
import com.sk89q.worldedit.Location;
|
||||
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author zml2008
|
||||
*/
|
||||
public class BukkitEntity extends LocalEntity {
|
||||
private final EntityType type;
|
||||
private final UUID entityId;
|
||||
|
||||
public BukkitEntity(Location loc, EntityType type, UUID entityId) {
|
||||
super(loc);
|
||||
this.type = type;
|
||||
this.entityId = entityId;
|
||||
}
|
||||
|
||||
public UUID getEntityId() {
|
||||
return entityId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawn(Location weLoc) {
|
||||
org.bukkit.Location loc = BukkitUtil.toLocation(weLoc);
|
||||
return loc.getWorld().spawnCreature(loc, type) != null;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.bukkit.entity;
|
||||
|
||||
import com.sk89q.worldedit.Location;
|
||||
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author zml2008
|
||||
*/
|
||||
public class BukkitExpOrb extends BukkitEntity {
|
||||
private final int amount;
|
||||
|
||||
public BukkitExpOrb(Location loc, UUID entityId, int amount) {
|
||||
super(loc, EntityType.EXPERIENCE_ORB, entityId);
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawn(Location weLoc) {
|
||||
org.bukkit.Location loc = BukkitUtil.toLocation(weLoc);
|
||||
ExperienceOrb orb = loc.getWorld().spawn(loc, ExperienceOrb.class);
|
||||
if (orb != null) {
|
||||
orb.setExperience(amount);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.bukkit.entity;
|
||||
|
||||
import com.sk89q.worldedit.Location;
|
||||
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author zml2008
|
||||
*/
|
||||
public class BukkitItem extends BukkitEntity {
|
||||
private final ItemStack stack;
|
||||
public BukkitItem(Location loc, ItemStack stack, UUID entityId) {
|
||||
super(loc, EntityType.DROPPED_ITEM, entityId);
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spawn(Location weLoc) {
|
||||
org.bukkit.Location loc = BukkitUtil.toLocation(weLoc);
|
||||
return loc.getWorld().dropItem(loc, stack) != null;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.bukkit.entity;
|
||||
|
||||
import com.sk89q.worldedit.Location;
|
||||
import com.sk89q.worldedit.bukkit.BukkitUtil;
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Painting;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author zml2008
|
||||
*/
|
||||
public class BukkitPainting extends BukkitEntity {
|
||||
private final Art art;
|
||||
private final BlockFace facingDirection;
|
||||
public BukkitPainting(Location loc, Art art, BlockFace facingDirection, UUID entityId) {
|
||||
super(loc, EntityType.PAINTING, entityId);
|
||||
this.art = art;
|
||||
this.facingDirection = facingDirection;
|
||||
}
|
||||
|
||||
public boolean spawn(Location weLoc) {
|
||||
org.bukkit.Location loc = BukkitUtil.toLocation(weLoc);
|
||||
Painting paint = loc.getWorld().spawn(loc, Painting.class);
|
||||
if (paint != null) {
|
||||
paint.setFacingDirection(facingDirection);
|
||||
paint.setArt(art);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user