Skip to content

Commit 99a3e21

Browse files
committed
Reorganize Prefix / Util, YML Saving Change
Refactored Prefix, PrefixUtil, and RequirementUtil into package prefix. Package util was getting pretty big and did not really match with the new Prefix. YML Saving Format now saves prefix data under "current-prefix" rather than a value tied to the player UUID. Player UUID is now a Configuration Section. (May require purging the old YML, plugin is fairly new so there probably will not be a "conversion" operation for this).
1 parent 2be614a commit 99a3e21

File tree

11 files changed

+25
-18
lines changed

11 files changed

+25
-18
lines changed

src/main/java/adhdmc/simpleprefixes/SimplePrefixes.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import adhdmc.simpleprefixes.config.PrefixConfig;
88
import adhdmc.simpleprefixes.dependency.PAPIExpansion;
99
import adhdmc.simpleprefixes.gui.chest.listener.PrefixMenuListener;
10-
import adhdmc.simpleprefixes.util.Prefix;
11-
import adhdmc.simpleprefixes.util.PrefixUtil;
10+
import adhdmc.simpleprefixes.prefix.Prefix;
11+
import adhdmc.simpleprefixes.prefix.PrefixUtil;
1212
import net.kyori.adventure.text.minimessage.MiniMessage;
1313
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
1414
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;

src/main/java/adhdmc/simpleprefixes/command/subcommand/InfoCommand.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
import adhdmc.simpleprefixes.command.SubCommand;
55
import adhdmc.simpleprefixes.util.Message;
66
import adhdmc.simpleprefixes.util.Permission;
7-
import adhdmc.simpleprefixes.util.Prefix;
7+
import adhdmc.simpleprefixes.prefix.Prefix;
88
import net.kyori.adventure.text.Component;
9-
import net.kyori.adventure.text.minimessage.MiniMessage;
109
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
1110
import org.bukkit.command.CommandSender;
1211

src/main/java/adhdmc/simpleprefixes/command/subcommand/ResetCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import adhdmc.simpleprefixes.command.SubCommand;
44
import adhdmc.simpleprefixes.util.Message;
55
import adhdmc.simpleprefixes.util.Permission;
6-
import adhdmc.simpleprefixes.util.PrefixUtil;
6+
import adhdmc.simpleprefixes.prefix.PrefixUtil;
77
import org.bukkit.command.CommandSender;
88
import org.bukkit.entity.Player;
99

src/main/java/adhdmc/simpleprefixes/command/subcommand/SetCommand.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package adhdmc.simpleprefixes.command.subcommand;
22

33
import adhdmc.simpleprefixes.command.SubCommand;
4+
import adhdmc.simpleprefixes.prefix.Prefix;
5+
import adhdmc.simpleprefixes.prefix.PrefixUtil;
6+
import adhdmc.simpleprefixes.prefix.RequirementUtil;
47
import adhdmc.simpleprefixes.util.*;
58
import org.bukkit.command.CommandSender;
69
import org.bukkit.entity.Player;
710

811
import java.util.ArrayList;
912
import java.util.List;
10-
import java.util.Locale;
1113

