mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-26 11:07:59 +01:00
implemented more of the /lib/
This commit is contained in:
parent
e1d3cd4f31
commit
04ab5a36ef
@ -146,7 +146,7 @@ public class CitizensNPC implements NPC {
|
||||
return;
|
||||
}
|
||||
addTrait(new LocationTrait(loc));
|
||||
mcEntity = manager.spawn(this);
|
||||
mcEntity = manager.spawn(this, loc);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -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,12 +111,14 @@ 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) {
|
||||
despawn(npc);
|
||||
if (spawned.containsKey(((CitizensNPC) npc).getHandle()))
|
||||
despawn(npc);
|
||||
byID.remove(npc.getId());
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
94
src/net/citizensnpcs/resources/lib/NPCNetHandler.java
Normal file
94
src/net/citizensnpcs/resources/lib/NPCNetHandler.java
Normal 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) {
|
||||
}
|
||||
}
|
52
src/net/citizensnpcs/resources/lib/NPCNetworkManager.java
Normal file
52
src/net/citizensnpcs/resources/lib/NPCNetworkManager.java
Normal 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;
|
||||
}
|
||||
}
|
20
src/net/citizensnpcs/resources/lib/NPCSocket.java
Normal file
20
src/net/citizensnpcs/resources/lib/NPCSocket.java
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user