Java Code Examples for org.bukkit.util.BlockIterator#hasNext()

The following examples show how to use org.bukkit.util.BlockIterator#hasNext() . 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: SubCommand_Buy.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCommand(
        @NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
    if (!(sender instanceof Player)) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("Can't run command by Console", sender));
        return;
    }

    final BlockIterator bIt = new BlockIterator((LivingEntity) sender, 10);

    if (!bIt.hasNext()) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
        return;
    }

    while (bIt.hasNext()) {
        final Block b = bIt.next();
        final Shop shop = plugin.getShopManager().getShop(b.getLocation());

        if (shop != null) {
            if (shop.getModerator().isModerator(((Player) sender).getUniqueId()) || QuickShop.getPermissionManager().hasPermission(sender, "quickshop.other.control")) {
                shop.setShopType(ShopType.BUYING);
                // shop.setSignText();
                shop.update();
                MsgUtil.sendMessage(sender, MsgUtil.getMessage("command.now-buying", sender, Util.getItemStackName(shop.getItem())));
            } else {
                MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-managed-shop", sender));
            }
            return;
        }
    }

    MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
}
 
Example 2
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Block getHitBlock(ProjectileHitEvent event) {
	BlockIterator iterator = new BlockIterator(event.getEntity().getWorld(), event.getEntity().getLocation().toVector(), event.getEntity().getVelocity().normalize(), 0.0D, 4);
	Block hitBlock = null;
	while (iterator.hasNext()) {
		hitBlock = iterator.next();
		if (hitBlock.getType() != Material.AIR) {
			break;
		}
	}
	return hitBlock;
}
 
Example 3
Source File: NMSHandler.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Block getHitBlock(ProjectileHitEvent event) {
	BlockIterator iterator = new BlockIterator(event.getEntity().getWorld(), event.getEntity().getLocation().toVector(), event.getEntity().getVelocity().normalize(), 0.0D, 4);
	Block hitBlock = null;
	while (iterator.hasNext()) {
		hitBlock = iterator.next();
		if (hitBlock.getType() != Material.AIR) {
			break;
		}
	}
	return hitBlock;
}
 
Example 4
Source File: ProjectileMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onProjectileHitEvent(ProjectileHitEvent event) {
    final Projectile projectile = event.getEntity();
    final ProjectileDefinition projectileDefinition = Projectiles.getProjectileDefinition(projectile);
    if(projectileDefinition == null) return;

    final Filter filter = projectileDefinition.destroyFilter();
    if(filter == null) return;

    final BlockIterator blockIterator = new BlockIterator(projectile.getWorld(), projectile.getLocation().toVector(), projectile.getVelocity().normalize(), 0d, 2);
    Block hitBlock = null;
    while(blockIterator.hasNext()) {
        hitBlock = blockIterator.next();
        if(hitBlock.getType() != Material.AIR) break;
    }

    if(hitBlock != null) {
        final MatchPlayer shooter = projectile.getShooter() instanceof Player ? getMatch().getPlayer((Player) projectile.getShooter()) : null;
        final IQuery query = shooter != null ? new PlayerBlockEventQuery(shooter, event, hitBlock.getState())
                                             : new BlockEventQuery(event, hitBlock);

        if(filter.query(query).isAllowed()) {
            final BlockTransformEvent bte = new BlockTransformEvent(event, hitBlock, Material.AIR);
            match.callEvent(bte);

            if(!bte.isCancelled()) {
                hitBlock.setType(Material.AIR);
                projectile.remove();
            }
        }
    }
}
 
Example 5
Source File: TargetHelper.java    From ActionHealth with MIT License 5 votes vote down vote up
public Block getTarget(Location from, int distance, Set<Byte> transparentTypeIds) {
    BlockIterator itr = new BlockIterator(from, 0, distance);
    while (itr.hasNext()) {
        Block block = itr.next();
        int id = block.getType().getId();
        if (transparentTypeIds == null) {
            if (id == 0) continue;
        } else if (transparentTypeIds.contains((byte) id)) {
            continue;
        }
        return block;
    }
    return null;
}
 
