mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 06:28:49 +00:00
Refactoring, improve database system and add creation timestamp to homes and warps
This commit is contained in:
1 parent
58eeab20c5
commit
98893814f7
24 files changed
+549
-657
No files matched your search
@@ -2,6 +2,7 @@ package me.william278.huskhomes2;
|
||||
|
||||
import de.themoep.minedown.MineDown;
|
||||
import me.william278.huskhomes2.teleport.points.Home;
|
||||
import me.william278.huskhomes2.teleport.points.SetPoint;
|
||||
import me.william278.huskhomes2.teleport.points.Warp;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -9,15 +10,7 @@ public class EditingHandler {
|
||||
|
||||
public static void showEditHomeOptions(Player p, Home home) {
|
||||
MessageManager.sendMessage(p, "edit_home_title", home.getName());
|
||||
MessageManager.sendMessage(p, "edit_description", MineDown.escape(home.getDescription().replace("]", "]").replace("[", "[").replace("(", "❲").replace(")", "❳")));
|
||||
MessageManager.sendMessage(p, "edit_location",
|
||||
Integer.toString((int) home.getX()),
|
||||
Integer.toString((int) home.getY()),
|
||||
Integer.toString((int) home.getZ()));
|
||||
MessageManager.sendMessage(p, "edit_world", home.getWorldName());
|
||||
if (HuskHomes.getSettings().doBungee()) {
|
||||
MessageManager.sendMessage(p, "edit_server", home.getServer());
|
||||
}
|
||||
showPointDetails(p, home);
|
||||
if (!home.isPublic()) {
|
||||
MessageManager.sendMessage(p, "edit_home_privacy_private");
|
||||
} else {
|
||||
@@ -37,17 +30,22 @@ public class EditingHandler {
|
||||
|
||||
public static void showEditWarpOptions(Player p, Warp warp) {
|
||||
MessageManager.sendMessage(p, "edit_warp_title", warp.getName());
|
||||
MessageManager.sendMessage(p, "edit_description", MineDown.escape(warp.getDescription().replace("]", "]").replace("[", "[").replace("(", "❲").replace(")", "❳")));
|
||||
MessageManager.sendMessage(p, "edit_location",
|
||||
Integer.toString((int) warp.getX()),
|
||||
Integer.toString((int) warp.getY()),
|
||||
Integer.toString((int) warp.getZ()));
|
||||
MessageManager.sendMessage(p, "edit_world", warp.getWorldName());
|
||||
if (HuskHomes.getSettings().doBungee()) {
|
||||
MessageManager.sendMessage(p, "edit_server", warp.getServer());
|
||||
}
|
||||
showPointDetails(p, warp);
|
||||
|
||||
MessageManager.sendMessage(p, "edit_warp_options", warp.getName());
|
||||
}
|
||||
|
||||
private static void showPointDetails(Player p, SetPoint point) {
|
||||
MessageManager.sendMessage(p, "edit_description", MineDown.escape(point.getDescription().replace("]", "]").replace("[", "[").replace("(", "❲").replace(")", "❳")));
|
||||
MessageManager.sendMessage(p, "edit_timestamp", point.getFormattedCreationTime());
|
||||
MessageManager.sendMessage(p, "edit_location",
|
||||
Integer.toString((int) point.getX()),
|
||||
Integer.toString((int) point.getY()),
|
||||
Integer.toString((int) point.getZ()));
|
||||
MessageManager.sendMessage(p, "edit_world", point.getWorldName());
|
||||
if (HuskHomes.getSettings().doBungee()) {
|
||||
MessageManager.sendMessage(p, "edit_server", point.getServer());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -229,7 +229,7 @@ public final class HuskHomes extends JavaPlugin {
|
||||
Metrics metrics = new Metrics(this, METRICS_PLUGIN_ID);
|
||||
metrics.addCustomChart(new SimplePie("bungee_mode", () -> Boolean.toString(getSettings().doBungee())));
|
||||
metrics.addCustomChart(new SimplePie("language", () -> getSettings().getLanguage()));
|
||||
metrics.addCustomChart(new SimplePie("database_type", () -> getSettings().getDatabaseType()));
|
||||
metrics.addCustomChart(new SimplePie("database_type", () -> getSettings().getDatabaseType().toLowerCase()));
|
||||
metrics.addCustomChart(new SimplePie("using_economy", () -> Boolean.toString(getSettings().doEconomy())));
|
||||
metrics.addCustomChart(new SimplePie("using_map", () -> Boolean.toString(getSettings().doMapIntegration())));
|
||||
if (getSettings().doMapIntegration()) {
|
||||
|
||||
@@ -64,7 +64,7 @@ public class MessageManager {
|
||||
Change the appearance/text of messages in the plugin using this config.\s
|
||||
This config makes use of MineDown formatting, with extensive support for custom colors & formats.\s
|
||||
For formatting help, see: https://github.com/Phoenix616/MineDown or check the HuskHomes Wiki.""");
|
||||
InputStream defaultMessageFile = plugin.getResource("Languages/" + language + ".yml");
|
||||
InputStream defaultMessageFile = plugin.getResource("languages/" + language + ".yml");
|
||||
if (defaultMessageFile != null) {
|
||||
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(new InputStreamReader(defaultMessageFile, StandardCharsets.UTF_8));
|
||||
config.setDefaults(yamlConfiguration);
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.bukkit.entity.Player;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
@@ -55,7 +54,7 @@ public class HuskHomesAPI {
|
||||
*/
|
||||
public Home getHome(String ownerUsername, String homeName) {
|
||||
try {
|
||||
return DataManager.getHome(ownerUsername, homeName, huskHomes.getInstance().getConnection());
|
||||
return DataManager.getHome(ownerUsername, homeName, HuskHomes.getConnection());
|
||||
} catch (SQLException e) {
|
||||
huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
|
||||
return null;
|
||||
@@ -70,7 +69,7 @@ public class HuskHomesAPI {
|
||||
*/
|
||||
public Warp getWarp(String warpName) {
|
||||
try {
|
||||
return DataManager.getWarp(warpName, huskHomes.getInstance().getConnection());
|
||||
return DataManager.getWarp(warpName, HuskHomes.getConnection());
|
||||
} catch (SQLException e) {
|
||||
huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
|
||||
return null;
|
||||
@@ -95,7 +94,7 @@ public class HuskHomesAPI {
|
||||
*/
|
||||
public List<Home> getHomes(String ownerUsername) {
|
||||
try {
|
||||
return DataManager.getPlayerHomes(ownerUsername, huskHomes.getInstance().getConnection());
|
||||
return DataManager.getPlayerHomes(ownerUsername, HuskHomes.getConnection());
|
||||
} catch (SQLException e) {
|
||||
huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
|
||||
return null;
|
||||
@@ -137,7 +136,7 @@ public class HuskHomesAPI {
|
||||
*/
|
||||
public List<Home> getPublicHomes() {
|
||||
try {
|
||||
return DataManager.getPublicHomes(huskHomes.getInstance().getConnection());
|
||||
return DataManager.getPublicHomes(HuskHomes.getConnection());
|
||||
} catch (SQLException e) {
|
||||
huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
|
||||
return null;
|
||||
@@ -160,7 +159,7 @@ public class HuskHomesAPI {
|
||||
*/
|
||||
public List<Warp> getWarps() {
|
||||
try {
|
||||
return DataManager.getWarps(huskHomes.getInstance().getConnection());
|
||||
return DataManager.getWarps(HuskHomes.getConnection());
|
||||
} catch (SQLException e) {
|
||||
huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
|
||||
return null;
|
||||
@@ -229,7 +228,7 @@ public class HuskHomesAPI {
|
||||
* @see TeleportationPoint
|
||||
*/
|
||||
public void teleportPlayer(Player player, String targetPlayerName, boolean timed) {
|
||||
Connection connection = huskHomes.getInstance().getConnection();
|
||||
Connection connection = HuskHomes.getConnection();
|
||||
Bukkit.getScheduler().runTask(huskHomes, () -> {
|
||||
try {
|
||||
if (timed) {
|
||||
|
||||
@@ -64,16 +64,7 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
case "description" -> {
|
||||
if (args.length >= 3) {
|
||||
// Get the new description
|
||||
StringBuilder newDescription = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
if (i > 2) {
|
||||
newDescription.append(" ").append(args[i]);
|
||||
} else {
|
||||
newDescription = new StringBuilder(args[i]);
|
||||
}
|
||||
}
|
||||
String newDescriptionString = newDescription.toString();
|
||||
editHomeDescription(p, homeName, newDescriptionString, connection);
|
||||
editHomeDescription(p, homeName, buildDescription(args), connection);
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/edithome <home> description <new description>");
|
||||
}
|
||||
@@ -93,6 +84,18 @@ public class EditHomeCommand extends CommandBase implements TabCompleter {
|
||||
});
|
||||
}
|
||||
|
||||
public static String buildDescription(String[] args) {
|
||||
StringBuilder newDescription = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
if (i > 2) {
|
||||
newDescription.append(" ").append(args[i]);
|
||||
} else {
|
||||
newDescription = new StringBuilder(args[i]);
|
||||
}
|
||||
}
|
||||
return newDescription.toString();
|
||||
}
|
||||
|
||||
private void editHomeLocation(Player p, String homeName, Connection connection) throws SQLException {
|
||||
Location newLocation = p.getLocation();
|
||||
TeleportationPoint newTeleportLocation = new TeleportationPoint(newLocation, HuskHomes.getSettings().getServerID());
|
||||
|
||||
@@ -59,16 +59,7 @@ public class EditWarpCommand extends CommandBase implements TabCompleter {
|
||||
case "description" -> {
|
||||
if (args.length >= 3) {
|
||||
// Get the new description
|
||||
StringBuilder newDescription = new StringBuilder();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
if (i > 2) {
|
||||
newDescription.append(" ").append(args[i]);
|
||||
} else {
|
||||
newDescription = new StringBuilder(args[i]);
|
||||
}
|
||||
}
|
||||
String newDescriptionString = newDescription.toString();
|
||||
editWarpDescription(p, warpName, newDescriptionString, connection);
|
||||
editWarpDescription(p, warpName, EditHomeCommand.buildDescription(args), connection);
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_invalid_syntax", "/editwarp <warp> description <new description>");
|
||||
}
|
||||
|
||||
@@ -41,12 +41,10 @@ public class HomeCommand extends CommandBase {
|
||||
}
|
||||
} else {
|
||||
List<Home> homes = DataManager.getPlayerHomes(p.getName(), connection);
|
||||
if (homes != null) {
|
||||
if (homes.size() == 1) {
|
||||
// Teleport the player if they only have one home
|
||||
TeleportManager.queueTimedTeleport(p, homes.get(0), connection);
|
||||
return;
|
||||
}
|
||||
if (homes.size() == 1) {
|
||||
// Teleport the player if they only have one home
|
||||
TeleportManager.queueTimedTeleport(p, homes.get(0), connection);
|
||||
return;
|
||||
}
|
||||
HomeListCommand.displayPlayerHomeList(p, 1);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -48,6 +48,7 @@ public class MySQL extends Database {
|
||||
"`name` varchar(16) NOT NULL," +
|
||||
"`description` varchar(255) NOT NULL," +
|
||||
"`public` boolean NOT NULL," +
|
||||
"`creation_time` timestamp NOT NULL," +
|
||||
"PRIMARY KEY (`player_id`, `name`)," +
|
||||
"FOREIGN KEY (`player_id`) REFERENCES " + HuskHomes.getSettings().getPlayerDataTable() + " (`player_id`) ON DELETE CASCADE ON UPDATE NO ACTION," +
|
||||
"FOREIGN KEY (`location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE CASCADE ON UPDATE NO ACTION" +
|
||||
@@ -57,6 +58,7 @@ public class MySQL extends Database {
|
||||
"`location_id` integer NOT NULL," +
|
||||
"`name` varchar(16) NOT NULL UNIQUE," +
|
||||
"`description` varchar(255) NOT NULL," +
|
||||
"`creation_time` timestamp NOT NULL," +
|
||||
"PRIMARY KEY (`location_id`)," +
|
||||
"FOREIGN KEY (`location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE CASCADE ON UPDATE NO ACTION" +
|
||||
");"
|
||||
|
||||
@@ -50,6 +50,7 @@ public class SQLite extends Database {
|
||||
"`name` varchar(16) NOT NULL," +
|
||||
"`description` varchar(255) NOT NULL," +
|
||||
"`public` boolean NOT NULL," +
|
||||
"`creation_time` timestamp NOT NULL," +
|
||||
"PRIMARY KEY (`player_id`, `name`)," +
|
||||
"FOREIGN KEY (`player_id`) REFERENCES " + HuskHomes.getSettings().getPlayerDataTable() + " (`player_id`) ON DELETE CASCADE ON UPDATE NO ACTION," +
|
||||
"FOREIGN KEY (`location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE CASCADE ON UPDATE NO ACTION" +
|
||||
@@ -59,6 +60,7 @@ public class SQLite extends Database {
|
||||
"`location_id` integer NOT NULL," +
|
||||
"`name` varchar(16) NOT NULL UNIQUE," +
|
||||
"`description` varchar(255) NOT NULL," +
|
||||
"`creation_time` timestamp NOT NULL," +
|
||||
"PRIMARY KEY (`location_id`)," +
|
||||
"FOREIGN KEY (`location_id`) REFERENCES " + HuskHomes.getSettings().getLocationsDataTable() + " (`location_id`) ON DELETE CASCADE ON UPDATE NO ACTION" +
|
||||
");"
|
||||
|
||||
@@ -64,7 +64,7 @@ public class PlayerListener implements Listener {
|
||||
HomeCommand.Tab.updatePlayerHomeCache(p);
|
||||
}
|
||||
|
||||
final Boolean isIgnoringRequests = DataManager.getPlayerIgnoringRequests(p, connection);
|
||||
final Boolean isIgnoringRequests = DataManager.isPlayerIgnoringRequests(p.getUniqueId(), connection);
|
||||
if (isIgnoringRequests != null) {
|
||||
if (isIgnoringRequests) {
|
||||
HuskHomes.setIgnoringTeleportRequests(p.getUniqueId());
|
||||
@@ -74,7 +74,7 @@ public class PlayerListener implements Listener {
|
||||
|
||||
// If bungee mode, check if the player joined the server from a teleport and act accordingly
|
||||
if (HuskHomes.getSettings().doBungee()) {
|
||||
final Boolean isTeleporting = DataManager.getPlayerTeleporting(p, connection);
|
||||
final Boolean isTeleporting = DataManager.isPlayerTeleporting(p.getUniqueId(), connection);
|
||||
if (isTeleporting != null) {
|
||||
if (isTeleporting) {
|
||||
TeleportManager.teleportPlayer(p);
|
||||
|
||||
@@ -113,7 +113,7 @@ public class PluginMessageListener implements org.bukkit.plugin.messaging.Plugin
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override @SuppressWarnings("UnstableApiUsage")
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||
// Return if the message is not a Bungee message
|
||||
if (!channel.equals("BungeeCord")) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Instant;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
@@ -94,7 +95,7 @@ public class EssentialsMigrator {
|
||||
continue;
|
||||
}
|
||||
DataManager.addHome(new Home(new TeleportationPoint(worldID, x, y, z, yaw, pitch, targetServer),
|
||||
playerName, playerUUID, homeName, homeDescription, false), playerUUID, connection);
|
||||
playerName, playerUUID, homeName, homeDescription, false, Instant.now().getEpochSecond()), playerUUID, connection);
|
||||
|
||||
plugin.getLogger().info("→ Migrated home " + homeName);
|
||||
} catch (NullPointerException | IllegalArgumentException e) {
|
||||
@@ -152,7 +153,7 @@ public class EssentialsMigrator {
|
||||
}
|
||||
|
||||
DataManager.addWarp(new Warp(new TeleportationPoint(worldID, x, y, z, yaw, pitch, targetServer),
|
||||
warpName, MessageManager.getRawMessage("warp_default_description")), connection);
|
||||
warpName, MessageManager.getRawMessage("warp_default_description"), Instant.now().getEpochSecond()), connection);
|
||||
plugin.getLogger().info("→ Migrated warp " + warpName);
|
||||
} catch (NullPointerException | IllegalArgumentException e) {
|
||||
plugin.getLogger().warning("✖ Failed to migrate warp " + warpFile.getName());
|
||||
|
||||
@@ -5,7 +5,8 @@ import org.bukkit.Bukkit;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
|
||||
public class UpgradeDatabase {
|
||||
|
||||
@@ -35,6 +36,36 @@ public class UpgradeDatabase {
|
||||
}
|
||||
});
|
||||
}
|
||||
if (plugin.getConfig().getInt("config_file_version", 1) <= 6) {
|
||||
plugin.getLogger().info("Detected that the database might need updating. Running database upgrade...");
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (PreparedStatement tableUpdateStatement = HuskHomes.getConnection().prepareStatement(
|
||||
"ALTER TABLE " + HuskHomes.getSettings().getHomesDataTable()
|
||||
+ " ADD `creation_time` timestamp NOT NULL DEFAULT ?;")) {
|
||||
tableUpdateStatement.setTimestamp(1, new Timestamp(Instant.now().getEpochSecond()));
|
||||
tableUpdateStatement.executeUpdate();
|
||||
plugin.getLogger().info("Database update complete!");
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().info("Skipped performing the database upgrade: " + e.getCause() + ". This might be because another server on your HuskHomes network already carried out the upgrade - in which case you can safely ignore this warning.");
|
||||
} finally {
|
||||
try (PreparedStatement tableUpdateStatement = HuskHomes.getConnection().prepareStatement(
|
||||
"ALTER TABLE " + HuskHomes.getSettings().getWarpsDataTable()
|
||||
+ " ADD `creation_time` timestamp NOT NULL DEFAULT ?;")) {
|
||||
tableUpdateStatement.setTimestamp(1, new Timestamp(Instant.now().getEpochSecond()));
|
||||
tableUpdateStatement.executeUpdate();
|
||||
plugin.getLogger().info("Database update complete!");
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().info("Skipped performing the database upgrade: " + e.getCause() + ". This might be because another server on your HuskHomes network already carried out the upgrade - in which case you can safely ignore this warning.");
|
||||
} finally {
|
||||
// Update the config file version
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
plugin.getConfig().set("config_file_version", 8);
|
||||
plugin.saveConfig();
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -138,7 +138,7 @@ public class TeleportManager {
|
||||
public static void queueRandomTeleport(Player player, Connection connection) throws SQLException {
|
||||
if (!player.hasPermission("huskhomes.rtp.bypass_cooldown")) {
|
||||
long currentTime = Instant.now().getEpochSecond();
|
||||
long coolDownTime = DataManager.getPlayerRtpCooldown(player, connection);
|
||||
long coolDownTime = DataManager.getPlayerRtpCoolDown(player, connection);
|
||||
if (currentTime < coolDownTime) {
|
||||
long timeRemaining = coolDownTime - currentTime;
|
||||
long timeRemainingMinutes = timeRemaining / 60;
|
||||
@@ -168,7 +168,7 @@ public class TeleportManager {
|
||||
}
|
||||
}
|
||||
teleportPlayer(player, randomPoint, connection);
|
||||
DataManager.updateRtpCooldown(player, connection);
|
||||
DataManager.updateRtpCoolDown(player, connection);
|
||||
return;
|
||||
}
|
||||
new TimedTeleport(player).begin();
|
||||
|
||||
@@ -127,7 +127,7 @@ public class TimedTeleport {
|
||||
}
|
||||
}
|
||||
TeleportManager.teleportPlayer(player, randomPoint, connection);
|
||||
DataManager.updateRtpCooldown(player, connection);
|
||||
DataManager.updateRtpCoolDown(player, connection);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
||||
@@ -13,12 +13,9 @@ import java.util.UUID;
|
||||
* An object representing a Player's home in-game
|
||||
* @author William
|
||||
*/
|
||||
public class Home extends TeleportationPoint {
|
||||
public class Home extends SetPoint {
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
private boolean isPublic;
|
||||
|
||||
private UUID ownerUUID;
|
||||
private String ownerUsername;
|
||||
|
||||
@@ -28,14 +25,12 @@ public class Home extends TeleportationPoint {
|
||||
* @param server The Bungee server ID of the home
|
||||
* @param homeOwner The Player who owns the home
|
||||
* @param name The name of the home
|
||||
* @param isPublic Whether or not the home is public
|
||||
* @param isPublic Whether the home is public
|
||||
*/
|
||||
public Home(Location location, String server, Player homeOwner, String name, boolean isPublic) {
|
||||
super(location, server);
|
||||
this.name = name;
|
||||
super(location, server, name, MessageManager.getRawMessage("home_default_description", homeOwner.getName()));
|
||||
this.ownerUUID = homeOwner.getUniqueId();
|
||||
this.ownerUsername = homeOwner.getName();
|
||||
this.description = MessageManager.getRawMessage("home_default_description", ownerUsername);
|
||||
this.isPublic = isPublic;
|
||||
}
|
||||
|
||||
@@ -47,14 +42,12 @@ public class Home extends TeleportationPoint {
|
||||
* @param ownerUUID The UUID string of the owner
|
||||
* @param name The name of the home
|
||||
* @param description The description of the home
|
||||
* @param isPublic Whether or not the home is public
|
||||
* @param isPublic Whether the home is public
|
||||
*/
|
||||
public Home(TeleportationPoint teleportationPoint, String ownerUsername, String ownerUUID, String name, String description, boolean isPublic) throws IllegalArgumentException {
|
||||
super(teleportationPoint.worldName, teleportationPoint.x, teleportationPoint.y, teleportationPoint.z, teleportationPoint.yaw, teleportationPoint.pitch, teleportationPoint.server);
|
||||
public Home(TeleportationPoint teleportationPoint, String ownerUsername, String ownerUUID, String name, String description, boolean isPublic, long creationTime) throws IllegalArgumentException {
|
||||
super(teleportationPoint.worldName, teleportationPoint.x, teleportationPoint.y, teleportationPoint.z, teleportationPoint.yaw, teleportationPoint.pitch, teleportationPoint.server, name, description, creationTime);
|
||||
this.ownerUsername = ownerUsername;
|
||||
this.ownerUUID = UUID.fromString(ownerUUID);
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.isPublic = isPublic;
|
||||
}
|
||||
|
||||
@@ -65,19 +58,17 @@ public class Home extends TeleportationPoint {
|
||||
* @param ownerUUID The {@link UUID} of the owner
|
||||
* @param name The name of the home
|
||||
* @param description The description of the home
|
||||
* @param isPublic Whether or not the home is public
|
||||
* @param isPublic Whether the home is public
|
||||
*/
|
||||
public Home(TeleportationPoint teleportationPoint, String ownerUsername, UUID ownerUUID, String name, String description, boolean isPublic) {
|
||||
super(teleportationPoint.worldName, teleportationPoint.x, teleportationPoint.y, teleportationPoint.z, teleportationPoint.yaw, teleportationPoint.pitch, teleportationPoint.server);
|
||||
public Home(TeleportationPoint teleportationPoint, String ownerUsername, UUID ownerUUID, String name, String description, boolean isPublic, long creationTime) {
|
||||
super(teleportationPoint.worldName, teleportationPoint.x, teleportationPoint.y, teleportationPoint.z, teleportationPoint.yaw, teleportationPoint.pitch, teleportationPoint.server, name, description, creationTime);
|
||||
this.ownerUsername = ownerUsername;
|
||||
this.ownerUUID = ownerUUID;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.isPublic = isPublic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the Home is public
|
||||
* Returns whether the Home is public
|
||||
* @return if the Home is public
|
||||
*/
|
||||
public boolean isPublic() {
|
||||
@@ -130,73 +121,41 @@ public class Home extends TeleportationPoint {
|
||||
this.ownerUsername = player.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the home
|
||||
* @return the Home name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of the home
|
||||
* @return the Home description
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the home
|
||||
* @param name the new Home name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the description of the home
|
||||
* @param description the new Home description
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
// Returns the maximum number of set homes a player can make
|
||||
public static int getSetHomeLimit(Player p) {
|
||||
p.recalculatePermissions();
|
||||
int maxSethomes = -1;
|
||||
int maxSetHomes = -1;
|
||||
for (PermissionAttachmentInfo permissionAI : p.getEffectivePermissions()) {
|
||||
String permission = permissionAI.getPermission();
|
||||
if (permission.contains("huskhomes.max_sethomes.")) {
|
||||
try {
|
||||
if (Integer.parseInt(permission.split("\\.")[2]) > maxSethomes) {
|
||||
maxSethomes = Integer.parseInt(permission.split("\\.")[2]);
|
||||
if (Integer.parseInt(permission.split("\\.")[2]) > maxSetHomes) {
|
||||
maxSetHomes = Integer.parseInt(permission.split("\\.")[2]);
|
||||
}
|
||||
} catch (Exception ignored) { }
|
||||
}
|
||||
}
|
||||
if (maxSethomes != -1) {
|
||||
return maxSethomes;
|
||||
if (maxSetHomes != -1) {
|
||||
return maxSetHomes;
|
||||
}
|
||||
return HuskHomes.getSettings().getMaximumHomes();
|
||||
}
|
||||
|
||||
// Returns the number of set homes a player can set for free
|
||||
public static int getFreeHomes(Player p) {
|
||||
int freeSethomes = -1;
|
||||
int freeSetHomes = -1;
|
||||
for (PermissionAttachmentInfo permissionAI : p.getEffectivePermissions()) {
|
||||
String permission = permissionAI.getPermission();
|
||||
if (permission.contains("huskhomes.free_sethomes.")) {
|
||||
try {
|
||||
if (Integer.parseInt(permission.split("\\.")[2]) > freeSethomes) {
|
||||
freeSethomes = Integer.parseInt(permission.split("\\.")[2]);
|
||||
if (Integer.parseInt(permission.split("\\.")[2]) > freeSetHomes) {
|
||||
freeSetHomes = Integer.parseInt(permission.split("\\.")[2]);
|
||||
}
|
||||
} catch(Exception ignored) { }
|
||||
}
|
||||
}
|
||||
if (freeSethomes != -1) {
|
||||
return freeSethomes;
|
||||
if (freeSetHomes != -1) {
|
||||
return freeSetHomes;
|
||||
}
|
||||
return HuskHomes.getSettings().getFreeHomeSlots();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package me.william278.huskhomes2.teleport.points;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.FormatStyle;
|
||||
import java.util.Locale;
|
||||
|
||||
public class SetPoint extends TeleportationPoint {
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
private final long creationTime;
|
||||
|
||||
public SetPoint(String worldName, double x, double y, double z, float yaw, float pitch, String server, String name, String description, long creationTime) {
|
||||
super(worldName, x, y, z, yaw, pitch, server);
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
|
||||
public SetPoint(Location location, String serverName, String name, String description) {
|
||||
super(location, serverName);
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.creationTime = Instant.now().getEpochSecond();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the point
|
||||
* @return the point name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of the point
|
||||
* @return the point description
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the point
|
||||
* @param name the new point name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the description of the point
|
||||
* @param description the new point description
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the creation time epoch seconds of the point
|
||||
*/
|
||||
public long getCreationTime() {
|
||||
return creationTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a formatted string displaying the time this point was created
|
||||
* @return The formatted creation time string
|
||||
*/
|
||||
public String getFormattedCreationTime() {
|
||||
return DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT)
|
||||
.withLocale(Locale.getDefault())
|
||||
.withZone(ZoneId.systemDefault())
|
||||
.format(Instant.ofEpochSecond(creationTime));
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,7 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
* An object representing an in-game warp
|
||||
* @author William
|
||||
*/
|
||||
public class Warp extends TeleportationPoint {
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
public class Warp extends SetPoint {
|
||||
|
||||
/**
|
||||
* An object representing an in-game warp
|
||||
@@ -23,9 +20,7 @@ public class Warp extends TeleportationPoint {
|
||||
* @param name The name of the Warp
|
||||
*/
|
||||
public Warp(Location location, String server, String name) {
|
||||
super(location, server);
|
||||
this.name = name;
|
||||
this.description = MessageManager.getRawMessage("warp_default_description");
|
||||
super(location, server, name, MessageManager.getRawMessage("warp_default_description"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,51 +29,17 @@ public class Warp extends TeleportationPoint {
|
||||
* @param name The name of the Warp
|
||||
* @param description The description of the Warp
|
||||
*/
|
||||
public Warp(TeleportationPoint teleportationPoint, String name, String description) {
|
||||
super(teleportationPoint.worldName, teleportationPoint.x, teleportationPoint.y, teleportationPoint.z, teleportationPoint.yaw, teleportationPoint.pitch, teleportationPoint.server);
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
public Warp(TeleportationPoint teleportationPoint, String name, String description, long creationTime) {
|
||||
super(teleportationPoint.worldName, teleportationPoint.x, teleportationPoint.y, teleportationPoint.z, teleportationPoint.yaw, teleportationPoint.pitch, teleportationPoint.server, name, description, creationTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description of the Warp
|
||||
* @return the Warp's description
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the Warp
|
||||
* @return the Warp's name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the Warp
|
||||
* @param name the new Warp name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the description of the Warp
|
||||
* @param description the new Warp description
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the player can use the warp
|
||||
* Whether the player can use the warp
|
||||
* @param player The player
|
||||
* @return boolean; whether or not they can use the warp
|
||||
* @return boolean; whether they can use the warp
|
||||
*/
|
||||
public boolean canUse(Player player) {
|
||||
return getWarpCanUse(player, name);
|
||||
return getWarpCanUse(player, getName());
|
||||
}
|
||||
|
||||
// Returns if the player has permission to access the warp
|
||||
|
||||
Reference in new issue
Block a user