mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 22:56:45 +01:00
Fixes #2245
Also some minor fixes to PlayerInteractEvent main/off hand logic
This commit is contained in:
parent
ed10877431
commit
aa894b8ad9
@ -10,12 +10,10 @@ import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
|||||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||||
import com.github.intellectualsites.plotsquared.plot.listener.PlayerBlockEventType;
|
import com.github.intellectualsites.plotsquared.plot.listener.PlayerBlockEventType;
|
||||||
import com.github.intellectualsites.plotsquared.plot.listener.PlotListener;
|
import com.github.intellectualsites.plotsquared.plot.listener.PlotListener;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.*;
|
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.*;
|
import com.github.intellectualsites.plotsquared.plot.util.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.*;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
@ -909,7 +907,7 @@ import java.util.regex.Pattern;
|
|||||||
if (!spies.isEmpty()) {
|
if (!spies.isEmpty()) {
|
||||||
String spyMessage =
|
String spyMessage =
|
||||||
Captions.PLOT_CHAT_SPY_FORMAT.s().replace("%plot_id%", id.x + ";" + id.y)
|
Captions.PLOT_CHAT_SPY_FORMAT.s().replace("%plot_id%", id.x + ";" + id.y)
|
||||||
.replace("%sender%", sender).replace("%msg%", message);
|
.replace("%sender%", sender).replace("%msg%", message);
|
||||||
for (Player player : spies) {
|
for (Player player : spies) {
|
||||||
player.sendMessage(spyMessage);
|
player.sendMessage(spyMessage);
|
||||||
}
|
}
|
||||||
@ -1734,7 +1732,32 @@ import java.util.regex.Pattern;
|
|||||||
blox -> !plot.equals(area.getOwnedPlot(BukkitUtil.getLocation(blox.getLocation()))));
|
blox -> !plot.equals(area.getOwnedPlot(BukkitUtil.getLocation(blox.getLocation()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
|
public void onCancelledInteract(PlayerInteractEvent event) {
|
||||||
|
if (event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||||
|
PlotArea area = pp.getPlotAreaAbs();
|
||||||
|
if (area == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Material type = player.getInventory().getItemInMainHand().getType();
|
||||||
|
if (type.toString().toLowerCase().endsWith("egg")) {
|
||||||
|
Block block = player.getTargetBlockExact(5, FluidCollisionMode.SOURCE_ONLY);
|
||||||
|
if (block != null && block.getType() != Material.AIR) {
|
||||||
|
Location location = BukkitUtil.getLocation(block.getLocation());
|
||||||
|
if (!EventUtil.manager
|
||||||
|
.checkPlayerBlockEvent(pp, PlayerBlockEventType.SPAWN_MOB, location,
|
||||||
|
new BukkitLazyBlock(PlotBlock.get(type.toString())), true)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
event.setUseItemInHand(Event.Result.DENY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = false)
|
||||||
public void onInteract(PlayerInteractEvent event) {
|
public void onInteract(PlayerInteractEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||||
@ -1907,25 +1930,25 @@ import java.util.regex.Pattern;
|
|||||||
}
|
}
|
||||||
ItemStack hand = player.getInventory().getItemInMainHand();
|
ItemStack hand = player.getInventory().getItemInMainHand();
|
||||||
ItemStack offHand = player.getInventory().getItemInOffHand();
|
ItemStack offHand = player.getInventory().getItemInOffHand();
|
||||||
Material type = (hand == null) ? null : hand.getType();
|
Material type = (hand == null) ? Material.AIR : hand.getType();
|
||||||
Material offType = (offHand == null) ? null : offHand.getType();
|
Material offType = (offHand == null) ? Material.AIR : offHand.getType();
|
||||||
if ((type == Material.AIR && offType != Material.AIR && !player.isSneaking()
|
if ((type == Material.AIR && offType != Material.AIR && !player.isSneaking()
|
||||||
&& blockType.isInteractable()) || (type == Material.AIR
|
&& blockType.isInteractable()) || (type == Material.AIR
|
||||||
&& offType == Material.AIR)) {
|
&& offType == Material.AIR)) {
|
||||||
eventType = PlayerBlockEventType.INTERACT_BLOCK;
|
eventType = PlayerBlockEventType.INTERACT_BLOCK;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!(type != null && type.equals(offType))) {
|
if (type == Material.AIR) {
|
||||||
type = offType;
|
type = offType;
|
||||||
}
|
}
|
||||||
if (type == null || type.isBlock()) {
|
if (type.isBlock()) {
|
||||||
location = BukkitUtil
|
location = BukkitUtil
|
||||||
.getLocation(block.getRelative(event.getBlockFace()).getLocation());
|
.getLocation(block.getRelative(event.getBlockFace()).getLocation());
|
||||||
eventType = PlayerBlockEventType.PLACE_BLOCK;
|
eventType = PlayerBlockEventType.PLACE_BLOCK;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
lb = new BukkitLazyBlock(PlotBlock.get(type.toString()));
|
lb = new BukkitLazyBlock(PlotBlock.get(type.toString()));
|
||||||
if (type.toString().endsWith("egg")) {
|
if (type.toString().toLowerCase().endsWith("egg")) {
|
||||||
eventType = PlayerBlockEventType.SPAWN_MOB;
|
eventType = PlayerBlockEventType.SPAWN_MOB;
|
||||||
} else {
|
} else {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
Loading…
Reference in New Issue
Block a user