mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-01-05 16:07:56 +01:00
Merge branch 'version/7.0.x'
# Conflicts: # gradle.properties
This commit is contained in:
commit
129ae6c971
14
CHANGELOG.md
14
CHANGELOG.md
@ -1,9 +1,19 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## 7.0.8 (beta)
|
## 7.0.8
|
||||||
* Add support for MC 1.19
|
* Add support for MC 1.19
|
||||||
* Add skulk-growth flag and config option
|
* Add skulk-growth flag and config option
|
||||||
* Fix possible error when using Paper's entity origin API.
|
* Add copper-fade flag
|
||||||
|
* Add data packs to report output
|
||||||
|
* Add protection for allay inventory slot
|
||||||
|
* Categorize allay item pickups under item-pickup flag
|
||||||
|
* Categorize dragon egg interaction (teleporting) as building
|
||||||
|
* Ignore most NPC-based actions for Player events
|
||||||
|
* Optimize handling of tamed animals where the owner was offline (Paper only)
|
||||||
|
* Optimize additional InventoryHolder accesses (Paper only)
|
||||||
|
* Fix an exception that occurred when plugins created portals with non-player entities
|
||||||
|
* Fix possible error when using Paper's entity origin API
|
||||||
|
* Update bstats and squirrelid libs
|
||||||
|
|
||||||
## 7.0.7
|
## 7.0.7
|
||||||
* Add rock-growth flag for budding amethyst and pointed dripstone.
|
* Add rock-growth flag for budding amethyst and pointed dripstone.
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
<allow pkg="io.papermc.lib"/>
|
<allow pkg="io.papermc.lib"/>
|
||||||
<allow pkg="com.destroystokyo.paper"/>
|
<allow pkg="com.destroystokyo.paper"/>
|
||||||
<allow pkg="io.papermc.paper"/>
|
<allow pkg="io.papermc.paper"/>
|
||||||
<allow pkg="co.aikar.timings.lib" />
|
|
||||||
<allow pkg="org.spigotmc" />
|
<allow pkg="org.spigotmc" />
|
||||||
</subpackage>
|
</subpackage>
|
||||||
|
|
||||||
|
@ -12,10 +12,6 @@
|
|||||||
name = "paper"
|
name = "paper"
|
||||||
url = uri("https://repo.papermc.io/repository/maven-public/")
|
url = uri("https://repo.papermc.io/repository/maven-public/")
|
||||||
}
|
}
|
||||||
maven {
|
|
||||||
name = "aikar-timings"
|
|
||||||
url = uri("https://repo.aikar.co/nexus/content/groups/aikar/")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
@ -33,7 +29,6 @@
|
|||||||
"compileOnly"("com.sk89q:commandbook:2.3") { isTransitive = false }
|
"compileOnly"("com.sk89q:commandbook:2.3") { isTransitive = false }
|
||||||
"shadeOnly"("io.papermc:paperlib:1.0.8")
|
"shadeOnly"("io.papermc:paperlib:1.0.8")
|
||||||
"shadeOnly"("org.bstats:bstats-bukkit:3.0.1")
|
"shadeOnly"("org.bstats:bstats-bukkit:3.0.1")
|
||||||
"shadeOnly"("co.aikar:minecraft-timings:1.0.4")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named<Copy>("processResources") {
|
tasks.named<Copy>("processResources") {
|
||||||
|
@ -37,7 +37,6 @@ public class BukkitConfigurationManager extends YamlConfigurationManager {
|
|||||||
|
|
||||||
private boolean hasCommandBookGodMode;
|
private boolean hasCommandBookGodMode;
|
||||||
boolean extraStats;
|
boolean extraStats;
|
||||||
boolean timedSessionHandlers;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct the object.
|
* Construct the object.
|
||||||
@ -57,7 +56,6 @@ public Collection<BukkitWorldConfiguration> getWorldConfigs() {
|
|||||||
public void load() {
|
public void load() {
|
||||||
super.load();
|
super.load();
|
||||||
this.extraStats = getConfig().getBoolean("custom-metrics-charts", true);
|
this.extraStats = getConfig().getBoolean("custom-metrics-charts", true);
|
||||||
this.timedSessionHandlers = getConfig().getBoolean("extra-timings.session-handlers", true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -139,7 +139,6 @@ public void load() {
|
|||||||
sessionManager = new BukkitSessionManager();
|
sessionManager = new BukkitSessionManager();
|
||||||
configuration = new BukkitConfigurationManager(WorldGuardPlugin.inst());
|
configuration = new BukkitConfigurationManager(WorldGuardPlugin.inst());
|
||||||
configuration.load();
|
configuration.load();
|
||||||
sessionManager.setUsingTimings(configuration.timedSessionHandlers);
|
|
||||||
regionContainer = new BukkitRegionContainer(WorldGuardPlugin.inst());
|
regionContainer = new BukkitRegionContainer(WorldGuardPlugin.inst());
|
||||||
regionContainer.initialize();
|
regionContainer.initialize();
|
||||||
debugHandler = new BukkitDebugHandler(WorldGuardPlugin.inst());
|
debugHandler = new BukkitDebugHandler(WorldGuardPlugin.inst());
|
||||||
|
@ -27,7 +27,9 @@
|
|||||||
import com.sk89q.worldguard.bukkit.util.Entities;
|
import com.sk89q.worldguard.bukkit.util.Entities;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.AnimalTamer;
|
||||||
import org.bukkit.entity.AreaEffectCloud;
|
import org.bukkit.entity.AreaEffectCloud;
|
||||||
import org.bukkit.entity.Creature;
|
import org.bukkit.entity.Creature;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@ -107,6 +109,12 @@ public boolean isKnown() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (object instanceof Tameable tameable && tameable.isTamed()) {
|
||||||
|
// if they're tamed but also the root cause, the owner is offline
|
||||||
|
// otherwise the owner will be the root cause (and known)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (object instanceof TNTPrimed || object instanceof Vehicle) {
|
if (object instanceof TNTPrimed || object instanceof Vehicle) {
|
||||||
if (!PaperLib.isPaper()) {
|
if (!PaperLib.isPaper()) {
|
||||||
return false;
|
return false;
|
||||||
@ -300,9 +308,24 @@ private void addAll(@Nullable Object... element) {
|
|||||||
} else if (o instanceof AreaEffectCloud) {
|
} else if (o instanceof AreaEffectCloud) {
|
||||||
indirect = true;
|
indirect = true;
|
||||||
addAll(((AreaEffectCloud) o).getSource());
|
addAll(((AreaEffectCloud) o).getSource());
|
||||||
} else if (o instanceof Tameable) {
|
} else if (o instanceof Tameable tameable) {
|
||||||
indirect = true;
|
indirect = true;
|
||||||
addAll(((Tameable) o).getOwner());
|
if (PaperLib.isPaper()) {
|
||||||
|
UUID ownerId = tameable.getOwnerUniqueId();
|
||||||
|
if (ownerId != null) {
|
||||||
|
Player owner = Bukkit.getPlayer(ownerId);
|
||||||
|
if (owner != null) {
|
||||||
|
addAll(owner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// this will cause offline player loads if the player is offline
|
||||||
|
// too bad for spigot users
|
||||||
|
AnimalTamer owner = tameable.getOwner();
|
||||||
|
if (owner instanceof OfflinePlayer player) {
|
||||||
|
addAll(player.getPlayer()); // player object if online, else null
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (o instanceof Creature && ((Creature) o).getTarget() != null) {
|
} else if (o instanceof Creature && ((Creature) o).getTarget() != null) {
|
||||||
indirect = true;
|
indirect = true;
|
||||||
addAll(((Creature) o).getTarget());
|
addAll(((Creature) o).getTarget());
|
||||||
|
@ -113,6 +113,7 @@
|
|||||||
import org.bukkit.event.entity.EntityDeathEvent;
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.entity.EntityInteractEvent;
|
import org.bukkit.event.entity.EntityInteractEvent;
|
||||||
|
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||||
import org.bukkit.event.entity.EntityTameEvent;
|
import org.bukkit.event.entity.EntityTameEvent;
|
||||||
import org.bukkit.event.entity.EntityUnleashEvent;
|
import org.bukkit.event.entity.EntityUnleashEvent;
|
||||||
import org.bukkit.event.entity.ExpBottleEvent;
|
import org.bukkit.event.entity.ExpBottleEvent;
|
||||||
@ -919,6 +920,12 @@ public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
|||||||
pickupDebounce.debounce(event.getPlayer(), item, event, new DestroyEntityEvent(event, create(event.getPlayer()), event.getItem()));
|
pickupDebounce.debounce(event.getPlayer(), item, event, new DestroyEntityEvent(event, create(event.getPlayer()), event.getItem()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onEntityPickupItem(EntityPickupItemEvent event) {
|
||||||
|
Item item = event.getItem();
|
||||||
|
pickupDebounce.debounce(event.getEntity(), item, event, new DestroyEntityEvent(event, create(event.getEntity()), event.getItem()));
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||||
Events.fireToCancel(event, new SpawnEntityEvent(event, create(event.getPlayer()), event.getItemDrop()));
|
Events.fireToCancel(event, new SpawnEntityEvent(event, create(event.getPlayer()), event.getItemDrop()));
|
||||||
|
@ -28,8 +28,8 @@
|
|||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.AbstractHorse;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Horse;
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -99,7 +99,7 @@ public void onPlayerMove(PlayerMoveEvent event) {
|
|||||||
moveType = MoveType.GLIDE;
|
moveType = MoveType.GLIDE;
|
||||||
} else if (event.getPlayer().isSwimming()) {
|
} else if (event.getPlayer().isSwimming()) {
|
||||||
moveType = MoveType.SWIM;
|
moveType = MoveType.SWIM;
|
||||||
} else if (event.getPlayer().getVehicle() != null && event.getPlayer().getVehicle() instanceof Horse) {
|
} else if (event.getPlayer().getVehicle() != null && event.getPlayer().getVehicle() instanceof AbstractHorse) {
|
||||||
moveType = MoveType.RIDE;
|
moveType = MoveType.RIDE;
|
||||||
}
|
}
|
||||||
com.sk89q.worldedit.util.Location weLocation = session.testMoveTo(localPlayer, BukkitAdapter.adapt(to), moveType);
|
com.sk89q.worldedit.util.Location weLocation = session.testMoveTo(localPlayer, BukkitAdapter.adapt(to), moveType);
|
||||||
|
@ -25,13 +25,17 @@
|
|||||||
import com.sk89q.worldguard.WorldGuard;
|
import com.sk89q.worldguard.WorldGuard;
|
||||||
import com.sk89q.worldguard.bukkit.BukkitWorldConfiguration;
|
import com.sk89q.worldguard.bukkit.BukkitWorldConfiguration;
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
|
import com.sk89q.worldguard.bukkit.cause.Cause;
|
||||||
import com.sk89q.worldguard.bukkit.util.Entities;
|
import com.sk89q.worldguard.bukkit.util.Entities;
|
||||||
|
import com.sk89q.worldguard.bukkit.util.InteropUtils;
|
||||||
import com.sk89q.worldguard.config.ConfigurationManager;
|
import com.sk89q.worldguard.config.ConfigurationManager;
|
||||||
import com.sk89q.worldguard.config.WorldConfiguration;
|
import com.sk89q.worldguard.config.WorldConfiguration;
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||||
|
import com.sk89q.worldguard.protection.FailedLoadRegionSet;
|
||||||
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
import com.sk89q.worldguard.protection.association.RegionAssociable;
|
||||||
import com.sk89q.worldguard.protection.flags.Flags;
|
import com.sk89q.worldguard.protection.flags.Flags;
|
||||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||||
|
import com.sk89q.worldguard.protection.flags.StateFlag.State;
|
||||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||||
@ -653,20 +657,27 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
|
|||||||
public void onCreatePortal(PortalCreateEvent event) {
|
public void onCreatePortal(PortalCreateEvent event) {
|
||||||
WorldConfiguration wcfg = getWorldConfig(event.getWorld());
|
WorldConfiguration wcfg = getWorldConfig(event.getWorld());
|
||||||
|
|
||||||
if (wcfg.regionNetherPortalProtection
|
if (wcfg.useRegions && wcfg.regionNetherPortalProtection
|
||||||
&& event.getReason() == PortalCreateEvent.CreateReason.NETHER_PAIR
|
&& event.getReason() == PortalCreateEvent.CreateReason.NETHER_PAIR
|
||||||
&& !event.getBlocks().isEmpty()) {
|
&& !event.getBlocks().isEmpty()) {
|
||||||
final com.sk89q.worldedit.world.World world = BukkitAdapter.adapt(event.getWorld());
|
final com.sk89q.worldedit.world.World world = BukkitAdapter.adapt(event.getWorld());
|
||||||
final RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer()
|
final Cause cause = Cause.create(event.getEntity());
|
||||||
.get(world);
|
LocalPlayer localPlayer = null;
|
||||||
if (regionManager == null) return;
|
if (cause.getRootCause() instanceof Player player) {
|
||||||
LocalPlayer associable = null;
|
if (wcfg.fakePlayerBuildOverride && InteropUtils.isFakePlayer(player)) {
|
||||||
if (event.getEntity() instanceof Player player) {
|
return;
|
||||||
associable = getPlugin().wrapPlayer(player);
|
}
|
||||||
if (WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(associable, world)) {
|
localPlayer = getPlugin().wrapPlayer(player);
|
||||||
|
if (WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, world)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
final RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer()
|
||||||
|
.get(world);
|
||||||
|
ApplicableRegionSet regions;
|
||||||
|
if (regionManager == null) {
|
||||||
|
regions = FailedLoadRegionSet.getInstance();
|
||||||
|
} else {
|
||||||
BlockVector3 min = null;
|
BlockVector3 min = null;
|
||||||
BlockVector3 max = null;
|
BlockVector3 max = null;
|
||||||
for (BlockState block : event.getBlocks()) {
|
for (BlockState block : event.getBlocks()) {
|
||||||
@ -675,13 +686,17 @@ public void onCreatePortal(PortalCreateEvent event) {
|
|||||||
max = max == null ? loc : loc.getMaximum(max);
|
max = max == null ? loc : loc.getMaximum(max);
|
||||||
}
|
}
|
||||||
ProtectedCuboidRegion target = new ProtectedCuboidRegion("__portal_check", true, min, max);
|
ProtectedCuboidRegion target = new ProtectedCuboidRegion("__portal_check", true, min, max);
|
||||||
final ApplicableRegionSet regions = regionManager.getApplicableRegions(target);
|
regions = regionManager.getApplicableRegions(target);
|
||||||
if (!regions.testState(associable, Flags.BUILD, Flags.BLOCK_PLACE)) {
|
}
|
||||||
if (associable != null) {
|
final RegionAssociable associable = createRegionAssociable(cause);
|
||||||
|
final State buildState = StateFlag.denyToNone(regions.queryState(associable, Flags.BUILD));
|
||||||
|
if (!StateFlag.test(buildState, regions.queryState(associable, Flags.BLOCK_BREAK))
|
||||||
|
|| !StateFlag.test(buildState, regions.queryState(associable, Flags.BLOCK_PLACE))) {
|
||||||
|
if (localPlayer != null && !cause.isIndirect()) {
|
||||||
// NB there is no way to cancel the teleport without PTA (since PlayerPortal doesn't have block info)
|
// NB there is no way to cancel the teleport without PTA (since PlayerPortal doesn't have block info)
|
||||||
// removing PTA was a mistake
|
// removing PTA was a mistake
|
||||||
String message = regions.queryValue(associable, Flags.DENY_MESSAGE);
|
String message = regions.queryValue(localPlayer, Flags.DENY_MESSAGE);
|
||||||
RegionProtectionListener.formatAndSendDenyMessage("create portals", associable, message);
|
RegionProtectionListener.formatAndSendDenyMessage("create portals", localPlayer, message);
|
||||||
}
|
}
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
@ -258,13 +258,11 @@ private void handleBlockRightClick(PlayerInteractEvent event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (wcfg.useRegions) {
|
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);
|
LocalPlayer localPlayer = getPlugin().wrapPlayer(player);
|
||||||
|
|
||||||
if (item != null && item.getType().getKey().toString().equals(wcfg.regionWand) && getPlugin().hasPermission(player, "worldguard.region.wand")) {
|
if (item != null && item.getType().getKey().toString().equals(wcfg.regionWand) && getPlugin().hasPermission(player, "worldguard.region.wand")) {
|
||||||
|
ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
|
||||||
|
.getApplicableRegions(BukkitAdapter.adapt(block.getLocation()), RegionQuery.QueryOption.SORT);
|
||||||
if (set.size() > 0) {
|
if (set.size() > 0) {
|
||||||
player.sendMessage(ChatColor.YELLOW + "Can you build? " + (set.testState(localPlayer, Flags.BUILD) ? "Yes" : "No"));
|
player.sendMessage(ChatColor.YELLOW + "Can you build? " + (set.testState(localPlayer, Flags.BUILD) ? "Yes" : "No"));
|
||||||
|
|
||||||
|
@ -28,7 +28,6 @@
|
|||||||
import com.sk89q.worldguard.bukkit.util.Entities;
|
import com.sk89q.worldguard.bukkit.util.Entities;
|
||||||
import com.sk89q.worldguard.session.AbstractSessionManager;
|
import com.sk89q.worldguard.session.AbstractSessionManager;
|
||||||
import com.sk89q.worldguard.session.Session;
|
import com.sk89q.worldguard.session.Session;
|
||||||
import com.sk89q.worldguard.session.handler.Handler;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -42,13 +41,6 @@
|
|||||||
*/
|
*/
|
||||||
public class BukkitSessionManager extends AbstractSessionManager implements Runnable, Listener {
|
public class BukkitSessionManager extends AbstractSessionManager implements Runnable, Listener {
|
||||||
|
|
||||||
private boolean useTimings;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Handler.Factory<? extends Handler> wrapForRegistration(Handler.Factory<? extends Handler> factory) {
|
|
||||||
return useTimings ? new TimedHandlerFactory(factory) : factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Re-initialize handlers and clear "last position," "last state," etc.
|
* Re-initialize handlers and clear "last position," "last state," etc.
|
||||||
* information for all players.
|
* information for all players.
|
||||||
@ -94,14 +86,6 @@ public boolean hasBypass(LocalPlayer player, World world) {
|
|||||||
return super.hasBypass(player, world);
|
return super.hasBypass(player, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUsingTimings() {
|
|
||||||
return useTimings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsingTimings(boolean useTimings) {
|
|
||||||
this.useTimings = useTimings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||||
|
@ -1,132 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.session;
|
|
||||||
|
|
||||||
import co.aikar.timings.lib.MCTiming;
|
|
||||||
import co.aikar.timings.lib.TimingManager;
|
|
||||||
import com.sk89q.worldedit.util.Location;
|
|
||||||
import com.sk89q.worldguard.LocalPlayer;
|
|
||||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
|
||||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
|
||||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
|
||||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
|
||||||
import com.sk89q.worldguard.session.MoveType;
|
|
||||||
import com.sk89q.worldguard.session.Session;
|
|
||||||
import com.sk89q.worldguard.session.handler.Handler;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.security.CodeSource;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
class TimedHandlerFactory extends Handler.Factory<Handler> {
|
|
||||||
|
|
||||||
private static final TimingManager TIMINGS = TimingManager.of(WorldGuardPlugin.inst());
|
|
||||||
private static final MCTiming UNKNOWN_SOURCE = TIMINGS.of("Third-Party Session Handlers");
|
|
||||||
private static final Map<CodeSource, TimingManager> PLUGIN_SOURCES = new HashMap<>();
|
|
||||||
|
|
||||||
private final Handler.Factory<?> factory;
|
|
||||||
private final MCTiming timing;
|
|
||||||
|
|
||||||
TimedHandlerFactory(Handler.Factory<?> factory) {
|
|
||||||
this.factory = factory;
|
|
||||||
this.timing = makeTiming();
|
|
||||||
}
|
|
||||||
|
|
||||||
private MCTiming makeTiming() {
|
|
||||||
CodeSource codeSource = factory.getClass().getProtectionDomain().getCodeSource();
|
|
||||||
TimingManager owner = PLUGIN_SOURCES.computeIfAbsent(codeSource, source -> {
|
|
||||||
for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
|
||||||
CodeSource pluginSource = plugin.getClass().getProtectionDomain().getCodeSource();
|
|
||||||
if (Objects.equals(pluginSource, source)) {
|
|
||||||
return TimingManager.of(plugin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
String handlerName = factory.getClass().getEnclosingClass().getSimpleName();
|
|
||||||
return owner == null
|
|
||||||
? TIMINGS.of(handlerName, UNKNOWN_SOURCE)
|
|
||||||
: owner.of(handlerName, owner.of("Session Handlers"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Handler create(Session session) {
|
|
||||||
return new TimedHandler(factory.create(session), session, timing);
|
|
||||||
}
|
|
||||||
|
|
||||||
static class TimedHandler extends Handler {
|
|
||||||
private final Handler handler;
|
|
||||||
private final MCTiming timing;
|
|
||||||
|
|
||||||
TimedHandler(Handler innerHandler, Session session, MCTiming timing) {
|
|
||||||
super(session);
|
|
||||||
this.handler = innerHandler;
|
|
||||||
this.timing = timing;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize(LocalPlayer player, Location current, ApplicableRegionSet set) {
|
|
||||||
try (MCTiming ignored = timing.startTiming()) {
|
|
||||||
handler.initialize(player, current, set);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean testMoveTo(LocalPlayer player, Location from, Location to, ApplicableRegionSet toSet, MoveType moveType) {
|
|
||||||
try (MCTiming ignored = timing.startTiming()) {
|
|
||||||
return handler.testMoveTo(player, from, to, toSet, moveType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCrossBoundary(LocalPlayer player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType) {
|
|
||||||
try (MCTiming ignored = timing.startTiming()) {
|
|
||||||
return handler.onCrossBoundary(player, from, to, toSet, entered, exited, moveType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick(LocalPlayer player, ApplicableRegionSet set) {
|
|
||||||
try (MCTiming ignored = timing.startTiming()) {
|
|
||||||
handler.tick(player, set);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public StateFlag.State getInvincibility(LocalPlayer player) {
|
|
||||||
try (MCTiming ignored = timing.startTiming()) {
|
|
||||||
return handler.getInvincibility(player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Handler getWrappedHandler() {
|
|
||||||
return handler;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package com.sk89q.worldguard.bukkit.util;
|
package com.sk89q.worldguard.bukkit.util;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Allay;
|
||||||
import org.bukkit.entity.Ambient;
|
import org.bukkit.entity.Ambient;
|
||||||
import org.bukkit.entity.ArmorStand;
|
import org.bukkit.entity.ArmorStand;
|
||||||
import org.bukkit.entity.Arrow;
|
import org.bukkit.entity.Arrow;
|
||||||
@ -218,6 +219,7 @@ public static boolean isConsideredBuildingIfUsed(Entity entity) {
|
|||||||
return entity instanceof Hanging
|
return entity instanceof Hanging
|
||||||
|| entity instanceof ArmorStand
|
|| entity instanceof ArmorStand
|
||||||
|| entity instanceof EnderCrystal
|
|| entity instanceof EnderCrystal
|
||||||
|
|| entity instanceof Allay
|
||||||
|| entity instanceof Minecart && entity instanceof InventoryHolder;
|
|| entity instanceof Minecart && entity instanceof InventoryHolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1317,6 +1317,7 @@ public static boolean isConsideredBuildingIfUsed(Material type) {
|
|||||||
return type == Material.REPEATER
|
return type == Material.REPEATER
|
||||||
|| type == Material.COMPARATOR
|
|| type == Material.COMPARATOR
|
||||||
|| type == Material.CAKE
|
|| type == Material.CAKE
|
||||||
|
|| type == Material.DRAGON_EGG
|
||||||
|| Tag.FLOWER_POTS.isTagged(type)
|
|| Tag.FLOWER_POTS.isTagged(type)
|
||||||
|| Tag.CANDLES.isTagged(type)
|
|| Tag.CANDLES.isTagged(type)
|
||||||
|| Tag.CANDLE_CAKES.isTagged(type);
|
|| Tag.CANDLE_CAKES.isTagged(type);
|
||||||
|
@ -44,10 +44,8 @@
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.BiPredicate;
|
import java.util.function.BiPredicate;
|
||||||
@ -75,8 +73,6 @@ public abstract class AbstractSessionManager implements SessionManager {
|
|||||||
createSession(key.playerRef.get())));
|
createSession(key.playerRef.get())));
|
||||||
|
|
||||||
private boolean hasCustom = false;
|
private boolean hasCustom = false;
|
||||||
// <original handler, wrapped handler>
|
|
||||||
private Map<Handler.Factory<? extends Handler>, Handler.Factory<? extends Handler>> wrappedHandlers = new HashMap<>();
|
|
||||||
private List<Handler.Factory<? extends Handler>> handlers = new LinkedList<>();
|
private List<Handler.Factory<? extends Handler>> handlers = new LinkedList<>();
|
||||||
|
|
||||||
private static final List<Handler.Factory<? extends Handler>> defaultHandlers = new LinkedList<>();
|
private static final List<Handler.Factory<? extends Handler>> defaultHandlers = new LinkedList<>();
|
||||||
@ -110,27 +106,20 @@ public boolean customHandlersRegistered() {
|
|||||||
return hasCustom;
|
return hasCustom;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Handler.Factory<? extends Handler> wrapForRegistration(Handler.Factory<? extends Handler> factory) {
|
|
||||||
return factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean registerHandler(Handler.Factory<? extends Handler> factory, @Nullable Handler.Factory<? extends Handler> after) {
|
public boolean registerHandler(Handler.Factory<? extends Handler> factory, @Nullable Handler.Factory<? extends Handler> after) {
|
||||||
if (factory == null) return false;
|
if (factory == null) return false;
|
||||||
WorldGuard.logger.log(Level.INFO, "Registering session handler "
|
WorldGuard.logger.log(Level.INFO, "Registering session handler "
|
||||||
+ factory.getClass().getEnclosingClass().getName());
|
+ factory.getClass().getEnclosingClass().getName());
|
||||||
hasCustom = true;
|
hasCustom = true;
|
||||||
Handler.Factory<? extends Handler> wrappedFactory = wrapForRegistration(factory);
|
|
||||||
if (after == null) {
|
if (after == null) {
|
||||||
handlers.add(wrappedFactory);
|
handlers.add(factory);
|
||||||
} else {
|
} else {
|
||||||
Handler.Factory<? extends Handler> wrappedAfter = wrappedHandlers.get(after);
|
int index = handlers.indexOf(after);
|
||||||
int index = handlers.indexOf(wrappedAfter != null ? wrappedAfter : after);
|
|
||||||
if (index == -1) return false;
|
if (index == -1) return false;
|
||||||
|
|
||||||
handlers.add(index + 1, factory); // shifts "after" right one, and everything after "after" right one
|
handlers.add(index + 1, factory); // shifts "after" right one, and everything after "after" right one
|
||||||
}
|
}
|
||||||
wrappedHandlers.put(factory, wrappedFactory);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +131,6 @@ public boolean unregisterHandler(Handler.Factory<? extends Handler> factory) {
|
|||||||
} else {
|
} else {
|
||||||
WorldGuard.logger.log(Level.INFO, "Unregistering session handler "
|
WorldGuard.logger.log(Level.INFO, "Unregistering session handler "
|
||||||
+ factory.getClass().getEnclosingClass().getName());
|
+ factory.getClass().getEnclosingClass().getName());
|
||||||
factory = wrappedHandlers.remove(factory);
|
|
||||||
}
|
}
|
||||||
return handlers.remove(factory);
|
return handlers.remove(factory);
|
||||||
}
|
}
|
||||||
|
@ -34,10 +34,10 @@
|
|||||||
import com.sk89q.worldguard.session.handler.Handler;
|
import com.sk89q.worldguard.session.handler.Handler;
|
||||||
import com.sk89q.worldguard.util.Locations;
|
import com.sk89q.worldguard.util.Locations;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ public Session(SessionManager manager) {
|
|||||||
* @param handler A new handler
|
* @param handler A new handler
|
||||||
*/
|
*/
|
||||||
public void register(Handler handler) {
|
public void register(Handler handler) {
|
||||||
handlers.put(handler.getWrappedHandler().getClass(), handler);
|
handlers.put(handler.getClass(), handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -91,7 +91,7 @@ public SessionManager getManager() {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T extends Handler> T getHandler(Class<T> type) {
|
public <T extends Handler> T getHandler(Class<T> type) {
|
||||||
return (T) handlers.get(type).getWrappedHandler();
|
return (T) handlers.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,11 +148,4 @@ public State getInvincibility(LocalPlayer player) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the handler wrapped by this handler object, if applicable, or just return this if no handler is wrapped.
|
|
||||||
* @return any wrapped handler, or this handler itself
|
|
||||||
*/
|
|
||||||
public Handler getWrappedHandler() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user