Arena system and some changes (not finished)

This commit is contained in:
Luca
2021-11-21 16:14:04 +01:00
parent 002b05820e
commit 1cca6eb41c
12 changed files with 635 additions and 2 deletions

View File

@ -0,0 +1,125 @@
package rip.tilly.bedwars.utils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import java.util.StringJoiner;
@Getter
@Setter
@AllArgsConstructor
public class CustomLocation {
private final long timestamp = System.currentTimeMillis();
private String world;
private double x;
private double y;
private double z;
private float yaw;
private float pitch;
public CustomLocation(double x, double y, double z) {
this(x, y, z, 0.0F, 0.0F);
}
public CustomLocation(String world, double x, double y, double z) {
this(world, x, y, z, 0.0F, 0.0F);
}
public CustomLocation(double x, double y, double z, float yaw, float pitch) {
this("world", x, y, z, yaw, pitch);
}
public static CustomLocation fromBukkitLocation(Location location) {
return new CustomLocation(location.getWorld().getName(), location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
}
public static CustomLocation stringToLocation(String string) {
String[] split = string.split(", ");
double x = Double.parseDouble(split[0]);
double y = Double.parseDouble(split[1]);
double z = Double.parseDouble(split[2]);
CustomLocation customLocation = new CustomLocation(x, y, z);
if (split.length == 4) {
customLocation.setWorld(split[3]);
} else if (split.length >= 5) {
customLocation.setYaw(Float.parseFloat(split[3]));
customLocation.setPitch(Float.parseFloat(split[4]));
if (split.length >= 6) {
customLocation.setWorld(split[5]);
}
}
return customLocation;
}
public static String locationToString(CustomLocation loc) {
StringJoiner joiner = new StringJoiner(", ");
joiner.add(Double.toString(loc.getX()));
joiner.add(Double.toString(loc.getY()));
joiner.add(Double.toString(loc.getZ()));
if (loc.getYaw() == 0.0f && loc.getPitch() == 0.0f) {
if (loc.getWorld().equals("world")) {
return joiner.toString();
} else {
joiner.add(loc.getWorld());
return joiner.toString();
}
} else {
joiner.add(Float.toString(loc.getYaw()));
joiner.add(Float.toString(loc.getPitch()));
if (loc.getWorld().equals("world")) {
return joiner.toString();
} else {
joiner.add(loc.getWorld());
return joiner.toString();
}
}
}
public Location toBukkitLocation() {
return new Location(this.toBukkitWorld(), this.x, this.y, this.z, this.yaw, this.pitch);
}
public World toBukkitWorld() {
if (this.world == null) {
return Bukkit.getServer().getWorlds().get(0);
} else {
return Bukkit.getServer().getWorld(this.world);
}
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof CustomLocation)) {
return false;
}
CustomLocation location = (CustomLocation) obj;
return location.x == this.x && location.y == this.y && location.z == this.z && location.pitch == this.pitch && location.yaw == this.yaw;
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("x", this.x)
.append("y", this.y)
.append("z", this.z)
.append("yaw", this.yaw)
.append("pitch", this.pitch)
.append("world", this.world)
.append("timestamp", this.timestamp)
.toString();
}
}

View File

@ -0,0 +1,88 @@
package rip.tilly.bedwars.utils.config;
import org.bukkit.Bukkit;
import org.bukkit.World;
import java.util.List;
import java.util.Set;
import java.util.UUID;
public class ConfigCursor {
private final FileConfig fileConfig;
private String path;
public ConfigCursor(FileConfig fileConfig, String path) {
this.fileConfig = fileConfig;
this.path = path;
}
public FileConfig getFileConfig() {
return this.fileConfig;
}
public String getPath() {
return this.path;
}
public void setPath(String path) {
this.path = path;
}
public boolean exists() {
return exists(null);
}
public boolean exists(String path) {
return this.fileConfig.getConfig().contains(this.path + ((path == null) ? "" : ("." + path)));
}
public Set<String> getKeys() {
return getKeys(null);
}
public Set<String> getKeys(String path) {
return this.fileConfig.getConfig().getConfigurationSection(this.path + ((path == null) ? "" : ("." + path))).getKeys(false);
}
public boolean getBoolean(String path) {
return this.fileConfig.getConfig().getBoolean(((this.path == null) ? "" : (this.path + ".")) + "." + path);
}
public int getInt(String path) {
return this.fileConfig.getConfig().getInt(((this.path == null) ? "" : (this.path + ".")) + "." + path);
}
public long getLong(String path) {
return this.fileConfig.getConfig().getLong(((this.path == null) ? "" : (this.path + ".")) + "." + path);
}
public String getString(String path) {
return this.fileConfig.getConfig().getString(((this.path == null) ? "" : (this.path + ".")) + "." + path);
}
public List<String> getStringList(String path) {
return this.fileConfig.getConfig().getStringList(((this.path == null) ? "" : (this.path + ".")) + "." + path);
}
public UUID getUuid(String path) {
return UUID.fromString(this.fileConfig.getConfig().getString(this.path + "." + path));
}
public World getWorld(String path) {
return Bukkit.getWorld(this.fileConfig.getConfig().getString(this.path + "." + path));
}
public void set(Object value) {
set(null, value);
}
public void set(String path, Object value) {
this.fileConfig.getConfig().set(this.path + ((path == null) ? "" : ("." + path)), value);
}
public void save() {
this.fileConfig.save();
}
}

