Search in sources :

Example 11 with MCLocation

use of com.laytonsmith.abstraction.MCLocation in project CommandHelper by EngineHub.

the class StaticTest method GetFakeLocation.

public static MCLocation GetFakeLocation(MCWorld w, double x, double y, double z) {
    MCLocation loc = mock(BukkitMCLocation.class);
    when(loc.getWorld()).thenReturn(w);
    when(loc.getX()).thenReturn(x);
    when(loc.getY()).thenReturn(y - 1);
    when(loc.getZ()).thenReturn(z);
    return loc;
}
Also used : BukkitMCLocation(com.laytonsmith.abstraction.bukkit.BukkitMCLocation) MCLocation(com.laytonsmith.abstraction.MCLocation)

Example 12 with MCLocation

use of com.laytonsmith.abstraction.MCLocation in project CommandHelper by EngineHub.

the class StaticTest method GetOnlinePlayer.

public static MCPlayer GetOnlinePlayer(String name, String worldName, MCServer s) {
    MCPlayer p = mock(MCPlayer.class);
    MCWorld w = mock(MCWorld.class);
    MCLocation fakeLocation = StaticTest.GetFakeLocation(w, 0, 0, 0);
    MCItemStack fakeItemStack = mock(MCItemStack.class);
    when(w.getName()).thenReturn(worldName);
    when(p.getWorld()).thenReturn(w);
    when(p.isOnline()).thenReturn(true);
    when(p.getName()).thenReturn(name);
    when(p.getServer()).thenReturn(s);
    when(p.isOp()).thenReturn(true);
    if (s != null && s.getOnlinePlayers() != null) {
        Collection<MCPlayer> online = s.getOnlinePlayers();
        boolean alreadyOnline = false;
        for (MCPlayer o : online) {
            if (o.getName().equals(name)) {
                alreadyOnline = true;
                break;
            }
        }
        if (!alreadyOnline) {
            online.add(p);
            when(s.getOnlinePlayers()).thenReturn(new HashSet<MCPlayer>());
        }
    }
    // Plethora of fake data
    when(p.getCompassTarget()).thenReturn(fakeLocation);
    when(p.getItemAt((Integer) Mockito.any())).thenReturn(fakeItemStack);
    return p;
}
Also used : BukkitMCLocation(com.laytonsmith.abstraction.bukkit.BukkitMCLocation) MCLocation(com.laytonsmith.abstraction.MCLocation) MCItemStack(com.laytonsmith.abstraction.MCItemStack) MCPlayer(com.laytonsmith.abstraction.MCPlayer) MCWorld(com.laytonsmith.abstraction.MCWorld) BukkitMCWorld(com.laytonsmith.abstraction.bukkit.BukkitMCWorld)

Example 13 with MCLocation

use of com.laytonsmith.abstraction.MCLocation in project CommandHelper by EngineHub.

the class RandomTests method testStaticGetLocation.

