Skip to content

Commit

Permalink
Merge branch 'version/7.0.x'
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
  • Loading branch information
wizjany committed May 27, 2023
2 parents b67fd01 + 44d0735 commit 129ae6c
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 212 deletions.
14 changes: 12 additions & 2 deletions CHANGELOG.md
@@ -1,9 +1,19 @@
# Changelog

## 7.0.8 (beta)
## 7.0.8
* Add support for MC 1.19
* 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
* Add rock-growth flag for budding amethyst and pointed dripstone.
Expand Down
1 change: 0 additions & 1 deletion config/checkstyle/import-control.xml
Expand Up @@ -31,7 +31,6 @@
<allow pkg="io.papermc.lib"/>
<allow pkg="com.destroystokyo.paper"/>
<allow pkg="io.papermc.paper"/>
<allow pkg="co.aikar.timings.lib" />
<allow pkg="org.spigotmc" />
</subpackage>

Expand Down
5 changes: 0 additions & 5 deletions worldguard-bukkit/build.gradle.kts
Expand Up @@ -12,10 +12,6 @@ repositories {
name = "paper"
url = uri("https://repo.papermc.io/repository/maven-public/")
}
maven {
name = "aikar-timings"
url = uri("https://repo.aikar.co/nexus/content/groups/aikar/")
}
}

