Compare commits

...
10 Commits
Author SHA1 Message Date
wizjany 4707b7c7f0 Fix infinite loop in addowner checks.
Fixes WORLDGUARD-4138.
2019-09-22 14:29:09 -04:00
wizjany b0ebbee3de Backport minecart-item-type fix from f5467001. 2019-09-03 17:56:52 -04:00
wizjany 8db0053ffc Extract/half-fix addowner checks.
Max-region-count-for-player is super bork.

Fixes WORLDGUARD-4129.
2019-08-12 20:25:18 -04:00
wizjany 6cf3c23b47 Check waterlogged blocks when emptying buckets.
Fixes WORLDGUARD-4119.

(cherry picked from commit 3272759f25)
2019-07-17 07:46:58 -04:00
wizjany de2b673902 Minecarts spawn in the clicked (rail) block. 2019-07-09 08:02:01 -04:00
wizjany e4da479603 Unfix WORLDGUARD-3360.
There's a reason this wasn't done before. This is fundamentally broken.

(cherry picked from commit ab7751e046)
2019-07-02 23:15:07 -04:00
wizjany 76c3405311 Don't replace in comments and strings when you refactor...
(cherry picked from commit a9cd23c6ef)
2019-07-02 23:14:59 -04:00
wizjany eee75778a1 Add config to disable villagers getting zapped to witches.
"weather.disable-villager-witchification"
2019-07-01 07:44:15 -04:00
wizjany 254b85d178 Add TP button to /rg list where applicable. 2019-07-01 07:44:07 -04:00
wizjany 4ff42c81b5 Send CUI changes when using /rg select. 2019-07-01 07:43:58 -04:00
12 changed files with 107 additions and 52 deletions

No files matched your search

