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.CommandExecutor;
 | 
				
			||||||
import org.bukkit.command.CommandSender;
 | 
					import org.bukkit.command.CommandSender;
 | 
				
			||||||
import org.bukkit.entity.Player;
 | 
					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 org.jetbrains.annotations.NotNull;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.IOException;
 | 
					import java.io.IOException;
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
import java.util.List;
 | 
					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 WordList wordList;
 | 
				
			||||||
    private WordCoordsConverter converter;
 | 
					    private WordCoordsConverter converter;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,6 +44,7 @@ public class WordCoordsModule extends TweaksModule implements CommandExecutor {
 | 
				
			||||||
        this.converter = new WordCoordsConverter(wordList);
 | 
					        this.converter = new WordCoordsConverter(wordList);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        registerCommand("wordcoords", this);
 | 
					        registerCommand("wordcoords", this);
 | 
				
			||||||
 | 
					        registerEvents(this);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
| 
						 | 
					@ -59,28 +64,21 @@ public class WordCoordsModule extends TweaksModule implements CommandExecutor {
 | 
				
			||||||
            z = player.getLocation().getBlockZ();
 | 
					            z = player.getLocation().getBlockZ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            encode = true;
 | 
					            encode = true;
 | 
				
			||||||
        } else {
 | 
					        } else if (args.length > 1) {
 | 
				
			||||||
            if (args.length > 1) {
 | 
					            try {
 | 
				
			||||||
                try {
 | 
					                double dx = Double.parseDouble(args[0]);
 | 
				
			||||||
                    double dx = Double.parseDouble(args[0]);
 | 
					                double dz = Double.parseDouble(args[args.length > 2 ? 2 : 1]);
 | 
				
			||||||
                    double dz = Double.parseDouble(args[args.length > 2 ? 2 : 1]);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (dx > Integer.MAX_VALUE || dx < Integer.MIN_VALUE || dz > Integer.MAX_VALUE || dz < Integer.MIN_VALUE) {
 | 
					                if (dx > Integer.MAX_VALUE || dx < Integer.MIN_VALUE || dz > Integer.MAX_VALUE || dz < Integer.MIN_VALUE) {
 | 
				
			||||||
                        sender.spigot().sendMessage(Language.getComponent("wordCoordsOutOfRange", ChatColor.RED));
 | 
					                    sender.spigot().sendMessage(Language.getComponent("wordCoordsOutOfRange", ChatColor.RED));
 | 
				
			||||||
                        return true;
 | 
					                    return true;
 | 
				
			||||||
                    }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    x = (int) dx;
 | 
					                x = (int) dx;
 | 
				
			||||||
                    z = (int) dz;
 | 
					                z = (int) dz;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    encode = true;
 | 
					                encode = true;
 | 
				
			||||||
                } catch (NumberFormatException ignored) { }
 | 
					            } catch (NumberFormatException ignored) { }
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (!encode) {
 | 
					 | 
				
			||||||
                String strArgs = String.join(" ", args);
 | 
					 | 
				
			||||||
                words = smartDetectWords(strArgs);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (encode) {
 | 
					        if (encode) {
 | 
				
			||||||
| 
						 | 
					@ -98,9 +96,22 @@ public class WordCoordsModule extends TweaksModule implements CommandExecutor {
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            sender.spigot().sendMessage(components);
 | 
					            sender.spigot().sendMessage(components);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            int[] xz = converter.decode(words);
 | 
					            String strArgs = String.join(" ", args);
 | 
				
			||||||
            x = xz[0];
 | 
					            words = smartDetectWords(strArgs);
 | 
				
			||||||
            z = xz[1];
 | 
					                
 | 
				
			||||||
 | 
					            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);
 | 
					            String encoded = "///" + String.join(".", words);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -109,7 +120,9 @@ public class WordCoordsModule extends TweaksModule implements CommandExecutor {
 | 
				
			||||||
                .color(ChatColor.GRAY)
 | 
					                .color(ChatColor.GRAY)
 | 
				
			||||||
                .append("%d, %d".formatted(x, z))
 | 
					                .append("%d, %d".formatted(x, z))
 | 
				
			||||||
                .color(ChatColor.AQUA) // TODO improve color
 | 
					                .color(ChatColor.AQUA) // TODO improve color
 | 
				
			||||||
                .append("±8")
 | 
					                .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)
 | 
					                .color(ChatColor.GRAY)
 | 
				
			||||||
                .create();
 | 
					                .create();
 | 
				
			||||||
            sender.spigot().sendMessage(components);
 | 
					            sender.spigot().sendMessage(components);
 | 
				
			||||||
| 
						 | 
					@ -141,4 +154,13 @@ public class WordCoordsModule extends TweaksModule implements CommandExecutor {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return words.toArray(String[]::new);
 | 
					        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));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -42,4 +42,6 @@ durabilityDisabled = Disabled durability alert
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# When console executes /wordcoords without arguments
 | 
					# When console executes /wordcoords without arguments
 | 
				
			||||||
wordCoordsPlayerOnly = Only players can execute this command without arguments.
 | 
					wordCoordsPlayerOnly = Only players can execute this command without arguments.
 | 
				
			||||||
wordCoordsOutOfRange = Those coordinates are invalid.
 | 
					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