configurations {
Expand All @@ -33,7 +29,6 @@ dependencies {
"compileOnly"("com.sk89q:commandbook:2.3") { isTransitive = false }
"shadeOnly"("io.papermc:paperlib:1.0.8")
"shadeOnly"("org.bstats:bstats-bukkit:3.0.1")
"shadeOnly"("co.aikar:minecraft-timings:1.0.4")
}

tasks.named<Copy>("processResources") {
Expand Down
Expand Up @@ -37,7 +37,6 @@ public class BukkitConfigurationManager extends YamlConfigurationManager {

private boolean hasCommandBookGodMode;
boolean extraStats;
boolean timedSessionHandlers;

/**
* Construct the object.
Expand All @@ -57,7 +56,6 @@ public Collection<BukkitWorldConfiguration> getWorldConfigs() {
public void load() {
super.load();
this.extraStats = getConfig().getBoolean("custom-metrics-charts", true);
this.timedSessionHandlers = getConfig().getBoolean("extra-timings.session-handlers", true);
}

@Override
Expand Down
Expand Up @@ -139,7 +139,6 @@ public void load() {
sessionManager = new BukkitSessionManager();
configuration = new BukkitConfigurationManager(WorldGuardPlugin.inst());
configuration.load();
sessionManager.setUsingTimings(configuration.timedSessionHandlers);
regionContainer = new BukkitRegionContainer(WorldGuardPlugin.inst());
regionContainer.initialize();
debugHandler = new BukkitDebugHandler(WorldGuardPlugin.inst());
Expand Down
Expand Up @@ -27,7 +27,9 @@
import com.sk89q.worldguard.bukkit.util.Entities;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity;
Expand Down Expand Up @@ -107,6 +109,12 @@ public boolean isKnown() {
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 (!PaperLib.isPaper()) {
return false;
Expand Down Expand Up @@ -300,9 +308,24 @@ private void addAll(@Nullable Object... element) {
} else if (o instanceof AreaEffectCloud) {
indirect = true;
addAll(((AreaEffectCloud) o).getSource());
} else if (o instanceof Tameable) {
} else if (o instanceof Tameable tameable) {
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) {
indirect = true;
addAll(((Creature) o).getTarget());
Expand Down
Expand Up @@ -113,6 +113,7 @@
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.EntityUnleashEvent;
import org.bukkit.event.entity.ExpBottleEvent;
Expand Down Expand Up @@ -919,6 +920,12 @@ public void onPlayerPickupItem(PlayerPickupItemEvent event) {
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)
public void onPlayerDropItem(PlayerDropItemEvent event) {
Events.fireToCancel(event, new SpawnEntityEvent(event, create(event.getPlayer()), event.getItemDrop()));
Expand Down
Expand Up @@ -28,8 +28,8 @@
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Horse;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -99,7 +99,7 @@ public void onPlayerMove(PlayerMoveEvent event) {
moveType = MoveType.GLIDE;
} else if (event.getPlayer().isSwimming()) {
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;
}
com.sk89q.worldedit.util.Location weLocation = session.testMoveTo(localPlayer, BukkitAdapter.adapt(to), moveType);
Expand Down
Expand Up @@ -25,13 +25,17 @@
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.BukkitWorldConfiguration;
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.InteropUtils;
import com.sk89q.worldguard.config.ConfigurationManager;
import com.sk89q.worldguard.config.WorldConfiguration;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.FailedLoadRegionSet;
import com.sk89q.worldguard.protection.association.RegionAssociable;
import com.sk89q.worldguard.protection.flags.Flags;
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.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.RegionQuery;
Expand Down Expand Up @@ -653,35 +657,46 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
public void onCreatePortal(PortalCreateEvent event) {
WorldConfiguration wcfg = getWorldConfig(event.getWorld());

if (wcfg.regionNetherPortalProtection
if (wcfg.useRegions && wcfg.regionNetherPortalProtection
&& event.getReason() == PortalCreateEvent.CreateReason.NETHER_PAIR
&& !event.getBlocks().isEmpty()) {
final com.sk89q.worldedit.world.World world = BukkitAdapter.adapt(event.getWorld());
final RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer()
.get(world);
if (regionManager == null) return;
LocalPlayer associable = null;
if (event.getEntity() instanceof Player player) {
associable = getPlugin().wrapPlayer(player);
if (WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(associable, world)) {
final Cause cause = Cause.create(event.getEntity());
LocalPlayer localPlayer = null;
if (cause.getRootCause() instanceof Player player) {
if (wcfg.fakePlayerBuildOverride && InteropUtils.isFakePlayer(player)) {
return;
}
localPlayer = getPlugin().wrapPlayer(player);
if (WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, world)) {
return;
}
}
BlockVector3 min = null;
BlockVector3 max = null;
for (BlockState block : event.getBlocks()) {
BlockVector3 loc = BlockVector3.at(block.getX(), block.getY(), block.getZ());
min = min == null ? loc : loc.getMinimum(min);
max = max == null ? loc : loc.getMaximum(max);
}
ProtectedCuboidRegion target = new ProtectedCuboidRegion("__portal_check", true, min, max);
final ApplicableRegionSet regions = regionManager.getApplicableRegions(target);
if (!regions.testState(associable, Flags.BUILD, Flags.BLOCK_PLACE)) {
if (associable != null) {
final RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer()
.get(world);
ApplicableRegionSet regions;
if (regionManager == null) {
regions = FailedLoadRegionSet.getInstance();
} else {
BlockVector3 min = null;
BlockVector3 max = null;
for (BlockState block : event.getBlocks()) {
BlockVector3 loc = BlockVector3.at(block.getX(), block.getY(), block.getZ());
min = min == null ? loc : loc.getMinimum(min);
max = max == null ? loc : loc.getMaximum(max);
}
ProtectedCuboidRegion target = new ProtectedCuboidRegion("__portal_check", true, min, max);
regions = regionManager.getApplicableRegions(target);
}
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)
// removing PTA was a mistake
String message = regions.queryValue(associable, Flags.DENY_MESSAGE);
RegionProtectionListener.formatAndSendDenyMessage("create portals", associable, message);
String message = regions.queryValue(localPlayer, Flags.DENY_MESSAGE);
RegionProtectionListener.formatAndSendDenyMessage("create portals", localPlayer, message);
}
event.setCancelled(true);
}
Expand Down
Expand Up @@ -258,13 +258,11 @@ private void handleBlockRightClick(PlayerInteractEvent event) {
}

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")) {
ApplicableRegionSet set = WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery()
.getApplicableRegions(BukkitAdapter.adapt(block.getLocation()), RegionQuery.QueryOption.SORT);
if (set.size() > 0) {
player.sendMessage(ChatColor.YELLOW + "Can you build? " + (set.testState(localPlayer, Flags.BUILD) ? "Yes" : "No"));

Expand Down
Expand Up @@ -28,7 +28,6 @@
import com.sk89q.worldguard.bukkit.util.Entities;
import com.sk89q.worldguard.session.AbstractSessionManager;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -42,13 +41,6 @@
*/
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.
* information for all players.
Expand Down Expand Up @@ -94,14 +86,6 @@ public boolean hasBypass(LocalPlayer player, World world) {
return super.hasBypass(player, world);
}

public boolean isUsingTimings() {
return useTimings;
}

public void setUsingTimings(boolean useTimings) {
this.useTimings = useTimings;
}

public void shutdown() {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
Expand Down

0 comments on commit 129ae6c

Please sign in to comment.