View File

@ -0,0 +1,50 @@
package rip.tilly.bedwars.utils.config;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
public class FileConfig {
private File file;
private FileConfiguration config;
public File getFile() {
return this.file;
}
public FileConfiguration getConfig() {
return this.config;
}
public FileConfig(JavaPlugin plugin, String fileName) {
this.file = new File(plugin.getDataFolder(), fileName);
if (!this.file.exists()) {
this.file.getParentFile().mkdirs();
if (plugin.getResource(fileName) == null) {
try {
this.file.createNewFile();
} catch (IOException e) {
plugin.getLogger().severe("Failed to create new file " + fileName);
}
} else {
plugin.saveResource(fileName, false);
}
}
this.config = YamlConfiguration.loadConfiguration(this.file);
}
public void save() {
try {
this.config.save(this.file);
} catch (IOException e) {
Bukkit.getLogger().severe("Could not save config file " + this.file.toString());
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,39 @@
package rip.tilly.bedwars.utils.config.file;
import lombok.Getter;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
@Getter
public class Config {
private final FileConfiguration config;
private final File configFile;
protected boolean wasCreated;
public Config(String name, JavaPlugin plugin) {
this.configFile = new File(plugin.getDataFolder() + "/" + name + ".yml");
if (!this.configFile.exists()) {
try {
this.configFile.getParentFile().mkdirs();
this.configFile.createNewFile();
this.wasCreated = true;
} catch (IOException e) {
e.printStackTrace();
}
}
this.config = YamlConfiguration.loadConfiguration(this.configFile);
}
public void save() {
try {
this.config.save(configFile);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,103 @@
package rip.tilly.bedwars.utils.config.file;
import lombok.Getter;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ConfigFile {
@Getter private File file;
@Getter private YamlConfiguration configuration;
public ConfigFile(JavaPlugin plugin, String name) {
file = new File(plugin.getDataFolder(), name + ".yml");
if (!file.getParentFile().exists()) {
file.getParentFile().mkdir();
}
plugin.saveResource(name + ".yml", false);
configuration = YamlConfiguration.loadConfiguration(file);
}
public double getDouble(String path) {
if (configuration.contains(path)) {
return configuration.getDouble(path);
}
return 0;
}
public int getInt(String path) {
if (configuration.contains(path)) {
return configuration.getInt(path);
}
return 0;
}
public boolean getBoolean(String path) {
if (configuration.contains(path)) {
return configuration.getBoolean(path);
}
return false;
}
public String getString(String path) {
if (configuration.contains(path)) {
return ChatColor.translateAlternateColorCodes('&', configuration.getString(path));
}
return "ERROR: STRING NOT FOUND";
}
public String getString(String path, String callback, boolean colorize) {
if (configuration.contains(path)) {
if (colorize) {
return ChatColor.translateAlternateColorCodes('&', configuration.getString(path));
} else {
return configuration.getString(path);
}
}
return callback;
}
public List<String> getReversedStringList(String path) {
List<String> list = getStringList(path);
if (list != null) {
int size = list.size();
List<String> toReturn = new ArrayList<>();
for (int i = size - 1; i >= 0; i--) {
toReturn.add(list.get(i));
}
return toReturn;
}
return Arrays.asList("ERROR: STRING LIST NOT FOUND!");
}
public List<String> getStringList(String path) {
if (configuration.contains(path)) {
ArrayList<String> strings = new ArrayList<>();
for (String string : configuration.getStringList(path)) {
strings.add(ChatColor.translateAlternateColorCodes('&', string));
}
return strings;
}
return Arrays.asList("ERROR: STRING LIST NOT FOUND!");
}
public List<String> getStringListOrDefault(String path, List<String> toReturn) {
if (configuration.contains(path)) {
ArrayList<String> strings = new ArrayList<>();
for (String string : configuration.getStringList(path)) {
strings.add(ChatColor.translateAlternateColorCodes('&', string));
}
return strings;
}
return toReturn;
}
}