Example 6
Source File: BlockInteractOcclusion.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void check(InteractWorldEvent e) {
    HawkPlayer pp = e.getHawkPlayer();
    Vector eyePos = pp.getPosition().clone().add(new Vector(0, pp.isSneaking() ? 1.54 : 1.62, 0));
    Vector direction = MathPlus.getDirection(pp.getYaw(), pp.getPitch());

    Location bLoc = e.getTargetedBlockLocation();
    Block b = bLoc.getBlock();
    WrappedBlock bNMS = WrappedBlock.getWrappedBlock(b, pp.getClientVersion());
    AABB targetAABB = new AABB(bNMS.getHitBox().getMin(), bNMS.getHitBox().getMax());

    double distance = targetAABB.distanceToPosition(eyePos);
    BlockIterator iter = new BlockIterator(pp.getWorld(), eyePos, direction, 0, (int) distance + 2);
    while (iter.hasNext()) {
        Block bukkitBlock = iter.next();

        if (bukkitBlock.getType() == Material.AIR || bukkitBlock.isLiquid())
            continue;
        if (bukkitBlock.getLocation().equals(bLoc))
            break;

        WrappedBlock iterBNMS = WrappedBlock.getWrappedBlock(bukkitBlock, pp.getClientVersion());
        AABB checkIntersection = new AABB(iterBNMS.getHitBox().getMin(), iterBNMS.getHitBox().getMax());
        Vector occludeIntersection = checkIntersection.intersectsRay(new Ray(eyePos, direction), 0, Float.MAX_VALUE);
        if (occludeIntersection != null) {
            if (occludeIntersection.distance(eyePos) < distance) {
                Placeholder ph = new Placeholder("type", iterBNMS.getBukkitBlock().getType());
                punishAndTryCancelAndBlockRespawn(pp, 1, e, ph);
                return;
            }
        }
    }
}
 
Example 7
Source File: SubCommand_Sell.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCommand(
        @NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
    if (!(sender instanceof Player)) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("Can't run command by Console", sender));
        return;
    }

    final BlockIterator bIt = new BlockIterator((LivingEntity) sender, 10);

    if (!bIt.hasNext()) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
        return;
    }

    while (bIt.hasNext()) {
        final Block b = bIt.next();
        final Shop shop = plugin.getShopManager().getShop(b.getLocation());

        if (shop != null) {
            if (shop.getModerator().isModerator(((Player) sender).getUniqueId()) || QuickShop.getPermissionManager().hasPermission(sender, "quickshop.other.control")) {
                shop.setShopType(ShopType.SELLING);
                // shop.setSignText();
                shop.update();
                MsgUtil.sendMessage(sender,
                        MsgUtil.getMessage("command.now-selling", sender, Util.getItemStackName(shop.getItem())));
                return;
            } else {
                MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-managed-shop", sender));
                return;
            }
        }
    }
    MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
}
 
Example 8
Source File: SubCommand_Remove.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCommand(
        @NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
    if (!(sender instanceof Player)) {
        MsgUtil.sendMessage(sender, ChatColor.RED + "Only players may use that command.");
        return;
    }

    final Player p = (Player) sender;
    final BlockIterator bIt = new BlockIterator(p, 10);

    if (!bIt.hasNext()) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
        return;
    }

    while (bIt.hasNext()) {
        final Block b = bIt.next();
        final Shop shop = plugin.getShopManager().getShop(b.getLocation());

        if (shop == null) {
            continue;
        }

        if (shop.getModerator().isModerator(((Player) sender).getUniqueId())
                || QuickShop.getPermissionManager().hasPermission(p, "quickshop.other.destroy")) {
            //shop.onUnload();
            shop.delete();
            plugin.log("Deleting shop "+shop+" request by /qs remove command.");
        } else {
            MsgUtil.sendMessage(sender, ChatColor.RED + MsgUtil.getMessage("no-permission", sender));
        }

        return;
    }

    MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
}
 
Example 9
Source File: SubCommand_Unlimited.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCommand(
        @NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
    if (!(sender instanceof Player)) {
        MsgUtil.sendMessage(sender, "Only player can run this command.");
        return;
    }

    final BlockIterator bIt = new BlockIterator((Player) sender, 10);

    if (!bIt.hasNext()) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
        return;
    }

    while (bIt.hasNext()) {
        final Block b = bIt.next();
        final Shop shop = plugin.getShopManager().getShop(b.getLocation());

        if (shop == null) {
            continue;
        }

        shop.setUnlimited(!shop.isUnlimited());
        // shop.setSignText();
        shop.update();

        if (shop.isUnlimited()) {
            MsgUtil.sendMessage(sender, MsgUtil.getMessage("command.toggle-unlimited.unlimited", sender));
            return;
        }

        MsgUtil.sendMessage(sender, MsgUtil.getMessage("command.toggle-unlimited.limited", sender));

        return;
    }

    MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
}
 
