Skip to content

Commit

Permalink
Add clipboard origin position lock command
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMicky-FR committed Jul 17, 2022
1 parent 9835d07 commit d2ca24f
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 24 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ WorldEditSelectionVisualizer (WESV) is essentially the famous [WorldEditCUI](htt

You can download releases and find more information on [SpigotMC](https://www.spigotmc.org/resources/worldeditselectionvisualizer.17311/).

## Commands
* `/wesv toggle` and `/wesv toggle clipboard`: toggle the selection/clipboard visualization
* `/wesv lock`: lock/unlock the origin of the clipboard visualization to your current location
* `/wesv lock tp`: teleport to the lock location (when clipboard visualization lock is enabled)

## Screenshots

| Cuboid selection | Cylinder selection | Convex selection |
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
allprojects {
group = 'fr.mrmicky'
version = '2.1.0'
version = '2.1.1'
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import fr.mrmicky.worldeditselectionvisualizer.selection.SelectionType;
import fr.mrmicky.worldeditselectionvisualizer.utils.ChatUtils;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
Expand Down Expand Up @@ -45,29 +46,22 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command

if (args[0].equalsIgnoreCase("toggle")) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "Only players can use this command");
sender.sendMessage(ChatColor.RED + "Only players can use this command.");
return true;
}

PlayerVisualizerData playerData = plugin.getPlayerData((Player) sender);
SelectionType type = SelectionType.SELECTION;
handleToggle((Player) sender, args);

if (args.length > 1 && args[1].equalsIgnoreCase("clipboard")) {
type = SelectionType.CLIPBOARD;
}

boolean enabled = !playerData.isSelectionVisible(type);
playerData.toggleSelectionVisibility(type, enabled);
return true;
}

if (type == SelectionType.SELECTION) {
sender.sendMessage(plugin.getMessage("visualizer-" + (enabled ? "enabled" : "disabled")));
} else {
sender.sendMessage(plugin.getMessage("visualizer-clipboard-" + (enabled ? "enabled" : "disabled")));
if (args[0].equalsIgnoreCase("lock")) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "Only players can use this command.");
return true;
}

if (plugin.getConfig().getBoolean("save-toggle")) {
plugin.getStorageManager().setEnable(playerData.getPlayer(), type, enabled);
}
handleLock((Player) sender, args);

return true;
}
Expand All @@ -88,6 +82,7 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman

if (sender instanceof Player) {
completions.add("toggle");
completions.add("lock");
}

if (sender.hasPermission("wesv.reload")) {
Expand All @@ -101,14 +96,68 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
return Collections.singletonList("clipboard");
}

if (args.length == 2 && args[0].equalsIgnoreCase("lock") && StringUtil.startsWithIgnoreCase("tp", args[1])) {
return Collections.singletonList("tp");
}

return Collections.emptyList();
}

private void handleToggle(Player player, String[] args) {
PlayerVisualizerData playerData = plugin.getPlayerData(player);
SelectionType type = SelectionType.SELECTION;

if (args.length > 1 && args[1].equalsIgnoreCase("clipboard")) {
type = SelectionType.CLIPBOARD;
}

boolean enabled = !playerData.isSelectionVisible(type);
String key = enabled ? "enabled" : "disabled";
playerData.toggleSelectionVisibility(type, enabled);

if (type == SelectionType.SELECTION) {
player.sendMessage(plugin.getMessage("visualizer-" + key));
} else {
player.sendMessage(plugin.getMessage("visualizer-clipboard-" + key));
}

if (plugin.getConfig().getBoolean("save-toggle")) {
plugin.getStorageManager().setEnable(player, type, enabled);
}
}

private void handleLock(Player player, String[] args) {
PlayerVisualizerData playerData = plugin.getPlayerData(player);
Location location = playerData.getClipboardLockLocation();

if (args.length > 1 && args[1].equalsIgnoreCase("tp")) {
if (location == null) {
player.sendMessage(plugin.getMessage("lock-no-position"));
return;
}

player.teleport(location);
return;
}

if (location != null) {
playerData.setClipboardLockLocation(null);
player.sendMessage(plugin.getMessage("lock-disabled"));
return;
}

playerData.setClipboardLockLocation(player.getLocation());

player.sendMessage(plugin.getMessage("lock-enabled"));
}

