Added mySQL support, RTP command and bStats metric collection

This commit is contained in:
William278 committed 2020-12-14 15:50:30 +00:00
1 parent 3d4e14d420
commit 18b244ed65
21 files changed
+941 -314

No files matched your search

@@ -13,35 +13,37 @@ import java.util.Random;
public class RandomPoint extends TeleportationPoint {
//List of all the unsafe blocks
final static HashSet<Material> bad_blocks = new HashSet<>();
final static HashSet<Material> unsafeBlocks = 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);
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);
}
private Location randomLocation(World world) {
//Generate Random Location
//Generate a random location
Random random = new Random();
int x = 0;
int z = 0;
int y = 0;
int negativex = 0;
int negativez = 0;
int x;
int z;
int y;
int negativeX;
int negativeZ;
x = random.nextInt(Main.settings.getRtpRange());
z = random.nextInt(Main.settings.getRtpRange());
negativex = random.nextInt(2);
negativez = random.nextInt(2);
if (negativex == 1) {
negativeX = random.nextInt(2);
negativeZ = random.nextInt(2);
if (negativeX == 1) {
x = x * -1;
}
if (negativez == 1)
if (negativeZ == 1)
z = z * -1;
y = 150;
@@ -53,17 +55,17 @@ public class RandomPoint extends TeleportationPoint {
}
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());
return !(unsafeBlocks.contains(below.getType())) || (block.getType().isSolid()) || (above.getType().isSolid());
}
private Location getRandomLocation(World world) {
@@ -1,5 +1,6 @@
package me.william278.huskhomes2.Objects;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
public class Settings {
@@ -8,15 +9,28 @@ public class Settings {
String server;
String storageType;
String playerDataTable;
String locationsDataTable;
String homesDataTable;
String warpsDataTable;
int mySQLport;
String mySQLhost;
String mySQLdatabase;
String mySQLusername;
String mySQLpassword;
int maximumHomes;
int teleportRequestExpiryTime;
int teleportWarmupTime;
int rtpRange;
int rtpCooldown;
boolean doBungee;
boolean doRtpCommand;
boolean doSpawnCommand;
boolean doWarpCommand;
private void setSettings(FileConfiguration configFile) {
this.language = configFile.getString("language");
@@ -25,10 +39,31 @@ public class Settings {
this.storageType = configFile.getString("data_storage_options.storage_type");
// Resolve conflict between storage type and bungee mode
if (storageType.equalsIgnoreCase("sqlite") && doBungee) {
Bukkit.getLogger().warning("Bungee mode was set in config to be enabled but storage type was set to SQLite!");
Bukkit.getLogger().warning("A mySQL Database is required to utilise Bungee mode, so bungee mode has been disabled.");
Bukkit.getLogger().warning("To use Bungee mode and cross-server teleportation, please update your data storage settings to use \"mysql\" and update the connection details accordingly.");
this.doBungee = false;
}
this.mySQLhost = configFile.getString("data_storage_options.mysql_database.host");
this.mySQLdatabase = configFile.getString("data_storage_options.mysql_database.database");
this.mySQLusername = configFile.getString("data_storage_options.mysql_database.username");
this.mySQLpassword = configFile.getString("data_storage_options.mysql_database.password");
this.mySQLport = configFile.getInt("data_storage_options.mysql_database.port");
this.playerDataTable = configFile.getString("data_storage_options.table_names.player_data");
this.locationsDataTable = configFile.getString("data_storage_options.table_names.locations_data");
this.homesDataTable = configFile.getString("data_storage_options.table_names.homes_data");
this.warpsDataTable = configFile.getString("data_storage_options.table_names.warps_data");
this.doSpawnCommand = configFile.getBoolean("spawn_command.enabled");
this.doWarpCommand = configFile.getBoolean("enable_warp_command");
this.doRtpCommand = configFile.getBoolean("rtp_command.enabled");
this.rtpRange = configFile.getInt("rtp_command.range");
this.rtpCooldown = configFile.getInt("rtp_command.cooldown");
this.maximumHomes = configFile.getInt("general.max_sethomes");
this.teleportRequestExpiryTime = configFile.getInt("general.teleport_request_expiry_time");
@@ -64,9 +99,17 @@ public class Settings {
return doBungee;
}
public int getMaximumHomes() { return maximumHomes; }
public int getMaximumHomes() {
return maximumHomes;
}
public int getTeleportRequestExpiryTime() { return teleportRequestExpiryTime; }
public int getRtpCooldown() {
return rtpCooldown;
}
public int getTeleportRequestExpiryTime() {
return teleportRequestExpiryTime;
}
public int getRtpRange() {
return rtpRange;
@@ -76,4 +119,40 @@ public class Settings {
return doRtpCommand;
}
public String getPlayerDataTable() {
return playerDataTable;
}
public String getLocationsDataTable() {
return locationsDataTable;
}
public String getHomesDataTable() {
return homesDataTable;
}
public String getWarpsDataTable() {
return warpsDataTable;
}
public int getMySQLport() {
return mySQLport;
}
public String getMySQLhost() {
return mySQLhost;
}
public String getMySQLdatabase() {
return mySQLdatabase;
}
public String getMySQLusername() {
return mySQLusername;
}
public String getMySQLpassword() {
return mySQLpassword;
}
}
@@ -3,6 +3,7 @@ package me.william278.huskhomes2.Objects;
import me.william278.huskhomes2.Main;
import me.william278.huskhomes2.messageManager;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
public class TimedTeleport {
@@ -31,6 +32,17 @@ public class TimedTeleport {
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();