Skip to content

Commit 0283a3d

Browse files
committed
some more refactoring
1 parent 9c98356 commit 0283a3d

File tree

8 files changed

+36
-43
lines changed

8 files changed

+36
-43
lines changed

src/main/java/simplexity/simplefly/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ public class Constants {
1212
public static final String FLY_SPEED_PERMISSION = "simplefly.flyspeed";
1313
public static final String FLY_OTHERS_PERMISSION = "simplefly.others.fly";
1414
public static final String FLY_SPEED_OTHERS_PERMISSION = "simplefly.others.flyspeed";
15+
public static final String FLY_RELOAD = "simplefly.reload";
1516

1617
}

src/main/java/simplexity/simplefly/FlyListeners.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.bukkit.event.player.PlayerRespawnEvent;
1313
import org.bukkit.persistence.PersistentDataContainer;
1414
import org.bukkit.persistence.PersistentDataType;
15-
import simplexity.simplefly.config.ConfigValues;
15+
import simplexity.simplefly.config.ConfigHandler;
1616
import simplexity.simplefly.config.LocaleMessage;
1717

1818
public class FlyListeners implements Listener {
@@ -21,7 +21,7 @@ public class FlyListeners implements Listener {
2121

2222
@EventHandler
2323
public void onPlayerLogin(PlayerJoinEvent joinEvent) {
24-
if (!ConfigValues.sessionPersistentFlight) {
24+
if (!ConfigHandler.sessionPersistentFlight) {
2525
return;
2626
}
2727
Player player = joinEvent.getPlayer();
@@ -42,7 +42,7 @@ public void onPlayerLogin(PlayerJoinEvent joinEvent) {
4242

4343
@EventHandler
4444
public void onWorldChange(PlayerChangedWorldEvent worldEvent) {
45-
if (!ConfigValues.worldChangePersistentFlight) return;
45+
if (!ConfigHandler.worldChangePersistentFlight) return;
4646
Player player = worldEvent.getPlayer();
4747
PersistentDataContainer playerPDC = player.getPersistentDataContainer();
4848
Boolean flyEnabled = playerPDC.getOrDefault(flyStatus, PersistentDataType.BOOLEAN, false);
@@ -53,7 +53,7 @@ public void onWorldChange(PlayerChangedWorldEvent worldEvent) {
5353

5454
@EventHandler
5555
public void onRespawn(PlayerRespawnEvent respawnEvent) {
56-
if (!ConfigValues.respawnPersistentFlight) return;
56+
if (!ConfigHandler.respawnPersistentFlight) return;
5757
Player player = respawnEvent.getPlayer();
5858
PersistentDataContainer playerPDC = player.getPersistentDataContainer();
5959
Boolean flyEnabled = playerPDC.getOrDefault(flyStatus, PersistentDataType.BOOLEAN, false);
@@ -64,7 +64,7 @@ public void onRespawn(PlayerRespawnEvent respawnEvent) {
6464

6565
@EventHandler
6666
public void onGamemodeChange(PlayerGameModeChangeEvent gameModeChangeEvent) {
67-
if (!ConfigValues.gamemodeChangePersistentFlight) return;
67+
if (!ConfigHandler.gamemodeChangePersistentFlight) return;
6868
Player player = gameModeChangeEvent.getPlayer();
6969
PersistentDataContainer playerPDC = player.getPersistentDataContainer();
7070
Bukkit.getScheduler().runTaskLater(SimpleFly.getInstance(), () -> {

src/main/java/simplexity/simplefly/SimpleFly.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package simplexity.simplefly;
22

3-
import io.papermc.paper.plugin.lifecycle.event.LifecycleEvent;
43
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
54
import net.kyori.adventure.text.minimessage.MiniMessage;
65
import org.bukkit.Server;
76
import org.bukkit.plugin.java.JavaPlugin;
87
import simplexity.simplefly.commands.Fly;
98
import simplexity.simplefly.commands.FlyReload;
10-
import simplexity.simplefly.commands.FlySpeed;
11-
import simplexity.simplefly.config.ConfigValues;
9+
import simplexity.simplefly.config.ConfigHandler;
1210

1311
public final class SimpleFly extends JavaPlugin {
1412

@@ -34,12 +32,12 @@ public void onEnable() {
3432
instance = this;
3533
flyServer = this.getServer();
3634
this.saveDefaultConfig();
37-
ConfigValues.reloadConfigValues();
35+
ConfigHandler.reloadConfigValues();
3836
this.getServer().getPluginManager().registerEvents(new simplexity.simplefly.FlyListeners(), this);
3937
this.getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, commands -> {
4038
commands.registrar().register(Fly.createCommand().build());
39+
commands.registrar().register(FlyReload.createCommand().build());
4140
});
42-
this.getCommand("flyreload").setExecutor(new FlyReload());
4341
}
4442

4543
}

src/main/java/simplexity/simplefly/commands/Fly.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public static LiteralArgumentBuilder<CommandSourceStack> createCommand() {
4040
.requires(ctx -> ctx.getSender().hasPermission(Constants.FLY_OTHERS_PERMISSION))
4141
.then(
4242
Commands.argument("player", ArgumentTypes.player())
43-
.suggests(SuggestionUtils::suggestPlayers))
44-
.executes(Fly::executeOnOther)
45-
.then(Commands.literal("enable").executes(ctx -> executeOnOtherWithArg(ctx, true)))
46-
.then(Commands.literal("disable").executes(ctx -> executeOnOtherWithArg(ctx, false))));
43+
.suggests(SuggestionUtils::suggestPlayers)
44+
.executes(Fly::executeOnOther)
45+
.then(Commands.literal("enable").executes(ctx -> executeOnOtherWithArg(ctx, true)))
46+
.then(Commands.literal("disable").executes(ctx -> executeOnOtherWithArg(ctx, false)))));
4747
}
4848

4949
private static boolean canExecute(CommandSourceStack css) {
@@ -84,6 +84,7 @@ private static int executeOnOther(CommandContext<CommandSourceStack> ctx) throws
8484
return Command.SINGLE_SUCCESS;
8585
}
8686

87+
@SuppressWarnings("SameReturnValue")
8788
private static int executeOnOtherWithArg(CommandContext<CommandSourceStack> ctx, boolean shouldEnable) throws CommandSyntaxException {
8889
CommandSender sender = ctx.getSource().getSender();
8990
PlayerSelectorArgumentResolver playerArg = ctx.getArgument("player", PlayerSelectorArgumentResolver.class);
@@ -108,7 +109,7 @@ private static int executeOnOtherWithArg(CommandContext<CommandSourceStack> ctx,
108109
} else {
109110
enabledString = LocaleMessage.DISABLED.getMessage();
110111
}
111-
sender.sendRichMessage(LocaleMessage.FLY_SET_MANY_OTHER_ARG.getMessage(),
112+
sender.sendRichMessage(LocaleMessage.FLY_SET_OTHER_MANY_ARG.getMessage(),
112113
Placeholder.parsed("value", enabledString),
113114
Placeholder.parsed("count", String.valueOf(modified)));
114115
return Command.SINGLE_SUCCESS;
Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
package simplexity.simplefly.commands;
22

3-
import org.bukkit.command.Command;
4-
import org.bukkit.command.CommandExecutor;
5-
import org.bukkit.command.CommandSender;
6-
import org.jetbrains.annotations.NotNull;
7-
import simplexity.simplefly.config.ConfigValues;
8-
import simplexity.simplefly.Util;
3+
import com.mojang.brigadier.Command;
4+
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
5+
import io.papermc.paper.command.brigadier.CommandSourceStack;
6+
import io.papermc.paper.command.brigadier.Commands;
7+
8+
import simplexity.simplefly.Constants;
9+
import simplexity.simplefly.config.ConfigHandler;
910
import simplexity.simplefly.config.LocaleMessage;
1011

11-
public class FlyReload implements CommandExecutor {
12-
13-
@Override
14-
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
15-
ConfigValues.reloadConfigValues();
16-
sender.sendRichMessage(LocaleMessage.FEEDBACK_CONFIG_RELOADED.getMessage());
17-
return false;
12+
public class FlyReload {
13+
14+
public static LiteralArgumentBuilder<CommandSourceStack> createCommand() {
15+
return Commands.literal("flyreload").requires(ctx -> ctx.getSender().hasPermission(Constants.FLY_RELOAD))
16+
.executes(ctx -> {
17+
ConfigHandler.reloadConfigValues();
18+
ctx.getSource().getSender().sendRichMessage(LocaleMessage.FEEDBACK_CONFIG_RELOADED.getMessage());
19+
return Command.SINGLE_SUCCESS;
20+
});
1821
}
22+
23+
1924
}

src/main/java/simplexity/simplefly/commands/FlySpeed.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
package simplexity.simplefly.commands;
22

33
import net.kyori.adventure.text.minimessage.MiniMessage;
4-
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
5-
import org.bukkit.command.Command;
6-
import org.bukkit.command.CommandSender;
7-
import org.bukkit.command.TabExecutor;
8-
import org.bukkit.entity.Player;
9-
import org.jetbrains.annotations.NotNull;
10-
import org.jetbrains.annotations.Nullable;
11-
import simplexity.simplefly.config.ConfigValues;
124
import simplexity.simplefly.SimpleFly;
13-
import simplexity.simplefly.Constants;
14-
import simplexity.simplefly.Util;
155

166
import java.util.ArrayList;
17-
import java.util.List;
187

198
public class FlySpeed {
209

2110
private static final MiniMessage miniMessage = SimpleFly.getMiniMessage();
22-
private static final ArrayList<String> tabComplete = new ArrayList<>();
2311
private static final String setArg = "set";
2412
private static final String resetArg = "reset";
2513
private static final String getArg = "get";

src/main/java/simplexity/simplefly/config/ConfigValues.java renamed to src/main/java/simplexity/simplefly/config/ConfigHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.slf4j.Logger;
55
import simplexity.simplefly.SimpleFly;
66

7-
public class ConfigValues {
7+
public class ConfigHandler {
88
private static final Logger logger = SimpleFly.getInstance().getSLF4JLogger();
99

1010
public static float maxFlySpeed, minFlySpeed;

src/main/java/simplexity/simplefly/config/LocaleMessage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public enum LocaleMessage {
1313
SERVER_NAME("insertion.server-name", "<white>[Server]</white>"),
1414
FLY_SET_OWN("fly-set.own", "Your fly has been <value>"),
1515
FLY_SET_OTHER("fly-set.other", "<target>'s fly has been <value>"),
16-
FLY_SET_OTHER_MANY("fly-set.many-other", "You have altered <count> player's fly states."),
17-
FLY_SET_MANY_OTHER_ARG("fly-set.many-other-with-arg", "You have <value> <count> players' fly states"),
16+
FLY_SET_OTHER_MANY("fly-set.other-many", "You have altered <count> player's fly states."),
17+
FLY_SET_OTHER_MANY_ARG("fly-set.other-many-with-arg", "You have <value> <count> players' fly states"),
1818
FLY_SET_BY_OTHER("fly-set.by-other", "<green>Your fly has been <value> by <initiator></green>"),
1919
FLY_SPEED_GET_OWN("fly-speed-get.own", "<grey>Your flyspeed is currently set to <value></grey>"),
2020
FLY_SPEED_GET_OTHER("fly-speed-get.other", "<grey><target>'s current flyspeed is <value></grey>"),

0 commit comments

Comments
 (0)