use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.
the class WorldGuardEntityListener method checkItemFrameProtection.
/**
* Checks regions and config settings to protect items from being knocked
* out of item frames.
* @param attacker attacking entity
* @param defender item frame being damaged
* @return true if the event should be cancelled
*/
private boolean checkItemFrameProtection(Entity attacker, ItemFrame defender) {
World world = defender.getWorld();
WorldConfiguration wcfg = getWorldConfig(world);
if (wcfg.useRegions) {
// bukkit throws this event when a player attempts to remove an item from a frame
if (!(attacker instanceof Player)) {
if (!StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(defender.getLocation()), (RegionAssociable) null, Flags.ENTITY_ITEM_FRAME_DESTROY))) {
return true;
}
}
}
if (wcfg.blockEntityItemFrameDestroy && !(attacker instanceof Player)) {
return true;
}
return false;
}
use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.
the class WorldGuardPlayerListener method onPlayerInteract.
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
handleBlockRightClick(event);
} else if (event.getAction() == Action.PHYSICAL) {
handlePhysicalInteract(event);
}
ConfigurationManager cfg = getConfig();
WorldConfiguration wcfg = getWorldConfig(world);
if (wcfg.removeInfiniteStacks && !getPlugin().hasPermission(player, "worldguard.override.infinite-stack")) {
int slot = player.getInventory().getHeldItemSlot();
ItemStack heldItem = player.getInventory().getItem(slot);
if (heldItem != null && heldItem.getAmount() < 0) {
player.getInventory().setItem(slot, null);
player.sendMessage(ChatColor.RED + "Infinite stack removed.");
}
}
}
use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.
the class WorldGuardPlayerListener method onPlayerJoin.
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
ConfigurationManager cfg = getConfig();
WorldConfiguration wcfg = getWorldConfig(world);
if (cfg.activityHaltToggle) {
player.sendMessage(ChatColor.YELLOW + "Intensive server activity has been HALTED.");
int removed = 0;
for (Entity entity : world.getEntities()) {
if (Entities.isIntensiveEntity(BukkitAdapter.adapt(entity))) {
entity.remove();
removed++;
}
}
if (removed > 10) {
log.info("Halt-Act: " + removed + " entities (>10) auto-removed from " + player.getWorld());
}
}
if (wcfg.fireSpreadDisableToggle) {
player.sendMessage(ChatColor.YELLOW + "Fire spread is currently globally disabled for this world.");
}
Events.fire(new ProcessPlayerEvent(player));
WorldGuard.getInstance().getExecutorService().submit(() -> WorldGuard.getInstance().getProfileCache().put(new Profile(player.getUniqueId(), player.getName())));
}
use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.
the class WorldGuardPlayerListener method onItemHeldChange.
@EventHandler(priority = EventPriority.HIGH)
public void onItemHeldChange(PlayerItemHeldEvent event) {
Player player = event.getPlayer();
WorldConfiguration wcfg = getWorldConfig(player.getWorld());
if (wcfg.removeInfiniteStacks && !getPlugin().hasPermission(player, "worldguard.override.infinite-stack")) {
int newSlot = event.getNewSlot();
ItemStack heldItem = player.getInventory().getItem(newSlot);
if (heldItem != null && heldItem.getAmount() < 0) {
player.getInventory().setItem(newSlot, null);
player.sendMessage(ChatColor.RED + "Infinite stack removed.");
}
}
}
use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.
the class ToggleCommands method stopFire.
@Command(aliases = { "stopfire" }, usage = "[<world>]", desc = "Disables all fire spread temporarily", max = 1)
@CommandPermissions({ "worldguard.fire-toggle.stop" })
public void stopFire(CommandContext args, Actor sender) throws CommandException {
World world;
if (args.argsLength() == 0) {
world = worldGuard.checkPlayer(sender).getWorld();
} else {
world = worldGuard.getPlatform().getMatcher().matchWorld(sender, args.getString(0));
}
WorldConfiguration wcfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world);
if (!wcfg.fireSpreadDisableToggle) {
worldGuard.getPlatform().broadcastNotification(LabelFormat.wrap("Fire spread has been globally disabled for '" + world.getName() + "' by " + sender.getDisplayName() + "."));
} else {
sender.print("Fire spread was already globally disabled.");
}
wcfg.fireSpreadDisableToggle = true;
}
Aggregations