org.bukkit.entity.LeashHitch Java Examples

The following examples show how to use org.bukkit.entity.LeashHitch. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RegionInteractListener.java    From NovaGuilds with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Handles breaking paintings, item frames, leashes
 *
 * @param event The event
 */
@EventHandler
public void onHangingEntityBreak(HangingBreakByEntityEvent event) {
	if(!(event.getRemover() instanceof Player)) {
		return;
	}

	Player player = (Player) event.getRemover();
	NovaPlayer nPlayer = PlayerManager.getPlayer(player);
	boolean isLeash = event.getEntity() instanceof LeashHitch;

	if(RegionManager.get(event.getEntity()) != null
			&& (!plugin.getRegionManager().canInteract(player, event.getEntity()) || (!nPlayer.getPreferences().getBypass() && !nPlayer.hasPermission(isLeash ? GuildPermission.MOB_LEASH : GuildPermission.BLOCK_BREAK)))) {
		event.setCancelled(true);
		(isLeash ? Message.CHAT_REGION_DENY_UNLEASH : Message.CHAT_REGION_DENY_INTERACT).send(player);
	}
}
 
Example #2
Source File: RegionMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Material getHangingType(Hanging hanging) {
  if (hanging instanceof Painting) {
    return Material.PAINTING;
  } else if (hanging instanceof ItemFrame) {
    return Material.ITEM_FRAME;
  } else if (hanging instanceof LeashHitch) {
    return Material.LEASH;
  } else {
    return null;
  }
}
 
Example #3
Source File: EventRuleMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
private static Material getHangingType(Hanging hanging) {
    if(hanging instanceof Painting) {
        return Material.PAINTING;
    } else if(hanging instanceof ItemFrame) {
        return Material.ITEM_FRAME;
    } else if(hanging instanceof LeashHitch) {
        return Material.LEASH;
    } else {
        return null;
    }
}
 
Example #4
Source File: SchematicUtil.java    From PlotMe-Core with GNU General Public License v3.0 5 votes vote down vote up
private org.bukkit.entity.Entity getLeash(IWorld world1, Leash leash, com.worldcretornica.plotme_core.api.Vector loc, int originX, int originY,
        int originZ) {
    org.bukkit.entity.Entity ent = null;
    World world = ((BukkitWorld) world1).getWorld();

    int x = leash.getX() - originX;
    int y = leash.getY() - originY;
    int z = leash.getZ() - originZ;

    org.bukkit.Location etloc = new org.bukkit.Location(world, x + loc.getBlockX(), y + loc.getBlockY(), z + loc.getBlockZ());

    Block block = world.getBlockAt(etloc);

    if (block.getType() == Material.FENCE || block.getType() == Material.NETHER_FENCE) {
        etloc.setX(Math.floor(etloc.getX()));
        etloc.setY(Math.floor(etloc.getY()));
        etloc.setZ(Math.floor(etloc.getZ()));

        ent = world.spawnEntity(etloc, EntityType.LEASH_HITCH);

        List<org.bukkit.entity.Entity> nearbyentities = ent.getNearbyEntities(1, 1, 1);

        for (org.bukkit.entity.Entity nearby : nearbyentities) {
            if (nearby instanceof LeashHitch) {
                if (nearby.getLocation().distance(ent.getLocation()) == 0) {
                    ent.remove();
                    return nearby;
                }
            }
        }
    }

    return ent;
}