mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 22:17:17 +00:00
Added cross-server teleportation handling
This commit is contained in:
1 parent
2aeab951c6
commit
879293237f
18 files changed
+823
-82
No files matched your search
+7
-3
@@ -4,17 +4,21 @@ import me.william278.huskhomes2.Main;
|
||||
import me.william278.huskhomes2.dataManager;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class HomeConditionsMet {
|
||||
public class SetHomeConditions {
|
||||
|
||||
boolean conditionsMet;
|
||||
String conditionsNotMetReason;
|
||||
|
||||
public HomeConditionsMet (Player player) {
|
||||
public SetHomeConditions(Player player, String homeName) {
|
||||
conditionsMet = false;
|
||||
if (dataManager.getPlayerHomeCount(player) > (Main.settings.getMaximumHomes()-1)) {
|
||||
conditionsMet = false;
|
||||
conditionsNotMetReason = "error_set_home_maximum_homes";
|
||||
return;
|
||||
}
|
||||
if (dataManager.homeExists(player, homeName)) {
|
||||
conditionsNotMetReason = "error_set_home_name_taken";
|
||||
return;
|
||||
}
|
||||
conditionsMet = true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package me.william278.huskhomes2.Objects;
|
||||
|
||||
import me.william278.huskhomes2.dataManager;
|
||||
|
||||
public class SetWarpConditions {
|
||||
|
||||
boolean conditionsMet;
|
||||
String conditionsNotMetReason;
|
||||
|
||||
public SetWarpConditions(String warpName) {
|
||||
conditionsMet = false;
|
||||
if (dataManager.warpExists(warpName)) {
|
||||
conditionsNotMetReason = "error_set_warp_name_taken";
|
||||
return;
|
||||
}
|
||||
conditionsMet = true;
|
||||
}
|
||||
|
||||
public boolean areConditionsMet() {
|
||||
return conditionsMet;
|
||||
}
|
||||
|
||||
public String getConditionsNotMetReason() {
|
||||
return conditionsNotMetReason;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@ public class Settings {
|
||||
String warpsTable;
|
||||
|
||||
int maximumHomes;
|
||||
int teleportRequestExpiryTime;
|
||||
int teleportWarmupTime;
|
||||
|
||||
boolean doBungee;
|
||||
|
||||
@@ -30,7 +32,9 @@ public class Settings {
|
||||
this.homesTable = configFile.getString("data_storage_options.table_names.home_data");
|
||||
this.warpsTable = configFile.getString("data_storage_options.table_names.warp_data");
|
||||
|
||||
this.maximumHomes = configFile.getInt("limits.max_sethomes");
|
||||
this.maximumHomes = configFile.getInt("general.max_sethomes");
|
||||
this.teleportRequestExpiryTime = configFile.getInt("general.teleport_request_expiry_time");
|
||||
this.teleportWarmupTime = configFile.getInt("general.teleport_warmup_time");
|
||||
|
||||
}
|
||||
|
||||
@@ -38,6 +42,10 @@ public class Settings {
|
||||
setSettings(configFile);
|
||||
}
|
||||
|
||||
public int getTeleportWarmupTime() {
|
||||
return teleportWarmupTime;
|
||||
}
|
||||
|
||||
public void reloadSettings(FileConfiguration configFile) {
|
||||
setSettings(configFile);
|
||||
}
|
||||
@@ -75,4 +83,7 @@ public class Settings {
|
||||
}
|
||||
|
||||
public int getMaximumHomes() { return maximumHomes; }
|
||||
|
||||
public int getTeleportRequestExpiryTime() { return teleportRequestExpiryTime; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package me.william278.huskhomes2.Objects;
|
||||
|
||||
import me.william278.huskhomes2.Main;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public class TeleportRequest {
|
||||
|
||||
String senderName;
|
||||
long requestExpiryTime;
|
||||
String requestType;
|
||||
|
||||
public TeleportRequest(String senderName, String requestType) {
|
||||
this.senderName = senderName;
|
||||
if (requestType.equalsIgnoreCase("tpa") || requestType.equalsIgnoreCase("tpahere")) {
|
||||
this.requestType = requestType.toLowerCase();
|
||||
}
|
||||
long currentUnixTime = Instant.now().getEpochSecond();
|
||||
requestExpiryTime = currentUnixTime + Main.settings.getTeleportRequestExpiryTime();
|
||||
}
|
||||
|
||||
public String getSenderName() {
|
||||
return senderName;
|
||||
}
|
||||
|
||||
public String getRequestType() {
|
||||
return requestType;
|
||||
}
|
||||
|
||||
public boolean getExpired() {
|
||||
long currentUnixTime = Instant.now().getEpochSecond();
|
||||
return currentUnixTime > requestExpiryTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package me.william278.huskhomes2.Objects;
|
||||
|
||||
import me.william278.huskhomes2.Main;
|
||||
import me.william278.huskhomes2.messageManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TimedTeleport {
|
||||
|
||||
String targetType; // "player" or "point"
|
||||
|
||||
TeleportationPoint targetPoint;
|
||||
String targetPlayerName;
|
||||
|
||||
Player teleporter;
|
||||
Location initialTeleporterLocation;
|
||||
double initialTeleporterHealth;
|
||||
|
||||
int timeRemaining;
|
||||
final int warmupTime = Main.settings.getTeleportWarmupTime();
|
||||
|
||||
public TimedTeleport(Player teleporter, TeleportationPoint targetPoint) {
|
||||
this.teleporter = teleporter;
|
||||
this.initialTeleporterLocation = teleporter.getLocation();
|
||||
this.initialTeleporterHealth = teleporter.getHealth();
|
||||
this.targetType = "point";
|
||||
this.targetPoint = targetPoint;
|
||||
this.timeRemaining = warmupTime;
|
||||
|
||||
messageManager.sendMessage(teleporter, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
||||
messageManager.sendMessage(teleporter, "teleporting_please_stand_still");
|
||||
}
|
||||
|
||||
public TimedTeleport(Player teleporter, String targetPlayerName) {
|
||||
this.teleporter = teleporter;
|
||||
this.initialTeleporterLocation = teleporter.getLocation();
|
||||
this.initialTeleporterHealth = teleporter.getHealth();
|
||||
this.targetType = "player";
|
||||
this.targetPlayerName = targetPlayerName;
|
||||
this.timeRemaining = warmupTime;
|
||||
|
||||
messageManager.sendMessage(teleporter, "teleporting_countdown_start", Integer.toString(this.warmupTime));
|
||||
messageManager.sendMessage(teleporter, "teleporting_please_stand_still");
|
||||
}
|
||||
|
||||
public String getTargetType() {
|
||||
return targetType;
|
||||
}
|
||||
|
||||
public TeleportationPoint getTargetPoint() {
|
||||
return targetPoint;
|
||||
}
|
||||
|
||||
public String getTargetPlayerName() {
|
||||
return targetPlayerName;
|
||||
}
|
||||
|
||||
// This converts a negative to a positive double, used in checking if a player has moved
|
||||
private static double makePositive(double d) {
|
||||
if (d < 0) {
|
||||
d = d * -1D;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
// This returns if the player has lost health during a timed teleport
|
||||
public boolean hasLostHealth(Player p) {
|
||||
return p.getHealth() < initialTeleporterHealth;
|
||||
}
|
||||
|
||||
// This returns if the player has moved during a timed teleport
|
||||
public boolean hasMoved(Player p) {
|
||||
Location currentLocation = p.getLocation();
|
||||
final double movementThreshold = 0.1;
|
||||
|
||||
double xDiff = makePositive(initialTeleporterLocation.getX() - currentLocation.getX());
|
||||
double yDiff = makePositive(initialTeleporterLocation.getY() - currentLocation.getY());
|
||||
double zDiff = makePositive(initialTeleporterLocation.getZ() - currentLocation.getZ());
|
||||
double totalDiff = xDiff + yDiff + zDiff;
|
||||
|
||||
return totalDiff > movementThreshold;
|
||||
}
|
||||
|
||||
public Player getTeleporter() {
|
||||
return teleporter;
|
||||
}
|
||||
|
||||
public int getTimeRemaining() {
|
||||
return timeRemaining;
|
||||
}
|
||||
|
||||
public void decrementTimeRemaining() {
|
||||
timeRemaining = timeRemaining - 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,8 +2,6 @@ package me.william278.huskhomes2.Objects;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Warp extends TeleportationPoint {
|
||||
|
||||
String name;
|
||||
|
||||
Reference in new issue
Block a user