Merge remote-tracking branch 'origin/breaking' into breaking

# Conflicts:
#	Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/generator/BukkitPlotGenerator.java
#	Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java
This commit is contained in:
sauilitired
2018-12-20 02:25:55 +01:00
23 changed files with 1018 additions and 954 deletions

View File

@ -576,34 +576,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
} catch (final NoSuchMethodException | ClassNotFoundException ignored) {
PlotSquared.debug("Not running Spigot. Skipping EntitySpawnListener event.");
}
if (PlotSquared.get().checkVersion(getServerVersion(), 1, 7, 9)) {
try {
getServer().getPluginManager().registerEvents(new EntityPortal_1_7_9(), this);
} catch (Throwable e) {
e.printStackTrace();
}
}
if (PlotSquared.get().checkVersion(getServerVersion(), BukkitVersion.v1_8_0)) {
try {
getServer().getPluginManager().registerEvents(new PlayerEvents_1_8(), this);
} catch (Throwable e) {
e.printStackTrace();
}
}
if (PlotSquared.get().checkVersion(getServerVersion(), BukkitVersion.v1_8_3)) {
try {
getServer().getPluginManager().registerEvents(new PlayerEvents183(), this);
} catch (Throwable e) {
e.printStackTrace();
}
}
if (PlotSquared.get().checkVersion(getServerVersion(), BukkitVersion.v1_9_0)) {
try {
getServer().getPluginManager().registerEvents(new PlayerEvents_1_9(main), this);
} catch (Throwable e) {
e.printStackTrace();
}
}
}
@Override public void registerInventoryEvents() {
@ -613,11 +585,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
@Override public void registerPlotPlusEvents() {
PlotPlusListener.startRunnable(this);
getServer().getPluginManager().registerEvents(new PlotPlusListener(), this);
if (PlotSquared.get().checkVersion(getServerVersion(), BukkitVersion.v1_12_0)) {
getServer().getPluginManager().registerEvents(new PlotPlusListener_1_12(), this);
} else {
getServer().getPluginManager().registerEvents(new PlotPlusListener_Legacy(), this);
}
}
@Override public void registerForceFieldEvents() {

View File

@ -1,95 +0,0 @@
package com.github.intellectualsites.plotsquared.bukkit.listeners;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityTeleportEvent;
import org.bukkit.event.vehicle.*;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import java.util.List;
@SuppressWarnings("unused") public class EntityPortal_1_7_9 implements Listener {
private static boolean ignoreTP = false;
public EntityPortal_1_7_9() {
}
public static void test(Entity entity) {
List<MetadataValue> meta = entity.getMetadata("plotworld");
World world = entity.getLocation().getWorld();
if (meta == null || meta.isEmpty()) {
if (PlotSquared.get().hasPlotArea(world.getName())) {
entity.setMetadata("plotworld",
new FixedMetadataValue((Plugin) PlotSquared.get().IMP, entity.getLocation()));
}
} else {
Location origin = (Location) meta.get(0).value();
World originWorld = origin.getWorld();
if (!originWorld.equals(world)) {
if (!ignoreTP) {
if (!world.getName().equalsIgnoreCase(originWorld + "_the_end")) {
try {
ignoreTP = true;
entity.teleport(origin);
} finally {
ignoreTP = false;
}
if (entity.getLocation().getWorld().equals(world)) {
entity.remove();
}
}
} else {
entity.remove();
}
}
}
}
@EventHandler public void onVehicle(VehicleUpdateEvent event) {
test(event.getVehicle());
}
@EventHandler public void onVehicle(VehicleDestroyEvent event) {
test(event.getVehicle());
}
@EventHandler public void onVehicle(VehicleEntityCollisionEvent event) {
test(event.getVehicle());
}
@EventHandler public void onVehicle(VehicleCreateEvent event) {
test(event.getVehicle());
}
@EventHandler public void onVehicle(VehicleBlockCollisionEvent event) {
test(event.getVehicle());
}
@EventHandler public void onTeleport(EntityTeleportEvent event) {
Entity ent = event.getEntity();
if (ent instanceof Vehicle || ent instanceof ArmorStand)
test(event.getEntity());
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void vehicleMove(VehicleMoveEvent event) throws IllegalAccessException {
test(event.getVehicle());
}
@EventHandler public void spawn(CreatureSpawnEvent event) {
switch (event.getEntityType()) {
case ARMOR_STAND:
test(event.getEntity());
}
}
}

View File

@ -7,16 +7,59 @@ import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import org.bukkit.World;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.EntityTeleportEvent;
import org.bukkit.event.vehicle.*;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import java.util.List;
@SuppressWarnings("unused") public class EntitySpawnListener implements Listener {
private static boolean ignoreTP = false;
public static void test(Entity entity) {
List<MetadataValue> meta = entity.getMetadata("plotworld");
World world = entity.getLocation().getWorld();
if (meta == null || meta.isEmpty()) {
if (PlotSquared.get().hasPlotArea(world.getName())) {
entity.setMetadata("plotworld",
new FixedMetadataValue((Plugin) PlotSquared.get().IMP, entity.getLocation()));
}
} else {
org.bukkit.Location origin = (org.bukkit.Location) meta.get(0).value();
World originWorld = origin.getWorld();
if (!originWorld.equals(world)) {
if (!ignoreTP) {
if (!world.getName().equalsIgnoreCase(originWorld + "_the_end")) {
try {
ignoreTP = true;
entity.teleport(origin);
} finally {
ignoreTP = false;
}
if (entity.getLocation().getWorld().equals(world)) {
entity.remove();
}
}
} else {
entity.remove();
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void creatureSpawnEvent(EntitySpawnEvent event) {
Entity entity = event.getEntity();
@ -58,4 +101,42 @@ import org.bukkit.plugin.Plugin;
}
}
}
@EventHandler public void onVehicle(VehicleUpdateEvent event) {
test(event.getVehicle());
}
@EventHandler public void onVehicle(VehicleDestroyEvent event) {
test(event.getVehicle());
}
@EventHandler public void onVehicle(VehicleEntityCollisionEvent event) {
test(event.getVehicle());
}
@EventHandler public void onVehicle(VehicleCreateEvent event) {
test(event.getVehicle());
}
@EventHandler public void onVehicle(VehicleBlockCollisionEvent event) {
test(event.getVehicle());
}
@EventHandler public void onTeleport(EntityTeleportEvent event) {
Entity ent = event.getEntity();
if (ent instanceof Vehicle || ent instanceof ArmorStand)
test(event.getEntity());
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void vehicleMove(VehicleMoveEvent event) throws IllegalAccessException {
test(event.getVehicle());
}
@EventHandler public void spawn(CreatureSpawnEvent event) {
switch (event.getEntityType()) {
case ARMOR_STAND:
test(event.getEntity());
}
}
}

View File

@ -4,7 +4,6 @@ import com.github.intellectualsites.plotsquared.bukkit.BukkitMain;
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitLazyBlock;
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitVersion;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.C;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
@ -21,6 +20,8 @@ import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Piston;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
@ -30,6 +31,7 @@ import org.bukkit.event.block.*;
import org.bukkit.event.entity.*;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.*;
@ -39,6 +41,8 @@ import org.bukkit.event.vehicle.VehicleMoveEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.help.HelpTopic;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
@ -46,9 +50,7 @@ import org.bukkit.projectiles.BlockProjectileSource;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.Map.Entry;
import java.util.regex.Pattern;
@ -64,8 +66,6 @@ import java.util.regex.Pattern;
private boolean tmpTeleport = true;
private Field fieldPlayer;
private PlayerMoveEvent moveTmp;
private boolean v112 =
PlotSquared.get().checkVersion(PlotSquared.imp().getServerVersion(), BukkitVersion.v1_12_0);
{
try {
@ -76,8 +76,7 @@ import java.util.regex.Pattern;
}
}
public static void sendBlockChange(final org.bukkit.Location bloc, final Material type,
final byte data) {
public static void sendBlockChange(final org.bukkit.Location bloc, final BlockData data) {
TaskManager.runTaskLater(() -> {
String world = bloc.getWorld().getName();
int x = bloc.getBlockX();
@ -91,7 +90,7 @@ import java.util.regex.Pattern;
|| 16 * Math.abs(loc.getZ() - z) / 16 > distance) {
continue;
}
((BukkitPlayer) player).player.sendBlockChange(bloc, type, data);
((BukkitPlayer) player).player.sendBlockChange(bloc, data);
}
}
}, 3);
@ -232,32 +231,48 @@ import java.util.regex.Pattern;
Block block = event.getBlock();
switch (block.getType()) {
case OBSERVER:
case LEGACY_REDSTONE_LAMP_OFF:
case REDSTONE:
case REDSTONE_ORE:
case REDSTONE_BLOCK:
case REDSTONE_TORCH:
case REDSTONE_WALL_TORCH:
case REDSTONE_WIRE:
case LEGACY_REDSTONE_LAMP_ON:
case LEGACY_PISTON_BASE:
case LEGACY_PISTON_STICKY_BASE:
case LEGACY_IRON_DOOR_BLOCK:
case REDSTONE_LAMP:
case PISTON_HEAD:
case PISTON:
case STICKY_PISTON:
case MOVING_PISTON:
case LEVER:
case LEGACY_WOODEN_DOOR:
case LEGACY_FENCE_GATE:
case LEGACY_WOOD_BUTTON:
case ACACIA_BUTTON:
case BIRCH_BUTTON:
case DARK_OAK_BUTTON:
case JUNGLE_BUTTON:
case OAK_BUTTON:
case SPRUCE_BUTTON:
case STONE_BUTTON:
case LEGACY_IRON_PLATE:
case LEGACY_WOOD_PLATE:
case LEGACY_STONE_PLATE:
case LEGACY_GOLD_PLATE:
case STONE_PRESSURE_PLATE:
case ACACIA_PRESSURE_PLATE:
case BIRCH_PRESSURE_PLATE:
case DARK_OAK_PRESSURE_PLATE:
case HEAVY_WEIGHTED_PRESSURE_PLATE:
case JUNGLE_PRESSURE_PLATE:
case LIGHT_WEIGHTED_PRESSURE_PLATE:
case OAK_PRESSURE_PLATE:
case SPRUCE_PRESSURE_PLATE:
case SPRUCE_DOOR:
case BIRCH_DOOR:
case JUNGLE_DOOR:
case ACACIA_DOOR:
case DARK_OAK_DOOR:
case IRON_DOOR:
case OAK_DOOR:
case IRON_TRAPDOOR:
case SPRUCE_FENCE_GATE:
case BIRCH_FENCE_GATE:
case JUNGLE_FENCE_GATE:
case ACACIA_FENCE_GATE:
case DARK_OAK_FENCE_GATE:
case OAK_FENCE_GATE:
case POWERED_RAIL:
return;
default:
@ -285,7 +300,7 @@ import java.util.regex.Pattern;
}
}
} else {
disable = UUIDHandler.getPlayer(plot.owner) == null;
disable = UUIDHandler.getPlayer(plot.guessOwner()) == null;
}
if (disable) {
for (UUID trusted : plot.getTrusted()) {
@ -314,8 +329,7 @@ import java.util.regex.Pattern;
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPhysicsEvent(BlockPhysicsEvent event) {
switch (event.getChangedType()) {
case LEGACY_REDSTONE_COMPARATOR_OFF:
case LEGACY_REDSTONE_COMPARATOR_ON: {
case COMPARATOR: {
Block block = event.getBlock();
Location loc = BukkitUtil.getLocation(block.getLocation());
PlotArea area = loc.getPlotArea();
@ -354,8 +368,9 @@ import java.util.regex.Pattern;
if (Settings.Redstone.DETECT_INVALID_EDGE_PISTONS) {
Block block = event.getBlock();
switch (block.getType()) {
case LEGACY_PISTON_BASE:
case LEGACY_PISTON_STICKY_BASE:
case PISTON:
case STICKY_PISTON:
Piston piston = (Piston) block.getBlockData();
Location loc = BukkitUtil.getLocation(block.getLocation());
PlotArea area = loc.getPlotArea();
if (area == null) {
@ -365,22 +380,17 @@ import java.util.regex.Pattern;
if (plot == null) {
return;
}
int data = block.getData();
switch (data) {
case 5:
case 13:
switch (piston.getFacing()) {
case EAST:
loc.setX(loc.getX() + 1);
break;
case 4:
case 12:
case SOUTH:
loc.setX(loc.getX() - 1);
break;
case 3:
case 11:
case WEST:
loc.setZ(loc.getZ() + 1);
break;
case 2:
case 10:
case NORTH:
loc.setZ(loc.getZ() - 1);
break;
}
@ -634,7 +644,7 @@ import java.util.regex.Pattern;
// Check allowed
Entity passenger = vehicle.getPassenger();
Entity passenger = vehicle.getPassengers().get(1);
if (passenger instanceof Player) {
final Player player = (Player) passenger;
@ -646,11 +656,7 @@ import java.util.regex.Pattern;
moveTmp.setCancelled(false);
fieldPlayer.set(moveTmp, player);
List<Entity> passengers;
if (v112)
passengers = vehicle.getPassengers();
else
passengers = null;
List<Entity> passengers = vehicle.getPassengers();
this.playerMove(moveTmp);
org.bukkit.Location dest;
@ -945,9 +951,8 @@ import java.util.regex.Pattern;
return;
}
if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
if (player.getInventory().getItemInMainHand().getType() == BukkitUtil.getBukkitLegacyMappings()
.fromLegacyToString(PlotSquared.get().worldedit.getConfiguration().wandItem)
.to(Material.class)) {
if (player.getInventory().getItemInMainHand().getType() == Material
.getMaterial(PlotSquared.get().worldedit.getConfiguration().wandItem)) {
return;
}
}
@ -1121,7 +1126,7 @@ import java.util.regex.Pattern;
event.setCancelled(true);
}
break;
case LEGACY_MYCEL:
case MYCELIUM:
if (Flags.MYCEL_GROW.isFalse(plot)) {
event.setCancelled(true);
}
@ -1245,7 +1250,7 @@ import java.util.regex.Pattern;
event.setCancelled(true);
}
break;
case LEGACY_SOIL:
case FARMLAND:
if (Flags.SOIL_DRY.isFalse(plot)) {
event.setCancelled(true);
}
@ -1281,7 +1286,7 @@ import java.util.regex.Pattern;
}
}
} else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects
.equals(plot, area.getOwnedPlot(fLocation))) {
.equals(null, area.getOwnedPlot(fLocation))) {
event.setCancelled(true);
}
}
@ -1357,7 +1362,7 @@ import java.util.regex.Pattern;
this.pistonBlocks = false;
}
}
if (!this.pistonBlocks && block.getType() != Material.LEGACY_PISTON_BASE) {
if (!this.pistonBlocks && !block.getType().toString().contains("PISTON")) {
BlockFace dir = event.getDirection();
location = BukkitUtil.getLocation(block.getLocation()
.add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2));
@ -1398,7 +1403,7 @@ import java.util.regex.Pattern;
this.pistonBlocks = false;
}
}
if (!this.pistonBlocks && block.getType() != Material.LEGACY_PISTON_BASE) {
if (!this.pistonBlocks && !block.getType().toString().contains("PISTON")) {
location = BukkitUtil.getLocation(
block.getLocation().add(dir.getModX() * 2, dir.getModY() * 2, dir.getModZ() * 2));
if (!area.contains(location)) {
@ -1489,6 +1494,203 @@ import java.util.regex.Pattern;
}
}
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
if (!event.isLeftClick() || (event.getAction() != InventoryAction.PLACE_ALL) || event
.isShiftClick()) {
return;
}
HumanEntity entity = event.getWhoClicked();
if (!(entity instanceof Player) || !PlotSquared.get()
.hasPlotArea(entity.getWorld().getName())) {
return;
}
HumanEntity clicker = event.getWhoClicked();
if (!(clicker instanceof Player)) {
return;
}
Player player = (Player) clicker;
PlotPlayer pp = BukkitUtil.getPlayer(player);
PlotInventory inventory = pp.getMeta("inventory");
if (inventory != null && event.getRawSlot() == event.getSlot()) {
if (!inventory.onClick(event.getSlot())) {
event.setCancelled(true);
inventory.close();
}
}
PlayerInventory inv = player.getInventory();
int slot = inv.getHeldItemSlot();
if ((slot > 8) || !event.getEventName().equals("InventoryCreativeEvent")) {
return;
}
ItemStack current = inv.getItemInHand();
ItemStack newItem = event.getCursor();
ItemMeta newMeta = newItem.getItemMeta();
ItemMeta oldMeta = newItem.getItemMeta();
String newLore = "";
if (newMeta != null) {
List<String> lore = newMeta.getLore();
if (lore != null) {
newLore = lore.toString();
}
}
String oldLore = "";
if (oldMeta != null) {
List<String> lore = oldMeta.getLore();
if (lore != null) {
oldLore = lore.toString();
}
}
if (!"[(+NBT)]".equals(newLore) || (current.equals(newItem) && newLore.equals(oldLore))) {
switch (newItem.getType()) {
case LEGACY_BANNER:
case PLAYER_HEAD:
if (newMeta != null)
break;
default:
return;
}
}
Block block = player.getTargetBlock(null, 7);
BlockState state = block.getState();
if (state == null) {
return;
}
Material stateType = state.getType();
Material itemType = newItem.getType();
if (stateType != itemType) {
switch (stateType) {
case LEGACY_STANDING_BANNER:
case LEGACY_WALL_BANNER:
if (itemType == Material.LEGACY_BANNER)
break;
case LEGACY_SKULL:
if (itemType == Material.LEGACY_SKULL_ITEM)
break;
default:
return;
}
}
Location l = BukkitUtil.getLocation(state.getLocation());
PlotArea area = l.getPlotArea();
if (area == null) {
return;
}
Plot plot = area.getPlotAbs(l);
boolean cancelled = false;
if (plot == null) {
if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.road");
cancelled = true;
}
} else if (!plot.hasOwner()) {
if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.unowned");
cancelled = true;
}
} else {
UUID uuid = pp.getUUID();
if (!plot.isAdded(uuid)) {
if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.other");
cancelled = true;
}
}
}
if (cancelled) {
if ((current.getType() == newItem.getType()) && (current.getDurability() == newItem
.getDurability())) {
event.setCursor(
new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
event.setCancelled(true);
return;
}
event.setCursor(
new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPotionSplash(LingeringPotionSplashEvent event) {
LingeringPotion entity = event.getEntity();
Location l = BukkitUtil.getLocation(entity);
if (!PlotSquared.get().hasPlotArea(l.getWorld())) {
return;
}
if (!this.onProjectileHit(event)) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInteract(PlayerInteractAtEntityEvent e) {
Entity entity = e.getRightClicked();
if (!(entity instanceof ArmorStand)) {
return;
}
Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation());
PlotArea area = l.getPlotArea();
if (area == null) {
return;
}
EntitySpawnListener.test(entity);
Plot plot = area.getPlotAbs(l);
PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
if (plot == null) {
if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.road");
e.setCancelled(true);
}
} else if (!plot.hasOwner()) {
if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.unowned");
e.setCancelled(true);
}
} else {
UUID uuid = pp.getUUID();
if (!plot.isAdded(uuid)) {
if (Flags.MISC_INTERACT.isTrue(plot)) {
return;
}
if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.other");
e.setCancelled(true);
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBigBoom(BlockExplodeEvent event) {
Block block = event.getBlock();
Location location = BukkitUtil.getLocation(block.getLocation());
String world = location.getWorld();
if (!PlotSquared.get().hasPlotArea(world)) {
return;
}
PlotArea area = location.getPlotArea();
if (area == null) {
Iterator<Block> iterator = event.blockList().iterator();
while (iterator.hasNext()) {
location = BukkitUtil.getLocation(iterator.next().getLocation());
if (location.getPlotArea() != null) {
iterator.remove();
}
}
return;
}
Plot plot = area.getOwnedPlot(location);
if (plot == null || !plot.getFlag(Flags.EXPLOSION).or(false)) {
event.setCancelled(true);
}
event.blockList().removeIf(
b -> !plot.equals(area.getOwnedPlot(BukkitUtil.getLocation(b.getLocation()))));
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
@ -1513,7 +1715,8 @@ import java.util.regex.Pattern;
Block block = event.getClickedBlock();
location = BukkitUtil.getLocation(block.getLocation());
Material blockType = block.getType();
int blockId = blockType.getId();
int blockId = ((LegacyPlotBlock) PlotSquared.get().IMP.getLegacyMappings()
.fromStringToLegacy(blockType.name())).id;
switch (blockType) {
case ANVIL:
case ACACIA_DOOR:
@ -1522,38 +1725,89 @@ import java.util.regex.Pattern;
case IRON_DOOR:
case JUNGLE_DOOR:
case SPRUCE_DOOR:
case LEGACY_TRAP_DOOR:
case OAK_DOOR:
case ACACIA_TRAPDOOR:
case BIRCH_TRAPDOOR:
case DARK_OAK_TRAPDOOR:
case JUNGLE_TRAPDOOR:
case OAK_TRAPDOOR:
case SPRUCE_TRAPDOOR:
case IRON_TRAPDOOR:
case LEGACY_WOOD_DOOR:
case LEGACY_WOODEN_DOOR:
case TRAPPED_CHEST:
case ENDER_CHEST:
case CHEST:
case ACACIA_FENCE_GATE:
case BIRCH_FENCE_GATE:
case DARK_OAK_FENCE_GATE:
case LEGACY_FENCE_GATE:
case OAK_FENCE_GATE:
case JUNGLE_FENCE_GATE:
case SPRUCE_FENCE_GATE:
case LEVER:
case LEGACY_DIODE:
case LEGACY_DIODE_BLOCK_OFF:
case LEGACY_DIODE_BLOCK_ON:
case REDSTONE_TORCH:
case REDSTONE_WALL_TORCH:
case COMMAND_BLOCK:
case LEGACY_REDSTONE_COMPARATOR:
case LEGACY_REDSTONE_COMPARATOR_OFF:
case LEGACY_REDSTONE_COMPARATOR_ON:
case COMPARATOR:
case REDSTONE_ORE:
case LEGACY_WOOD_BUTTON:
case BIRCH_BUTTON:
case DARK_OAK_BUTTON:
case JUNGLE_BUTTON:
case ACACIA_BUTTON:
case OAK_BUTTON:
case SPRUCE_BUTTON:
case STONE_BUTTON:
case BEACON:
case LEGACY_BED_BLOCK:
case BLACK_BED:
case BLUE_BED:
case BROWN_BED:
case CYAN_BED:
case GRAY_BED:
case GREEN_BED:
case LIGHT_BLUE_BED:
case LIGHT_GRAY_BED:
case LIME_BED:
case MAGENTA_BED:
case ORANGE_BED:
case PINK_BED:
case PURPLE_BED:
case RED_BED:
case WHITE_BED:
case YELLOW_BED:
case SIGN:
case WALL_SIGN:
case LEGACY_ENCHANTMENT_TABLE:
case ENCHANTING_TABLE:
case BREWING_STAND:
case LEGACY_STANDING_BANNER:
case LEGACY_BURNING_FURNACE:
case BLACK_BANNER:
case BLACK_WALL_BANNER:
case BLUE_BANNER:
case BLUE_WALL_BANNER:
case BROWN_BANNER:
case BROWN_WALL_BANNER:
case CYAN_BANNER:
case CYAN_WALL_BANNER:
case GRAY_BANNER:
case GRAY_WALL_BANNER:
case GREEN_BANNER:
case GREEN_WALL_BANNER:
case LIGHT_BLUE_BANNER:
case LIGHT_BLUE_WALL_BANNER:
case LIGHT_GRAY_BANNER:
case LIGHT_GRAY_WALL_BANNER:
case LIME_BANNER:
case LIME_WALL_BANNER:
case MAGENTA_BANNER:
case MAGENTA_WALL_BANNER:
case ORANGE_BANNER:
case ORANGE_WALL_BANNER:
case PINK_BANNER:
case PINK_WALL_BANNER:
case PURPLE_BANNER:
case PURPLE_WALL_BANNER:
case RED_BANNER:
case RED_WALL_BANNER:
case WHITE_BANNER:
case WHITE_WALL_BANNER:
case YELLOW_BANNER:
case YELLOW_WALL_BANNER:
case FURNACE:
case CAKE:
case DISPENSER:
@ -1562,7 +1816,7 @@ import java.util.regex.Pattern;
case NOTE_BLOCK:
case JUKEBOX:
case CRAFTING_TABLE:
case LEGACY_SILVER_SHULKER_BOX:
case LIGHT_GRAY_SHULKER_BOX:
case BLACK_SHULKER_BOX:
case BLUE_SHULKER_BOX:
case RED_SHULKER_BOX:
@ -1578,8 +1832,8 @@ import java.util.regex.Pattern;
case LIME_SHULKER_BOX:
case LIGHT_BLUE_SHULKER_BOX:
case MAGENTA_SHULKER_BOX:
case LEGACY_COMMAND_REPEATING:
case LEGACY_COMMAND_CHAIN:
case CHAIN_COMMAND_BLOCK:
case REPEATING_COMMAND_BLOCK:
eventType = PlayerBlockEventType.INTERACT_BLOCK;
break;
@ -1593,18 +1847,17 @@ import java.util.regex.Pattern;
break;
}
lb = new BukkitLazyBlock(PlotBlock.get(block.getType().toString()));
ItemStack hand = player.getItemInHand();
ItemStack hand = player.getInventory().getItemInMainHand();
if (eventType != null && (eventType != PlayerBlockEventType.INTERACT_BLOCK
|| !player.isSneaking())) {
break;
}
Material type = (hand == null) ? null : hand.getType();
int id = (type == null) ? 0 : type.getId();
if (type == Material.AIR) {
eventType = PlayerBlockEventType.INTERACT_BLOCK;
break;
}
if (id < 198) {
if (type == null || type.isBlock()) {
location = BukkitUtil
.getLocation(block.getRelative(event.getBlockFace()).getLocation());
eventType = PlayerBlockEventType.PLACE_BLOCK;
@ -1612,63 +1865,81 @@ import java.util.regex.Pattern;
}
Material handType = hand.getType();
lb = new BukkitLazyBlock(PlotBlock.get(handType.toString()));
switch (handType) {
case LEGACY_FIREWORK:
case LEGACY_MONSTER_EGG:
case LEGACY_MONSTER_EGGS:
eventType = PlayerBlockEventType.SPAWN_MOB;
break;
case ARMOR_STAND:
location = BukkitUtil
.getLocation(block.getRelative(event.getBlockFace()).getLocation());
eventType = PlayerBlockEventType.PLACE_MISC;
break;
case WRITTEN_BOOK:
case LEGACY_BOOK_AND_QUILL:
case BOOK:
eventType = PlayerBlockEventType.READ;
break;
case APPLE:
case BAKED_POTATO:
case LEGACY_MUSHROOM_SOUP:
case BREAD:
case CARROT:
case LEGACY_CARROT_ITEM:
case COOKIE:
case LEGACY_GRILLED_PORK:
case POISONOUS_POTATO:
case MUTTON:
case LEGACY_PORK:
case POTATO:
case LEGACY_POTATO_ITEM:
case POTION:
case PUMPKIN_PIE:
case RABBIT:
case RABBIT_FOOT:
case RABBIT_STEW:
case LEGACY_RAW_BEEF:
case LEGACY_RAW_FISH:
case LEGACY_RAW_CHICKEN:
eventType = PlayerBlockEventType.EAT;
break;
case MINECART:
case LEGACY_STORAGE_MINECART:
case LEGACY_POWERED_MINECART:
case HOPPER_MINECART:
case LEGACY_EXPLOSIVE_MINECART:
case LEGACY_COMMAND_MINECART:
case LEGACY_BOAT:
eventType = PlayerBlockEventType.PLACE_VEHICLE;
break;
case PAINTING:
case ITEM_FRAME:
location = BukkitUtil
.getLocation(block.getRelative(event.getBlockFace()).getLocation());
eventType = PlayerBlockEventType.PLACE_HANGING;
break;
default:
eventType = PlayerBlockEventType.INTERACT_BLOCK;
break;
if (handType.toString().endsWith("egg")) {
eventType = PlayerBlockEventType.SPAWN_MOB;
} else {
switch (handType) {
case FIREWORK_ROCKET:
case FIREWORK_STAR:
eventType = PlayerBlockEventType.SPAWN_MOB;
break;
case ARMOR_STAND:
location = BukkitUtil
.getLocation(block.getRelative(event.getBlockFace()).getLocation());
eventType = PlayerBlockEventType.PLACE_MISC;
break;
case WRITTEN_BOOK:
case WRITABLE_BOOK:
case ENCHANTED_BOOK:
case KNOWLEDGE_BOOK:
case BOOK:
eventType = PlayerBlockEventType.READ;
break;
case APPLE:
case BAKED_POTATO:
case MUSHROOM_STEW:
case BREAD:
case CARROT:
case GOLDEN_CARROT:
case COOKIE:
case PORKCHOP:
case POISONOUS_POTATO:
case MUTTON:
case COOKED_PORKCHOP:
case POTATO:
case POTION:
case PUMPKIN_PIE:
case RABBIT:
case RABBIT_FOOT:
case RABBIT_STEW:
case BEEF:
case COOKED_BEEF:
case TROPICAL_FISH:
case PUFFERFISH:
case CHICKEN:
case COOKED_CHICKEN:
case COOKED_MUTTON:
case COOKED_RABBIT:
case COOKED_SALMON:
case SALMON:
case COD:
case COOKED_COD:
eventType = PlayerBlockEventType.EAT;
break;
case MINECART:
case CHEST_MINECART:
case FURNACE_MINECART:
case HOPPER_MINECART:
case TNT_MINECART:
case COMMAND_BLOCK_MINECART:
case BIRCH_BOAT:
case ACACIA_BOAT:
case DARK_OAK_BOAT:
case JUNGLE_BOAT:
case OAK_BOAT:
case SPRUCE_BOAT:
eventType = PlayerBlockEventType.PLACE_VEHICLE;
break;
case PAINTING:
case ITEM_FRAME:
location = BukkitUtil
.getLocation(block.getRelative(event.getBlockFace()).getLocation());
eventType = PlayerBlockEventType.PLACE_HANGING;
break;
default:
eventType = PlayerBlockEventType.INTERACT_BLOCK;
break;
}
}
break;
}
@ -1682,12 +1953,9 @@ import java.util.regex.Pattern;
return;
}
if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
if (player.getInventory().getItemInMainHand().getType() == BukkitUtil.getBukkitLegacyMappings()
.fromLegacyToString(PlotSquared.get().worldedit.getConfiguration().wandItem)
.to(Material.class)) {
return;
}
if (player.getInventory().getItemInMainHand().getType() == Material
.getMaterial(PlotSquared.get().worldedit.getConfiguration().wandItem)) {
return;
}
}
if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, location, lb, true)) {
@ -1723,7 +1991,7 @@ import java.util.regex.Pattern;
case BUILD_WITHER:
case BUILD_SNOWMAN:
case CUSTOM:
if (!area.SPAWN_CUSTOM && entity.getType().getTypeId() != 30) {
if (!area.SPAWN_CUSTOM && entity.getType() != EntityType.ARMOR_STAND) {
event.setCancelled(true);
return;
}
@ -1935,23 +2203,6 @@ import java.util.regex.Pattern;
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryClick(InventoryClickEvent event) {
HumanEntity clicker = event.getWhoClicked();
if (!(clicker instanceof Player)) {
return;
}
Player player = (Player) clicker;
PlotPlayer pp = BukkitUtil.getPlayer(player);
PlotInventory inventory = pp.getMeta("inventory");
if (inventory != null && event.getRawSlot() == event.getSlot()) {
if (!inventory.onClick(event.getSlot())) {
event.setCancelled(true);
inventory.close();
}
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryClose(InventoryCloseEvent event) {
HumanEntity closer = event.getPlayer();
@ -2255,24 +2506,8 @@ import java.util.regex.Pattern;
@SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.HIGHEST)
public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
EntityDamageByEntityEvent eventChange = null;
if (PlotSquared.get()
.checkVersion(PlotSquared.get().IMP.getServerVersion(), BukkitVersion.v1_11_0)) {
eventChange = new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(),
EntityDamageEvent.DamageCause.FIRE_TICK, (double) event.getDuration());
} else {
try {
Constructor<EntityDamageByEntityEvent> constructor = EntityDamageByEntityEvent.class
.getConstructor(Entity.class, Entity.class, EntityDamageEvent.DamageCause.class,
Integer.TYPE);
eventChange = constructor.newInstance(event.getCombuster(), event.getEntity(),
EntityDamageEvent.DamageCause.FIRE_TICK, event.getDuration());
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
e.printStackTrace();
}
}
if (eventChange == null) {
return;
}
eventChange = new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(),
EntityDamageEvent.DamageCause.FIRE_TICK, (double) event.getDuration());
onEntityDamageByEntityEvent(eventChange);
if (eventChange.isCancelled()) {
event.setCancelled(true);
@ -2454,8 +2689,8 @@ import java.util.regex.Pattern;
}
}
return true;
} else if (dplot != null && (!(dplot.equals(vplot)) || (vplot != null && Objects
.equals(dplot.owner, vplot.owner)))) {
} else if (dplot != null && (!dplot.equals(vplot) || Objects
.equals(dplot.guessOwner(), vplot.guessOwner()))) {
return vplot != null && Flags.PVE.isTrue(vplot);
}
return ((vplot != null && Flags.PVE.isTrue(vplot)) || !(damager instanceof Arrow
@ -2540,7 +2775,7 @@ import java.util.regex.Pattern;
if (plot.getFlag(Flags.DISABLE_PHYSICS, false)) {
Block block = event.getBlockPlaced();
if (block.getType().hasGravity()) {
sendBlockChange(block.getLocation(), block.getType(), block.getData());
sendBlockChange(block.getLocation(), block.getBlockData());
}
}
} else if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) {

View File

@ -1,45 +0,0 @@
package com.github.intellectualsites.plotsquared.bukkit.listeners;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockExplodeEvent;
import java.util.Iterator;
@SuppressWarnings("unused") public class PlayerEvents183 implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBigBoom(BlockExplodeEvent event) {
Block block = event.getBlock();
Location location = BukkitUtil.getLocation(block.getLocation());
String world = location.getWorld();
if (!PlotSquared.get().hasPlotArea(world)) {
return;
}
PlotArea area = location.getPlotArea();
if (area == null) {
Iterator<Block> iterator = event.blockList().iterator();
while (iterator.hasNext()) {
location = BukkitUtil.getLocation(iterator.next().getLocation());
if (location.getPlotArea() != null) {
iterator.remove();
}
}
return;
}
Plot plot = area.getOwnedPlot(location);
if (plot == null || !plot.getFlag(Flags.EXPLOSION).or(false)) {
event.setCancelled(true);
}
event.blockList().removeIf(
b -> !plot.equals(area.getOwnedPlot(BukkitUtil.getLocation(b.getLocation()))));
}
}

View File

@ -1,184 +0,0 @@
package com.github.intellectualsites.plotsquared.bukkit.listeners;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.C;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.listener.PlotListener;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.Permissions;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
@SuppressWarnings("unused") public class PlayerEvents_1_8 extends PlotListener implements Listener {
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
if (!event.isLeftClick() || (event.getAction() != InventoryAction.PLACE_ALL) || event
.isShiftClick()) {
return;
}
HumanEntity entity = event.getWhoClicked();
if (!(entity instanceof Player) || !PlotSquared.get()
.hasPlotArea(entity.getWorld().getName())) {
return;
}
Player player = (Player) entity;
PlayerInventory inv = player.getInventory();
int slot = inv.getHeldItemSlot();
if ((slot > 8) || !event.getEventName().equals("InventoryCreativeEvent")) {
return;
}
ItemStack current = inv.getItemInHand();
ItemStack newItem = event.getCursor();
ItemMeta newMeta = newItem.getItemMeta();
ItemMeta oldMeta = newItem.getItemMeta();
String newLore = "";
if (newMeta != null) {
List<String> lore = newMeta.getLore();
if (lore != null) {
newLore = lore.toString();
}
}
String oldLore = "";
if (oldMeta != null) {
List<String> lore = oldMeta.getLore();
if (lore != null) {
oldLore = lore.toString();
}
}
if (!"[(+NBT)]".equals(newLore) || (current.equals(newItem) && newLore.equals(oldLore))) {
switch (newItem.getType()) {
case LEGACY_BANNER:
case PLAYER_HEAD:
if (newMeta != null)
break;
default:
return;
}
}
HashSet<Material> blocks = null;
Block block = player.getTargetBlock(blocks, 7);
BlockState state = block.getState();
if (state == null) {
return;
}
Material stateType = state.getType();
Material itemType = newItem.getType();
if (stateType != itemType) {
switch (stateType) {
case LEGACY_STANDING_BANNER:
case LEGACY_WALL_BANNER:
if (itemType == Material.LEGACY_BANNER)
break;
case LEGACY_SKULL:
if (itemType == Material.LEGACY_SKULL_ITEM)
break;
default:
return;
}
}
Location l = BukkitUtil.getLocation(state.getLocation());
PlotArea area = l.getPlotArea();
if (area == null) {
return;
}
Plot plot = area.getPlotAbs(l);
PlotPlayer pp = BukkitUtil.getPlayer(player);
boolean cancelled = false;
if (plot == null) {
if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.road");
cancelled = true;
}
} else if (!plot.hasOwner()) {
if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.unowned");
cancelled = true;
}
} else {
UUID uuid = pp.getUUID();
if (!plot.isAdded(uuid)) {
if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.other");
cancelled = true;
}
}
}
if (cancelled) {
if ((current.getType() == newItem.getType()) && (current.getDurability() == newItem
.getDurability())) {
event.setCursor(
new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
event.setCancelled(true);
return;
}
event.setCursor(
new ItemStack(newItem.getType(), newItem.getAmount(), newItem.getDurability()));
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInteract(PlayerInteractAtEntityEvent e) {
Entity entity = e.getRightClicked();
if (!(entity instanceof ArmorStand)) {
return;
}
Location l = BukkitUtil.getLocation(e.getRightClicked().getLocation());
PlotArea area = l.getPlotArea();
if (area == null) {
return;
}
EntityPortal_1_7_9.test(entity);
Plot plot = area.getPlotAbs(l);
PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
if (plot == null) {
if (!Permissions.hasPermission(pp, "plots.admin.interact.road")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.road");
e.setCancelled(true);
}
} else if (!plot.hasOwner()) {
if (!Permissions.hasPermission(pp, "plots.admin.interact.unowned")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.unowned");
e.setCancelled(true);
}
} else {
UUID uuid = pp.getUUID();
if (!plot.isAdded(uuid)) {
if (Flags.MISC_INTERACT.isTrue(plot)) {
return;
}
if (!Permissions.hasPermission(pp, "plots.admin.interact.other")) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, "plots.admin.interact.other");
e.setCancelled(true);
}
}
}
}
}