Example 10
Source File: DelsignCommand.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(CommandSender sender, String[] args) {
	if(!sender.hasPermission("areashop.delsign")) {
		plugin.message(sender, "delsign-noPermission");
		return;
	}
	if(!(sender instanceof Player)) {
		plugin.message(sender, "cmd-onlyByPlayer");
		return;
	}
	Player player = (Player)sender;

	// Get the sign
	Block block = null;
	BlockIterator blockIterator = new BlockIterator(player, 100);
	while(blockIterator.hasNext() && block == null) {
		Block next = blockIterator.next();
		if(next.getType() != Material.AIR) {
			block = next;
		}
	}
	if(block == null || !Materials.isSign(block.getType())) {
		plugin.message(sender, "delsign-noSign");
		return;
	}
	RegionSign regionSign = SignsFeature.getSignByLocation(block.getLocation());
	if(regionSign == null) {
		plugin.message(sender, "delsign-noRegion");
		return;
	}
	plugin.message(sender, "delsign-success", regionSign.getRegion());
	regionSign.remove();
}
 
Example 11
Source File: SubCommand_SuperCreate.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCommand(
        @NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
    if (!(sender instanceof Player)) {
        MsgUtil.sendMessage(sender, "This command can't be run by console");
        return;
    }

    final Player p = (Player) sender;
    final ItemStack item = p.getInventory().getItemInMainHand();

    if (item.getType() == Material.AIR) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("no-anythings-in-your-hand", sender));
        return;
    }

    final BlockIterator bIt = new BlockIterator((LivingEntity) sender, 10);

    while (bIt.hasNext()) {
        final Block b = bIt.next();

        if (!Util.canBeShop(b)) {
            continue;
        }

        BlockFace blockFace;

        try {
            blockFace = p.getFacing();
        } catch (Throwable throwable) {
            blockFace = Util.getYawFace(p.getLocation().getYaw());
        }

        if (!plugin.getShopManager().canBuildShop(p, b, blockFace)) {
            // As of the new checking system, most plugins will tell the
            // player why they can't create a shop there.
            // So telling them a message would cause spam etc.
            Util.debugLog("Util report you can't build shop there.");
            return;
        }

        if (Util.getSecondHalf(b) != null
                && !QuickShop.getPermissionManager().hasPermission(sender, "quickshop.create.double")) {
            MsgUtil.sendMessage(p, MsgUtil.getMessage("no-double-chests", sender));
            return;
        }

        if (Util.isBlacklisted(item)
                && !QuickShop.getPermissionManager()
                .hasPermission(p, "quickshop.bypass." + item.getType().name())) {
            MsgUtil.sendMessage(p, MsgUtil.getMessage("blacklisted-item", sender));
            return;
        }

        if (cmdArg.length >= 1) {
            plugin.getShopManager().handleChat(p, cmdArg[0], true);
            return;
        }
        // Send creation menu.
        final Info info =
                new Info(
                        b.getLocation(),
                        ShopAction.CREATE,
                        p.getInventory().getItemInMainHand(),
                        b.getRelative(p.getFacing().getOppositeFace()));

        plugin.getShopManager().getActions().put(p.getUniqueId(), info);
        MsgUtil.sendMessage(p,
                MsgUtil.getMessage("how-much-to-trade-for", sender, Util.getItemStackName(item), Integer.toString(plugin.isAllowStack() && QuickShop.getPermissionManager().hasPermission(p, "quickshop.create.stacks") ? item.getAmount() : 1)));
        return;
    }
    MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
}
 
