From 5d4085ab07f651023af649545068a79fca9ca43a Mon Sep 17 00:00:00 2001 From: Video Date: Fri, 4 Nov 2022 22:26:19 -0600 Subject: [PATCH] Fixes FS-323 by rewriting ride modes to make sense --- .../totalfreedommod/command/Command_ride.java | 27 ++++++++++--------- .../totalfreedommod/player/PlayerData.java | 19 ++++++++----- .../totalfreedommod/sql/SQLite.java | 2 +- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java index 30a1883b..25623bd0 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java @@ -84,19 +84,22 @@ public class Command_ride extends FreedomCommand return true; } - if (args.length >= 2) + if (args.length >= 2 && args[0].equalsIgnoreCase("mode")) { - if (args[0].equalsIgnoreCase("mode")) + try { - if (args[1].equalsIgnoreCase("normal") || args[1].equalsIgnoreCase("off") || args[1].equalsIgnoreCase("ask")) - { - PlayerData playerDataSender = plugin.pl.getData(playerSender); - playerDataSender.setRideMode(args[1].toLowerCase()); - plugin.pl.save(playerDataSender); - msg("Ride mode is now set to " + args[1].toLowerCase() + "."); - return true; - } + PlayerData.RideMode mode = PlayerData.RideMode.valueOf(args[1].toUpperCase()); + PlayerData playerDataSender = plugin.pl.getData(playerSender); + playerDataSender.setRideMode(mode); + plugin.pl.save(playerDataSender); + msg("Ride mode is now set to " + mode.name().toLowerCase() + "."); } + catch (IllegalArgumentException ex) + { + msg("Invalid mode.", ChatColor.RED); + } + + return true; } final Player player = getPlayer(args[0], true); @@ -114,13 +117,13 @@ public class Command_ride extends FreedomCommand return true; } - if (playerData.getRideMode().equals("off") && !isAdmin(sender)) + if (playerData.getRideMode() == PlayerData.RideMode.OFF && !isAdmin(sender)) { msg("That player cannot be ridden.", ChatColor.RED); return true; } - if (playerData.getRideMode().equals("ask") && !FUtil.isExecutive(playerSender.getName())) + if (playerData.getRideMode() == PlayerData.RideMode.ASK && !FUtil.isExecutive(playerSender.getName())) { msg("Sent a request to the player.", ChatColor.GREEN); msg(player, sender.getName() + " has requested to ride you.", ChatColor.AQUA); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java b/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java index 680bc98d..bd15bf1e 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/player/PlayerData.java @@ -23,7 +23,7 @@ public class PlayerData private Boolean masterBuilder = false; - private String rideMode = "ask"; + private RideMode rideMode = RideMode.ASK; private int coins; @@ -51,7 +51,7 @@ public class PlayerData tag = resultSet.getString("tag"); discordID = resultSet.getString("discord_id"); masterBuilder = resultSet.getBoolean("master_builder"); - rideMode = resultSet.getString("ride_mode"); + rideMode = RideMode.valueOf(resultSet.getString("ride_mode").toUpperCase()); coins = resultSet.getInt("coins"); items.clear(); items.addAll(FUtil.stringToList(resultSet.getString("items"))); @@ -82,7 +82,7 @@ public class PlayerData "- Total Votes: " + totalVotes + "\n" + "- Display Discord: " + displayDiscord + "\n" + "- Tag: " + FUtil.colorize(tag) + ChatColor.GRAY + "\n" + - "- Ride Mode: " + rideMode + "\n" + + "- Ride Mode: " + rideMode.name() + "\n" + "- Login Message: " + loginMessage; } @@ -194,7 +194,7 @@ public class PlayerData put("tag", tag); put("discord_id", discordID); put("master_builder", masterBuilder); - put("ride_mode", rideMode); + put("ride_mode", rideMode.name()); put("coins", coins); put("items", FUtil.listToString(items)); put("total_votes", totalVotes); @@ -249,12 +249,12 @@ public class PlayerData this.masterBuilder = masterBuilder; } - public String getRideMode() + public RideMode getRideMode() { return rideMode; } - public void setRideMode(String rideMode) + public void setRideMode(RideMode rideMode) { this.rideMode = rideMode; } @@ -308,4 +308,11 @@ public class PlayerData { this.inspect = inspect; } + + public enum RideMode + { + ASK, + NORMAL, + OFF + } } \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java b/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java index 336c7934..81386984 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/sql/SQLite.java @@ -249,7 +249,7 @@ public class SQLite extends FreedomService statement.setString(4, player.getTag()); statement.setString(5, player.getDiscordID()); statement.setBoolean(6, player.isMasterBuilder()); - statement.setString(7, player.getRideMode()); + statement.setString(7, player.getRideMode().name()); statement.setInt(8, player.getCoins()); statement.setString(9, FUtil.listToString(player.getItems())); statement.setInt(10, player.getTotalVotes());