View File

@ -1,31 +0,0 @@
package com.github.intellectualsites.plotsquared.bukkit.listeners;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import org.bukkit.entity.LingeringPotion;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.LingeringPotionSplashEvent;
@SuppressWarnings("unused") public class PlayerEvents_1_9 implements Listener {
private final PlayerEvents parent;
public PlayerEvents_1_9(PlayerEvents parent) {
this.parent = parent;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPotionSplash(LingeringPotionSplashEvent event) {
LingeringPotion entity = event.getEntity();
Location l = BukkitUtil.getLocation(entity);
if (!PlotSquared.get().hasPlotArea(l.getWorld())) {
return;
}
if (!parent.onProjectileHit(event)) {
event.setCancelled(true);
}
}
}

View File

@ -12,6 +12,7 @@ import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -19,6 +20,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
@ -30,16 +32,16 @@ import java.util.UUID;
@SuppressWarnings("unused") public class PlotPlusListener extends PlotListener implements Listener {
private static final HashMap<String, Interval> feedRunnable = new HashMap<>();
private static final HashMap<String, Interval> healRunnable = new HashMap<>();
private static final HashMap<UUID, Interval> feedRunnable = new HashMap<>();
private static final HashMap<UUID, Interval> healRunnable = new HashMap<>();
public static void startRunnable(JavaPlugin plugin) {
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
@Override public void run() {
if (!healRunnable.isEmpty()) {
for (Iterator<Entry<String, Interval>> iterator =
for (Iterator<Entry<UUID, Interval>> iterator =
healRunnable.entrySet().iterator(); iterator.hasNext(); ) {
Entry<String, Interval> entry = iterator.next();
Entry<UUID, Interval> entry = iterator.next();
Interval value = entry.getValue();
++value.count;
if (value.count == value.interval) {
@ -57,9 +59,9 @@ import java.util.UUID;
}
}
if (!feedRunnable.isEmpty()) {
for (Iterator<Entry<String, Interval>> iterator =
for (Iterator<Entry<UUID, Interval>> iterator =
feedRunnable.entrySet().iterator(); iterator.hasNext(); ) {
Entry<String, Interval> entry = iterator.next();
Entry<UUID, Interval> entry = iterator.next();
Interval value = entry.getValue();
++value.count;
if (value.count == value.interval) {
@ -134,20 +136,19 @@ import java.util.UUID;
Optional<Integer[]> feed = plot.getFlag(Flags.FEED);
if (feed.isPresent()) {
Integer[] value = feed.get();
feedRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
feedRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20));
}
Optional<Integer[]> heal = plot.getFlag(Flags.HEAL);
if (heal.isPresent()) {
Integer[] value = heal.get();
healRunnable.put(player.getName(), new Interval(value[0], value[1], 20));
healRunnable.put(player.getUniqueId(), new Interval(value[0], value[1], 20));
}
}
@EventHandler public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
String name = player.getName();
feedRunnable.remove(name);
healRunnable.remove(name);
feedRunnable.remove(player.getUniqueId());
healRunnable.remove(player.getUniqueId());
}
@EventHandler public void onPlotLeave(PlayerLeavePlotEvent event) {
@ -157,9 +158,24 @@ import java.util.UUID;
return;
}
BukkitUtil.getPlayer(leaver);
String name = leaver.getName();
feedRunnable.remove(name);
healRunnable.remove(name);
feedRunnable.remove(leaver.getUniqueId());
healRunnable.remove(leaver.getUniqueId());
}
@EventHandler public void onItemPickup(EntityPickupItemEvent event) {
LivingEntity ent = event.getEntity();
if (ent instanceof Player) {
Player player = (Player) ent;
PlotPlayer pp = BukkitUtil.getPlayer(player);
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
if (plot == null) {
return;
}
UUID uuid = pp.getUUID();
if (!plot.isAdded(uuid) && Flags.DROP_PROTECTION.isTrue(plot)) {
event.setCancelled(true);
}
}
}
private static class Interval {

View File

@ -1,32 +0,0 @@
package com.github.intellectualsites.plotsquared.bukkit.listeners;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityPickupItemEvent;
import java.util.UUID;
@SuppressWarnings("unused") public class PlotPlusListener_1_12 implements Listener {
@EventHandler public void onItemPickup(EntityPickupItemEvent event) {
LivingEntity ent = event.getEntity();
if (ent instanceof Player) {
Player player = (Player) ent;
PlotPlayer pp = BukkitUtil.getPlayer(player);
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
if (plot == null) {
return;
}
UUID uuid = pp.getUUID();
if (!plot.isAdded(uuid) && Flags.DROP_PROTECTION.isTrue(plot)) {
event.setCancelled(true);
}
}
}
}

View File

@ -1,28 +0,0 @@
package com.github.intellectualsites.plotsquared.bukkit.listeners;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerPickupItemEvent;
import java.util.UUID;
@SuppressWarnings("unused") public class PlotPlusListener_Legacy implements Listener {
@EventHandler public void onItemPickup(PlayerPickupItemEvent event) {
Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player);
Plot plot = BukkitUtil.getLocation(player).getOwnedPlot();
if (plot == null) {
return;
}
UUID uuid = pp.getUUID();
if (!plot.isAdded(uuid) && Flags.DROP_PROTECTION.isTrue(plot)) {
event.setCancelled(true);
}
}
}

View File

@ -1,6 +1,5 @@
package com.github.intellectualsites.plotsquared.bukkit.object.entity;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitVersion;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import org.bukkit.*;
import org.bukkit.block.BlockFace;
@ -53,21 +52,15 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
if (depth == 1) {
return;
}
if (PlotSquared.get()
.checkVersion(PlotSquared.get().IMP.getServerVersion(), BukkitVersion.v1_10_0)
|| entity instanceof ArmorStand) {
if (!entity.hasGravity()) {
this.noGravity = true;
}
if (!entity.hasGravity()) {
this.noGravity = true;
}
switch (entity.getType()) {
case ARROW:
case BOAT:
if (PlotSquared.get()
.checkVersion(PlotSquared.get().IMP.getServerVersion(), BukkitVersion.v1_9_0)) {
Boat boat = (Boat) entity;
this.dataByte = getOrdinal(TreeSpecies.values(), boat.getWoodType());
}
Boat boat = (Boat) entity;
this.dataByte = getOrdinal(TreeSpecies.values(), boat.getWoodType());
return;
case ARROW:
case COMPLEX_PART:
case EGG:
case ENDER_CRYSTAL:
@ -103,9 +96,6 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
case AREA_EFFECT_CLOUD:
// Do this stuff later
return;
default:
PlotSquared.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
return;
// MISC //
case DROPPED_ITEM:
Item item = (Item) entity;
@ -284,6 +274,8 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
}
storeLiving((LivingEntity) entity);
// END LIVING //
default:
PlotSquared.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
}
}
@ -324,13 +316,8 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
void restoreEquipment(LivingEntity entity) {
EntityEquipment equipment = entity.getEquipment();
if (PlotSquared.get()
.checkVersion(PlotSquared.get().IMP.getServerVersion(), BukkitVersion.v1_9_0)) {
equipment.setItemInMainHand(this.lived.mainHand);
equipment.setItemInOffHand(this.lived.offHand);
} else {
equipment.setItemInHand(this.lived.mainHand);
}
equipment.setItemInMainHand(this.lived.mainHand);
equipment.setItemInOffHand(this.lived.offHand);
equipment.setHelmet(this.lived.helmet);
equipment.setChestplate(this.lived.chestplate);
equipment.setLeggings(this.lived.leggings);
@ -369,14 +356,8 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
}
void storeEquipment(EntityEquipment equipment) {
if (PlotSquared.get()
.checkVersion(PlotSquared.get().IMP.getServerVersion(), BukkitVersion.v1_9_0)) {
this.lived.mainHand = equipment.getItemInMainHand().clone();
this.lived.offHand = equipment.getItemInOffHand().clone();
} else {
this.lived.mainHand = equipment.getItemInHand().clone();
this.lived.offHand = null;
}
this.lived.mainHand = equipment.getItemInMainHand().clone();
this.lived.offHand = equipment.getItemInOffHand().clone();
this.lived.boots = equipment.getBoots().clone();
this.lived.leggings = equipment.getLeggings().clone();
this.lived.chestplate = equipment.getChestplate().clone();
@ -461,22 +442,18 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
if (this.depth == 1) {
return entity;
}
if (PlotSquared.get()
.checkVersion(PlotSquared.get().IMP.getServerVersion(), BukkitVersion.v1_10_0)
|| entity instanceof ArmorStand) {
if (this.noGravity) {
entity.setGravity(false);
}
if (this.noGravity) {
entity.setGravity(false);
}
switch (entity.getType()) {
case ARROW:
case BOAT:
if (PlotSquared.get()
.checkVersion(PlotSquared.get().IMP.getServerVersion(), BukkitVersion.v1_9_0)) {
Boat boat = (Boat) entity;
boat.setWoodType(TreeSpecies.values()[dataByte]);
}
Boat boat = (Boat) entity;
boat.setWoodType(TreeSpecies.values()[dataByte]);
return entity;
case SLIME:
((Slime) entity).setSize(this.dataByte);
return entity;
case ARROW:
case COMPLEX_PART:
case EGG:
case ENDER_CRYSTAL:
@ -496,10 +473,6 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
case MINECART_TNT:
case PLAYER:
case PRIMED_TNT:
return entity;
case SLIME:
((Slime) entity).setSize(this.dataByte);
return entity;
case SMALL_FIREBALL:
case SNOWBALL:
case SPLASH_POTION:
@ -516,9 +489,6 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
case UNKNOWN:
// Do this stuff later
return entity;
default:
PlotSquared.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
return entity;
// MISC //
case ITEM_FRAME:
ItemFrame itemframe = (ItemFrame) entity;
@ -703,6 +673,9 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
}
restoreLiving((LivingEntity) entity);
return entity;
default:
PlotSquared.debug("&cCOULD NOT IDENTIFY ENTITY: " + entity.getType());
return entity;
// END LIVING
}
}

View File

@ -1,73 +0,0 @@
package com.github.intellectualsites.plotsquared.bukkit.titles;
import com.github.intellectualsites.plotsquared.bukkit.chat.Reflection;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.lang.reflect.Method;
public class DefaultTitleManager_183 extends DefaultTitleManager {
/**
* Create a new 1.8 title.
*
* @param title Title text
* @param subtitle Subtitle text
* @param fadeInTime Fade in time
* @param stayTime Stay on screen time
* @param fadeOutTime Fade out time
*/
DefaultTitleManager_183(String title, String subtitle, int fadeInTime, int stayTime,
int fadeOutTime) {
super(title, subtitle, fadeInTime, stayTime, fadeOutTime);
}
/**
* Load spigot and NMS classes.
*/
@Override void loadClasses() {
this.packetTitle = Reflection.getNMSClass("PacketPlayOutTitle");
this.chatBaseComponent = Reflection.getNMSClass("IChatBaseComponent");
this.packetActions = Reflection.getNMSClass("PacketPlayOutTitle$EnumTitleAction");
this.nmsChatSerializer = Reflection.getNMSClass("IChatBaseComponent$ChatSerializer");
}
@Override public void send(Player player)
throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
if (this.packetTitle != null) {
// First reset previous settings
resetTitle(player);
// Send timings first
Object handle = getHandle(player);
Object connection = getField(handle.getClass(), "playerConnection").get(handle);
Object[] actions = this.packetActions.getEnumConstants();
Method sendPacket = getMethod(connection.getClass(), "sendPacket");
Object packet = this.packetTitle
.getConstructor(this.packetActions, this.chatBaseComponent, Integer.TYPE,
Integer.TYPE, Integer.TYPE)
.newInstance(actions[2], null, this.fadeInTime * (this.ticks ? 1 : 20),
this.stayTime * (this.ticks ? 1 : 20),
this.fadeOutTime * (this.ticks ? 1 : 20));
// Send if set
if ((this.fadeInTime != -1) && (this.fadeOutTime != -1) && (this.stayTime != -1)) {
sendPacket.invoke(connection, packet);
}
// Send title
Object serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getTitle())
+ "\",color:" + this.titleColor.name().toLowerCase() + "}");
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent)
.newInstance(actions[0], serialized);
sendPacket.invoke(connection, packet);
if (!this.getSubtitle().isEmpty()) {
// Send subtitle if present
serialized = getMethod(this.nmsChatSerializer, "a", String.class).invoke(null,
"{text:\"" + ChatColor.translateAlternateColorCodes('&', this.getSubtitle())
+ "\",color:" + this.subtitleColor.name().toLowerCase() + "}");
packet = this.packetTitle.getConstructor(this.packetActions, this.chatBaseComponent)
.newInstance(actions[1], serialized);
sendPacket.invoke(connection, packet);
}
}
}
}

