mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 22:16:34 +00:00
Much renaming and some movement
This commit is contained in:
69 files changed
+621
-606
No files matched your search
@@ -0,0 +1,143 @@
|
||||
package me.william278.huskhomes2.teleport;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* An object representing a Player's home in-game
|
||||
* @author William
|
||||
*/
|
||||
public class Home extends TeleportationPoint {
|
||||
|
||||
String name;
|
||||
String description;
|
||||
boolean isPublic;
|
||||
|
||||
UUID ownerUUID;
|
||||
String ownerUsername;
|
||||
|
||||
/**
|
||||
* An object representing a Player's home in-game
|
||||
* @param location The Bukkit location of the home
|
||||
* @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
|
||||
*/
|
||||
public Home(Location location, String server, Player homeOwner, String name, boolean isPublic) {
|
||||
super(location, server);
|
||||
this.name = name;
|
||||
this.ownerUUID = homeOwner.getUniqueId();
|
||||
this.ownerUsername = homeOwner.getName();
|
||||
this.description = ownerUsername + "'s home";
|
||||
this.isPublic = isPublic;
|
||||
}
|
||||
|
||||
/**
|
||||
* An object representing a Player's home in-game
|
||||
* @param teleportationPoint The position of the home
|
||||
* @param ownerUsername The username of the owner
|
||||
* @param ownerUUID The 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
|
||||
*/
|
||||
public Home(TeleportationPoint teleportationPoint, String ownerUsername, String ownerUUID, String name, String description, boolean isPublic) {
|
||||
super(teleportationPoint.worldName, teleportationPoint.x, teleportationPoint.y, teleportationPoint.z, teleportationPoint.yaw, teleportationPoint.pitch, teleportationPoint.server);
|
||||
this.ownerUsername = ownerUsername;
|
||||
this.ownerUUID = UUID.fromString(ownerUUID);
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.isPublic = isPublic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the Home is public
|
||||
* @return if the Home is public
|
||||
*/
|
||||
public boolean isPublic() {
|
||||
return isPublic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the privacy of the home
|
||||
* @param isPublic should the home be public?
|
||||
*/
|
||||
public void setPublic(boolean isPublic) {
|
||||
this.isPublic = isPublic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the UUID of the Home's owner
|
||||
* @return the owner's UUID
|
||||
*/
|
||||
public UUID getOwnerUUID() {
|
||||
return ownerUUID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the username of the Home's owner
|
||||
* @return the owner's username
|
||||
*/
|
||||
public String getOwnerUsername() {
|
||||
return ownerUsername;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Player who owns the home
|
||||
* @return the Player owner of the home
|
||||
*/
|
||||
public Player getOwner() {
|
||||
Player player = Bukkit.getPlayer(ownerUUID);
|
||||
if (player != null) {
|
||||
return player;
|
||||
} else {
|
||||
throw new IllegalStateException("The home owner is not online");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the owner of the home
|
||||
* @param player The new owner of the home
|
||||
*/
|
||||
public void setOwner(Player player) {
|
||||
this.ownerUUID = player.getUniqueId();
|
||||
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.name = description;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package me.william278.huskhomes2.teleport;
|
||||
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.MessageManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
|
||||
public class RandomPoint extends TeleportationPoint {
|
||||
|
||||
// List containing all unsafe blocks
|
||||
final static HashSet<Material> unsafeBlocks = new HashSet<>();
|
||||
|
||||
// Maximum number of attempts to find a random location
|
||||
final static int maxRandomAttempts = 8;
|
||||
|
||||
static {
|
||||
unsafeBlocks.add(Material.LAVA);
|
||||
unsafeBlocks.add(Material.FIRE);
|
||||
unsafeBlocks.add(Material.CACTUS);
|
||||
unsafeBlocks.add(Material.WATER);
|
||||
unsafeBlocks.add(Material.MAGMA_BLOCK);
|
||||
unsafeBlocks.add(Material.JUNGLE_LEAVES);
|
||||
unsafeBlocks.add(Material.SPRUCE_LEAVES);
|
||||
unsafeBlocks.add(Material.OAK_LEAVES);
|
||||
unsafeBlocks.add(Material.BIRCH_LEAVES);
|
||||
unsafeBlocks.add(Material.ACACIA_LEAVES);
|
||||
unsafeBlocks.add(Material.DARK_OAK_LEAVES);
|
||||
unsafeBlocks.add(Material.OBSIDIAN);
|
||||
}
|
||||
|
||||
private Location randomLocation(World world) {
|
||||
// Generate a random location
|
||||
Random random = new Random();
|
||||
|
||||
int x;
|
||||
int y = 64;
|
||||
int z;
|
||||
double blockCenterX = 0.5;
|
||||
double blockCenterZ = 0.5;
|
||||
int negativeX;
|
||||
int negativeZ;
|
||||
|
||||
// The furthest distance at which a player can be teleported to
|
||||
int rtpRange = HuskHomes.settings.getRtpRange();
|
||||
|
||||
// Calculate random X and Z coords
|
||||
x = random.nextInt(rtpRange);
|
||||
z = random.nextInt(rtpRange);
|
||||
|
||||
// Determine if the plugin should teleport to positive or negative Z
|
||||
negativeX = random.nextInt(2);
|
||||
negativeZ = random.nextInt(2);
|
||||
if (negativeX == 1) {
|
||||
x = x * -1;
|
||||
blockCenterX = blockCenterX * -1;
|
||||
}
|
||||
if (negativeZ == 1) {
|
||||
z = z * -1;
|
||||
blockCenterZ = blockCenterZ * -1;
|
||||
}
|
||||
|
||||
// Put together random location, get the highest block plus one to determine Y
|
||||
Location randomLocation = new Location(world, (x + blockCenterX), y, (z + blockCenterZ));
|
||||
y = world.getHighestBlockYAt(randomLocation) + 1;
|
||||
randomLocation.setY(y);
|
||||
|
||||
return randomLocation;
|
||||
}
|
||||
|
||||
// Checks to see if the location is safe to teleport to
|
||||
private boolean isLocationSafe(Location location){
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY()-1;
|
||||
int z = location.getBlockZ();
|
||||
|
||||
World world = location.getWorld();
|
||||
|
||||
// Failsafe check in case the world is null
|
||||
if (world != null) {
|
||||
|
||||
// Get instances of the blocks around where the player would spawn
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
Block below = world.getBlockAt(x, y - 1, z);
|
||||
Block above = world.getBlockAt(x, y + 1, z);
|
||||
|
||||
// Check to see if those blocks are safe to teleport to
|
||||
if (!unsafeBlocks.contains(block.getType()) && block.getType().isSolid()) {
|
||||
if (!unsafeBlocks.contains(above.getType())) {
|
||||
return !unsafeBlocks.contains(below.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Location getRandomLocation(World world) {
|
||||
Location randomLocation = randomLocation(world);
|
||||
|
||||
int attempts = 0;
|
||||
|
||||
// Keep looking for a random location that is safe
|
||||
while (!isLocationSafe(randomLocation)){
|
||||
|
||||
// Failsafe timeout in case the plugin can't find a safe location within a number of tries.
|
||||
if (attempts < maxRandomAttempts) {
|
||||
randomLocation = randomLocation(world);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
attempts = attempts + 1;
|
||||
}
|
||||
return randomLocation;
|
||||
}
|
||||
|
||||
public RandomPoint(Player player) {
|
||||
super(player.getLocation(), HuskHomes.settings.getServerID());
|
||||
Location randomLocation = getRandomLocation(player.getWorld());
|
||||
if (randomLocation != null) {
|
||||
setLocation(randomLocation, HuskHomes.settings.getServerID());
|
||||
} else {
|
||||
MessageManager.sendMessage(player, "error_rtp_randomization_timeout");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package me.william278.huskhomes2.teleport;
|
||||
|
||||
import me.william278.huskhomes2.integrations.VaultIntegration;
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.data.DataManager;
|
||||
import me.william278.huskhomes2.MessageManager;
|
||||
import me.william278.huskhomes2.PermissionHomeLimits;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SetHomeConditions {
|
||||
|
||||
private boolean conditionsMet;
|
||||
private String conditionsNotMetReason;
|
||||
|
||||
public SetHomeConditions(Player player, String homeName) {
|
||||
conditionsMet = false;
|
||||
int currentHomeCount = DataManager.getPlayerHomeCount(player);
|
||||
if (currentHomeCount > (PermissionHomeLimits.getSetHomeLimit(player) - 1)) {
|
||||
conditionsNotMetReason = "error_set_home_maximum_homes";
|
||||
return;
|
||||
}
|
||||
if (DataManager.homeExists(player, homeName)) {
|
||||
conditionsNotMetReason = "error_set_home_name_taken";
|
||||
return;
|
||||
}
|
||||
if (homeName.length() > 16) {
|
||||
conditionsNotMetReason = "error_set_home_invalid_length";
|
||||
return;
|
||||
}
|
||||
if (!homeName.matches("[A-Za-z0-9_\\-]+")) {
|
||||
conditionsNotMetReason = "error_set_home_invalid_characters";
|
||||
return;
|
||||
}
|
||||
if (HuskHomes.settings.doEconomy()) {
|
||||
double setHomeCost = HuskHomes.settings.getSetHomeCost();
|
||||
if (setHomeCost > 0) {
|
||||
int currentPlayerHomeSlots = DataManager.getPlayerHomeSlots(player);
|
||||
if (currentHomeCount > (currentPlayerHomeSlots - 1)) {
|
||||
if (!VaultIntegration.takeMoney(player, setHomeCost)) {
|
||||
conditionsNotMetReason = "error_insufficient_funds";
|
||||
return;
|
||||
} else {
|
||||
DataManager.incrementPlayerHomeSlots(player);
|
||||
MessageManager.sendMessage(player, "set_home_spent_money", VaultIntegration.format(setHomeCost));
|
||||
}
|
||||
} else if (currentHomeCount == (currentPlayerHomeSlots - 1)) {
|
||||
MessageManager.sendMessage(player, "set_home_used_free_slots", Integer.toString(PermissionHomeLimits.getFreeHomes(player)), VaultIntegration.format(setHomeCost));
|
||||
}
|
||||
}
|
||||
}
|
||||
conditionsMet = true;
|
||||
}
|
||||
|
||||
public boolean areConditionsMet() {
|
||||
return conditionsMet;
|
||||
}
|
||||
|
||||
public String getConditionsNotMetReason() {
|
||||
return conditionsNotMetReason;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package me.william278.huskhomes2.teleport;
|
||||
|
||||
import me.william278.huskhomes2.data.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;
|
||||
}
|
||||
if (warpName.length() > 16) {
|
||||
conditionsNotMetReason = "error_set_warp_invalid_length";
|
||||
return;
|
||||
}
|
||||
if (!warpName.matches("[A-Za-z0-9_\\-]+")) {
|
||||
conditionsNotMetReason = "error_set_warp_invalid_characters";
|
||||
return;
|
||||
}
|
||||
conditionsMet = true;
|
||||
}
|
||||
|
||||
public boolean areConditionsMet() {
|
||||
return conditionsMet;
|
||||
}
|
||||
|
||||
public String getConditionsNotMetReason() {
|
||||
return conditionsNotMetReason;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package me.william278.huskhomes2.teleport;
|
||||
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.data.DataManager;
|
||||
import me.william278.huskhomes2.integrations.VaultIntegration;
|
||||
import me.william278.huskhomes2.MessageManager;
|
||||
import me.william278.huskhomes2.PluginMessageHandler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class TeleportManager {
|
||||
|
||||
public static HashSet<TimedTeleport> queuedTeleports = new HashSet<>();
|
||||
|
||||
public static TeleportationPoint spawnLocation = null;
|
||||
|
||||
public static void teleportPlayer(Player player, String targetPlayer) {
|
||||
DataManager.setPlayerLastPosition(player, new TeleportationPoint(player.getLocation(), HuskHomes.settings.getServerID()));
|
||||
setPlayerDestinationFromTargetPlayer(player, targetPlayer);
|
||||
}
|
||||
|
||||
public static void teleportPlayer(Player player, TeleportationPoint point) {
|
||||
DataManager.setPlayerLastPosition(player, new TeleportationPoint(player.getLocation(), HuskHomes.settings.getServerID()));
|
||||
DataManager.setPlayerDestinationLocation(player, point);
|
||||
teleportPlayer(player);
|
||||
}
|
||||
|
||||
public static void teleportPlayer(Player p) {
|
||||
TeleportationPoint teleportationPoint = DataManager.getPlayerDestination(p);
|
||||
if (teleportationPoint != null) {
|
||||
String server = teleportationPoint.getServer();
|
||||
if (!HuskHomes.settings.doBungee() || server.equals(HuskHomes.settings.getServerID())) {
|
||||
p.teleport(teleportationPoint.getLocation());
|
||||
p.playSound(p.getLocation(), HuskHomes.settings.getTeleportationCompleteSound(), 1, 1);
|
||||
MessageManager.sendMessage(p, "teleporting_complete");
|
||||
DataManager.setPlayerTeleporting(p, false);
|
||||
DataManager.clearPlayerDestination(p.getName());
|
||||
} else if (HuskHomes.settings.doBungee()) {
|
||||
DataManager.setPlayerDestinationLocation(p, teleportationPoint);
|
||||
DataManager.setPlayerTeleporting(p, true);
|
||||
PluginMessageHandler.sendPlayer(p, server);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void queueTimedTeleport(Player player, String targetPlayer) {
|
||||
if (player.hasPermission("huskhomes.bypass_timer")) {
|
||||
teleportPlayer(player, targetPlayer);
|
||||
return;
|
||||
}
|
||||
|
||||
queuedTeleports.add(new TimedTeleport(player, targetPlayer));
|
||||
}
|
||||
|
||||
public static void queueTimedTeleport(Player player, TeleportationPoint point) {
|
||||
if (player.hasPermission("huskhomes.bypass_timer")) {
|
||||
teleportPlayer(player, point);
|
||||
return;
|
||||
}
|
||||
|
||||
queuedTeleports.add(new TimedTeleport(player, point));
|
||||
}
|
||||
|
||||
public static void queueRandomTeleport(Player player) {
|
||||
if (!player.hasPermission("huskhomes.rtp.bypass_cooldown")) {
|
||||
long currentTime = Instant.now().getEpochSecond();
|
||||
long cooldownTime = DataManager.getPlayerRtpCooldown(player);
|
||||
if (currentTime < cooldownTime) {
|
||||
long timeRemaining = cooldownTime - currentTime;
|
||||
long timeRemainingMinutes = timeRemaining / 60;
|
||||
MessageManager.sendMessage(player, "error_rtp_cooldown", Long.toString(timeRemainingMinutes));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (HuskHomes.settings.doEconomy()) {
|
||||
double rtpCost = HuskHomes.settings.getRtpCost();
|
||||
if (rtpCost > 0) {
|
||||
if (!VaultIntegration.hasMoney(player, rtpCost)) {
|
||||
MessageManager.sendMessage(player, "error_insufficient_funds", VaultIntegration.format(rtpCost));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (player.hasPermission("huskhomes.bypass_timer")) {
|
||||
if (HuskHomes.settings.doEconomy()) {
|
||||
double rtpCost = HuskHomes.settings.getRtpCost();
|
||||
if (rtpCost > 0) {
|
||||
VaultIntegration.takeMoney(player, rtpCost);
|
||||
MessageManager.sendMessage(player, "rtp_spent_money", VaultIntegration.format(rtpCost));
|
||||
}
|
||||
}
|
||||
teleportPlayer(player, new RandomPoint(player));
|
||||
DataManager.updateRtpCooldown(player);
|
||||
return;
|
||||
}
|
||||
|
||||
queuedTeleports.add(new TimedTeleport(player));
|
||||
}
|
||||
|
||||
public static void teleportHere(Player requester, String targetPlayerName) {
|
||||
Player targetPlayer = Bukkit.getPlayer(targetPlayerName);
|
||||
if (targetPlayer != null) {
|
||||
if (targetPlayer.getUniqueId() != requester.getUniqueId()) {
|
||||
teleportPlayer(targetPlayer, requester.getName());
|
||||
} else {
|
||||
MessageManager.sendMessage(requester, "error_tp_self");
|
||||
}
|
||||
} else {
|
||||
if (HuskHomes.settings.doBungee()) {
|
||||
teleportHereCrossServer(requester, targetPlayerName);
|
||||
} else {
|
||||
MessageManager.sendMessage(requester, "error_player_not_found", targetPlayerName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void teleportHereCrossServer(Player requester, String targetPlayerName) {
|
||||
PluginMessageHandler.sendPluginMessage(requester, targetPlayerName, "teleport_to_me", requester.getName());
|
||||
}
|
||||
|
||||
private static void setTeleportationDestinationCrossServer(Player requester, String targetPlayerName) {
|
||||
PluginMessageHandler.sendPluginMessage(requester, targetPlayerName, "set_tp_destination", requester.getName());
|
||||
}
|
||||
|
||||
public static void setPlayerDestinationFromTargetPlayer(Player requester, String targetPlayerName) {
|
||||
Player targetPlayer = Bukkit.getPlayer(targetPlayerName);
|
||||
if (targetPlayer != null) {
|
||||
if (requester.getUniqueId() != targetPlayer.getUniqueId()) {
|
||||
DataManager.setPlayerDestinationLocation(requester,
|
||||
new TeleportationPoint(targetPlayer.getLocation(), HuskHomes.settings.getServerID()));
|
||||
teleportPlayer(requester);
|
||||
} else {
|
||||
MessageManager.sendMessage(requester, "error_tp_self");
|
||||
}
|
||||
} else {
|
||||
if (HuskHomes.settings.doBungee()) {
|
||||
setTeleportationDestinationCrossServer(requester, targetPlayerName);
|
||||
} else {
|
||||
MessageManager.sendMessage(requester, "error_player_not_found", targetPlayerName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package me.william278.huskhomes2.teleport;
|
||||
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
|
||||
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 + HuskHomes.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,153 @@
|
||||
package me.william278.huskhomes2.teleport;
|
||||
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.integrations.VanishChecker;
|
||||
import me.william278.huskhomes2.MessageManager;
|
||||
import me.william278.huskhomes2.PluginMessageHandler;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class TeleportRequestHandler {
|
||||
|
||||
// Target player and teleport request to them hashmap
|
||||
public static HashMap<Player, TeleportRequest> teleportRequests = new HashMap<>();
|
||||
|
||||
private static void sendTeleportRequestCrossServer(Player requester, String targetPlayerName, String teleportRequestType) {
|
||||
String pluginMessage = teleportRequestType + "_request";
|
||||
PluginMessageHandler.sendPluginMessage(requester, targetPlayerName, pluginMessage, requester.getName());
|
||||
}
|
||||
|
||||
private static void replyTeleportRequestCrossServer(Player replier, String requesterName, String teleportRequestType, boolean accepted) {
|
||||
String pluginMessage = teleportRequestType + "_request_reply";
|
||||
PluginMessageHandler.sendPluginMessage(replier, requesterName, pluginMessage, replier.getName() + ":" + accepted);
|
||||
}
|
||||
|
||||
public static TextComponent createButton(String buttonText, net.md_5.bungee.api.ChatColor color, ClickEvent.Action actionType, String command, String hoverMessage, net.md_5.bungee.api.ChatColor hoverMessageColor, Boolean hoverMessageItalic) {
|
||||
TextComponent button = new TextComponent(buttonText);
|
||||
button.setColor(color);
|
||||
|
||||
button.setClickEvent(new ClickEvent(actionType, (command)));
|
||||
button.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(new ComponentBuilder(hoverMessage).color(hoverMessageColor).italic(hoverMessageItalic).create())));
|
||||
return button;
|
||||
}
|
||||
|
||||
public static void sendTpAcceptDenyButtons(Player p) {
|
||||
// Send the "Accept" or "Decline" response buttons to the player who has received a request
|
||||
// Options text
|
||||
TextComponent options = new TextComponent(MessageManager.getRawMessage("tpa_request_buttons_prompt"));
|
||||
options.setColor(net.md_5.bungee.api.ChatColor.GRAY);
|
||||
|
||||
TextComponent separator = new TextComponent(MessageManager.getRawMessage("list_item_divider"));
|
||||
separator.setColor(net.md_5.bungee.api.ChatColor.GRAY);
|
||||
|
||||
// Build the components together
|
||||
ComponentBuilder teleportResponses = new ComponentBuilder();
|
||||
teleportResponses.append(options);
|
||||
teleportResponses.append(createButton(MessageManager.getRawMessage("tpa_accept_button"), net.md_5.bungee.api.ChatColor.GREEN, ClickEvent.Action.RUN_COMMAND, "/tpaccept", MessageManager.getRawMessage("tpa_accept_button_tooltip"), net.md_5.bungee.api.ChatColor.GRAY, false));
|
||||
teleportResponses.append(separator);
|
||||
teleportResponses.append(createButton(MessageManager.getRawMessage("tpa_decline_button"), net.md_5.bungee.api.ChatColor.RED, ClickEvent.Action.RUN_COMMAND, "/tpdeny", MessageManager.getRawMessage("tpa_decline_button_tooltip"), net.md_5.bungee.api.ChatColor.GRAY, false));
|
||||
|
||||
// Create and send the message
|
||||
p.spigot().sendMessage(teleportResponses.create());
|
||||
}
|
||||
|
||||
public static void sendTeleportToRequest(Player requester, String targetPlayerName) {
|
||||
Player targetPlayer = Bukkit.getPlayer(targetPlayerName);
|
||||
if (targetPlayer != null) {
|
||||
if (targetPlayer.getUniqueId() != requester.getUniqueId()) {
|
||||
if (!VanishChecker.isVanished(targetPlayer)) {
|
||||
teleportRequests.put(targetPlayer, new TeleportRequest(requester.getName(), "tpa"));
|
||||
MessageManager.sendMessage(requester, "tpa_request_sent", targetPlayerName);
|
||||
MessageManager.sendMessage(targetPlayer, "tpa_request_ask", requester.getName());
|
||||
TeleportRequestHandler.sendTpAcceptDenyButtons(targetPlayer);
|
||||
} else {
|
||||
MessageManager.sendMessage(requester, "error_player_not_found", targetPlayerName);
|
||||
}
|
||||
} else {
|
||||
MessageManager.sendMessage(requester, "error_tp_self");
|
||||
}
|
||||
} else {
|
||||
if (HuskHomes.settings.doBungee()) {
|
||||
sendTeleportRequestCrossServer(requester, targetPlayerName, "tpa");
|
||||
MessageManager.sendMessage(requester, "tpa_request_sent", targetPlayerName);
|
||||
} else {
|
||||
MessageManager.sendMessage(requester, "error_player_not_found", targetPlayerName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendTeleportHereRequest(Player requester, String targetPlayerName) {
|
||||
Player targetPlayer = Bukkit.getPlayer(targetPlayerName);
|
||||
if (targetPlayer != null) {
|
||||
if (targetPlayer.getUniqueId() != requester.getUniqueId()) {
|
||||
teleportRequests.put(targetPlayer, new TeleportRequest(requester.getName(), "tpahere"));
|
||||
MessageManager.sendMessage(requester, "tpahere_request_sent", targetPlayerName);
|
||||
MessageManager.sendMessage(targetPlayer, "tpahere_request_ask", requester.getName());
|
||||
TeleportRequestHandler.sendTpAcceptDenyButtons(targetPlayer);
|
||||
} else {
|
||||
MessageManager.sendMessage(requester, "error_tp_self");
|
||||
}
|
||||
} else {
|
||||
if (HuskHomes.settings.doBungee()) {
|
||||
sendTeleportRequestCrossServer(requester, targetPlayerName, "tpahere");
|
||||
MessageManager.sendMessage(requester, "tpahere_request_sent", targetPlayerName);
|
||||
} else {
|
||||
MessageManager.sendMessage(requester, "error_player_not_found", targetPlayerName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void replyTpRequest(Player p, boolean accepted) {
|
||||
if (!teleportRequests.containsKey(p)) {
|
||||
MessageManager.sendMessage(p, "error_tpa_no_pending_request");
|
||||
return;
|
||||
}
|
||||
TeleportRequest teleportRequest = teleportRequests.get(p);
|
||||
String requesterName = teleportRequest.getSenderName();
|
||||
String requestType = teleportRequest.getRequestType();
|
||||
Player requester = Bukkit.getPlayer(requesterName);
|
||||
|
||||
if (requester != null) {
|
||||
if (accepted) {
|
||||
MessageManager.sendMessage(p, "tpa_you_accepted", requesterName);
|
||||
MessageManager.sendMessage(requester, "tpa_has_accepted", p.getName());
|
||||
|
||||
if (requestType.equals("tpa")) {
|
||||
TeleportManager.queueTimedTeleport(requester, p.getName());
|
||||
} else if (requestType.equals("tpahere")) {
|
||||
TeleportManager.queueTimedTeleport(p, requesterName);
|
||||
}
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "tpa_you_declined", requesterName);
|
||||
MessageManager.sendMessage(requester, "tpa_has_declined", p.getName());
|
||||
}
|
||||
} else {
|
||||
if (HuskHomes.settings.doBungee()) {
|
||||
if (accepted) {
|
||||
MessageManager.sendMessage(p, "tpa_you_accepted", requesterName);
|
||||
|
||||
if (requestType.equals("tpa")) {
|
||||
replyTeleportRequestCrossServer(p, requesterName, "tpa", true);
|
||||
} else if (requestType.equals("tpahere")) {
|
||||
replyTeleportRequestCrossServer(p, requesterName, "tpahere", true);
|
||||
TeleportManager.queueTimedTeleport(p, requesterName);
|
||||
}
|
||||
} else {
|
||||
replyTeleportRequestCrossServer(p, requesterName, requestType, false);
|
||||
MessageManager.sendMessage(p, "tpa_you_declined", requesterName);
|
||||
}
|
||||
} else {
|
||||
MessageManager.sendMessage(p, "error_player_not_found", requesterName);
|
||||
}
|
||||
}
|
||||
teleportRequests.remove(p);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package me.william278.huskhomes2.teleport;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
/**
|
||||
* @author William
|
||||
* HuskHomes' position representation object; represents an in-game location on a server
|
||||
*/
|
||||
public class TeleportationPoint {
|
||||
|
||||
String server;
|
||||
String worldName;
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
float yaw;
|
||||
float pitch;
|
||||
|
||||
/**
|
||||
* Update the location of a TeleportationPoint
|
||||
* @param location a new Bukkit location
|
||||
* @param server a new Bungee server ID
|
||||
*/
|
||||
public void setLocation(Location location, String server) {
|
||||
worldName = location.getWorld().getName();
|
||||
x = location.getX();
|
||||
y = location.getY();
|
||||
z = location.getZ();
|
||||
yaw = location.getYaw();
|
||||
pitch = location.getPitch();
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
/**
|
||||
* HuskHomes' position representation object; represents an in-game location on a server
|
||||
* @param location The Bukkit location
|
||||
* @param server The Bungee server ID which the location is on
|
||||
*/
|
||||
public TeleportationPoint(Location location, String server) {
|
||||
if (location.getWorld() == null) {
|
||||
throw new IllegalStateException("The location provided has an invalid world");
|
||||
}
|
||||
setLocation(location, server);
|
||||
}
|
||||
|
||||
/**
|
||||
* HuskHomes' position representation object; represents an in-game location on a server
|
||||
* @param worldName The name of the location's world
|
||||
* @param x The location's x-coordinate
|
||||
* @param y The location's y-coordinate
|
||||
* @param z The location's z-coordinate
|
||||
* @param yaw The location's yaw angle
|
||||
* @param pitch The location's pitch angle
|
||||
* @param server The Bungee server ID which the location is on
|
||||
*/
|
||||
public TeleportationPoint(String worldName, double x, double y, double z, float yaw, float pitch, String server) {
|
||||
this.server = server;
|
||||
this.worldName = worldName;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Bukkit location from a TeleportationPoint
|
||||
* @return the Bukkit location on the server from a TeleportationPoint
|
||||
* @throws IllegalStateException if the location is not valid on the server
|
||||
*/
|
||||
public Location getLocation() {
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world != null) {
|
||||
return new Location(world, x, y, z, yaw, pitch);
|
||||
} else {
|
||||
throw new IllegalStateException("The world \"" + worldName + "\" could not be found on the server; could not return location");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the world from a TeleportationPoint
|
||||
* @return the name of the world the position is on from a TeleportationPoint
|
||||
*/
|
||||
public String getWorldName() {
|
||||
return worldName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Bungee server ID from a TeleportationPoint
|
||||
* @return the TeleportationPoint's Bungee server ID
|
||||
*/
|
||||
public String getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the x-coordinate of a TeleportationPoint
|
||||
* @return the x-coordinate
|
||||
*/
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the y-coordinate of a TeleportationPoint
|
||||
* @return the y-coordinate
|
||||
*/
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the z-coordinate of a TeleportationPoint
|
||||
* @return the z-coordinate
|
||||
*/
|
||||
public double getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the yaw angle of a TeleportationPoint
|
||||
* @return the yaw angle
|
||||
*/
|
||||
public float getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pitch angle of a TeleportationPoint
|
||||
* @return the pitch angle
|
||||
*/
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package me.william278.huskhomes2.teleport;
|
||||
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
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 = HuskHomes.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) {
|
||||
this.teleporter = teleporter;
|
||||
this.initialTeleporterLocation = teleporter.getLocation();
|
||||
this.initialTeleporterHealth = teleporter.getHealth();
|
||||
this.targetType = "random";
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package me.william278.huskhomes2.teleport;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
* An object representing an in-game warp
|
||||
* @author William
|
||||
*/
|
||||
public class Warp extends TeleportationPoint {
|
||||
|
||||
String name;
|
||||
String description;
|
||||
|
||||
/**
|
||||
* An object representing an in-game warp
|
||||
* @param location the Bukkit location of the Warp
|
||||
* @param server The Bungee server ID of the Warp
|
||||
* @param name The name of the Warp
|
||||
*/
|
||||
public Warp(Location location, String server, String name) {
|
||||
super(location, server);
|
||||
this.name = name;
|
||||
this.description = "A publicly accessible warp";
|
||||
}
|
||||
|
||||
/**
|
||||
* An object representing an in-game warp
|
||||
* @param teleportationPoint The position of the Warp
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.name = description;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user