Skip to content

Commit bbc8184

Browse files
committed
Bump version, add locale stuff for importhomes command
1 parent 1742c48 commit bbc8184

8 files changed

Lines changed: 251 additions & 77 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>simplexity</groupId>
88
<artifactId>SimpleHomes</artifactId>
9-
<version>1.1.1</version>
9+
<version>1.2.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>SimpleHomes</name>

src/main/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,16 @@ provides a straightforward interface for home management commands.
2828
| `homes.count.bypass` | op | Allows for setting infinite homes regardless of how many you have set as the max |
2929
| `homes.reload` | op | Allows reloading the config |
3030
| `homes.safety.bypass` | false | Allows bypassing the safety checks |
31+
32+
## Importing from other plugins
33+
34+
**THIS COMMAND IS IRREVERSIBLE AND WILL DELETE ANY HOMES YOU HAVE ALREADY SET IN SIMPLEHOMES**
35+
it is **HIGHLY** recommended you do not run this command while anyone is online, to reduce the risk of any save corruption.
36+
**USE AT YOUR OWN RISK**
37+
38+
To import from another plugin, you need to go to console, as the command is console-only. Command syntax is as follows:
39+
`importhomes <plugin> [player]`
40+
The player argument is optional, if you want to import all homes that are saved in the plugin specified, leave the player argument out.
41+
42+
Currently supported plugins to import from:
43+
- Essentials

src/main/java/simplexity/simplehomes/SimpleHomes.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import simplexity.simplehomes.configs.LocaleHandler;
99
import simplexity.simplehomes.saving.SQLHandler;
1010

11+
import java.util.Objects;
12+
1113
public final class SimpleHomes extends JavaPlugin {
1214

1315
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
@@ -39,11 +41,11 @@ public void onDisable() {
3941
}
4042

4143
private void registerCommands() {
42-
this.getCommand("sethome").setExecutor(new SetHome());
43-
this.getCommand("delhome").setExecutor(new DeleteHome());
44-
this.getCommand("home").setExecutor(new Home());
45-
this.getCommand("homelist").setExecutor(new HomeList());
46-
this.getCommand("homesreload").setExecutor(new HomesReload());
47-
this.getCommand("importhomes").setExecutor(new ImportHomes()); // TODO: Add command into plugin.yml
44+
Objects.requireNonNull(this.getCommand("sethome")).setExecutor(new SetHome());
45+
Objects.requireNonNull(this.getCommand("delhome")).setExecutor(new DeleteHome());
46+
Objects.requireNonNull(this.getCommand("home")).setExecutor(new Home());
47+
Objects.requireNonNull(this.getCommand("homelist")).setExecutor(new HomeList());
48+
Objects.requireNonNull(this.getCommand("homesreload")).setExecutor(new HomesReload());
49+
Objects.requireNonNull(this.getCommand("importhomes")).setExecutor(new ImportHomes());
4850
}
4951
}

src/main/java/simplexity/simplehomes/Util.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ public static int maxHomesPermission(Player player){
3232
}
3333
return maxHomes;
3434
}
35-
3635
}
Lines changed: 71 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package simplexity.simplehomes.commands;
22

3+
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
34
import org.bukkit.Bukkit;
5+
import org.bukkit.Location;
46
import org.bukkit.OfflinePlayer;
57
import org.bukkit.command.Command;
68
import org.bukkit.command.CommandExecutor;
@@ -9,6 +11,8 @@
911
import org.bukkit.configuration.ConfigurationSection;
1012
import org.bukkit.configuration.file.YamlConfiguration;
1113
import org.jetbrains.annotations.NotNull;
14+
import simplexity.simplehomes.configs.LocaleHandler;
15+
import simplexity.simplehomes.saving.SQLHandler;
1216

