parent
					
						
							
								41583939ac
							
						
					
				
			
			
				commit
				
					
						4f752bef61
					
				
			
		
					 2 changed files with 49 additions and 25 deletions
				
			
		| 
						 | 
				
			
			@ -19,13 +19,17 @@ import org.bukkit.command.Command;
 | 
			
		|||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.event.EventHandler;
 | 
			
		||||
import org.bukkit.event.Listener;
 | 
			
		||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
 | 
			
		||||
import org.jetbrains.annotations.NotNull;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.NoSuchElementException;
 | 
			
		||||
 | 
			
		||||
public class WordCoordsModule extends TweaksModule implements CommandExecutor {
 | 
			
		||||
public class WordCoordsModule extends TweaksModule implements CommandExecutor, Listener {
 | 
			
		||||
    private WordList wordList;
 | 
			
		||||
    private WordCoordsConverter converter;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -40,6 +44,7 @@ public class WordCoordsModule extends TweaksModule implements CommandExecutor {
 | 
			
		|||
        this.converter = new WordCoordsConverter(wordList);
 | 
			
		||||
 | 
			
		||||
        registerCommand("wordcoords", this);
 | 
			
		||||
        registerEvents(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
| 
						 | 
				
			
			@ -59,8 +64,7 @@ public class WordCoordsModule extends TweaksModule implements CommandExecutor {
 | 
			
		|||
            z = player.getLocation().getBlockZ();
 | 
			
		||||
 | 
			
		||||
            encode = true;
 | 
			
		||||
        } else {
 | 
			
		||||
            if (args.length > 1) {
 | 
			
		||||
        } else if (args.length > 1) {
 | 
			
		||||
            try {
 | 
			
		||||
                double dx = Double.parseDouble(args[0]);
 | 
			
		||||
                double dz = Double.parseDouble(args[args.length > 2 ? 2 : 1]);
 | 
			
		||||
| 
						 | 
				
			
			@ -77,12 +81,6 @@ public class WordCoordsModule extends TweaksModule implements CommandExecutor {
 | 
			
		|||
            } catch (NumberFormatException ignored) { }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
            if (!encode) {
 | 
			
		||||
                String strArgs = String.join(" ", args);
 | 
			
		||||
                words = smartDetectWords(strArgs);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (encode) {
 | 
			
		||||
            words = converter.encode(x, z);
 | 
			
		||||
            String encoded = "///" + String.join(".", words);
 | 
			
		||||
| 
						 | 
				
			
			@ -98,9 +96,22 @@ public class WordCoordsModule extends TweaksModule implements CommandExecutor {
 | 
			
		|||
            
 | 
			
		||||
            sender.spigot().sendMessage(components);
 | 
			
		||||
        } else {
 | 
			
		||||
            String strArgs = String.join(" ", args);
 | 
			
		||||
            words = smartDetectWords(strArgs);
 | 
			
		||||
                
 | 
			
		||||
            if (words.length == 0) {
 | 
			
		||||
                sender.spigot().sendMessage(Language.getComponent("wordCoordsNoWords", ChatColor.GRAY));
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            try {
 | 
			
		||||
                int[] xz = converter.decode(words);
 | 
			
		||||
                x = xz[0];
 | 
			
		||||
                z = xz[1];
 | 
			
		||||
            } catch (NoSuchElementException e) {
 | 
			
		||||
                sender.spigot().sendMessage(Language.getComponent("wordCoordsInvalidWord", ChatColor.RED, e.getMessage()));
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            String encoded = "///" + String.join(".", words);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -109,6 +120,8 @@ public class WordCoordsModule extends TweaksModule implements CommandExecutor {
 | 
			
		|||
                .color(ChatColor.GRAY)
 | 
			
		||||
                .append("%d, %d".formatted(x, z))
 | 
			
		||||
                .color(ChatColor.AQUA) // TODO improve color
 | 
			
		||||
                .event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, "%d, %d".formatted(x, z)))
 | 
			
		||||
                .event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("Click to copy")))
 | 
			
		||||
                .append(" ±8")
 | 
			
		||||
                .color(ChatColor.GRAY)
 | 
			
		||||
                .create();
 | 
			
		||||
| 
						 | 
				
			
			@ -141,4 +154,13 @@ public class WordCoordsModule extends TweaksModule implements CommandExecutor {
 | 
			
		|||
 | 
			
		||||
        return words.toArray(String[]::new);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler
 | 
			
		||||
    public void onCommand(PlayerCommandPreprocessEvent event) {
 | 
			
		||||
        if (event.getMessage().startsWith("///")) {
 | 
			
		||||
            event.setCancelled(true);
 | 
			
		||||
 | 
			
		||||
            event.getPlayer().performCommand("wordcoords " + event.getMessage().substring(3));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -43,3 +43,5 @@ durabilityDisabled = Disabled durability alert
 | 
			
		|||
# When console executes /wordcoords without arguments
 | 
			
		||||
wordCoordsPlayerOnly = Only players can execute this command without arguments.
 | 
			
		||||
wordCoordsOutOfRange = Those coordinates are invalid.
 | 
			
		||||
wordCoordsInvalidWord = Invalid word: "%s"
 | 
			
		||||
wordCoordsNoWords = Please provide the Z coordinate.
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue