2014-08-12 02:51:00 +02:00
|
|
|
/*
|
|
|
|
* WorldGuard, a suite of tools for Minecraft
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldGuard team and contributors
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldguard.bukkit.listener;
|
|
|
|
|
2018-07-21 18:03:32 +02:00
|
|
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
2018-07-22 05:06:01 +02:00
|
|
|
import com.sk89q.worldedit.world.gamemode.GameMode;
|
2014-08-12 02:51:00 +02:00
|
|
|
import com.sk89q.worldguard.LocalPlayer;
|
2018-07-21 18:03:32 +02:00
|
|
|
import com.sk89q.worldguard.WorldGuard;
|
2014-08-12 02:51:00 +02:00
|
|
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
2014-08-24 10:09:39 +02:00
|
|
|
import com.sk89q.worldguard.bukkit.event.player.ProcessPlayerEvent;
|
|
|
|
import com.sk89q.worldguard.bukkit.util.Events;
|
2018-07-22 05:06:01 +02:00
|
|
|
import com.sk89q.worldguard.config.ConfigurationManager;
|
2018-12-26 06:19:23 +01:00
|
|
|
import com.sk89q.worldguard.config.WorldConfiguration;
|
2014-08-12 02:51:00 +02:00
|
|
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
2018-07-19 16:06:02 +02:00
|
|
|
import com.sk89q.worldguard.protection.flags.Flags;
|
2016-05-22 01:23:35 +02:00
|
|
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
2015-06-04 09:36:33 +02:00
|
|
|
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
2014-08-12 02:51:00 +02:00
|
|
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
2019-03-04 23:44:54 +01:00
|
|
|
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
2015-01-18 03:54:10 +01:00
|
|
|
import com.sk89q.worldguard.session.MoveType;
|
2015-05-28 20:28:02 +02:00
|
|
|
import com.sk89q.worldguard.session.Session;
|
2015-01-18 03:54:10 +01:00
|
|
|
import com.sk89q.worldguard.session.handler.GameModeFlag;
|
2018-12-26 05:32:35 +01:00
|
|
|
import com.sk89q.worldguard.util.Entities;
|
2014-08-12 02:51:00 +02:00
|
|
|
import com.sk89q.worldguard.util.command.CommandFilter;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Location;
|
2018-07-22 05:06:01 +02:00
|
|
|
import org.bukkit.Material;
|
2015-06-06 04:08:07 +02:00
|
|
|
import org.bukkit.TravelAgent;
|
2014-08-12 02:51:00 +02:00
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.event.block.Action;
|
2016-05-22 01:23:35 +02:00
|
|
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
|
|
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
|
|
|
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
|
|
import org.bukkit.event.player.PlayerItemHeldEvent;
|
|
|
|
import org.bukkit.event.player.PlayerJoinEvent;
|
|
|
|
import org.bukkit.event.player.PlayerLoginEvent;
|
|
|
|
import org.bukkit.event.player.PlayerPortalEvent;
|
|
|
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
|
|
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
2014-08-12 02:51:00 +02:00
|
|
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.plugin.PluginManager;
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Set;
|
2014-08-22 07:22:28 +02:00
|
|
|
import java.util.logging.Logger;
|
2014-08-12 02:51:00 +02:00
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
2018-07-22 05:06:01 +02:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2014-08-12 02:51:00 +02:00
|
|
|
/**
|
|
|
|
* Handles all events thrown in relation to a player.
|
|
|
|
*/
|
|
|
|
public class WorldGuardPlayerListener implements Listener {
|
|
|
|
|
2014-08-22 07:22:28 +02:00
|
|
|
private static final Logger log = Logger.getLogger(WorldGuardPlayerListener.class.getCanonicalName());
|
2018-12-02 06:47:45 +01:00
|
|
|
private static final Pattern opPattern = Pattern.compile("^/(?:minecraft:)?(?:bukkit:)?(?:de)?op(?:\\s.*)?$", Pattern.CASE_INSENSITIVE);
|
2014-08-12 02:51:00 +02:00
|
|
|
private WorldGuardPlugin plugin;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the object;
|
|
|
|
*
|
|
|
|
* @param plugin
|
|
|
|
*/
|
|
|
|
public WorldGuardPlayerListener(WorldGuardPlugin plugin) {
|
|
|
|
this.plugin = plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register events.
|
|
|
|
*/
|
|
|
|
public void registerEvents() {
|
2014-12-31 10:31:30 +01:00
|
|
|
PluginManager pm = plugin.getServer().getPluginManager();
|
2014-08-12 02:51:00 +02:00
|
|
|
pm.registerEvents(this, plugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
|
|
|
Player player = event.getPlayer();
|
2018-07-22 05:06:01 +02:00
|
|
|
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
2018-12-26 06:19:23 +01:00
|
|
|
WorldConfiguration wcfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(localPlayer.getWorld());
|
2018-07-22 05:06:01 +02:00
|
|
|
Session session = WorldGuard.getInstance().getPlatform().getSessionManager().getIfPresent(localPlayer);
|
2015-05-28 20:28:02 +02:00
|
|
|
if (session != null) {
|
|
|
|
GameModeFlag handler = session.getHandler(GameModeFlag.class);
|
2018-07-22 05:06:01 +02:00
|
|
|
if (handler != null && wcfg.useRegions && !WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer,
|
|
|
|
localPlayer.getWorld())) {
|
2015-05-28 20:28:02 +02:00
|
|
|
GameMode expected = handler.getSetGameMode();
|
2018-07-22 05:06:01 +02:00
|
|
|
if (handler.getOriginalGameMode() != null && expected != null && expected != BukkitAdapter.adapt(event.getNewGameMode())) {
|
2015-05-28 20:28:02 +02:00
|
|
|
log.info("Game mode change on " + player.getName() + " has been blocked due to the region GAMEMODE flag");
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
2014-08-12 02:51:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
|
|
|
Player player = event.getPlayer();
|
2018-07-22 05:06:01 +02:00
|
|
|
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
2014-08-12 02:51:00 +02:00
|
|
|
World world = player.getWorld();
|
|
|
|
|
2018-07-21 18:03:32 +02:00
|
|
|
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
|
2018-12-26 06:19:23 +01:00
|
|
|
WorldConfiguration wcfg = cfg.get(localPlayer.getWorld());
|
2014-08-12 02:51:00 +02:00
|
|
|
|
|
|
|
if (cfg.activityHaltToggle) {
|
|
|
|
player.sendMessage(ChatColor.YELLOW
|
|
|
|
+ "Intensive server activity has been HALTED.");
|
|
|
|
|
|
|
|
int removed = 0;
|
|
|
|
|
|
|
|
for (Entity entity : world.getEntities()) {
|
2018-12-26 05:32:35 +01:00
|
|
|
if (Entities.isIntensiveEntity(BukkitAdapter.adapt(entity))) {
|
2014-08-12 02:51:00 +02:00
|
|
|
entity.remove();
|
|
|
|
removed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (removed > 10) {
|
2014-08-22 07:22:28 +02:00
|
|
|
log.info("Halt-Act: " + removed + " entities (>10) auto-removed from "
|
2014-08-12 02:51:00 +02:00
|
|
|
+ player.getWorld().toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wcfg.fireSpreadDisableToggle) {
|
|
|
|
player.sendMessage(ChatColor.YELLOW
|
|
|
|
+ "Fire spread is currently globally disabled for this world.");
|
|
|
|
}
|
|
|
|
|
2014-08-24 10:09:39 +02:00
|
|
|
Events.fire(new ProcessPlayerEvent(player));
|
2014-08-12 02:51:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(ignoreCancelled = true)
|
|
|
|
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
|
|
|
Player player = event.getPlayer();
|
2018-07-21 18:03:32 +02:00
|
|
|
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
2018-12-26 06:19:23 +01:00
|
|
|
WorldConfiguration wcfg =
|
|
|
|
WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(localPlayer.getWorld());
|
2014-08-12 02:51:00 +02:00
|
|
|
if (wcfg.useRegions) {
|
2019-03-04 23:44:54 +01:00
|
|
|
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);
|
2014-08-12 02:51:00 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-04 23:44:54 +01:00
|
|
|
boolean anyRemoved = false;
|
2014-08-12 02:51:00 +02:00
|
|
|
for (Iterator<Player> i = event.getRecipients().iterator(); i.hasNext();) {
|
2018-02-24 15:39:16 +01:00
|
|
|
Player rPlayer = i.next();
|
2018-07-21 18:03:32 +02:00
|
|
|
LocalPlayer rLocal = plugin.wrapPlayer(rPlayer);
|
2019-03-04 23:44:54 +01:00
|
|
|
if (!query.testState(rLocal.getLocation(), rLocal, Flags.RECEIVE_CHAT)) {
|
2014-08-12 02:51:00 +02:00
|
|
|
i.remove();
|
2019-03-04 23:44:54 +01:00
|
|
|
anyRemoved = true;
|
2014-08-12 02:51:00 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-04 23:44:54 +01:00
|
|
|
if (anyRemoved && event.getRecipients().size() == 0 && wcfg.regionCancelEmptyChatEvents) {
|
2014-08-12 02:51:00 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(ignoreCancelled = true)
|
|
|
|
public void onPlayerLogin(PlayerLoginEvent event) {
|
|
|
|
Player player = event.getPlayer();
|
2018-07-21 18:03:32 +02:00
|
|
|
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
|
2014-08-12 02:51:00 +02:00
|
|
|
|
2018-01-21 06:29:16 +01:00
|
|
|
String hostKey = cfg.hostKeys.get(player.getUniqueId().toString());
|
|
|
|
if (hostKey == null) {
|
|
|
|
hostKey = cfg.hostKeys.get(player.getName().toLowerCase());
|
|
|
|
}
|
|
|
|
|
2014-08-12 02:51:00 +02:00
|
|
|
if (hostKey != null) {
|
|
|
|
String hostname = event.getHostname();
|
|
|
|
int colonIndex = hostname.indexOf(':');
|
|
|
|
if (colonIndex != -1) {
|
|
|
|
hostname = hostname.substring(0, colonIndex);
|
|
|
|
}
|
|
|
|
|
2016-12-23 01:42:19 +01:00
|
|
|
if (!hostname.equals(hostKey)
|
|
|
|
&& !(cfg.hostKeysAllowFMLClients && hostname.equals(hostKey + "\u0000FML\u0000"))) {
|
2014-08-12 02:51:00 +02:00
|
|
|
event.disallow(PlayerLoginEvent.Result.KICK_OTHER,
|
|
|
|
"You did not join with the valid host key!");
|
2014-08-22 07:22:28 +02:00
|
|
|
log.warning("WorldGuard host key check: " +
|
2014-08-12 02:51:00 +02:00
|
|
|
player.getName() + " joined with '" + hostname +
|
|
|
|
"' but '" + hostKey + "' was expected. Kicked!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg.deopOnJoin) {
|
|
|
|
player.setOp(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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);
|
|
|
|
}
|
|
|
|
|
2018-07-21 18:03:32 +02:00
|
|
|
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
|
2018-12-26 06:19:23 +01:00
|
|
|
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(world));
|
2014-08-12 02:51:00 +02:00
|
|
|
|
|
|
|
if (wcfg.removeInfiniteStacks
|
|
|
|
&& !plugin.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.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when a player right clicks a block.
|
|
|
|
*
|
|
|
|
* @param event Thrown event
|
|
|
|
*/
|
|
|
|
private void handleBlockRightClick(PlayerInteractEvent event) {
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Block block = event.getClickedBlock();
|
|
|
|
World world = block.getWorld();
|
2018-07-22 05:06:01 +02:00
|
|
|
Material type = block.getType();
|
2014-08-12 02:51:00 +02:00
|
|
|
Player player = event.getPlayer();
|
2016-05-22 01:23:35 +02:00
|
|
|
@Nullable ItemStack item = event.getItem();
|
2014-08-12 02:51:00 +02:00
|
|
|
|
2018-07-22 05:06:01 +02:00
|
|
|
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
|
2018-12-26 06:19:23 +01:00
|
|
|
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(world));
|
2014-08-12 02:51:00 +02:00
|
|
|
|
|
|
|
// Infinite stack removal
|
2018-07-22 05:06:01 +02:00
|
|
|
if ((type == Material.CHEST
|
|
|
|
|| type == Material.JUKEBOX
|
|
|
|
|| type == Material.DISPENSER
|
|
|
|
|| type == Material.FURNACE
|
|
|
|
|| type == Material.DROPPER
|
|
|
|
|| type == Material.BREWING_STAND
|
|
|
|
|| type == Material.TRAPPED_CHEST
|
|
|
|
|| type == Material.ENCHANTING_TABLE)
|
2014-08-12 02:51:00 +02:00
|
|
|
&& wcfg.removeInfiniteStacks
|
|
|
|
&& !plugin.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) {
|
2016-05-22 01:23:35 +02:00
|
|
|
//Block placedIn = block.getRelative(event.getBlockFace());
|
2018-07-22 05:06:01 +02:00
|
|
|
ApplicableRegionSet set =
|
|
|
|
WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(block.getLocation()));
|
2016-05-22 01:23:35 +02:00
|
|
|
//ApplicableRegionSet placedInSet = plugin.getRegionContainer().createQuery().getApplicableRegions(placedIn.getLocation());
|
2014-08-12 02:51:00 +02:00
|
|
|
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
|
|
|
|
2018-07-22 05:06:01 +02:00
|
|
|
if (item != null && item.getType().getKey().toString().equals(wcfg.regionWand) && plugin.hasPermission(player, "worldguard.region.wand")) {
|
2014-08-12 02:51:00 +02:00
|
|
|
if (set.size() > 0) {
|
2018-08-13 14:46:36 +02:00
|
|
|
player.sendMessage(ChatColor.YELLOW + "Can you build? " + (set.testState(localPlayer, Flags.BUILD) ? "Yes" : "No"));
|
2014-08-12 02:51:00 +02:00
|
|
|
|
|
|
|
StringBuilder str = new StringBuilder();
|
|
|
|
for (Iterator<ProtectedRegion> it = set.iterator(); it.hasNext();) {
|
|
|
|
str.append(it.next().getId());
|
|
|
|
if (it.hasNext()) {
|
|
|
|
str.append(", ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-13 14:46:36 +02:00
|
|
|
localPlayer.print("Applicable regions: " + str.toString());
|
2014-08-12 02:51:00 +02:00
|
|
|
} else {
|
2018-08-13 14:46:36 +02:00
|
|
|
localPlayer.print("WorldGuard: No defined regions here!");
|
2014-08-12 02:51:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when a player steps on a pressure plate or tramples crops.
|
|
|
|
*
|
|
|
|
* @param event Thrown event
|
|
|
|
*/
|
|
|
|
private void handlePhysicalInteract(PlayerInteractEvent event) {
|
|
|
|
if (event.isCancelled()) return;
|
|
|
|
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
Block block = event.getClickedBlock(); //not actually clicked but whatever
|
2016-05-22 01:23:35 +02:00
|
|
|
//int type = block.getTypeId();
|
2014-08-12 02:51:00 +02:00
|
|
|
World world = player.getWorld();
|
|
|
|
|
2018-07-22 05:06:01 +02:00
|
|
|
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
|
2018-12-26 06:19:23 +01:00
|
|
|
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(world));
|
2014-08-12 02:51:00 +02:00
|
|
|
|
2018-07-22 05:06:01 +02:00
|
|
|
if (block.getType() == Material.FARMLAND && wcfg.disablePlayerCropTrampling) {
|
2014-08-12 02:51:00 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.HIGHEST)
|
|
|
|
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
|
|
|
Player player = event.getPlayer();
|
2018-08-13 14:46:36 +02:00
|
|
|
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
2014-08-12 02:51:00 +02:00
|
|
|
|
2018-07-22 05:06:01 +02:00
|
|
|
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
|
2018-12-26 06:19:23 +01:00
|
|
|
WorldConfiguration wcfg = cfg.get(localPlayer.getWorld());
|
2014-08-12 02:51:00 +02:00
|
|
|
|
|
|
|
if (wcfg.useRegions) {
|
2018-07-22 05:06:01 +02:00
|
|
|
ApplicableRegionSet set =
|
2018-08-13 14:46:36 +02:00
|
|
|
WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(localPlayer.getLocation());
|
2014-08-12 02:51:00 +02:00
|
|
|
|
2018-08-13 14:46:36 +02:00
|
|
|
com.sk89q.worldedit.util.Location spawn = set.queryValue(localPlayer, Flags.SPAWN_LOC);
|
2014-08-12 02:51:00 +02:00
|
|
|
|
|
|
|
if (spawn != null) {
|
2018-07-22 05:06:01 +02:00
|
|
|
event.setRespawnLocation(BukkitAdapter.adapt(spawn));
|
2014-08-12 02:51:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler(priority = EventPriority.HIGH)
|
|
|
|
public void onItemHeldChange(PlayerItemHeldEvent event) {
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
2018-07-22 05:06:01 +02:00
|
|
|
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
|
2018-12-26 06:19:23 +01:00
|
|
|
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(player.getWorld()));
|
2014-08-12 02:51:00 +02:00
|
|
|
|
|
|
|
if (wcfg.removeInfiniteStacks
|
|
|
|
&& !plugin.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.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-18 03:54:10 +01:00
|
|
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
2014-08-12 02:51:00 +02:00
|
|
|
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
|
|
|
World world = event.getFrom().getWorld();
|
2015-01-18 03:54:10 +01:00
|
|
|
Player player = event.getPlayer();
|
2018-07-22 05:06:01 +02:00
|
|
|
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
|
|
|
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
|
2018-12-26 06:19:23 +01:00
|
|
|
WorldConfiguration wcfg = cfg.get(localPlayer.getWorld());
|
2014-08-12 02:51:00 +02:00
|
|
|
|
|
|
|
if (wcfg.useRegions) {
|
2018-07-22 05:06:01 +02:00
|
|
|
ApplicableRegionSet set =
|
|
|
|
WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(event.getTo()));
|
|
|
|
ApplicableRegionSet setFrom =
|
|
|
|
WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(BukkitAdapter.adapt(event.getFrom()));
|
2014-08-12 02:51:00 +02:00
|
|
|
|
|
|
|
if (cfg.usePlayerTeleports) {
|
2018-07-22 05:06:01 +02:00
|
|
|
if (null != WorldGuard.getInstance().getPlatform().getSessionManager().get(localPlayer).testMoveTo(localPlayer,
|
|
|
|
BukkitAdapter.adapt(event.getTo()),
|
|
|
|
MoveType.TELEPORT)) {
|
2014-08-12 02:51:00 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.getCause() == TeleportCause.ENDER_PEARL) {
|
2019-03-14 23:07:41 +01:00
|
|
|
if (!WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
|
|
|
|
boolean cancel = false;
|
|
|
|
String message = null;
|
|
|
|
if (!setFrom.testState(localPlayer, Flags.ENDERPEARL)) {
|
|
|
|
cancel = true;
|
|
|
|
message = set.queryValue(localPlayer, Flags.EXIT_DENY_MESSAGE);
|
|
|
|
} else if (!set.testState(localPlayer, Flags.ENDERPEARL)) {
|
|
|
|
cancel = true;
|
|
|
|
message = set.queryValue(localPlayer, Flags.ENTRY_DENY_MESSAGE);
|
|
|
|
}
|
|
|
|
if (cancel) {
|
|
|
|
player.sendMessage(message);
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
2014-08-12 02:51:00 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-04 23:44:54 +01:00
|
|
|
if (event.getCause() == TeleportCause.CHORUS_FRUIT) {
|
|
|
|
if (!WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
|
2019-03-14 23:07:41 +01:00
|
|
|
boolean cancel = false;
|
|
|
|
String message = null;
|
|
|
|
if (!setFrom.testState(localPlayer, Flags.CHORUS_TELEPORT)) {
|
|
|
|
cancel = true;
|
|
|
|
message = set.queryValue(localPlayer, Flags.EXIT_DENY_MESSAGE);
|
|
|
|
} else if (!set.testState(localPlayer, Flags.CHORUS_TELEPORT)) {
|
|
|
|
cancel = true;
|
|
|
|
message = set.queryValue(localPlayer, Flags.ENTRY_DENY_MESSAGE);
|
|
|
|
}
|
|
|
|
if (cancel) {
|
|
|
|
player.sendMessage(message);
|
2019-03-04 23:44:54 +01:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
2016-05-20 21:03:45 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-04 23:44:54 +01:00
|
|
|
}
|
2014-08-12 02:51:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-04 09:36:33 +02:00
|
|
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
|
|
|
|
public void onPlayerPortal(PlayerPortalEvent event) {
|
2015-06-27 06:42:08 +02:00
|
|
|
if (event.getTo() == null) { // apparently this counts as a cancelled event, implementation specific though
|
|
|
|
return;
|
|
|
|
}
|
2018-07-22 05:06:01 +02:00
|
|
|
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
|
|
|
|
LocalPlayer localPlayer = plugin.wrapPlayer(event.getPlayer());
|
2018-12-26 06:19:23 +01:00
|
|
|
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(event.getTo().getWorld()));
|
2015-06-19 23:01:30 +02:00
|
|
|
if (!wcfg.regionNetherPortalProtection) return;
|
2015-06-06 04:08:07 +02:00
|
|
|
if (event.getCause() != TeleportCause.NETHER_PORTAL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!event.useTravelAgent()) { // either end travel (even though we checked cause) or another plugin is fucking with us, shouldn't create a portal though
|
|
|
|
return;
|
2015-06-04 09:36:33 +02:00
|
|
|
}
|
2015-06-06 04:08:07 +02:00
|
|
|
TravelAgent pta = event.getPortalTravelAgent();
|
|
|
|
if (pta == null) { // possible, but shouldn't create a portal
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pta.findPortal(event.getTo()) != null) {
|
|
|
|
return; // portal exists...it shouldn't make a new one
|
|
|
|
}
|
|
|
|
// HOPEFULLY covered everything the server can throw at us...proceed protection checking
|
|
|
|
// a lot of that is implementation specific though
|
|
|
|
|
|
|
|
// hackily estimate the area that could be effected by this event, since the server refuses to tell us
|
|
|
|
int radius = pta.getCreationRadius();
|
2015-06-04 09:36:33 +02:00
|
|
|
Location min = event.getTo().clone().subtract(radius, radius, radius);
|
|
|
|
Location max = event.getTo().clone().add(radius, radius, radius);
|
2018-07-22 05:06:01 +02:00
|
|
|
com.sk89q.worldedit.world.World world = BukkitAdapter.adapt(event.getTo().getWorld());
|
2015-06-04 09:36:33 +02:00
|
|
|
|
2018-11-04 07:57:45 +01:00
|
|
|
ProtectedRegion check = new ProtectedCuboidRegion("__portalcheck__", BukkitAdapter.adapt(min.getBlock().getLocation()).toVector().toBlockPoint(),
|
|
|
|
BukkitAdapter.adapt(max.getBlock().getLocation()).toVector().toBlockPoint());
|
2015-06-04 09:36:33 +02:00
|
|
|
|
2018-07-22 05:06:01 +02:00
|
|
|
if (wcfg.useRegions && !WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, world)) {
|
|
|
|
RegionManager mgr = WorldGuard.getInstance().getPlatform().getRegionContainer().get(world);
|
2016-05-22 01:23:35 +02:00
|
|
|
if (mgr == null) return;
|
|
|
|
ApplicableRegionSet set = mgr.getApplicableRegions(check);
|
2018-07-19 16:06:02 +02:00
|
|
|
if (!set.testState(plugin.wrapPlayer(event.getPlayer()), Flags.BUILD)) {
|
2015-06-04 09:36:33 +02:00
|
|
|
event.getPlayer().sendMessage(ChatColor.RED + "Destination is in a protected area.");
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-12 02:51:00 +02:00
|
|
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
|
|
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
LocalPlayer localPlayer = plugin.wrapPlayer(player);
|
2018-07-22 05:06:01 +02:00
|
|
|
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
|
2018-12-26 06:19:23 +01:00
|
|
|
WorldConfiguration wcfg = cfg.get(localPlayer.getWorld());
|
2014-08-12 02:51:00 +02:00
|
|
|
|
2018-07-22 05:06:01 +02:00
|
|
|
if (wcfg.useRegions && !WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld())) {
|
|
|
|
ApplicableRegionSet set =
|
|
|
|
WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().getApplicableRegions(localPlayer.getLocation());
|
2014-08-12 02:51:00 +02:00
|
|
|
|
2018-07-19 16:06:02 +02:00
|
|
|
Set<String> allowedCommands = set.queryValue(localPlayer, Flags.ALLOWED_CMDS);
|
|
|
|
Set<String> blockedCommands = set.queryValue(localPlayer, Flags.BLOCKED_CMDS);
|
2014-08-12 02:51:00 +02:00
|
|
|
CommandFilter test = new CommandFilter(allowedCommands, blockedCommands);
|
|
|
|
|
|
|
|
if (!test.apply(event.getMessage())) {
|
2019-03-04 23:44:54 +01:00
|
|
|
String message = set.queryValue(localPlayer, Flags.DENY_MESSAGE);
|
|
|
|
RegionProtectionListener.formatAndSendDenyMessage("use " + event.getMessage(), localPlayer, message);
|
2014-08-12 02:51:00 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg.blockInGameOp) {
|
|
|
|
if (opPattern.matcher(event.getMessage()).matches()) {
|
2018-12-02 06:47:45 +01:00
|
|
|
player.sendMessage(ChatColor.RED + "/op and /deop can only be used in console (as set by a WG setting).");
|
2014-08-12 02:51:00 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|