Code cleanup
This commit is contained in:
parent
c163885345
commit
fa14d001da
|
|
@ -8,17 +8,15 @@ import com.alttd.database.Database;
|
||||||
import com.alttd.listeners.*;
|
import com.alttd.listeners.*;
|
||||||
import com.alttd.objects.APartType;
|
import com.alttd.objects.APartType;
|
||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
|
import lombok.Getter;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class AltitudeParticles extends JavaPlugin {
|
public class AltitudeParticles extends JavaPlugin {
|
||||||
|
|
||||||
|
@Getter
|
||||||
public static AltitudeParticles instance;
|
public static AltitudeParticles instance;
|
||||||
|
|
||||||
public static AltitudeParticles getInstance() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ import org.jetbrains.annotations.Nullable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class CommandManager implements CommandExecutor, TabExecutor {
|
public class CommandManager implements CommandExecutor, TabExecutor {
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ package com.alttd.commands.subcommands;
|
||||||
import com.alttd.AltitudeParticles;
|
import com.alttd.AltitudeParticles;
|
||||||
import com.alttd.commands.SubCommand;
|
import com.alttd.commands.SubCommand;
|
||||||
import com.alttd.config.Config;
|
import com.alttd.config.Config;
|
||||||
import com.alttd.config.DatabaseConfig;
|
|
||||||
import com.alttd.config.ParticleConfig;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ abstract class AbstractConfig {
|
||||||
throw new RuntimeException(ex.getCause());
|
throw new RuntimeException(ex.getCause());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.severe("Error invoking %.", method.toString());
|
Logger.severe("Error invoking %.", method.toString());
|
||||||
ex.printStackTrace();
|
Logger.error("Failed to invoke", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -69,7 +69,7 @@ abstract class AbstractConfig {
|
||||||
yaml.save(file);
|
yaml.save(file);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Logger.severe("Could not save %.", file.toString());
|
Logger.severe("Could not save %.", file.toString());
|
||||||
ex.printStackTrace();
|
Logger.error("Failed to save", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,4 +127,4 @@ abstract class AbstractConfig {
|
||||||
ConfigurationSection getConfigurationSection(String path) {
|
ConfigurationSection getConfigurationSection(String path) {
|
||||||
return yaml.getConfigurationSection(path);
|
return yaml.getConfigurationSection(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.alttd.config;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public final class Config extends AbstractConfig {
|
public final class Config extends AbstractConfig {
|
||||||
|
|
||||||
static Config config;
|
static Config config;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
package com.alttd.config;
|
package com.alttd.config;
|
||||||
|
|
||||||
import com.alttd.database.Database;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class DatabaseConfig extends AbstractConfig {
|
public class DatabaseConfig extends AbstractConfig {
|
||||||
|
|
||||||
static DatabaseConfig config;
|
static DatabaseConfig config;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ public class Database {
|
||||||
try {
|
try {
|
||||||
openConnection();
|
openConnection();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Logger.error("Unable to open connection", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tables
|
// Tables
|
||||||
|
|
@ -48,7 +48,7 @@ public class Database {
|
||||||
try {
|
try {
|
||||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
Logger.error("Error while trying to open connection", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
connection = DriverManager.getConnection(
|
connection = DriverManager.getConnection(
|
||||||
|
|
@ -66,7 +66,7 @@ public class Database {
|
||||||
try {
|
try {
|
||||||
instance.openConnection();
|
instance.openConnection();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
Logger.error("Error while trying to get connection", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return connection;
|
return connection;
|
||||||
|
|
@ -74,15 +74,17 @@ public class Database {
|
||||||
|
|
||||||
private static void createActiveParticlesTable() {
|
private static void createActiveParticlesTable() {
|
||||||
try {
|
try {
|
||||||
String sql = "CREATE TABLE IF NOT EXISTS active_particles(" +
|
String sql = """
|
||||||
"uuid VARCHAR(36) NOT NULL, " +
|
CREATE TABLE IF NOT EXISTS active_particles(
|
||||||
"particle_type VARCHAR(36) NOT NULL, " +
|
uuid VARCHAR(36) NOT NULL,
|
||||||
"particle_id VARCHAR(36) NOT NULL, " +
|
particle_type VARCHAR(36) NOT NULL,
|
||||||
"PRIMARY KEY (uuid, particle_type)" +
|
particle_id VARCHAR(36) NOT NULL,
|
||||||
")";
|
PRIMARY KEY (uuid, particle_type)
|
||||||
|
)""";
|
||||||
connection.prepareStatement(sql).executeUpdate();
|
connection.prepareStatement(sql).executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Logger.error("Error while trying to create user point table", e);
|
||||||
|
|
||||||
Logger.severe("Error while trying to create user point table");
|
Logger.severe("Error while trying to create user point table");
|
||||||
Logger.severe("Shutting down AltitudeParticles");
|
Logger.severe("Shutting down AltitudeParticles");
|
||||||
Bukkit.getPluginManager().disablePlugin(AltitudeParticles.getInstance());
|
Bukkit.getPluginManager().disablePlugin(AltitudeParticles.getInstance());
|
||||||
|
|
@ -91,16 +93,16 @@ public class Database {
|
||||||
|
|
||||||
private static void createUserSettingsTable() {
|
private static void createUserSettingsTable() {
|
||||||
try {
|
try {
|
||||||
String sql = "CREATE TABLE IF NOT EXISTS user_settings(" +
|
String sql = """
|
||||||
"uuid VARCHAR(36) NOT NULL, " +
|
CREATE TABLE IF NOT EXISTS user_settings(
|
||||||
"particles_active BIT(1) NOT NULL DEFAULT b'1', " +
|
uuid VARCHAR(36) NOT NULL,
|
||||||
"seeing_particles BIT(1) NOT NULL DEFAULT b'1', " +
|
particles_active BIT(1) NOT NULL DEFAULT b'1',
|
||||||
"PRIMARY KEY (uuid)" +
|
seeing_particles BIT(1) NOT NULL DEFAULT b'1',
|
||||||
")";
|
PRIMARY KEY (uuid)
|
||||||
|
)""";
|
||||||
connection.prepareStatement(sql).executeUpdate();
|
connection.prepareStatement(sql).executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Logger.error("Error while trying to create user point table", e);
|
||||||
Logger.severe("Error while trying to create user point table");
|
|
||||||
Logger.severe("Shutting down AltitudeParticles");
|
Logger.severe("Shutting down AltitudeParticles");
|
||||||
Bukkit.getPluginManager().disablePlugin(AltitudeParticles.getInstance());
|
Bukkit.getPluginManager().disablePlugin(AltitudeParticles.getInstance());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,44 +16,44 @@ import java.util.UUID;
|
||||||
public class Queries {
|
public class Queries {
|
||||||
|
|
||||||
public static void setSeeingParticles(UUID uuid, boolean seeingParticles) {
|
public static void setSeeingParticles(UUID uuid, boolean seeingParticles) {
|
||||||
String sql = "UPDATE user_settings " +
|
String sql = """
|
||||||
"SET seeing_particles = ?" +
|
UPDATE user_settings
|
||||||
"WHERE uuid = ?";
|
SET seeing_particles = ?
|
||||||
|
WHERE uuid = ?""";
|
||||||
|
|
||||||
try {
|
try (PreparedStatement preparedStatement = Database.getConnection().prepareStatement(sql)) {
|
||||||
PreparedStatement preparedStatement = Database.getConnection().prepareStatement(sql);
|
|
||||||
preparedStatement.setInt(1, seeingParticles ? 1 : 0);
|
preparedStatement.setInt(1, seeingParticles ? 1 : 0);
|
||||||
preparedStatement.setString(2, uuid.toString());
|
preparedStatement.setString(2, uuid.toString());
|
||||||
|
|
||||||
preparedStatement.executeUpdate();
|
preparedStatement.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Logger.error(String.format("unable to set seeing particles for %s", uuid.toString()), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setParticlesActive(UUID uuid, boolean particlesActive) {
|
public static void setParticlesActive(UUID uuid, boolean particlesActive) {
|
||||||
String sql = "UPDATE user_settings " +
|
String sql = """
|
||||||
"SET particles_active = ? " +
|
UPDATE user_settings
|
||||||
"WHERE uuid = ?";
|
SET particles_active = ?
|
||||||
|
WHERE uuid = ?""";
|
||||||
|
|
||||||
try {
|
try (PreparedStatement preparedStatement = Database.getConnection().prepareStatement(sql)) {
|
||||||
PreparedStatement preparedStatement = Database.getConnection().prepareStatement(sql);
|
|
||||||
preparedStatement.setInt(1, particlesActive ? 1 : 0);
|
preparedStatement.setInt(1, particlesActive ? 1 : 0);
|
||||||
preparedStatement.setString(2, uuid.toString());
|
preparedStatement.setString(2, uuid.toString());
|
||||||
|
|
||||||
preparedStatement.executeUpdate();
|
preparedStatement.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Logger.error(String.format("unable to set particles for %s", uuid.toString()), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addParticle(UUID uuid, APartType aPartType, String particleId) {
|
public static void addParticle(UUID uuid, APartType aPartType, String particleId) {
|
||||||
String sql = "INSERT INTO active_particles (uuid, particle_type, particle_id) " +
|
String sql = """
|
||||||
"VALUES (?, ?, ?) " +
|
INSERT INTO active_particles (uuid, particle_type, particle_id)
|
||||||
"ON DUPLICATE KEY UPDATE particle_id = ?";
|
VALUES (?, ?, ?)
|
||||||
|
ON DUPLICATE KEY UPDATE particle_id = ?""";
|
||||||
|
|
||||||
try {
|
try (PreparedStatement preparedStatement = Database.getConnection().prepareStatement(sql)) {
|
||||||
PreparedStatement preparedStatement = Database.getConnection().prepareStatement(sql);
|
|
||||||
preparedStatement.setString(1, uuid.toString());
|
preparedStatement.setString(1, uuid.toString());
|
||||||
preparedStatement.setString(2, aPartType.getName());
|
preparedStatement.setString(2, aPartType.getName());
|
||||||
preparedStatement.setString(3, particleId);
|
preparedStatement.setString(3, particleId);
|
||||||
|
|
@ -61,43 +61,45 @@ public class Queries {
|
||||||
|
|
||||||
preparedStatement.executeUpdate();
|
preparedStatement.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Logger.error(String.format("unable to add particle for %s", uuid.toString()), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeParticle(UUID uuid, APartType aPartType) {
|
public static void removeParticle(UUID uuid, APartType aPartType) {
|
||||||
String sql = "DELETE FROM active_particles " +
|
String sql = """
|
||||||
"WHERE uuid = ? " +
|
DELETE FROM active_particles
|
||||||
"AND particle_type = ?";
|
WHERE uuid = ?
|
||||||
|
AND particle_type = ?""";
|
||||||
|
|
||||||
try {
|
try (PreparedStatement preparedStatement = Database.getConnection().prepareStatement(sql)) {
|
||||||
PreparedStatement preparedStatement = Database.getConnection().prepareStatement(sql);
|
|
||||||
preparedStatement.setString(1, uuid.toString());
|
preparedStatement.setString(1, uuid.toString());
|
||||||
preparedStatement.setString(2, aPartType.getName());
|
preparedStatement.setString(2, aPartType.getName());
|
||||||
|
|
||||||
preparedStatement.executeUpdate();
|
preparedStatement.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Logger.error(String.format("unable to remove particles for %s", uuid.toString()), e);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearParticles(UUID uuid) {
|
public static void clearParticles(UUID uuid) {
|
||||||
String sql = "DELETE FROM active_particles " +
|
String sql = """
|
||||||
"WHERE uuid = ?";
|
DELETE FROM active_particles
|
||||||
try {
|
WHERE uuid = ?""";
|
||||||
PreparedStatement preparedStatement = Database.getConnection().prepareStatement(sql);
|
try (PreparedStatement preparedStatement = Database.getConnection().prepareStatement(sql)) {
|
||||||
preparedStatement.setString(1, uuid.toString());
|
preparedStatement.setString(1, uuid.toString());
|
||||||
|
|
||||||
preparedStatement.executeUpdate();
|
preparedStatement.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Logger.error(String.format("unable to clear particles for %s", uuid.toString()), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PlayerSettings getPlayerSettings(UUID uuid) {
|
public static PlayerSettings getPlayerSettings(UUID uuid) {
|
||||||
String sql = "SELECT * FROM user_settings WHERE uuid = ?";
|
String sql = """
|
||||||
try {
|
SELECT * FROM user_settings
|
||||||
PreparedStatement preparedStatement = Database.getConnection().prepareStatement(sql);
|
WHERE uuid = ?""";
|
||||||
|
try (PreparedStatement preparedStatement = Database.getConnection().prepareStatement(sql)) {
|
||||||
preparedStatement.setString(1, uuid.toString());
|
preparedStatement.setString(1, uuid.toString());
|
||||||
|
|
||||||
ResultSet resultSet = preparedStatement.executeQuery();
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
|
@ -109,18 +111,18 @@ public class Queries {
|
||||||
return new PlayerSettings(particlesActive, seeingParticles, uuid, activeParticles);
|
return new PlayerSettings(particlesActive, seeingParticles, uuid, activeParticles);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Logger.error(String.format("unable to get player settings for %s", uuid.toString()), e);
|
||||||
}
|
}
|
||||||
return createNewPlayerSettings(uuid);
|
return createNewPlayerSettings(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HashMap<APartType, ParticleSet> getActiveParticles(UUID uuid) {
|
private static HashMap<APartType, ParticleSet> getActiveParticles(UUID uuid) {
|
||||||
HashMap<APartType, ParticleSet> activeParticles = new HashMap<>();
|
HashMap<APartType, ParticleSet> activeParticles = new HashMap<>();
|
||||||
String sql = "SELECT * FROM active_particles " +
|
String sql = """
|
||||||
"WHERE uuid = ?";
|
SELECT * FROM active_particles
|
||||||
|
WHERE uuid = ?""";
|
||||||
|
|
||||||
try {
|
try (PreparedStatement preparedStatement = Database.getConnection().prepareStatement(sql)) {
|
||||||
PreparedStatement preparedStatement = Database.getConnection().prepareStatement(sql);
|
|
||||||
preparedStatement.setString(1, uuid.toString());
|
preparedStatement.setString(1, uuid.toString());
|
||||||
|
|
||||||
ResultSet resultSet = preparedStatement.executeQuery();
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
|
@ -145,19 +147,19 @@ public class Queries {
|
||||||
activeParticles.put(aPartType, first.get());
|
activeParticles.put(aPartType, first.get());
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Logger.error(String.format("unable to get player settings for %s", uuid.toString()), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return activeParticles;
|
return activeParticles;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PlayerSettings createNewPlayerSettings(UUID uuid) {
|
private static PlayerSettings createNewPlayerSettings(UUID uuid) {
|
||||||
String sql = "INSERT INTO user_settings (uuid, particles_active, seeing_particles)" +
|
String sql = """
|
||||||
"VALUES (?, ?, ?)" +
|
INSERT INTO user_settings (uuid, particles_active, seeing_particles)
|
||||||
"ON DUPLICATE KEY UPDATE particles_active = ?, seeing_particles = ?";
|
VALUES (?, ?, ?)
|
||||||
|
ON DUPLICATE KEY UPDATE particles_active = ?, seeing_particles = ?""";
|
||||||
|
|
||||||
try {
|
try (PreparedStatement preparedStatement = Database.getConnection().prepareStatement(sql)) {
|
||||||
PreparedStatement preparedStatement = Database.getConnection().prepareStatement(sql);
|
|
||||||
preparedStatement.setString(1, uuid.toString());
|
preparedStatement.setString(1, uuid.toString());
|
||||||
preparedStatement.setInt(2, 1);
|
preparedStatement.setInt(2, 1);
|
||||||
preparedStatement.setInt(3, 1);
|
preparedStatement.setInt(3, 1);
|
||||||
|
|
@ -166,7 +168,7 @@ public class Queries {
|
||||||
|
|
||||||
preparedStatement.executeUpdate();
|
preparedStatement.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
Logger.error(String.format("unable to get player settings for %s", uuid.toString()), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new PlayerSettings(true, true, uuid);
|
return new PlayerSettings(true, true, uuid);
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class ChooseParticleGUI extends DefaultGUI {
|
public class ChooseParticleGUI extends DefaultGUI {
|
||||||
|
|
||||||
|
|
@ -38,7 +37,7 @@ public class ChooseParticleGUI extends DefaultGUI {
|
||||||
super(name);
|
super(name);
|
||||||
List<ParticleSet> availableParticles = ParticleStorage.getParticleSets(aPartType).stream()
|
List<ParticleSet> availableParticles = ParticleStorage.getParticleSets(aPartType).stream()
|
||||||
.filter(particleSet -> player.hasPermission(particleSet.getPackPermission()) || player.hasPermission(particleSet.getPermission()))
|
.filter(particleSet -> player.hasPermission(particleSet.getPackPermission()) || player.hasPermission(particleSet.getPermission()))
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
PlayerSettings playerSettings = PlayerSettings.getPlayer(player.getUniqueId());
|
PlayerSettings playerSettings = PlayerSettings.getPlayer(player.getUniqueId());
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (ParticleSet particleSet : availableParticles) {
|
for (ParticleSet particleSet : availableParticles) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package com.alttd.objects;
|
package com.alttd.objects;
|
||||||
|
|
||||||
import com.alttd.config.Config;
|
import com.alttd.config.Config;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
|
@ -15,37 +17,19 @@ public enum APartType { //TODO add description?
|
||||||
CLICK_BLOCK("CLICK_BLOCK", "Right click block", Material.DIAMOND_BLOCK, TimeUnit.SECONDS.toMillis(Config.CLICK_BLOCK_COOL_DOWN), null, true),
|
CLICK_BLOCK("CLICK_BLOCK", "Right click block", Material.DIAMOND_BLOCK, TimeUnit.SECONDS.toMillis(Config.CLICK_BLOCK_COOL_DOWN), null, true),
|
||||||
TELEPORT_ARRIVE("TELEPORT", "Teleport", Material.DRAGON_EGG, TimeUnit.SECONDS.toMillis(Config.TELEPORT_ARRIVE_COOL_DOWN), null, true);
|
TELEPORT_ARRIVE("TELEPORT", "Teleport", Material.DRAGON_EGG, TimeUnit.SECONDS.toMillis(Config.TELEPORT_ARRIVE_COOL_DOWN), null, true);
|
||||||
|
|
||||||
|
@Getter
|
||||||
private final String name;
|
private final String name;
|
||||||
|
@Getter
|
||||||
private final String displayName;
|
private final String displayName;
|
||||||
|
@Getter
|
||||||
private final Material material;
|
private final Material material;
|
||||||
|
@Getter
|
||||||
private final long delay;
|
private final long delay;
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
private ItemStack itemStack;
|
private ItemStack itemStack;
|
||||||
private final boolean event;
|
private final boolean event;
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDisplayName() {
|
|
||||||
return displayName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Material getMaterial() {
|
|
||||||
return material;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getDelay() {
|
|
||||||
return delay;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getItemStack() {
|
|
||||||
return itemStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setItemStack(ItemStack itemStack) {
|
|
||||||
this.itemStack = itemStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasEvent() {
|
public boolean hasEvent() {
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
package com.alttd.objects;
|
package com.alttd.objects;
|
||||||
|
|
||||||
import com.alttd.config.Config;
|
|
||||||
import com.alttd.storage.PlayerSettings;
|
import com.alttd.storage.PlayerSettings;
|
||||||
import com.alttd.util.Logger;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
|
@ -24,18 +22,18 @@ public class Frame {
|
||||||
*/
|
*/
|
||||||
public void spawn(Location location, float rotation) {
|
public void spawn(Location location, float rotation) {
|
||||||
Location tmpLocation = location.clone();
|
Location tmpLocation = location.clone();
|
||||||
AParticles.forEach(AParticle -> {
|
AParticles.forEach(aParticle -> {
|
||||||
ThreadLocalRandom current = ThreadLocalRandom.current();
|
ThreadLocalRandom current = ThreadLocalRandom.current();
|
||||||
double offsetX = ((AParticle.offset_range() == 0) ? 0 : current.nextDouble(-AParticle.offset_range(), AParticle.offset_range()));
|
double offsetX = ((aParticle.offset_range() == 0) ? 0 : current.nextDouble(-aParticle.offset_range(), aParticle.offset_range()));
|
||||||
double offsetZ = ((AParticle.offset_range() == 0) ? 0 : current.nextDouble(-AParticle.offset_range(), AParticle.offset_range()));
|
double offsetZ = ((aParticle.offset_range() == 0) ? 0 : current.nextDouble(-aParticle.offset_range(), aParticle.offset_range()));
|
||||||
double offsetY = ((AParticle.offset_range() == 0) ? 0 : current.nextDouble(-AParticle.offset_range(), AParticle.offset_range()));
|
double offsetY = ((aParticle.offset_range() == 0) ? 0 : current.nextDouble(-aParticle.offset_range(), aParticle.offset_range()));
|
||||||
XZ xz = new XZ(location.getX(), location.getX() + AParticle.x() + offsetX,
|
XZ xz = new XZ(location.getX(), location.getX() + aParticle.x() + offsetX,
|
||||||
location.getZ(), location.getZ() + AParticle.z() + offsetZ,
|
location.getZ(), location.getZ() + aParticle.z() + offsetZ,
|
||||||
rotation);
|
rotation);
|
||||||
AParticle.particleBuilder()
|
aParticle.particleBuilder()
|
||||||
.location(tmpLocation.set(
|
.location(tmpLocation.set(
|
||||||
xz.getRotatedX(),
|
xz.getRotatedX(),
|
||||||
location.getY() + AParticle.y() + offsetY,
|
location.getY() + aParticle.y() + offsetY,
|
||||||
xz.getRotatedZ()))
|
xz.getRotatedZ()))
|
||||||
.receivers(Bukkit.getOnlinePlayers().stream()
|
.receivers(Bukkit.getOnlinePlayers().stream()
|
||||||
.filter(player -> {
|
.filter(player -> {
|
||||||
|
|
@ -51,7 +49,7 @@ public class Frame {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private class XZ {
|
private static class XZ {
|
||||||
private final double cx, cz; //Coordinates to rotate around
|
private final double cx, cz; //Coordinates to rotate around
|
||||||
private double x, z; //Coordinated to rotate
|
private double x, z; //Coordinated to rotate
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import com.alttd.frameSpawners.FrameSpawnerPlayer;
|
||||||
import com.alttd.storage.PlayerSettings;
|
import com.alttd.storage.PlayerSettings;
|
||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
import de.myzelyam.api.vanish.VanishAPI;
|
import de.myzelyam.api.vanish.VanishAPI;
|
||||||
|
import lombok.Getter;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
@ -22,10 +23,14 @@ public class ParticleSet {
|
||||||
|
|
||||||
private final List<Frame> frames;
|
private final List<Frame> frames;
|
||||||
private final int frameDelay, repeat, repeatDelay;
|
private final int frameDelay, repeat, repeatDelay;
|
||||||
|
@Getter
|
||||||
private final APartType aPartType;
|
private final APartType aPartType;
|
||||||
private final String uniqueId;
|
private final String uniqueId;
|
||||||
|
@Getter
|
||||||
private final String permission;
|
private final String permission;
|
||||||
|
@Getter
|
||||||
private final String packPermission;
|
private final String packPermission;
|
||||||
|
@Getter
|
||||||
private final ItemStack itemStack;
|
private final ItemStack itemStack;
|
||||||
private final boolean stationary;
|
private final boolean stationary;
|
||||||
|
|
||||||
|
|
@ -77,22 +82,6 @@ public class ParticleSet {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public APartType getAPartType() {
|
|
||||||
return aPartType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPermission() {
|
|
||||||
return permission;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPackPermission() {
|
|
||||||
return packPermission;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getItemStack() {
|
|
||||||
return itemStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getParticleId() {
|
public String getParticleId() {
|
||||||
return uniqueId;
|
return uniqueId;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.alttd.storage;
|
||||||
import com.alttd.database.Queries;
|
import com.alttd.database.Queries;
|
||||||
import com.alttd.objects.APartType;
|
import com.alttd.objects.APartType;
|
||||||
import com.alttd.objects.ParticleSet;
|
import com.alttd.objects.ParticleSet;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -12,8 +13,12 @@ public class PlayerSettings {
|
||||||
|
|
||||||
private static final HashMap<UUID, PlayerSettings> playerSettingsMap = new HashMap<>();
|
private static final HashMap<UUID, PlayerSettings> playerSettingsMap = new HashMap<>();
|
||||||
|
|
||||||
private boolean particlesActive, seeingParticles;
|
private boolean particlesActive;
|
||||||
|
@Getter
|
||||||
|
private boolean seeingParticles;
|
||||||
|
@Getter
|
||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
|
@Getter
|
||||||
private final HashMap<APartType, ParticleSet> particles;
|
private final HashMap<APartType, ParticleSet> particles;
|
||||||
private final HashMap<APartType, Long> lastUsed;
|
private final HashMap<APartType, Long> lastUsed;
|
||||||
|
|
||||||
|
|
@ -54,23 +59,11 @@ public class PlayerSettings {
|
||||||
return particlesActive;
|
return particlesActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSeeingParticles() {
|
|
||||||
return seeingParticles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean toggleSeeingParticles() {
|
public boolean toggleSeeingParticles() {
|
||||||
seeingParticles = !seeingParticles;
|
seeingParticles = !seeingParticles;
|
||||||
return seeingParticles;
|
return seeingParticles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getUuid() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<APartType, ParticleSet> getParticles() {
|
|
||||||
return particles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addParticle(APartType aPartType, ParticleSet particleSet) {
|
public void addParticle(APartType aPartType, ParticleSet particleSet) {
|
||||||
particles.put(aPartType, particleSet);
|
particles.put(aPartType, particleSet);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user