mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 06:28:49 +00:00
More classes moving
This commit is contained in:
47 files changed
+230
-234
No files matched your search
@@ -0,0 +1,175 @@
|
||||
package me.william278.huskhomes2.teleport.points;
|
||||
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* An object representing a Player's home in-game
|
||||
* @author William
|
||||
*/
|
||||
public class Home extends TeleportationPoint {
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
private boolean isPublic;
|
||||
|
||||
private UUID ownerUUID;
|
||||
private 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;
|
||||
}
|
||||
|
||||
// Returns the maximum number of set homes a player can make
|
||||
public static int getSetHomeLimit(Player p) {
|
||||
p.recalculatePermissions();
|
||||
for (PermissionAttachmentInfo permissionAI : p.getEffectivePermissions()) {
|
||||
String permission = permissionAI.getPermission();
|
||||
if (permission.contains("huskhomes.max_sethomes.")) {
|
||||
try {
|
||||
return Integer.parseInt(permission.split("\\.")[2]);
|
||||
} catch(Exception e) {
|
||||
return HuskHomes.settings.getMaximumHomes();
|
||||
}
|
||||
}
|
||||
}
|
||||
return HuskHomes.settings.getMaximumHomes();
|
||||
}
|
||||
|
||||
// Returns the number of set homes a player can set for free
|
||||
public static int getFreeHomes(Player p) {
|
||||
for (PermissionAttachmentInfo permissionAI : p.getEffectivePermissions()) {
|
||||
String permission = permissionAI.getPermission();
|
||||
if (permission.contains("huskhomes.free_sethomes.")) {
|
||||
try {
|
||||
return Integer.parseInt(permission.split("\\.")[2]);
|
||||
} catch(Exception e) {
|
||||
return HuskHomes.settings.getFreeHomeSlots();
|
||||
}
|
||||
}
|
||||
}
|
||||
return HuskHomes.settings.getFreeHomeSlots();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package me.william278.huskhomes2.teleport.points;
|
||||
|
||||
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.EnumSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class RandomPoint extends TeleportationPoint {
|
||||
|
||||
// List containing all unsafe blocks
|
||||
private final static Set<Material> unsafeBlocks = EnumSet.noneOf(Material.class);
|
||||
|
||||
// Maximum number of attempts to find a random location
|
||||
private 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 = ThreadLocalRandom.current();
|
||||
|
||||
int x;
|
||||
int y = 64;
|
||||
int z;
|
||||
double blockCenterX = 0.5;
|
||||
double blockCenterZ = 0.5;
|
||||
|
||||
// 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
|
||||
if (random.nextBoolean()) {
|
||||
x *= -1;
|
||||
blockCenterX *= -1;
|
||||
}
|
||||
if (random.nextBoolean()) {
|
||||
z *= -1;
|
||||
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,137 @@
|
||||
package me.william278.huskhomes2.teleport.points;
|
||||
|
||||
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 {
|
||||
|
||||
protected String server;
|
||||
protected String worldName;
|
||||
protected double x;
|
||||
protected double y;
|
||||
protected double z;
|
||||
protected float yaw;
|
||||
protected 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,70 @@
|
||||
package me.william278.huskhomes2.teleport.points;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
* An object representing an in-game warp
|
||||
* @author William
|
||||
*/
|
||||
public class Warp extends TeleportationPoint {
|
||||
|
||||
private String name;
|
||||
private 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