use of com.laytonsmith.abstraction.MCLocation in project CommandHelper by EngineHub.
the class PlayerManangementTest method testSetPloc.
public void testSetPloc() throws Exception, Exception {
MCWorld w = GetWorld("world");
CommandHelperPlugin.myServer = fakeServer;
String name = fakePlayer.getName();
when(fakeServer.getPlayer(name)).thenReturn(fakePlayer);
when(fakePlayer.getWorld()).thenReturn(w);
MCLocation loc = StaticTest.GetFakeLocation(w, 0, 0, 0);
when(fakePlayer.getLocation()).thenReturn(loc);
Run("set_ploc(1, 1, 1)", fakePlayer);
// when(StaticLayer.GetLocation(w, 1, 2, 1)).thenReturn(loc);
MCLocation loc1 = StaticTest.GetFakeLocation(w, 1, 2, 1);
// verify(fakePlayer).teleport(loc1);
assertEquals(fakePlayer.getLocation().getX(), loc1.getX(), 0.00000000000001);
Run("set_ploc(array(2, 2, 2))", fakePlayer);
verify(fakePlayer).teleport(StaticLayer.GetLocation(w, 2, 3, 2, 0, 0));
Run("set_ploc('" + fakePlayer.getName() + "', 3, 3, 3)", fakePlayer);
verify(fakePlayer).teleport(StaticLayer.GetLocation(w, 3, 4, 3, 0, 0));
Run("set_ploc('" + fakePlayer.getName() + "', array(4, 4, 4))", fakePlayer);
verify(fakePlayer).teleport(StaticLayer.GetLocation(w, 4, 5, 4, 0, 0));
}
use of com.laytonsmith.abstraction.MCLocation in project CommandHelper by EngineHub.
the class PlayerManangementTest method testPcursor.
@Test(timeout = 10000)
public void testPcursor() throws Exception, Exception {
MCBlock b = mock(MCBlock.class);
CommandHelperPlugin.myServer = fakeServer;
when(fakeServer.getPlayer(fakePlayer.getName())).thenReturn(fakePlayer);
when(fakePlayer.getTargetBlock((HashSet) eq(null), anyInt())).thenReturn(b);
MCWorld w = mock(MCWorld.class);
MCLocation loc = StaticTest.GetFakeLocation(w, 0, 0, 0);
when(b.getLocation()).thenReturn(loc);
when(b.getWorld()).thenReturn(w);
Run("pcursor()", fakePlayer);
verify(fakePlayer, times(1)).getTargetBlock((HashSet) eq(null), anyInt());
}
use of com.laytonsmith.abstraction.MCLocation in project CommandHelper by EngineHub.
the class Prefilters method LocationMatch.
private static void LocationMatch(Construct location1, Construct location2) throws PrefilterNonMatchException {
MCLocation l1 = ObjectGenerator.GetGenerator().location(location1, null, location1.getTarget());
MCLocation l2 = ObjectGenerator.GetGenerator().location(location2, null, Target.UNKNOWN);
if ((!l1.getWorld().equals(l2.getWorld())) || (l1.getBlockX() != l2.getBlockX()) || (l1.getBlockY() != l2.getBlockY()) || (l1.getBlockZ() != l2.getBlockZ())) {
throw new PrefilterNonMatchException();
}
}
use of com.laytonsmith.abstraction.MCLocation in project CommandHelper by EngineHub.
the class BukkitMCPlayer method spawnParticle.
@Override
public void spawnParticle(MCLocation l, MCParticle pa, int count, double offsetX, double offsetY, double offsetZ, double velocity, Object data) {
try {
Particle type = Particle.valueOf(pa.name());
Location loc = ((BukkitMCLocation) l).asLocation();
if (data != null && type.getDataType().equals(ItemStack.class) && data instanceof MCItemStack) {
p.spawnParticle(type, loc, count, offsetX, offsetY, offsetZ, velocity, ((MCItemStack) data).getHandle());
} else {
p.spawnParticle(type, loc, count, offsetX, offsetY, offsetZ, velocity);
}
} catch (NoClassDefFoundError ex) {
// probably prior to 1.9
}
}
use of com.laytonsmith.abstraction.MCLocation in project CommandHelper by EngineHub.
the class BukkitMCWorld method spawnMob.
@Override
public CArray spawnMob(MCMobs name, String subClass, int qty, MCLocation l, Target t) {
Class mobType = null;
CArray ids = new CArray(t);
Location location = (Location) l.getHandle();
MCVersion version = Static.getServer().getMinecraftVersion();
String[] subTypes = subClass.toUpperCase().split("-");
try {
switch(name) {
case BAT:
mobType = Bat.class;
break;
case BLAZE:
mobType = Blaze.class;
break;
case CAVESPIDER:
mobType = CaveSpider.class;
break;
case CHICKEN:
mobType = Chicken.class;
break;
case COW:
mobType = Cow.class;
break;
case CREEPER:
mobType = Creeper.class;
break;
case ELDERGUARDIAN:
mobType = ElderGuardian.class;
break;
case ENDERDRAGON:
mobType = EnderDragon.class;
break;
case ENDERMAN:
mobType = Enderman.class;
break;
case ENDERMITE:
mobType = Endermite.class;
break;
case EVOKER:
mobType = Evoker.class;
break;
case GHAST:
mobType = Ghast.class;
break;
case GUARDIAN:
mobType = Guardian.class;
break;
case GIANT:
mobType = Giant.class;
break;
case HORSE:
mobType = Horse.class;
if (!(subClass.isEmpty()) && version.gte(MCVersion.MC1_11)) {
for (String type : subTypes) {
try {
MCHorse.MCHorseVariant htype = MCHorse.MCHorseVariant.valueOf(type);
switch(htype) {
case DONKEY:
mobType = Donkey.class;
break;
case MULE:
mobType = Mule.class;
break;
case SKELETON:
mobType = SkeletonHorse.class;
break;
case ZOMBIE:
mobType = ZombieHorse.class;
break;
}
subClass = "";
break;
} catch (IllegalArgumentException notVar) {
// not variant
}
}
}
break;
case ILLUSIONER:
mobType = Illusioner.class;
break;
case IRONGOLEM:
mobType = IronGolem.class;
break;
case LLAMA:
mobType = Llama.class;
break;
case MAGMACUBE:
mobType = MagmaCube.class;
break;
case MOOSHROOM:
mobType = MushroomCow.class;
break;
case OCELOT:
mobType = Ocelot.class;
break;
case PARROT:
mobType = Parrot.class;
break;
case PIG:
mobType = Pig.class;
break;
case PIGZOMBIE:
mobType = PigZombie.class;
break;
case POLARBEAR:
mobType = PolarBear.class;
break;
case RABBIT:
mobType = Rabbit.class;
break;
case SHEEP:
mobType = Sheep.class;
break;
case SHULKER:
mobType = Shulker.class;
break;
case SILVERFISH:
mobType = Silverfish.class;
break;
case SKELETON:
mobType = Skeleton.class;
if (!(subClass.isEmpty()) && version.gte(MCVersion.MC1_11)) {
MCSkeletonType stype = MCSkeletonType.NORMAL;
for (String type : subTypes) {
try {
stype = MCSkeletonType.valueOf(type);
} catch (IllegalArgumentException ex) {
throw new CREFormatException(type + " is not a skeleton type", t);
}
}
if (stype == MCSkeletonType.WITHER) {
mobType = WitherSkeleton.class;
} else if (stype == MCSkeletonType.STRAY) {
mobType = Stray.class;
}
subClass = "";
}
break;
case SLIME:
mobType = Slime.class;
break;
case SNOWGOLEM:
mobType = Snowman.class;
break;
case SPIDER:
mobType = Spider.class;
break;
case SPIDERJOCKEY:
mobType = Spider.class;
break;
case SQUID:
mobType = Squid.class;
break;
case VEX:
mobType = Vex.class;
break;
case VILLAGER:
mobType = Villager.class;
break;
case VINDICATOR:
mobType = Vindicator.class;
break;
case WITCH:
mobType = Witch.class;
break;
case WITHER:
mobType = Wither.class;
break;
case WOLF:
mobType = Wolf.class;
break;
case ZOMBIE:
mobType = Zombie.class;
if (!subClass.isEmpty() && version.gte(MCVersion.MC1_11)) {
for (int i = 0; i < subTypes.length; i++) {
try {
MCZombieType ztype = MCZombieType.valueOf(subTypes[i]);
switch(ztype) {
case HUSK:
mobType = Husk.class;
case BABY:
continue;
case VILLAGER_BLACKSMITH:
subTypes[i] = "BLACKSMITH";
break;
case VILLAGER_BUTCHER:
subTypes[i] = "BUTCHER";
break;
case VILLAGER_LIBRARIAN:
subTypes[i] = "LIBRARIAN";
break;
case VILLAGER_PRIEST:
subTypes[i] = "PRIEST";
break;
case VILLAGER:
subTypes[i] = "FARMER";
break;
}
mobType = ZombieVillager.class;
} catch (IllegalArgumentException ex) {
// not a ZombieType
}
}
}
break;
}
} catch (NoClassDefFoundError e) {
throw new CREFormatException("No mob of type " + name + " exists", t);
}
for (int i = 0; i < qty; i++) {
Entity e = w.spawn(location, mobType);
if (name == MCMobs.SPIDERJOCKEY) {
e.setPassenger(w.spawn(location, Skeleton.class));
}
if (!subClass.isEmpty()) {
// if subClass is blank, none of this needs to run at all
if (e instanceof Sheep) {
Sheep s = (Sheep) e;
MCDyeColor color;
for (String type : subTypes) {
try {
color = MCDyeColor.valueOf(type);
s.setColor(BukkitMCDyeColor.getConvertor().getConcreteEnum(color));
} catch (IllegalArgumentException ex) {
throw new CREFormatException(type + " is not a valid color", t);
}
}
} else if (e instanceof Ocelot) {
Ocelot o = (Ocelot) e;
MCOcelotType otype;
for (String type : subTypes) {
try {
otype = MCOcelotType.valueOf(type);
o.setCatType(BukkitMCOcelotType.getConvertor().getConcreteEnum(otype));
} catch (IllegalArgumentException ex) {
throw new CREFormatException(type + " is not an ocelot type", t);
}
}
} else if (e instanceof Creeper) {
Creeper c = (Creeper) e;
for (String type : subTypes) {
try {
MCCreeperType ctype = MCCreeperType.valueOf(type);
switch(ctype) {
case POWERED:
c.setPowered(true);
break;
default:
break;
}
} catch (IllegalArgumentException ex) {
throw new CREFormatException(type + " is not a creeper state", t);
}
}
} else if (e instanceof Wolf) {
Wolf w = (Wolf) e;
for (String type : subTypes) {
try {
MCWolfType wtype = MCWolfType.valueOf(type);
switch(wtype) {
case ANGRY:
w.setAngry(true);
break;
case TAMED:
w.setTamed(true);
break;
default:
break;
}
} catch (IllegalArgumentException ex) {
throw new CREFormatException(type + " is not a wolf state", t);
}
}
} else if (e instanceof Villager) {
Villager v = (Villager) e;
MCProfession job;
for (String type : subTypes) {
try {
job = MCProfession.valueOf(type);
v.setProfession(BukkitMCProfession.getConvertor().getConcreteEnum(job));
} catch (IllegalArgumentException ex) {
throw new CREFormatException(type + " is not a valid profession", t);
}
}
} else if (e instanceof Enderman) {
Enderman en = (Enderman) e;
for (String type : subTypes) {
try {
MaterialData held = new MaterialData(Material.valueOf(type));
en.setCarriedMaterial(held);
} catch (IllegalArgumentException ex) {
throw new CREFormatException(type + " is not a valid material", t);
}
}
} else if (e instanceof Slime) {
Slime sl = (Slime) e;
for (String type : subTypes) {
if (!"".equals(type)) {
try {
sl.setSize(Integer.parseInt(type));
} catch (IllegalArgumentException ex) {
throw new CREFormatException(type + " is not a valid size", t);
}
}
}
} else if (e instanceof Skeleton) {
Skeleton sk = (Skeleton) e;
for (String type : subTypes) {
try {
sk.setSkeletonType(Skeleton.SkeletonType.valueOf(type));
} catch (IllegalArgumentException ex) {
throw new CREFormatException(type + " is not a skeleton type", t);
}
}
} else if (e instanceof Zombie) {
if (e instanceof PigZombie) {
PigZombie pz = (PigZombie) e;
for (String value : subTypes) {
if (value.equals("BABY")) {
pz.setBaby(true);
continue;
}
try {
pz.setAnger(Integer.valueOf(value));
} catch (IllegalArgumentException iae) {
throw new CREFormatException(value + " is not a number.", t);
}
}
} else if (version.gte(MCVersion.MC1_11) && e instanceof ZombieVillager) {
ZombieVillager zv = (ZombieVillager) e;
for (String type : subTypes) {
if (type.equals("BABY")) {
zv.setBaby(true);
continue;
}
try {
MCProfession job = MCProfession.valueOf(type);
zv.setVillagerProfession(BukkitMCProfession.getConvertor().getConcreteEnum(job));
} catch (IllegalArgumentException ex) {
throw new CREFormatException(type + " is not a valid profession", t);
}
}
} else {
Zombie z = (Zombie) e;
for (String type : subTypes) {
try {
MCZombieType ztype = MCZombieType.valueOf(type);
switch(ztype) {
case BABY:
z.setBaby(true);
break;
case VILLAGER:
z.setVillager(true);
break;
case VILLAGER_BLACKSMITH:
case VILLAGER_BUTCHER:
case VILLAGER_LIBRARIAN:
case VILLAGER_PRIEST:
if (version.gte(MCVersion.MC1_9)) {
// < MC 1.11
z.setVillagerProfession(Villager.Profession.valueOf(type.substring(9).toUpperCase()));
} else {
z.setVillager(true);
}
break;
case HUSK:
if (version.gte(MCVersion.MC1_10) && version.lt(MCVersion.MC1_11)) {
z.setVillagerProfession(Villager.Profession.HUSK);
}
break;
}
} catch (IllegalArgumentException ex) {
throw new CREFormatException(type + " is not a zombie state", t);
}
}
}
} else if (e instanceof Pig) {
Pig p = (Pig) e;
for (String type : subTypes) {
try {
MCPigType ptype = MCPigType.valueOf(type);
switch(ptype) {
case SADDLED:
p.setSaddle(true);
break;
default:
break;
}
} catch (IllegalArgumentException ex) {
throw new CREFormatException(type + " is not a pig state", t);
}
}
} else if (e instanceof Horse) {
Horse h = (Horse) e;
for (String type : subTypes) {
if (version.lt(MCVersion.MC1_11)) {
try {
MCHorse.MCHorseVariant htype = MCHorse.MCHorseVariant.valueOf(type);
h.setVariant(BukkitMCHorse.BukkitMCHorseVariant.getConvertor().getConcreteEnum(htype));
// no other variants can have colors or patterns
break;
} catch (IllegalArgumentException ex) {
// not variant
}
}
try {
MCHorse.MCHorseColor hcolor = MCHorse.MCHorseColor.valueOf(type);
h.setColor(BukkitMCHorse.BukkitMCHorseColor.getConvertor().getConcreteEnum(hcolor));
continue;
} catch (IllegalArgumentException ex) {
// not color
}
try {
MCHorse.MCHorsePattern hpattern = MCHorse.MCHorsePattern.valueOf(type);
h.setStyle(BukkitMCHorse.BukkitMCHorsePattern.getConvertor().getConcreteEnum(hpattern));
} catch (IllegalArgumentException notAnything) {
throw new CREFormatException("Type " + type + " did not match any horse variants," + " colors, or patterns.", t);
}
}
}
}
ids.push(new CString(e.getUniqueId().toString(), t), t);
}
return ids;
}
Aggregations