1214
public class SetCommand extends SubCommand {
1315
public SetCommand() {

src/main/java/adhdmc/simpleprefixes/dependency/PAPIExpansion.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package adhdmc.simpleprefixes.dependency;
22

33
import adhdmc.simpleprefixes.SimplePrefixes;
4-
import adhdmc.simpleprefixes.util.PrefixUtil;
4+
import adhdmc.simpleprefixes.prefix.PrefixUtil;
55
import me.clip.placeholderapi.PlaceholderAPI;
66
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
7-
import net.kyori.adventure.text.minimessage.MiniMessage;
8-
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
9-
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
107
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
118
import org.bukkit.OfflinePlayer;
129
import org.jetbrains.annotations.NotNull;

src/main/java/adhdmc/simpleprefixes/gui/chest/PrefixMenu.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import adhdmc.simpleprefixes.SimplePrefixes;
44
import adhdmc.simpleprefixes.util.Message;
5-
import adhdmc.simpleprefixes.util.Prefix;
6-
import adhdmc.simpleprefixes.util.RequirementUtil;
5+
import adhdmc.simpleprefixes.prefix.Prefix;
6+
import adhdmc.simpleprefixes.prefix.RequirementUtil;
77
import me.clip.placeholderapi.PlaceholderAPI;
88
import net.kyori.adventure.text.Component;
99
import net.kyori.adventure.text.minimessage.MiniMessage;

src/main/java/adhdmc/simpleprefixes/gui/chest/listener/PrefixMenuListener.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import adhdmc.simpleprefixes.gui.chest.PrefixMenu;
44
import adhdmc.simpleprefixes.util.Message;
5-
import adhdmc.simpleprefixes.util.PrefixUtil;
5+
import adhdmc.simpleprefixes.prefix.PrefixUtil;
66
import org.bukkit.Sound;
77
import org.bukkit.entity.Player;
88
import org.bukkit.event.EventHandler;

src/main/java/adhdmc/simpleprefixes/util/Prefix.java src/main/java/adhdmc/simpleprefixes/prefix/Prefix.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
package adhdmc.simpleprefixes.util;
1+
package adhdmc.simpleprefixes.prefix;
22

33
import adhdmc.simpleprefixes.SimplePrefixes;
44
import adhdmc.simpleprefixes.config.PrefixConfig;
5+
import adhdmc.simpleprefixes.util.Message;
56
import org.bukkit.configuration.ConfigurationSection;
67

78
import java.util.*;

src/main/java/adhdmc/simpleprefixes/util/PrefixUtil.java src/main/java/adhdmc/simpleprefixes/prefix/PrefixUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package adhdmc.simpleprefixes.util;
1+
package adhdmc.simpleprefixes.prefix;
22

33
import adhdmc.simpleprefixes.config.Config;
44
import adhdmc.simpleprefixes.util.saving.PlayerPDC;

src/main/java/adhdmc/simpleprefixes/util/RequirementUtil.java src/main/java/adhdmc/simpleprefixes/prefix/RequirementUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package adhdmc.simpleprefixes.util;
1+
package adhdmc.simpleprefixes.prefix;
22

33
import me.clip.placeholderapi.PlaceholderAPI;
44
import org.bukkit.NamespacedKey;

src/main/java/adhdmc/simpleprefixes/util/saving/YMLFile.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22

33
import adhdmc.simpleprefixes.SimplePrefixes;
44
import org.bukkit.OfflinePlayer;
5+
import org.bukkit.configuration.ConfigurationSection;
56
import org.bukkit.configuration.InvalidConfigurationException;
67
import org.bukkit.configuration.file.FileConfiguration;
78
import org.bukkit.configuration.file.YamlConfiguration;
89

910
import java.io.File;
1011
import java.io.IOException;
12+
import java.util.UUID;
1113

1214
public class YMLFile extends SaveHandler {
1315
private final File dataFile = new File(SimplePrefixes.getPlugin().getDataFolder(), "prefix_data.yml");
1416
private final FileConfiguration prefixData = new YamlConfiguration();
17+
private final String CURRENT_PREFIX = "current-prefix";
1518

1619
@Override
1720
public void init() {
@@ -26,12 +29,17 @@ public void init() {
2629

2730
@Override
2831
public String getPrefixId(OfflinePlayer p) {
29-
return prefixData.getString(p.getUniqueId().toString(), null);
32+
ConfigurationSection playerData = prefixData.getConfigurationSection(p.getUniqueId().toString());
33+
if (playerData == null) { return null; }
34+
return playerData.getString(CURRENT_PREFIX, null);
3035
}
3136

3237
@Override
3338
public void setPrefixId(OfflinePlayer p, String id) {
34-
prefixData.set(p.getUniqueId().toString(), id);
39+
String uuid = p.getUniqueId().toString();
40+
ConfigurationSection playerData = prefixData.getConfigurationSection(uuid);
41+
if (playerData == null) playerData = prefixData.createSection(uuid);
42+
playerData.set(CURRENT_PREFIX, id);
3543
try { prefixData.save(dataFile); }
3644
catch (IOException e) { e.printStackTrace(); }
3745
}

0 commit comments

Comments
 (0)