private void sendUsage(CommandSender sender) {
String version = plugin.getDescription().getVersion();
sender.sendMessage(ChatUtils.color("&6WorldEditSelectionVisualizer v" + version + "&7 by &6MrMicky&7."));

if (sender instanceof Player) {
sender.sendMessage(ChatUtils.color("&7- /wesv lock"));
sender.sendMessage(ChatUtils.color("&7- /wesv lock tp"));
sender.sendMessage(ChatUtils.color("&7- /wesv toggle"));
sender.sendMessage(ChatUtils.color("&7- /wesv toggle clipboard"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void run() {
}

Collection<Shape> renderables = primary ? selectionPoints.getPrimary() : selectionPoints.getSecondary();
Vector3d location = new Vector3d(player.getLocation().toVector());
Vector3d location = new Vector3d(playerData.getClipboardLocation().toVector());
Vector3d origin = (type != SelectionType.CLIPBOARD) ? Vector3d.ZERO : location.subtract(selection.getOrigin()).floor();
ParticleRenderer renderer = new ParticleRenderer(player, location, origin, maxDistanceSquared, particleData);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package fr.mrmicky.worldeditselectionvisualizer.selection;

import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.EnumMap;
Expand All @@ -19,6 +21,9 @@ public class PlayerVisualizerData {
@NotNull
private final Player player;

@Nullable
private Location clipboardLockLocation;

private boolean holdingSelectionItem = true;

public PlayerVisualizerData(@NotNull Player player) {
Expand Down Expand Up @@ -55,8 +60,25 @@ public boolean isSelectionVisible(SelectionType type) {
public void toggleSelectionVisibility(SelectionType type, boolean enable) {
if (!enable) {
enabledVisualizations.remove(type);
} else {
enabledVisualizations.computeIfAbsent(type, PlayerSelection::new);
return;
}

enabledVisualizations.computeIfAbsent(type, PlayerSelection::new);
}

public @NotNull Location getClipboardLocation() {
if (clipboardLockLocation == null) {
return player.getLocation();
}

return clipboardLockLocation;
}

public @Nullable Location getClipboardLockLocation() {
return clipboardLockLocation;
}

public void setClipboardLockLocation(@Nullable Location location) {
clipboardLockLocation = location;
}
}
11 changes: 7 additions & 4 deletions plugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ check-updates: true
# You can edit the plugin messages here
messages:
no-permissions: "&cYou don't have the permission to use this command."
config-reloaded: "&aThe config was reloaded"
config-reloaded: "&aThe config was reloaded."
selection-too-large: "&6The visualizer only works with selections up to a size of %blocks% blocks."
visualizer-enabled: "&6Your visualizer has been &eenabled."
visualizer-disabled: "&6Your visualizer has been &cdisabled."
visualizer-clipboard-enabled: "&6Your clipboard visualizer has been &eenabled&6."
visualizer-enabled: "&6Your visualizer has been &aenabled&6."
visualizer-disabled: "&6Your visualizer has been &cdisabled&6."
visualizer-clipboard-enabled: "&6Your clipboard visualizer has been &aenabled&6."
visualizer-clipboard-disabled: "&6Your clipboard visualizer has been &cdisabled&6."
lock-enabled: "&6Clipboard origin lock is now &aenabled &6at your current position. Use &3/wesv lock tp &6to return to this position."
lock-disabled: "&6Clipboard origin lock is now &cdisabled&6."
lock-no-position: "&cClipboard origin lock isn't enabled&6."

# When enabled, if a player disables the selection visualization and leaves the server, when he will
# come back, the selection visualization will be still disabled until he activates it again with /wesv toggle.
Expand Down

0 comments on commit d2ca24f

Please sign in to comment.