下面列出了怎么用org.bukkit.entity.Guardian的API类实例代码及写法,或者点击链接到github查看源代码。
@SuppressWarnings({"null", "deprecation"})
@Override
protected boolean init(Class<? extends Guardian> c, Guardian e) {
if(e != null)
isElder = e.isElder();
return true;
}
@SuppressWarnings("deprecation")
@Override
public void set(Guardian entity) {
if(isElder)
entity.setElder(true);
}
/**
* Runs repeating tasks to deliver acid damage to mobs, etc.
* @param plugin - ASkyBlock plugin object - ASkyBlock plugin
*/
public AcidTask(final ASkyBlock plugin) {
this.plugin = plugin;
// Initialize water item list
itemsInWater = new HashSet<>();
// This part will kill monsters if they fall into the water
// because it
// is acid
if (Settings.mobAcidDamage > 0D || Settings.animalAcidDamage > 0D) {
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, () -> {
List<Entity> entList = ASkyBlock.getIslandWorld().getEntities();
for (Entity current : entList) {
if (plugin.isOnePointEight() && current instanceof Guardian) {
// Guardians are immune to acid too
continue;
}
if ((current instanceof Monster) && Settings.mobAcidDamage > 0D) {
if ((current.getLocation().getBlock().getType() == Material.WATER)
|| (current.getLocation().getBlock().getType() == Material.STATIONARY_WATER)) {
((Monster) current).damage(Settings.mobAcidDamage);
}
} else if ((current instanceof Animals) && Settings.animalAcidDamage > 0D) {
if ((current.getLocation().getBlock().getType() == Material.WATER)
|| (current.getLocation().getBlock().getType() == Material.STATIONARY_WATER)) {
if (!current.getType().equals(EntityType.CHICKEN) || Settings.damageChickens) {
((Animals) current).damage(Settings.animalAcidDamage);
}
}
}
}
}, 0L, 20L);
}
runAcidItemRemovalTask();
}
@SuppressWarnings("deprecation")
@Override
protected boolean match(Guardian entity) {
return entity.isElder() == isElder;
}
@Override
public Class<? extends Guardian> getType() {
return Guardian.class;
}
@Override
Guardian getBukkitEntity();
@Test
public void testGetEntity() {
List<Entity> testList = new ArrayList<>();
ArmorStand fakeArmorStand = mock(ArmorStand.class);
Cow fakeCow = mock(Cow.class);
Evoker fakeEvoker = mock(Evoker.class);
Guardian fakeGuardian = mock(Guardian.class);
Pig fakePig = mock(Pig.class);
PigZombie fakePigZombie = mock(PigZombie.class);
Pillager fakePillager = mock(Pillager.class);
Sheep fakeSheep = mock(Sheep.class);
Skeleton fakeSkeleton = mock(Skeleton.class);
Turtle fakeTurtle = mock(Turtle.class);
Villager fakeVillager = mock(Villager.class);
WanderingTrader fakeWanderingTrader = mock(WanderingTrader.class);
testList.add(fakeArmorStand);
testList.add(fakeCow);
testList.add(fakeEvoker);
testList.add(fakeGuardian);
testList.add(fakePig);
testList.add(fakePigZombie);
testList.add(fakePillager);
testList.add(fakeSheep);
testList.add(fakeSkeleton);
testList.add(fakeTurtle);
testList.add(fakeVillager);
testList.add(fakeWanderingTrader);
List<Sheep> sheepList = EntityUtil.getEntity(testList, Sheep.class);
assertEquals(1, sheepList.size());
assertEquals(fakeSheep, sheepList.get(0));
List<Animals> animalsList = EntityUtil.getAnimals(testList);
assertEquals(4, animalsList.size());
assertTrue(animalsList.contains(fakeCow));
assertTrue(animalsList.contains(fakePig));
assertTrue(animalsList.contains(fakeSheep));
assertTrue(animalsList.contains(fakeTurtle));
List<Monster> monsterList = EntityUtil.getMonsters(testList);
assertEquals(5, monsterList.size());
assertTrue(monsterList.contains(fakeEvoker));
assertTrue(monsterList.contains(fakeGuardian));
assertTrue(monsterList.contains(fakePigZombie));
assertTrue(monsterList.contains(fakePillager));
assertTrue(monsterList.contains(fakeSkeleton));
List<NPC> npcList = EntityUtil.getNPCs(testList);
assertEquals(2, npcList.size());
assertTrue(npcList.contains(fakeVillager));
assertTrue(npcList.contains(fakeWanderingTrader));
}