下面列出了怎么用org.bukkit.entity.Enderman的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
protected boolean init(final @Nullable Class<? extends Enderman> c, final @Nullable Enderman e) {
if (e != null) {
if (useBlockData) {
BlockData data = e.getCarriedBlock();
if (data != null) {
Material type = data.getMaterial();
assert type != null;
hand = new ItemType[] {new ItemType(type)};
}
} else {
MaterialData m = e.getCarriedMaterial();
if (m != null) {
final ItemStack i = m.toItemStack(1);
if (i == null)
return false;
hand = new ItemType[] {new ItemType(i)};
}
}
}
return true;
}
@Override
public void set(final Enderman entity) {
if (hand != null) {
final ItemType t = CollectionUtils.getRandom(hand);
assert t != null;
final ItemStack i = t.getBlock().getRandom();
if (i != null) {
if (useBlockData) { // 1.13: item->block usually keeps only material
entity.setCarriedBlock(Bukkit.createBlockData(i.getType()));
} else {
MaterialData data = i.getData();
assert data != null;
entity.setCarriedMaterial(data);
}
}
}
}
/**
* Allows or prevents enderman griefing
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEndermanGrief(final EntityChangeBlockEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
if (!(e.getEntity() instanceof Enderman)) {
return;
}
if (!inWorld(e.getEntity())) {
return;
}
// Prevent Enderman griefing at spawn
if (plugin.getGrid() != null && plugin.getGrid().isAtSpawn(e.getEntity().getLocation())) {
e.setCancelled(true);
}
if (Settings.allowEndermanGriefing)
return;
// Stop the Enderman from griefing
// plugin.getLogger().info("Enderman stopped from griefing);
e.setCancelled(true);
}
/**
* Drops the Enderman's block when he dies if he has one
*
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEndermanDeath(final EntityDeathEvent e) {
if (DEBUG) {
plugin.getLogger().info(e.getEventName());
}
if (!Settings.endermanDeathDrop)
return;
if (!inWorld(e.getEntity())) {
return;
}
if (!(e.getEntity() instanceof Enderman)) {
// plugin.getLogger().info("Not an Enderman!");
return;
}
// Get the block the enderman is holding
Enderman ender = (Enderman) e.getEntity();
MaterialData m = ender.getCarriedMaterial();
if (m != null && !m.getItemType().equals(Material.AIR)) {
// Drop the item
// plugin.getLogger().info("Dropping item " + m.toString());
e.getEntity().getWorld().dropItemNaturally(e.getEntity().getLocation(), m.toItemStack(1));
}
}
@Override
public boolean match(final Enderman entity) {
return hand == null || SimpleExpression.check(hand, new Checker<ItemType>() {
@SuppressWarnings("null")
@Override
public boolean check(final @Nullable ItemType t) {
// TODO {Block/Material}Data -> Material conversion is not 100% accurate, needs a better solution
if (useBlockData)
return t != null && t.isOfType(entity.getCarriedBlock().getMaterial());
else
return t != null && t.isOfType(entity.getCarriedMaterial().getItemType());
}
}, false, false);
}
public EndermanAttackPlayerEvent(Enderman entity, Player player) {
super(entity);
this.player = player;
}
public EndermanEscapeEvent(Enderman entity, Reason reason) {
super(entity);
this.reason = reason;
}
@Override
public Enderman getEntity() {
return (Enderman) super.getEntity();
}
@Override
public Class<Enderman> getType() {
return Enderman.class;
}
@Override
public Enderman getBukkitEntity() {
return (Enderman) super.getBukkitEntity();
}
/**
* The enderman considering attacking
*
* @return The enderman considering attacking
*/
@Override
public Enderman getEntity() {
return (Enderman) super.getEntity();
}