View File

@ -1,33 +1,20 @@
package com.github.intellectualsites.plotsquared.bukkit.titles;
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitVersion;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.AbstractTitle;
import org.bukkit.entity.Player;
@SuppressWarnings("deprecation") public class DefaultTitle_111 extends AbstractTitle {
private final boolean valid;
public DefaultTitle_111() {
this.valid = PlotSquared.get()
.checkVersion(PlotSquared.get().IMP.getServerVersion(), BukkitVersion.v1_11_0);
}
@Override
public void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out) {
if (valid) {
try {
final Player playerObj = ((BukkitPlayer) player).player;
TitleManager_1_11 title = new TitleManager_1_11(head, sub, in, delay, out);
title.send(playerObj);
return;
} catch (Throwable ignored) {
}
try {
final Player playerObj = ((BukkitPlayer) player).player;
TitleManager_1_11 title = new TitleManager_1_11(head, sub, in, delay, out);
title.send(playerObj);
return;
} catch (Throwable ignored) {
}
AbstractTitle.TITLE_CLASS = new DefaultTitle_180();
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out);
}
}

View File

@ -1,19 +0,0 @@
package com.github.intellectualsites.plotsquared.bukkit.titles;
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.AbstractTitle;
public class DefaultTitle_180 extends AbstractTitle {
@Override
public void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out) {
try {
DefaultTitleManager title = new DefaultTitleManager(head, sub, in, delay, out);
title.send(((BukkitPlayer) player).player);
} catch (Exception ignored) {
AbstractTitle.TITLE_CLASS = new DefaultTitle_19();
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out);
}
}
}