/*@Test*/
public void testStaticGetLocation() {
    MCWorld fakeWorld = mock(MCWorld.class);
    MCServer fakeServer = mock(MCServer.class);
    when(fakeServer.getWorld("world")).thenReturn(fakeWorld);
    CommandHelperPlugin.myServer = fakeServer;
    CArray ca1 = new CArray(Target.UNKNOWN, C.onstruct(1), C.onstruct(2), C.onstruct(3));
    CArray ca2 = new CArray(Target.UNKNOWN, C.onstruct(1), C.onstruct(2), C.onstruct(3), C.onstruct("world"));
    CArray ca3 = new CArray(Target.UNKNOWN, C.onstruct(1), C.onstruct(2), C.onstruct(3), C.onstruct(45), C.onstruct(50));
    CArray ca4 = new CArray(Target.UNKNOWN, C.onstruct(1), C.onstruct(2), C.onstruct(3), C.onstruct("world"), C.onstruct(45), C.onstruct(50));
    MCLocation l1 = ObjectGenerator.GetGenerator().location(ca1, fakeWorld, Target.UNKNOWN);
    MCLocation l2 = ObjectGenerator.GetGenerator().location(ca2, fakeWorld, Target.UNKNOWN);
    MCLocation l3 = ObjectGenerator.GetGenerator().location(ca3, fakeWorld, Target.UNKNOWN);
    MCLocation l4 = ObjectGenerator.GetGenerator().location(ca4, fakeWorld, Target.UNKNOWN);
    assertEquals(fakeWorld, l1.getWorld());
    assertEquals(fakeWorld, l2.getWorld());
    assertEquals(fakeWorld, l3.getWorld());
    assertEquals(fakeWorld, l4.getWorld());
    assertEquals(1, l1.getX(), 0.00000000000000001);
    assertEquals(1, l2.getX(), 0.00000000000000001);
    assertEquals(1, l4.getX(), 0.00000000000000001);
    assertEquals(1, l4.getX(), 0.00000000000000001);
    assertEquals(2, l1.getY(), 0.00000000000000001);
    assertEquals(2, l2.getY(), 0.00000000000000001);
    assertEquals(2, l3.getY(), 0.00000000000000001);
    assertEquals(2, l4.getY(), 0.00000000000000001);
    assertEquals(3, l1.getZ(), 0.00000000000000001);
    assertEquals(3, l2.getZ(), 0.00000000000000001);
    assertEquals(3, l3.getZ(), 0.00000000000000001);
    assertEquals(3, l4.getZ(), 0.00000000000000001);
    assertEquals(0, l1.getYaw(), 0.0000000000000000001);
    assertEquals(0, l2.getYaw(), 0.0000000000000000001);
    assertEquals(45, l3.getYaw(), 0.0000000000000000001);
    assertEquals(45, l4.getYaw(), 0.0000000000000000001);
    assertEquals(0, l1.getPitch(), 0.0000000000000000001);
    assertEquals(0, l2.getPitch(), 0.0000000000000000001);
    assertEquals(50, l3.getPitch(), 0.0000000000000000001);
    assertEquals(50, l4.getPitch(), 0.0000000000000000001);
    CommandHelperPlugin.myServer = null;
}
Also used : MCLocation(com.laytonsmith.abstraction.MCLocation) CArray(com.laytonsmith.core.constructs.CArray) MCServer(com.laytonsmith.abstraction.MCServer) MCWorld(com.laytonsmith.abstraction.MCWorld)

Example 14 with MCLocation

use of com.laytonsmith.abstraction.MCLocation in project CommandHelper by EngineHub.

the class InventoryManagement method GetInventory.

// @api
// public static class pinv_consolidate extends AbstractFunction {
// 
// public String getName() {
// return "pinv_consolidate";
// }
// 
// public Integer[] numArgs() {
// return new Integer[]{0, 1};
// }
// 
// public String docs() {
// return "void {[player]} Consolidates a player's inventory as much as possible."
// + " There is no guarantee anything will happen after this function"
// + " is called, and there is no way to specify details about how"
// + " consolidation occurs, however, the following heuristics are followed:"
// + " The hotbar items will not be moved from the hotbar, unless there are"
// + " two+ slots that have the same item. Items in the main inventory area"
// + " will be moved closer to the bottom of the main inventory. No empty slots"
// + " will be filled in the hotbar.";
// }
// 
// public Class<? extends CREThrowable>[] thrown() {
// return new Class[]{};
// }
// 
// public boolean isRestricted() {
// return true;
// }
// 
// public boolean preResolveVariables() {
// return true;
// }
// 
// public Boolean runAsync() {
// return false;
// }
// 
// public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException {
// MCPlayer p = environment.GetPlayer();
// if(args.length == 1){
// p = Static.GetPlayer(args[0], t);
// }
// //First, we need to address the hotbar
// for(int i = 0; i < 10; i++){
// //If the stack size is maxed out, we're done.
// }
// 
// return CVoid.VOID;
// }
// 
// public CHVersion since() {
// return CHVersion.V3_3_1;
// }
// }
private static MCInventory GetInventory(Construct specifier, MCWorld w, Target t) {
    MCInventory inv;
    if (specifier instanceof CArray) {
        MCLocation l = ObjectGenerator.GetGenerator().location(specifier, w, t);
        inv = StaticLayer.GetConvertor().GetLocationInventory(l);
    } else {
        MCEntity entity = Static.getEntity(specifier, t);
        inv = StaticLayer.GetConvertor().GetEntityInventory(entity);
    }
    if (inv == null) {
        throw new CREFormatException("The entity or location specified is not capable of having an inventory.", t);
    } else {
        return inv;
    }
}
Also used : MCLocation(com.laytonsmith.abstraction.MCLocation) MCInventory(com.laytonsmith.abstraction.MCInventory) MCEntity(com.laytonsmith.abstraction.MCEntity) CArray(com.laytonsmith.core.constructs.CArray) CREFormatException(com.laytonsmith.core.exceptions.CRE.CREFormatException)

