Skip to content

Commit

Permalink
Remove old debug code
Browse files Browse the repository at this point in the history
  • Loading branch information
iso2013 committed May 23, 2018
1 parent f696c89 commit fb2a114
Showing 1 changed file with 1 addition and 127 deletions.
128 changes: 1 addition & 127 deletions Plugin/src/main/java/net/blitzcube/peapi/PacketEntityAPIPlugin.java
Original file line number Diff line number Diff line change
@@ -1,144 +1,18 @@
package net.blitzcube.peapi;

import net.blitzcube.peapi.api.entity.fake.IFakeEntity;
import net.blitzcube.peapi.api.entity.fake.IFakeEntityFactory;
import net.blitzcube.peapi.api.entity.modifier.IEntityModifier;
import net.blitzcube.peapi.api.entity.modifier.IEntityModifierRegistry;
import net.blitzcube.peapi.api.event.IEntityPacketEvent;
import net.blitzcube.peapi.api.listener.IListener;
import net.blitzcube.peapi.api.packet.IEntityPacket;
import net.blitzcube.peapi.api.packet.IEntityPacketFactory;
import net.blitzcube.peapi.api.packet.IEntitySpawnPacket;
import org.bukkit.entity.EntityType;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;

import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("unused")
public final class PacketEntityAPIPlugin extends JavaPlugin implements Listener {
private final Map<Integer, EntityType> ids = new HashMap<>();

@Override
@SuppressWarnings("unchecked")
public void onEnable() {
PacketEntityAPI.initialize(this, api -> api.addListener(new Demo(api.getModifierRegistry(), api
.getPacketFactory(), api.getEntityFactory())));
PacketEntityAPI.initialize(this, null);
}

@Override
public void onDisable() {

}

@SuppressWarnings("unchecked")
private class Demo implements IListener {
private final IEntityModifier<String> name;
private final IEntityModifier<Boolean> nameVisible;
private final IEntityModifier<Integer> size;
private final IEntityModifier<Boolean> marker;
private final IEntityModifier<Boolean> invisible;
private final IEntityModifier<Boolean> asInvisible;
private final IEntityModifier<Boolean> noAI;
private final IEntityModifier<Boolean> silent;

private final IFakeEntityFactory entity;
private final IEntityPacketFactory packet;

Demo(IEntityModifierRegistry reg, IEntityPacketFactory factory, IFakeEntityFactory fakeFactory) {
this.name = reg.lookup(EntityType.ARMOR_STAND, "CUSTOM_NAME");
this.nameVisible = reg.lookup(EntityType.ARMOR_STAND, "CUSTOM_NAME_VISIBLE");
this.size = reg.lookup(EntityType.SLIME, "SIZE");
this.marker = reg.lookup(EntityType.ARMOR_STAND, "MARKER");
this.invisible = reg.lookup(EntityType.SILVERFISH, "INVISIBLE");
this.asInvisible = reg.lookup(EntityType.ARMOR_STAND, "INVISIBLE");
this.noAI = reg.lookup(EntityType.SILVERFISH, "NO_AI");
this.silent = reg.lookup(EntityType.SILVERFISH, "SILENT");

this.entity = fakeFactory;
this.packet = factory;
}

@Override
public ListenerPriority getPriority() {
return ListenerPriority.NORMAL;
}

@Override
public void onEvent(IEntityPacketEvent e) {
if (e.getPacket() instanceof IEntitySpawnPacket) {
IFakeEntity sf1 = entity.createFakeEntity(EntityType.SILVERFISH);
IFakeEntity sf2 = entity.createFakeEntity(EntityType.SILVERFISH);
IFakeEntity sf3 = entity.createFakeEntity(EntityType.SILVERFISH);
IFakeEntity slime = entity.createFakeEntity(EntityType.SLIME);
IFakeEntity armorStand1 = entity.createFakeEntity(EntityType.ARMOR_STAND);
IFakeEntity armorStand2 = entity.createFakeEntity(EntityType.ARMOR_STAND);

sf1.setLocation(((IEntitySpawnPacket) e.getPacket()).getLocation().clone().add(new Vector(0, 1.5, 0)));
sf2.setLocation(((IEntitySpawnPacket) e.getPacket()).getLocation().clone().add(new Vector(0, 1.5, 0)));
sf3.setLocation(((IEntitySpawnPacket) e.getPacket()).getLocation().clone().add(new Vector(0, 1.5, 0)));
slime.setLocation(((IEntitySpawnPacket) e.getPacket()).getLocation().clone().add(new Vector(0, 1.5,
0)));
armorStand1.setLocation(((IEntitySpawnPacket) e.getPacket()).getLocation().clone().add(new Vector(0,
1.5, 0)));
armorStand2.setLocation(((IEntitySpawnPacket) e.getPacket()).getLocation().clone().add(new Vector(0,
1.5, 0)));

//These are commented out because debugging:
invisible.setValue(sf1.getModifiableEntity(), true);
invisible.setValue(sf2.getModifiableEntity(), true);
invisible.setValue(sf3.getModifiableEntity(), true);
invisible.setValue(slime.getModifiableEntity(), true);
asInvisible.setValue(armorStand1.getModifiableEntity(), true);
asInvisible.setValue(armorStand2.getModifiableEntity(), true);

silent.setValue(sf1.getModifiableEntity(), true);
silent.setValue(sf2.getModifiableEntity(), true);
silent.setValue(sf3.getModifiableEntity(), true);
noAI.setValue(sf1.getModifiableEntity(), true);
noAI.setValue(sf2.getModifiableEntity(), true);
noAI.setValue(sf3.getModifiableEntity(), true);

name.setValue(armorStand1.getModifiableEntity(), "This is a test!");
name.setValue(armorStand2.getModifiableEntity(), "Welcome to MLAPI!");

nameVisible.setValue(armorStand1.getModifiableEntity(), true);
nameVisible.setValue(armorStand2.getModifiableEntity(), true);

marker.setValue(armorStand1.getModifiableEntity(), true);
marker.setValue(armorStand2.getModifiableEntity(), true);

size.setValue(slime.getModifiableEntity(), -1);

IEntityPacket[] as1packets = packet.createObjectSpawnPacket(armorStand1.getIdentifier());
IEntityPacket[] as2packets = packet.createObjectSpawnPacket(armorStand2.getIdentifier());

e.context().queueDispatch(
packet.createEntitySpawnPacket(sf1.getIdentifier()),
packet.createEntitySpawnPacket(sf2.getIdentifier()),
packet.createEntitySpawnPacket(sf3.getIdentifier()),
packet.createEntitySpawnPacket(slime.getIdentifier()),
as1packets[0],
as2packets[0]
).queueDispatch(
as1packets[1],
as2packets[1]
).queueDispatch(new IEntityPacket[]{
packet.createMountPacket(sf1.getIdentifier(), armorStand1.getIdentifier()),
packet.createMountPacket(sf2.getIdentifier(), sf1.getIdentifier()),
packet.createMountPacket(slime.getIdentifier(), sf2.getIdentifier()),
packet.createMountPacket(armorStand2.getIdentifier(), slime.getIdentifier()),
packet.createMountPacket(sf3.getIdentifier(), armorStand2.getIdentifier()),
packet.createMountPacket(e.getPacket().getIdentifier(), sf3.getIdentifier())
}, 1);
}
}

@Override
public EntityType[] getTargets() {
return EntityType.values();
}
}
}

0 comments on commit fb2a114

Please sign in to comment.