use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.
the class WorldGuardPlayerListener method onPlayerGameModeChange.
@EventHandler
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
Player player = event.getPlayer();
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
WorldConfiguration wcfg = getWorldConfig(player.getWorld());
Session session = WorldGuard.getInstance().getPlatform().getSessionManager().getIfPresent(localPlayer);
if (session != null) {
GameModeFlag handler = session.getHandler(GameModeFlag.class);
if (handler != null && wcfg.useRegions && !WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
GameMode expected = handler.getSetGameMode();
if (handler.getOriginalGameMode() != null && expected != null && expected != BukkitAdapter.adapt(event.getNewGameMode())) {
log.info("Game mode change on " + player.getName() + " has been blocked due to the region GAMEMODE flag");
event.setCancelled(true);
}
}
}
}
use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.
the class WorldGuardPlayerListener method onPlayerCommandPreprocess.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
ConfigurationManager cfg = getConfig();
WorldConfiguration wcfg = getWorldConfig(player.getWorld());
if (wcfg.useRegions && !WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(localPlayer.getLocation());
Set<String> allowedCommands = set.queryValue(localPlayer, Flags.ALLOWED_CMDS);
Set<String> blockedCommands = set.queryValue(localPlayer, Flags.BLOCKED_CMDS);
CommandFilter test = new CommandFilter(allowedCommands, blockedCommands);
if (!test.apply(event.getMessage())) {
String message = set.queryValue(localPlayer, Flags.DENY_MESSAGE);
RegionProtectionListener.formatAndSendDenyMessage("use " + event.getMessage(), localPlayer, message);
event.setCancelled(true);
return;
}
}
if (cfg.blockInGameOp) {
if (opPattern.matcher(event.getMessage()).matches()) {
player.sendMessage(ChatColor.RED + "/op and /deop can only be used in console (as set by a WG setting).");
event.setCancelled(true);
return;
}
}
}
use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.
the class WorldGuardPlayerListener method handleBlockRightClick.
/**
* Called when a player right clicks a block.
*
* @param event Thrown event
*/
private void handleBlockRightClick(PlayerInteractEvent event) {
if (event.useItemInHand() == Event.Result.DENY) {
return;
}
Block block = event.getClickedBlock();
World world = block.getWorld();
Material type = block.getType();
Player player = event.getPlayer();
@Nullable ItemStack item = event.getItem();
WorldConfiguration wcfg = getWorldConfig(world);
// Infinite stack removal
if (Materials.isInventoryBlock(type) && wcfg.removeInfiniteStacks && !getPlugin().hasPermission(player, "worldguard.override.infinite-stack")) {
for (int slot = 0; slot < 40; slot++) {
ItemStack heldItem = player.getInventory().getItem(slot);
if (heldItem != null && heldItem.getAmount() < 0) {
player.getInventory().setItem(slot, null);
player.sendMessage(ChatColor.RED + "Infinite stack in slot #" + slot + " removed.");
}
}
}
if (wcfg.useRegions) {
// Block placedIn = block.getRelative(event.getBlockFace());
ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation()));
// ApplicableRegionSet placedInSet = plugin.getRegionContainer().createQuery().getApplicableRegions(placedIn.getLocation());
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
if (item != null && item.getType().getKey().toString().equals(wcfg.regionWand) && getPlugin().hasPermission(player, "worldguard.region.wand")) {
if (set.size() > 0) {
player.sendMessage(ChatColor.YELLOW + "Can you build? " + (set.testState(localPlayer, Flags.BUILD) ? "Yes" : "No"));
StringBuilder str = new StringBuilder();
for (Iterator<ProtectedRegion> it = set.iterator(); it.hasNext(); ) {
str.append(it.next().getId());
if (it.hasNext()) {
str.append(", ");
}
}
localPlayer.print("Applicable regions: " + str);
} else {
localPlayer.print("WorldGuard: No defined regions here!");
}
event.setUseItemInHand(Event.Result.DENY);
}
}
}
use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.
the class WorldGuardPlayerListener method onPlayerChat.
@EventHandler(ignoreCancelled = true)
public void onPlayerChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer();
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
WorldConfiguration wcfg = getWorldConfig(player.getWorld());
if (wcfg.useRegions) {
RegionQuery query = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery();
ApplicableRegionSet chatFrom = query.getApplicableRegions(localPlayer.getLocation());
if (!chatFrom.testState(localPlayer, Flags.SEND_CHAT)) {
String message = chatFrom.queryValue(localPlayer, Flags.DENY_MESSAGE);
RegionProtectionListener.formatAndSendDenyMessage("chat", localPlayer, message);
event.setCancelled(true);
return;
}
boolean anyRemoved = false;
for (Iterator<Player> i = event.getRecipients().iterator(); i.hasNext(); ) {
Player rPlayer = i.next();
LocalPlayer rLocal = getPlugin().wrapPlayer(rPlayer);
if (!query.testState(rLocal.getLocation(), rLocal, Flags.RECEIVE_CHAT)) {
i.remove();
anyRemoved = true;
}
}
if (anyRemoved && event.getRecipients().isEmpty() && wcfg.regionCancelEmptyChatEvents) {
event.setCancelled(true);
}
}
}
use of com.sk89q.worldguard.config.WorldConfiguration in project WorldGuard by EngineHub.
the class WorldGuardWeatherListener method onLightningStrike.
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onLightningStrike(LightningStrikeEvent event) {
WorldConfiguration wcfg = getWorldConfig(event.getWorld());
if (!wcfg.disallowedLightningBlocks.isEmpty()) {
final Block target = event.getLightning().getLocation().getBlock();
Material targetId = target.getType();
if (targetId == Material.AIR) {
targetId = target.getRelative(BlockFace.DOWN).getType();
}
if (wcfg.disallowedLightningBlocks.contains(BukkitAdapter.asBlockType(targetId).getId())) {
event.setCancelled(true);
}
}
Location loc = event.getLightning().getLocation();
if (wcfg.useRegions) {
if (!StateFlag.test(WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(loc), (RegionAssociable) null, Flags.LIGHTNING))) {
event.setCancelled(true);
}
}
}
Aggregations