Skip to content

Commit

Permalink
Merge branch 'master' into folia
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/wgextender/features/regionprotect/ownormembased/PvPHandlingListener.java
#	src/wgextender/features/regionprotect/ownormembased/RestrictCommands.java
  • Loading branch information
imDaniX committed Sep 2, 2024
2 parents 5b84216 + 1506e56 commit 9fe187d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 61 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# WGExtender Fork
A fork of [WGExtender](https://github.com/Shevchik/WorldGuardExtender) that aims to support latest versions of Paper.
It also adds configurable minimal region claim size limits.
# [Releases](https://github.com/imDaniX/WGExtender/releases/latest) | [Dev Builds](https://github.com/imDaniX/WGExtender/actions?query=branch%3Amaster)
2 changes: 1 addition & 1 deletion src/wgextender/WGExtender.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onEnable() {
WGRegionCommandWrapper.inject(config);
WEWandCommandWrapper.inject(config);
pvplistener = new PvPHandlingListener(config);
pvplistener.inject();
pvplistener.inject(this);
oldpvphandler = new OldPVPFlagsHandler();
if (config.miscOldPvpFlags) {
getLogger().warning(
Expand Down
7 changes: 6 additions & 1 deletion src/wgextender/features/flags/OldPVPFlagsHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
Expand Down Expand Up @@ -121,12 +122,16 @@ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {

@EventHandler(priority = EventPriority.LOWEST)
public void onInteract(PlayerInteractEvent event) {
if (event.getAction().isRightClick() &&
if (isRightClick(event.getAction()) &&
event.getHand() == EquipmentSlot.OFF_HAND &&
event.getItem() != null &&
event.getItem().getType() == Material.BOW &&
WGRegionUtils.isFlagTrue(event.getPlayer().getLocation(), WGExtenderFlags.OLDPVP_NOBOW)) {
event.setCancelled(true);
}
}

private static boolean isRightClick(Action action) {
return action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK;
}
}
46 changes: 0 additions & 46 deletions src/wgextender/features/regionprotect/WGOverrideListener.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.sk89q.worldguard.bukkit.util.Entities;
import com.sk89q.worldguard.bukkit.util.Events;
import com.sk89q.worldguard.bukkit.util.InteropUtils;
import com.sk89q.worldguard.commands.CommandUtils;
import com.sk89q.worldguard.config.WorldConfiguration;
import com.sk89q.worldguard.domains.Association;
import com.sk89q.worldguard.protection.association.Associables;
import com.sk89q.worldguard.protection.association.DelayedRegionOverlapAssociation;
Expand All @@ -29,30 +31,51 @@
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredListener;
import wgextender.Config;
import wgextender.features.regionprotect.WGOverrideListener;
import wgextender.utils.WGRegionUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

public class PvPHandlingListener extends WGOverrideListener {
public class PvPHandlingListener implements Listener {

private final Config config;

private static final String DENY_MESSAGE_KEY = "worldguard.region.lastMessage";
private static final int LAST_MESSAGE_DELAY = 500;

private RegisteredListener origin;

public PvPHandlingListener(Config config) {
this.config = config;
}

@Override
protected Class<? extends Listener> getClassToReplace() {
return RegionProtectionListener.class;
public void inject(Plugin plugin) {
HandlerList handlers = DamageEntityEvent.getHandlerList();
for (var listener : handlers.getRegisteredListeners()) {
if (listener.getListener().getClass().equals(RegionProtectionListener.class)) {
origin = listener;
break;
}
}
Objects.requireNonNull(origin, "Couldn't find the original RegionProtectionListener");
handlers.unregister(origin);
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

public void uninject() {
if (origin == null) return;
HandlerList handlers = DamageEntityEvent.getHandlerList();
handlers.unregister(this);
handlers.register(origin);
origin = null;
}

@EventHandler(ignoreCancelled = true)
public void onDamageEntity(DamageEntityEvent event) {
if (event.getResult() == Result.ALLOW) {
Expand Down Expand Up @@ -155,7 +178,7 @@ public void onDamageEntity(DamageEntityEvent event) {
}
}

private RegionAssociable createRegionAssociable(Cause cause) {
private static RegionAssociable createRegionAssociable(Cause cause) {
if (!cause.isKnown()) {
return Associables.constant(Association.NON_MEMBER);
}
Expand All @@ -175,14 +198,19 @@ private RegionAssociable createRegionAssociable(Cause cause) {

private boolean isWhitelisted(Cause cause, World world, boolean pvp) {
Object rootCause = cause.getRootCause();

if (rootCause instanceof Block block) {
Material type = block.getType();
return (type == Material.HOPPER) || (type == Material.DROPPER);
} else if (rootCause instanceof Player player) {
if (WGRegionUtils.getWorldConfig(world).fakePlayerBuildOverride && InteropUtils.isFakePlayer(player)) {
WorldConfiguration config = WGRegionUtils.getWorldConfig(world);

if (config.fakePlayerBuildOverride && InteropUtils.isFakePlayer(player)) {
return true;
}
return !pvp && WGRegionUtils.canBypassProtection(player);

LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
return !pvp && WGRegionUtils.getPlatform().getSessionManager().hasBypass(localPlayer, localPlayer.getWorld());
} else {
return false;
}
Expand All @@ -196,16 +224,23 @@ private void tellErrorMessage(DelegateEvent event, Cause cause, Location locatio
if (cause.getRootCause() instanceof Player player) {
long now = System.currentTimeMillis();
Long lastTime = WGMetadata.getIfPresent(player, DENY_MESSAGE_KEY, Long.class);
if ((lastTime == null) || ((now - lastTime) >= LAST_MESSAGE_DELAY)) {
String message = WGRegionUtils.REGION_QUERY.queryValue(BukkitAdapter.adapt(location), WorldGuardPlugin.inst().wrapPlayer(player), Flags.DENY_MESSAGE);
if (message != null && !message.isEmpty()) {
player.sendMessage(message.replace("%what%", what));
}
if (lastTime == null || now - lastTime >= LAST_MESSAGE_DELAY) {
RegionQuery query = WGRegionUtils.getPlatform().getRegionContainer().createQuery();
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
String message = query.queryValue(BukkitAdapter.adapt(location), localPlayer, Flags.DENY_MESSAGE);
formatAndSendDenyMessage(what, localPlayer, message);
WGMetadata.put(player, DENY_MESSAGE_KEY, now);
}
}
}

private static void formatAndSendDenyMessage(String what, LocalPlayer localPlayer, String message) {
if (message == null || message.isEmpty()) return;
message = WGRegionUtils.getPlatform().getMatcher().replaceMacros(localPlayer, message);
message = CommandUtils.replaceColorMacros(message);
localPlayer.printRaw(message.replace("%what%", what));
}

private static StateFlag[] getFlags(DelegateEvent event) {
return event.getRelevantFlags().toArray(new StateFlag[0]);
}
Expand Down

0 comments on commit 9fe187d

Please sign in to comment.