View File

@ -1,19 +0,0 @@
package com.github.intellectualsites.plotsquared.bukkit.titles;
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.AbstractTitle;
public class DefaultTitle_183 extends AbstractTitle {
@Override
public void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out) {
try {
DefaultTitleManager_183 title = new DefaultTitleManager_183(head, sub, in, delay, out);
title.send(((BukkitPlayer) player).player);
} catch (Exception ignored) {
AbstractTitle.TITLE_CLASS = new HackTitle();
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out);
}
}
}

View File

@ -1,26 +0,0 @@
package com.github.intellectualsites.plotsquared.bukkit.titles;
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.AbstractTitle;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
import org.bukkit.entity.Player;
@SuppressWarnings("deprecation") public class DefaultTitle_19 extends AbstractTitle {
@Override
public void sendTitle(PlotPlayer player, String head, String sub, int in, int delay, int out) {
try {
final Player playerObj = ((BukkitPlayer) player).player;
playerObj.sendTitle(head, sub);
TaskManager.runTaskLater(new Runnable() {
@Override public void run() {
playerObj.sendTitle("", "");
}
}, delay * 20);
} catch (Throwable ignored) {
AbstractTitle.TITLE_CLASS = new DefaultTitle_183();
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, in, delay, out);
}
}
}

View File

