Use ray-tracing based target block for 1.13.2+ (#3763)

Uses new method of ray-tracing to target block instead of using BlockIterator which doesn't respect the player looking at a different y-level. Falls back to old BlockIterator method on server versions older than 1.13.2

Fixes #3756.
This commit is contained in:
Josh Roy 2020-11-09 11:38:02 -05:00 committed by GitHub
parent bb43e8f7b6
commit 5b0c2a4131
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import net.ess3.api.MaxMoneyException;
import net.ess3.api.events.AfkStatusChangeEvent;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import java.math.BigDecimal;
@ -207,4 +208,6 @@ public interface IUser {
void setLastMessageReplyRecipient(boolean enabled);
Map<User, BigDecimal> getConfirmingPayments();
Block getTargetBlock(int maxDistance);
}

View File

@ -17,6 +17,7 @@ import net.ess3.api.events.MuteStatusChangeEvent;
import net.ess3.api.events.UserBalanceUpdateEvent;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.ItemStack;
@ -1009,4 +1010,13 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
public void setLastHomeConfirmationTimestamp() {
this.lastHomeConfirmationTimestamp = System.currentTimeMillis();
}
@Override
public Block getTargetBlock(int maxDistance) {
final Block block;
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_13_2_R01) || (block = base.getTargetBlockExact(maxDistance)) == null) {
return base.getTargetBlock(null, maxDistance);
}
return block;
}
}

View File

@ -17,7 +17,7 @@ public class Commandbreak extends EssentialsCommand {
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
final Block block = user.getBase().getTargetBlock(null, 20);
final Block block = user.getTargetBlock(20);
if (block.getType() == Material.AIR) {
throw new NoChargeException();
}

View File

@ -25,7 +25,7 @@ public class Commandeditsign extends EssentialsCommand {
throw new NotEnoughArgumentsException();
}
final Block target = user.getBase().getTargetBlock(null, 5); //5 is a good number
final Block target = user.getTargetBlock(5); //5 is a good number
if (!(target.getState() instanceof Sign)) {
throw new Exception(tl("editsignCommandTarget"));
}
@ -69,7 +69,7 @@ public class Commandeditsign extends EssentialsCommand {
return Lists.newArrayList("1", "2", "3", "4");
} else if (args.length == 3 && args[0].equalsIgnoreCase("set") && NumberUtil.isPositiveInt(args[1])) {
final int line = Integer.parseInt(args[1]);
final Block target = user.getBase().getTargetBlock(null, 5);
final Block target = user.getTargetBlock(5);
if (target.getState() instanceof Sign && line <= 4) {
final Sign sign = (Sign) target.getState();
return Lists.newArrayList(FormatUtil.unformatString(user, "essentials.editsign", sign.getLine(line - 1)));

View File

@ -20,7 +20,7 @@ public class Commandlightning extends EssentialsLoopCommand {
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
if (args.length == 0 || !sender.isAuthorized("essentials.lightning.others", ess)) {
if (sender.isPlayer()) {
sender.getPlayer().getWorld().strikeLightning(sender.getPlayer().getTargetBlock(null, 600).getLocation());
sender.getPlayer().getWorld().strikeLightning(sender.getUser(ess).getTargetBlock(600).getLocation());
return;
}
throw new NotEnoughArgumentsException();

View File

@ -37,7 +37,7 @@ public class SignPlayerListener implements Listener {
if (event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_AIR) {
Block targetBlock = null;
try {
targetBlock = event.getPlayer().getTargetBlock(null, 5);
targetBlock = ess.getUser(event.getPlayer()).getTargetBlock(5);
} catch (final IllegalStateException ex) {
if (ess.getSettings().isDebug()) {
ess.getLogger().log(Level.WARNING, ex.getMessage(), ex);