@@ -231,6 +231,7 @@ public class BukkitWorldConfiguration extends YamlWorldConfiguration {
disableThunder = getBoolean("weather.disable-thunderstorm", false);
disableWeather = getBoolean("weather.disable-weather", false);
disablePigZap = getBoolean("weather.disable-pig-zombification", false);
disableVillagerZap = getBoolean("weather.disable-villager-witchification", false);
disableCreeperPower = getBoolean("weather.disable-powered-creepers", false);
alwaysRaining = getBoolean("weather.always-raining", false);
alwaysThundering = getBoolean("weather.always-thundering", false);
@@ -46,7 +46,6 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockDispenseArmorEvent;
import org.bukkit.event.block.BlockDispenseEvent;
@@ -129,9 +128,6 @@ public class BlacklistListener extends AbstractListener {
@EventHandler(ignoreCancelled = true)
public void onUseBlock(final UseBlockEvent event) {
if (event.getResult() == Event.Result.ALLOW) {
return;
}
Player player = event.getCause().getFirstPlayer();
if (player == null) {
@@ -64,6 +64,7 @@ import org.bukkit.block.DoubleChest;
import org.bukkit.block.Dropper;
import org.bukkit.block.Hopper;
import org.bukkit.block.PistonMoveReaction;
import org.bukkit.block.data.Waterlogged;
import org.bukkit.block.data.type.Dispenser;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.Entity;
@@ -530,7 +531,15 @@ public class EventAbstractionListener extends AbstractListener {
@EventHandler(ignoreCancelled = true)
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
Player player = event.getPlayer();
Block blockAffected = event.getBlockClicked().getRelative(event.getBlockFace());
Block blockClicked = event.getBlockClicked();
Block blockAffected;
if (blockClicked.getBlockData() instanceof Waterlogged) {
blockAffected = blockClicked;
} else {
blockAffected = blockClicked.getRelative(event.getBlockFace());
}
boolean allowed = false;
// Milk buckets can't be emptied as of writing
@@ -1004,14 +1013,16 @@ public class EventAbstractionListener extends AbstractListener {
// Handle created Minecarts
if (item != null && Materials.isMinecart(item.getType())) {
// TODO: Give a more specific Minecart type
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.MINECART));
EntityType entityType = Materials.getRelatedEntity(item.getType());
if (entityType == null) {
entityType = EntityType.MINECART;
}
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), entityType));
return;
}
// Handle created boats
if (item != null && Materials.isBoat(item.getType())) {
// TODO as above
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.BOAT));
return;
}
@@ -71,6 +71,7 @@ import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityTransformEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.PigZapEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
@@ -683,10 +684,24 @@ public class WorldGuardEntityListener implements Listener {
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onEntityTransform(EntityTransformEvent event) {
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
final Entity entity = event.getEntity();
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(entity.getWorld()));
final EntityType type = entity.getType();
if (wcfg.disableVillagerZap && type == EntityType.VILLAGER
&& event.getTransformReason() == EntityTransformEvent.TransformReason.LIGHTNING) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPigZap(PigZapEvent event) {
ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(event.getEntity().getWorld()));
final Entity entity = event.getEntity();
WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(entity.getWorld()));
if (wcfg.disablePigZap) {
event.setCancelled(true);
@@ -806,6 +806,17 @@ public final class Materials {
return ENTITY_ITEMS.get(type);
}
/**
* Get the related entity type for a material.
*
* @param material the material
* @return the related entity type or {@code null} if one is not known or exists
*/
@Nullable
public static EntityType getRelatedEntity(Material material) {
return ENTITY_ITEMS.inverse().get(material);
}
/**
* Get the material of the block placed by the given bucket, defaulting
* to water if the bucket type is not known.
@@ -82,41 +82,19 @@ public class MemberCommands extends RegionCommandsBase {
flags = "nw:",
desc = "Add an owner to a region",
min = 2)
public void addOwner(CommandContext args, Actor sender) throws CommandException, AuthorizationException {
public void addOwner(CommandContext args, Actor sender) throws CommandException {
warnAboutSaveFailures(sender);
World world = checkWorld(args, sender, 'w'); // Get the world
LocalPlayer player = null;
if (sender instanceof LocalPlayer) {
player = (LocalPlayer) sender;
}
String id = args.getString(0);
RegionManager manager = checkRegionManager(world);
ProtectedRegion region = checkExistingRegion(manager, id, true);
id = region.getId();
DefaultDomain owners = region.getOwners();
if (player != null) {
if (owners != null && owners.size() == 0) {
if (!sender.hasPermission("worldguard.region.unlimited")) {
int maxRegionCount = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world).getMaxRegionCount(player);
if (maxRegionCount >= 0 && manager.getRegionCountOfPlayer(player)
>= maxRegionCount) {
throw new CommandException("You already own the maximum allowed amount of regions.");
}
}
sender.checkPermission("worldguard.region.addowner.unclaimed." + id.toLowerCase());
} else {
// Check permissions
if (!getPermissionModel(player).mayAddOwners(region)) {
throw new CommandPermissionsException();
}
}
// Check permissions
if (!getPermissionModel(sender).mayAddOwners(region)) {
throw new CommandPermissionsException();
}
// Resolve owners asynchronously
@@ -126,13 +104,46 @@ public class MemberCommands extends RegionCommandsBase {
final String description = String.format("Adding owners to the region '%s' on '%s'", region.getId(), world.getName());
AsyncCommandBuilder.wrap(resolver, sender)
AsyncCommandBuilder.wrap(checkedAddOwners(sender, manager, region, world, resolver), sender)
.registerWithSupervisor(worldGuard.getSupervisor(), description)
.onSuccess(String.format("Region '%s' updated with new owners.", region.getId()), region.getOwners()::addAll)
.onFailure("Failed to add new owners", worldGuard.getExceptionConverter())
.buildAndExec(worldGuard.getExecutorService());
}
private static Callable<DefaultDomain> checkedAddOwners(Actor sender, RegionManager manager, ProtectedRegion region,
World world, DomainInputResolver resolver) {
return () -> {
DefaultDomain owners = resolver.call();
// TODO this was always broken and never checked other players
if (sender instanceof LocalPlayer) {
LocalPlayer player = (LocalPlayer) sender;
if (owners.contains(player) && !sender.hasPermission("worldguard.region.unlimited")) {
int maxRegionCount = WorldGuard.getInstance().getPlatform().getGlobalStateManager()
.get(world).getMaxRegionCount(player);
if (maxRegionCount >= 0 && manager.getRegionCountOfPlayer(player)
>= maxRegionCount) {
throw new CommandException("You already own the maximum allowed amount of regions.");
}
}
}
if (region.getOwners().size() == 0) {
boolean anyOwners = false;
ProtectedRegion parent = region;
while ((parent = parent.getParent()) != null) {
if (parent.getOwners().size() > 0) {
anyOwners = true;
break;
}
}
if (!anyOwners) {
sender.checkPermission("worldguard.region.addowner.unclaimed." + region.getId().toLowerCase());
}
}
return owners;
};
}
@Command(aliases = {"removemember", "remmember", "removemem", "remmem", "rm"},
usage = "<id> <owners...>",
flags = "naw:",
@@ -357,7 +357,9 @@ class RegionCommandsBase {
BlockVector3 pt1 = cuboid.getMinimumPoint();
BlockVector3 pt2 = cuboid.getMaximumPoint();
session.setRegionSelector(player.getWorld(), new CuboidRegionSelector(player.getWorld(), pt1, pt2));
CuboidRegionSelector selector = new CuboidRegionSelector(player.getWorld(), pt1, pt2);
session.setRegionSelector(player.getWorld(), selector);
selector.explainRegionAdjust(player, session);
player.print("Region selected as a cuboid.");
} else if (region instanceof ProtectedPolygonalRegion) {
@@ -365,8 +367,9 @@ class RegionCommandsBase {
Polygonal2DRegionSelector selector = new Polygonal2DRegionSelector(
player.getWorld(), poly2d.getPoints(),
poly2d.getMinimumPoint().getBlockY(),
poly2d.getMaximumPoint().getBlockY() );
poly2d.getMaximumPoint().getBlockY());
session.setRegionSelector(player.getWorld(), selector);
selector.explainRegionAdjust(player, session);
player.print("Region selected as a polygon.");
} else if (region instanceof GlobalProtectedRegion) {
@@ -33,6 +33,7 @@ import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.internal.permission.RegionPermissionModel;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
@@ -260,6 +261,12 @@ public class RegionLister implements Callable<Integer> {
.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND,
"/rg info -w " + world + " " + entry.region.getId()))));
}
if (perms != null && entry.region.getFlag(Flags.TELE_LOC) != null && perms.mayTeleportTo(entry.region)) {
builder.append(TextComponent.space().append(TextComponent.of("[TP]", TextColor.GRAY)
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to teleport")))
.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND,
"/rg tp -w " + world + " " + entry.region.getId()))));
}
return builder.build();
}
@@ -134,6 +134,7 @@ public abstract class WorldConfiguration {
public boolean alwaysRaining;
public boolean alwaysThundering;
public boolean disablePigZap;
public boolean disableVillagerZap;
public boolean disableCreeperPower;
public boolean disableHealthRegain;
public boolean disableMushroomSpread;
@@ -65,7 +65,7 @@ public interface ApplicableRegionSet extends Iterable<ProtectedRegion> {
*
* <p>{@code subject} can be non-null to satisfy region group requirements,
* otherwise it will be assumed that the caller that is not a member of any
* regions. (FlagUtil on a region can be changed so that they only apply
* regions. (Flags on a region can be changed so that they only apply
* to certain users.) The subject argument is required if the
* {@link Flags#BUILD} flag is in the list of flags.</p>
*
@@ -83,7 +83,7 @@ public interface ApplicableRegionSet extends Iterable<ProtectedRegion> {
*
* <p>{@code subject} can be non-null to satisfy region group requirements,
* otherwise it will be assumed that the caller that is not a member of any
* regions. (FlagUtil on a region can be changed so that they only apply
* regions. (Flags on a region can be changed so that they only apply
* to certain users.) The subject argument is required if the
* {@link Flags#BUILD} flag is in the list of flags.</p>
*
@@ -108,7 +108,7 @@ public interface ApplicableRegionSet extends Iterable<ProtectedRegion> {
*
* <p>{@code subject} can be non-null to satisfy region group requirements,
* otherwise it will be assumed that the caller that is not a member of any
* regions. (FlagUtil on a region can be changed so that they only apply
* regions. (Flags on a region can be changed so that they only apply
* to certain users.) The subject argument is required if the
* {@link Flags#BUILD} flag is the flag being queried.</p>
*
@@ -126,7 +126,7 @@ public interface ApplicableRegionSet extends Iterable<ProtectedRegion> {
*
* <p>{@code subject} can be non-null to satisfy region group requirements,
* otherwise it will be assumed that the caller that is not a member of any
* regions. (FlagUtil on a region can be changed so that they only apply
* regions. (Flags on a region can be changed so that they only apply
* to certain users.) The subject argument is required if the
* {@link Flags#BUILD} flag is the flag being queried.</p>
*
@@ -67,7 +67,6 @@ public class RegionQuery {
this.config = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
this.cache = cache;
//noinspection deprecation
}
/**
@@ -178,7 +177,7 @@ public class RegionQuery {
*
* <p>{@code player} can be non-null to satisfy region group requirements,
* otherwise it will be assumed that the caller that is not a member of any
* regions. (FlagUtil on a region can be changed so that they only apply
* regions. (Flags on a region can be changed so that they only apply
* to certain users.) The player argument is required if the
* {@link Flags#BUILD} flag is in the list of flags.</p>
*
@@ -201,7 +200,7 @@ public class RegionQuery {
*
* <p>{@code player} can be non-null to satisfy region group requirements,
* otherwise it will be assumed that the caller that is not a member of any
* regions. (FlagUtil on a region can be changed so that they only apply
* regions. (Flags on a region can be changed so that they only apply
* to certain users.) The player argument is required if the
* {@link Flags#BUILD} flag is in the list of flags.</p>
*
@@ -225,7 +224,7 @@ public class RegionQuery {
*
* <p>{@code player} can be non-null to satisfy region group requirements,
* otherwise it will be assumed that the caller that is not a member of any
* regions. (FlagUtil on a region can be changed so that they only apply
* regions. (Flags on a region can be changed so that they only apply
* to certain users.) The player argument is required if the
* {@link Flags#BUILD} flag is in the list of flags.</p>
*
@@ -247,7 +246,7 @@ public class RegionQuery {
*
* <p>{@code player} can be non-null to satisfy region group requirements,
* otherwise it will be assumed that the caller that is not a member of any
* regions. (FlagUtil on a region can be changed so that they only apply
* regions. (Flags on a region can be changed so that they only apply
* to certain users.) The player argument is required if the
* {@link Flags#BUILD} flag is in the list of flags.</p>
*
@@ -276,7 +275,7 @@ public class RegionQuery {
*
* <p>{@code player} can be non-null to satisfy region group requirements,
* otherwise it will be assumed that the caller that is not a member of any
* regions. (FlagUtil on a region can be changed so that they only apply
* regions. (Flags on a region can be changed so that they only apply
* to certain users.) The player argument is required if the
* {@link Flags#BUILD} flag is the flag being queried.</p>
*
@@ -305,7 +304,7 @@ public class RegionQuery {
*
* <p>{@code player} can be non-null to satisfy region group requirements,
* otherwise it will be assumed that the caller that is not a member of any
* regions. (FlagUtil on a region can be changed so that they only apply
* regions. (Flags on a region can be changed so that they only apply
* to certain users.) The player argument is required if the
* {@link Flags#BUILD} flag is the flag being queried.</p>
*
@@ -327,7 +326,7 @@ public class RegionQuery {
*
* <p>{@code player} can be non-null to satisfy region group requirements,
* otherwise it will be assumed that the caller that is not a member of any
* regions. (FlagUtil on a region can be changed so that they only apply
* regions. (Flags on a region can be changed so that they only apply
* to certain users.) The player argument is required if the
* {@link Flags#BUILD} flag is the flag being queried.</p>
*
@@ -348,7 +347,7 @@ public class RegionQuery {
*
* <p>{@code player} can be non-null to satisfy region group requirements,
* otherwise it will be assumed that the caller that is not a member of any
* regions. (FlagUtil on a region can be changed so that they only apply
* regions. (Flags on a region can be changed so that they only apply
* to certain users.) The player argument is required if the
* {@link Flags#BUILD} flag is the flag being queried.</p>
*
@@ -34,7 +34,7 @@ public class RegionReport extends DataReport {
append("Priority", region.getPriority());
append("Owners", region.getOwners());
append("Members", region.getMembers());
append("FlagUtil", region.getFlags());
append("Flags", region.getFlags());
}
}