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() { public void resetSelection() {
this.selection = null; this.selection = null;
Bukkit.getScheduler().runTaskAsynchronously(BlockEdit.getPlugin(),() -> SelectionHighlight.sendStop(getPlayer())); this.selectionPoint1 = null;
this.selectionPoint2 = null;
} }
private void updateSelection() { private void updateSelection() {
@@ -47,18 +48,6 @@ public class BEPlayer {
return; 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); selection = BoundingBox.of(selectionPoint1, selectionPoint2);
// bounding boxes are dumb. // bounding boxes are dumb.
selection.expand(0.5, 0.5, 0.5); selection.expand(0.5, 0.5, 0.5);
@@ -89,6 +78,7 @@ public class BEPlayer {
* @return Clone of selectionPoint1 * @return Clone of selectionPoint1
*/ */
public Location getSelectionPoint1() { public Location getSelectionPoint1() {
if (selectionPoint1 == null) return null;
return selectionPoint1.clone(); return selectionPoint1.clone();
} }
@@ -96,6 +86,7 @@ public class BEPlayer {
* @return Clone of selectionPoint2 * @return Clone of selectionPoint2
*/ */
public Location getSelectionPoint2() { public Location getSelectionPoint2() {
if (selectionPoint2 == null) return null;
return selectionPoint2.clone(); return selectionPoint2.clone();
} }
@@ -1,7 +1,10 @@
package me.youhavetrouble.blockedit.commands; package me.youhavetrouble.blockedit.commands;
import me.youhavetrouble.blockedit.BEPlayer; import me.youhavetrouble.blockedit.BEPlayer;
import me.youhavetrouble.blockedit.BlockEdit;
import me.youhavetrouble.blockedit.optionals.SelectionHighlight;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
@@ -15,8 +18,8 @@ public class DeselCommand implements TabExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player player)) return true; if (!(sender instanceof Player player)) return true;
BEPlayer bePlayer = BEPlayer.getByPlayer(player); BEPlayer.getByPlayer(player).resetSelection();
bePlayer.resetSelection(); Bukkit.getScheduler().runTaskAsynchronously(BlockEdit.getPlugin(),() -> SelectionHighlight.sendStop(player));
player.sendMessage(Component.text("You have reset your selection")); player.sendMessage(Component.text("You have reset your selection"));
return true; return true;
} }
@@ -15,7 +15,7 @@ import java.awt.*;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
/** /*
* Highlighting selection blocks thanks to https://github.com/ArtFect/BlockHighlight * Highlighting selection blocks thanks to https://github.com/ArtFect/BlockHighlight
* *
* MIT License * MIT License
@@ -43,6 +43,7 @@ import java.nio.charset.StandardCharsets;
public class SelectionHighlight { public class SelectionHighlight {
public static void highlightBlock(Player player, Location location, String color, String text, int time) { 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")) { if (BlockEdit.getPlugin().getServer().getPluginManager().isPluginEnabled("ProtocolLib")) {
sendBlockHighlight(player, location, color, text, time); sendBlockHighlight(player, location, color, text, time);
} }
@@ -1,10 +1,14 @@
package me.youhavetrouble.blockedit.wands; package me.youhavetrouble.blockedit.wands;
import me.youhavetrouble.blockedit.BEPlayer; import me.youhavetrouble.blockedit.BEPlayer;
import me.youhavetrouble.blockedit.BlockEdit;
import me.youhavetrouble.blockedit.api.BlockEditWand; import me.youhavetrouble.blockedit.api.BlockEditWand;
import me.youhavetrouble.blockedit.api.BlockEditWands; import me.youhavetrouble.blockedit.api.BlockEditWands;
import me.youhavetrouble.blockedit.optionals.SelectionHighlight;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@@ -48,14 +52,42 @@ public class SelectionWand implements Listener, BlockEditWand {
if (action.equals(Action.LEFT_CLICK_BLOCK)) { if (action.equals(Action.LEFT_CLICK_BLOCK)) {
event.setCancelled(true); event.setCancelled(true);
BEPlayer.getByPlayer(player).setSelectionPoint1(block.getLocation()); BEPlayer.getByPlayer(player).setSelectionPoint1(block.getLocation());
highlightPoints(player);
player.sendMessage(Component.text("First point set")); player.sendMessage(Component.text("First point set"));
return; return;
} }
if (action.equals(Action.RIGHT_CLICK_BLOCK)) { if (action.equals(Action.RIGHT_CLICK_BLOCK)) {
event.setCancelled(true); event.setCancelled(true);
BEPlayer.getByPlayer(player).setSelectionPoint2(block.getLocation()); BEPlayer.getByPlayer(player).setSelectionPoint2(block.getLocation());
highlightPoints(player);
player.sendMessage(Component.text("Second point set")); player.sendMessage(Component.text("Second point set"));
return; 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);
}
});
}
} }