Search in sources :

Example 11 with MCItemStack

use of com.laytonsmith.abstraction.MCItemStack 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)

Aggregations

MCItemStack (com.laytonsmith.abstraction.MCItemStack)11 MCItemMeta (com.laytonsmith.abstraction.MCItemMeta)4 CArray (com.laytonsmith.core.constructs.CArray)4 CString (com.laytonsmith.core.constructs.CString)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 MCLocation (com.laytonsmith.abstraction.MCLocation)3 CNull (com.laytonsmith.core.constructs.CNull)3 Construct (com.laytonsmith.core.constructs.Construct)3 CREFormatException (com.laytonsmith.core.exceptions.CRE.CREFormatException)3 Location (org.bukkit.Location)3 ItemStack (org.bukkit.inventory.ItemStack)3 MCEnchantment (com.laytonsmith.abstraction.MCEnchantment)2 MCFurnaceRecipe (com.laytonsmith.abstraction.MCFurnaceRecipe)2 MCShapedRecipe (com.laytonsmith.abstraction.MCShapedRecipe)2 MCShapelessRecipe (com.laytonsmith.abstraction.MCShapelessRecipe)2 BukkitMCLocation (com.laytonsmith.abstraction.bukkit.BukkitMCLocation)2 CRECastException (com.laytonsmith.core.exceptions.CRE.CRECastException)2 CRENotFoundException (com.laytonsmith.core.exceptions.CRE.CRENotFoundException)2 CRERangeException (com.laytonsmith.core.exceptions.CRE.CRERangeException)2