Rewriting entire backend, several commands, and part of GUI

This commit was long overdue. I'm rewriting the entire backend, changing the functionality of a few core commands, adding a new command manager, and rewriting a portion of the GUI to handle the new data structure.
This commit is contained in:
Esophose 2018-09-23 20:42:52 -06:00
parent 3d2306e7bb
commit a817341392
46 changed files with 1720 additions and 2139 deletions

22
pom.xml
View file

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.esophose.playerparticles</groupId> <groupId>com.esophose.playerparticles</groupId>
<artifactId>PlayerParticles</artifactId> <artifactId>PlayerParticles</artifactId>
<version>5.2</version> <version>5.3</version>
<name>PlayerParticles</name> <name>PlayerParticles</name>
<url>https://github.com/Esophose/PlayerParticles</url> <url>https://github.com/Esophose/PlayerParticles</url>
<description>Display particles around your player using customized styles and data!</description> <description>Display particles around your player using customized styles and data!</description>
@ -42,6 +42,7 @@
<include>com.zaxxer:HikariCP</include> <include>com.zaxxer:HikariCP</include>
<include>org.slf4j:slf4j-api</include> <include>org.slf4j:slf4j-api</include>
<include>org.slf4j:slf4j-nop</include> <include>org.slf4j:slf4j-nop</include>
<include>org.xerial:sqlite-jdbc</include>
</includes> </includes>
</artifactSet> </artifactSet>
<filters> <filters>
@ -54,7 +55,7 @@
</excludes> </excludes>
</filter> </filter>
</filters> </filters>
<outputFile>C:\Users\Esophose\Desktop\Spigot Dev Servers\1.13\plugins\update\PlayerParticles v5.2.jar</outputFile> <outputFile>C:\Users\Esophose\Desktop\Spigot Dev Servers\1.13\plugins\update\PlayerParticles v5.3.jar</outputFile>
</configuration> </configuration>
</execution> </execution>
<execution> <execution>
@ -69,6 +70,7 @@
<include>com.zaxxer:HikariCP</include> <include>com.zaxxer:HikariCP</include>
<include>org.slf4j:slf4j-api</include> <include>org.slf4j:slf4j-api</include>
<include>org.slf4j:slf4j-nop</include> <include>org.slf4j:slf4j-nop</include>
<include>org.xerial:sqlite-jdbc</include>
</includes> </includes>
</artifactSet> </artifactSet>
<filters> <filters>
@ -81,7 +83,7 @@
</excludes> </excludes>
</filter> </filter>
</filters> </filters>
<outputFile>C:\Users\Esophose\Desktop\Spigot Dev Servers\1.12\plugins\update\PlayerParticles v5.2.jar</outputFile> <outputFile>C:\Users\Esophose\Desktop\Spigot Dev Servers\1.12\plugins\update\PlayerParticles v5.3.jar</outputFile>
</configuration> </configuration>
</execution> </execution>
<execution> <execution>
@ -96,6 +98,7 @@
<include>com.zaxxer:HikariCP</include> <include>com.zaxxer:HikariCP</include>
<include>org.slf4j:slf4j-api</include> <include>org.slf4j:slf4j-api</include>
<include>org.slf4j:slf4j-nop</include> <include>org.slf4j:slf4j-nop</include>
<include>org.xerial:sqlite-jdbc</include>
</includes> </includes>
</artifactSet> </artifactSet>
<filters> <filters>
@ -108,7 +111,7 @@
</excludes> </excludes>
</filter> </filter>
</filters> </filters>
<outputFile>C:\Users\Esophose\Desktop\Spigot Dev Servers\1.11\plugins\update\PlayerParticles v5.2.jar</outputFile> <outputFile>C:\Users\Esophose\Desktop\Spigot Dev Servers\1.11\plugins\update\PlayerParticles v5.3.jar</outputFile>
</configuration> </configuration>
</execution> </execution>
<execution> <execution>
@ -123,6 +126,7 @@
<include>com.zaxxer:HikariCP</include> <include>com.zaxxer:HikariCP</include>
<include>org.slf4j:slf4j-api</include> <include>org.slf4j:slf4j-api</include>
<include>org.slf4j:slf4j-nop</include> <include>org.slf4j:slf4j-nop</include>
<include>org.xerial:sqlite-jdbc</include>
</includes> </includes>
</artifactSet> </artifactSet>
<filters> <filters>
@ -135,7 +139,7 @@
</excludes> </excludes>
</filter> </filter>
</filters> </filters>
<outputFile>C:\Users\Esophose\Desktop\Spigot Dev Servers\1.10\plugins\update\PlayerParticles v5.2.jar</outputFile> <outputFile>C:\Users\Esophose\Desktop\Spigot Dev Servers\1.10\plugins\update\PlayerParticles v5.3.jar</outputFile>
</configuration> </configuration>
</execution> </execution>
<execution> <execution>
@ -150,6 +154,7 @@
<include>com.zaxxer:HikariCP</include> <include>com.zaxxer:HikariCP</include>
<include>org.slf4j:slf4j-api</include> <include>org.slf4j:slf4j-api</include>
<include>org.slf4j:slf4j-nop</include> <include>org.slf4j:slf4j-nop</include>
<include>org.xerial:sqlite-jdbc</include>
</includes> </includes>
</artifactSet> </artifactSet>
<filters> <filters>
@ -162,7 +167,7 @@
</excludes> </excludes>
</filter> </filter>
</filters> </filters>
<outputFile>C:\Users\Esophose\Desktop\Spigot Dev Servers\1.9\plugins\update\PlayerParticles v5.2.jar</outputFile> <outputFile>C:\Users\Esophose\Desktop\Spigot Dev Servers\1.9\plugins\update\PlayerParticles v5.3.jar</outputFile>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
@ -191,6 +196,11 @@
<artifactId>HikariCP</artifactId> <artifactId>HikariCP</artifactId>
<version>3.2.0</version> <version>3.2.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.23.1</version>
</dependency>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>

View file

@ -1,291 +0,0 @@
/**
* Copyright Esophose 2018
* While using any of the code provided by this plugin
* you must not claim it as your own. This plugin may
* be modified and installed on a server, but may not
* be distributed to any person by any means.
*/
package com.esophose.playerparticles;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import com.esophose.playerparticles.gui.PlayerParticlesGui;
import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.particles.ParticleEffect;
import com.esophose.playerparticles.particles.ParticleEffect.BlockData;
import com.esophose.playerparticles.particles.ParticleEffect.ItemData;
import com.esophose.playerparticles.particles.ParticleEffect.NoteColor;
import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
import com.esophose.playerparticles.particles.ParticleEffect.ParticleColor;
import com.esophose.playerparticles.particles.ParticleEffect.ParticleData;
import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty;
import com.esophose.playerparticles.styles.DefaultStyles;
import com.esophose.playerparticles.styles.api.ParticleStyle;
import com.esophose.playerparticles.util.ParticleUtils;
public class PPlayer {
/**
* The UUID of the player
*/
private final UUID playerUUID;
/**
* The effect and style the player is using
*/
private ParticleEffect particleEffect;
private ParticleStyle particleStyle;
/**
* All data used to display custom particles
*/
private ItemData particleItemData;
private BlockData particleBlockData;
private OrdinaryColor particleColorData;
private NoteColor particleNoteColorData;
/**
* Constructs a new PPlayer
*
* @param uuid The player UUID
* @param effect The player's effect
* @param style The player's style
* @param itemData The player's item data
* @param blockData The player's block data
* @param colorData The player's color data
* @param noteColorData The player's note color data
*/
public PPlayer(UUID uuid, ParticleEffect effect, ParticleStyle style, ItemData itemData, BlockData blockData, OrdinaryColor colorData, NoteColor noteColorData) {
this.playerUUID = uuid;
this.setParticleEffect(effect);
this.setParticleStyle(style);
this.setItemData(itemData);
this.setBlockData(blockData);
this.setColorData(colorData);
this.setNoteColorData(noteColorData);
}
/**
* Gets the player's UUID
*
* @return The player's UUID
*/
public UUID getUniqueId() {
return this.playerUUID;
}
/**
* Gets the Player from their UUID
*
* @return The player if they are online, null if they are offline
*/
public Player getPlayer() {
return Bukkit.getPlayer(this.playerUUID);
}
/**
* Gets the player's particle effect
*
* @return The player's particle effect
*/
public ParticleEffect getParticleEffect() {
return this.particleEffect;
}
/**
* Gets the player's particle style
*
* @return The player's particle style
*/
public ParticleStyle getParticleStyle() {
if (this.particleStyle == null) return DefaultStyles.NONE;
return this.particleStyle;
}
/**
* Gets the player's item data
*
* @return The player's item data
*/
public ItemData getItemData() {
return this.particleItemData;
}
/**
* Gets the player's block data
*
* @return The player's block data
*/
public BlockData getBlockData() {
return this.particleBlockData;
}
/**
* Gets the player's color data
*
* @return The player's color data
*/
public OrdinaryColor getColorData() {
return this.particleColorData;
}
/**
* Gets the player's note color data
*
* @return The player's note color data
*/
public NoteColor getNoteColorData() {
return this.particleNoteColorData;
}
/**
* Sets the player's particle effect
*
* @param effect The player's new particle effect
*/
public void setParticleEffect(ParticleEffect effect) {
if (effect == null) effect = ParticleEffect.NONE;
this.particleEffect = effect;
}
/**
* Sets the player's particle style
*
* @param style The player's new particle style
*/
public void setParticleStyle(ParticleStyle style) {
if (style == null) style = DefaultStyles.NONE;
this.particleStyle = style;
}
/**
* Sets the player's item data
*
* @param itemData The player's new item data
*/
public void setItemData(ItemData itemData) {
if (itemData == null) itemData = new ItemData(ParticleUtils.closestMatchWithFallback("IRON_SHOVEL", "IRON_SPADE"));
this.particleItemData = itemData;
}
/**
* Sets the player's block data
*
* @param blockData The player's new block data
*/
public void setBlockData(BlockData blockData) {
if (blockData == null) blockData = new BlockData(Material.STONE);
this.particleBlockData = blockData;
}
/**
* Sets the player's color data
*
* @param colorData The player's new color data
*/
public void setColorData(OrdinaryColor colorData) {
if (colorData == null) colorData = new OrdinaryColor(0, 0, 0);
this.particleColorData = colorData;
}
/**
* Sets the player's note color data
*
* @param noteColorData The player's new note color data
*/
public void setNoteColorData(NoteColor noteColorData) {
if (noteColorData == null) noteColorData = new NoteColor(0);
this.particleNoteColorData = noteColorData;
}
/**
* Gets the data the current particle effect will spawn with
*
* @return The ParticleData the current particle effect requires
*/
public ParticleData getParticleSpawnData() {
if (this.particleEffect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
if (this.particleEffect == ParticleEffect.ITEM) {
return this.particleItemData;
} else {
return this.particleBlockData;
}
}
return null;
}
/**
* Gets the color the current particle effect will spawn with
*
* @return Gets the ParticleColor the current particle effect will spawn with
*/
public ParticleColor getParticleSpawnColor() {
if (this.particleEffect.hasProperty(ParticleProperty.COLORABLE)) {
if (this.particleEffect == ParticleEffect.NOTE) {
if (this.particleNoteColorData.getValueX() * 24 == 99) {
return ParticleManager.getRainbowNoteParticleColor();
}
return this.particleNoteColorData;
} else {
if (this.particleColorData.getRed() == 999 && this.particleColorData.getGreen() == 999 && this.particleColorData.getBlue() == 999) {
return ParticleManager.getRainbowParticleColor();
} else {
return this.particleColorData;
}
}
}
return null;
}
/**
* Gets the current particle data as a string
*
* @return The particle data in a human-readable string
*/
public String getParticleDataString() {
if (this.particleEffect == ParticleEffect.BLOCK || this.particleEffect == ParticleEffect.FALLING_DUST) {
return particleBlockData.getMaterial().toString().toLowerCase();
} else if (this.particleEffect == ParticleEffect.ITEM) {
return particleItemData.getMaterial().toString().toLowerCase();
} else if (this.particleEffect.hasProperty(ParticleProperty.COLORABLE)) {
if (this.particleEffect == ParticleEffect.NOTE) {
if (this.particleNoteColorData.getValueX() * 24 == 99) {
return PlayerParticlesGui.rainbowName;
}
return "note #" + (int) (this.particleNoteColorData.getValueX() * 24);
} else {
if (this.particleColorData.getRed() == 999 && this.particleColorData.getGreen() == 999 && this.particleColorData.getBlue() == 999) {
return PlayerParticlesGui.rainbowName;
} else {
return ChatColor.RED + "" + this.particleColorData.getRed() + " " + ChatColor.GREEN + this.particleColorData.getGreen() + " " + ChatColor.AQUA + this.particleColorData.getBlue();
}
}
}
return "none";
}
/**
* Gets a default PPlayer
* Used for when a new PPlayer is being created
*
* @param playerUUID The player's UUID
* @return A default PPlayer
*/
public static PPlayer getNewPPlayer(UUID playerUUID) {
ParticleEffect particleEffect = ParticleEffect.NONE;
ParticleStyle particleStyle = DefaultStyles.NONE;
ItemData particleItemData = new ItemData(ParticleUtils.closestMatchWithFallback("IRON_SHOVEL", "IRON_SPADE"));
BlockData particleBlockData = new BlockData(Material.STONE);
OrdinaryColor particleColorData = new OrdinaryColor(0, 0, 0);
NoteColor particleNoteColorData = new NoteColor(0);
return new PPlayer(playerUUID, particleEffect, particleStyle, particleItemData, particleBlockData, particleColorData, particleNoteColorData);
}
}

View file