Example 12
Source File: SubCommand_Size.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCommand(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
    if (!(sender instanceof Player)) {
        MsgUtil.sendMessage(sender, "This command can't be run by console");
        return;
    }
    if (cmdArg.length < 1) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("command.bulk-size-not-set", sender));
        return;
    }
    int amount;
    try {
        amount = Integer.parseInt(cmdArg[0]);
    } catch (NumberFormatException e) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-a-integer", sender, cmdArg[0]));
        return;
    }
    final BlockIterator bIt = new BlockIterator((Player) sender, 10);
    // Loop through every block they're looking at upto 10 blocks away
    if (!bIt.hasNext()) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
        return;
    }

    while (bIt.hasNext()) {
        final Block b = bIt.next();
        final Shop shop = plugin.getShopManager().getShop(b.getLocation());
        if (shop != null) {
            if (shop.getModerator().isModerator(((Player) sender).getUniqueId()) || sender.hasPermission("quickshop.other.amount")) {
                if (amount <= 0 || amount > Util.getItemMaxStackSize(shop.getItem().getType())) {
                    MsgUtil.sendMessage(sender, MsgUtil.getMessage("command.invalid-bulk-amount", sender, Integer.toString(amount)));
                    return;
                }
                shop.getItem().setAmount(amount);
                shop.refresh();
                MsgUtil.sendMessage(sender, MsgUtil.getMessage("command.bulk-size-now", sender, Integer.toString(shop.getItem().getAmount()), Util.getItemStackName(shop.getItem())));
                return;
            } else {
                MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-managed-shop", sender));
            }
        }
    }
    MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));


}
 
Example 13
Source File: FlagSnowballs.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler
public void onProjectileHit(ProjectileHitEvent event) {
	Projectile projectile = event.getEntity();
	if (!(projectile instanceof Snowball)) {
		return;
	}
	
	ProjectileSource shooter = projectile.getShooter();
	if (!(shooter instanceof Player)) {
		return;
	}
	
	SpleefPlayer player = getHeavySpleef().getSpleefPlayer(shooter);
	GameManager manager = getHeavySpleef().getGameManager();
	Game game;
	
	if ((game = manager.getGame(player)) == null) {
		return;
	}

	Location location = projectile.getLocation();
	Vector start = location.toVector();
	Vector dir = projectile.getVelocity().normalize();
	
	BlockIterator iterator = new BlockIterator(projectile.getWorld(), start, dir, 0, 4);
	
	Block blockHit = null;
	
	while (iterator.hasNext()) {
		blockHit = iterator.next();
		
		if (blockHit.getType() != Material.AIR) {
			break;
		}
	}
	
	if (!game.canSpleef(blockHit)) {
		//Cannot remove this block
		return;
	}
	
	projectile.remove();
	game.addBlockBroken(player, blockHit);
	
	blockHit.setType(Material.AIR);
	if (game.getPropertyValue(GameProperty.PLAY_BLOCK_BREAK)) {
		blockHit.getWorld().playEffect(blockHit.getLocation(), Effect.STEP_SOUND, blockHit.getTypeId());
	}
}
 
Example 14
Source File: SubCommand_Staff.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCommand(
        @NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
    if (!(sender instanceof Player)) {
        MsgUtil.sendMessage(sender, "Only player can execute this command.");
        return;
    }

    final BlockIterator bIt = new BlockIterator((LivingEntity) sender, 10);

    if (!bIt.hasNext()) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
        return;
    }
    while (bIt.hasNext()) {
        final Block b = bIt.next();
        final Shop shop = plugin.getShopManager().getShop(b.getLocation());
        if (shop == null || !shop.getModerator().isModerator(((Player) sender).getUniqueId())) {
            continue;
        }
        switch (cmdArg.length) {
            case 1:
                switch (cmdArg[0]) {
                    case "clear":
                        shop.clearStaffs();
                        MsgUtil.sendMessage(sender, MsgUtil.getMessage("shop-staff-cleared", sender));
                        return;
                    case "list":
                        final List<UUID> staffs = shop.getStaffs();
                        if (staffs.isEmpty()) {
                            MsgUtil.sendMessage(sender,
                                    ChatColor.GREEN
                                            + MsgUtil.getMessage("tableformat.left_begin", sender)
                                            + "Empty");
                            return;
                        }
                        for (UUID uuid : staffs) {
                            MsgUtil.sendMessage(sender,
                                    ChatColor.GREEN
                                            + MsgUtil.getMessage("tableformat.left_begin", sender)
                                            + Bukkit.getOfflinePlayer(uuid).getName());
                        }
                        return;
                    case "add":
                    case "del":
                    default:
                        MsgUtil.sendMessage(sender, MsgUtil.getMessage("command.wrong-args", sender));
                        return;
                }
            case 2:
                final OfflinePlayer offlinePlayer = plugin.getServer().getOfflinePlayer(cmdArg[1]);
                String offlinePlayerName = offlinePlayer.getName();

                if (offlinePlayerName == null) {
                    offlinePlayerName = "null";
                }
                switch (cmdArg[0]) {
                    case "add":
                        shop.addStaff(offlinePlayer.getUniqueId());
                        MsgUtil.sendMessage(sender, MsgUtil.getMessage("shop-staff-added", sender, offlinePlayerName));
                        return;
                    case "del":
                        shop.delStaff(offlinePlayer.getUniqueId());
                        MsgUtil.sendMessage(sender,
                                MsgUtil.getMessage("shop-staff-deleted", sender, offlinePlayerName));
                        return;
                    default:
                        MsgUtil.sendMessage(sender, MsgUtil.getMessage("command.wrong-args", sender));
                        return;
                }
            default:
                MsgUtil.sendMessage(sender, MsgUtil.getMessage("command.wrong-args", sender));
                return;
        }
    }
    //no match shop
    MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
}
 