1317
import java.io.File;
1418
import java.util.UUID;
@@ -21,49 +25,38 @@ public class ImportHomes implements CommandExecutor {
2125
@Override
2226
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
2327
if (!(sender instanceof ConsoleCommandSender)) {
24-
sender.sendRichMessage("<red>This command can only be used by the Console.");
28+
sender.sendRichMessage(LocaleHandler.getInstance().getOnlyConsole());
2529
return true;
2630
}
2731

2832
if (args.length == 0) {
29-
sender.sendRichMessage("<red>Not enough arguments.");
33+
sender.sendRichMessage(LocaleHandler.getInstance().getImportNotEnoughArgs());
3034
return true;
3135
}
3236

33-
if (args.length == 1) {
34-
if (args[0].equalsIgnoreCase("help")) {
35-
sender.sendRichMessage("<aqua>This is a Console exclusive command used to import homes to SimpleHomes from other plugins.");
36-
sender.sendRichMessage("<aqua>Not all home plugins are supported, to add support submit an issue on GitHub");
37-
sender.sendRichMessage(" <aqua>https://github.com/Simplexity-Development/SimpleHomes/issues");
38-
sender.sendRichMessage("<gold>This command is <red>DESTRUCTIVE</red> and will overwrite homes with the same name.");
39-
sender.sendRichMessage("<gold>This command is <red>UNSUPPORTED</red> and may <red>CORRUPT SAVE DATA</red>.");
40-
sender.sendRichMessage("<red>>>>>> USE AT YOUR OWN RISK <<<<<</red>.");
41-
sender.sendRichMessage("<aqua>Usage:</aqua> <yellow>/importhomes <plugin> [username]");
42-
sender.sendRichMessage(" <yellow>username <aqua>is an optional argument to import specifically that user's homes.");
43-
sender.sendRichMessage("<green>Valid Plugins: Essentials");
37+
if (args[0].equalsIgnoreCase("help")) {
38+
sender.sendRichMessage(LocaleHandler.getInstance().getImportHelp());
39+
return true;
40+
}
41+
if (args[0].equalsIgnoreCase("confirm")) {
42+
if (this.lastUsed == null || this.args == null) {
43+
sender.sendRichMessage(LocaleHandler.getInstance().getCannotConfirm());
4444
return true;
4545
}
46-
if (args[0].equalsIgnoreCase("confirm")) {
47-
if (this.lastUsed == null || this.args == null) {
48-
sender.sendRichMessage("<red>No command was executed recently to confirm.");
49-
return true;
50-
}
51-
if (System.currentTimeMillis() - this.lastUsed > 15000) {
52-
this.lastUsed = null;
53-
this.args = null;
54-
sender.sendRichMessage("<red>Command timed out, please run again.");
55-
return true;
56-
}
57-
return executeCommand();
46+
if (System.currentTimeMillis() - this.lastUsed > 15000) {
47+
this.lastUsed = null;
48+
this.args = null;
49+
sender.sendRichMessage(LocaleHandler.getInstance().getTimedOut());
50+
return true;
5851
}
52+
return executeCommand();
5953
}
6054

55+
6156
this.lastUsed = System.currentTimeMillis();
6257
this.args = args;
63-
sender.sendRichMessage("<gold>You are about to run: <yellow>/" + label + " " + String.join(" ", args));
64-
sender.sendRichMessage("<red><bold>THIS ACTION IS DESTRUCTIVE AND WILL OVERWRITE EXISTING HOMES IN SIMPLEHOMES.");
65-
sender.sendRichMessage("<red><bold>THIS ACTION IS NOT SUPPORTED AND MAY CORRUPT SAVE DATA, USE AT YOUR OWN RISK.");
66-
sender.sendRichMessage("<gold>Please confirm this command using <yellow>/" + label + " confirm");
58+
sender.sendRichMessage(LocaleHandler.getInstance().getUnsupportedDestructive(),
59+
Placeholder.parsed("command", label));
6760
return true;
6861
}
6962

@@ -75,19 +68,19 @@ public boolean executeCommand() {
7568

7669
String playerName = args.length > 1 ? args[1] : null;
7770

78-
switch (args[0].toLowerCase()) {
79-
case "essentials" -> importEssentialsHomes(playerName);
80-
default -> sender.sendRichMessage("<red>No valid plugin was found.");
71+
if (args[0].equalsIgnoreCase("essentials")) {
72+
importEssentialsHomes(playerName);
73+
} else {
74+
sender.sendRichMessage(LocaleHandler.getInstance().getNoValidPlugin());
8175
}
82-
8376
return true;
8477
}
8578

8679
private void importEssentialsHomes(String playerName) {
8780
CommandSender sender = Bukkit.getServer().getConsoleSender();
8881
File userdataFolder = new File(Bukkit.getServer().getPluginsFolder() + "/Essentials/userdata");
8982
if (!userdataFolder.isDirectory()) {
90-
sender.sendRichMessage("<gold>There is no /plugins/Essentials/userdata folder!");
83+
sender.sendRichMessage(LocaleHandler.getInstance().getEssentialsNotExist());
9184
return;
9285
}
9386

@@ -96,46 +89,75 @@ private void importEssentialsHomes(String playerName) {
9689
UUID uuid = player.getUniqueId();
9790
File playerDataFile = new File(userdataFolder, uuid + ".yml");
9891
if (!playerDataFile.exists()) {
99-
sender.sendRichMessage("<gold>This player does not exist or does not have an Essentials/userdata file!");
100-
sender.sendRichMessage("<yellow>Player Name: </yellow>" + playerName);
101-
sender.sendRichMessage("<yellow>Retrieved UUID: </yellow>" + uuid);
102-
sender.sendRichMessage("<yellow>Searched File: </yellow>" + playerDataFile);
92+
sender.sendRichMessage(LocaleHandler.getInstance().getPlayerNotExist(),
93+
Placeholder.parsed("name", playerName),
94+
Placeholder.parsed("uuid", uuid.toString()),
95+
Placeholder.parsed("file", playerDataFile.getAbsolutePath()));
10396
return;
10497
}
10598
YamlConfiguration playerData = YamlConfiguration.loadConfiguration(playerDataFile);
10699
ConfigurationSection homes = playerData.getConfigurationSection("homes");
107100
if (homes == null || homes.getKeys(false).isEmpty()) {
108-
sender.sendRichMessage("<gold>This player does not have any homes in their Essentials/userdata file!");
109-
sender.sendRichMessage("<yellow>Player Name: </yellow>" + playerName);
110-
sender.sendRichMessage("<yellow>Retrieved UUID: </yellow>" + uuid);
111-
sender.sendRichMessage("<yellow>Searched File: </yellow>" + playerDataFile);
101+
sender.sendRichMessage(LocaleHandler.getInstance().getPlayerNotExist(),
102+
Placeholder.parsed("name", playerName),
103+
Placeholder.parsed("uuid", uuid.toString()),
104+
Placeholder.parsed("file", playerDataFile.getAbsolutePath()));
112105
return;
113106
}
114107
for (String key : homes.getKeys(false)) {
115-
// TODO: Rewrite SQLHandler to support this.
116108
ConfigurationSection home = homes.getConfigurationSection(key);
117-
sender.sendRichMessage("Found Home: " + key + " " + home.getInt("x") + " " + home.getInt("z")); // TODO: Remove after testing.
109+
Location location = getLocationFromHome(home);
110+
if (location == null) continue;
111+
SQLHandler.getInstance().setHome(uuid, location, key.toLowerCase());
118112
}
113+
sender.sendRichMessage(LocaleHandler.getInstance().getImportedHomes(),
114+
Placeholder.parsed("name", playerName));
119115
return;
120116
}
121117

122118
File[] files = userdataFolder.listFiles();
123119
assert files != null; // Already did an isDirectory() check earlier.
124120
if (files.length == 0) {
125-
sender.sendRichMessage("<gold>There is nothing inside of the /plugins/Essentials/userdata folder.");
121+
sender.sendRichMessage(LocaleHandler.getInstance().getNothingInsideFolder());
126122
return;
127123
}
128124
for (File userFile : files) {
129125
YamlConfiguration playerData = YamlConfiguration.loadConfiguration(userFile);
130-
sender.sendRichMessage("Found File: " + userFile.getName()); // TODO: Remove after testing.
131-
sender.sendRichMessage("Found Name: " + playerData.getString("last-account-name")); // TODO: Remove after testing.
126+
String uuidString = userFile.getName().replace(".yml", "");
127+
UUID uuid = UUID.fromString(uuidString);
132128
ConfigurationSection homes = playerData.getConfigurationSection("homes");
133129
if (homes == null || homes.getKeys(false).isEmpty()) continue;
134130
for (String key : homes.getKeys(false)) {
135-
// TODO: Rewrite SQLHandler to support this.
136131
ConfigurationSection home = homes.getConfigurationSection(key);
137-
sender.sendRichMessage("Found Home: " + key + " " + home.getInt("x") + " " + home.getInt("z")); // TODO: Remove after testing.
132+
Location location = getLocationFromHome(home);
133+
if (location == null) continue;
134+
SQLHandler.getInstance().setHome(uuid, location, key);
138135
}
136+
OfflinePlayer player = Bukkit.getServer().getOfflinePlayer(uuid);
137+
String userName = player.getName();
138+
if (userName == null) userName = "";
139+
sender.sendRichMessage(LocaleHandler.getInstance().getImportedHomes(),
140+
Placeholder.parsed("name", userName));
141+
}
142+
sender.sendRichMessage(LocaleHandler.getInstance().getImportComplete());
143+
}
144+
145+
private Location getLocationFromHome(ConfigurationSection home) {
146+
String worldString;
147+
try {
148+
worldString = home.getString("world");
149+
} catch (NullPointerException e) {
150+
return null;
151+
}
152+
if (worldString == null || worldString.isEmpty()) {
153+
return null;
139154
}
155+
UUID worldUUID = UUID.fromString(worldString);
156+
double x = home.getDouble("x");
157+
double y = home.getDouble("y");
158+
double z = home.getDouble("z");
159+
float yaw = (float) home.getDouble("yaw");
160+
float pitch = (float) home.getDouble("pitch");
161+
return new Location(Bukkit.getServer().getWorld(worldUUID), x, y, z, yaw, pitch);
140162
}
141163
}

0 commit comments

Comments
 (0)