moved highlight so it doesn't disrupt api

This commit is contained in:
YouHaveTrouble
2021-07-28 04:24:49 +02:00
parent fa231f48c3
commit e10e378300
4 changed files with 43 additions and 16 deletions
@@ -30,7 +30,8 @@ public class BEPlayer {
public void resetSelection() {
this.selection = null;
Bukkit.getScheduler().runTaskAsynchronously(BlockEdit.getPlugin(),() -> SelectionHighlight.sendStop(getPlayer()));
this.selectionPoint1 = null;
this.selectionPoint2 = null;
}
private void updateSelection() {
@@ -47,18 +48,6 @@ public class BEPlayer {
return;
}
Bukkit.getScheduler().runTaskAsynchronously(BlockEdit.getPlugin(), () -> {
SelectionHighlight.sendStop(getPlayer());
if (selectionPoint1.equals(selectionPoint2)) {
SelectionHighlight.highlightBlock(getPlayer(), selectionPoint1, "#ffffff", "Selection Points", 10000);
} else {
SelectionHighlight.highlightBlock(getPlayer(), selectionPoint1, "#ffffff", "Selection Point 1", 10000);
SelectionHighlight.highlightBlock(getPlayer(), selectionPoint2, "#ffffff", "Selection Point 2", 10000);
}
});
selection = BoundingBox.of(selectionPoint1, selectionPoint2);
// bounding boxes are dumb.
selection.expand(0.5, 0.5, 0.5);
@@ -89,6 +78,7 @@ public class BEPlayer {
* @return Clone of selectionPoint1
*/
public Location getSelectionPoint1() {
if (selectionPoint1 == null) return null;
return selectionPoint1.clone();
}
@@ -96,6 +86,7 @@ public class BEPlayer {
* @return Clone of selectionPoint2
*/
public Location getSelectionPoint2() {
if (selectionPoint2 == null) return null;
return selectionPoint2.clone();
}
@@ -1,7 +1,10 @@
package me.youhavetrouble.blockedit.commands;
import me.youhavetrouble.blockedit.BEPlayer;
import me.youhavetrouble.blockedit.BlockEdit;
import me.youhavetrouble.blockedit.optionals.SelectionHighlight;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
@@ -15,8 +18,8 @@ public class DeselCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player player)) return true;
BEPlayer bePlayer = BEPlayer.getByPlayer(player);
bePlayer.resetSelection();
BEPlayer.getByPlayer(player).resetSelection();
Bukkit.getScheduler().runTaskAsynchronously(BlockEdit.getPlugin(),() -> SelectionHighlight.sendStop(player));
player.sendMessage(Component.text("You have reset your selection"));
return true;
}
@@ -15,7 +15,7 @@ import java.awt.*;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
/**
/*
* Highlighting selection blocks thanks to https://github.com/ArtFect/BlockHighlight
*
* MIT License
@@ -43,6 +43,7 @@ import java.nio.charset.StandardCharsets;
public class SelectionHighlight {
public static void highlightBlock(Player player, Location location, String color, String text, int time) {
if (location == null) return;
if (BlockEdit.getPlugin().getServer().getPluginManager().isPluginEnabled("ProtocolLib")) {
sendBlockHighlight(player, location, color, text, time);
}
@@ -1,10 +1,14 @@
package me.youhavetrouble.blockedit.wands;
import me.youhavetrouble.blockedit.BEPlayer;
import me.youhavetrouble.blockedit.BlockEdit;
import me.youhavetrouble.blockedit.api.BlockEditWand;
import me.youhavetrouble.blockedit.api.BlockEditWands;
import me.youhavetrouble.blockedit.optionals.SelectionHighlight;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -48,14 +52,42 @@ public class SelectionWand implements Listener, BlockEditWand {
if (action.equals(Action.LEFT_CLICK_BLOCK)) {
event.setCancelled(true);
BEPlayer.getByPlayer(player).setSelectionPoint1(block.getLocation());
highlightPoints(player);
player.sendMessage(Component.text("First point set"));
return;
}
if (action.equals(Action.RIGHT_CLICK_BLOCK)) {
event.setCancelled(true);
BEPlayer.getByPlayer(player).setSelectionPoint2(block.getLocation());
highlightPoints(player);
player.sendMessage(Component.text("Second point set"));
return;
}
}
private void highlightPoints(Player player) {
Bukkit.getScheduler().runTaskAsynchronously(BlockEdit.getPlugin(), () -> {
BEPlayer bePlayer = BEPlayer.getByPlayer(player);
SelectionHighlight.sendStop(player);
Location selection1 = bePlayer.getSelectionPoint1();
Location selection2 = bePlayer.getSelectionPoint2();
if (selection1 != null && selection1.equals(selection2)) {
SelectionHighlight.highlightBlock(player, bePlayer.getSelectionPoint1(), "#ffffff", "Selection Points", 10000);
return;
}
if (selection1 != null && !selection1.equals(selection2)) {
SelectionHighlight.highlightBlock(player, bePlayer.getSelectionPoint1(), "#ffffff", "Selection Point 1", 10000);
}
if (selection2 != null && !selection2.equals(selection1)) {
SelectionHighlight.highlightBlock(player, bePlayer.getSelectionPoint2(), "#ffffff", "Selection Point 2", 10000);
}
});
}
}