BukkitPlayer implements Player, CommandSender, FineTarget, BurnTarget, KillTarget, KickTarget { @Override public boolean hasPermission(String permString) { if (stopwatch.elapsed(TimeUnit.SECONDS) > MAX_CACHE_AGE_SECS) { stopwatch.reset(); stopwatch.start(); playerPermCache.clear(); } Boolean hasPerm = playerPermCache.get(permString); if (hasPerm == null) { Boolean newPerm = minecraftAPI.playerIdHasPermission(playerId, permString); if (newPerm != null) playerPermCache.putIfAbsent(permString, newPerm); } hasPerm = playerPermCache.get(permString); return hasPerm != null && hasPerm; } BukkitPlayer(UUID uuid, MinecraftAPI api);   BukkitPlayer(UUID uuid, MinecraftAPI api, Ticker ticker); @Override boolean hasPermission(String permString); @NotNull @Override String getName(); @NotNull @Override UUID getId(); String getWorldName(); boolean burn(final int duration, final String messageString); @Override void sendMessage(final String message); @Override void sendMessages(final List<String> messages); @Override void sendMessage(TextComponent message); void executeCommand(final String command); boolean fine(final Double amount, final String messageString); void kick(final String messageString); void kill(final String messageString); @Override String getPlace(); @Override MinecraftAPI getMineCraftApi();  }
@Test public void hasPermissionWorksWithNull() { MockMinecraftAPI api = new MockMinecraftAPI(); BukkitPlayer bukkitPlayer = new BukkitPlayer(UUID.randomUUID(), api); api.permReturnValue = null; assertFalse(bukkitPlayer.hasPermission("TestTrue")); }
@Test public void testHasPermissionCachesValues() { MockMinecraftAPI api = new MockMinecraftAPI(); BukkitPlayer bukkitPlayer = new BukkitPlayer(UUID.randomUUID(), api, ticker); api.permReturnValue = Boolean.TRUE; assertTrue(bukkitPlayer.hasPermission("TestTrue")); api.permReturnValue = Boolean.FALSE; assertTrue(bukkitPlayer.hasPermission("TestTrue")); api.permReturnValue = Boolean.FALSE; ticker.setElapsed(TimeUnit.SECONDS.toNanos(BukkitPlayer.MAX_CACHE_AGE_SECS + 1)); assertFalse(bukkitPlayer.hasPermission("TestTrue")); }