mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 18:45:29 +01:00
removed duplicate files
This commit is contained in:
parent
b8bb1955d9
commit
76a769489c
Binary file not shown.
@ -1,83 +0,0 @@
|
||||
package net.citizensnpcs.npc.entity;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
import net.citizensnpcs.npc.CitizensNPC;
|
||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||
import net.minecraft.server.Entity;
|
||||
import net.minecraft.server.EntityLiving;
|
||||
import net.minecraft.server.EntityTypes;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
public abstract class CitizensMobNPC extends CitizensNPC {
|
||||
private final Constructor<? extends EntityLiving> constructor;
|
||||
|
||||
protected CitizensMobNPC(CitizensNPCManager manager, int id, String name, Class<? extends EntityLiving> clazz) {
|
||||
super(manager, id, name);
|
||||
try {
|
||||
this.constructor = clazz.getConstructor(World.class);
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalStateException("unable to find an entity constructor");
|
||||
}
|
||||
if (!classToInt.containsKey(clazz))
|
||||
registerEntityClass(clazz);
|
||||
}
|
||||
|
||||
private EntityLiving createEntityFromClass(net.minecraft.server.World world) {
|
||||
try {
|
||||
return constructor.newInstance(world);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityLiving createHandle(Location loc) {
|
||||
EntityLiving entity = createEntityFromClass(((CraftWorld) loc.getWorld()).getHandle());
|
||||
mcEntity.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity getBukkitEntity() {
|
||||
return (LivingEntity) getHandle().getBukkitEntity();
|
||||
}
|
||||
|
||||
private static Map<Class<? extends Entity>, Integer> classToInt;
|
||||
private static Map<Integer, Class<? extends Entity>> intToClass;
|
||||
|
||||
private static void registerEntityClass(Class<? extends Entity> clazz) {
|
||||
Class<?> search = clazz;
|
||||
while ((search = search.getSuperclass()) != null && Entity.class.isAssignableFrom(search)) {
|
||||
if (!classToInt.containsKey(search))
|
||||
continue;
|
||||
int code = classToInt.get(search);
|
||||
intToClass.put(code, clazz);
|
||||
classToInt.put(clazz, code);
|
||||
return;
|
||||
}
|
||||
throw new IllegalArgumentException("unable to find valid entity superclass");
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
Field field = EntityTypes.class.getDeclaredField("d");
|
||||
field.setAccessible(true);
|
||||
intToClass = (Map<Integer, Class<? extends Entity>>) field.get(null);
|
||||
field = EntityTypes.class.getDeclaredField("e");
|
||||
field.setAccessible(true);
|
||||
classToInt = (Map<Class<? extends Entity>, Integer>) field.get(null);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
throw new IllegalStateException(
|
||||
"Unable to fetch entity class mapping - is Citizens updated for this version of CraftBukkit?");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
package net.citizensnpcs.resource.lib.entity;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
import net.citizensnpcs.resource.lib.NPCNetHandler;
|
||||
import net.citizensnpcs.resource.lib.NPCNetworkManager;
|
||||
import net.citizensnpcs.resource.lib.NPCSocket;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.ItemInWorldManager;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.NetHandler;
|
||||
import net.minecraft.server.NetworkManager;
|
||||
import net.minecraft.server.World;
|
||||
|
||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class EntityHumanNPC extends EntityPlayer {
|
||||
|
||||
public EntityHumanNPC(MinecraftServer minecraftServer, World world, String string,
|
||||
ItemInWorldManager itemInWorldManager) {
|
||||
super(minecraftServer, world, string, itemInWorldManager);
|
||||
itemInWorldManager.setGameMode(0);
|
||||
|
||||
NPCSocket socket = new NPCSocket();
|
||||
NetworkManager netMgr = new NPCNetworkManager(socket, "npc mgr", new NetHandler() {
|
||||
@Override
|
||||
public boolean c() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
netServerHandler = new NPCNetHandler(minecraftServer, netMgr, this);
|
||||
netMgr.a(netServerHandler);
|
||||
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftPlayer getBukkitEntity() {
|
||||
if (bukkitEntity == null) {
|
||||
super.getBukkitEntity();
|
||||
removeFromPlayerMap(name);
|
||||
// Bukkit uses a map of player names to CraftPlayer instances to
|
||||
// solve a reconnect issue, so NPC names will conflict with ordinary
|
||||
// player names. Workaround.
|
||||
}
|
||||
return super.getBukkitEntity();
|
||||
}
|
||||
|
||||
public void removeFromPlayerMap(String name) {
|
||||
if (players != null)
|
||||
players.remove(name);
|
||||
}
|
||||
|
||||
private static Map<String, CraftPlayer> players;
|
||||
|
||||
static {
|
||||
try {
|
||||
Field f = CraftEntity.class.getDeclaredField("players");
|
||||
f.setAccessible(true);
|
||||
players = (Map<String, CraftPlayer>) f.get(null);
|
||||
} catch (Exception ex) {
|
||||
Messaging.log("Unable to fetch player map from CraftEntity: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user