implemented more of the /lib/

This commit is contained in:
aPunch 2012-01-15 01:00:04 -06:00
parent 9100fe4720
commit 198e919d73
6 changed files with 193 additions and 4 deletions

View File

@ -146,7 +146,7 @@ public class CitizensNPC implements NPC {
return;
}
addTrait(new LocationTrait(loc));
mcEntity = manager.spawn(this);
mcEntity = manager.spawn(this, loc);
}
@Override

View File

@ -97,8 +97,7 @@ public class CitizensNPCManager implements NPCManager {
return count;
}
public CraftNPC spawn(NPC npc) {
Location loc = ((LocationTrait) npc.getTrait("location")).getLocation();
public CraftNPC spawn(NPC npc, Location loc) {
WorldServer ws = getWorldServer(loc.getWorld());
CraftNPC mcEntity = new CraftNPC(getMinecraftServer(ws.getServer()), ws, npc.getFullName(),
new ItemInWorldManager(ws));
@ -112,11 +111,13 @@ public class CitizensNPCManager implements NPCManager {
public void despawn(NPC npc) {
CraftNPC mcEntity = ((CitizensNPC) npc).getHandle();
// TODO send Packet29DestroyEntity
getWorldServer(((LocationTrait) npc.getTrait("location")).getLocation().getWorld()).removeEntity(mcEntity);
spawned.remove(mcEntity.getPlayer());
}
public void remove(NPC npc) {
if (spawned.containsKey(((CitizensNPC) npc).getHandle()))
despawn(npc);
byID.remove(npc.getId());
}

View File

@ -1,13 +1,35 @@
package net.citizensnpcs.resources.lib;
import java.io.IOException;
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;
public class CraftNPC extends EntityPlayer {
public CraftNPC(MinecraftServer minecraftserver, World world, String s, ItemInWorldManager iteminworldmanager) {
super(minecraftserver, world, s, iteminworldmanager);
iteminworldmanager.setGameMode(0);
NPCSocket socket = new NPCSocket();
NetworkManager netMgr = new NPCNetworkManager(socket, "npc mgr", new NetHandler() {
@Override
public boolean c() {
return false;
}
});
this.netServerHandler = new NPCNetHandler(minecraftserver, netMgr, this);
netMgr.a(this.netServerHandler);
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,94 @@
package net.citizensnpcs.resources.lib;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.NetServerHandler;
import net.minecraft.server.NetworkManager;
import net.minecraft.server.Packet;
import net.minecraft.server.Packet101CloseWindow;
import net.minecraft.server.Packet102WindowClick;
import net.minecraft.server.Packet106Transaction;
import net.minecraft.server.Packet10Flying;
import net.minecraft.server.Packet130UpdateSign;
import net.minecraft.server.Packet14BlockDig;
import net.minecraft.server.Packet15Place;
import net.minecraft.server.Packet16BlockItemSwitch;
import net.minecraft.server.Packet255KickDisconnect;
import net.minecraft.server.Packet28EntityVelocity;
import net.minecraft.server.Packet3Chat;
import net.minecraft.server.Packet51MapChunk;
public class NPCNetHandler extends NetServerHandler {
public NPCNetHandler(MinecraftServer minecraftServer, NetworkManager networkManager, EntityPlayer entityPlayer) {
super(minecraftServer, networkManager, entityPlayer);
}
@Override
public void a() {
}
@Override
public void sendMessage(String string) {
}
@Override
public void a(String string, Object[] objects) {
}
@Override
public void a(Packet packet) {
}
@Override
public void sendPacket(Packet packet) {
}
@Override
public void a(Packet3Chat packet) {
}
@Override
public void a(Packet10Flying packet) {
}
@Override
public void a(Packet14BlockDig packet) {
}
@Override
public void a(Packet15Place packet) {
}
@Override
public void a(Packet16BlockItemSwitch packet) {
}
@Override
public void a(Packet28EntityVelocity packet) {
}
@Override
public void a(Packet51MapChunk packet) {
}
@Override
public void a(Packet101CloseWindow packet) {
}
@Override
public void a(Packet102WindowClick packet) {
}
@Override
public void a(Packet106Transaction packet) {
}
@Override
public void a(Packet255KickDisconnect packet) {
}
@Override
public void a(Packet130UpdateSign packet) {
}
}

View File

@ -0,0 +1,52 @@
package net.citizensnpcs.resources.lib;
import java.lang.reflect.Field;
import java.net.Socket;
import net.minecraft.server.NetHandler;
import net.minecraft.server.NetworkManager;
import net.minecraft.server.Packet;
public class NPCNetworkManager extends NetworkManager {
public NPCNetworkManager(Socket socket, String string, NetHandler netHandler) {
super(socket, string, netHandler);
try {
// the field above the 3 synchronized lists.
Field f = NetworkManager.class.getDeclaredField("l");
f.setAccessible(true);
f.set(this, false);
} catch (Exception e) {
}
}
@Override
public void a(NetHandler netHandler) {
}
@Override
public void queue(Packet packet) {
}
@Override
public void a(String s, Object... objects) {
}
@Override
public void a() {
}
@Override
public void b() {
}
@Override
public void d() {
}
@Override
public int e() {
return 0;
}
}

View File

@ -0,0 +1,20 @@
package net.citizensnpcs.resources.lib;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
public class NPCSocket extends Socket {
@Override
public InputStream getInputStream() {
return new ByteArrayInputStream(new byte[10]);
}
@Override
public OutputStream getOutputStream() {
return new ByteArrayOutputStream();
}
}