Example 15
Source File: SubCommand_Item.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCommand(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
    if (!(sender instanceof Player)) {
        MsgUtil.sendMessage(sender, "Can't run command by Console");
        return;
    }
    final BlockIterator bIt = new BlockIterator((Player) sender, 10);
    // Loop through every block they're looking at upto 10 blocks away
    if (!bIt.hasNext()) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
        return;
    }
    while (bIt.hasNext()) {
        final Block b = bIt.next();
        final Shop shop = plugin.getShopManager().getShop(b.getLocation());

        if (shop != null) {
            if (!shop.getModerator().isModerator(((Player) sender).getUniqueId()) && !QuickShop.getPermissionManager().hasPermission(sender, "quickshop.other.item")) {
                MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-managed-shop", sender));
                return;
            }
            ItemStack itemStack = ((Player) sender).getInventory().getItemInMainHand().clone();
            if (itemStack.getType() == Material.AIR) {
                MsgUtil.sendMessage(sender, MsgUtil.getMessage("command.no-trade-item", sender));
                return;
            }
            if (Util.isBlacklisted(itemStack) && !QuickShop.getPermissionManager().hasPermission(sender, "quickshop.bypass." + itemStack.getType().name())) {
                MsgUtil.sendMessage(sender, MsgUtil.getMessage("blacklisted-item", sender));
                return;
            }
            if (!plugin.isAllowStack() && !QuickShop.getPermissionManager().hasPermission(sender, "quickshop.create.stacks")) {
                itemStack.setAmount(1);
            }
            shop.setItem(itemStack);
            MsgUtil.sendItemholochat(shop, shop.getItem(), (Player) sender, MsgUtil.getMessage("command.trade-item-now", sender, Integer.toString(shop.getItem().getAmount()), Util.getItemStackName(shop.getItem())));
            return;
        }
        // shop.setSignText();
    }
    MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
}
 