@ -28,8 +28,12 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.esophose.playerparticles.command.ParticleCommandCompleter;
import com.esophose.playerparticles.command.ParticleCommandExecutor;
import com.esophose.playerparticles.database.DatabaseConnector;
import com.esophose.playerparticles.database.MySqlDatabaseConnector;
import com.esophose.playerparticles.database.SqliteDatabaseConnector;
import com.esophose.playerparticles.gui.PlayerParticlesGui; import com.esophose.playerparticles.gui.PlayerParticlesGui;
import com.esophose.playerparticles.manager.DatabaseManager;
import com.esophose.playerparticles.manager.MessageManager; import com.esophose.playerparticles.manager.MessageManager;
import com.esophose.playerparticles.manager.ParticleManager; import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.styles.DefaultStyles; import com.esophose.playerparticles.styles.DefaultStyles;
@ -38,6 +42,8 @@ import com.esophose.playerparticles.updater.Updater;
public class PlayerParticles extends JavaPlugin { public class PlayerParticles extends JavaPlugin {
private static Plugin pluginInstance;
/** /**
* The version a new update has, will be null if the config has it disabled * The version a new update has, will be null if the config has it disabled
* or if there is no new version * or if there is no new version
@ -45,14 +51,9 @@ public class PlayerParticles extends JavaPlugin {
public static String updateVersion = null; public static String updateVersion = null;
/** /**
* The MySQL database connection manager * The database connection manager
*/ */
public static DatabaseManager mySQL = null; public static DatabaseConnector databaseConnector = null;
/**
* Whether or not to use MySQL as determined in the config
*/
public static boolean useMySQL = false;
/** /**
* Registers all the styles available by default * Registers all the styles available by default
@ -66,8 +67,9 @@ public class PlayerParticles extends JavaPlugin {
* Checks for any updates if checking is enabled in the config * Checks for any updates if checking is enabled in the config
*/ */
public void onEnable() { public void onEnable() {
pluginInstance = Bukkit.getServer().getPluginManager().getPlugin("PlayerParticles");
DefaultStyles.registerStyles(); DefaultStyles.registerStyles();
MessageManager.setup(); MessageManager.setup(this.getConfig());
saveDefaultConfig(); saveDefaultConfig();
getCommand("pp").setTabCompleter(new ParticleCommandCompleter()); getCommand("pp").setTabCompleter(new ParticleCommandCompleter());
getCommand("pp").setExecutor(new ParticleCommandExecutor()); getCommand("pp").setExecutor(new ParticleCommandExecutor());
@ -76,59 +78,23 @@ public class PlayerParticles extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new PlayerParticlesGui(), this); Bukkit.getPluginManager().registerEvents(new PlayerParticlesGui(), this);
double configVersion = getConfig().getDouble("version"); double configVersion = getConfig().getDouble("version");
if (configVersion < Double.parseDouble(getDescription().getVersion())) { if (configVersion < Double.parseDouble(getDescription().getVersion())) {
// Make sure database information gets carried over between config updates
boolean databaseEnable = false;
String databaseHostname = "";
int databasePort = 3306;
String databaseName = "";
String databaseUserName = "";
String databaseUserPassword = "";
File configFile = new File(getDataFolder(), "config.yml"); File configFile = new File(getDataFolder(), "config.yml");
if (configFile.exists()) { if (configFile.exists()) {
databaseEnable = getConfig().getBoolean("database-enable");
databaseHostname = getConfig().getString("database-hostname");
databasePort = getConfig().getInt("database-port");
databaseName = getConfig().getString("database-name");
databaseUserName = getConfig().getString("database-user-name");
databaseUserPassword = getConfig().getString("database-user-password");
if (databaseEnable) { // @formatter:off
getLogger().warning("== WARNING == The PlayerParticles database configuration was detected as database-enable=true. " +
"The database configuration has been loaded this time for critical schema updates, but has also been DELETED from the config.yml! " +
"This needs to be replaced or else the plugin wont connect to the database on its next load!"); // @formatter:on
}
configFile.delete(); configFile.delete();
} }
saveDefaultConfig(); saveDefaultConfig();
reloadConfig(); reloadConfig();
getConfig().set("database-enable", databaseEnable);
getConfig().set("database-hostname", databaseHostname);
getConfig().set("database-port", databasePort);
getConfig().set("database-name", databaseName);
getConfig().set("database-user-name", databaseUserName);
getConfig().set("database-user-password", databaseUserPassword);
getLogger().warning("The config.yml has been updated to v" + getDescription().getVersion() + "!"); getLogger().warning("The config.yml has been updated to v" + getDescription().getVersion() + "!");
} }
if (configVersion < 5.2) { configureDatabase(getConfig().getBoolean("database-enable"));
checkDatabase(true); // @formatter:off
getLogger().warning("All previous player data has been purged. " +
"PlayerParticles v" + getDescription().getVersion() + " is not backwards compatible with the previous data schema. " +
"If you were using regular file storage, the new data file is called pplayerData.yml, the old file playerData.yml is still there. " +
"If you were using database storage, all data has been deleted."); // @formatter:on
} else {
checkDatabase(false);
}
checkDatabase(configVersion < 5.2);
startParticleTask(); startParticleTask();
if (shouldCheckUpdates()) { if (shouldCheckUpdates()) {
new BukkitRunnable() { new BukkitRunnable() {
public void run() { public void run() {
final File file = getFile();
try { // This can throw an exception if the server has no internet connection or if the Curse API is down try { // This can throw an exception if the server has no internet connection or if the Curse API is down
Updater updater = new Updater(getPlugin(), 82823, file, Updater.UpdateType.NO_DOWNLOAD, false); Updater updater = new Updater(pluginInstance, 82823, getFile(), Updater.UpdateType.NO_DOWNLOAD, false);
if (Double.parseDouble(updater.getLatestName().replaceAll("PlayerParticles v", "")) > Double.parseDouble(getPlugin().getDescription().getVersion())) { if (Double.parseDouble(updater.getLatestName().replaceAll("PlayerParticles v", "")) > Double.parseDouble(getPlugin().getDescription().getVersion())) {
updateVersion = updater.getLatestName().replaceAll("PlayerParticles v", ""); updateVersion = updater.getLatestName().replaceAll("PlayerParticles v", "");
getLogger().info("An update (v" + updateVersion + ") is available! You are running v" + getPlugin().getDescription().getVersion()); getLogger().info("An update (v" + updateVersion + ") is available! You are running v" + getPlugin().getDescription().getVersion());
@ -142,13 +108,11 @@ public class PlayerParticles extends JavaPlugin {
} }
/** /**
* Clean up MySQL connection if it's open * Clean up database connection if it's open
* Close all users with an open PlayerParticles GUI
*/ */
public void onDisable() { public void onDisable() {
if (useMySQL) { databaseConnector.closeConnection();
mySQL.closeConnection();
}
PlayerParticlesGui.forceCloseAllOpenGUIs(); PlayerParticlesGui.forceCloseAllOpenGUIs();
} }
@ -158,7 +122,7 @@ public class PlayerParticles extends JavaPlugin {
* @return The PlayerParticles plugin instance * @return The PlayerParticles plugin instance
*/ */
public static Plugin getPlugin() { public static Plugin getPlugin() {
return Bukkit.getPluginManager().getPlugin("PlayerParticles"); return pluginInstance;
} }
/** /**
@ -171,74 +135,63 @@ public class PlayerParticles extends JavaPlugin {
} }
/** /**
* Checks if database-enable is true in the config, if it is then continue * Checks if database-enable is true in the config, if it is then uses MySql
* Gets the database connection information from the config and tries to connect to the server * Gets the database connection information from the config and tries to connect to the server
* Removes old table from previous versions of the plugin * Removes old table from previous versions of the plugin
* Creates new tables if they don't exist * Creates new tables if they don't exist
* Sets useMySQL to true if it connects successfully, and false if it fails or isn't enabled
*/ */
private void checkDatabase(boolean shouldPurge) { private void configureDatabase(boolean useMySql) {
if (getConfig().getBoolean("database-enable")) { if (useMySql) {
mySQL = new DatabaseManager(getConfig()); databaseConnector = new MySqlDatabaseConnector(this.getConfig());
} else {
databaseConnector = new SqliteDatabaseConnector(this.getDataFolder().getAbsolutePath());
}
useMySQL = mySQL.isInitialized(); // If something goes wrong, this will be set to false if (!databaseConnector.isInitialized()) {
if (!useMySQL) return; // Break out, couldn't set up the database connection getLogger().severe("Unable to connect to the MySql database! Is your login information correct? Falling back to file database.");
configureDatabase(false);
// Queries are purposely not run in an asynchronous task, this is on plugin startup and shouldn't affect the end users
mySQL.connect((connection) -> { // @formatter:off
if (shouldPurge) { // Reset the database
try (Statement statement = connection.createStatement()) {
statement.addBatch("DROP TABLE pp_users"); // Drop tables, they will be recreated from scratch
statement.addBatch("DROP TABLE pp_fixed");
statement.addBatch("DROP TABLE pp_data_item");
statement.addBatch("DROP TABLE pp_data_block");
statement.addBatch("DROP TABLE pp_data_color");
statement.addBatch("DROP TABLE pp_data_note");
} catch (SQLException e) {
getLogger().info("Failed to connect to the MySQL Database! Check to see if your login information is correct!");
getLogger().info("Additional information: " + e.getMessage());
useMySQL = false;
return; return;
} }
databaseConnector.connect((connection) -> {
// Check if pp_users exists, if it does, this is an old database schema that needs to be deleted
try { // @formatter:off
try (Statement statement = connection.createStatement()) {
ResultSet result = statement.executeQuery("SHOW TABLES LIKE 'pp_users'");
if (result.next()) {
databaseConnector.updateSQL(
"DROP TABLE pp_users;" +
"DROP TABLE pp_fixed;" +
"DROP TABLE pp_data_item;" +
"DROP TABLE pp_data_block;" +
"DROP TABLE pp_data_color;" +
"DROP TABLE pp_data_note;"
);
}
} }
try (Statement statement = connection.createStatement(); // Check if pp_group exists, if it doesn't, we need to create all the tables
ResultSet res = statement.executeQuery("SHOW TABLES LIKE 'pp_users'")) { try (Statement statement = connection.createStatement()) {
ResultSet result = statement.executeQuery("SHOW TABLES LIKE 'pp_group'");
if (res.next()) { // Database is already created if (!result.next()) {
try (Statement statement2 = connection.createStatement(); databaseConnector.updateSQL(
ResultSet res2 = statement2.executeQuery("SHOW TABLES LIKE 'pp_fixed'")) { "CREATE TABLE pp_player (uuid VARCHAR(36));" +
"CREATE TABLE pp_group (uuid VARCHAR(36), owner_uuid VARCHAR(36), id SMALLINT);" +
if (!res2.next()) { // Is the current database of an old version? "CREATE TABLE pp_fixed (owner_uuid VARCHAR(36), id SMALLINT, particle_uuid VARCHAR(36), world VARCHAR(100), xPos DOUBLE, yPos DOUBLE, zPos DOUBLE);" +
mySQL.updateSQL("CREATE TABLE pp_fixed (uuid VARCHAR(36), player_uuid VARCHAR(36), id SMALLINT, effect VARCHAR(32), style VARCHAR(32), worldName VARCHAR(50), xPos DOUBLE, yPos DOUBLE, zPos DOUBLE);" + "CREATE TABLE pp_particle (uuid VARCHAR(36), group_uuid VARCHAR(36), effect VARCHAR(100), style VARCHAR(100), item_material VARCHAR(100), block_material VARCHAR(100), note SMALLINT, r SMALLINT, g SMALLINT, b SMALLINT);"
"ALTER TABLE pp_data_item CHANGE player_uuid uuid VARCHAR(36);" + );
"ALTER TABLE pp_data_block CHANGE player_uuid uuid VARCHAR(36);" +
"ALTER TABLE pp_data_color CHANGE player_uuid uuid VARCHAR(36);" +
"ALTER TABLE pp_data_note CHANGE player_uuid uuid VARCHAR(36);");
} }
} }
} else { // Database isn't created yet } catch (SQLException ex) {
mySQL.updateSQL("CREATE TABLE pp_users (player_uuid VARCHAR(36), effect VARCHAR(32), style VARCHAR(32));" + getLogger().severe("Unable to connect to the MySql database! Is your login information correct? Falling back to file database instead.");
"CREATE TABLE pp_fixed (uuid VARCHAR(36), player_uuid VARCHAR(36), id SMALLINT, effect VARCHAR(32), style VARCHAR(32), worldName VARCHAR(50), xPos DOUBLE, yPos DOUBLE, zPos DOUBLE);" + configureDatabase(false);
"CREATE TABLE pp_data_item (uuid VARCHAR(36), material VARCHAR(32));" + return;
"CREATE TABLE pp_data_block (uuid VARCHAR(36), material VARCHAR(32));" +
"CREATE TABLE pp_data_color (uuid VARCHAR(36), r SMALLINT, g SMALLINT, b SMALLINT);" +
"CREATE TABLE pp_data_note (uuid VARCHAR(36), note SMALLINT);");
} }
}); // @formatter:on
} catch (SQLException e) {
getLogger().info("Failed to connect to the MySQL Database! Check to see if your login information is correct!");
getLogger().info("Additional information: " + e.getMessage());
useMySQL = false;
}
});
} else {
useMySQL = false;
} // @formatter:on
} }
/** /**
* Starts the task reponsible for spawning particles * Starts the task responsible for spawning particles
* Run in the synchronous task so it starts after all plugins have loaded, including extensions * Run in the synchronous task so it starts after all plugins have loaded, including extensions
*/ */
private void startParticleTask() { private void startParticleTask() {

View file

@ -0,0 +1,15 @@
package com.esophose.playerparticles.command;
import com.esophose.playerparticles.particles.PPlayer;
public interface CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args);
public void onTabComplete(PPlayer pplayer, String[] args);
public String getName();
public String getArguments();
}

View file

@ -6,7 +6,7 @@
* be distributed to any person by any means. * be distributed to any person by any means.
*/ */
package com.esophose.playerparticles; package com.esophose.playerparticles.command;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -20,8 +20,9 @@ import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil; import org.bukkit.util.StringUtil;
import com.esophose.playerparticles.manager.MessageManager.MessageType; import com.esophose.playerparticles.manager.MessageManager.MessageType;
import com.esophose.playerparticles.manager.PPlayerDataManager; import com.esophose.playerparticles.manager.DataManager;
import com.esophose.playerparticles.manager.PermissionManager; import com.esophose.playerparticles.manager.PermissionManager;
import com.esophose.playerparticles.particles.PPlayer;
import com.esophose.playerparticles.particles.ParticleEffect; import com.esophose.playerparticles.particles.ParticleEffect;
import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty; import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty;
import com.esophose.playerparticles.util.ParticleUtils; import com.esophose.playerparticles.util.ParticleUtils;
@ -64,7 +65,7 @@ public class ParticleCommandCompleter implements TabCompleter {
completions.add("<id>"); completions.add("<id>");
} }
} else if (args[0].equalsIgnoreCase("data")) { } else if (args[0].equalsIgnoreCase("data")) {
PPlayer pplayer = PPlayerDataManager.getInstance().getPPlayer(((Player) sender).getUniqueId()); PPlayer pplayer = DataManager.getInstance().getPPlayer(((Player) sender).getUniqueId());
if (pplayer == null) { if (pplayer == null) {
completions.add(ChatColor.stripColor(MessageType.NO_DATA_USAGE.getMessage())); completions.add(ChatColor.stripColor(MessageType.NO_DATA_USAGE.getMessage()));
} else if (pplayer.getParticleEffect().hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA) && args.length == 2) { } else if (pplayer.getParticleEffect().hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA) && args.length == 2) {

View file

@ -6,7 +6,7 @@
* be distributed to any person by any means. * be distributed to any person by any means.
*/ */
package com.esophose.playerparticles; package com.esophose.playerparticles.command;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -23,17 +23,16 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.esophose.playerparticles.PlayerParticles;
import com.esophose.playerparticles.gui.PlayerParticlesGui; import com.esophose.playerparticles.gui.PlayerParticlesGui;
import com.esophose.playerparticles.gui.PlayerParticlesGui.GuiState; import com.esophose.playerparticles.gui.PlayerParticlesGui.GuiState;
import com.esophose.playerparticles.manager.PPlayerDataManager; import com.esophose.playerparticles.manager.DataManager;
import com.esophose.playerparticles.manager.MessageManager; import com.esophose.playerparticles.manager.MessageManager;
import com.esophose.playerparticles.manager.MessageManager.MessageType; import com.esophose.playerparticles.manager.MessageManager.MessageType;
import com.esophose.playerparticles.manager.ParticleManager; import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.manager.PermissionManager; import com.esophose.playerparticles.manager.PermissionManager;
import com.esophose.playerparticles.particles.FixedParticleEffect; import com.esophose.playerparticles.particles.FixedParticleEffect;
import com.esophose.playerparticles.particles.ParticleEffect; import com.esophose.playerparticles.particles.ParticleEffect;
import com.esophose.playerparticles.particles.ParticleEffect.BlockData;
import com.esophose.playerparticles.particles.ParticleEffect.ItemData;
import com.esophose.playerparticles.particles.ParticleEffect.NoteColor; import com.esophose.playerparticles.particles.ParticleEffect.NoteColor;
import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor; import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty; import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty;
@ -106,15 +105,15 @@ public class ParticleCommandExecutor implements CommandExecutor {
// Commands that require access to effects // Commands that require access to effects
if (PermissionManager.getEffectsUserHasPermissionFor(p).size() != 1) { if (PermissionManager.getEffectsUserHasPermissionFor(p).size() != 1) {
final String[] f_cmdArgs = cmdArgs; final String[] f_cmdArgs = cmdArgs;
PPlayerDataManager.getInstance().getPPlayer(p.getUniqueId(), (pplayer) -> { // The PPlayer MUST be loaded before we can execute any of these commands DataManager.getInstance().getPPlayer(p.getUniqueId(), (pplayer) -> { // The PPlayer MUST be loaded before we can execute any of these commands
// If the player no longer has permission for their effect, remove it // If the player no longer has permission for their effect, remove it
if (!PermissionManager.hasEffectPermission(p, pplayer.getParticleEffect())) { if (!PermissionManager.hasEffectPermission(p, pplayer.getParticleEffect())) {
PPlayerDataManager.getInstance().savePPlayer(pplayer.getUniqueId(), ParticleEffect.NONE); DataManager.getInstance().savePPlayer(pplayer.getUniqueId(), ParticleEffect.NONE);
} }
// If the player no longer has permission for their style, default to none // If the player no longer has permission for their style, default to none
if (!PermissionManager.hasStylePermission(p, pplayer.getParticleStyle())) { if (!PermissionManager.hasStylePermission(p, pplayer.getParticleStyle())) {
PPlayerDataManager.getInstance().savePPlayer(pplayer.getUniqueId(), DefaultStyles.NONE); DataManager.getInstance().savePPlayer(pplayer.getUniqueId(), DefaultStyles.NONE);
} }
switch (args[0].toLowerCase()) { switch (args[0].toLowerCase()) {
@ -170,13 +169,13 @@ public class ParticleCommandExecutor implements CommandExecutor {
* @param p The player who used the command * @param p The player who used the command
*/ */
private void onWorlds(Player p) { private void onWorlds(Player p) {
if (PPlayerDataManager.getInstance().getDisabledWorlds() == null || PPlayerDataManager.getInstance().getDisabledWorlds().isEmpty()) { if (DataManager.getInstance().getDisabledWorlds() == null || DataManager.getInstance().getDisabledWorlds().isEmpty()) {
MessageManager.sendMessage(p, MessageType.DISABLED_WORLDS_NONE); MessageManager.sendMessage(p, MessageType.DISABLED_WORLDS_NONE);
return; return;
} }
String worlds = ""; String worlds = "";
for (String s : PPlayerDataManager.getInstance().getDisabledWorlds()) { for (String s : DataManager.getInstance().getDisabledWorlds()) {
worlds += s + ", "; worlds += s + ", ";
} }
if (worlds.length() > 2) worlds = worlds.substring(0, worlds.length() - 2); if (worlds.length() > 2) worlds = worlds.substring(0, worlds.length() - 2);
@ -201,7 +200,7 @@ public class ParticleCommandExecutor implements CommandExecutor {
* @param args The arguments for the command * @param args The arguments for the command
*/ */
private void onData(Player p, String[] args) { private void onData(Player p, String[] args) {
ParticleEffect effect = PPlayerDataManager.getInstance().getPPlayer(p.getUniqueId()).getParticleEffect(); ParticleEffect effect = DataManager.getInstance().getPPlayer(p.getUniqueId()).getParticleEffect();
if ((!effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA) && !effect.hasProperty(ParticleProperty.COLORABLE)) || args.length == 0) { if ((!effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA) && !effect.hasProperty(ParticleProperty.COLORABLE)) || args.length == 0) {
if (effect.hasProperty(ParticleProperty.COLORABLE)) { if (effect.hasProperty(ParticleProperty.COLORABLE)) {
if (effect == ParticleEffect.NOTE) { if (effect == ParticleEffect.NOTE) {
@ -227,7 +226,7 @@ public class ParticleCommandExecutor implements CommandExecutor {
if (effect.hasProperty(ParticleProperty.COLORABLE)) { if (effect.hasProperty(ParticleProperty.COLORABLE)) {
if (effect == ParticleEffect.NOTE) { if (effect == ParticleEffect.NOTE) {
if (args[0].equalsIgnoreCase("rainbow")) { if (args[0].equalsIgnoreCase("rainbow")) {
PPlayerDataManager.getInstance().savePPlayer(p.getUniqueId(), new NoteColor(99)); DataManager.getInstance().savePPlayer(p.getUniqueId(), new NoteColor(99));
MessageManager.sendMessage(p, MessageType.DATA_APPLIED, "note"); MessageManager.sendMessage(p, MessageType.DATA_APPLIED, "note");
return; return;
} }
@ -247,11 +246,11 @@ public class ParticleCommandExecutor implements CommandExecutor {
return; return;
} }
PPlayerDataManager.getInstance().savePPlayer(p.getUniqueId(), new NoteColor(note)); DataManager.getInstance().savePPlayer(p.getUniqueId(), new NoteColor(note));
MessageManager.sendMessage(p, MessageType.DATA_APPLIED, "note"); MessageManager.sendMessage(p, MessageType.DATA_APPLIED, "note");
} else { } else {
if (args[0].equalsIgnoreCase("rainbow")) { if (args[0].equalsIgnoreCase("rainbow")) {
PPlayerDataManager.getInstance().savePPlayer(p.getUniqueId(), new OrdinaryColor(999, 999, 999)); DataManager.getInstance().savePPlayer(p.getUniqueId(), new OrdinaryColor(999, 999, 999));
MessageManager.sendMessage(p, MessageType.DATA_APPLIED, "color"); MessageManager.sendMessage(p, MessageType.DATA_APPLIED, "color");
} else if (args.length >= 3) { } else if (args.length >= 3) {
int r = -1; int r = -1;
@ -274,7 +273,7 @@ public class ParticleCommandExecutor implements CommandExecutor {
return; return;
} }
PPlayerDataManager.getInstance().savePPlayer(p.getUniqueId(), new OrdinaryColor(r, g, b)); DataManager.getInstance().savePPlayer(p.getUniqueId(), new OrdinaryColor(r, g, b));
MessageManager.sendMessage(p, MessageType.DATA_APPLIED, "color"); MessageManager.sendMessage(p, MessageType.DATA_APPLIED, "color");
} else { } else {
MessageManager.sendMessage(p, MessageType.DATA_INVALID_ARGUMENTS, "color"); MessageManager.sendMessage(p, MessageType.DATA_INVALID_ARGUMENTS, "color");
@ -300,7 +299,7 @@ public class ParticleCommandExecutor implements CommandExecutor {
return; return;
} }
PPlayerDataManager.getInstance().savePPlayer(p.getUniqueId(), new ItemData(material)); DataManager.getInstance().savePPlayer(p.getUniqueId(), new ItemData(material));
MessageManager.sendMessage(p, MessageType.DATA_APPLIED, "item"); MessageManager.sendMessage(p, MessageType.DATA_APPLIED, "item");
} else { } else {
Material material = null; Material material = null;
@ -320,7 +319,7 @@ public class ParticleCommandExecutor implements CommandExecutor {
return; return;
} }
PPlayerDataManager.getInstance().savePPlayer(p.getUniqueId(), new BlockData(material)); DataManager.getInstance().savePPlayer(p.getUniqueId(), new BlockData(material));
MessageManager.sendMessage(p, MessageType.DATA_APPLIED, "block"); MessageManager.sendMessage(p, MessageType.DATA_APPLIED, "block");
} }
} }
@ -343,14 +342,14 @@ public class ParticleCommandExecutor implements CommandExecutor {
if (altPlayer == null) { if (altPlayer == null) {
MessageManager.sendMessage(p, MessageType.FAILED_EXECUTE_NOT_FOUND, altPlayerName); MessageManager.sendMessage(p, MessageType.FAILED_EXECUTE_NOT_FOUND, altPlayerName);
} else { } else {
PPlayerDataManager.getInstance().resetPPlayer(altPlayer.getUniqueId()); DataManager.getInstance().resetPPlayer(altPlayer.getUniqueId());
MessageManager.sendMessage(altPlayer, MessageType.RESET); MessageManager.sendMessage(altPlayer, MessageType.RESET);
MessageManager.sendMessage(p, MessageType.EXECUTED_FOR_PLAYER, altPlayer.getName()); MessageManager.sendMessage(p, MessageType.EXECUTED_FOR_PLAYER, altPlayer.getName());
} }
} }
} else { } else {
PPlayerDataManager.getInstance().resetPPlayer(p.getUniqueId()); DataManager.getInstance().resetPPlayer(p.getUniqueId());
MessageManager.sendMessage(p, MessageType.RESET); MessageManager.sendMessage(p, MessageType.RESET);
} }
} }
@ -373,7 +372,7 @@ public class ParticleCommandExecutor implements CommandExecutor {
MessageManager.sendMessage(p, MessageType.NO_PERMISSION, effect.getName()); MessageManager.sendMessage(p, MessageType.NO_PERMISSION, effect.getName());
return; return;
} }
PPlayerDataManager.getInstance().savePPlayer(p.getUniqueId(), effect); DataManager.getInstance().savePPlayer(p.getUniqueId(), effect);
if (effect != ParticleEffect.NONE) { if (effect != ParticleEffect.NONE) {
MessageManager.sendMessage(p, MessageType.NOW_USING, effect.getName()); MessageManager.sendMessage(p, MessageType.NOW_USING, effect.getName());
} else { } else {
@ -432,7 +431,7 @@ public class ParticleCommandExecutor implements CommandExecutor {
MessageManager.sendMessage(p, MessageType.NO_PERMISSION_STYLE, style.getName()); MessageManager.sendMessage(p, MessageType.NO_PERMISSION_STYLE, style.getName());
return; return;
} }
PPlayerDataManager.getInstance().savePPlayer(p.getUniqueId(), style); DataManager.getInstance().savePPlayer(p.getUniqueId(), style);
if (style != DefaultStyles.NONE) { if (style != DefaultStyles.NONE) {
MessageManager.sendMessage(p, MessageType.NOW_USING_STYLE, style.getName()); MessageManager.sendMessage(p, MessageType.NOW_USING_STYLE, style.getName());
} else { } else {
@ -501,7 +500,7 @@ public class ParticleCommandExecutor implements CommandExecutor {
if (cmd.equalsIgnoreCase("create")) { if (cmd.equalsIgnoreCase("create")) {
final String[] f_args = args; final String[] f_args = args;
PPlayerDataManager.getInstance().hasPlayerReachedMaxFixedEffects(p.getUniqueId(), (reachedMax) -> { DataManager.getInstance().hasPlayerReachedMaxFixedEffects(p.getUniqueId(), (reachedMax) -> {
if (reachedMax) { if (reachedMax) {
MessageManager.sendMessage(p, MessageType.MAX_FIXED_EFFECTS_REACHED); MessageManager.sendMessage(p, MessageType.MAX_FIXED_EFFECTS_REACHED);
return; return;
@ -540,7 +539,7 @@ public class ParticleCommandExecutor implements CommandExecutor {
} }
double distanceFromEffect = p.getLocation().distance(new Location(p.getWorld(), xPos, yPos, zPos)); double distanceFromEffect = p.getLocation().distance(new Location(p.getWorld(), xPos, yPos, zPos));
int maxCreationDistance = PPlayerDataManager.getInstance().getMaxFixedEffectCreationDistance(); int maxCreationDistance = DataManager.getInstance().getMaxFixedEffectCreationDistance();
if (maxCreationDistance != 0 && distanceFromEffect > maxCreationDistance) { if (maxCreationDistance != 0 && distanceFromEffect > maxCreationDistance) {
MessageManager.sendMessage(p, MessageType.CREATE_FIXED_OUT_OF_RANGE, maxCreationDistance + ""); MessageManager.sendMessage(p, MessageType.CREATE_FIXED_OUT_OF_RANGE, maxCreationDistance + "");
return; return;
@ -656,14 +655,14 @@ public class ParticleCommandExecutor implements CommandExecutor {
final OrdinaryColor f_colorData = colorData; final OrdinaryColor f_colorData = colorData;
final NoteColor f_noteData = noteColorData; final NoteColor f_noteData = noteColorData;
PPlayerDataManager.getInstance().getNextFixedEffectId(p.getUniqueId(), (nextFixedEffectId) -> { DataManager.getInstance().getNextFixedEffectId(p.getUniqueId(), (nextFixedEffectId) -> {
FixedParticleEffect fixedEffect = new FixedParticleEffect(p.getUniqueId(), // @formatter:off FixedParticleEffect fixedEffect = new FixedParticleEffect(p.getUniqueId(), // @formatter:off
nextFixedEffectId, nextFixedEffectId,
p.getLocation().getWorld().getName(), f_xPos, f_yPos, f_zPos, p.getLocation().getWorld().getName(), f_xPos, f_yPos, f_zPos,
effect, style, f_itemData, f_blockData, f_colorData, f_noteData); // @formatter:on effect, style, f_itemData, f_blockData, f_colorData, f_noteData); // @formatter:on
MessageManager.sendMessage(p, MessageType.CREATE_FIXED_SUCCESS); MessageManager.sendMessage(p, MessageType.CREATE_FIXED_SUCCESS);
PPlayerDataManager.getInstance().saveFixedEffect(fixedEffect); DataManager.getInstance().saveFixedEffect(fixedEffect);
}); });
}); });
} else if (cmd.equalsIgnoreCase("remove")) { } else if (cmd.equalsIgnoreCase("remove")) {
@ -681,7 +680,7 @@ public class ParticleCommandExecutor implements CommandExecutor {
} }
final int f_id = id; final int f_id = id;
PPlayerDataManager.getInstance().removeFixedEffect(p.getUniqueId(), id, (successful) -> { DataManager.getInstance().removeFixedEffect(p.getUniqueId(), id, (successful) -> {
if (successful) { if (successful) {
MessageManager.sendMessage(p, MessageType.REMOVE_FIXED_SUCCESS, f_id + ""); MessageManager.sendMessage(p, MessageType.REMOVE_FIXED_SUCCESS, f_id + "");
} else { } else {
@ -689,7 +688,7 @@ public class ParticleCommandExecutor implements CommandExecutor {
} }
}); });
} else if (cmd.equalsIgnoreCase("list")) { } else if (cmd.equalsIgnoreCase("list")) {
PPlayerDataManager.getInstance().getFixedEffectIdsForPlayer(p.getUniqueId(), (ids) -> { DataManager.getInstance().getFixedEffectIdsForPlayer(p.getUniqueId(), (ids) -> {
Collections.sort(ids); Collections.sort(ids);
if (ids.isEmpty()) { if (ids.isEmpty()) {
@ -723,7 +722,7 @@ public class ParticleCommandExecutor implements CommandExecutor {
final int f_id = id; final int f_id = id;
PPlayerDataManager.getInstance().getFixedEffectForPlayerById(p.getUniqueId(), id, (fixedEffect) -> { DataManager.getInstance().getFixedEffectForPlayerById(p.getUniqueId(), id, (fixedEffect) -> {
if (fixedEffect == null) { if (fixedEffect == null) {
MessageManager.sendMessage(p, MessageType.INFO_FIXED_NONEXISTANT, f_id + ""); MessageManager.sendMessage(p, MessageType.INFO_FIXED_NONEXISTANT, f_id + "");
return; return;
@ -767,7 +766,7 @@ public class ParticleCommandExecutor implements CommandExecutor {
fixedEffectsToRemove.add(fixedEffect); fixedEffectsToRemove.add(fixedEffect);
for (FixedParticleEffect fixedEffect : fixedEffectsToRemove) for (FixedParticleEffect fixedEffect : fixedEffectsToRemove)
PPlayerDataManager.getInstance().removeFixedEffect(fixedEffect.getOwnerUniqueId(), fixedEffect.getId(), (successful) -> { }); DataManager.getInstance().removeFixedEffect(fixedEffect.getOwnerUniqueId(), fixedEffect.getId(), (successful) -> { });
String clearMessage = MessageType.CLEAR_FIXED_SUCCESS.getMessage() // @formatter:off String clearMessage = MessageType.CLEAR_FIXED_SUCCESS.getMessage() // @formatter:off
.replaceAll("\\{0\\}", fixedEffectsToRemove.size() + "") .replaceAll("\\{0\\}", fixedEffectsToRemove.size() + "")
@ -807,7 +806,7 @@ public class ParticleCommandExecutor implements CommandExecutor {
MessageManager.sendMessage(p, MessageType.GUI_BY_DEFAULT); MessageManager.sendMessage(p, MessageType.GUI_BY_DEFAULT);
} }
PPlayerDataManager.getInstance().getPPlayer(p.getUniqueId(), (pplayer) -> { DataManager.getInstance().getPPlayer(p.getUniqueId(), (pplayer) -> {
PlayerParticlesGui.changeState(pplayer, GuiState.DEFAULT); PlayerParticlesGui.changeState(pplayer, GuiState.DEFAULT);
}); });
} }

View file

@ -0,0 +1,83 @@
package com.esophose.playerparticles.database;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
public abstract class DatabaseConnector {
/**
* Checks if the connection to the database has been created
*
* @return If the connection is created or not
*/
public abstract boolean isInitialized();
/**
* Closes all open connections to the database
*/
public abstract void closeConnection();
/**
* Executes a callback with a Connection passed and automatically closes it when finished
*
* @param callback The callback to execute once the connection is retrieved
*/
public abstract void connect(ConnectionCallback callback);
/**
* Gets a connection to the database
*
* @return A Connection to the database
* @throws SQLException If an SQL problem occurs getting the connection
*/
protected abstract Connection getConnection() throws SQLException;
/**
* Executes an update statement and cleans up all resources
* Allows batched statements separated by semicolons
*
* @param query The update statement to run
* @return An int with the status of the first statement in the query
* @throws SQLException If an SQL problem occurs executing the statement
*/
public int updateSQL(String query) throws SQLException {
Connection connection = null;
Statement statement = null;
try {
connection = this.getConnection();
statement = connection.createStatement();
int[] results;
if (query.indexOf(';') != -1) {
String[] queries = query.split(";");
for (String q : queries) {
statement.addBatch(q);
}
results = statement.executeBatch();
} else {
results = new int[] { statement.executeUpdate(query) };
}
statement.close();
return results[0];
} catch (SQLException ex) {
throw ex;
} finally {
try { if (connection != null) connection.close(); } catch (Exception ex) { };
try { if (statement != null) statement.close(); } catch (Exception ex) { };
}
}
/**
* Allows Lambda expressions to be used to reduce duplicated code for getting connections
*/
public static interface ConnectionCallback {
public void execute(Connection connection) throws SQLException;
}
}

View file

@ -0,0 +1,58 @@
package com.esophose.playerparticles.database;
import java.sql.Connection;
import java.sql.SQLException;
import org.bukkit.configuration.file.FileConfiguration;
import com.esophose.playerparticles.PlayerParticles;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
public class MySqlDatabaseConnector extends DatabaseConnector {
private HikariDataSource hikari;
private boolean initializedSuccessfully = false;
public MySqlDatabaseConnector(FileConfiguration pluginConfig) {
String hostname = pluginConfig.getString("database-hostname");
String port = pluginConfig.getString("database-port");
String database = pluginConfig.getString("database-name");
String user = pluginConfig.getString("database-user-name");
String pass = pluginConfig.getString("database-user-password");
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://" + hostname + ":" + port + "/" + database);
config.setUsername(user);
config.setPassword(pass);
config.setMaximumPoolSize(5);
try {
hikari = new HikariDataSource(config);
initializedSuccessfully = true;
} catch (Exception ex) {
initializedSuccessfully = false;
}
}
public boolean isInitialized() {
return initializedSuccessfully;
}
public void closeConnection() {
hikari.close();
}
public void connect(ConnectionCallback callback) {
try (Connection connection = this.getConnection()) {
callback.execute(connection);
} catch (SQLException ex) {
PlayerParticles.getPlugin().getLogger().severe("An error occurred retrieving a mysql database connection: " + ex.getMessage());
}
}
protected Connection getConnection() throws SQLException {
return hikari.getConnection();
}
}

View file

@ -0,0 +1,38 @@
package com.esophose.playerparticles.database;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import com.esophose.playerparticles.PlayerParticles;
public class SqliteDatabaseConnector extends DatabaseConnector {
private final String connectionString;
public SqliteDatabaseConnector(String directory) {
this.connectionString = "jdbc:sqlite:" + directory + File.separator + "playerparticles.db";
}
public boolean isInitialized() {
return true; // Always available
}
public void closeConnection() {
// Nothing to do
}
public void connect(ConnectionCallback callback) {
try (Connection connection = this.getConnection()) {
callback.execute(connection);
} catch (SQLException ex) {
PlayerParticles.getPlugin().getLogger().severe("An error occurred retrieving an sqlite database connection: " + ex.getMessage());
}
}
protected Connection getConnection() throws SQLException {
return DriverManager.getConnection(this.connectionString);
}
}

View file

@ -38,13 +38,11 @@ import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.material.Dye; import org.bukkit.material.Dye;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.esophose.playerparticles.PPlayer;
import com.esophose.playerparticles.PlayerParticles; import com.esophose.playerparticles.PlayerParticles;
import com.esophose.playerparticles.manager.PPlayerDataManager; import com.esophose.playerparticles.manager.DataManager;
import com.esophose.playerparticles.manager.MessageManager.MessageType; import com.esophose.playerparticles.manager.MessageManager.MessageType;
import com.esophose.playerparticles.particles.PPlayer;
import com.esophose.playerparticles.particles.ParticleEffect; import com.esophose.playerparticles.particles.ParticleEffect;
import com.esophose.playerparticles.particles.ParticleEffect.BlockData;
import com.esophose.playerparticles.particles.ParticleEffect.ItemData;
import com.esophose.playerparticles.particles.ParticleEffect.NoteColor; import com.esophose.playerparticles.particles.ParticleEffect.NoteColor;
import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor; import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty; import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty;
@ -135,7 +133,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
Inventory testingInventory = Bukkit.createInventory(null, 9); Inventory testingInventory = Bukkit.createInventory(null, 9);
for (Material mat : Material.values()) { for (Material mat : Material.values()) {
// Verify an ItemStack of the material can be placed into an inventory. In 1.12 and up this can easily be checked with mat.isItem(), but that doesn't exist pre 1.12 // Verify an ItemStack of the material can be placed into an inventory. In 1.12 and up this can easily be checked with mat.isItem(), but that doesn't exist pre-1.12
testingInventory.clear(); testingInventory.clear();
testingInventory.setItem(0, new ItemStack(mat, 1)); testingInventory.setItem(0, new ItemStack(mat, 1));
ItemStack itemStack = testingInventory.getItem(0); ItemStack itemStack = testingInventory.getItem(0);
@ -199,7 +197,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
for (Map.Entry<UUID, GuiInventory> entry : playerGuiInventories.entrySet()) { for (Map.Entry<UUID, GuiInventory> entry : playerGuiInventories.entrySet()) {
UUID playerUUID = entry.getKey(); UUID playerUUID = entry.getKey();
PPlayer pplayer = PPlayerDataManager.getInstance().getPPlayer(playerUUID); PPlayer pplayer = DataManager.getInstance().getPPlayer(playerUUID);
if (pplayer == null) { if (pplayer == null) {
toRemoveList.add(playerUUID); toRemoveList.add(playerUUID);
continue; continue;
@ -274,7 +272,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
if ((state == GuiState.EFFECT && PermissionManager.getEffectsUserHasPermissionFor(player).size() == 1) || if ((state == GuiState.EFFECT && PermissionManager.getEffectsUserHasPermissionFor(player).size() == 1) ||
(state == GuiState.STYLE && PermissionManager.getStylesUserHasPermissionFor(player).size() == 1) || (state == GuiState.STYLE && PermissionManager.getStylesUserHasPermissionFor(player).size() == 1) ||
(state == GuiState.DATA && p.getParticleSpawnData() == null && p.getParticleSpawnColor() == null)) return; (state == GuiState.DATA && p.getSpawnMaterial() == null && p.getSpawnColor() == null)) return;
// Update the state and create an inventory for the player if one isn't already open for them // Update the state and create an inventory for the player if one isn't already open for them
// If they have the wrong inventory open for some reason, create a new one and open it for them // If they have the wrong inventory open for some reason, create a new one and open it for them
@ -365,7 +363,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
else if (pe.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) if (pe == ParticleEffect.ITEM) dataType = "item " + dataType; else if (pe.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) if (pe == ParticleEffect.ITEM) dataType = "item " + dataType;
else dataType = "block " + dataType; // @formatter:on else dataType = "block " + dataType; // @formatter:on
dataIconMeta.setLore(Arrays.asList(MessageType.GUI_ICON_SET_YOUR.getMessageReplaced(dataType))); dataIconMeta.setLore(Arrays.asList(MessageType.GUI_ICON_SET_YOUR.getMessageReplaced(dataType)));
if (p.getParticleSpawnData() == null && p.getParticleSpawnColor() == null) { if (p.getSpawnMaterial() == null && p.getSpawnColor() == null) {
dataIconMeta.setLore(Arrays.asList(MessageType.GUI_NO_DATA.getMessage())); dataIconMeta.setLore(Arrays.asList(MessageType.GUI_NO_DATA.getMessage()));
} }
dataIcon.setItemMeta(dataIconMeta); dataIcon.setItemMeta(dataIconMeta);
@ -475,7 +473,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
int materialIndex = 0; int materialIndex = 0;
if (pe == ParticleEffect.ITEM) { // Item data if (pe == ParticleEffect.ITEM) { // Item data
Material currentItemMaterial = p.getItemData().getMaterial(); Material currentItemMaterial = p.getMaterialData().getMaterial();
while (materialBag.size() < 28) { // Grab 28 random materials that are an item while (materialBag.size() < 28) { // Grab 28 random materials that are an item
Material randomMaterial = ITEM_MATERIALS.get(RANDOM.nextInt(ITEM_MATERIALS.size())); Material randomMaterial = ITEM_MATERIALS.get(RANDOM.nextInt(ITEM_MATERIALS.size()));
@ -551,7 +549,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
if (!guiInventory.getInventory().equals(e.getClickedInventory())) return; // Clicked bottom inventory if (!guiInventory.getInventory().equals(e.getClickedInventory())) return; // Clicked bottom inventory
PPlayer pplayer = PPlayerDataManager.getInstance().getPPlayer(player.getUniqueId()); PPlayer pplayer = DataManager.getInstance().getPPlayer(player.getUniqueId());
if (pplayer == null) { if (pplayer == null) {
player.closeInventory(); player.closeInventory();
return; return;
@ -578,11 +576,11 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
} }
break; break;
case EFFECT: case EFFECT:
PPlayerDataManager.getInstance().savePPlayer(pplayer.getUniqueId(), ParticleManager.effectFromString(name)); DataManager.getInstance().savePPlayer(pplayer.getUniqueId(), ParticleManager.effectFromString(name));
changeState(pplayer, GuiState.DEFAULT); changeState(pplayer, GuiState.DEFAULT);
break; break;
case STYLE: case STYLE:
PPlayerDataManager.getInstance().savePPlayer(pplayer.getUniqueId(), ParticleStyleManager.styleFromString(name)); DataManager.getInstance().savePPlayer(pplayer.getUniqueId(), ParticleStyleManager.styleFromString(name));
changeState(pplayer, GuiState.DEFAULT); changeState(pplayer, GuiState.DEFAULT);
break; break;
case DATA: case DATA:
@ -590,18 +588,18 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
if (pe.hasProperty(ParticleProperty.COLORABLE)) { if (pe.hasProperty(ParticleProperty.COLORABLE)) {
if (pe == ParticleEffect.NOTE) { if (pe == ParticleEffect.NOTE) {
if (clicked.getItemMeta().getDisplayName().equals(rainbowName)) { if (clicked.getItemMeta().getDisplayName().equals(rainbowName)) {
PPlayerDataManager.getInstance().savePPlayer(pplayer.getUniqueId(), new NoteColor(99)); DataManager.getInstance().savePPlayer(pplayer.getUniqueId(), new NoteColor(99));
} else { } else {
int note = Integer.parseInt(ChatColor.stripColor(clicked.getItemMeta().getDisplayName()).substring(6)); int note = Integer.parseInt(ChatColor.stripColor(clicked.getItemMeta().getDisplayName()).substring(6));
PPlayerDataManager.getInstance().savePPlayer(pplayer.getUniqueId(), new NoteColor(note)); DataManager.getInstance().savePPlayer(pplayer.getUniqueId(), new NoteColor(note));
} }
} else { } else {
if (clicked.getItemMeta().getDisplayName().equals(rainbowName)) { if (clicked.getItemMeta().getDisplayName().equals(rainbowName)) {
PPlayerDataManager.getInstance().savePPlayer(pplayer.getUniqueId(), new OrdinaryColor(999, 999, 999)); DataManager.getInstance().savePPlayer(pplayer.getUniqueId(), new OrdinaryColor(999, 999, 999));
} else { } else {
for (int i = 0; i < colorMapping.length; i++) { for (int i = 0; i < colorMapping.length; i++) {
if (clicked.getItemMeta().getDisplayName().equals(colorMapping[i].getName())) { if (clicked.getItemMeta().getDisplayName().equals(colorMapping[i].getName())) {
PPlayerDataManager.getInstance().savePPlayer(pplayer.getUniqueId(), colorMapping[i].getOrdinaryColor()); DataManager.getInstance().savePPlayer(pplayer.getUniqueId(), colorMapping[i].getOrdinaryColor());
} }
} }
} }
@ -609,9 +607,9 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
} else if (pe.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) { } else if (pe.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
Material clickedMaterial = clicked.getType(); // All preset materials have a data value of 0 Material clickedMaterial = clicked.getType(); // All preset materials have a data value of 0
if (pe == ParticleEffect.ITEM) { if (pe == ParticleEffect.ITEM) {
PPlayerDataManager.getInstance().savePPlayer(pplayer.getUniqueId(), new ItemData(clickedMaterial)); DataManager.getInstance().savePPlayer(pplayer.getUniqueId(), new ItemData(clickedMaterial));
} else { } else {
PPlayerDataManager.getInstance().savePPlayer(pplayer.getUniqueId(), new BlockData(clickedMaterial)); DataManager.getInstance().savePPlayer(pplayer.getUniqueId(), new BlockData(clickedMaterial));
} }
} }

View file

@ -0,0 +1,693 @@
/**
* Copyright Esophose 2018
* While using any of the code provided by this plugin
* you must not claim it as your own. This plugin may
* be modified and installed on a server, but may not
* be distributed to any person by any means.
*/
package com.esophose.playerparticles.manager;
import java.io.File;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.scheduler.BukkitRunnable;
import com.esophose.playerparticles.PlayerParticles;
import com.esophose.playerparticles.particles.FixedParticleEffect;
import com.esophose.playerparticles.particles.PPlayer;
import com.esophose.playerparticles.particles.ParticleEffect;
import com.esophose.playerparticles.particles.ParticleEffect.NoteColor;
import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
import com.esophose.playerparticles.styles.api.ParticleStyle;
import com.esophose.playerparticles.styles.api.ParticleStyleManager;
import com.esophose.playerparticles.util.ParticleUtils;
public class DataManager {
/**
* The disabled worlds cached for quick access
*/
private static List<String> disabledWorlds = null;
/**
* The max number of fixed effects a player can have, defined in the config
*/
private static int maxFixedEffects = -1;
/**
* The max distance a fixed effect can be created relative to the player
*/
private static int maxFixedEffectCreationDistance = -1;
/**
* This is not instantiable
*/
private DataManager() { }
/**
* Gets a PPlayer from cache
* This method should be used over the other one unless you absolutely need the PPlayer and you don't care about waiting
* You should always check for a null result when using this method
*
* @param playerUUID The PPlayer to get
* @return The PPlayer from cache
*/
public static PPlayer getPPlayer(UUID playerUUID) {
for (PPlayer pp : ParticleManager.particlePlayers)
if (pp.getUniqueId() == playerUUID)
return pp;
return null;
}
/**
* Gets a player from the save data, creates one if it doesn't exist and caches it
*
* @param playerUUID The pplayer to get
* @param callback The callback to execute with the found pplayer, or a newly generated one
*/
public static void getPPlayer(UUID playerUUID, ConfigurationCallback<PPlayer> callback) {
// Try to get them from cache first
PPlayer fromCache = getPPlayer(playerUUID);
if (fromCache != null) {
callback.execute(fromCache);
return;
}
// Either get an existing one from the database, or create a new one
buildPPlayer(playerUUID, true, (pplayer) -> {
ParticleManager.particlePlayers.add(pplayer);
callback.execute(pplayer);
});
}
/**
* Gets a PPlayer matching the UUID given
* If createIfNotFound is true, one will be created if it doesn't exist
*
* @param playerUUID The UUID to match the PPlayer to
* @param createIfNotFound If true, creates a new PPlayer if the requested one doesn't exist
* @param callback The callback to execute with the built PPlayer
*/
private static void buildPPlayer(UUID playerUUID, boolean createIfNotFound, ConfigurationCallback<PPlayer> callback) {
async(() -> {
String id = playerUUID.toString(); // @formatter:off
PlayerParticles.databaseConnector.connect((connection) -> {
String query = "SELECT * FROM pp_users u " +
"JOIN pp_data_item i ON u.player_uuid = i.uuid " +
"JOIN pp_data_block b ON u.player_uuid = b.uuid " +
"JOIN pp_data_color c ON u.player_uuid = c.uuid " +
"JOIN pp_data_note n ON u.player_uuid = n.uuid " +
"WHERE u.player_uuid = '" + id + "'";
try (Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery(query)) {
if (res.next()) {
ParticleEffect particleEffect = ParticleEffect.fromName(res.getString("u.effect"));
ParticleStyle particleStyle = ParticleStyleManager.styleFromString(res.getString("u.style"));
ItemData particleItemData = new ItemData(Material.matchMaterial(res.getString("i.material")));
BlockData particleBlockData = new BlockData(Material.matchMaterial(res.getString("b.material")));
OrdinaryColor particleColorData = new OrdinaryColor(res.getInt("c.r"), res.getInt("c.g"), res.getInt("c.b"));
NoteColor particleNoteColorData = new NoteColor(res.getByte("n.note"));
sync(() -> callback.execute(new PPlayer(playerUUID, particleEffect, particleStyle, particleItemData, particleBlockData, particleColorData, particleNoteColorData)));
return;
}
if (createIfNotFound) { // Didn't find an existing PPlayer, create and return a new one
PPlayer pplayer = PPlayer.getNewPPlayer(playerUUID);
saveNewPPlayer(pplayer);
sync(() -> callback.execute(pplayer));
}
}
});
});
}
/**
* Saves a new PPlayer to the database or the file
*
* @param pplayer The PPlayer to save
*/
public static void saveNewPPlayer(PPlayer pplayer) {
async(() -> {
PlayerParticles.databaseConnector.connect((connection) -> {
try (Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery("SELECT * FROM pp_users WHERE player_uuid = '" + pplayer.getUniqueId() + "'")) {
if (!res.next()) {
PlayerParticles.databaseConnector.updateSQL("INSERT INTO pp_users (player_uuid, effect, style) VALUES (" +
"'" + pplayer.getUniqueId().toString() + "', " +
"'" + pplayer.getParticleEffect().getName() + "', " +
"'" + pplayer.getParticleStyle().getName() + "'" +
"); " +
"INSERT INTO pp_data_item (uuid, material) VALUES (" +
"'" + pplayer.getUniqueId().toString() + "', " +
"'" + pplayer.getMaterialData().getMaterial().name() + "'" +
"); " +
"INSERT INTO pp_data_block (uuid, material) VALUES (" +
"'" + pplayer.getUniqueId().toString() + "', " +
"'" + pplayer.getBlockData().getMaterial().name() + "'" +
"); " +
"INSERT INTO pp_data_color (uuid, r, g, b) VALUES (" +
"'" + pplayer.getUniqueId().toString() + "', " +
pplayer.getColorData().getRed() + ", " +
pplayer.getColorData().getGreen() + ", " +
pplayer.getColorData().getBlue() +
"); " +
"INSERT INTO pp_data_note (uuid, note) VALUES (" +
"'" + pplayer.getUniqueId().toString() + "', " +
(byte) (pplayer.getNoteColorData().getValueX() * 24) +
");"
);
} else {
throw new RuntimeException("The user " + pplayer.getUniqueId() + " is already in the database. They can not be added.");
}
}
});
});
ParticleManager.updateIfContains(pplayer); // Update the player in case this is a /pp reset
}
/**
* Loads a PPlayer and caches it
*
* @param playerUUID The pplayer to load
*/
public static void loadPPlayer(UUID playerUUID) {
for (PPlayer pplayer : ParticleManager.particlePlayers)
if (pplayer.getUniqueId() == playerUUID)
return;
buildPPlayer(playerUUID, false, (pplayer) -> {
ParticleManager.particlePlayers.add(pplayer);
});
}
/**
* Resets all saved information about a PPlayer
* This should be made into a single batch query in the future
*
* @param playerUUID The pplayer to reset
*/
public static void resetPPlayer(UUID playerUUID) {
PPlayer pplayer = PPlayer.getNewPPlayer(playerUUID);
savePPlayer(playerUUID, pplayer.getParticleEffect());
savePPlayer(playerUUID, pplayer.getParticleStyle());
savePPlayer(playerUUID, pplayer.getMaterialData());
savePPlayer(playerUUID, pplayer.getBlockData());
savePPlayer(playerUUID, pplayer.getColorData());
savePPlayer(playerUUID, pplayer.getNoteColorData());
}
/**
* Saves the effect to the player's save file or database entry
*
* @param playerUUID The UUID of the player
* @param particleEffect The effect that is being saved
*/
public static void savePPlayer(UUID playerUUID, ParticleEffect particleEffect) {
getPPlayer(playerUUID, (pplayer) -> {
async(() -> {
try {
PlayerParticles.databaseConnector.updateSQL("UPDATE pp_users SET effect = '" + particleEffect.getName() + "' WHERE player_uuid = '" + playerUUID + "';");
} catch (SQLException e) {
e.printStackTrace();
}
});
pplayer.setParticleEffect(particleEffect);
});
}
/**
* Saves the style to the player's save file or database entry
*
* @param playerUUID The UUID of the player
* @param particleStyle The style that is being saved
*/
public static void savePPlayer(UUID playerUUID, ParticleStyle particleStyle) {
getPPlayer(playerUUID, (pplayer) -> {
async(() -> {
try {
PlayerParticles.databaseConnector.updateSQL("UPDATE pp_users SET style = '" + particleStyle.getName() + "' WHERE player_uuid = '" + playerUUID + "';");
} catch (SQLException e) {
e.printStackTrace();
}
});
pplayer.setParticleStyle(particleStyle);
});
}
/**
* Saves the item data to the player's save file or database entry
*
* @param playerUUID The UUID of the player
* @param particleItemData The data that is being saved
*/
public static void savePPlayer(UUID playerUUID, ItemData particleItemData) {
getPPlayer(playerUUID, (pplayer) -> {
async(() -> {
try {
PlayerParticles.databaseConnector.updateSQL("UPDATE pp_data_item SET material = '" + particleItemData.getMaterial().name() + "' WHERE uuid = '" + playerUUID + "';");
} catch (SQLException e) {
e.printStackTrace();
}
});
pplayer.setItemMaterial(particleItemData);
});
}
/**
* Saves the block data to the player's save file or database entry
*
* @param playerUUID The UUID of the player
* @param particleBlockData The data that is being saved
*/
public static void savePPlayer(UUID playerUUID, BlockData particleBlockData) {
getPPlayer(playerUUID, (pplayer) -> {
async(() -> {
try {
PlayerParticles.databaseConnector.updateSQL("UPDATE pp_data_block SET material = '" + particleBlockData.getMaterial().name() + "' WHERE uuid = '" + playerUUID + "';");
} catch (SQLException e) {
e.printStackTrace();
}
});
pplayer.setBlockData(particleBlockData);
});
}
/**
* Saves the color data to the player's save file or database entry
*
* @param playerUUID The UUID of the player
* @param particleColorData The data that is being saved
*/
public static void savePPlayer(UUID playerUUID, OrdinaryColor particleColorData) {
getPPlayer(playerUUID, (pplayer) -> {
async(() -> {
try {
PlayerParticles.databaseConnector.updateSQL("UPDATE pp_data_color SET r = " + particleColorData.getRed() + ", g = " + particleColorData.getGreen() + ", b = " + particleColorData.getBlue() + " WHERE uuid = '" + playerUUID + "';");
} catch (SQLException e) {
e.printStackTrace();
}
});
pplayer.setColorData(particleColorData);
});
}
/**
* Saves the note color data to the player's save file or database entry
*
* @param playerUUID The UUID of the player
* @param particleNoteColorData The data that is being saved
*/
public static void savePPlayer(UUID playerUUID, NoteColor particleNoteColorData) {
getPPlayer(playerUUID, (pplayer) -> {
async(() -> {
try {
PlayerParticles.databaseConnector.updateSQL("UPDATE pp_data_note SET note = " + (byte) (particleNoteColorData.getValueX() * 24) + " WHERE uuid = '" + playerUUID + "';");
} catch (SQLException e) {
e.printStackTrace();
}
});
pplayer.setNoteColorData(particleNoteColorData);
});
}
/**
* Saves a fixed effect to save data
*
* @param fixedEffect The fixed effect to save
*/
public static void saveFixedEffect(FixedParticleEffect fixedEffect) {
async(() -> {
PlayerParticles.databaseConnector.connect((connection) -> {
try (Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery("SELECT * FROM pp_fixed WHERE player_uuid = '" + fixedEffect.getOwnerUniqueId() + "' AND id = " + fixedEffect.getId())) {
if (res.next()) {
return;
}
String fixedEffectUUID = UUID.randomUUID().toString();
PlayerParticles.databaseConnector.updateSQL("INSERT INTO pp_fixed (uuid, player_uuid, id, effect, style, worldName, xPos, yPos, zPos) VALUES (" +
"'" + fixedEffectUUID + "', " +
"'" + fixedEffect.getOwnerUniqueId().toString() + "', " +
fixedEffect.getId() + ", " +
"'" + fixedEffect.getParticleEffect().getName() + "', " +
"'" + fixedEffect.getParticleStyle().getName() + "', " +
"'" + fixedEffect.getLocation().getWorld().getName() + "', " +
fixedEffect.getLocation().getX() + ", " +
fixedEffect.getLocation().getY() + ", " +
fixedEffect.getLocation().getZ() +
"); " +
"INSERT INTO pp_data_item (uuid, material) VALUES (" +
"'" + fixedEffectUUID + "', " +
"'" + fixedEffect.getMaterialData().getMaterial().name() + "'" +
"); " +
"INSERT INTO pp_data_block (uuid, material) VALUES (" +
"'" + fixedEffectUUID + "', " +
"'" + fixedEffect.getBlockData().getMaterial().name() + "'" +
"); " +
"INSERT INTO pp_data_color (uuid, r, g, b) VALUES (" +
"'" + fixedEffectUUID + "', " +
fixedEffect.getColorData().getRed() + ", " +
fixedEffect.getColorData().getGreen() + ", " +
fixedEffect.getColorData().getBlue() +
"); " +
"INSERT INTO pp_data_note (uuid, note) VALUES (" +
"'" + fixedEffectUUID + "', " +
(byte) (fixedEffect.getNoteColorData().getValueX() * 24) +
");"
);
sync(() -> ParticleManager.addFixedEffect(fixedEffect));
}
});
});
}
/**
* Deletes a fixed effect from save data
*
* @param playerUUID The player who owns the effect
* @param id The id of the effect to remove
* @param callback The callback to execute with if the fixed effect was removed or not
*/
public static void removeFixedEffect(UUID playerUUID, int id, ConfigurationCallback<Boolean> callback) {
async(() -> {
PlayerParticles.databaseConnector.connect((connection) -> {
try (Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery("SELECT uuid FROM pp_fixed WHERE player_uuid = '" + playerUUID.toString() + "' AND id = " + id)) {
if (!res.next()) {
callback.execute(false);
return;
}
String uuid = res.getString("uuid");
PlayerParticles.databaseConnector.updateSQL("DELETE FROM pp_fixed WHERE uuid = '" + uuid + "';" +
"DELETE FROM pp_data_item WHERE uuid = '" + uuid + "';" +
"DELETE FROM pp_data_block WHERE uuid = '" + uuid + "';" +
"DELETE FROM pp_data_color WHERE uuid = '" + uuid + "';" +
"DELETE FROM pp_data_note WHERE uuid = '" + uuid + "';"
);
sync(() -> {
ParticleManager.removeFixedEffectForPlayer(playerUUID, id);
callback.execute(true);
});
}
});
});
}
/**
* Resets all fixed effects for a given player
*
* @param playerUUID The player to remove all effects from
*/
public static void resetFixedEffects(UUID playerUUID) {
async(() -> {
try { // @formatter:off
PlayerParticles.databaseConnector.updateSQL("DELETE FROM pp_data_item WHERE uuid IN (SELECT uuid FROM pp_fixed WHERE player_uuid = '" + playerUUID.toString() + "');" +
"DELETE FROM pp_data_block WHERE uuid IN (SELECT uuid FROM pp_fixed WHERE player_uuid = '" + playerUUID.toString() + "');" +
"DELETE FROM pp_data_color WHERE uuid IN (SELECT uuid FROM pp_fixed WHERE player_uuid = '" + playerUUID.toString() + "');" +
"DELETE FROM pp_data_note WHERE uuid IN (SELECT uuid FROM pp_fixed WHERE player_uuid = '" + playerUUID.toString() + "');" +
"DELETE FROM pp_fixed WHERE player_uuid = '" + playerUUID.toString() + "';"
); // @formatter:on
} catch (SQLException e) {
e.printStackTrace();
}
});
ParticleManager.removeAllFixedEffectsForPlayer(playerUUID);
}
/**
* Gets a list of all saved fixed particle effects
*
* @param callback The callback to execute with a list of all saved fixed particle effects
*/
public static void getAllFixedEffects(ConfigurationCallback<List<FixedParticleEffect>> callback) {
async(() -> {
PlayerParticles.databaseConnector.connect((connection) -> {
String query = "SELECT * FROM pp_fixed f " +
"JOIN pp_data_item i ON f.uuid = i.uuid " +
"JOIN pp_data_block b ON f.uuid = b.uuid " +
"JOIN pp_data_color c ON f.uuid = c.uuid " +
"JOIN pp_data_note n ON f.uuid = n.uuid";
try (Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery(query)) {
List<FixedParticleEffect> fixedEffects = new ArrayList<FixedParticleEffect>();
while (res.next()) {
UUID pplayerUUID = UUID.fromString(res.getString("f.player_uuid"));
int id = res.getInt("f.id");
String worldName = res.getString("f.worldName");
double xPos = res.getDouble("f.xPos");
double yPos = res.getDouble("f.yPos");
double zPos = res.getDouble("f.zPos");
ParticleEffect particleEffect = ParticleManager.effectFromString(res.getString("f.effect"));
ParticleStyle particleStyle = ParticleStyleManager.styleFromString(res.getString("f.style"));
ItemData particleItemData = new ItemData(Material.matchMaterial(res.getString("i.material")));
BlockData particleBlockData = new BlockData(Material.matchMaterial(res.getString("b.material")));
OrdinaryColor particleColorData = new OrdinaryColor(res.getInt("c.r"), res.getInt("c.g"), res.getInt("c.b"));
NoteColor particleNoteColorData = new NoteColor(res.getByte("n.note"));
fixedEffects.add(new FixedParticleEffect(pplayerUUID, id, worldName, xPos, yPos, zPos, particleEffect, particleStyle, particleItemData, particleBlockData, particleColorData, particleNoteColorData));
}
sync(() -> callback.execute(fixedEffects));
}
});
});
}
/**
* Gets a fixed effect for a pplayer by its id
*
* @param pplayerUUID The player who owns the effect
* @param id The id for the effect to get
* @param callback The callback to execute with the effect, if one exists
*/
public static void getFixedEffectForPlayerById(UUID pplayerUUID, int id, ConfigurationCallback<FixedParticleEffect> callback) {
async(() -> {
PlayerParticles.databaseConnector.connect((connection) -> { // @formatter:off
String query = "SELECT * FROM pp_fixed f " +
"JOIN pp_data_item i ON f.uuid = i.uuid " +
"JOIN pp_data_block b ON f.uuid = b.uuid " +
"JOIN pp_data_color c ON f.uuid = c.uuid " +
"JOIN pp_data_note n ON f.uuid = n.uuid " +
"WHERE f.player_uuid = '" + pplayerUUID.toString() + "' AND f.id = '" + id + "'"; // @formatter:on
try (Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery(query)) {
if (res.next()) {
String worldName = res.getString("f.worldName");
double xPos = res.getDouble("f.xPos");
double yPos = res.getDouble("f.yPos");
double zPos = res.getDouble("f.zPos");
ParticleEffect particleEffect = ParticleManager.effectFromString(res.getString("f.effect"));
ParticleStyle particleStyle = ParticleStyleManager.styleFromString(res.getString("f.style"));
ItemData particleItemData = new ItemData(Material.matchMaterial(res.getString("i.material")));
BlockData particleBlockData = new BlockData(Material.matchMaterial(res.getString("b.material")));
OrdinaryColor particleColorData = new OrdinaryColor(res.getInt("c.r"), res.getInt("c.g"), res.getInt("c.b"));
NoteColor particleNoteColorData = new NoteColor(res.getByte("n.note"));
sync(() -> callback.execute(new FixedParticleEffect(pplayerUUID, id, worldName, xPos, yPos, zPos, particleEffect, particleStyle, particleItemData, particleBlockData, particleColorData, particleNoteColorData)));
}
}
});
});
}
/**
* Gets a list of all fixed effect ids for a player
*
* @param pplayerUUID The player
* @param callback The callback to execute with a list of all fixed effect ids for the given player
*/
public static void getFixedEffectIdsForPlayer(UUID pplayerUUID, ConfigurationCallback<List<Integer>> callback) {
async(() -> {
PlayerParticles.databaseConnector.connect((connection) -> {
try (Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery("SELECT id FROM pp_fixed WHERE player_uuid = '" + pplayerUUID.toString() + "'")) {
List<Integer> ids = new ArrayList<Integer>();
while (res.next()) {
ids.add(res.getInt(1));
}
sync(() -> callback.execute(ids));
}
});
});
}
/**
* Checks if the given player has reached the max number of fixed effects
*
* @param pplayerUUID The player to check
* @param callback The callback to execute with if the player can create any more fixed effects
*/
public static void hasPlayerReachedMaxFixedEffects(UUID pplayerUUID, ConfigurationCallback<Boolean> callback) {
if (maxFixedEffects == -1) { // Initialize on the fly
maxFixedEffects = PlayerParticles.getPlugin().getConfig().getInt("max-fixed-effects");
}
if (Bukkit.getPlayer(pplayerUUID).hasPermission("playerparticles.fixed.unlimited")) {
callback.execute(false);
return;
}
async(() -> {
PlayerParticles.databaseConnector.connect((connection) -> {
try (Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery("SELECT COUNT(1) FROM pp_fixed WHERE player_uuid = '" + pplayerUUID.toString() + "'")) {
boolean hasReachedMax;
if (res.next())
hasReachedMax = res.getInt(1) >= maxFixedEffects;
else
hasReachedMax = false;
sync(() -> callback.execute(hasReachedMax));
}
});
});
}
/**
* Gets the next Id for a player's fixed effects
*
* @param pplayerUUID The player to get the Id for
* @param callback The callback to execute with the smallest available Id the player can use
*/
public static void getNextFixedEffectId(UUID pplayerUUID, ConfigurationCallback<Integer> callback) {
async(() -> {
PlayerParticles.databaseConnector.connect((connection) -> {
try (Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery("SELECT id FROM pp_fixed WHERE player_uuid = '" + pplayerUUID.toString() + "'")) {
Set<String> idsSet = new HashSet<String>();
while (res.next())
idsSet.add(res.getInt(1) + "");
if (idsSet.isEmpty()) {
sync(() -> callback.execute(1));
return;
}
int[] ids = new int[idsSet.size()];
int i = 0;
for (String key : idsSet)
ids[i++] = Integer.parseInt(key);
sync(() -> callback.execute(ParticleUtils.getSmallestPositiveInt(ids)));
}
});
});
}
/**
* Gets the max distance a fixed effect can be created from the player
*
* @return The max distance a fixed effect can be created from the player
*/
public static int getMaxFixedEffectCreationDistance() {
if (maxFixedEffectCreationDistance == -1) { // Initialize on the fly
maxFixedEffectCreationDistance = PlayerParticles.getPlugin().getConfig().getInt("max-fixed-effect-creation-distance");
}
return maxFixedEffectCreationDistance;
}
/**
* Checks if a world is disabled for particles to spawn in
*
* @param world The world name to check
* @return True if the world is disabled
*/
public static boolean isWorldDisabled(String world) {
return getDisabledWorlds().contains(world);
}
/**
* Gets all the worlds that are disabled
*
* @return All world names that are disabled
*/
public static List<String> getDisabledWorlds() {
if (disabledWorlds == null) { // Initialize on the fly
disabledWorlds = PlayerParticles.getPlugin().getConfig().getStringList("disabled-worlds");
}
return disabledWorlds;
}
/**
* Asynchronizes the callback with it's own thread
*
* @param asyncCallback The callback to run on a separate thread
*/
private static void async(SyncInterface asyncCallback) {
new BukkitRunnable() {
public void run() {
asyncCallback.execute();
}
}.runTaskAsynchronously(PlayerParticles.getPlugin());
}
/**
* Synchronizes the callback with the main thread
*
* @param syncCallback The callback to run on the main thread
*/
private static void sync(SyncInterface syncCallback) {
new BukkitRunnable() {
public void run() {
syncCallback.execute();
}
}.runTask(PlayerParticles.getPlugin());
}
/**
* Provides an easy way to run a section of code either synchronously or asynchronously using a callback
*/
private static interface SyncInterface {
public void execute();
}
/**
* Allows callbacks to be passed between configuration methods and executed for returning objects after database queries
*/
public static interface ConfigurationCallback<T> {
public void execute(T obj);
}
}

View file

@ -1,114 +0,0 @@
package com.esophose.playerparticles.manager;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import org.bukkit.configuration.file.FileConfiguration;
import com.esophose.playerparticles.PlayerParticles;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
public class DatabaseManager {
private HikariDataSource hikari;
private boolean initializedSuccessfully = false;
public DatabaseManager(FileConfiguration pluginConfig) {
String hostname = pluginConfig.getString("database-hostname");
String port = pluginConfig.getString("database-port");
String database = pluginConfig.getString("database-name");
String user = pluginConfig.getString("database-user-name");
String pass = pluginConfig.getString("database-user-password");
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://" + hostname + ":" + port + "/" + database);
config.setUsername(user);
config.setPassword(pass);
config.setMaximumPoolSize(5);
try {
hikari = new HikariDataSource(config);
initializedSuccessfully = true;
} catch (Exception ex) {
initializedSuccessfully = false;
}
}
/**
* Checks if the connection to the database has been created
*
* @return If the connection is created or not
*/
public boolean isInitialized() {
return initializedSuccessfully;
}
/**
* Closes all connections to the database
*/
public void closeConnection() {
hikari.close();
}
/**
* Executes a callback with a Connection passed and automatically closes it
*
* @param callback The callback to execute once the connection is retrieved
*/
public void connect(ConnectionCallback callback) {
try (Connection connection = hikari.getConnection()) {
callback.execute(connection);
} catch (SQLException ex) {
PlayerParticles.getPlugin().getLogger().warning("An error occurred retrieving a database connection: " + ex.getMessage());
}
}
/**
* Executes an update statement and cleans up all resources
*
* @param query The update statement to run
* @return An int with the status of the first statement in the query
* @throws SQLException If an SQL problem occurs executing the statement
*/
public int updateSQL(String query) throws SQLException {
Connection connection = null;
Statement statement = null;
try {
connection = hikari.getConnection();
statement = connection.createStatement();
int[] results;
if (query.indexOf(';') != -1) {
String[] queries = query.split(";");
for (String q : queries) {
statement.addBatch(q);
}
results = statement.executeBatch();
} else {
results = new int[] { statement.executeUpdate(query) };
}
statement.close();
return results[0];
} catch (SQLException ex) {
throw ex;
} finally {
try { if (connection != null) connection.close(); } catch (Exception ex) { };
try { if (statement != null) statement.close(); } catch (Exception ex) { };
}
}
/**
* Allows Lambda expressions to be used to reduce duplicated code for getting connections
*/
public static interface ConnectionCallback {
public void execute(Connection connection) throws SQLException;
}
}

View file

@ -18,6 +18,7 @@ public class MessageManager {
/** /**
* Contains the location in the config of every chat message * Contains the location in the config of every chat message
* TODO: Implement .lang files
*/ */
public static enum MessageType { public static enum MessageType {
@ -150,10 +151,6 @@ public class MessageManager {
} }
} }
/**
* Stores the main config for quick access
*/
private static FileConfiguration config;
/** /**
* Stores if messages and their prefixes should be displayed * Stores if messages and their prefixes should be displayed
*/ */
@ -168,8 +165,7 @@ public class MessageManager {
* This should only get called once by the PlayerParticles class, however * This should only get called once by the PlayerParticles class, however
* calling it multiple times wont affect anything negatively * calling it multiple times wont affect anything negatively
*/ */
public static void setup() { public static void setup(FileConfiguration config) {
config = PlayerParticles.getPlugin().getConfig();
messagesEnabled = config.getBoolean("messages-enabled"); messagesEnabled = config.getBoolean("messages-enabled");
prefixEnabled = config.getBoolean("use-message-prefix"); prefixEnabled = config.getBoolean("use-message-prefix");
messagePrefix = parseColors(config.getString("message-prefix")); messagePrefix = parseColors(config.getString("message-prefix"));

View file

@ -1,998 +0,0 @@
/**
* Copyright Esophose 2018
* While using any of the code provided by this plugin
* you must not claim it as your own. This plugin may
* be modified and installed on a server, but may not
* be distributed to any person by any means.
*/
package com.esophose.playerparticles.manager;
import java.io.File;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.scheduler.BukkitRunnable;
import com.esophose.playerparticles.PPlayer;
import com.esophose.playerparticles.PlayerParticles;
import com.esophose.playerparticles.particles.FixedParticleEffect;
import com.esophose.playerparticles.particles.ParticleEffect;
import com.esophose.playerparticles.particles.ParticleEffect.BlockData;
import com.esophose.playerparticles.particles.ParticleEffect.ItemData;
import com.esophose.playerparticles.particles.ParticleEffect.NoteColor;
import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
import com.esophose.playerparticles.styles.api.ParticleStyle;
import com.esophose.playerparticles.styles.api.ParticleStyleManager;
import com.esophose.playerparticles.util.ParticleUtils;
public class PPlayerDataManager {
/**
* The instance of the ConfigManager used for effect data
*/
private static PPlayerDataManager instance = new PPlayerDataManager("pplayerData");
/**
* The file the data is located in for the instance
*/
private File playerDataYamlFile;
/**
* The configuration used to edit the .yaml file
*/
private FileConfiguration playerDataYaml;
/**
* The disabled worlds cached for quick access
*/
private List<String> disabledWorlds = null;
/**
* The max number of fixed effects a player can have, defined in the config
*/
private int maxFixedEffects = -1;
/**
* The max distance a fixed effect can be created relative to the player
*/
private int maxFixedEffectCreationDistance = -1;
/**
* @return The instance of the config for effects
*/
public static PPlayerDataManager getInstance() {
return instance;
}
/**
* @param fileName The name of the file
*/
private PPlayerDataManager(String fileName) {
if (!PlayerParticles.useMySQL) { // Don't bother creating the playerData.yml file if we aren't going to use it
if (!PlayerParticles.getPlugin().getDataFolder().exists()) PlayerParticles.getPlugin().getDataFolder().mkdir();
playerDataYamlFile = new File(PlayerParticles.getPlugin().getDataFolder(), fileName + ".yml");
if (!playerDataYamlFile.exists()) {
try {
playerDataYamlFile.createNewFile();
} catch (Exception e) {
e.printStackTrace();
}
}
playerDataYaml = YamlConfiguration.loadConfiguration(playerDataYamlFile);
}
}
/**
* Saves the playerData.yml file to disk
*/
private void save() {
try {
playerDataYaml.save(playerDataYamlFile);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Gets a PPlayer from cache
* This method should be used over the other one unless you absolutely need the PPlayer and you don't care about waiting
* You should always check for a null result when using this method
*
* @param playerUUID The PPlayer to get
* @return The PPlayer from cache
*/
public PPlayer getPPlayer(UUID playerUUID) {
for (PPlayer pp : ParticleManager.particlePlayers)
if (pp.getUniqueId() == playerUUID)
return pp;
return null;
}
/**
* Gets a player from the save data, creates one if it doesn't exist and caches it
*
* @param playerUUID The pplayer to get
* @param callback The callback to execute with the found pplayer, or a newly generated one
*/
public void getPPlayer(UUID playerUUID, ConfigurationCallback<PPlayer> callback) {
// Try to get them from cache first
PPlayer fromCache = getPPlayer(playerUUID);
if (fromCache != null) {
callback.execute(fromCache);
return;
}
// Either get an existing one from the database, or create a new one
buildPPlayer(playerUUID, true, (pplayer) -> {
ParticleManager.particlePlayers.add(pplayer);
callback.execute(pplayer);
});
}
/**
* Gets a PPlayer matching the UUID given
* If createIfNotFound is true, one will be created if it doesn't exist
*
* @param playerUUID The UUID to match the PPlayer to
* @param createIfNotFound If true, creates a new PPlayer if the requested one doesn't exist
* @param callback The callback to execute with the built PPlayer
*/
private void buildPPlayer(UUID playerUUID, boolean createIfNotFound, ConfigurationCallback<PPlayer> callback) {
if (!PlayerParticles.useMySQL) {
if (playerDataYaml.contains(playerUUID.toString())) {
ConfigurationSection section = playerDataYaml.getConfigurationSection(playerUUID.toString());
ConfigurationSection effectSection = section.getConfigurationSection("effect");
ConfigurationSection styleSection = section.getConfigurationSection("style");
ConfigurationSection itemDataSection = section.getConfigurationSection("itemData");
ConfigurationSection blockDataSection = section.getConfigurationSection("blockData");
ConfigurationSection colorDataSection = section.getConfigurationSection("colorData");
ConfigurationSection noteColorDataSection = section.getConfigurationSection("noteColorData");
ParticleEffect particleEffect = ParticleEffect.fromName(effectSection.getString("name"));
ParticleStyle particleStyle = ParticleStyleManager.styleFromString(styleSection.getString("name"));
ItemData particleItemData = new ItemData(Material.matchMaterial(itemDataSection.getString("material")));
BlockData particleBlockData = new BlockData(Material.matchMaterial(blockDataSection.getString("material")));
OrdinaryColor particleColorData = new OrdinaryColor(colorDataSection.getInt("r"), colorDataSection.getInt("g"), colorDataSection.getInt("b"));
NoteColor particleNoteColorData = new NoteColor(noteColorDataSection.getInt("note"));
callback.execute(new PPlayer(playerUUID, particleEffect, particleStyle, particleItemData, particleBlockData, particleColorData, particleNoteColorData));
return;
}
if (createIfNotFound) {
// Didn't find an existing PPlayer, create and return a new one
PPlayer pplayer = PPlayer.getNewPPlayer(playerUUID);
saveNewPPlayer(pplayer);
callback.execute(pplayer);
}
} else {
async(() -> {
String id = playerUUID.toString(); // @formatter:off
PlayerParticles.mySQL.connect((connection) -> {
String query = "SELECT * FROM pp_users u " +
"JOIN pp_data_item i ON u.player_uuid = i.uuid " +
"JOIN pp_data_block b ON u.player_uuid = b.uuid " +
"JOIN pp_data_color c ON u.player_uuid = c.uuid " +
"JOIN pp_data_note n ON u.player_uuid = n.uuid " +
"WHERE u.player_uuid = '" + id + "'";
try (Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery(query)) {
if (res.next()) {
ParticleEffect particleEffect = ParticleEffect.fromName(res.getString("u.effect"));
ParticleStyle particleStyle = ParticleStyleManager.styleFromString(res.getString("u.style"));
ItemData particleItemData = new ItemData(Material.matchMaterial(res.getString("i.material")));
BlockData particleBlockData = new BlockData(Material.matchMaterial(res.getString("b.material")));
OrdinaryColor particleColorData = new OrdinaryColor(res.getInt("c.r"), res.getInt("c.g"), res.getInt("c.b"));
NoteColor particleNoteColorData = new NoteColor(res.getByte("n.note"));
sync(() -> callback.execute(new PPlayer(playerUUID, particleEffect, particleStyle, particleItemData, particleBlockData, particleColorData, particleNoteColorData)));
return;
}
if (createIfNotFound) { // Didn't find an existing PPlayer, create and return a new one
PPlayer pplayer = PPlayer.getNewPPlayer(playerUUID);
saveNewPPlayer(pplayer);
sync(() -> callback.execute(pplayer));
}
}
});
});
}
}
/**
* Saves a new PPlayer to the database or the file
*
* @param pplayer The PPlayer to save
*/
public void saveNewPPlayer(PPlayer pplayer) {
if (!PlayerParticles.useMySQL) {
if (!playerDataYaml.isConfigurationSection(pplayer.getUniqueId().toString())) {
String id = pplayer.getUniqueId().toString();
playerDataYaml.createSection(id);
playerDataYaml.createSection(id + ".effect");
playerDataYaml.createSection(id + ".style");
playerDataYaml.createSection(id + ".itemData");
playerDataYaml.createSection(id + ".blockData");
playerDataYaml.createSection(id + ".colorData");
playerDataYaml.createSection(id + ".noteColorData");
}
ConfigurationSection section = playerDataYaml.getConfigurationSection(pplayer.getUniqueId().toString());
ConfigurationSection effectSection = section.getConfigurationSection("effect");
ConfigurationSection styleSection = section.getConfigurationSection("style");
ConfigurationSection itemDataSection = section.getConfigurationSection("itemData");
ConfigurationSection blockDataSection = section.getConfigurationSection("blockData");
ConfigurationSection colorDataSection = section.getConfigurationSection("colorData");
ConfigurationSection noteColorDataSection = section.getConfigurationSection("noteColorData");
effectSection.set("name", pplayer.getParticleEffect().getName());
styleSection.set("name", pplayer.getParticleStyle().getName());
itemDataSection.set("material", pplayer.getItemData().getMaterial().name());
blockDataSection.set("material", pplayer.getBlockData().getMaterial().name());
colorDataSection.set("r", pplayer.getColorData().getRed());
colorDataSection.set("g", pplayer.getColorData().getGreen());
colorDataSection.set("b", pplayer.getColorData().getBlue());
noteColorDataSection.set("note", (byte) (pplayer.getNoteColorData().getValueX() * 24));
save();
} else {
async(() -> {
PlayerParticles.mySQL.connect((connection) -> {
try (Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery("SELECT * FROM pp_users WHERE player_uuid = '" + pplayer.getUniqueId() + "'")) {
if (!res.next()) {
PlayerParticles.mySQL.updateSQL("INSERT INTO pp_users (player_uuid, effect, style) VALUES (" +
"'" + pplayer.getUniqueId().toString() + "', " +
"'" + pplayer.getParticleEffect().getName() + "', " +
"'" + pplayer.getParticleStyle().getName() + "'" +
"); " +
"INSERT INTO pp_data_item (uuid, material) VALUES (" +
"'" + pplayer.getUniqueId().toString() + "', " +
"'" + pplayer.getItemData().getMaterial().name() + "'" +
"); " +
"INSERT INTO pp_data_block (uuid, material) VALUES (" +
"'" + pplayer.getUniqueId().toString() + "', " +
"'" + pplayer.getBlockData().getMaterial().name() + "'" +
"); " +
"INSERT INTO pp_data_color (uuid, r, g, b) VALUES (" +
"'" + pplayer.getUniqueId().toString() + "', " +
pplayer.getColorData().getRed() + ", " +
pplayer.getColorData().getGreen() + ", " +
pplayer.getColorData().getBlue() +
"); " +
"INSERT INTO pp_data_note (uuid, note) VALUES (" +
"'" + pplayer.getUniqueId().toString() + "', " +
(byte) (pplayer.getNoteColorData().getValueX() * 24) +
");"
);
} else {
throw new RuntimeException("The user " + pplayer.getUniqueId() + " is already in the database. They can not be added.");
}
}
});
});
}
ParticleManager.updateIfContains(pplayer); // Update the player in case this is a /pp reset
}
/**
* Loads a PPlayer and caches it
*
* @param playerUUID The pplayer to load
*/
public void loadPPlayer(UUID playerUUID) {
for (PPlayer pplayer : ParticleManager.particlePlayers)
if (pplayer.getUniqueId() == playerUUID)
return;
buildPPlayer(playerUUID, false, (pplayer) -> {
ParticleManager.particlePlayers.add(pplayer);
});
}
/**
* Resets all saved information about a PPlayer
* This should be made into a single batch query in the future
*
* @param playerUUID The pplayer to reset
*/
public void resetPPlayer(UUID playerUUID) {
PPlayer pplayer = PPlayer.getNewPPlayer(playerUUID);
savePPlayer(playerUUID, pplayer.getParticleEffect());
savePPlayer(playerUUID, pplayer.getParticleStyle());
savePPlayer(playerUUID, pplayer.getItemData());
savePPlayer(playerUUID, pplayer.getBlockData());
savePPlayer(playerUUID, pplayer.getColorData());
savePPlayer(playerUUID, pplayer.getNoteColorData());
}
/**
* Saves the effect to the player's save file or database entry
*
* @param playerUUID The UUID of the player
* @param particleEffect The effect that is being saved
*/
public void savePPlayer(UUID playerUUID, ParticleEffect particleEffect) {
getPPlayer(playerUUID, (pplayer) -> {
if (!PlayerParticles.useMySQL) {
ConfigurationSection section = playerDataYaml.getConfigurationSection(playerUUID.toString() + ".effect");
section.set("name", particleEffect.getName());
save();
} else {
async(() -> {
try {
PlayerParticles.mySQL.updateSQL("UPDATE pp_users SET effect = '" + particleEffect.getName() + "' WHERE player_uuid = '" + playerUUID + "';");
} catch (SQLException e) {
e.printStackTrace();
}
});
}
pplayer.setParticleEffect(particleEffect);
});
}
/**
* Saves the style to the player's save file or database entry
*
* @param playerUUID The UUID of the player
* @param particleStyle The style that is being saved
*/
public void savePPlayer(UUID playerUUID, ParticleStyle particleStyle) {
getPPlayer(playerUUID, (pplayer) -> {
if (!PlayerParticles.useMySQL) {
ConfigurationSection section = playerDataYaml.getConfigurationSection(playerUUID.toString() + ".style");
section.set("name", particleStyle.getName());
save();
} else {
async(() -> {
try {
PlayerParticles.mySQL.updateSQL("UPDATE pp_users SET style = '" + particleStyle.getName() + "' WHERE player_uuid = '" + playerUUID + "';");
} catch (SQLException e) {
e.printStackTrace();
}
});
}
pplayer.setParticleStyle(particleStyle);
});
}
/**
* Saves the item data to the player's save file or database entry
*
* @param playerUUID The UUID of the player
* @param particleItemData The data that is being saved
*/
public void savePPlayer(UUID playerUUID, ItemData particleItemData) {
getPPlayer(playerUUID, (pplayer) -> {
if (!PlayerParticles.useMySQL) {
ConfigurationSection section = playerDataYaml.getConfigurationSection(playerUUID.toString() + ".itemData");
section.set("material", particleItemData.getMaterial().name());
save();
} else {
async(() -> {
try {
PlayerParticles.mySQL.updateSQL("UPDATE pp_data_item SET material = '" + particleItemData.getMaterial().name() + "' WHERE uuid = '" + playerUUID + "';");
} catch (SQLException e) {
e.printStackTrace();
}
});
}
pplayer.setItemData(particleItemData);
});
}
/**
* Saves the block data to the player's save file or database entry
*
* @param playerUUID The UUID of the player
* @param particleBlockData The data that is being saved
*/
public void savePPlayer(UUID playerUUID, BlockData particleBlockData) {
getPPlayer(playerUUID, (pplayer) -> {
if (!PlayerParticles.useMySQL) {
ConfigurationSection section = playerDataYaml.getConfigurationSection(playerUUID.toString() + ".blockData");
section.set("material", particleBlockData.getMaterial().name());
save();
} else {
async(() -> {
try {
PlayerParticles.mySQL.updateSQL("UPDATE pp_data_block SET material = '" + particleBlockData.getMaterial().name() + "' WHERE uuid = '" + playerUUID + "';");
} catch (SQLException e) {
e.printStackTrace();
}
});
}
pplayer.setBlockData(particleBlockData);
});
}
/**
* Saves the color data to the player's save file or database entry
*
* @param playerUUID The UUID of the player
* @param particleColorData The data that is being saved
*/
public void savePPlayer(UUID playerUUID, OrdinaryColor particleColorData) {
getPPlayer(playerUUID, (pplayer) -> {
if (!PlayerParticles.useMySQL) {
ConfigurationSection section = playerDataYaml.getConfigurationSection(playerUUID.toString() + ".colorData");
section.set("r", particleColorData.getRed());
section.set("g", particleColorData.getGreen());
section.set("b", particleColorData.getBlue());
save();
} else {
async(() -> {
try {
PlayerParticles.mySQL.updateSQL("UPDATE pp_data_color SET r = " + particleColorData.getRed() + ", g = " + particleColorData.getGreen() + ", b = " + particleColorData.getBlue() + " WHERE uuid = '" + playerUUID + "';");
} catch (SQLException e) {
e.printStackTrace();
}
});
}
pplayer.setColorData(particleColorData);
});
}
/**
* Saves the note color data to the player's save file or database entry
*
* @param playerUUID The UUID of the player
* @param particleNoteColorData The data that is being saved
*/
public void savePPlayer(UUID playerUUID, NoteColor particleNoteColorData) {
getPPlayer(playerUUID, (pplayer) -> {
if (!PlayerParticles.useMySQL) {
ConfigurationSection section = playerDataYaml.getConfigurationSection(playerUUID.toString() + ".noteColorData");
section.set("note", (byte) (particleNoteColorData.getValueX() * 24));
save();
} else {
async(() -> {
try {
PlayerParticles.mySQL.updateSQL("UPDATE pp_data_note SET note = " + (byte) (particleNoteColorData.getValueX() * 24) + " WHERE uuid = '" + playerUUID + "';");
} catch (SQLException e) {
e.printStackTrace();
}
});
}
pplayer.setNoteColorData(particleNoteColorData);
});
}
/**
* Saves a fixed effect to save data
*
* @param fixedEffect The fixed effect to save
*/
public void saveFixedEffect(FixedParticleEffect fixedEffect) {
if (!PlayerParticles.useMySQL) {
if (!playerDataYaml.isConfigurationSection(fixedEffect.getOwnerUniqueId().toString() + ".fixedEffect." + fixedEffect.getId())) {
ConfigurationSection baseSection = playerDataYaml.createSection(fixedEffect.getOwnerUniqueId().toString() + ".fixedEffect." + fixedEffect.getId());
baseSection.createSection("effect");
baseSection.createSection("style");
baseSection.createSection("itemData");
baseSection.createSection("blockData");
baseSection.createSection("colorData");
baseSection.createSection("noteColorData");
} else {
return;
}
ConfigurationSection section = playerDataYaml.getConfigurationSection(fixedEffect.getOwnerUniqueId().toString() + ".fixedEffect." + fixedEffect.getId());
ConfigurationSection effectSection = section.getConfigurationSection("effect");
ConfigurationSection styleSection = section.getConfigurationSection("style");
ConfigurationSection itemDataSection = section.getConfigurationSection("itemData");
ConfigurationSection blockDataSection = section.getConfigurationSection("blockData");
ConfigurationSection colorDataSection = section.getConfigurationSection("colorData");
ConfigurationSection noteColorDataSection = section.getConfigurationSection("noteColorData");
section.set("id", fixedEffect.getId());
section.set("worldName", fixedEffect.getLocation().getWorld().getName());
section.set("xPos", fixedEffect.getLocation().getX());
section.set("yPos", fixedEffect.getLocation().getY());
section.set("zPos", fixedEffect.getLocation().getZ());
effectSection.set("name", fixedEffect.getParticleEffect().getName());
styleSection.set("name", fixedEffect.getParticleStyle().getName());
itemDataSection.set("material", fixedEffect.getItemData().getMaterial().name());
blockDataSection.set("material", fixedEffect.getBlockData().getMaterial().name());
colorDataSection.set("r", fixedEffect.getColorData().getRed());
colorDataSection.set("g", fixedEffect.getColorData().getGreen());
colorDataSection.set("b", fixedEffect.getColorData().getBlue());
noteColorDataSection.set("note", (byte) (fixedEffect.getNoteColorData().getValueX() * 24));
save();
ParticleManager.addFixedEffect(fixedEffect);
} else {
async(() -> {
PlayerParticles.mySQL.connect((connection) -> {
try (Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery("SELECT * FROM pp_fixed WHERE player_uuid = '" + fixedEffect.getOwnerUniqueId() + "' AND id = " + fixedEffect.getId())) {
if (res.next()) {
return;
}
String fixedEffectUUID = UUID.randomUUID().toString();
PlayerParticles.mySQL.updateSQL("INSERT INTO pp_fixed (uuid, player_uuid, id, effect, style, worldName, xPos, yPos, zPos) VALUES (" +
"'" + fixedEffectUUID + "', " +
"'" + fixedEffect.getOwnerUniqueId().toString() + "', " +
fixedEffect.getId() + ", " +
"'" + fixedEffect.getParticleEffect().getName() + "', " +
"'" + fixedEffect.getParticleStyle().getName() + "', " +
"'" + fixedEffect.getLocation().getWorld().getName() + "', " +
fixedEffect.getLocation().getX() + ", " +
fixedEffect.getLocation().getY() + ", " +
fixedEffect.getLocation().getZ() +
"); " +
"INSERT INTO pp_data_item (uuid, material) VALUES (" +
"'" + fixedEffectUUID + "', " +
"'" + fixedEffect.getItemData().getMaterial().name() + "'" +
"); " +
"INSERT INTO pp_data_block (uuid, material) VALUES (" +
"'" + fixedEffectUUID + "', " +
"'" + fixedEffect.getBlockData().getMaterial().name() + "'" +
"); " +
"INSERT INTO pp_data_color (uuid, r, g, b) VALUES (" +
"'" + fixedEffectUUID + "', " +
fixedEffect.getColorData().getRed() + ", " +
fixedEffect.getColorData().getGreen() + ", " +
fixedEffect.getColorData().getBlue() +
"); " +
"INSERT INTO pp_data_note (uuid, note) VALUES (" +
"'" + fixedEffectUUID + "', " +
(byte) (fixedEffect.getNoteColorData().getValueX() * 24) +
");"
);
sync(() -> ParticleManager.addFixedEffect(fixedEffect));
}
});
});
}
}
/**
* Deletes a fixed effect from save data
*
* @param playerUUID The player who owns the effect
* @param id The id of the effect to remove
* @param callback The callback to execute with if the fixed effect was removed or not
*/
public void removeFixedEffect(UUID playerUUID, int id, ConfigurationCallback<Boolean> callback) {
if (!PlayerParticles.useMySQL) {
if (!playerDataYaml.isConfigurationSection(playerUUID.toString() + ".fixedEffect." + id)) {
callback.execute(false);
return;
}
playerDataYaml.set(playerUUID.toString() + ".fixedEffect." + id, null);
save();
ParticleManager.removeFixedEffectForPlayer(playerUUID, id);
callback.execute(true);
} else {
async(() -> {
PlayerParticles.mySQL.connect((connection) -> {
try (Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery("SELECT uuid FROM pp_fixed WHERE player_uuid = '" + playerUUID.toString() + "' AND id = " + id)) {
if (!res.next()) {
callback.execute(false);
return;
}
String uuid = res.getString("uuid");
PlayerParticles.mySQL.updateSQL("DELETE FROM pp_fixed WHERE uuid = '" + uuid + "';" +
"DELETE FROM pp_data_item WHERE uuid = '" + uuid + "';" +
"DELETE FROM pp_data_block WHERE uuid = '" + uuid + "';" +
"DELETE FROM pp_data_color WHERE uuid = '" + uuid + "';" +
"DELETE FROM pp_data_note WHERE uuid = '" + uuid + "';"
);
sync(() -> {
ParticleManager.removeFixedEffectForPlayer(playerUUID, id);
callback.execute(true);
});
}
});
});
}
}
/**
* Resets all fixed effects for a given player
*
* @param playerUUID The player to remove all effects from
*/
public void resetFixedEffects(UUID playerUUID) {
if (!PlayerParticles.useMySQL) {
playerDataYaml.set(playerUUID.toString() + ".fixedEffect", null);
save();
} else {
async(() -> {
try { // @formatter:off
PlayerParticles.mySQL.updateSQL("DELETE FROM pp_data_item WHERE uuid IN (SELECT uuid FROM pp_fixed WHERE player_uuid = '" + playerUUID.toString() + "');" +
"DELETE FROM pp_data_block WHERE uuid IN (SELECT uuid FROM pp_fixed WHERE player_uuid = '" + playerUUID.toString() + "');" +
"DELETE FROM pp_data_color WHERE uuid IN (SELECT uuid FROM pp_fixed WHERE player_uuid = '" + playerUUID.toString() + "');" +
"DELETE FROM pp_data_note WHERE uuid IN (SELECT uuid FROM pp_fixed WHERE player_uuid = '" + playerUUID.toString() + "');" +
"DELETE FROM pp_fixed WHERE player_uuid = '" + playerUUID.toString() + "';"
); // @formatter:on
} catch (SQLException e) {
e.printStackTrace();
}
});
}
ParticleManager.removeAllFixedEffectsForPlayer(playerUUID);
}
/**
* Gets a list of all saved fixed particle effects
*
* @param callback The callback to execute with a list of all saved fixed particle effects
*/
public void getAllFixedEffects(ConfigurationCallback<List<FixedParticleEffect>> callback) {
if (!PlayerParticles.useMySQL) {
List<FixedParticleEffect> fixedEffects = new ArrayList<FixedParticleEffect>();
Set<String> playerKeys = playerDataYaml.getKeys(false);
for (String playerKey : playerKeys) {
if (playerDataYaml.isConfigurationSection(playerKey + ".fixedEffect")) {
Set<String> fixedEffectKeys = playerDataYaml.getConfigurationSection(playerKey + ".fixedEffect").getKeys(false);
for (String fixedEffectKey : fixedEffectKeys) {
ConfigurationSection section = playerDataYaml.getConfigurationSection(playerKey + ".fixedEffect." + fixedEffectKey);
ConfigurationSection effectSection = section.getConfigurationSection("effect");
ConfigurationSection styleSection = section.getConfigurationSection("style");
ConfigurationSection itemDataSection = section.getConfigurationSection("itemData");
ConfigurationSection blockDataSection = section.getConfigurationSection("blockData");
ConfigurationSection colorDataSection = section.getConfigurationSection("colorData");
ConfigurationSection noteColorDataSection = section.getConfigurationSection("noteColorData");
int id = section.getInt("id");
String worldName = section.getString("worldName");
double xPos = section.getDouble("xPos");
double yPos = section.getDouble("yPos");
double zPos = section.getDouble("zPos");
ParticleEffect particleEffect = ParticleEffect.fromName(effectSection.getString("name"));
ParticleStyle particleStyle = ParticleStyleManager.styleFromString(styleSection.getString("name"));
ItemData particleItemData = new ItemData(Material.matchMaterial(itemDataSection.getString("material")));
BlockData particleBlockData = new BlockData(Material.matchMaterial(blockDataSection.getString("material")));
OrdinaryColor particleColorData = new OrdinaryColor(colorDataSection.getInt("r"), colorDataSection.getInt("g"), colorDataSection.getInt("b"));
NoteColor particleNoteColorData = new NoteColor(noteColorDataSection.getInt("note"));
fixedEffects.add(new FixedParticleEffect(UUID.fromString(playerKey), id, worldName, xPos, yPos, zPos, particleEffect, particleStyle, particleItemData, particleBlockData, particleColorData, particleNoteColorData));
}
}
}
callback.execute(fixedEffects);
} else { // @formatter:off
async(() -> {
PlayerParticles.mySQL.connect((connection) -> {
String query = "SELECT * FROM pp_fixed f " +
"JOIN pp_data_item i ON f.uuid = i.uuid " +
"JOIN pp_data_block b ON f.uuid = b.uuid " +
"JOIN pp_data_color c ON f.uuid = c.uuid " +
"JOIN pp_data_note n ON f.uuid = n.uuid";
try (Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery(query)) {
List<FixedParticleEffect> fixedEffects = new ArrayList<FixedParticleEffect>();
while (res.next()) {
UUID pplayerUUID = UUID.fromString(res.getString("f.player_uuid"));
int id = res.getInt("f.id");
String worldName = res.getString("f.worldName");
double xPos = res.getDouble("f.xPos");
double yPos = res.getDouble("f.yPos");
double zPos = res.getDouble("f.zPos");
ParticleEffect particleEffect = ParticleManager.effectFromString(res.getString("f.effect"));
ParticleStyle particleStyle = ParticleStyleManager.styleFromString(res.getString("f.style"));
ItemData particleItemData = new ItemData(Material.matchMaterial(res.getString("i.material")));
BlockData particleBlockData = new BlockData(Material.matchMaterial(res.getString("b.material")));
OrdinaryColor particleColorData = new OrdinaryColor(res.getInt("c.r"), res.getInt("c.g"), res.getInt("c.b"));
NoteColor particleNoteColorData = new NoteColor(res.getByte("n.note"));
fixedEffects.add(new FixedParticleEffect(pplayerUUID, id, worldName, xPos, yPos, zPos, particleEffect, particleStyle, particleItemData, particleBlockData, particleColorData, particleNoteColorData));
}
sync(() -> callback.execute(fixedEffects));
}
});
});
}
}
/**
* Gets a fixed effect for a pplayer by its id
*
* @param pplayerUUID The player who owns the effect
* @param id The id for the effect to get
* @param callback The callback to execute with the effect, if one exists
*/
public void getFixedEffectForPlayerById(UUID pplayerUUID, int id, ConfigurationCallback<FixedParticleEffect> callback) {
if (!PlayerParticles.useMySQL) {
if (playerDataYaml.isConfigurationSection(pplayerUUID.toString() + ".fixedEffect." + id)) {
ConfigurationSection section = playerDataYaml.getConfigurationSection(pplayerUUID + ".fixedEffect." + id);
ConfigurationSection effectSection = section.getConfigurationSection("effect");
ConfigurationSection styleSection = section.getConfigurationSection("style");
ConfigurationSection itemDataSection = section.getConfigurationSection("itemData");
ConfigurationSection blockDataSection = section.getConfigurationSection("blockData");
ConfigurationSection colorDataSection = section.getConfigurationSection("colorData");
ConfigurationSection noteColorDataSection = section.getConfigurationSection("noteColorData");
String worldName = section.getString("worldName");
double xPos = section.getDouble("xPos");
double yPos = section.getDouble("yPos");
double zPos = section.getDouble("zPos");
ParticleEffect particleEffect = ParticleEffect.fromName(effectSection.getString("name"));
ParticleStyle particleStyle = ParticleStyleManager.styleFromString(styleSection.getString("name"));
ItemData particleItemData = new ItemData(Material.matchMaterial(itemDataSection.getString("material")));
BlockData particleBlockData = new BlockData(Material.matchMaterial(blockDataSection.getString("material")));
OrdinaryColor particleColorData = new OrdinaryColor(colorDataSection.getInt("r"), colorDataSection.getInt("g"), colorDataSection.getInt("b"));
NoteColor particleNoteColorData = new NoteColor(noteColorDataSection.getInt("note"));
callback.execute(new FixedParticleEffect(pplayerUUID, id, worldName, xPos, yPos, zPos, particleEffect, particleStyle, particleItemData, particleBlockData, particleColorData, particleNoteColorData));
}
} else {
async(() -> {
PlayerParticles.mySQL.connect((connection) -> { // @formatter:off
String query = "SELECT * FROM pp_fixed f " +
"JOIN pp_data_item i ON f.uuid = i.uuid " +
"JOIN pp_data_block b ON f.uuid = b.uuid " +
"JOIN pp_data_color c ON f.uuid = c.uuid " +
"JOIN pp_data_note n ON f.uuid = n.uuid " +
"WHERE f.player_uuid = '" + pplayerUUID.toString() + "' AND f.id = '" + id + "'"; // @formatter:on
try (Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery(query)) {
if (res.next()) {
String worldName = res.getString("f.worldName");
double xPos = res.getDouble("f.xPos");
double yPos = res.getDouble("f.yPos");
double zPos = res.getDouble("f.zPos");
ParticleEffect particleEffect = ParticleManager.effectFromString(res.getString("f.effect"));
ParticleStyle particleStyle = ParticleStyleManager.styleFromString(res.getString("f.style"));
ItemData particleItemData = new ItemData(Material.matchMaterial(res.getString("i.material")));
BlockData particleBlockData = new BlockData(Material.matchMaterial(res.getString("b.material")));
OrdinaryColor particleColorData = new OrdinaryColor(res.getInt("c.r"), res.getInt("c.g"), res.getInt("c.b"));
NoteColor particleNoteColorData = new NoteColor(res.getByte("n.note"));
sync(() -> callback.execute(new FixedParticleEffect(pplayerUUID, id, worldName, xPos, yPos, zPos, particleEffect, particleStyle, particleItemData, particleBlockData, particleColorData, particleNoteColorData)));
}
}
});
});
}
}
/**
* Gets a list of all fixed effect ids for a player
*
* @param pplayerUUID The player
* @param callback The callback to execute with a list of all fixed effect ids for the given player
*/
public void getFixedEffectIdsForPlayer(UUID pplayerUUID, ConfigurationCallback<List<Integer>> callback) {
if (!PlayerParticles.useMySQL) {
List<Integer> ids = new ArrayList<Integer>();
if (playerDataYaml.isConfigurationSection(pplayerUUID.toString() + ".fixedEffect")) {
Set<String> keys = playerDataYaml.getConfigurationSection(pplayerUUID.toString() + ".fixedEffect").getKeys(false);
for (String key : keys) {
ids.add(Integer.parseInt(key));
}
}
callback.execute(ids);
} else {
async(() -> {
PlayerParticles.mySQL.connect((connection) -> {
try (Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery("SELECT id FROM pp_fixed WHERE player_uuid = '" + pplayerUUID.toString() + "'")) {
List<Integer> ids = new ArrayList<Integer>();
while (res.next()) {
ids.add(res.getInt(1));
}
sync(() -> callback.execute(ids));
}
});
});
}
}
/**
* Checks if the given player has reached the max number of fixed effects
*
* @param pplayerUUID The player to check
* @param callback The callback to execute with if the player can create any more fixed effects
*/
public void hasPlayerReachedMaxFixedEffects(UUID pplayerUUID, ConfigurationCallback<Boolean> callback) {
if (maxFixedEffects == -1) { // Initialize on the fly
maxFixedEffects = PlayerParticles.getPlugin().getConfig().getInt("max-fixed-effects");
}
if (Bukkit.getPlayer(pplayerUUID).hasPermission("playerparticles.fixed.unlimited")) {
callback.execute(false);
return;
}
if (!PlayerParticles.useMySQL) {
if (playerDataYaml.isConfigurationSection(pplayerUUID.toString() + ".fixedEffect")) {
callback.execute(playerDataYaml.getConfigurationSection(pplayerUUID.toString() + ".fixedEffect").getKeys(false).size() >= maxFixedEffects);
} else callback.execute(false);
} else {
async(() -> {
PlayerParticles.mySQL.connect((connection) -> {
try (Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery("SELECT COUNT(1) FROM pp_fixed WHERE player_uuid = '" + pplayerUUID.toString() + "'")) {
boolean hasReachedMax;
if (res.next())
hasReachedMax = res.getInt(1) >= maxFixedEffects;
else
hasReachedMax = false;
sync(() -> callback.execute(hasReachedMax));
}
});
});
}
}
/**
* Gets the next Id for a player's fixed effects
*
* @param pplayerUUID The player to get the Id for
* @param callback The callback to execute with the smallest available Id the player can use
*/
public void getNextFixedEffectId(UUID pplayerUUID, ConfigurationCallback<Integer> callback) {
if (!PlayerParticles.useMySQL) {
if (!playerDataYaml.isConfigurationSection(pplayerUUID.toString() + ".fixedEffect")) {
callback.execute(1);
return;
}
Set<String> idsSet = playerDataYaml.getConfigurationSection(pplayerUUID.toString() + ".fixedEffect").getKeys(false);
if (idsSet.isEmpty()) callback.execute(1);
int[] ids = new int[idsSet.size()];
int i = 0;
for (String key : idsSet)
ids[i++] = Integer.parseInt(key);
callback.execute(ParticleUtils.getSmallestPositiveInt(ids));
} else {
async(() -> {
PlayerParticles.mySQL.connect((connection) -> {
try (Statement statement = connection.createStatement();
ResultSet res = statement.executeQuery("SELECT id FROM pp_fixed WHERE player_uuid = '" + pplayerUUID.toString() + "'")) {
Set<String> idsSet = new HashSet<String>();
while (res.next())
idsSet.add(res.getInt(1) + "");
if (idsSet.isEmpty()) {
sync(() -> callback.execute(1));
return;
}
int[] ids = new int[idsSet.size()];
int i = 0;
for (String key : idsSet)
ids[i++] = Integer.parseInt(key);
sync(() -> callback.execute(ParticleUtils.getSmallestPositiveInt(ids)));
}
});
});
}
}
/**
* Gets the max distance a fixed effect can be created from the player
*
* @return The max distance a fixed effect can be created from the player
*/
public int getMaxFixedEffectCreationDistance() {
if (maxFixedEffectCreationDistance == -1) { // Initialize on the fly
maxFixedEffectCreationDistance = PlayerParticles.getPlugin().getConfig().getInt("max-fixed-effect-creation-distance");
}
return maxFixedEffectCreationDistance;
}
/**
* Checks if a world is disabled for particles to spawn in
*
* @param world The world name to check
* @return True if the world is disabled
*/
public boolean isWorldDisabled(String world) {
return getDisabledWorlds().contains(world);
}
/**
* Gets all the worlds that are disabled
*
* @return All world names that are disabled
*/
public List<String> getDisabledWorlds() {
if (disabledWorlds == null) { // Initialize on the fly
disabledWorlds = PlayerParticles.getPlugin().getConfig().getStringList("disabled-worlds");
}
return disabledWorlds;
}
/**
* Asynchronizes the callback with it's own thread
*
* @param asyncCallback The callback to run on a separate thread
*/
private void async(SyncInterface asyncCallback) {
new BukkitRunnable() {
public void run() {
asyncCallback.execute();
}
}.runTaskAsynchronously(PlayerParticles.getPlugin());
}
/**
* Synchronizes the callback with the main thread
*
* @param syncCallback The callback to run on the main thread
*/
private void sync(SyncInterface syncCallback) {
new BukkitRunnable() {
public void run() {
syncCallback.execute();
}
}.runTask(PlayerParticles.getPlugin());
}
/**
* Provides an easy way to run a section of code either synchronously or asynchronously using a callback
*/
private static interface SyncInterface {
public void execute();
}
/**
* Allows callbacks to be passed between configuration methods and executed for returning objects after database queries
*/
public static interface ConfigurationCallback<T> {
public void execute(T obj);
}
}

View file

@ -10,6 +10,7 @@ package com.esophose.playerparticles.manager;
import java.awt.Color; import java.awt.Color;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -23,12 +24,13 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.esophose.playerparticles.PPlayer;
import com.esophose.playerparticles.particles.FixedParticleEffect; import com.esophose.playerparticles.particles.FixedParticleEffect;
import com.esophose.playerparticles.particles.PPlayer;
import com.esophose.playerparticles.particles.ParticleEffect; import com.esophose.playerparticles.particles.ParticleEffect;
import com.esophose.playerparticles.particles.ParticleEffect.NoteColor; import com.esophose.playerparticles.particles.ParticleEffect.NoteColor;
import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor; import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty; import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty;
import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyleManager; import com.esophose.playerparticles.styles.api.ParticleStyleManager;
@ -58,7 +60,7 @@ public class ParticleManager extends BukkitRunnable implements Listener {
*/ */
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent e) { public void onPlayerJoin(PlayerJoinEvent e) {
PPlayerDataManager.getInstance().loadPPlayer(e.getPlayer().getUniqueId()); DataManager.loadPPlayer(e.getPlayer().getUniqueId());
} }
/** /**
@ -68,7 +70,7 @@ public class ParticleManager extends BukkitRunnable implements Listener {
*/ */
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent e) { public void onPlayerQuit(PlayerQuitEvent e) {
PPlayer pplayer = PPlayerDataManager.getInstance().getPPlayer(e.getPlayer().getUniqueId()); PPlayer pplayer = DataManager.getPPlayer(e.getPlayer().getUniqueId());
if (pplayer != null) if (pplayer != null)
particlePlayers.remove(pplayer); particlePlayers.remove(pplayer);
} }
@ -77,7 +79,7 @@ public class ParticleManager extends BukkitRunnable implements Listener {
* Adds all fixed effects from the config * Adds all fixed effects from the config
*/ */
public static void addAllFixedEffects() { public static void addAllFixedEffects() {
PPlayerDataManager.getInstance().getAllFixedEffects((fixedEffects) -> { DataManager.getAllFixedEffects((fixedEffects) -> {
fixedParticleEffects.addAll(fixedEffects); fixedParticleEffects.addAll(fixedEffects);
}); });
} }
@ -121,7 +123,7 @@ public class ParticleManager extends BukkitRunnable implements Listener {
public static void refreshPPlayers() { public static void refreshPPlayers() {
particlePlayers.clear(); particlePlayers.clear();
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
PPlayerDataManager.getInstance().loadPPlayer(player.getUniqueId()); DataManager.loadPPlayer(player.getUniqueId());
} }
/** /**
@ -185,7 +187,7 @@ public class ParticleManager extends BukkitRunnable implements Listener {
valid = false; valid = false;
} }
if (PPlayerDataManager.getInstance().isWorldDisabled(player.getWorld().getName())) { if (DataManager.isWorldDisabled(player.getWorld().getName())) {
valid = false; valid = false;
} }
@ -193,7 +195,9 @@ public class ParticleManager extends BukkitRunnable implements Listener {
Location loc = player.getLocation(); Location loc = player.getLocation();
loc.setY(loc.getY() + 1); loc.setY(loc.getY() + 1);
displayParticles(pplayer, loc);
for (ParticlePair particles : pplayer.getParticles())
displayParticles(particles, loc);
} }
// Loop for FixedParticleEffects // Loop for FixedParticleEffects
@ -214,20 +218,20 @@ public class ParticleManager extends BukkitRunnable implements Listener {
/** /**
* Displays particles at the given player location with their settings * Displays particles at the given player location with their settings
* *
* @param pplayer The PPlayer to use for getting particle settings * @param particle The ParticlePair to use for getting particle settings
* @param location The location to display at * @param location The location to display at
*/ */
private void displayParticles(PPlayer pplayer, Location location) { private void displayParticles(ParticlePair particle, Location location) {
if (!ParticleStyleManager.isCustomHandled(pplayer.getParticleStyle())) { if (!ParticleStyleManager.isCustomHandled(particle.getStyle())) {
ParticleEffect effect = pplayer.getParticleEffect(); ParticleEffect effect = particle.getEffect();
if (effect == ParticleEffect.NONE) return; if (effect == ParticleEffect.NONE) return;
for (PParticle particle : pplayer.getParticleStyle().getParticles(pplayer, location)) { for (PParticle pparticle : particle.getStyle().getParticles(particle, location)) {
if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) { if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
effect.display(pplayer.getParticleSpawnData(), particle.getXOff(), particle.getYOff(), particle.getZOff(), particle.getSpeed(), 1, particle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE))); effect.display(particle.getSpawnMaterial(), pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), 1, pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)));
} else if (effect.hasProperty(ParticleProperty.COLORABLE)) { } else if (effect.hasProperty(ParticleProperty.COLORABLE)) {
effect.display(pplayer.getParticleSpawnColor(), particle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE))); effect.display(particle.getSpawnColor(), pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)));
} else { } else {
effect.display(particle.getXOff(), particle.getYOff(), particle.getZOff(), particle.getSpeed(), 1, particle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE))); effect.display(pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), 1, pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)));
} }
} }
} }
@ -236,19 +240,19 @@ public class ParticleManager extends BukkitRunnable implements Listener {
/** /**
* An alternative method used for custom handled styles * An alternative method used for custom handled styles
* *
* @param pplayer The PPlayer to use for getting particle settings * @param particle The ParticlePair to use for getting particle settings
* @param particles The particles to display * @param particles The particles to display
*/ */
public static void displayParticles(PPlayer pplayer, PParticle[] particles) { public static void displayParticles(ParticlePair particle, List<PParticle> particles) {
ParticleEffect effect = pplayer.getParticleEffect(); ParticleEffect effect = particle.getEffect();
if (effect == ParticleEffect.NONE) return; if (effect == ParticleEffect.NONE) return;
for (PParticle particle : particles) { for (PParticle pparticle : particles) {
if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) { if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
effect.display(pplayer.getParticleSpawnData(), particle.getXOff(), particle.getYOff(), particle.getZOff(), particle.getSpeed(), 1, particle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE))); effect.display(particle.getSpawnMaterial(), pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), 1, pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)));
} else if (effect.hasProperty(ParticleProperty.COLORABLE)) { } else if (effect.hasProperty(ParticleProperty.COLORABLE)) {
effect.display(pplayer.getParticleSpawnColor(), particle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE))); effect.display(particle.getSpawnColor(), pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)));
} else { } else {
effect.display(particle.getXOff(), particle.getYOff(), particle.getZOff(), particle.getSpeed(), 1, particle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE))); effect.display(pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), 1, pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)));
} }
} }
} }
@ -259,15 +263,15 @@ public class ParticleManager extends BukkitRunnable implements Listener {
* @param fixedEffect The fixed effect to display * @param fixedEffect The fixed effect to display
*/ */
private void displayFixedParticleEffect(FixedParticleEffect fixedEffect) { private void displayFixedParticleEffect(FixedParticleEffect fixedEffect) {
PPlayer fakePPlayer = new PPlayer(fixedEffect.getOwnerUniqueId(), fixedEffect.getParticleEffect(), fixedEffect.getParticleStyle(), null, null, null, null); ParticlePair particle = fixedEffect.getParticlePair();
ParticleEffect effect = fixedEffect.getParticleEffect(); ParticleEffect effect = particle.getEffect();
for (PParticle particle : fixedEffect.getParticleStyle().getParticles(fakePPlayer, fixedEffect.getLocation())) { for (PParticle pparticle : particle.getStyle().getParticles(particle, fixedEffect.getLocation())) {
if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) { if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
effect.display(fixedEffect.getParticleSpawnData(), particle.getXOff(), particle.getYOff(), particle.getZOff(), particle.getSpeed(), 1, particle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE))); effect.display(particle.getSpawnMaterial(), pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), 1, pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)));
} else if (effect.hasProperty(ParticleProperty.COLORABLE)) { } else if (effect.hasProperty(ParticleProperty.COLORABLE)) {
effect.display(fixedEffect.getParticleSpawnColor(), particle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE))); effect.display(particle.getSpawnColor(), pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)));
} else { } else {
effect.display(particle.getXOff(), particle.getYOff(), particle.getZOff(), particle.getSpeed(), 1, particle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE))); effect.display(pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), 1, pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)));
} }
} }
} }

View file

@ -58,9 +58,9 @@ public class PermissionManager {
*/ */
public static List<String> getEffectsUserHasPermissionFor(Player p) { public static List<String> getEffectsUserHasPermissionFor(Player p) {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
for (ParticleEffect pe : ParticleEffect.getSupportedEffects()) { for (ParticleEffect pe : ParticleEffect.getSupportedEffects())
if (hasEffectPermission(p, pe)) list.add(pe.getName()); if (hasEffectPermission(p, pe))
} list.add(pe.getName());
return list; return list;
} }
@ -72,9 +72,9 @@ public class PermissionManager {
*/ */
public static List<String> getStylesUserHasPermissionFor(Player p) { public static List<String> getStylesUserHasPermissionFor(Player p) {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
for (ParticleStyle ps : ParticleStyleManager.getStyles()) { for (ParticleStyle ps : ParticleStyleManager.getStyles())
if (hasStylePermission(p, ps)) list.add(ps.getName()); if (hasStylePermission(p, ps))
} list.add(ps.getName());
return list; return list;
} }

View file

@ -14,18 +14,6 @@ import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import com.esophose.playerparticles.PPlayer;
import com.esophose.playerparticles.manager.PPlayerDataManager;
import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.particles.ParticleEffect.BlockData;
import com.esophose.playerparticles.particles.ParticleEffect.ItemData;
import com.esophose.playerparticles.particles.ParticleEffect.NoteColor;
import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
import com.esophose.playerparticles.particles.ParticleEffect.ParticleColor;
import com.esophose.playerparticles.particles.ParticleEffect.ParticleData;
import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty;
import com.esophose.playerparticles.styles.api.ParticleStyle;
public class FixedParticleEffect { public class FixedParticleEffect {
/** /**
@ -46,16 +34,7 @@ public class FixedParticleEffect {
/** /**
* The effect and style this effect uses * The effect and style this effect uses
*/ */
private ParticleEffect particleEffect; private ParticlePair particlePair;
private ParticleStyle particleStyle;
/**
* The data this effect uses
*/
private ItemData particleItemData;
private BlockData particleBlockData;
private OrdinaryColor particleColorData;
private NoteColor particleNoteColorData;
/** /**
* Constructs a new FixedParticleEffect * Constructs a new FixedParticleEffect
@ -67,34 +46,12 @@ public class FixedParticleEffect {
* @param xPos The X position in the world * @param xPos The X position in the world
* @param yPos The Y position in the world * @param yPos The Y position in the world
* @param zPos The Z position in the world * @param zPos The Z position in the world
* @param particleEffect The particle effect to use * @param particlePair The ParticlePair that represents this FixedParticleEffect's appearance
* @param particleStyle The particle style to use
* @param itemData The item data for the effect
* @param blockData The block data for the effect
* @param colorData The color data for the effect
* @param noteColorData The note color data for the effect
*/ */
public FixedParticleEffect(UUID pplayerUUID, int id, String worldName, double xPos, double yPos, double zPos, ParticleEffect particleEffect, ParticleStyle particleStyle, ItemData itemData, BlockData blockData, OrdinaryColor colorData, NoteColor noteColorData) { public FixedParticleEffect(UUID pplayerUUID, int id, String worldName, double xPos, double yPos, double zPos, ParticlePair particlePair) {
this.pplayerUUID = pplayerUUID; this.pplayerUUID = pplayerUUID;
this.id = id; this.id = id;
this.particlePair = particlePair;
this.particleEffect = particleEffect;
this.particleStyle = particleStyle;
this.particleItemData = itemData;
this.particleBlockData = blockData;
this.particleColorData = colorData;
this.particleNoteColorData = noteColorData;
// The PPlayer must be loaded
PPlayerDataManager.getInstance().loadPPlayer(pplayerUUID);
PPlayer owner = PPlayerDataManager.getInstance().getPPlayer(this.pplayerUUID);
// Check nulls, if any are null set them to the PPlayer's values
if (this.particleItemData == null) this.particleItemData = owner.getItemData();
if (this.particleBlockData == null) this.particleBlockData = owner.getBlockData();
if (this.particleColorData == null) this.particleColorData = owner.getColorData();
if (this.particleNoteColorData == null) this.particleNoteColorData = owner.getNoteColorData();
World world = Bukkit.getWorld(worldName); World world = Bukkit.getWorld(worldName);
if (world == null) { // Default to the first world in case it doesn't exist if (world == null) { // Default to the first world in case it doesn't exist
@ -123,127 +80,12 @@ public class FixedParticleEffect {
} }
/** /**
* Gets the particle effect used for this effect * Gets the ParticlePair, which contains all spawn information about this fixed effect
* *
* @return The particle effect used for this effect * @return The ParticlePair that represents this FixedParticleEffect's appearance
*/ */
public ParticleEffect getParticleEffect() { public ParticlePair getParticlePair() {
return this.particleEffect; return this.particlePair;
}
/**
* Gets the particle style used for this effect
*
* @return The particle style used for this effect
*/
public ParticleStyle getParticleStyle() {
return this.particleStyle;
}
/**
* Gets the effect's item data
*
* @return The effect's item data
*/
public ItemData getItemData() {
return this.particleItemData;
}
/**
* Gets the effect's block data
*
* @return The effect's block data
*/
public BlockData getBlockData() {
return this.particleBlockData;
}
/**
* Gets the effect's color data
*
* @return The effect's color data
*/
public OrdinaryColor getColorData() {
return this.particleColorData;
}
/**
* Gets the effect's note color data
*
* @return The effect's note color data
*/
public NoteColor getNoteColorData() {
return this.particleNoteColorData;
}
/**
* Gets the data the current particle effect will spawn with
*
* @return The ParticleData the current particle effect requires
*/
public ParticleData getParticleSpawnData() {
if (this.particleEffect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
if (this.particleEffect == ParticleEffect.BLOCK || this.particleEffect == ParticleEffect.FALLING_DUST) {
return particleBlockData;
} else if (this.particleEffect == ParticleEffect.ITEM) {
return this.particleItemData;
}
}
return null;
}
/**
* Gets the color the current particle effect will spawn with
*
* @return Gets the ParticleColor the current particle effect will spawn with
*/
public ParticleColor getParticleSpawnColor() {
if (this.particleEffect.hasProperty(ParticleProperty.COLORABLE)) {
if (this.particleEffect == ParticleEffect.NOTE) {
if (this.particleNoteColorData.getValueX() * 24 == 99) {
return ParticleManager.getRainbowNoteParticleColor();
}
return this.particleNoteColorData;
} else {
if (this.particleColorData.getRed() == 999 && this.particleColorData.getGreen() == 999 && this.particleColorData.getBlue() == 999) {
return ParticleManager.getRainbowParticleColor();
} else {
return this.particleColorData;
}
}
}
return null;
}
/**
* Gets the particle data as a string
*
* @return A string of the current effect's data
*/
public String getParticleDataString() {
if (this.particleEffect.hasProperty(ParticleProperty.COLORABLE)) {
if (this.particleEffect == ParticleEffect.NOTE) {
if (this.particleNoteColorData.getValueX() * 24 == 99) {
return "rainbow";
} else {
return (this.particleNoteColorData.getValueX() * 24) + "";
}
} else {
if (this.particleColorData.getRed() == 999 && this.particleColorData.getGreen() == 999 && this.particleColorData.getBlue() == 999) {
return "rainbow";
} else {
return this.particleColorData.getRed() + " " + this.particleColorData.getGreen() + " " + this.particleColorData.getBlue();
}
}
} else if (this.particleEffect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
if (this.particleEffect == ParticleEffect.BLOCK || this.particleEffect == ParticleEffect.FALLING_DUST) {
return this.particleBlockData.getMaterial().toString().toLowerCase();
} else if (this.particleEffect == ParticleEffect.ITEM) {
return this.particleItemData.getMaterial().toString().toLowerCase();
}
}
return "None";
} }
/** /**

View file

@ -0,0 +1,108 @@
/**
* Copyright Esophose 2018
* While using any of the code provided by this plugin
* you must not claim it as your own. This plugin may
* be modified and installed on a server, but may not
* be distributed to any person by any means.
*/
package com.esophose.playerparticles.particles;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import com.esophose.playerparticles.styles.api.ParticleStyle;
public class PPlayer {
/**
* The UUID of the player
*/
private final UUID playerUUID;
/**
* A List<ParticlePair> of all particles the user has applied
*/
private List<ParticlePair> particles;
/**
* Constructs a new PPlayer
*
* @param uuid The player UUID
* @param particlePairs The ParticlePairs this PPlayer has
*/
public PPlayer(UUID uuid, List<ParticlePair> particlePairs) {
this.playerUUID = uuid;
this.particles = particlePairs;
}
/**
* Gets the player's UUID
*
* @return The player's UUID
*/
public UUID getUniqueId() {
return this.playerUUID;
}
/**
* Gets the Player from their UUID
*
* @return The player if they are online, null if they are offline
*/
public Player getPlayer() {
return Bukkit.getPlayer(this.playerUUID);
}
/**
* Get the effect/style/data for particles this player has set
*
* @return
*/
public List<ParticlePair> getParticles() {
return this.particles;
}
/**
* Get all ParticlePairs with a style matching the input
*
* @param style The style to match
* @return A List<ParticlePair> with a matching style
*/
public List<ParticlePair> getParticlesForStyle(ParticleStyle style) {
List<ParticlePair> matches = new ArrayList<ParticlePair>();
for (ParticlePair pair : this.particles)
if (pair.getStyle().equals(style))
matches.add(pair);
return matches;
}
/**
* Get a ParticlePair by its id
*
* @param id The id of the ParticlePair
* @return A ParticlePair with the given id, otherwise null
*/
public ParticlePair getParticle(int id) {
for (ParticlePair particle : this.particles)
if (particle.getId() == id)
return particle;
return null;
}
/**
* Gets a default PPlayer
* Used for when a new PPlayer is being created
*
* @param playerUUID The player's UUID
* @return A default PPlayer
*/
public static PPlayer getNewPPlayer(UUID playerUUID) {
return new PPlayer(playerUUID, new ArrayList<ParticlePair>());
}
}

View file

@ -26,14 +26,11 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
/** @SuppressWarnings("deprecation")
* Heavily modified to work with the Spigot Particle API
*
* @author Esophose
*/
public enum ParticleEffect { public enum ParticleEffect {
// Ordered and named by their Minecraft 1.13 internal names // Ordered and named by their Minecraft 1.13 internal names
NONE("", ""), // Custom effect to represent none selected, always display first
AMBIENT_ENTITY_EFFECT("SPELL_MOB_AMBIENT", "SPELL_MOB_AMBIENT", ParticleProperty.COLORABLE), AMBIENT_ENTITY_EFFECT("SPELL_MOB_AMBIENT", "SPELL_MOB_AMBIENT", ParticleProperty.COLORABLE),
ANGRY_VILLAGER("VILLAGER_ANGRY", "VILLAGER_ANGRY"), ANGRY_VILLAGER("VILLAGER_ANGRY", "VILLAGER_ANGRY"),
BARRIER("BARRIER", "BARRIER"), BARRIER("BARRIER", "BARRIER"),
@ -72,7 +69,6 @@ public enum ParticleEffect {
LAVA("LAVA", "LAVA"), LAVA("LAVA", "LAVA"),
MYCELIUM("TOWN_AURA", "TOWN_AURA"), MYCELIUM("TOWN_AURA", "TOWN_AURA"),
NAUTILUS("NAUTILUS", null), NAUTILUS("NAUTILUS", null),
NONE("", ""), // Custom effect to represent none selected
NOTE("NOTE", "NOTE", ParticleProperty.COLORABLE), NOTE("NOTE", "NOTE", ParticleProperty.COLORABLE),
POOF("EXPLOSION_NORMAL", "EXPLOSION_NORMAL"), // The 1.13 combination of explode and showshovel POOF("EXPLOSION_NORMAL", "EXPLOSION_NORMAL"), // The 1.13 combination of explode and showshovel
PORTAL("PORTAL", "PORTAL"), PORTAL("PORTAL", "PORTAL"),
@ -200,28 +196,6 @@ public enum ParticleEffect {
return null; return null;
} }
/**
* Determine if the data type for a particle effect is correct
*
* @param effect Particle effect
* @param data Particle data
* @return Whether the data type is correct or not
*/
private static boolean isDataCorrect(ParticleEffect effect, ParticleData data) {
return ((effect == BLOCK || effect == FALLING_DUST) && data instanceof BlockData) || (effect == ITEM && data instanceof ItemData);
}
/**
* Determine if the color type for a particle effect is correct
*
* @param effect Particle effect
* @param color Particle color
* @return Whether the color type is correct or not
*/
private static boolean isColorCorrect(ParticleEffect effect, ParticleColor color) {
return ((effect == ENTITY_EFFECT || effect == AMBIENT_ENTITY_EFFECT || effect == DUST) && color instanceof OrdinaryColor) || (effect == NOTE && color instanceof NoteColor);
}
/** /**
* Displays a particle effect * Displays a particle effect
* *
@ -253,9 +227,6 @@ public enum ParticleEffect {
if (!hasProperty(ParticleProperty.COLORABLE)) { if (!hasProperty(ParticleProperty.COLORABLE)) {
throw new ParticleColorException("This particle effect is not colorable"); throw new ParticleColorException("This particle effect is not colorable");
} }
if (!isColorCorrect(this, color)) {
throw new ParticleColorException("The particle color type is incorrect");
}
if (this == DUST && VERSION_13) { // DUST uses a special data object for spawning in 1.13 if (this == DUST && VERSION_13) { // DUST uses a special data object for spawning in 1.13
OrdinaryColor dustColor = (OrdinaryColor)color; OrdinaryColor dustColor = (OrdinaryColor)color;
@ -280,7 +251,7 @@ public enum ParticleEffect {
* visible for all players within a certain range in the world of @param * visible for all players within a certain range in the world of @param
* center * center
* *
* @param data Data of the effect * @param spawnMaterial Material of the effect
* @param offsetX Maximum distance particles can fly away from the center on the x-axis * @param offsetX Maximum distance particles can fly away from the center on the x-axis
* @param offsetY Maximum distance particles can fly away from the center on the y-axis * @param offsetY Maximum distance particles can fly away from the center on the y-axis
* @param offsetZ Maximum distance particles can fly away from the center on the z-axis * @param offsetZ Maximum distance particles can fly away from the center on the z-axis
@ -289,22 +260,20 @@ public enum ParticleEffect {
* @param center Center location of the effect * @param center Center location of the effect
* @throws ParticleDataException If the particle effect does not require additional data or if the data type is incorrect * @throws ParticleDataException If the particle effect does not require additional data or if the data type is incorrect
*/ */
public void display(ParticleData data, float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center) throws ParticleDataException { public void display(Material spawnMaterial, float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center) throws ParticleDataException {
if (!hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) { if (!hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
throw new ParticleDataException("This particle effect does not require additional data"); throw new ParticleDataException("This particle effect does not require additional data");
} }
if (!isDataCorrect(this, data)) {
throw new ParticleDataException("The particle data type is incorrect");
}
Object extraData = null; Object extraData = null;
if (internalEnum.getDataType().getTypeName().equals("org.bukkit.block.data.BlockData")) { if (internalEnum.getDataType().getTypeName().equals("org.bukkit.block.data.BlockData")) {
try { // The Material.createBlockData() method doesn't exist in Minecraft versions less than 1.13... so this is disgusting... but it works great try { // The Material.createBlockData() method doesn't exist in Minecraft versions less than 1.13... so this is disgusting... but it works great
extraData = createBlockData_METHOD.invoke(data.getMaterial()); extraData = createBlockData_METHOD.invoke(spawnMaterial);
} catch (Exception e) { } } catch (Exception e) { }
} else if (internalEnum.getDataType() == ItemStack.class) { } else if (internalEnum.getDataType() == ItemStack.class) {
extraData = new ItemStack(data.getMaterial()); extraData = new ItemStack(spawnMaterial);
} else if (internalEnum.getDataType() == MaterialData.class) { } else if (internalEnum.getDataType() == MaterialData.class) {
extraData = new MaterialData(data.getMaterial()); // Deprecated, only used in versions < 1.13 extraData = new MaterialData(spawnMaterial); // Deprecated, only used in versions < 1.13
} else { } else {
System.out.println(internalEnum.getDataType()); System.out.println(internalEnum.getDataType());
extraData = null; extraData = null;
@ -350,83 +319,6 @@ public enum ParticleEffect {
COLORABLE; COLORABLE;
} }
/**
* Represents the particle data for effects like
* {@link ParticleEffect#ITEM}, {@link ParticleEffect#BLOCK}, and {@link ParticleEffect#FALLING_DUST}
* <p>
* This class is part of the <b>ParticleEffect Library</b> and follows the
* same usage conditions
*
* @author DarkBlade12
* @since 1.6
*/
public static abstract class ParticleData {
private final Material material;
/**
* Construct a new particle data
*
* @param material Material of the item/block
*/
public ParticleData(Material material) {
this.material = material;
}
/**
* Returns the material of this data
*
* @return The material
*/
public Material getMaterial() {
return material;
}
}
/**
* Represents the item data for the {@link ParticleEffect#ITEM} effect
* <p>
* This class is part of the <b>ParticleEffect Library</b> and follows the
* same usage conditions
*
* @author DarkBlade12
* @since 1.6
*/
public static final class ItemData extends ParticleData {
/**
* Construct a new item data
*
* @param material Material of the item
*/
public ItemData(Material material) {
super(material);
}
}
/**
* Represents the block data for the {@link ParticleEffect#BLOCK} and
* {@link ParticleEffect#FALLING_DUST} effects
* <p>
* This class is part of the <b>ParticleEffect Library</b> and follows the
* same usage conditions
*
* @author DarkBlade12
* @since 1.6
*/
public static final class BlockData extends ParticleData {
/**
* Construct a new block data
*
* @param material Material of the block
* @throws IllegalArgumentException If the material is not a block
*/
public BlockData(Material material) throws IllegalArgumentException {
super(material);
if (!material.isBlock()) {
throw new IllegalArgumentException("The material is not a block");
}
}
}
/** /**
* Represents the color for effects like {@link ParticleEffect#ENTITY_EFFECT}, * Represents the color for effects like {@link ParticleEffect#ENTITY_EFFECT},
* {@link ParticleEffect#AMBIENT_ENTITY_EFFECT}, {@link ParticleEffect#DUST} * {@link ParticleEffect#AMBIENT_ENTITY_EFFECT}, {@link ParticleEffect#DUST}

View file

@ -0,0 +1,224 @@
package com.esophose.playerparticles.particles;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import com.esophose.playerparticles.gui.PlayerParticlesGui;
import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.particles.ParticleEffect.NoteColor;
import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
import com.esophose.playerparticles.particles.ParticleEffect.ParticleColor;
import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty;
import com.esophose.playerparticles.styles.DefaultStyles;
import com.esophose.playerparticles.styles.api.ParticleStyle;
import com.esophose.playerparticles.util.ParticleUtils;
public class ParticlePair {
private UUID ownerUUID;
private int id;
private ParticleEffect effect;
private ParticleStyle style;
private Material particleItemMaterial;
private Material particleBlockMaterial;
private OrdinaryColor particleColorData;
private NoteColor particleNoteColorData;
public ParticlePair(UUID ownerUUID, int id, ParticleEffect effect, ParticleStyle style, Material itemMaterial, Material blockMaterial, OrdinaryColor colorData, NoteColor noteColorData) {
this.ownerUUID = ownerUUID;
this.id = id;
this.effect = effect;
this.style = style;
this.setParticleEffect(effect);
this.setParticleStyle(style);
this.setItemMaterial(itemMaterial);
this.setBlockData(blockMaterial);
this.setColorData(colorData);
this.setNoteColorData(noteColorData);
}
/**
* Sets the player's particle effect
*
* @param effect The player's new particle effect
*/
public void setParticleEffect(ParticleEffect effect) {
if (effect == null) effect = ParticleEffect.NONE;
this.effect = effect;
}
/**
* Sets the player's particle style
*
* @param style The player's new particle style
*/
public void setParticleStyle(ParticleStyle style) {
if (style == null) style = DefaultStyles.NONE;
this.style = style;
}
/**
* Sets the player's item material
*
* @param itemMaterial The player's new item material
*/
public void setItemMaterial(Material itemMaterial) {
if (itemMaterial == null || itemMaterial.isBlock()) itemMaterial = ParticleUtils.closestMatchWithFallback("IRON_SHOVEL", "IRON_SPADE");
this.particleItemMaterial = itemMaterial;
}
/**
* Sets the player's block material
*
* @param blockMaterial The player's new block material
*/
public void setBlockData(Material blockMaterial) {
if (blockMaterial == null) blockMaterial = Material.STONE;
this.particleBlockMaterial = blockMaterial;
}
/**
* Sets the player's color data
*
* @param colorData The player's new color data
*/
public void setColorData(OrdinaryColor colorData) {
if (colorData == null) colorData = new OrdinaryColor(0, 0, 0);
this.particleColorData = colorData;
}
/**
* Sets the player's note color data
*
* @param noteColorData The player's new note color data
*/
public void setNoteColorData(NoteColor noteColorData) {
if (noteColorData == null) noteColorData = new NoteColor(0);
this.particleNoteColorData = noteColorData;
}
/**
* Get the UUID of the PPlayer that owns this ParticlePair
*
* @return The owner's UUID
*/
public UUID getOwnerUniqueId() {
return this.ownerUUID;
}
/**
* Get the id of this particle
*
* @return The id of this particle
*/
public int getId() {
return this.id;
}
/**
* Get the ParticleEffect that this ParticlePair represents
*
* @return The effect
*/
public ParticleEffect getEffect() {
return this.effect;
}
/**
* Get the ParticleStyle that this ParticlePair represents
*
* @return The style
*/
public ParticleStyle getStyle() {
return this.style;
}
/**
* Gets the color the current particle effect will spawn with
*
* @return Gets the ParticleColor the current particle effect will spawn with
*/
public ParticleColor getSpawnColor() {
if (this.effect.hasProperty(ParticleProperty.COLORABLE)) {
if (this.effect == ParticleEffect.NOTE) {
if (this.particleNoteColorData.getValueX() * 24 == 99) {
return ParticleManager.getRainbowNoteParticleColor();
}
return this.particleNoteColorData;
} else {
if (this.particleColorData.getRed() == 999 && this.particleColorData.getGreen() == 999 && this.particleColorData.getBlue() == 999) {
return ParticleManager.getRainbowParticleColor();
} else {
return this.particleColorData;
}
}
}
return null;
}
/**
* Gets the material the current particle effect will spawn with
*
* @return The Material the current particle effect requires
*/
public Material getSpawnMaterial() {
if (this.effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
if (this.effect == ParticleEffect.ITEM) {
return this.particleItemMaterial;
} else {
return this.particleBlockMaterial;
}
}
return null;
}
/**
* Gets the current particle data as a string
*
* @return The particle data in a human-readable string
*/
public String getParticleDataString() {
if (this.effect == ParticleEffect.BLOCK || this.effect == ParticleEffect.FALLING_DUST) {
return this.particleBlockMaterial.toString().toLowerCase();
} else if (this.effect == ParticleEffect.ITEM) {
return this.particleItemMaterial.toString().toLowerCase();
} else if (this.effect.hasProperty(ParticleProperty.COLORABLE)) {
if (this.effect == ParticleEffect.NOTE) {
if (this.particleNoteColorData.getValueX() * 24 == 99) {
return PlayerParticlesGui.rainbowName;
}
return "note #" + (int) (this.particleNoteColorData.getValueX() * 24);
} else {
if (this.particleColorData.getRed() == 999 && this.particleColorData.getGreen() == 999 && this.particleColorData.getBlue() == 999) {
return PlayerParticlesGui.rainbowName;
} else {
return ChatColor.RED + "" + this.particleColorData.getRed() + " " + ChatColor.GREEN + this.particleColorData.getGreen() + " " + ChatColor.AQUA + this.particleColorData.getBlue();
}
}
}
return "none";
}
/**
* Gets a ParticlePair with the default values applied
*
* @return A ParticlePair with default values
*/
public static ParticlePair getDefault() {
return new ParticlePair(null, // @formatter:off
-1,
ParticleEffect.NONE,
DefaultStyles.NONE,
ParticleUtils.closestMatchWithFallback("IRON_SHOVEL", "IRON_SPADE"),
Material.STONE,
new OrdinaryColor(0, 0, 0),
new NoteColor(0)); // @formatter:on
}
}

View file

@ -40,6 +40,7 @@ public class DefaultStyles {
* Registered in alphabetical order * Registered in alphabetical order
*/ */
public static void registerStyles() { public static void registerStyles() {
ParticleStyleManager.registerStyle(NONE); // Always display none first
ParticleStyleManager.registerStyle(ARROWS); ParticleStyleManager.registerStyle(ARROWS);
ParticleStyleManager.registerStyle(BEAM); ParticleStyleManager.registerStyle(BEAM);
ParticleStyleManager.registerCustomHandledStyle(BLOCKBREAK); ParticleStyleManager.registerCustomHandledStyle(BLOCKBREAK);
@ -50,7 +51,6 @@ public class DefaultStyles {
ParticleStyleManager.registerStyle(HALO); ParticleStyleManager.registerStyle(HALO);
ParticleStyleManager.registerCustomHandledStyle(HURT); ParticleStyleManager.registerCustomHandledStyle(HURT);
ParticleStyleManager.registerCustomHandledStyle(MOVE); ParticleStyleManager.registerCustomHandledStyle(MOVE);
ParticleStyleManager.registerStyle(NONE);
ParticleStyleManager.registerStyle(ORBIT); ParticleStyleManager.registerStyle(ORBIT);
ParticleStyleManager.registerStyle(POINT); ParticleStyleManager.registerStyle(POINT);
ParticleStyleManager.registerStyle(QUADHELIX); ParticleStyleManager.registerStyle(QUADHELIX);

View file

@ -11,7 +11,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.entity.EntityShootBowEvent;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
@ -20,16 +20,16 @@ public class ParticleStyleArrows implements ParticleStyle, Listener {
private String[] arrowEntityNames = new String[] { "ARROW", "SPECTRAL_ARROW", "TIPPED_ARROW" }; private String[] arrowEntityNames = new String[] { "ARROW", "SPECTRAL_ARROW", "TIPPED_ARROW" };
private List<Arrow> arrows = new ArrayList<Arrow>(); private List<Arrow> arrows = new ArrayList<Arrow>();
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<PParticle>(); List<PParticle> particles = new ArrayList<PParticle>();
for (Arrow arrow : arrows) { for (Arrow arrow : arrows) {
if (((Player) arrow.getShooter()).getUniqueId() == pplayer.getUniqueId()) { if (((Player) arrow.getShooter()).getUniqueId() == particle.getOwnerUniqueId()) {
particles.add(new PParticle(arrow.getLocation(), 0.05F, 0.05F, 0.05F, 0.0F)); particles.add(new PParticle(arrow.getLocation(), 0.05F, 0.05F, 0.05F, 0.0F));
} }
} }
return particles.toArray(new PParticle[particles.size()]); return particles;
} }
/** /**

View file

@ -1,8 +1,11 @@
package com.esophose.playerparticles.styles; package com.esophose.playerparticles.styles;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
@ -11,17 +14,17 @@ public class ParticleStyleBeam implements ParticleStyle {
private float step = 0; private float step = 0;
private boolean reversed = false; private boolean reversed = false;
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
int points = 16; int points = 16;
double radius = 1; double radius = 1;
double slice = 2 * Math.PI / points; double slice = 2 * Math.PI / points;
PParticle[] particles = new PParticle[points]; List<PParticle> particles = new ArrayList<PParticle>();
for (int i = 0; i < points; i++) { for (int i = 0; i < points; i++) {
double angle = slice * i; double angle = slice * i;
double newX = location.getX() + radius * Math.cos(angle); double newX = location.getX() + radius * Math.cos(angle);
double newY = location.getY() + (step / 10) - 1; double newY = location.getY() + (step / 10) - 1;
double newZ = location.getZ() + radius * Math.sin(angle); double newZ = location.getZ() + radius * Math.sin(angle);
particles[i] = new PParticle(new Location(location.getWorld(), newX, newY, newZ)); particles.add(new PParticle(new Location(location.getWorld(), newX, newY, newZ)));
} }
return particles; return particles;
} }

View file

@ -10,22 +10,22 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.manager.DataManager;
import com.esophose.playerparticles.manager.PPlayerDataManager;
import com.esophose.playerparticles.manager.ParticleManager; import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.manager.PermissionManager; import com.esophose.playerparticles.particles.PPlayer;
import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleBlockBreak implements ParticleStyle, Listener { public class ParticleStyleBlockBreak implements ParticleStyle, Listener {
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<PParticle>(); List<PParticle> particles = new ArrayList<PParticle>();
for (int i = 0; i < 15; i++) for (int i = 0; i < 15; i++)
particles.add(new PParticle(location.clone().add(0.5, 0.5, 0.5), 0.5F, 0.5F, 0.5F, 0.05F)); particles.add(new PParticle(location.clone().add(0.5, 0.5, 0.5), 0.5F, 0.5F, 0.5F, 0.05F));
return particles.toArray(new PParticle[particles.size()]); return particles;
} }
public void updateTimers() { public void updateTimers() {
@ -43,10 +43,12 @@ public class ParticleStyleBlockBreak implements ParticleStyle, Listener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
PPlayer pplayer = PPlayerDataManager.getInstance().getPPlayer(player.getUniqueId()); PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.BLOCKBREAK && PermissionManager.hasStylePermission(player, DefaultStyles.BLOCKBREAK)) { if (pplayer != null) {
for (ParticlePair particle : pplayer.getParticlesForStyle(DefaultStyles.BLOCKBREAK)) {
Location loc = event.getBlock().getLocation(); Location loc = event.getBlock().getLocation();
ParticleManager.displayParticles(pplayer, DefaultStyles.BLOCKBREAK.getParticles(pplayer, loc)); ParticleManager.displayParticles(particle, DefaultStyles.BLOCKBREAK.getParticles(particle, loc));
}
} }
} }

View file

@ -1,5 +1,8 @@
package com.esophose.playerparticles.styles; package com.esophose.playerparticles.styles;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -8,17 +11,17 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.manager.DataManager;
import com.esophose.playerparticles.manager.PPlayerDataManager;
import com.esophose.playerparticles.manager.ParticleManager; import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.manager.PermissionManager; import com.esophose.playerparticles.particles.PPlayer;
import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleBlockEdit implements ParticleStyle, Listener { public class ParticleStyleBlockEdit implements ParticleStyle, Listener {
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
return new PParticle[0]; // Particles are taken from DefaultStyles.BLOCKPLACE or DefaultStyles.BLOCKBREAK return new ArrayList<PParticle>(); // Particles are taken from DefaultStyles.BLOCKPLACE or DefaultStyles.BLOCKBREAK
} }
public void updateTimers() { public void updateTimers() {
@ -36,20 +39,24 @@ public class ParticleStyleBlockEdit implements ParticleStyle, Listener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
PPlayer pplayer = PPlayerDataManager.getInstance().getPPlayer(player.getUniqueId()); PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.BLOCKEDIT && PermissionManager.hasStylePermission(player, DefaultStyles.BLOCKEDIT)) { if (pplayer != null) {
for (ParticlePair particle : pplayer.getParticlesForStyle(DefaultStyles.BLOCKEDIT)) {
Location loc = event.getBlock().getLocation(); Location loc = event.getBlock().getLocation();
ParticleManager.displayParticles(pplayer, DefaultStyles.BLOCKBREAK.getParticles(pplayer, loc)); ParticleManager.displayParticles(particle, DefaultStyles.BLOCKBREAK.getParticles(particle, loc));
}
} }
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
PPlayer pplayer = PPlayerDataManager.getInstance().getPPlayer(player.getUniqueId()); PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.BLOCKEDIT && PermissionManager.hasStylePermission(player, DefaultStyles.BLOCKEDIT)) { if (pplayer != null) {
Location loc = event.getBlockPlaced().getLocation(); for (ParticlePair particle : pplayer.getParticlesForStyle(DefaultStyles.BLOCKEDIT)) {
ParticleManager.displayParticles(pplayer, DefaultStyles.BLOCKPLACE.getParticles(pplayer, loc)); Location loc = event.getBlock().getLocation();
ParticleManager.displayParticles(particle, DefaultStyles.BLOCKPLACE.getParticles(particle, loc));
}
} }
} }

View file

@ -10,22 +10,22 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.manager.DataManager;
import com.esophose.playerparticles.manager.PPlayerDataManager;
import com.esophose.playerparticles.manager.ParticleManager; import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.manager.PermissionManager; import com.esophose.playerparticles.particles.PPlayer;
import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleBlockPlace implements ParticleStyle, Listener { public class ParticleStyleBlockPlace implements ParticleStyle, Listener {
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<PParticle>(); List<PParticle> particles = new ArrayList<PParticle>();
for (int i = 0; i < 15; i++) for (int i = 0; i < 15; i++)
particles.add(new PParticle(location.clone().add(0.5, 0.5, 0.5), 0.75F, 0.75F, 0.75F, 0.05F)); particles.add(new PParticle(location.clone().add(0.5, 0.5, 0.5), 0.75F, 0.75F, 0.75F, 0.05F));
return particles.toArray(new PParticle[particles.size()]); return particles;
} }
public void updateTimers() { public void updateTimers() {
@ -43,10 +43,12 @@ public class ParticleStyleBlockPlace implements ParticleStyle, Listener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
PPlayer pplayer = PPlayerDataManager.getInstance().getPPlayer(player.getUniqueId()); PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.BLOCKPLACE && PermissionManager.hasStylePermission(player, DefaultStyles.BLOCKPLACE)) { if (pplayer != null) {
Location loc = event.getBlockPlaced().getLocation(); for (ParticlePair particle : pplayer.getParticlesForStyle(DefaultStyles.BLOCKPLACE)) {
ParticleManager.displayParticles(pplayer, DefaultStyles.BLOCKPLACE.getParticles(pplayer, loc)); Location loc = event.getBlock().getLocation();
ParticleManager.displayParticles(particle, DefaultStyles.BLOCKPLACE.getParticles(particle, loc));
}
} }
} }

View file

@ -29,7 +29,7 @@ import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
import com.esophose.playerparticles.util.VectorUtils; import com.esophose.playerparticles.util.VectorUtils;
@ -49,7 +49,7 @@ public class ParticleStyleCube implements ParticleStyle {
private int step = 0; private int step = 0;
private boolean skipNextStep = false; // Only spawn every 2 ticks private boolean skipNextStep = false; // Only spawn every 2 ticks
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> pparticles = new ArrayList<PParticle>(); List<PParticle> pparticles = new ArrayList<PParticle>();
if (!skipNextStep) { if (!skipNextStep) {
@ -83,7 +83,7 @@ public class ParticleStyleCube implements ParticleStyle {
} }
} }
return pparticles.toArray(new PParticle[pparticles.size()]); return pparticles;
} }
public void updateTimers() { public void updateTimers() {

View file

@ -1,15 +1,20 @@
package com.esophose.playerparticles.styles; package com.esophose.playerparticles.styles;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleFeet implements ParticleStyle { public class ParticleStyleFeet implements ParticleStyle {
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
return new PParticle[] { new PParticle(location.subtract(0, 0.95, 0), 0.4F, 0.0F, 0.4F, 0.0F) }; List<PParticle> particles = new ArrayList<PParticle>();
particles.add(new PParticle(location.subtract(0, 0.95, 0), 0.4F, 0.0F, 0.4F, 0.0F));
return particles;
} }
public void updateTimers() { public void updateTimers() {

View file

@ -1,8 +1,11 @@
package com.esophose.playerparticles.styles; package com.esophose.playerparticles.styles;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
@ -10,18 +13,19 @@ public class ParticleStyleHalo implements ParticleStyle {
private float step = 0; private float step = 0;
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
if (step % 2 == 0) return new PParticle[0]; if (step % 2 == 0) return new ArrayList<PParticle>();
int points = 16; int points = 16;
double radius = .65; double radius = .65;
double slice = 2 * Math.PI / points; double slice = 2 * Math.PI / points;
PParticle[] particles = new PParticle[points]; List<PParticle> particles = new ArrayList<PParticle>();
for (int i = 0; i < points; i++) { for (int i = 0; i < points; i++) {
double angle = slice * i; double angle = slice * i;
double newX = location.getX() + radius * Math.cos(angle); double newX = location.getX() + radius * Math.cos(angle);
double newY = location.getY() + 1.5; double newY = location.getY() + 1.5;
double newZ = location.getZ() + radius * Math.sin(angle); double newZ = location.getZ() + radius * Math.sin(angle);
particles[i] = new PParticle(new Location(location.getWorld(), newX, newY, newZ)); particles.add(new PParticle(new Location(location.getWorld(), newX, newY, newZ)));
} }
return particles; return particles;
} }

View file

@ -1,5 +1,8 @@
package com.esophose.playerparticles.styles; package com.esophose.playerparticles.styles;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -7,22 +10,22 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.manager.DataManager;
import com.esophose.playerparticles.manager.PPlayerDataManager;
import com.esophose.playerparticles.manager.ParticleManager; import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.manager.PermissionManager; import com.esophose.playerparticles.particles.PPlayer;
import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleHurt implements ParticleStyle, Listener { public class ParticleStyleHurt implements ParticleStyle, Listener {
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
PParticle[] baseParticles = DefaultStyles.THICK.getParticles(pplayer, location); List<PParticle> baseParticles = DefaultStyles.THICK.getParticles(particle, location);
int multiplyingFactor = 3; // Uses the same logic as ParticleStyleThick except multiplies the resulting particles by 3x int multiplyingFactor = 3; // Uses the same logic as ParticleStyleThick except multiplies the resulting particles by 3x
PParticle[] particles = new PParticle[baseParticles.length * multiplyingFactor]; List<PParticle> particles = new ArrayList<PParticle>();
for (int i = 0; i < baseParticles.length * multiplyingFactor; i++) { for (int i = 0; i < baseParticles.size() * multiplyingFactor; i++) {
particles[i] = baseParticles[i % baseParticles.length]; particles.add(baseParticles.get(i % baseParticles.size()));
} }
return particles; return particles;
@ -44,10 +47,12 @@ public class ParticleStyleHurt implements ParticleStyle, Listener {
public void onEntityDamage(EntityDamageEvent event) { public void onEntityDamage(EntityDamageEvent event) {
if (event.getEntity() instanceof Player) { if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity(); Player player = (Player) event.getEntity();
PPlayer pplayer = PPlayerDataManager.getInstance().getPPlayer(player.getUniqueId()); PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.HURT && PermissionManager.hasStylePermission(player, DefaultStyles.HURT)) { if (pplayer != null) {
for (ParticlePair particle : pplayer.getParticlesForStyle(DefaultStyles.HURT)) {
Location loc = player.getLocation().clone().add(0, 1, 0); Location loc = player.getLocation().clone().add(0, 1, 0);
ParticleManager.displayParticles(pplayer, DefaultStyles.HURT.getParticles(pplayer, loc)); ParticleManager.displayParticles(particle, DefaultStyles.HURT.getParticles(particle, loc));
}
} }
} }
} }

View file

@ -1,22 +1,24 @@
package com.esophose.playerparticles.styles; package com.esophose.playerparticles.styles;
import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.manager.DataManager;
import com.esophose.playerparticles.manager.PPlayerDataManager;
import com.esophose.playerparticles.manager.ParticleManager; import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.manager.PermissionManager; import com.esophose.playerparticles.particles.PPlayer;
import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleMove implements ParticleStyle, Listener { public class ParticleStyleMove implements ParticleStyle, Listener {
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
return DefaultStyles.NONE.getParticles(pplayer, location); return DefaultStyles.NONE.getParticles(particle, location);
} }
public void updateTimers() { public void updateTimers() {
@ -33,12 +35,12 @@ public class ParticleStyleMove implements ParticleStyle, Listener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerMove(PlayerMoveEvent e) { public void onPlayerMove(PlayerMoveEvent e) {
PPlayer pplayer = PPlayerDataManager.getInstance().getPPlayer(e.getPlayer().getUniqueId()); PPlayer pplayer = DataManager.getPPlayer(e.getPlayer().getUniqueId());
if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.MOVE) { if (pplayer != null) {
if (PermissionManager.hasStylePermission(e.getPlayer(), DefaultStyles.MOVE)) { for (ParticlePair particle : pplayer.getParticlesForStyle(DefaultStyles.MOVE)) {
Location loc = e.getPlayer().getLocation(); Location loc = e.getPlayer().getLocation();
loc.setY(loc.getY() + 0.05); loc.setY(loc.getY() + 0.05);
ParticleManager.displayParticles(pplayer, DefaultStyles.MOVE.getParticles(pplayer, loc)); ParticleManager.displayParticles(particle, DefaultStyles.MOVE.getParticles(particle, loc));
} }
} }
} }

View file

@ -1,111 +1,131 @@
package com.esophose.playerparticles.styles; package com.esophose.playerparticles.styles;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import com.esophose.playerparticles.PPlayer;
import com.esophose.playerparticles.particles.ParticleEffect; import com.esophose.playerparticles.particles.ParticleEffect;
import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleNone implements ParticleStyle { public class ParticleStyleNone implements ParticleStyle {
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
ParticleEffect particleEffect = pplayer.getParticleEffect(); ParticleEffect particleEffect = particle.getEffect();
if (particleEffect.equals(ParticleEffect.ANGRY_VILLAGER)) { List<PParticle> particles = new ArrayList<PParticle>();
return new PParticle[] { new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F) };
} else if (particleEffect.equals(ParticleEffect.BUBBLE)) { switch (particleEffect) {
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) }; case AMBIENT_ENTITY_EFFECT:
} else if (particleEffect.equals(ParticleEffect.CLOUD)) { return Collections.singletonList(new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F));
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) }; case ANGRY_VILLAGER:
} else if (particleEffect.equals(ParticleEffect.CRIT)) { return Collections.singletonList(new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F));
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) }; case BARRIER:
} else if (particleEffect.equals(ParticleEffect.UNDERWATER)) { return Collections.singletonList(new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F));
PParticle[] particles = new PParticle[5]; case BLOCK:
for (int i = 0; i < 5; i++) return Collections.singletonList(new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F));
particles[i] = new PParticle(location, 0.5F, 0.5F, 0.5F, 0.0F); case BUBBLE:
return particles; return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
} else if (particleEffect.equals(ParticleEffect.DRIPPING_LAVA)) { case BUBBLE_COLUMN_UP:
return new PParticle[] { new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F) }; return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
} else if (particleEffect.equals(ParticleEffect.DRIPPING_LAVA)) { case BUBBLE_POP:
return new PParticle[] { new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F) }; return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
} else if (particleEffect.equals(ParticleEffect.ENCHANT)) { case CLOUD:
return new PParticle[] { new PParticle(location, 0.6F, 0.6F, 0.6F, 0.05F) }; return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
} else if (particleEffect.equals(ParticleEffect.POOF)) { case CRIT:
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) }; return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
} else if (particleEffect.equals(ParticleEffect.FIREWORK)) { case CURRENT_DOWN:
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) }; return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
} else if (particleEffect.equals(ParticleEffect.FLAME)) { case DAMAGE_INDICATOR:
return new PParticle[] { new PParticle(location, 0.1F, 0.1F, 0.1F, 0.05F) }; return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
} else if (particleEffect.equals(ParticleEffect.FOOTSTEP)) { case DOLPHIN:
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) }; return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
} else if (particleEffect.equals(ParticleEffect.HAPPY_VILLAGER)) { case DRAGON_BREATH:
return new PParticle[] { new PParticle(location, 0.5F, 0.5F, 0.5F, 0.0F) }; return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
} else if (particleEffect.equals(ParticleEffect.HEART)) { case DRIPPING_LAVA:
return new PParticle[] { new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F) }; return Collections.singletonList(new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F));
} else if (particleEffect.equals(ParticleEffect.EXPLOSION_EMITTER)) { case DRIPPING_WATER:
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) }; return Collections.singletonList(new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F));
} else if (particleEffect.equals(ParticleEffect.INSTANT_EFFECT)) { case DUST:
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) }; return Collections.singletonList(new PParticle(location, 0.5F, 0.5F, 0.5F, 0.0F));
} else if (particleEffect.equals(ParticleEffect.EXPLOSION)) { case ENCHANT:
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) }; return Collections.singletonList(new PParticle(location, 0.6F, 0.6F, 0.6F, 0.05F));
} else if (particleEffect.equals(ParticleEffect.LARGE_SMOKE)) { case ENCHANTED_HIT:
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) }; return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
} else if (particleEffect.equals(ParticleEffect.LAVA)) { case END_ROD:
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) }; return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
} else if (particleEffect.equals(ParticleEffect.ENCHANTED_HIT)) { case ENTITY_EFFECT:
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) }; return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
} else if (particleEffect.equals(ParticleEffect.ENTITY_EFFECT)) { case EXPLOSION:
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) }; return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
} else if (particleEffect.equals(ParticleEffect.AMBIENT_ENTITY_EFFECT)) { case EXPLOSION_EMITTER:
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) }; return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
} else if (particleEffect.equals(ParticleEffect.NOTE)) { case FALLING_DUST:
return new PParticle[] { new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F) };
} else if (particleEffect.equals(ParticleEffect.PORTAL)) {
return new PParticle[] { new PParticle(location, 0.5F, 0.5F, 0.5F, 0.05F) };
} else if (particleEffect.equals(ParticleEffect.DUST)) {
return new PParticle[] { new PParticle(location, 0.5F, 0.5F, 0.5F, 0.0F) };
} else if (particleEffect.equals(ParticleEffect.ITEM_SLIME)) {
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) };
} else if (particleEffect.equals(ParticleEffect.SMOKE)) {
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) };
} else if (particleEffect.equals(ParticleEffect.ITEM_SNOWBALL)) {
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) };
} else if (particleEffect.equals(ParticleEffect.SPELL)) {
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) };
} else if (particleEffect.equals(ParticleEffect.UNDERWATER)) {
PParticle[] particles = new PParticle[3];
for (int i = 0; i < 3; i++)
particles[i] = new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F);
return particles;
} else if (particleEffect.equals(ParticleEffect.WITCH)) {
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) };
} else if (particleEffect.equals(ParticleEffect.BARRIER)) {
return new PParticle[] { new PParticle(location, 1.2F, 1.2F, 1.2F, 0.0F) };
} else if (particleEffect.equals(ParticleEffect.SPLASH)) {
return new PParticle[] { new PParticle(location, 0.8F, 0.8F, 0.8F, 0.0F) };
} else if (particleEffect.equals(ParticleEffect.DRAGON_BREATH)) {
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) };
} else if (particleEffect.equals(ParticleEffect.END_ROD)) {
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) };
} else if (particleEffect.equals(ParticleEffect.DAMAGE_INDICATOR)) {
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) };
} else if (particleEffect.equals(ParticleEffect.SWEEP_ATTACK)) {
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) };
} else if (particleEffect.equals(ParticleEffect.BLOCK)) {
return new PParticle[] { new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F) };
} else if (particleEffect.equals(ParticleEffect.ITEM)) {
return new PParticle[] { new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F) };
} else if (particleEffect.equals(ParticleEffect.FALLING_DUST)) {
PParticle[] particles = new PParticle[2];
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
particles[i] = new PParticle(location.add(0, 0.75, 0), 0.6F, 0.4F, 0.6F, 0.0F); particles.add(new PParticle(location.add(0, 0.75, 0), 0.6F, 0.4F, 0.6F, 0.0F));
return particles; return particles;
} else if (particleEffect.equals(ParticleEffect.TOTEM_OF_UNDYING)) { case FIREWORK:
return new PParticle[] { new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F) }; return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
} else if (particleEffect.equals(ParticleEffect.SPIT)) { case FISHING:
return new PParticle[] { new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F) }; return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
} else { case FLAME:
return new PParticle[] { new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F) }; return Collections.singletonList(new PParticle(location, 0.1F, 0.1F, 0.1F, 0.05F));
case FOOTSTEP:
return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
case HAPPY_VILLAGER:
return Collections.singletonList(new PParticle(location, 0.5F, 0.5F, 0.5F, 0.0F));
case HEART:
return Collections.singletonList(new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F));
case INSTANT_EFFECT:
return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
case ITEM:
return Collections.singletonList(new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F));
case ITEM_SLIME:
return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
case ITEM_SNOWBALL:
return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
case LARGE_SMOKE:
return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
case LAVA:
return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
case MYCELIUM:
return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
case NAUTILUS:
return Collections.singletonList(new PParticle(location, 0.5F, 0.5F, 0.5F, 0.05F));
case NONE:
return particles;
case NOTE:
return Collections.singletonList(new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F));
case POOF:
return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
case PORTAL:
return Collections.singletonList(new PParticle(location, 0.5F, 0.5F, 0.5F, 0.05F));
case RAIN:
return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
case SMOKE:
return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
case SPELL:
return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
case SPIT:
return Collections.singletonList(new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F));
case SPLASH:
return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
case SQUID_INK:
return Collections.singletonList(new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F));
case SWEEP_ATTACK:
return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
case TOTEM_OF_UNDYING:
return Collections.singletonList(new PParticle(location, 0.6F, 0.6F, 0.6F, 0.0F));
case UNDERWATER:
for (int i = 0; i < 5; i++)
particles.add(new PParticle(location, 0.5F, 0.5F, 0.5F, 0.0F));
return particles;
case WITCH:
return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
default:
return Collections.singletonList(new PParticle(location, 0.4F, 0.4F, 0.4F, 0.0F));
} }
} }

View file

@ -1,8 +1,11 @@
package com.esophose.playerparticles.styles; package com.esophose.playerparticles.styles;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
@ -10,13 +13,13 @@ public class ParticleStyleOrbit implements ParticleStyle {
private float step = 0; private float step = 0;
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
int orbs = 3; int orbs = 3;
PParticle[] particles = new PParticle[orbs]; List<PParticle> particles = new ArrayList<PParticle>();
for (int i = 0; i < orbs; i++) { for (int i = 0; i < orbs; i++) {
double dx = -(Math.cos((step / 120) * (Math.PI * 2) + (((Math.PI * 2) / orbs) * i))); double dx = -(Math.cos((step / 120) * (Math.PI * 2) + (((Math.PI * 2) / orbs) * i)));
double dz = -(Math.sin((step / 120) * (Math.PI * 2) + (((Math.PI * 2) / orbs) * i))); double dz = -(Math.sin((step / 120) * (Math.PI * 2) + (((Math.PI * 2) / orbs) * i)));
particles[i] = new PParticle(new Location(location.getWorld(), location.getX() + dx, location.getY(), location.getZ() + dz)); particles.add(new PParticle(new Location(location.getWorld(), location.getX() + dx, location.getY(), location.getZ() + dz)));
} }
return particles; return particles;
} }

View file

@ -1,15 +1,18 @@
package com.esophose.playerparticles.styles; package com.esophose.playerparticles.styles;
import java.util.Collections;
import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStylePoint implements ParticleStyle { public class ParticleStylePoint implements ParticleStyle {
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
return new PParticle[] { new PParticle(location.add(0.0, 1.5, 0.0)) }; return Collections.singletonList(new PParticle(location.add(0.0, 1.5, 0.0)));
} }
public void updateTimers() { public void updateTimers() {

View file

@ -1,8 +1,11 @@
package com.esophose.playerparticles.styles; package com.esophose.playerparticles.styles;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
@ -12,13 +15,13 @@ public class ParticleStyleQuadhelix implements ParticleStyle {
private float stepY = 0; private float stepY = 0;
private boolean reverse = false; private boolean reverse = false;
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
PParticle[] particles = new PParticle[4]; List<PParticle> particles = new ArrayList<PParticle>();
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
double dx = -(Math.cos((stepX / 90) * (Math.PI * 2) + ((Math.PI / 2) * i))) * ((60 - Math.abs(stepY)) / 60); double dx = -(Math.cos((stepX / 90) * (Math.PI * 2) + ((Math.PI / 2) * i))) * ((60 - Math.abs(stepY)) / 60);
double dy = (stepY / 60) * 1.5; double dy = (stepY / 60) * 1.5;
double dz = -(Math.sin((stepX / 90) * (Math.PI * 2) + ((Math.PI / 2) * i))) * ((60 - Math.abs(stepY)) / 60); double dz = -(Math.sin((stepX / 90) * (Math.PI * 2) + ((Math.PI / 2) * i))) * ((60 - Math.abs(stepY)) / 60);
particles[i] = new PParticle(new Location(location.getWorld(), location.getX() + dx, location.getY() + dy, location.getZ() + dz)); particles.add(new PParticle(new Location(location.getWorld(), location.getX() + dx, location.getY() + dy, location.getZ() + dz)));
} }
return particles; return particles;
} }

View file

@ -1,20 +1,22 @@
package com.esophose.playerparticles.styles; package com.esophose.playerparticles.styles;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleSphere implements ParticleStyle { public class ParticleStyleSphere implements ParticleStyle {
@Override public List<PParticle> getParticles(ParticlePair particle, Location location) {
public PParticle[] getParticles(PPlayer pplayer, Location location) { int density = 15;
int particleCount = 15;
float radius = 1.5f; float radius = 1.5f;
PParticle[] particles = new PParticle[particleCount]; List<PParticle> particles = new ArrayList<PParticle>();
for (int i = 0; i < particleCount; i++) { for (int i = 0; i < density; i++) {
double u = Math.random(); double u = Math.random();
double v = Math.random(); double v = Math.random();
double theta = 2 * Math.PI * u; double theta = 2 * Math.PI * u;
@ -22,7 +24,7 @@ public class ParticleStyleSphere implements ParticleStyle {
double x = location.getX() + (radius * Math.sin(phi) * Math.cos(theta)); double x = location.getX() + (radius * Math.sin(phi) * Math.cos(theta));
double y = location.getY() + (radius * Math.sin(phi) * Math.sin(theta)); double y = location.getY() + (radius * Math.sin(phi) * Math.sin(theta));
double z = location.getZ() + (radius * Math.cos(phi)); double z = location.getZ() + (radius * Math.cos(phi));
particles[i] = new PParticle(new Location(location.getWorld(), x, y, z)); particles.add(new PParticle(new Location(location.getWorld(), x, y, z)));
} }
return particles; return particles;

View file

@ -1,8 +1,11 @@
package com.esophose.playerparticles.styles; package com.esophose.playerparticles.styles;
import java.util.Collections;
import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
@ -10,7 +13,7 @@ public class ParticleStyleSpin implements ParticleStyle {
private float step = 0; private float step = 0;
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
int points = 15; int points = 15;
double radius = .5; double radius = .5;
double slice = 2 * Math.PI / points; double slice = 2 * Math.PI / points;
@ -18,7 +21,7 @@ public class ParticleStyleSpin implements ParticleStyle {
double newX = location.getX() + radius * Math.cos(angle); double newX = location.getX() + radius * Math.cos(angle);
double newY = location.getY() + 1.5; double newY = location.getY() + 1.5;
double newZ = location.getZ() + radius * Math.sin(angle); double newZ = location.getZ() + radius * Math.sin(angle);
return new PParticle[] { new PParticle(new Location(location.getWorld(), newX, newY, newZ)) }; return Collections.singletonList(new PParticle(new Location(location.getWorld(), newX, newY, newZ)));
} }
public void updateTimers() { public void updateTimers() {

View file

@ -5,7 +5,7 @@ import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
@ -13,7 +13,7 @@ public class ParticleStyleSpiral implements ParticleStyle {
private float stepX = 0; private float stepX = 0;
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<PParticle>(); List<PParticle> particles = new ArrayList<PParticle>();
for (int stepY = -60; stepY < 60; stepY += 10) { for (int stepY = -60; stepY < 60; stepY += 10) {
double dx = -(Math.cos(((stepX + stepY) / 90) * Math.PI * 2)) * 0.8; double dx = -(Math.cos(((stepX + stepY) / 90) * Math.PI * 2)) * 0.8;
@ -21,7 +21,7 @@ public class ParticleStyleSpiral implements ParticleStyle {
double dz = -(Math.sin(((stepX + stepY) / 90) * Math.PI * 2)) * 0.8; double dz = -(Math.sin(((stepX + stepY) / 90) * Math.PI * 2)) * 0.8;
particles.add(new PParticle(new Location(location.getWorld(), location.getX() + dx, location.getY() + dy, location.getZ() + dz))); particles.add(new PParticle(new Location(location.getWorld(), location.getX() + dx, location.getY() + dy, location.getZ() + dz)));
} }
return particles.toArray(new PParticle[particles.size()]); return particles;
} }
public void updateTimers() { public void updateTimers() {

View file

@ -12,10 +12,10 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.manager.DataManager;
import com.esophose.playerparticles.manager.PPlayerDataManager;
import com.esophose.playerparticles.manager.ParticleManager; import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.manager.PermissionManager; import com.esophose.playerparticles.particles.PPlayer;
import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
@ -25,16 +25,16 @@ public class ParticleStyleSwords implements ParticleStyle, Listener {
static { static {
SWORD_NAMES = new ArrayList<String>(); SWORD_NAMES = new ArrayList<String>();
SWORD_NAMES.addAll(Arrays.asList("WOOD_SWORD", "STONE_SWORD", "IRON_SWORD", "GOLD_SWORD", "DIAMOND_SWORD")); SWORD_NAMES.addAll(Arrays.asList("WOOD_SWORD", "STONE_SWORD", "IRON_SWORD", "GOLD_SWORD", "GOLDEN_SWORD", "DIAMOND_SWORD", "TRIDENT"));
} }
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
PParticle[] baseParticles = DefaultStyles.THICK.getParticles(pplayer, location); List<PParticle> baseParticles = DefaultStyles.THICK.getParticles(particle, location);
int multiplyingFactor = 3; // Uses the same logic as ParticleStyleThick except multiplies the resulting particles by 3x int multiplyingFactor = 3; // Uses the same logic as ParticleStyleThick except multiplies the resulting particles by 3x
PParticle[] particles = new PParticle[baseParticles.length * multiplyingFactor]; List<PParticle> particles = new ArrayList<PParticle>();
for (int i = 0; i < baseParticles.length * multiplyingFactor; i++) { for (int i = 0; i < baseParticles.size() * multiplyingFactor; i++) {
particles[i] = baseParticles[i % baseParticles.length]; particles.add(baseParticles.get(i % baseParticles.size()));
} }
return particles; return particles;
@ -57,11 +57,11 @@ public class ParticleStyleSwords implements ParticleStyle, Listener {
if (event.getDamager() instanceof Player && event.getEntity() instanceof LivingEntity) { if (event.getDamager() instanceof Player && event.getEntity() instanceof LivingEntity) {
Player player = (Player) event.getDamager(); Player player = (Player) event.getDamager();
LivingEntity entity = (LivingEntity) event.getEntity(); LivingEntity entity = (LivingEntity) event.getEntity();
PPlayer pplayer = PPlayerDataManager.getInstance().getPPlayer(player.getUniqueId()); PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
if (pplayer != null && pplayer.getParticleStyle() == DefaultStyles.SWORDS && PermissionManager.hasStylePermission(player, DefaultStyles.SWORDS)) { if (pplayer != null) {
if (player.getInventory().getItemInMainHand() != null && SWORD_NAMES.contains(player.getInventory().getItemInMainHand().getType().name())) { for (ParticlePair particle : pplayer.getParticlesForStyle(DefaultStyles.SWORDS)) {
Location loc = entity.getLocation().clone().add(0, 1, 0); Location loc = entity.getLocation().clone().add(0, 1, 0);
ParticleManager.displayParticles(pplayer, DefaultStyles.SWORDS.getParticles(pplayer, loc)); ParticleManager.displayParticles(particle, DefaultStyles.SWORDS.getParticles(particle, loc));
} }
} }
} }

View file

@ -1,20 +1,23 @@
package com.esophose.playerparticles.styles; package com.esophose.playerparticles.styles;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleThick implements ParticleStyle { public class ParticleStyleThick implements ParticleStyle {
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
PParticle[] baseParticles = DefaultStyles.NONE.getParticles(pplayer, location); List<PParticle> baseParticles = DefaultStyles.NONE.getParticles(particle, location);
int multiplyingFactor = 15; // Uses the same logic as ParticleStyleNone except multiplies the resulting particles by 15x int multiplyingFactor = 10; // Uses the same logic as ParticleStyleNone except multiplies the resulting particles by 10x
PParticle[] particles = new PParticle[baseParticles.length * multiplyingFactor]; List<PParticle> particles = new ArrayList<PParticle>();
for (int i = 0; i < baseParticles.length * multiplyingFactor; i++) { for (int i = 0; i < baseParticles.size() * multiplyingFactor; i++) {
particles[i] = baseParticles[i % baseParticles.length]; particles.add(baseParticles.get(i % baseParticles.size()));
} }
return particles; return particles;

View file

@ -6,7 +6,7 @@ import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle; import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
import com.esophose.playerparticles.util.VectorUtils; import com.esophose.playerparticles.util.VectorUtils;
@ -15,7 +15,7 @@ public class ParticleStyleWings implements ParticleStyle {
private int spawnTimer = 0; // Spawn particles every 3 ticks private int spawnTimer = 0; // Spawn particles every 3 ticks
public PParticle[] getParticles(PPlayer pplayer, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<PParticle>(); List<PParticle> particles = new ArrayList<PParticle>();
if (spawnTimer == 0) { if (spawnTimer == 0) {
for (double t = 0; t < Math.PI * 2; t += Math.PI / 64) { for (double t = 0; t < Math.PI * 2; t += Math.PI / 64) {
@ -26,7 +26,7 @@ public class ParticleStyleWings implements ParticleStyle {
particles.add(new PParticle(loc)); particles.add(new PParticle(loc));
} }
} }
return particles.toArray(new PParticle[particles.size()]); return particles;
} }
public void updateTimers() { public void updateTimers() {

View file

@ -13,7 +13,7 @@ import org.bukkit.Location;
public class PParticle { public class PParticle {
/** /**
* Data that affects the particle * Data that determines where the particle will spawn
*/ */
private Location location; private Location location;
private float speed; private float speed;

View file

@ -8,9 +8,11 @@
package com.esophose.playerparticles.styles.api; package com.esophose.playerparticles.styles.api;
import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import com.esophose.playerparticles.PPlayer; import com.esophose.playerparticles.particles.ParticlePair;
public interface ParticleStyle { public interface ParticleStyle {
@ -19,9 +21,9 @@ public interface ParticleStyle {
* *
* @param pplayer The PPlayer to display the particles for * @param pplayer The PPlayer to display the particles for
* @param location The central location of the particles * @param location The central location of the particles
* @return A list of all PParticles' to spawn * @return A List<PParticle> of PParticles to spawn
*/ */
public PParticle[] getParticles(PPlayer pplayer, Location location); public List<PParticle> getParticles(ParticlePair particle, Location location);
/** /**
* Used to update timers for animations, called once per particle tick * Used to update timers for animations, called once per particle tick

View file

@ -9,6 +9,7 @@
package com.esophose.playerparticles.styles.api; package com.esophose.playerparticles.styles.api;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import com.esophose.playerparticles.PlayerParticles; import com.esophose.playerparticles.PlayerParticles;
@ -17,8 +18,8 @@ public class ParticleStyleManager {
/** /**
* Arrays that contain all registered styles * Arrays that contain all registered styles
*/ */
private static ArrayList<ParticleStyle> styles = new ArrayList<ParticleStyle>(); private static List<ParticleStyle> styles = new ArrayList<ParticleStyle>();
private static ArrayList<ParticleStyle> customHandledStyles = new ArrayList<ParticleStyle>(); private static List<ParticleStyle> customHandledStyles = new ArrayList<ParticleStyle>();
/** /**
* Registers a style that is put into the plugin's update loop * Registers a style that is put into the plugin's update loop
@ -59,9 +60,9 @@ public class ParticleStyleManager {
/** /**
* Gets all registered styles * Gets all registered styles
* *
* @return An ArrayList of all registered styles * @return A List<ParticleStyle> of all registered styles
*/ */
public static ArrayList<ParticleStyle> getStyles() { public static List<ParticleStyle> getStyles() {
return styles; return styles;
} }

View file

@ -14,7 +14,7 @@
# I don't recommend changing it # I don't recommend changing it
# NOTE: Updating to a new version of the plugin will change this number and delete your config. # NOTE: Updating to a new version of the plugin will change this number and delete your config.
# Make sure you create a backup each time before you update! # Make sure you create a backup each time before you update!
version: 5.2 version: 5.3
# Check for new versions of the plugin # Check for new versions of the plugin
# Default: true # Default: true
@ -206,11 +206,11 @@ message-disabled-worlds: '&eParticles are disabled in these worlds:&b'
message-executed-for-player: '&aCommand executed for &b{TYPE}' message-executed-for-player: '&aCommand executed for &b{TYPE}'
# Failed Execute Not Found # Failed Execute Not Found
# Default: '&cFailed to execute for &b{TYPE}&c! Player not found!' # Default: '&cFailed to execute command for &b{TYPE}&c! Player not found!'
message-failed-execute-not-found: '&cFailed to execute command for &b{TYPE}&c! Player not found!' message-failed-execute-not-found: '&cFailed to execute command for &b{TYPE}&c! Player not found!'
# Failed Execute No Permission # Failed Execute No Permission
# Default: '&cFailed to execute for &b{TYPE}&c! You do not have permission!' # Default: '&cFailed to execute command for &b{TYPE}&c! You do not have permission!'
message-failed-execute-no-permission: '&cFailed to execute command for &b{TYPE}&c! You do not have permission!' message-failed-execute-no-permission: '&cFailed to execute command for &b{TYPE}&c! You do not have permission!'
# ----------------- # # ----------------- #

View file

@ -1,6 +1,6 @@
name: PlayerParticles name: PlayerParticles
main: com.esophose.playerparticles.PlayerParticles main: com.esophose.playerparticles.PlayerParticles
version: 5.2 version: 5.3
api-version: 1.13 api-version: 1.13
description: Make particles around players in fancy ways. description: Make particles around players in fancy ways.
author: Esophose author: Esophose