Permalink
Browse files

Further compat work.

  • Loading branch information...
me4502 committed Jul 21, 2018
1 parent 6c5319f commit 89db0d9fee1452aaf5d7c5080f7a02865bd29bc4
Showing with 541 additions and 636 deletions.
  1. +9 −5 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/commands/WorldGuardCommands.java
  2. +7 −6 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/event/block/AbstractBlockEvent.java
  3. +35 −53 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/ChestProtectionListener.java
  4. +7 −7 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/EventAbstractionListener.java
  5. +14 −6 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/InvincibilityListener.java
  6. +6 −4 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerModesListener.java
  7. +1 −1 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/PlayerMoveListener.java
  8. +21 −20 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionFlagsListener.java
  9. +29 −23 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionProtectionListener.java
  10. +8 −5 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/SpongeUtil.java
  11. +81 −85 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardBlockListener.java
  12. +4 −2 ...uard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardCommandBookListener.java
  13. +28 −26 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java
  14. +8 −5 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardHangingListener.java
  15. +15 −11 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardPlayerListener.java
  16. +3 −2 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardServerListener.java
  17. +5 −3 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardVehicleListener.java
  18. +12 −8 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardWeatherListener.java
  19. +5 −3 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardWorldListener.java
  20. +2 −1 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldRulesListener.java
  21. +0 −54 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/debounce/BlockBlockPair.java
  22. +0 −58 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/debounce/BlockMaterialPair.java
  23. +3 −4 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/util/Blocks.java
  24. +2 −3 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/util/InteropUtils.java
  25. +233 −237 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/util/Materials.java
  26. +3 −4 worldguard-legacy/src/main/java/com/sk89q/worldguard/protection/GlobalRegionManager.java