@ -1,17 +1,7 @@
package com.github.intellectualsites.plotsquared.bukkit.util;
public class BukkitVersion {
public static int[] v1_13_2 = {1, 13, 2};
public static int[] v1_13_1 = {1, 13, 1};
public static int[] v1_13_0 = {1, 13, 0};
public static int[] v1_12_1 = {1, 12, 1};
public static int[] v1_12_0 = {1, 12, 0};
public static int[] v1_11_0 = {1, 11, 0};
public static int[] v1_10_2 = {1, 10, 2};
public static int[] v1_10_0 = {1, 10, 0};
public static int[] v1_9_4 = {1, 9, 4};
public static int[] v1_9_0 = {1, 9, 0};
public static int[] v1_8_3 = {1, 8, 3};
public static int[] v1_8_0 = {1, 8, 0};
public static int[] v1_7_6 = {1, 7, 6};
public static int[] v1_7_0 = {1, 7, 0};
public static int[] v1_6_0 = {1, 6, 0};
}

View File

@ -50,19 +50,7 @@ public class SendChunk {
RefClass classChunk = getRefClass("{nms}.Chunk");
this.methodInitLighting = classChunk.getMethod("initLighting");
RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
if (PlotSquared.get()
.checkVersion(PlotSquared.get().IMP.getServerVersion(), BukkitVersion.v1_9_4)) {
//this works for 1.9.4 and 1.10
tempMapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), int.class);
} else {
try {
tempMapChunk = classMapChunk
.getConstructor(classChunk.getRealClass(), boolean.class, int.class);
} catch (NoSuchMethodException ignored) {
tempMapChunk = classMapChunk
.getConstructor(classChunk.getRealClass(), boolean.class, int.class, int.class);
}
}
tempMapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), int.class);
this.mapChunk = tempMapChunk;
RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
this.connection = classEntityPlayer.getField("playerConnection");
@ -119,22 +107,9 @@ public class SendChunk {
chunks.remove(chunk);
Object con = this.connection.of(entity).get();
Object packet = null;
if (PlotSquared.get()
.checkVersion(PlotSquared.get().IMP.getServerVersion(), BukkitVersion.v1_9_4)) {
try {
packet = this.mapChunk.create(c, 65535);
} catch (Exception ignored) {
}
} else {
try {
packet = this.mapChunk.create(c, true, 65535);
} catch (ReflectiveOperationException | IllegalArgumentException e) {
try {
packet = this.mapChunk.create(c, true, 65535, 5);
} catch (ReflectiveOperationException | IllegalArgumentException e1) {
e1.printStackTrace();
}
}
try {
packet = this.mapChunk.create(c, 65535);
} catch (Exception ignored) {
}
if (packet == null) {
PlotSquared.debug("Error with PacketPlayOutMapChunk reflection.");