Re-added many HuskHomes commands

This commit is contained in:
William278 committed 2020-12-13 02:17:58 +00:00
1 parent d20baa41d1
commit 1b8254d46a
34 files changed
+1485 -47

No files matched your search

@@ -0,0 +1,85 @@
package me.william278.huskhomes2.Objects;
import me.william278.huskhomes2.Main;
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 of all the unsafe blocks
final static HashSet<Material> bad_blocks = new HashSet<>();
static{
bad_blocks.add(Material.LAVA);
bad_blocks.add(Material.FIRE);
bad_blocks.add(Material.CACTUS);
bad_blocks.add(Material.WATER);
bad_blocks.add(Material.MAGMA_BLOCK);
bad_blocks.add(Material.JUNGLE_LEAVES);
bad_blocks.add(Material.SPRUCE_LEAVES);
}
private Location randomLocation(World world) {
//Generate Random Location
Random random = new Random();
int x = 0;
int z = 0;
int y = 0;
int negativex = 0;
int negativez = 0;
x = random.nextInt(Main.settings.getRtpRange());
z = random.nextInt(Main.settings.getRtpRange());
negativex = random.nextInt(2);
negativez = random.nextInt(2);
if (negativex == 1) {
x = x * -1;
}
if (negativez == 1)
z = z * -1;
y = 150;
Location randomLocation = new Location(world, x, y, z);
y = randomLocation.getWorld().getHighestBlockYAt(randomLocation);
randomLocation.setY(y);
return randomLocation;
}
private boolean isLocationSafe(Location location){
int x = location.getBlockX();
int y = location.getBlockY();
int z = location.getBlockZ();
//Get instances of the blocks around where the player would spawn
Block block = location.getWorld().getBlockAt(x, y, z);
Block below = location.getWorld().getBlockAt(x, y - 1, z);
Block above = location.getWorld().getBlockAt(x, y + 1, z);
//Check to see if the surroundings are safe or not
return !(bad_blocks.contains(below.getType())) || (block.getType().isSolid()) || (above.getType().isSolid());
}
private Location getRandomLocation(World world) {
Location randomLocation = randomLocation(world);
while (!isLocationSafe(randomLocation)){
//Keep looking for a safe location
randomLocation = randomLocation(world);
}
return randomLocation;
}
public RandomPoint(Player player) {
super(player.getLocation(), Main.settings.getServerID());
setLocation(getRandomLocation(player.getWorld()), Main.settings.getServerID());
}
}
@@ -12,8 +12,10 @@ public class Settings {
int maximumHomes;
int teleportRequestExpiryTime;
int teleportWarmupTime;
int rtpRange;
boolean doBungee;
boolean doRtpCommand;
boolean doSpawnCommand;
private void setSettings(FileConfiguration configFile) {
@@ -25,6 +27,9 @@ public class Settings {
this.doSpawnCommand = configFile.getBoolean("spawn_command.enabled");
this.doRtpCommand = configFile.getBoolean("rtp_command.enabled");
this.rtpRange = configFile.getInt("rtp_command.range");
this.maximumHomes = configFile.getInt("general.max_sethomes");
this.teleportRequestExpiryTime = configFile.getInt("general.teleport_request_expiry_time");
this.teleportWarmupTime = configFile.getInt("general.teleport_warmup_time");
@@ -63,4 +68,12 @@ public class Settings {
public int getTeleportRequestExpiryTime() { return teleportRequestExpiryTime; }
public int getRtpRange() {
return rtpRange;
}
public boolean doRtpCommand() {
return doRtpCommand;
}
}
@@ -14,7 +14,7 @@ public class TeleportationPoint {
float yaw;
float pitch;
private void setLocation(Location location, String server) {
public void setLocation(Location location, String server) {
worldName = location.getWorld().getName();
x = location.getX();
y = location.getY();