Refactoring, improve database system and add creation timestamp to homes and warps

This commit is contained in:
William committed 2021-08-10 13:43:11 +01:00
1 parent 58eeab20c5
commit 98893814f7
24 files changed
+549 -657

No files matched your search

@@ -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