Example 16
Source File: SubCommand_Create.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCommand(
        @NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
    if (!(sender instanceof Player)) {
        MsgUtil.sendMessage(sender, "This command can't be run by console");
        return;
    }

    final Player p = (Player) sender;
    final ItemStack item = p.getInventory().getItemInMainHand();

    if (item.getType() == Material.AIR) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("no-anythings-in-your-hand", sender));
        return;
    }

    final BlockIterator bIt = new BlockIterator((LivingEntity) sender, 10);

    while (bIt.hasNext()) {
        final Block b = bIt.next();

        if (!Util.canBeShop(b)) {
            continue;
        }

        if (p.isOnline()) {
            Result result = plugin.getPermissionChecker().canBuild(p, b);
            if (!result.isSuccess()) {
                MsgUtil.sendMessage(p, MsgUtil.getMessage("3rd-plugin-build-check-failed", p, result.getMessage()));
                Util.debugLog("Failed to create shop because protection check failed, found:" + result.getMessage());
                return;
            }
        }

        BlockFace blockFace;
        try {
            blockFace = p.getFacing();
        } catch (Throwable throwable) {
            blockFace = Util.getYawFace(p.getLocation().getYaw());
        }

        if (!plugin.getShopManager().canBuildShop(p, b, blockFace)) {
            // As of the new checking system, most plugins will tell the
            // player why they can't create a shop there.
            // So telling them a message would cause spam etc.
            Util.debugLog("Util report you can't build shop there.");
            return;
        }

        if (Util.getSecondHalf(b) != null
                && !QuickShop.getPermissionManager().hasPermission(p, "quickshop.create.double")) {
            MsgUtil.sendMessage(p, MsgUtil.getMessage("no-double-chests", sender));
            return;
        }

        if (Util.isBlacklisted(item)
                && !QuickShop.getPermissionManager()
                .hasPermission(p, "quickshop.bypass." + item.getType().name())) {
            MsgUtil.sendMessage(p, MsgUtil.getMessage("blacklisted-item", sender));
            return;
        }

        // Send creation menu.
        plugin
                .getShopManager()
                .getActions()
                .put(
                        p.getUniqueId(),
                        new Info(
                                b.getLocation(),
                                ShopAction.CREATE,
                                p.getInventory().getItemInMainHand(),
                                b.getRelative(p.getFacing().getOppositeFace())));

        if (cmdArg.length >= 1) {
            plugin.getShopManager().handleChat(p, cmdArg[0]);

            return;
        }

        MsgUtil.sendMessage(p,
                MsgUtil.getMessage("how-much-to-trade-for", sender, Util.getItemStackName(item), Integer.toString(plugin.isAllowStack() && QuickShop.getPermissionManager().hasPermission(p, "quickshop.create.stacks") ? item.getAmount() : 1)));

        return;
    }
}
 
Example 17
Source File: LoseCheckerTask.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void run() {
	for (Game game : gameManager.getGames()) {
		if (game.getGameState() != GameState.INGAME) {
			continue;
		}
		
		Set<SpleefPlayer> deathCandidates = null;
		final boolean isLiquidDeathzone = game.getPropertyValue(GameProperty.USE_LIQUID_DEATHZONE);
		
		for (SpleefPlayer player : game.getPlayers()) {
			Location playerLoc = player.getBukkitPlayer().getLocation();
			
			boolean isDeathCandidate = isInsideDeathzone(playerLoc, game, isLiquidDeathzone);
			if (!isDeathCandidate && recentLocations.containsKey(player)) {
				//Try to check every block the player has passed between the recent location and his location now
				Location recent = recentLocations.get(player);
				org.bukkit.util.Vector direction = playerLoc.clone().subtract(recent).toVector();
				int directionLength = (int) direction.length();
				
				if (directionLength > 0) {
					BlockIterator iterator = new BlockIterator(game.getWorld(), recent.toVector(), direction, 0D, directionLength);
					while (iterator.hasNext()) {
						Block passedBlock = iterator.next();
						
						if (isInsideDeathzone(passedBlock.getLocation(), game, isLiquidDeathzone)) {
							isDeathCandidate = true;
							break;
						}
					}
				}
			}
			
			if (isDeathCandidate) {
				//Lazy initialization for performance optimization
				if (deathCandidates == null) {
					deathCandidates = Sets.newHashSet();
				}
				
				deathCandidates.add(player);
			}
			
			recentLocations.put(player, playerLoc);
		}
		
		if (deathCandidates != null) {
			for (SpleefPlayer deathCandidate : deathCandidates) {
				game.requestLose(deathCandidate, QuitCause.LOSE);
			}
		}
	}
}
 
Example 18
Source File: SubCommand_SetOwner.java    From QuickShop-Reremake with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCommand(
        @NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] cmdArg) {
    if (!(sender instanceof Player)) {
        MsgUtil.sendMessage(sender, "Only player can run this command");
        return;
    }

    if (cmdArg.length < 1) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("command.no-owner-given", sender));
        return;
    }

    final BlockIterator bIt = new BlockIterator((Player) sender, 10);

    if (!bIt.hasNext()) {
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
        return;
    }

    while (bIt.hasNext()) {
        final Block b = bIt.next();
        final Shop shop = plugin.getShopManager().getShop(b.getLocation());

        if (shop == null) {
            continue;
        }

        @SuppressWarnings("deprecation") final OfflinePlayer newShopOwner = plugin.getServer().getOfflinePlayer(cmdArg[0]);
        if (newShopOwner.getName() == null) {
            MsgUtil.sendMessage(sender, MsgUtil.getMessage("unknown-player", null));
            return;
        }
        shop.setOwner(newShopOwner.getUniqueId());
        //shop.setSignText();
        //shop.update();
        MsgUtil.sendMessage(sender, MsgUtil.getMessage("command.new-owner", sender, newShopOwner.getName()));
        return;
    }

    MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
}
 
