Skip to content
Permalink
Browse files

Initial update to 1.14.

  • Loading branch information...
wizjany committed May 21, 2019
1 parent 1792bcb commit 7d388014ee9acefe9e7910344cb0169cbc18df70
@@ -91,6 +91,7 @@
public static final StateFlag WITHER_DAMAGE = register(new StateFlag("wither-damage", true));
public static final StateFlag ENDER_BUILD = register(new StateFlag("enderman-grief", true));
public static final StateFlag SNOWMAN_TRAILS = register(new StateFlag("snowman-trails", true));
public static final StateFlag RAVAGER_RAVAGE = register(new StateFlag("ravager-grief", true));
public static final StateFlag ENTITY_PAINTING_DESTROY = register(new StateFlag("entity-painting-destroy", true));
public static final StateFlag ENTITY_ITEM_FRAME_DESTROY = register(new StateFlag("entity-item-frame-destroy", true));

@@ -10,7 +10,7 @@ repositories {

dependencies {
compile project(path: ':worldguard-core', configuration: 'shadow')
api 'org.bukkit:bukkit:1.13-R0.1-SNAPSHOT'
api 'org.bukkit:bukkit:1.14.1-R0.1-SNAPSHOT'
api 'com.sk89q.worldedit:worldedit-bukkit:7.0.0-SNAPSHOT'

implementation ('com.sk89q:commandbook:2.3') {
@@ -19,16 +19,16 @@

package com.sk89q.worldguard.bukkit.listener;

import com.google.common.base.Function;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;

import javax.annotation.Nullable;

class BlockStateAsBlockFunction implements Function<BlockState, Block> {
final class BlockStateAsBlockFunction {
private BlockStateAsBlockFunction() {
}

@Override
public Block apply(@Nullable BlockState blockState) {
static Block apply(@Nullable BlockState blockState) {
return blockState != null ? blockState.getBlock() : null;
}

@@ -29,6 +29,7 @@
import com.sk89q.worldguard.bukkit.event.block.UseBlockEvent;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.SignChangeEvent;
@@ -135,15 +136,15 @@ public void onSignChange(SignChangeEvent event) {
BukkitWorldConfiguration wcfg = (BukkitWorldConfiguration) getWorldConfig(WorldGuardPlugin.inst().wrapPlayer(player));

if (wcfg.signChestProtection) {
if (event.getLine(0).equalsIgnoreCase("[Lock]")) {
if ("[Lock]".equalsIgnoreCase(event.getLine(0))) {
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().getType() != Material.SIGN) {
if (!Tag.STANDING_SIGNS.isTagged(event.getBlock().getType())) {
player.sendMessage(ChatColor.RED
+ "The [Lock] sign must be a sign post, not a wall sign.");

@@ -152,7 +153,7 @@ public void onSignChange(SignChangeEvent event) {
return;
}

if (!event.getLine(1).equalsIgnoreCase(player.getName())) {
if (!player.getName().equalsIgnoreCase(event.getLine(1))) {
player.sendMessage(ChatColor.RED
+ "The first owner line must be your name.");

@@ -164,7 +165,7 @@ public void onSignChange(SignChangeEvent event) {
Material below = event.getBlock().getRelative(0, -1, 0).getType();

if (below == Material.TNT || below == Material.SAND
|| below == Material.GRAVEL || below == Material.SIGN) {
|| below == Material.GRAVEL || Tag.STANDING_SIGNS.isTagged(below)) {
player.sendMessage(ChatColor.RED
+ "That is not a safe block that you're putting this sign on.");

@@ -178,7 +179,7 @@ public void onSignChange(SignChangeEvent event) {
+ "A chest or double chest above is now protected.");
}
} else if (!wcfg.disableSignChestProtectionCheck) {
if (event.getLine(0).equalsIgnoreCase("[Lock]")) {
if ("[Lock]".equalsIgnoreCase(event.getLine(0))) {
player.sendMessage(ChatColor.RED
+ "WorldGuard's sign chest protection is disabled.");

@@ -21,7 +21,6 @@

import static com.sk89q.worldguard.bukkit.cause.Cause.create;

import com.google.common.collect.Lists;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.BukkitWorldConfiguration;
@@ -64,12 +63,12 @@
import org.bukkit.block.Dropper;
import org.bukkit.block.Hopper;
import org.bukkit.block.PistonMoveReaction;
import org.bukkit.block.data.Directional;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Item;
import org.bukkit.entity.LingeringPotion;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.ThrownPotion;
@@ -125,19 +124,21 @@
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.event.player.PlayerTakeLecternBookEvent;
import org.bukkit.event.player.PlayerUnleashEntityEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.event.vehicle.VehicleDestroyEvent;
import org.bukkit.event.world.PortalCreateEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Dispenser;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import javax.annotation.Nullable;

@@ -188,7 +189,7 @@ public void onBlockPlace(BlockPlaceEvent event) {
BlockState previousState = event.getBlockReplacedState();

// Some blocks, like tall grass and fire, get replaced
if (previousState.getType() != Material.AIR) {
if (previousState.getType() != Material.AIR && previousState.getType() != event.getBlockReplacedState().getType()) {
Events.fireToCancel(event, new BreakBlockEvent(event, create(event.getPlayer()), previousState.getLocation(), previousState.getType()));
}

@@ -240,7 +241,7 @@ public void onBlockBurn(BlockBurnEvent event) {
@EventHandler(ignoreCancelled = true)
public void onStructureGrowEvent(StructureGrowEvent event) {
int originalCount = event.getBlocks().size();
List<Block> blockList = Lists.transform(event.getBlocks(), new BlockStateAsBlockFunction());
List<Block> blockList = event.getBlocks().stream().map(BlockStateAsBlockFunction::apply).collect(Collectors.toList());

Player player = event.getPlayer();
if (player != null) {
@@ -269,8 +270,9 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) {

// Fire two events: one as BREAK and one as PLACE
if (event.getTo() != Material.AIR && event.getBlock().getType() != Material.AIR) {
Events.fireToCancel(event, new BreakBlockEvent(event, create(entity), block));
Events.fireToCancel(event, new PlaceBlockEvent(event, create(entity), block.getLocation(), to));
if (!Events.fireToCancel(event, new BreakBlockEvent(event, create(entity), block))) {
Events.fireToCancel(event, new PlaceBlockEvent(event, create(entity), block.getLocation(), to));
}
} else {
if (event.getTo() == Material.AIR) {
// Track the source so later we can create a proper chain of causes
@@ -305,11 +307,6 @@ public void onEntityChangeBlock(EntityChangeBlockEvent event) {
@EventHandler(ignoreCancelled = true)
public void onEntityExplode(EntityExplodeEvent event) {
Entity entity = event.getEntity();
if (event.getYield() == 0 && event.blockList().isEmpty()) {
// avoids ender dragon spam
return;
}

Events.fireBulkEventToCancel(event, new BreakBlockEvent(event, create(entity), event.getLocation().getWorld(), event.blockList(), Material.AIR));
}

@@ -618,27 +615,7 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
Events.fireToCancel(event, new SpawnEntityEvent(event, Cause.unknown(), event.getEntity()));
}
break;
case NATURAL:
case JOCKEY:
case CHUNK_GEN:
case SPAWNER:
case LIGHTNING:
case BUILD_SNOWMAN:
case BUILD_IRONGOLEM:
case BUILD_WITHER:
case VILLAGE_DEFENSE:
case VILLAGE_INVASION:
case BREEDING:
case SLIME_SPLIT:
case REINFORCEMENTS:
case NETHER_PORTAL:
case INFECTION:
case CURED:
case OCELOT_BABY:
case SILVERFISH_BLOCK:
case MOUNT:
case CUSTOM:
case DEFAULT:
default:
}
}

@@ -789,7 +766,7 @@ public void onEntityUnleash(EntityUnleashEvent event) {
if (event instanceof PlayerUnleashEntityEvent) {
PlayerUnleashEntityEvent playerEvent = (PlayerUnleashEntityEvent) event;
Events.fireToCancel(playerEvent, new UseEntityEvent(playerEvent, create(playerEvent.getPlayer()), event.getEntity()));
} // TODO: Raise anyway?
}
}

@EventHandler(ignoreCancelled = true)
@@ -925,18 +902,18 @@ public void onBlockDispense(BlockDispenseEvent event) {
Events.fireToCancel(event, new UseItemEvent(event, cause, dispenserBlock.getWorld(), item));

// Simulate right click event as players have it
if (dispenserBlock.getBlockData() instanceof Dispenser) {
Dispenser dispenser = (Dispenser) dispenserBlock.getBlockData();
Block placed = dispenserBlock.getRelative(dispenser.getFacing());
Block clicked = placed.getRelative(dispenser.getFacing());
handleBlockRightClick(event, cause, item, clicked, dispenser.getFacing().getOppositeFace(), placed);
if (dispenserBlock.getBlockData() instanceof Directional) {
BlockFace facing = ((Directional) dispenserBlock.getBlockData()).getFacing();
Block placed = dispenserBlock.getRelative(facing);
Block clicked = placed.getRelative(facing);
handleBlockRightClick(event, cause, item, clicked, facing.getOppositeFace(), placed);
}
}

@EventHandler(ignoreCancelled = true)
public void onLingeringSplash(LingeringPotionSplashEvent event) {
AreaEffectCloud aec = event.getAreaEffectCloud();
LingeringPotion potion = event.getEntity();
ThrownPotion potion = event.getEntity();
World world = potion.getWorld();
Cause cause = create(event.getEntity());

@@ -973,6 +950,20 @@ public void onBlockExplode(BlockExplodeEvent event) {
Events.fireBulkEventToCancel(event, eventToFire);
}

@EventHandler(ignoreCancelled = true)
public void onTakeLecternBook(PlayerTakeLecternBookEvent event) {
final UseBlockEvent useEvent = new UseBlockEvent(event, create(event.getPlayer()), event.getLectern().getBlock());
useEvent.getRelevantFlags().add(Flags.CHEST_ACCESS);
Events.fireToCancel(event, useEvent);
}

@EventHandler(ignoreCancelled = true)
public void onPortalCreate(PortalCreateEvent event) {
List<Block> blockList = event.getBlocks().stream().map(BlockStateAsBlockFunction::apply).collect(Collectors.toList());
final PlaceBlockEvent placeEvent = new PlaceBlockEvent(event, create(event.getEntity()), event.getWorld(), blockList, Material.NETHER_PORTAL);
Events.fireBulkEventToCancel(event, placeEvent);
}

/**
* Handle the right click of a block while an item is held.
*
@@ -109,6 +109,10 @@ public void onBreakBlock(final BreakBlockEvent event) {
if (event.getCause().find(EntityType.ENDERMAN) != null) {
event.filter(testState(query, Flags.ENDER_BUILD), false);
}

if (event.getCause().find(EntityType.RAVAGER) != null) {
event.filter(testState(query, Flags.RAVAGER_RAVAGE), false);
}
}

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
@@ -126,21 +130,18 @@ public void onEntityDamage(EntityDamageEvent event) {
return;
}
} else {
try {
if (entity instanceof Player && event.getCause() == DamageCause.FLY_INTO_WALL) {
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer((Player) entity);
if (!query.testState(BukkitAdapter.adapt(entity.getLocation()), localPlayer, Flags.FALL_DAMAGE)) {
event.setCancelled(true);
return;
}
if (entity instanceof Player && event.getCause() == DamageCause.FLY_INTO_WALL) {
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer((Player) entity);
if (!query.testState(BukkitAdapter.adapt(entity.getLocation()), localPlayer, Flags.FALL_DAMAGE)) {
event.setCancelled(true);
return;
}
} catch (NoSuchFieldError ignored) {
}
}

if (event instanceof EntityDamageByEntityEvent) {
Entity damager = (((EntityDamageByEntityEvent) event)).getDamager();
if (damager != null && damager.getType() == EntityType.FIREWORK) {
if (damager.getType() == EntityType.FIREWORK) {
if (!query.testState(BukkitAdapter.adapt(entity.getLocation()), (RegionAssociable) null, Flags.FIREWORK_DAMAGE)) {
event.setCancelled(true);
return;

0 comments on commit 7d38801

Please sign in to comment.
You can’t perform that action at this time.