Example 15 with MCLocation

use of com.laytonsmith.abstraction.MCLocation in project CommandHelper by EngineHub.

the class BukkitConvertor method GetEntitiesAt.

@Override
public List<MCEntity> GetEntitiesAt(MCLocation location, double radius) {
    if (location == null) {
        return Collections.EMPTY_LIST;
    }
    if (radius <= 0) {
        radius = 1;
    }
    Location l = (Location) location.getHandle();
    Collection<Entity> near;
    try {
        near = l.getWorld().getNearbyEntities(l, radius, radius, radius);
    } catch (NoSuchMethodError ex) {
        // Probably before 1.8.3
        Entity tempEntity = l.getWorld().spawnEntity(l, EntityType.ARROW);
        near = tempEntity.getNearbyEntities(radius, radius, radius);
        tempEntity.remove();
    }
    List<MCEntity> entities = new ArrayList<>();
    for (Entity e : near) {
        entities.add(BukkitGetCorrectEntity(e));
    }
    return entities;
}
Also used : BukkitMCHumanEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCHumanEntity) Entity(org.bukkit.entity.Entity) BukkitMCComplexLivingEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCComplexLivingEntity) BukkitMCEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCEntity) MCEntity(com.laytonsmith.abstraction.MCEntity) BukkitMCLivingEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) ComplexLivingEntity(org.bukkit.entity.ComplexLivingEntity) HumanEntity(org.bukkit.entity.HumanEntity) BukkitMCEntity(com.laytonsmith.abstraction.bukkit.entities.BukkitMCEntity) MCEntity(com.laytonsmith.abstraction.MCEntity) ArrayList(java.util.ArrayList) Location(org.bukkit.Location) MCLocation(com.laytonsmith.abstraction.MCLocation)

Aggregations

MCLocation (com.laytonsmith.abstraction.MCLocation)15 BukkitMCLocation (com.laytonsmith.abstraction.bukkit.BukkitMCLocation)6 Location (org.bukkit.Location)6 MCWorld (com.laytonsmith.abstraction.MCWorld)4 BukkitMCWorld (com.laytonsmith.abstraction.bukkit.BukkitMCWorld)4 MCEntity (com.laytonsmith.abstraction.MCEntity)3 MCItemStack (com.laytonsmith.abstraction.MCItemStack)3 CArray (com.laytonsmith.core.constructs.CArray)3 EventHandler (org.bukkit.event.EventHandler)3 BukkitMCEntity (com.laytonsmith.abstraction.bukkit.entities.BukkitMCEntity)2 BukkitMCLivingEntity (com.laytonsmith.abstraction.bukkit.entities.BukkitMCLivingEntity)2 CREFormatException (com.laytonsmith.core.exceptions.CRE.CREFormatException)2 StaticTest (com.laytonsmith.testing.StaticTest)2 Particle (org.bukkit.Particle)2 Test (org.junit.Test)2 MCInventory (com.laytonsmith.abstraction.MCInventory)1 MCLivingEntity (com.laytonsmith.abstraction.MCLivingEntity)1 MCPlayer (com.laytonsmith.abstraction.MCPlayer)1 MCServer (com.laytonsmith.abstraction.MCServer)1 MCBlock (com.laytonsmith.abstraction.blocks.MCBlock)1