Example 19
Source File: AddsignCommand.java    From AreaShop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void execute(CommandSender sender, String[] args) {
	if(!sender.hasPermission("areashop.addsign")) {
		plugin.message(sender, "addsign-noPermission");
		return;
	}
	if(!(sender instanceof Player)) {
		plugin.message(sender, "cmd-onlyByPlayer");
		return;
	}
	Player player = (Player)sender;

	// Get the sign
	Block block = null;
	BlockIterator blockIterator = new BlockIterator(player, 100);
	while(blockIterator.hasNext() && block == null) {
		Block next = blockIterator.next();
		if(next.getType() != Material.AIR) {
			block = next;
		}
	}
	if(block == null || !Materials.isSign(block.getType())) {
		plugin.message(sender, "addsign-noSign");
		return;
	}

	GeneralRegion region;
	if(args.length > 1) {
		// Get region by argument
		region = plugin.getFileManager().getRegion(args[1]);
		if(region == null) {
			plugin.message(sender, "cmd-notRegistered", args[1]);
			return;
		}
	} else {
		// Get region by sign position
		List<GeneralRegion> regions = Utils.getImportantRegions(block.getLocation());
		if(regions.isEmpty()) {
			plugin.message(sender, "addsign-noRegions");
			return;
		} else if(regions.size() > 1) {
			plugin.message(sender, "addsign-couldNotDetect", regions.get(0).getName(), regions.get(1).getName());
			return;
		}
		region = regions.get(0);
	}
	String profile = null;
	if(args.length > 2) {
		profile = args[2];
		Set<String> profiles = plugin.getConfig().getConfigurationSection("signProfiles").getKeys(false);
		if(!profiles.contains(profile)) {
			plugin.message(sender, "addsign-wrongProfile", Utils.createCommaSeparatedList(profiles), region);
			return;
		}
	}
	RegionSign regionSign = SignsFeature.getSignByLocation(block.getLocation());
	if(regionSign != null) {
		plugin.message(sender, "addsign-alreadyRegistered", regionSign.getRegion());
		return;
	}

	region.getSignsFeature().addSign(block.getLocation(), block.getType(), plugin.getBukkitHandler().getSignFacing(block), profile);
	if(profile == null) {
		plugin.message(sender, "addsign-success", region);
	} else {
		plugin.message(sender, "addsign-successProfile", profile, region);
	}
	region.update();
}
 
Example 20
Source File: ProjectileMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onProjectileHitEvent(ProjectileHitEvent event) {
  Projectile projectile = event.getEntity();
  ProjectileDefinition projectileDefinition = getProjectileDefinition(projectile);
  if (projectileDefinition == null) return;
  Filter filter = projectileDefinition.destroyFilter;
  if (filter == null) return;

  BlockIterator it =
      new BlockIterator(
          projectile.getWorld(),
          projectile.getLocation().toVector(),
          projectile.getVelocity().normalize(),
          0d,
          2);

  Block hitBlock = null;
  while (it.hasNext()) {
    hitBlock = it.next();

    if (hitBlock.getType() != Material.AIR) {
      break;
    }
  }

  if (hitBlock != null) {
    MatchPlayer player =
        projectile.getShooter() instanceof Player
            ? match.getPlayer((Player) projectile.getShooter())
            : null;
    Query query =
        player != null
            ? new PlayerBlockQuery(event, player, hitBlock.getState())
            : new BlockQuery(event, hitBlock);

    if (filter.query(query).isAllowed()) {
      BlockTransformEvent bte = new BlockTransformEvent(event, hitBlock, Material.AIR);
      match.callEvent(bte);
      if (!bte.isCancelled()) {
        hitBlock.setType(Material.AIR);
        projectile.remove();
      }
    }
  }
}