@@ -26,6 +26,9 @@
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.sk89q.minecraft.util.commands.*;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.config.ConfigurationManager;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.util.logging.LoggerToChatHandler;
@@ -95,13 +98,13 @@ public void reload(CommandContext args, CommandSender sender) throws CommandExce
}
try {
ConfigurationManager config = plugin.getGlobalStateManager();
ConfigurationManager config = WorldGuard.getInstance().getPlatform().getGlobalStateManager();
config.unload();
config.load();
for (World world : Bukkit.getServer().getWorlds()) {
config.get(world);
config.get(BukkitAdapter.adapt(world));
}
plugin.getRegionContainer().reload();
WorldGuard.getInstance().getPlatform().getRegionContainer().reload();
// WGBukkit.cleanCache();
sender.sendMessage("WorldGuard configuration reloaded.");
} catch (Throwable t) {
@@ -250,12 +253,13 @@ public void stopProfile(CommandContext args, final CommandSender sender) throws
@CommandPermissions("worldguard.flushstates")
public void flushStates(CommandContext args, CommandSender sender) throws CommandException {
if (args.argsLength() == 0) {
plugin.getSessionManager().resetAllStates();
WorldGuard.getInstance().getPlatform().getSessionManager().resetAllStates();
sender.sendMessage("Cleared all states.");
} else {
Player player = plugin.getServer().getPlayer(args.getString(0));
if (player != null) {
plugin.getSessionManager().resetState(player);
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
WorldGuard.getInstance().getPlatform().getSessionManager().resetState(localPlayer);
sender.sendMessage("Cleared states for player \"" + player.getName() + "\".");
}
}
@@ -19,22 +19,23 @@
package com.sk89q.worldguard.bukkit.event.block;
import com.google.common.base.Predicate;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldguard.bukkit.cause.Cause;
import com.sk89q.worldguard.bukkit.event.DelegateEvent;
import com.sk89q.worldguard.bukkit.event.BulkEvent;
import com.sk89q.worldguard.bukkit.event.DelegateEvent;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.Predicate;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
/**
* This event is an internal event. We do not recommend handling or throwing
@@ -65,7 +66,7 @@ protected AbstractBlockEvent(@Nullable Event originalEvent, Cause cause, Locatio
}
private static List<Block> createList(Block block) {
List<Block> blocks = new ArrayList<Block>();
List<Block> blocks = new ArrayList<>();
blocks.add(block);
return blocks;
}
@@ -102,7 +103,7 @@ public boolean filter(Predicate<Location> predicate, boolean cancelEventOnFalse)
Iterator<Block> it = blocks.iterator();
while (it.hasNext()) {
if (!predicate.apply(it.next().getLocation())) {
if (!predicate.test(it.next().getLocation())) {
hasRemoval = true;
if (cancelEventOnFalse) {
@@ -19,16 +19,16 @@
package com.sk89q.worldguard.bukkit.listener;
import com.google.common.base.Predicate;
import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.bukkit.BukkitWorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.event.DelegateEvent;
import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent;
import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent;
import com.sk89q.worldguard.bukkit.event.block.UseBlockEvent;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.SignChangeEvent;
@@ -58,110 +58,92 @@ public void onPlaceBlock(final PlaceBlockEvent event) {
final Player player = event.getCause().getFirstPlayer();
if (player != null) {
final BukkitWorldConfiguration wcfg = getWorldConfig(player);
final BukkitWorldConfiguration wcfg = getWorldConfig(WorldGuardPlugin.inst().wrapPlayer(player));
// Early guard
if (!wcfg.signChestProtection) {
return;
}
event.filter(new Predicate<Location>() {
@Override
public boolean apply(Location target) {
if (wcfg.getChestProtection().isChest(event.getEffectiveMaterial().getId()) && wcfg.isChestProtected(target.getBlock(), player)) {
sendMessage(event, player, ChatColor.DARK_RED + "This spot is for a chest that you don't have permission for.");
return false;
}
return true;
event.filter(target -> {
if (wcfg.getChestProtection().isChest(BukkitAdapter.adapt(event.getEffectiveMaterial())) && wcfg.isChestProtected(BukkitAdapter.adapt(target.getBlock().getLocation()),
WorldGuardPlugin.inst().wrapPlayer(player))) {
sendMessage(event, player, ChatColor.DARK_RED + "This spot is for a chest that you don't have permission for.");
return false;
}
return true;
}, true);
}
}
@EventHandler(ignoreCancelled = true)
public void onBreakBlock(final BreakBlockEvent event) {
final Player player = event.getCause().getFirstPlayer();
final LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
final BukkitWorldConfiguration wcfg = getWorldConfig(event.getWorld());
final BukkitWorldConfiguration wcfg = getWorldConfig(localPlayer);
// Early guard
if (!wcfg.signChestProtection) {
return;
}
if (player != null) {
event.filter(new Predicate<Location>() {
@Override
public boolean apply(Location target) {
if (wcfg.isChestProtected(target.getBlock(), player)) {
sendMessage(event, player, ChatColor.DARK_RED + "This chest is protected.");
return false;
}
return true;
event.filter(target -> {
if (wcfg.isChestProtected(BukkitAdapter.adapt(target.getBlock().getLocation()), localPlayer)) {
sendMessage(event, player, ChatColor.DARK_RED + "This chest is protected.");
return false;
}
return true;
}, true);
} else {
event.filter(new Predicate<Location>() {
@Override
public boolean apply(Location target) {
return !wcfg.isChestProtected(target.getBlock());
}
});
event.filter(target -> !wcfg.isChestProtected(BukkitAdapter.adapt(target.getBlock().getLocation())));
}
}
@EventHandler(ignoreCancelled = true)
public void onUseBlock(final UseBlockEvent event) {
final Player player = event.getCause().getFirstPlayer();
final LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
final BukkitWorldConfiguration wcfg = getWorldConfig(event.getWorld());
final BukkitWorldConfiguration wcfg = getWorldConfig(localPlayer);
// Early guard
if (!wcfg.signChestProtection) {
return;
}
if (player != null) {
event.filter(new Predicate<Location>() {
@Override
public boolean apply(Location target) {
if (wcfg.isChestProtected(target.getBlock(), player)) {
sendMessage(event, player, ChatColor.DARK_RED + "This chest is protected.");
return false;
}
return true;
event.filter(target -> {
if (wcfg.isChestProtected(BukkitAdapter.adapt(target.getBlock().getLocation()), localPlayer)) {
sendMessage(event, player, ChatColor.DARK_RED + "This chest is protected.");
return false;
}
return true;
}, true);
} else {
event.filter(new Predicate<Location>() {
@Override
public boolean apply(Location target) {
return !wcfg.isChestProtected(target.getBlock());
}
});
event.filter(target -> !wcfg.isChestProtected(BukkitAdapter.adapt(target.getBlock().getLocation())));
}
}
@EventHandler(ignoreCancelled = true)
public void onSignChange(SignChangeEvent event) {
Player player = event.getPlayer();
BukkitWorldConfiguration wcfg = getWorldConfig(player);
BukkitWorldConfiguration wcfg = getWorldConfig(WorldGuardPlugin.inst().wrapPlayer(player));
if (wcfg.signChestProtection) {
if (event.getLine(0).equalsIgnoreCase("[Lock]")) {
if (wcfg.isChestProtectedPlacement(event.getBlock(), player)) {
if (wcfg.isChestProtectedPlacement(BukkitAdapter.adapt(event.getBlock().getLocation()), WorldGuardPlugin.inst().wrapPlayer(player))) {
player.sendMessage(ChatColor.DARK_RED + "You do not own the adjacent chest.");
event.getBlock().breakNaturally();
event.setCancelled(true);
return;
}
if (event.getBlock().getTypeId() != BlockID.SIGN_POST) {
if (event.getBlock().getType() != Material.SIGN) {
player.sendMessage(ChatColor.RED
+ "The [Lock] sign must be a sign post, not a wall sign.");
@@ -179,10 +161,10 @@ public void onSignChange(SignChangeEvent event) {
return;
}
int below = event.getBlock().getRelative(0, -1, 0).getTypeId();
Material below = event.getBlock().getRelative(0, -1, 0).getType();
if (below == BlockID.TNT || below == BlockID.SAND
|| below == BlockID.GRAVEL || below == BlockID.SIGN_POST) {
if (below == Material.TNT || below == Material.SAND
|| below == Material.GRAVEL || below == Material.SIGN) {
player.sendMessage(ChatColor.RED
+ "That is not a safe block that you're putting this sign on.");
@@ -130,7 +130,7 @@ public void onBlockBreak(BlockBreakEvent event) {
@EventHandler(ignoreCancelled = true)
public void onBlockMultiPlace(BlockMultiPlaceEvent event) {
List<Block> blocks = new ArrayList<Block>();
List<Block> blocks = new ArrayList<>();
for (BlockState bs : event.getReplacedBlockStates()) {
blocks.add(bs.getBlock());
}
@@ -219,7 +219,7 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) {
Material to = event.getTo();
// Forget about Redstone ore, especially since we handle it in INTERACT
if (Materials.isRedstoneOre(block.getType()) && Materials.isRedstoneOre(to)) {
if (block.getType() == Material.REDSTONE_ORE && to == Material.REDSTONE_ORE) {
return;
}
@@ -278,7 +278,7 @@ public void onBlockPistonRetract(BlockPistonRetractEvent event) {
ArrayList<Block> blocks;
try {
blocks = new ArrayList<Block>(event.getBlocks());
blocks = new ArrayList<>(event.getBlocks());
} catch (NoSuchMethodError e) {
blocks = Lists.newArrayList(event.getRetractLocation().getBlock());
if (piston.getType() == Material.PISTON_MOVING_PIECE) {
@@ -308,7 +308,7 @@ public void onBlockPistonRetract(BlockPistonRetractEvent event) {
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
EventDebounce.Entry entry = pistonExtendDebounce.getIfNotPresent(new BlockPistonExtendKey(event), event);
if (entry != null) {
List<Block> blocks = new ArrayList<Block>(event.getBlocks());
List<Block> blocks = new ArrayList<>(event.getBlocks());
int originalLength = blocks.size();
BlockFace dir = event.getDirection();
for (int i = 0; i < blocks.size(); i++) {
@@ -336,7 +336,7 @@ public void onBlockDamage(BlockDamageEvent event) {
// Previously, and perhaps still, the only way to catch cake eating
// events was through here
if (target.getType() == Material.CAKE_BLOCK) {
if (target.getType() == Material.CAKE) {
Events.fireToCancel(event, new UseBlockEvent(event, create(event.getPlayer()), target));
}
}
@@ -354,7 +354,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {
switch (event.getAction()) {
case PHYSICAL:
// Forget about Redstone ore
if (Materials.isRedstoneOre(clicked.getType()) || clicked.getType() == Material.SOIL) {
if (clicked.getType() == Material.REDSTONE_ORE || clicked.getType() == Material.FARMLAND) {
silent = true;
}
@@ -947,7 +947,7 @@ public void onBlockDispense(BlockDispenseEvent event) {
}
// Handle cocoa beans
if (item != null && item.getType() == Material.INK_SACK && Materials.isDyeColor(item.getData(), DyeColor.BROWN)) {
if (item != null && item.getType() == Material.COCOA_BEANS) {
// CraftBukkit doesn't or didn't throw a clicked place for this
if (!(faceClicked == BlockFace.DOWN || faceClicked == BlockFace.UP)) {
Events.fireToCancel(event, new PlaceBlockEvent(event, cause, placed.getLocation(), Material.COCOA));
@@ -19,6 +19,9 @@
package com.sk89q.worldguard.bukkit.listener;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.BukkitWorldConfiguration;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import org.bukkit.entity.Entity;
@@ -48,19 +51,22 @@ public InvincibilityListener(WorldGuardPlugin plugin) {
* @param player The player
* @return True if invincible
*/
private boolean isInvincible(Player player) {
return getPlugin().getSessionManager().get(player).isInvincible(player);
private boolean isInvincible(LocalPlayer player) {
return WorldGuard.getInstance().getPlatform().getSessionManager().get(player).isInvincible(player);
}
@EventHandler(ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent event) {
Entity victim = event.getEntity();
BukkitWorldConfiguration worldConfig = getPlugin().getGlobalStateManager().get(victim.getWorld());
if (victim instanceof Player) {
Player player = (Player) victim;
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
if (isInvincible(player)) {
BukkitWorldConfiguration worldConfig =
(BukkitWorldConfiguration) WorldGuard.getInstance().getPlatform().getGlobalStateManager().get((World) localPlayer.getExtent());
if (isInvincible(localPlayer)) {
player.setFireTicks(0);
event.setCancelled(true);
@@ -84,8 +90,9 @@ public void onEntityCombust(EntityCombustEvent event) {
if (entity instanceof Player) {
Player player = (Player) entity;
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
if (isInvincible(player)) {
if (isInvincible(localPlayer)) {
event.setCancelled(true);
}
}
@@ -95,8 +102,9 @@ public void onEntityCombust(EntityCombustEvent event) {
public void onFoodLevelChange(FoodLevelChangeEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
if (event.getFoodLevel() < player.getFoodLevel() && isInvincible(player)) {
if (event.getFoodLevel() < player.getFoodLevel() && isInvincible(localPlayer)) {
event.setCancelled(true);
}
}
Oops, something went wrong.

0 comments on commit 89db0d9

Please sign in to comment.