Most 1.14 support, code cleanup

This commit is contained in:
Esophose 2019-04-28 00:17:08 -06:00
parent b2459eb8d0
commit 43daf65386
60 changed files with 1763 additions and 1639 deletions

2
.gitignore vendored
View file

@ -39,6 +39,8 @@ Icon
/doc /doc
/target /target
/images /images
/build
/.idea
# Files that might appear on external disk # Files that might appear on external disk
.Spotlight-V100 .Spotlight-V100

27
PlayerParticles.iml Normal file
View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="ExternalSystem" linkedProjectPath="$MODULE_DIR$/../UltimateTimber" rootProjectPath="$MODULE_DIR$/../UltimateTimber" />
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-nop:1.7.25" level="project" />
<orderEntry type="library" name="Maven: com.zaxxer:HikariCP:3.2.0" level="project" />
<orderEntry type="library" name="Maven: org.xerial:sqlite-jdbc:3.23.1" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" name="Maven: org.spigotmc:spigot-api:1.14-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:21.0" level="project" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
<orderEntry type="library" name="Maven: net.md-5:bungeecord-chat:1.13-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.23" level="project" />
</component>
</module>

View file

@ -1,9 +1,12 @@
== UPDATING WILL DELETE YOUR CONFIG.YML == == UPDATING WILL DELETE YOUR CONFIG.YML ==
* Create a backup of your config.yml if you wish to import all your old settings! * Create a backup of your config.yml if you wish to import all your old settings!
=== v6.4 (In progress) === === v6.4 (In progress) ===
+ Added support for Minecraft 1.14
+ Added effects: '', '', '', '', '', ''
+ Added setting 'gui-close-after-group-selected' to the config.yml + Added setting 'gui-close-after-group-selected' to the config.yml
+ Added setting 'gui-presets-only' to the config.yml + Added setting 'gui-presets-only' to the config.yml
+ Added Vietnamese translation file (vi_VN.lang) + Added Vietnamese translation file (vi_VN.lang)
* Fixed '/pp add' item data parameter being ignored
=== v6.3 === === v6.3 ===
+ Added the ability to remove particles by id/effect/style using '/pp remove <id>|<effect>|<style>' + Added the ability to remove particles by id/effect/style using '/pp remove <id>|<effect>|<style>'
+ Added new styles 'popper', 'pulse', 'twins', 'whirl', and 'whirlwind' + Added new styles 'popper', 'pulse', 'twins', 'whirl', and 'whirlwind'

122
pom.xml
View file

@ -5,7 +5,7 @@
<version>6.4</version> <version>6.4</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 and blocks using customized styles and data!</description>
<build> <build>
<sourceDirectory>src</sourceDirectory> <sourceDirectory>src</sourceDirectory>
<resources> <resources>
@ -31,7 +31,7 @@
<version>3.1.0</version> <version>3.1.0</version>
<executions> <executions>
<execution> <execution>
<id>1.13</id> <id>shaded</id>
<phase>package</phase> <phase>package</phase>
<goals> <goals>
<goal>shade</goal> <goal>shade</goal>
@ -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>com.googlecode.json-simple:json-simple</include>
</includes> </includes>
</artifactSet> </artifactSet>
<filters> <filters>
@ -54,115 +55,7 @@
</excludes> </excludes>
</filter> </filter>
</filters> </filters>
<outputFile>C:\Users\Esophose\Desktop\Spigot Dev Servers\1.13\plugins\update\PlayerParticles v${project.version}.jar</outputFile> <outputFile>./target/PlayerParticles_v${project.version}.jar</outputFile>
</configuration>
</execution>
<execution>
<id>1.12</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>com.zaxxer:HikariCP</include>
<include>org.slf4j:slf4j-api</include>
<include>org.slf4j:slf4j-nop</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<outputFile>C:\Users\Esophose\Desktop\Spigot Dev Servers\1.12\plugins\update\PlayerParticles v${project.version}.jar</outputFile>
</configuration>
</execution>
<execution>
<id>1.11</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>com.zaxxer:HikariCP</include>
<include>org.slf4j:slf4j-api</include>
<include>org.slf4j:slf4j-nop</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<outputFile>C:\Users\Esophose\Desktop\Spigot Dev Servers\1.11\plugins\update\PlayerParticles v${project.version}.jar</outputFile>
</configuration>
</execution>
<execution>
<id>1.10</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>com.zaxxer:HikariCP</include>
<include>org.slf4j:slf4j-api</include>
<include>org.slf4j:slf4j-nop</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<outputFile>C:\Users\Esophose\Desktop\Spigot Dev Servers\1.10\plugins\update\PlayerParticles v${project.version}.jar</outputFile>
</configuration>
</execution>
<execution>
<id>1.9</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>com.zaxxer:HikariCP</include>
<include>org.slf4j:slf4j-api</include>
<include>org.slf4j:slf4j-nop</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<outputFile>C:\Users\Esophose\Desktop\Spigot Dev Servers\1.9\plugins\update\PlayerParticles v${project.version}.jar</outputFile>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
@ -200,10 +93,15 @@
<artifactId>sqlite-jdbc</artifactId> <artifactId>sqlite-jdbc</artifactId>
<version>3.23.1</version> <version>3.23.1</version>
</dependency> </dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version> <version>1.14-R0.1-SNAPSHOT</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View file

@ -38,6 +38,7 @@ import com.esophose.playerparticles.manager.SettingManager;
import com.esophose.playerparticles.manager.SettingManager.PSetting; import com.esophose.playerparticles.manager.SettingManager.PSetting;
import com.esophose.playerparticles.particles.PPlayerMovementListener; import com.esophose.playerparticles.particles.PPlayerMovementListener;
import com.esophose.playerparticles.styles.DefaultStyles; import com.esophose.playerparticles.styles.DefaultStyles;
import com.esophose.playerparticles.updater.DataUpdater;
import com.esophose.playerparticles.updater.PluginUpdateListener; import com.esophose.playerparticles.updater.PluginUpdateListener;
import com.esophose.playerparticles.updater.Updater; import com.esophose.playerparticles.updater.Updater;
import com.esophose.playerparticles.util.Metrics; import com.esophose.playerparticles.util.Metrics;
@ -69,7 +70,7 @@ public class PlayerParticles extends JavaPlugin {
* Executes essential tasks for starting up the plugin * Executes essential tasks for starting up the plugin
*/ */
public void onEnable() { public void onEnable() {
pluginInstance = (PlayerParticles)Bukkit.getServer().getPluginManager().getPlugin("PlayerParticles"); pluginInstance = (PlayerParticles) Bukkit.getServer().getPluginManager().getPlugin("PlayerParticles");
this.registerCommands(); this.registerCommands();
@ -80,23 +81,23 @@ public class PlayerParticles extends JavaPlugin {
pm.registerEvents(new PPlayerMovementListener(), this); pm.registerEvents(new PPlayerMovementListener(), this);
pm.registerEvents(new PlayerChatHook(), this); pm.registerEvents(new PlayerChatHook(), this);
saveDefaultConfig(); this.saveDefaultConfig();
double configVersion = PSetting.VERSION.getDouble(); double configVersion = PSetting.VERSION.getDouble();
double currentVersion = Double.parseDouble(getDescription().getVersion()); double currentVersion = Double.parseDouble(this.getDescription().getVersion());
boolean updatePluginSettings = configVersion < currentVersion; boolean updatePluginSettings = configVersion < currentVersion;
if (updatePluginSettings) { if (updatePluginSettings) {
configureDatabase(PSetting.DATABASE_ENABLE.getBoolean()); this.configureDatabase(PSetting.DATABASE_ENABLE.getBoolean());
DataUpdater.updateData(configVersion, currentVersion); DataUpdater.updateData(configVersion, currentVersion);
databaseConnector.closeConnection(); this.databaseConnector.closeConnection();
databaseConnector = null; this.databaseConnector = null;
File configFile = new File(getDataFolder(), "config.yml"); File configFile = new File(this.getDataFolder(), "config.yml");
if (configFile.exists()) { if (configFile.exists()) {
configFile.delete(); configFile.delete();
} }
saveDefaultConfig(); this.saveDefaultConfig();
reloadConfig(); this.reloadConfig();
getLogger().warning("The config.yml has been updated to v" + getDescription().getVersion() + "!"); this.getLogger().warning("The config.yml has been updated to v" + this.getDescription().getVersion() + "!");
} }
if (PSetting.CHECK_UPDATES.getBoolean()) { if (PSetting.CHECK_UPDATES.getBoolean()) {
@ -127,7 +128,7 @@ public class PlayerParticles extends JavaPlugin {
* Close all users with an open PlayerParticles GUI * Close all users with an open PlayerParticles GUI
*/ */
public void onDisable() { public void onDisable() {
databaseConnector.closeConnection(); this.databaseConnector.closeConnection();
GuiHandler.forceCloseAllOpenGUIs(); GuiHandler.forceCloseAllOpenGUIs();
} }
@ -154,18 +155,18 @@ public class PlayerParticles extends JavaPlugin {
this.reloadConfig(); this.reloadConfig();
// If not null, plugin is already loaded // If not null, plugin is already loaded
if (particleTask != null) { if (this.particleTask != null) {
particleTask.cancel(); this.particleTask.cancel();
particleTask = null; this.particleTask = null;
databaseConnector.closeConnection(); this.databaseConnector.closeConnection();
databaseConnector = null; this.databaseConnector = null;
GuiHandler.forceCloseAllOpenGUIs(); GuiHandler.forceCloseAllOpenGUIs();
} else { } else {
DefaultStyles.registerStyles(); // Only ever load styles once DefaultStyles.registerStyles(); // Only ever load styles once
} }
// This runs before the SettingManager is reloaded, the credentials will not be stored in memory for more than a few milliseconds // This runs before the SettingManager is reloaded, the credentials will not be stored in memory for more than a few milliseconds
configureDatabase(PSetting.DATABASE_ENABLE.getBoolean()); this.configureDatabase(PSetting.DATABASE_ENABLE.getBoolean());
DataUpdater.tryCreateTables(); DataUpdater.tryCreateTables();
SettingManager.reload(); SettingManager.reload();
@ -176,7 +177,7 @@ public class PlayerParticles extends JavaPlugin {
PlayerChatHook.setup(); PlayerChatHook.setup();
ParticleManager.refreshData(); ParticleManager.refreshData();
startParticleTask(); this.startParticleTask();
} }
/** /**
@ -194,7 +195,7 @@ public class PlayerParticles extends JavaPlugin {
* @return The DatabaseConnector * @return The DatabaseConnector
*/ */
public DatabaseConnector getDBConnector() { public DatabaseConnector getDBConnector() {
return databaseConnector; return this.databaseConnector;
} }
/** /**
@ -214,20 +215,19 @@ public class PlayerParticles extends JavaPlugin {
*/ */
private void configureDatabase(boolean useMySql) { private void configureDatabase(boolean useMySql) {
if (useMySql) { if (useMySql) {
databaseConnector = new MySqlDatabaseConnector(); this.databaseConnector = new MySqlDatabaseConnector();
} else { } else {
try { try {
Class.forName("org.sqlite.JDBC"); // This is required to put here for Spigot 1.9 and 1.10 for some reason Class.forName("org.sqlite.JDBC"); // This is required to put here for Spigot 1.9 and 1.10 for some reason
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
databaseConnector = new SqliteDatabaseConnector(this.getDataFolder().getAbsolutePath()); this.databaseConnector = new SqliteDatabaseConnector(this.getDataFolder().getAbsolutePath());
} }
if (!databaseConnector.isInitialized()) { if (!this.databaseConnector.isInitialized()) {
getLogger().severe("Unable to connect to the MySQL database! Is your login information correct? Falling back to SQLite database instead."); this.getLogger().severe("Unable to connect to the MySQL database! Is your login information correct? Falling back to SQLite database instead.");
configureDatabase(false); this.configureDatabase(false);
return;
} }
} }
@ -236,13 +236,10 @@ public class PlayerParticles extends JavaPlugin {
* 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() {
final Plugin playerParticles = this; Bukkit.getScheduler().runTaskLater(pluginInstance, () -> {
new BukkitRunnable() {
public void run() {
long ticks = PSetting.TICKS_PER_PARTICLE.getLong(); long ticks = PSetting.TICKS_PER_PARTICLE.getLong();
particleTask = new ParticleManager().runTaskTimer(playerParticles, 5, ticks); this.particleTask = new ParticleManager().runTaskTimer(pluginInstance, 5, ticks);
} }, 1);
}.runTaskLater(playerParticles, 1);
} }
} }

View file

@ -67,7 +67,7 @@ public class AddCommandModule implements CommandModule {
} else if (args[2].equalsIgnoreCase("random")) { } else if (args[2].equalsIgnoreCase("random")) {
noteColorData = new NoteColor(98); noteColorData = new NoteColor(98);
} else { } else {
int note = -1; int note;
try { try {
note = Integer.parseInt(args[2]); note = Integer.parseInt(args[2]);
} catch (Exception e) { } catch (Exception e) {
@ -88,9 +88,7 @@ public class AddCommandModule implements CommandModule {
} else if (args[2].equalsIgnoreCase("random")) { } else if (args[2].equalsIgnoreCase("random")) {
colorData = new OrdinaryColor(998, 998, 998); colorData = new OrdinaryColor(998, 998, 998);
} else { } else {
int r = -1; int r, g, b;
int g = -1;
int b = -1;
try { try {
r = Integer.parseInt(args[2]); r = Integer.parseInt(args[2]);
@ -131,7 +129,7 @@ public class AddCommandModule implements CommandModule {
} }
ParticleGroup group = pplayer.getActiveParticleGroup(); ParticleGroup group = pplayer.getActiveParticleGroup();
ParticlePair newParticle = new ParticlePair(pplayer.getUniqueId(), pplayer.getNextActiveParticleId(), effect, style, blockData, blockData, colorData, noteColorData); ParticlePair newParticle = new ParticlePair(pplayer.getUniqueId(), pplayer.getNextActiveParticleId(), effect, style, itemData, blockData, colorData, noteColorData);
group.getParticles().add(newParticle); group.getParticles().add(newParticle);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group); DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
@ -144,18 +142,18 @@ public class AddCommandModule implements CommandModule {
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
Player p = pplayer.getPlayer(); Player p = pplayer.getPlayer();
List<String> matches = new ArrayList<String>(); List<String> matches = new ArrayList<>();
if (args.length <= 1) { // Effect name if (args.length <= 1) { // Effect name
if (args.length == 0) matches = PermissionManager.getEffectNamesUserHasPermissionFor(p); if (args.length == 0) matches = PermissionManager.getEffectNamesUserHasPermissionFor(p);
else StringUtil.copyPartialMatches(args[0], PermissionManager.getEffectNamesUserHasPermissionFor(p), matches); else StringUtil.copyPartialMatches(args[0], PermissionManager.getEffectNamesUserHasPermissionFor(p), matches);
} else if (args.length == 2) { // Style name } else if (args.length == 2) { // Style name
StringUtil.copyPartialMatches(args[1], PermissionManager.getStyleNamesUserHasPermissionFor(p), matches); StringUtil.copyPartialMatches(args[1], PermissionManager.getStyleNamesUserHasPermissionFor(p), matches);
} else if (args.length >= 3) { // Data } else { // Data
ParticleEffect effect = ParticleEffect.fromName(args[0]); ParticleEffect effect = ParticleEffect.fromName(args[0]);
if (effect != null) { if (effect != null) {
if (effect.hasProperty(ParticleProperty.COLORABLE)) { if (effect.hasProperty(ParticleProperty.COLORABLE)) {
List<String> possibleValues = new ArrayList<String>(); List<String> possibleValues = new ArrayList<>();
if (effect == ParticleEffect.NOTE) { // Note data if (effect == ParticleEffect.NOTE) { // Note data
if (args.length == 3) { if (args.length == 3) {
possibleValues.add("<0-24>"); possibleValues.add("<0-24>");
@ -178,9 +176,9 @@ public class AddCommandModule implements CommandModule {
StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches); StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches);
} else if (args.length == 3 && effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) { } else if (args.length == 3 && effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) { // Block material if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) { // Block material
matches = StringUtil.copyPartialMatches(args[2], ParticleUtils.getAllBlockMaterials(), matches); StringUtil.copyPartialMatches(args[2], ParticleUtils.getAllBlockMaterials(), matches);
} else if (effect == ParticleEffect.ITEM) { // Item material } else if (effect == ParticleEffect.ITEM) { // Item material
matches = StringUtil.copyPartialMatches(args[2], ParticleUtils.getAllItemMaterials(), matches); StringUtil.copyPartialMatches(args[2], ParticleUtils.getAllItemMaterials(), matches);
} }
} }
} }

View file

@ -14,7 +14,7 @@ public interface CommandModule {
* @param pplayer The PPlayer who executed this command * @param pplayer The PPlayer who executed this command
* @param args The arguments to this command * @param args The arguments to this command
*/ */
public void onCommandExecute(PPlayer pplayer, String[] args); void onCommandExecute(PPlayer pplayer, String[] args);
/** /**
* Called when a player tries to tab complete this command * Called when a player tries to tab complete this command
@ -23,35 +23,35 @@ public interface CommandModule {
* @param args Arguments typed so far * @param args Arguments typed so far
* @return A list of possible argument values * @return A list of possible argument values
*/ */
public List<String> onTabComplete(PPlayer pplayer, String[] args); List<String> onTabComplete(PPlayer pplayer, String[] args);
/** /**
* Gets the name of this command * Gets the name of this command
* *
* @return The name of this command * @return The name of this command
*/ */
public String getName(); String getName();
/** /**
* Gets the Lang description of this command * Gets the Lang description of this command
* *
* @return The description of this command * @return The description of this command
*/ */
public Lang getDescription(); Lang getDescription();
/** /**
* Gets any arguments this command has * Gets any arguments this command has
* *
* @return The arguments this command has * @return The arguments this command has
*/ */
public String getArguments(); String getArguments();
/** /**
* True if this command requires the player to have any effects * True if this command requires the player to have any effects
* *
* @return If the player must have effects to use this command * @return If the player must have effects to use this command
*/ */
public boolean requiresEffects(); boolean requiresEffects();
/** /**
* Displays a command's usage to the player * Displays a command's usage to the player
@ -59,7 +59,7 @@ public interface CommandModule {
* @param pplayer The PPlayer to display the command usage to * @param pplayer The PPlayer to display the command usage to
* @param command The command to display usage for * @param command The command to display usage for
*/ */
public static void printUsage(PPlayer pplayer, CommandModule command) { static void printUsage(PPlayer pplayer, CommandModule command) {
LangManager.sendMessage(pplayer, Lang.COMMAND_DESCRIPTIONS_USAGE, command.getName(), command.getArguments()); LangManager.sendMessage(pplayer, Lang.COMMAND_DESCRIPTIONS_USAGE, command.getName(), command.getArguments());
} }
@ -69,7 +69,7 @@ public interface CommandModule {
* @param pplayer The PPlayer to display the command usage to * @param pplayer The PPlayer to display the command usage to
* @param command The command to display usage for * @param command The command to display usage for
*/ */
public static void printUsageWithDescription(PPlayer pplayer, CommandModule command) { static void printUsageWithDescription(PPlayer pplayer, CommandModule command) {
if (command.getArguments().length() == 0) { if (command.getArguments().length() == 0) {
LangManager.sendSimpleMessage(pplayer, Lang.COMMAND_DESCRIPTIONS_HELP_1, command.getName(), LangManager.getText(command.getDescription())); LangManager.sendSimpleMessage(pplayer, Lang.COMMAND_DESCRIPTIONS_HELP_1, command.getName(), LangManager.getText(command.getDescription()));
} else { } else {

View file

@ -12,7 +12,7 @@ public interface CommandModuleSecondary {
* @param sender The CommandSender who executed this command * @param sender The CommandSender who executed this command
* @param args The arguments to this command * @param args The arguments to this command
*/ */
public void onCommandExecute(CommandSender sender, String[] args); void onCommandExecute(CommandSender sender, String[] args);
/** /**
* Called when a player tries to tab complete this command * Called when a player tries to tab complete this command
@ -21,6 +21,6 @@ public interface CommandModuleSecondary {
* @param args Arguments typed so far * @param args Arguments typed so far
* @return A list of possible argument values * @return A list of possible argument values
*/ */
public List<String> onTabComplete(CommandSender sender, String[] args); List<String> onTabComplete(CommandSender sender, String[] args);
} }

View file

@ -43,7 +43,7 @@ public class DataCommandModule implements CommandModule {
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
List<String> matches = new ArrayList<String>(); List<String> matches = new ArrayList<>();
if (args.length <= 1) { if (args.length <= 1) {
if (args.length == 0) matches = PermissionManager.getEffectNamesUserHasPermissionFor(pplayer.getPlayer()); if (args.length == 0) matches = PermissionManager.getEffectNamesUserHasPermissionFor(pplayer.getPlayer());
else StringUtil.copyPartialMatches(args[0], PermissionManager.getEffectNamesUserHasPermissionFor(pplayer.getPlayer()), matches); else StringUtil.copyPartialMatches(args[0], PermissionManager.getEffectNamesUserHasPermissionFor(pplayer.getPlayer()), matches);

View file

@ -29,7 +29,7 @@ public class EditCommandModule implements CommandModule {
return; return;
} }
int id = -1; int id;
try { try {
id = Integer.parseInt(args[0]); id = Integer.parseInt(args[0]);
} catch (Exception e) { } catch (Exception e) {
@ -48,19 +48,17 @@ public class EditCommandModule implements CommandModule {
} }
String[] cmdArgs = new String[args.length - 2]; String[] cmdArgs = new String[args.length - 2];
for (int i = 2; i < args.length; i++) { System.arraycopy(args, 2, cmdArgs, 0, args.length - 2);
cmdArgs[i - 2] = args[i];
}
switch (args[1].toLowerCase()) { switch (args[1].toLowerCase()) {
case "effect": case "effect":
editEffect(pplayer, id, cmdArgs); this.editEffect(pplayer, id, cmdArgs);
break; break;
case "style": case "style":
editStyle(pplayer, id, cmdArgs); this.editStyle(pplayer, id, cmdArgs);
break; break;
case "data": case "data":
editData(pplayer, id, cmdArgs); this.editData(pplayer, id, cmdArgs);
break; break;
default: default:
LangManager.sendMessage(pplayer, Lang.EDIT_INVALID_PROPERTY, args[1]); LangManager.sendMessage(pplayer, Lang.EDIT_INVALID_PROPERTY, args[1]);
@ -148,7 +146,7 @@ public class EditCommandModule implements CommandModule {
} else if (args[0].equalsIgnoreCase("random")) { } else if (args[0].equalsIgnoreCase("random")) {
noteColorData = new NoteColor(98); noteColorData = new NoteColor(98);
} else { } else {
int note = -1; int note;
try { try {
note = Integer.parseInt(args[0]); note = Integer.parseInt(args[0]);
} catch (Exception e) { } catch (Exception e) {
@ -169,9 +167,7 @@ public class EditCommandModule implements CommandModule {
} else if (args[0].equalsIgnoreCase("random")) { } else if (args[0].equalsIgnoreCase("random")) {
colorData = new OrdinaryColor(998, 998, 998); colorData = new OrdinaryColor(998, 998, 998);
} else { } else {
int r = -1; int r, g, b;
int g = -1;
int b = -1;
try { try {
r = Integer.parseInt(args[0]); r = Integer.parseInt(args[0]);
@ -229,8 +225,8 @@ public class EditCommandModule implements CommandModule {
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
Player p = pplayer.getPlayer(); Player p = pplayer.getPlayer();
List<String> matches = new ArrayList<String>(); List<String> matches = new ArrayList<>();
List<String> ids = new ArrayList<String>(); List<String> ids = new ArrayList<>();
for (ParticlePair particles : pplayer.getActiveParticles()) for (ParticlePair particles : pplayer.getActiveParticles())
ids.add(String.valueOf(particles.getId())); ids.add(String.valueOf(particles.getId()));
@ -244,11 +240,11 @@ public class EditCommandModule implements CommandModule {
int id = -1; int id = -1;
try { try {
id = Integer.parseInt(args[0]); id = Integer.parseInt(args[0]);
} catch (Exception e) { } } catch (Exception ignored) { }
if (pplayer.getActiveParticle(id) != null) { if (pplayer.getActiveParticle(id) != null) {
if (args.length == 2) { if (args.length == 2) {
List<String> possibleValues = new ArrayList<String>(); List<String> possibleValues = new ArrayList<>();
possibleValues.add("effect"); possibleValues.add("effect");
possibleValues.add("style"); possibleValues.add("style");
possibleValues.add("data"); possibleValues.add("data");
@ -266,7 +262,7 @@ public class EditCommandModule implements CommandModule {
case "data": case "data":
ParticleEffect effect = pplayer.getActiveParticle(id).getEffect(); ParticleEffect effect = pplayer.getActiveParticle(id).getEffect();
if (effect.hasProperty(ParticleProperty.COLORABLE)) { if (effect.hasProperty(ParticleProperty.COLORABLE)) {
List<String> possibleValues = new ArrayList<String>(); List<String> possibleValues = new ArrayList<>();
if (effect == ParticleEffect.NOTE) { // Note data if (effect == ParticleEffect.NOTE) { // Note data
if (args.length == 3) { if (args.length == 3) {
possibleValues.add("<0-24>"); possibleValues.add("<0-24>");
@ -289,9 +285,9 @@ public class EditCommandModule implements CommandModule {
StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches); StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches);
} else if (args.length == 3 && effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) { } else if (args.length == 3 && effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) { // Block material if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) { // Block material
matches = StringUtil.copyPartialMatches(args[2], ParticleUtils.getAllBlockMaterials(), matches); StringUtil.copyPartialMatches(args[2], ParticleUtils.getAllBlockMaterials(), matches);
} else if (effect == ParticleEffect.ITEM) { // Item material } else if (effect == ParticleEffect.ITEM) { // Item material
matches = StringUtil.copyPartialMatches(args[2], ParticleUtils.getAllItemMaterials(), matches); StringUtil.copyPartialMatches(args[2], ParticleUtils.getAllItemMaterials(), matches);
} }
} }
break; break;

View file

@ -21,20 +21,20 @@ public class EffectsCommandModule implements CommandModule {
return; return;
} }
String toSend = ""; StringBuilder toSend = new StringBuilder();
for (String name : effectList) { for (String name : effectList) {
toSend += name + ", "; toSend.append(name).append(", ");
} }
if (toSend.endsWith(", ")) { if (toSend.toString().endsWith(", ")) {
toSend = toSend.substring(0, toSend.length() - 2); toSend = new StringBuilder(toSend.substring(0, toSend.length() - 2));
} }
LangManager.sendMessage(pplayer, Lang.EFFECT_LIST, toSend); LangManager.sendMessage(pplayer, Lang.EFFECT_LIST, toSend.toString());
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return new ArrayList<String>(); return new ArrayList<>();
} }
public String getName() { public String getName() {

View file

@ -52,28 +52,26 @@ public class FixedCommandModule implements CommandModule {
String cmd = args[0]; String cmd = args[0];
String[] cmdArgs = new String[args.length - 1]; String[] cmdArgs = new String[args.length - 1];
for (int i = 1; i < args.length; i++) { System.arraycopy(args, 1, cmdArgs, 0, args.length - 1);
cmdArgs[i - 1] = args[i];
}
switch (cmd.toLowerCase()) { switch (cmd.toLowerCase()) {
case "create": case "create":
handleCreate(pplayer, p, cmdArgs); this.handleCreate(pplayer, p, cmdArgs);
return; return;
case "edit": case "edit":
handleEdit(pplayer, p, cmdArgs); this.handleEdit(pplayer, p, cmdArgs);
return; return;
case "remove": case "remove":
handleRemove(pplayer, p, cmdArgs); this.handleRemove(pplayer, p, cmdArgs);
return; return;
case "list": case "list":
handleList(pplayer, p, cmdArgs); this.handleList(pplayer, p, cmdArgs);
return; return;
case "info": case "info":
handleInfo(pplayer, p, cmdArgs); this.handleInfo(pplayer, p, cmdArgs);
return; return;
case "clear": case "clear":
handleClear(pplayer, p, cmdArgs); this.handleClear(pplayer, p, cmdArgs);
return; return;
default: default:
LangManager.sendMessage(pplayer, Lang.FIXED_INVALID_COMMAND); LangManager.sendMessage(pplayer, Lang.FIXED_INVALID_COMMAND);
@ -105,10 +103,10 @@ public class FixedCommandModule implements CommandModule {
return; return;
} }
double xPos = -1, yPos = -1, zPos = -1; double xPos, yPos, zPos;
if (args[0].equalsIgnoreCase("looking")) { if (args[0].equalsIgnoreCase("looking")) {
Block targetBlock = p.getTargetBlock((Set<Material>)null, 8); Block targetBlock = p.getTargetBlock(null, 8);
int maxDistanceSqrd = 6 * 6; int maxDistanceSqrd = 6 * 6;
if (targetBlock.getLocation().distanceSquared(p.getLocation()) > maxDistanceSqrd) { if (targetBlock.getLocation().distanceSquared(p.getLocation()) > maxDistanceSqrd) {
LangManager.sendMessage(pplayer, Lang.FIXED_CREATE_LOOKING_TOO_FAR); LangManager.sendMessage(pplayer, Lang.FIXED_CREATE_LOOKING_TOO_FAR);
@ -126,8 +124,7 @@ public class FixedCommandModule implements CommandModule {
paddedArgs[0] = String.valueOf(xPos); paddedArgs[0] = String.valueOf(xPos);
paddedArgs[1] = String.valueOf(yPos); paddedArgs[1] = String.valueOf(yPos);
paddedArgs[2] = String.valueOf(zPos); paddedArgs[2] = String.valueOf(zPos);
for (int i = 1; i < args.length; i++) System.arraycopy(args, 1, paddedArgs, 3, args.length - 1);
paddedArgs[i + 2] = args[i];
args = paddedArgs; args = paddedArgs;
} else { } else {
try { try {
@ -200,7 +197,7 @@ public class FixedCommandModule implements CommandModule {
} else if (args[5].equalsIgnoreCase("random")) { } else if (args[5].equalsIgnoreCase("random")) {
noteColorData = new NoteColor(98); noteColorData = new NoteColor(98);
} else { } else {
int note = -1; int note;
try { try {
note = Integer.parseInt(args[5]); note = Integer.parseInt(args[5]);
} catch (Exception e) { } catch (Exception e) {
@ -221,9 +218,7 @@ public class FixedCommandModule implements CommandModule {
} else if (args[5].equalsIgnoreCase("random")) { } else if (args[5].equalsIgnoreCase("random")) {
colorData = new OrdinaryColor(998, 998, 998); colorData = new OrdinaryColor(998, 998, 998);
} else { } else {
int r = -1; int r, g, b;
int g = -1;
int b = -1;
try { try {
r = Integer.parseInt(args[5]); r = Integer.parseInt(args[5]);
@ -244,7 +239,7 @@ public class FixedCommandModule implements CommandModule {
} }
} else if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) { } else if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) { if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) {
Material material = null; Material material;
try { try {
material = ParticleUtils.closestMatch(args[5]); material = ParticleUtils.closestMatch(args[5]);
if (material == null) material = Material.matchMaterial(args[5]); if (material == null) material = Material.matchMaterial(args[5]);
@ -256,7 +251,7 @@ public class FixedCommandModule implements CommandModule {
blockData = material; blockData = material;
} else if (effect == ParticleEffect.ITEM) { } else if (effect == ParticleEffect.ITEM) {
Material material = null; Material material;
try { try {
material = ParticleUtils.closestMatch(args[5]); material = ParticleUtils.closestMatch(args[5]);
if (material == null) material = Material.matchMaterial(args[5]); if (material == null) material = Material.matchMaterial(args[5]);
@ -292,7 +287,7 @@ public class FixedCommandModule implements CommandModule {
return; return;
} }
int id = -1; int id;
try { try {
id = Integer.parseInt(args[0]); id = Integer.parseInt(args[0]);
} catch (Exception ex) { } catch (Exception ex) {
@ -307,11 +302,12 @@ public class FixedCommandModule implements CommandModule {
} }
String editType = args[1].toLowerCase(); String editType = args[1].toLowerCase();
if (editType.equals("location")) { switch (editType) {
double xPos = -1, yPos = -1, zPos = -1; case "location":
double xPos, yPos, zPos;
if (args[2].equalsIgnoreCase("looking")) { if (args[2].equalsIgnoreCase("looking")) {
Block targetBlock = p.getTargetBlock((Set<Material>)null, 8); Block targetBlock = p.getTargetBlock(null, 8);
int maxDistanceSqrd = 6 * 6; int maxDistanceSqrd = 6 * 6;
if (targetBlock.getLocation().distanceSquared(p.getLocation()) > maxDistanceSqrd) { if (targetBlock.getLocation().distanceSquared(p.getLocation()) > maxDistanceSqrd) {
LangManager.sendMessage(pplayer, Lang.FIXED_EDIT_LOOKING_TOO_FAR); LangManager.sendMessage(pplayer, Lang.FIXED_EDIT_LOOKING_TOO_FAR);
@ -359,7 +355,8 @@ public class FixedCommandModule implements CommandModule {
} }
fixedEffect.setCoordinates(xPos, yPos, zPos); fixedEffect.setCoordinates(xPos, yPos, zPos);
} else if (editType.equals("effect")) { break;
case "effect": {
ParticleEffect effect = ParticleEffect.fromName(args[2]); ParticleEffect effect = ParticleEffect.fromName(args[2]);
if (effect == null) { if (effect == null) {
LangManager.sendMessage(pplayer, Lang.FIXED_EDIT_EFFECT_INVALID, args[2]); LangManager.sendMessage(pplayer, Lang.FIXED_EDIT_EFFECT_INVALID, args[2]);
@ -370,7 +367,9 @@ public class FixedCommandModule implements CommandModule {
} }
fixedEffect.getParticlePair().setEffect(effect); fixedEffect.getParticlePair().setEffect(effect);
} else if (editType.equals("style")) { break;
}
case "style":
ParticleStyle style = ParticleStyle.fromName(args[2]); ParticleStyle style = ParticleStyle.fromName(args[2]);
if (style == null) { if (style == null) {
LangManager.sendMessage(pplayer, Lang.FIXED_EDIT_STYLE_INVALID, args[2]); LangManager.sendMessage(pplayer, Lang.FIXED_EDIT_STYLE_INVALID, args[2]);
@ -384,7 +383,8 @@ public class FixedCommandModule implements CommandModule {
} }
fixedEffect.getParticlePair().setStyle(style); fixedEffect.getParticlePair().setStyle(style);
} else if (editType.equals("data")) { break;
case "data": {
Material itemData = null; Material itemData = null;
Material blockData = null; Material blockData = null;
OrdinaryColor colorData = null; OrdinaryColor colorData = null;
@ -398,7 +398,7 @@ public class FixedCommandModule implements CommandModule {
} else if (args[2].equalsIgnoreCase("random")) { } else if (args[2].equalsIgnoreCase("random")) {
noteColorData = new NoteColor(98); noteColorData = new NoteColor(98);
} else { } else {
int note = -1; int note;
try { try {
note = Integer.parseInt(args[2]); note = Integer.parseInt(args[2]);
} catch (Exception e) { } catch (Exception e) {
@ -419,9 +419,7 @@ public class FixedCommandModule implements CommandModule {
} else if (args[2].equalsIgnoreCase("random")) { } else if (args[2].equalsIgnoreCase("random")) {
colorData = new OrdinaryColor(998, 998, 998); colorData = new OrdinaryColor(998, 998, 998);
} else { } else {
int r = -1; int r, g, b;
int g = -1;
int b = -1;
try { try {
r = Integer.parseInt(args[2]); r = Integer.parseInt(args[2]);
@ -442,7 +440,7 @@ public class FixedCommandModule implements CommandModule {
} }
} else if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) { } else if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) { if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) {
Material material = null; Material material;
try { try {
material = ParticleUtils.closestMatch(args[2]); material = ParticleUtils.closestMatch(args[2]);
if (material == null) material = Material.matchMaterial(args[2]); if (material == null) material = Material.matchMaterial(args[2]);
@ -454,7 +452,7 @@ public class FixedCommandModule implements CommandModule {
blockData = material; blockData = material;
} else if (effect == ParticleEffect.ITEM) { } else if (effect == ParticleEffect.ITEM) {
Material material = null; Material material;
try { try {
material = ParticleUtils.closestMatch(args[2]); material = ParticleUtils.closestMatch(args[2]);
if (material == null) material = Material.matchMaterial(args[2]); if (material == null) material = Material.matchMaterial(args[2]);
@ -475,7 +473,9 @@ public class FixedCommandModule implements CommandModule {
fixedEffect.getParticlePair().setNoteColor(noteColorData); fixedEffect.getParticlePair().setNoteColor(noteColorData);
fixedEffect.getParticlePair().setItemMaterial(itemData); fixedEffect.getParticlePair().setItemMaterial(itemData);
fixedEffect.getParticlePair().setBlockMaterial(blockData); fixedEffect.getParticlePair().setBlockMaterial(blockData);
} else { break;
}
default:
LangManager.sendMessage(pplayer, Lang.FIXED_EDIT_INVALID_PROPERTY); LangManager.sendMessage(pplayer, Lang.FIXED_EDIT_INVALID_PROPERTY);
return; return;
} }
@ -497,7 +497,7 @@ public class FixedCommandModule implements CommandModule {
return; return;
} }
int id = -1; int id;
try { try {
id = Integer.parseInt(args[0]); id = Integer.parseInt(args[0]);
} catch (Exception e) { } catch (Exception e) {
@ -529,15 +529,15 @@ public class FixedCommandModule implements CommandModule {
return; return;
} }
String msg = ""; StringBuilder msg = new StringBuilder();
boolean first = true; boolean first = true;
for (int id : ids) { for (int id : ids) {
if (!first) msg += ", "; if (!first) msg.append(", ");
else first = false; else first = false;
msg += id; msg.append(id);
} }
LangManager.sendMessage(pplayer, Lang.FIXED_LIST_SUCCESS, msg); LangManager.sendMessage(pplayer, Lang.FIXED_LIST_SUCCESS, msg.toString());
} }
/** /**
@ -553,7 +553,7 @@ public class FixedCommandModule implements CommandModule {
return; return;
} }
int id = -1; int id;
try { try {
id = Integer.parseInt(args[0]); id = Integer.parseInt(args[0]);
} catch (Exception e) { } catch (Exception e) {
@ -570,7 +570,7 @@ public class FixedCommandModule implements CommandModule {
ParticlePair particle = fixedEffect.getParticlePair(); ParticlePair particle = fixedEffect.getParticlePair();
DecimalFormat df = new DecimalFormat("0.##"); // Decimal formatter so the coords aren't super long DecimalFormat df = new DecimalFormat("0.##"); // Decimal formatter so the coords aren't super long
LangManager.sendMessage(pplayer, // @formatter:off LangManager.sendMessage(pplayer,
Lang.FIXED_INFO_SUCCESS, Lang.FIXED_INFO_SUCCESS,
fixedEffect.getId(), fixedEffect.getId(),
fixedEffect.getLocation().getWorld().getName(), fixedEffect.getLocation().getWorld().getName(),
@ -580,7 +580,7 @@ public class FixedCommandModule implements CommandModule {
particle.getEffect().getName(), particle.getEffect().getName(),
particle.getStyle().getName(), particle.getStyle().getName(),
particle.getDataString() particle.getDataString()
); // @formatter:on );
} }
/** /**
@ -601,7 +601,7 @@ public class FixedCommandModule implements CommandModule {
return; return;
} }
int radius = -1; int radius;
try { try {
radius = Math.abs(Integer.parseInt(args[0])); radius = Math.abs(Integer.parseInt(args[0]));
} catch (Exception e) { } catch (Exception e) {
@ -609,7 +609,7 @@ public class FixedCommandModule implements CommandModule {
return; return;
} }
ArrayList<FixedParticleEffect> fixedEffectsToRemove = new ArrayList<FixedParticleEffect>(); ArrayList<FixedParticleEffect> fixedEffectsToRemove = new ArrayList<>();
for (PPlayer ppl : ParticleManager.getPPlayers()) for (PPlayer ppl : ParticleManager.getPPlayers())
for (FixedParticleEffect fixedEffect : ppl.getFixedParticles()) for (FixedParticleEffect fixedEffect : ppl.getFixedParticles())
@ -624,18 +624,17 @@ public class FixedCommandModule implements CommandModule {
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
Player p = pplayer.getPlayer(); Player p = pplayer.getPlayer();
List<String> matches = new ArrayList<String>(); List<String> matches = new ArrayList<>();
String[] subCommands = new String[] { "create", "edit", "remove", "list", "info", "clear" };
if (args.length <= 1) { if (args.length <= 1) {
List<String> possibleCmds = new ArrayList<String>(Arrays.asList(subCommands)); List<String> possibleCmds = new ArrayList<>(Arrays.asList("create", "edit", "remove", "list", "info", "clear"));
if (args.length == 0) matches = possibleCmds; if (args.length == 0) matches = possibleCmds;
else StringUtil.copyPartialMatches(args[0], possibleCmds, matches); else StringUtil.copyPartialMatches(args[0], possibleCmds, matches);
} else { } else {
switch (args[0].toLowerCase()) { switch (args[0].toLowerCase()) {
case "create": case "create":
if (args.length >= 2 && args.length <= 4) { if (args.length <= 4) {
List<String> possibleValues = new ArrayList<String>(); List<String> possibleValues = new ArrayList<>();
if (args.length == 4) { if (args.length == 4) {
possibleValues.add("~"); possibleValues.add("~");
} }
@ -650,11 +649,10 @@ public class FixedCommandModule implements CommandModule {
} }
// Pad arguments if the first coordinate is "looking" // Pad arguments if the first coordinate is "looking"
if (args.length > 1 && args[1].equalsIgnoreCase("looking")) { if (args[1].equalsIgnoreCase("looking")) {
String[] paddedArgs = new String[args.length + 2]; String[] paddedArgs = new String[args.length + 2];
paddedArgs[0] = paddedArgs[1] = paddedArgs[2] = paddedArgs[3] = ""; paddedArgs[0] = paddedArgs[1] = paddedArgs[2] = paddedArgs[3] = "";
for (int i = 2; i < args.length; i++) System.arraycopy(args, 2, paddedArgs, 4, args.length - 2);
paddedArgs[i + 2] = args[i];
args = paddedArgs; args = paddedArgs;
} }
@ -666,7 +664,7 @@ public class FixedCommandModule implements CommandModule {
ParticleEffect effect = ParticleEffect.fromName(args[4]); ParticleEffect effect = ParticleEffect.fromName(args[4]);
if (effect != null) { if (effect != null) {
if (effect.hasProperty(ParticleProperty.COLORABLE)) { if (effect.hasProperty(ParticleProperty.COLORABLE)) {
List<String> possibleValues = new ArrayList<String>(); List<String> possibleValues = new ArrayList<>();
if (effect == ParticleEffect.NOTE) { // Note data if (effect == ParticleEffect.NOTE) { // Note data
if (args.length == 7) { if (args.length == 7) {
possibleValues.add("<0-24>"); possibleValues.add("<0-24>");
@ -689,9 +687,9 @@ public class FixedCommandModule implements CommandModule {
StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches); StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches);
} else if (args.length == 7 && effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) { } else if (args.length == 7 && effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) { // Block material if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) { // Block material
matches = StringUtil.copyPartialMatches(args[6], ParticleUtils.getAllBlockMaterials(), matches); StringUtil.copyPartialMatches(args[6], ParticleUtils.getAllBlockMaterials(), matches);
} else if (effect == ParticleEffect.ITEM) { // Item material } else if (effect == ParticleEffect.ITEM) { // Item material
matches = StringUtil.copyPartialMatches(args[6], ParticleUtils.getAllItemMaterials(), matches); StringUtil.copyPartialMatches(args[6], ParticleUtils.getAllItemMaterials(), matches);
} }
} }
} }
@ -699,11 +697,11 @@ public class FixedCommandModule implements CommandModule {
break; break;
case "edit": case "edit":
if (args.length == 2) { if (args.length == 2) {
StringUtil.copyPartialMatches(args[1], pplayer.getFixedEffectIds().stream().map((x) -> String.valueOf(x)).collect(Collectors.toList()), matches); StringUtil.copyPartialMatches(args[1], pplayer.getFixedEffectIds().stream().map(String::valueOf).collect(Collectors.toList()), matches);
} else if (args.length == 3) { } else if (args.length == 3) {
String[] validProperties = new String[] { "location", "effect", "style", "data" }; String[] validProperties = new String[] { "location", "effect", "style", "data" };
StringUtil.copyPartialMatches(args[2], Arrays.asList(validProperties), matches); StringUtil.copyPartialMatches(args[2], Arrays.asList(validProperties), matches);
} else if (args.length > 3) { } else {
String property = args[2].toLowerCase(); String property = args[2].toLowerCase();
if (property.equals("location")) { if (property.equals("location")) {
List<String> possibleValues = new ArrayList<String>(); List<String> possibleValues = new ArrayList<String>();
@ -732,7 +730,7 @@ public class FixedCommandModule implements CommandModule {
if (fixedEffect != null) { if (fixedEffect != null) {
ParticleEffect effect = fixedEffect.getParticlePair().getEffect(); ParticleEffect effect = fixedEffect.getParticlePair().getEffect();
if (effect.hasProperty(ParticleProperty.COLORABLE)) { if (effect.hasProperty(ParticleProperty.COLORABLE)) {
List<String> possibleValues = new ArrayList<String>(); List<String> possibleValues = new ArrayList<>();
if (effect == ParticleEffect.NOTE) { // Note data if (effect == ParticleEffect.NOTE) { // Note data
if (args.length == 4) { if (args.length == 4) {
possibleValues.add("<0-24>"); possibleValues.add("<0-24>");
@ -755,9 +753,9 @@ public class FixedCommandModule implements CommandModule {
StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches); StringUtil.copyPartialMatches(args[args.length - 1], possibleValues, matches);
} else if (args.length == 4 && effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) { } else if (args.length == 4 && effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) { // Block material if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) { // Block material
matches = StringUtil.copyPartialMatches(args[3], ParticleUtils.getAllBlockMaterials(), matches); StringUtil.copyPartialMatches(args[3], ParticleUtils.getAllBlockMaterials(), matches);
} else if (effect == ParticleEffect.ITEM) { // Item material } else if (effect == ParticleEffect.ITEM) { // Item material
matches = StringUtil.copyPartialMatches(args[3], ParticleUtils.getAllItemMaterials(), matches); StringUtil.copyPartialMatches(args[3], ParticleUtils.getAllItemMaterials(), matches);
} }
} }
} }
@ -765,16 +763,14 @@ public class FixedCommandModule implements CommandModule {
} }
break; break;
case "remove": case "remove":
StringUtil.copyPartialMatches(args[1], pplayer.getFixedEffectIds().stream().map((x) -> String.valueOf(x)).collect(Collectors.toList()), matches);
break;
case "list":
break;
case "info": case "info":
StringUtil.copyPartialMatches(args[1], pplayer.getFixedEffectIds().stream().map((x) -> String.valueOf(x)).collect(Collectors.toList()), matches); StringUtil.copyPartialMatches(args[1], pplayer.getFixedEffectIds().stream().map(String::valueOf).collect(Collectors.toList()), matches);
break; break;
case "clear": case "clear":
matches.add("<radius>"); matches.add("<radius>");
break; break;
case "list":
break;
} }
} }

View file

@ -43,7 +43,7 @@ public class GUICommandModule implements CommandModule {
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return new ArrayList<String>(); return new ArrayList<>();
} }
public String getName() { public String getName() {

View file

@ -20,7 +20,7 @@ import com.esophose.playerparticles.particles.ParticlePair;
public class GroupCommandModule implements CommandModule { public class GroupCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
List<String> validCommands = Arrays.asList(new String[] { "save", "load", "remove", "info", "list" }); List<String> validCommands = Arrays.asList("save", "load", "remove", "info", "list");
if (args.length == 0 || !validCommands.contains(args[0])) { if (args.length == 0 || !validCommands.contains(args[0])) {
LangManager.sendMessage(pplayer, Lang.COMMAND_DESCRIPTION_GROUP_SAVE); LangManager.sendMessage(pplayer, Lang.COMMAND_DESCRIPTION_GROUP_SAVE);
LangManager.sendMessage(pplayer, Lang.COMMAND_DESCRIPTION_GROUP_LOAD); LangManager.sendMessage(pplayer, Lang.COMMAND_DESCRIPTION_GROUP_LOAD);
@ -37,19 +37,19 @@ public class GroupCommandModule implements CommandModule {
switch (args[0].toLowerCase()) { switch (args[0].toLowerCase()) {
case "save": case "save":
onSave(pplayer, args[1].toLowerCase()); this.onSave(pplayer, args[1].toLowerCase());
break; break;
case "load": case "load":
onLoad(pplayer, args[1].toLowerCase()); this.onLoad(pplayer, args[1].toLowerCase());
break; break;
case "remove": case "remove":
onRemove(pplayer, args[1].toLowerCase()); this.onRemove(pplayer, args[1].toLowerCase());
break; break;
case "info": case "info":
onInfo(pplayer, args[1].toLowerCase()); this.onInfo(pplayer, args[1].toLowerCase());
break; break;
case "list": case "list":
onList(pplayer); this.onList(pplayer);
break; break;
default: default:
LangManager.sendMessage(pplayer, Lang.COMMAND_DESCRIPTION_GROUP_SAVE); LangManager.sendMessage(pplayer, Lang.COMMAND_DESCRIPTION_GROUP_SAVE);
@ -95,7 +95,7 @@ public class GroupCommandModule implements CommandModule {
ParticleGroup group = pplayer.getParticleGroupByName(groupName); ParticleGroup group = pplayer.getParticleGroupByName(groupName);
boolean groupUpdated = false; boolean groupUpdated = false;
if (group == null) { if (group == null) {
List<ParticlePair> particles = new ArrayList<ParticlePair>(); List<ParticlePair> particles = new ArrayList<>();
for (ParticlePair particle : pplayer.getActiveParticles()) for (ParticlePair particle : pplayer.getActiveParticles())
particles.add(particle.clone()); // Make sure the ParticlePairs aren't the same references in both the active and saved group particles.add(particle.clone()); // Make sure the ParticlePairs aren't the same references in both the active and saved group
group = new ParticleGroup(groupName, particles); group = new ParticleGroup(groupName, particles);
@ -238,38 +238,38 @@ public class GroupCommandModule implements CommandModule {
List<ParticleGroup> groups = pplayer.getParticleGroups(); List<ParticleGroup> groups = pplayer.getParticleGroups();
groups.sort(Comparator.comparing(ParticleGroup::getName)); groups.sort(Comparator.comparing(ParticleGroup::getName));
String groupsList = ""; StringBuilder groupsList = new StringBuilder();
for (ParticleGroup group : groups) for (ParticleGroup group : groups)
if (!group.getName().equals(ParticleGroup.DEFAULT_NAME)) if (!group.getName().equals(ParticleGroup.DEFAULT_NAME))
groupsList += group.getName() + ", "; groupsList.append(group.getName()).append(", ");
if (groupsList.endsWith(", ")) if (groupsList.toString().endsWith(", "))
groupsList = groupsList.substring(0, groupsList.length() - 2); groupsList = new StringBuilder(groupsList.substring(0, groupsList.length() - 2));
String presetsList = ""; StringBuilder presetsList = new StringBuilder();
for (ParticleGroupPreset group : ParticleGroupPresetManager.getPresetGroupsForPlayer(pplayer.getPlayer())) for (ParticleGroupPreset group : ParticleGroupPresetManager.getPresetGroupsForPlayer(pplayer.getPlayer()))
presetsList += group.getGroup().getName() + ", "; presetsList.append(group.getGroup().getName()).append(", ");
if (presetsList.endsWith(", ")) if (presetsList.toString().endsWith(", "))
presetsList = presetsList.substring(0, presetsList.length() - 2); presetsList = new StringBuilder(presetsList.substring(0, presetsList.length() - 2));
if (groupsList.isEmpty() && presetsList.isEmpty()) { if ((groupsList.length() == 0) && (presetsList.length() == 0)) {
LangManager.sendMessage(pplayer, Lang.GROUP_LIST_NONE); LangManager.sendMessage(pplayer, Lang.GROUP_LIST_NONE);
return; return;
} }
if (!groupsList.isEmpty()) { if (groupsList.length() > 0) {
LangManager.sendMessage(pplayer, Lang.GROUP_LIST_OUTPUT, groupsList); LangManager.sendMessage(pplayer, Lang.GROUP_LIST_OUTPUT, groupsList.toString());
} }
if (!presetsList.isEmpty()) { if (presetsList.length() > 0) {
LangManager.sendMessage(pplayer, Lang.GROUP_LIST_PRESETS, presetsList); LangManager.sendMessage(pplayer, Lang.GROUP_LIST_PRESETS, presetsList.toString());
} }
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
List<String> matches = new ArrayList<String>(); List<String> matches = new ArrayList<>();
List<String> subCommands = Arrays.asList(new String[] { "save", "load", "remove", "info", "list" }); List<String> subCommands = Arrays.asList("save", "load", "remove", "info", "list");
if (args.length <= 1) { if (args.length <= 1) {
if (args.length == 0) matches = subCommands; if (args.length == 0) matches = subCommands;
@ -278,7 +278,7 @@ public class GroupCommandModule implements CommandModule {
if (args[0].equalsIgnoreCase("save")) { if (args[0].equalsIgnoreCase("save")) {
matches.add("<groupName>"); matches.add("<groupName>");
} else { } else {
List<String> groupNames = new ArrayList<String>(); List<String> groupNames = new ArrayList<>();
for (ParticleGroup group : pplayer.getParticleGroups()) for (ParticleGroup group : pplayer.getParticleGroups())
if (!group.getName().equals(ParticleGroup.DEFAULT_NAME)) if (!group.getName().equals(ParticleGroup.DEFAULT_NAME))
groupNames.add(group.getName()); groupNames.add(group.getName());
@ -305,7 +305,7 @@ public class GroupCommandModule implements CommandModule {
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return true; return false;
} }
} }

View file

@ -19,7 +19,7 @@ public class HelpCommandModule implements CommandModule {
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return new ArrayList<String>(); return new ArrayList<>();
} }
public String getName() { public String getName() {

View file

@ -31,7 +31,7 @@ public class ListCommandModule implements CommandModule {
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return new ArrayList<String>(); return new ArrayList<>();
} }
public String getName() { public String getName() {

View file

@ -58,10 +58,10 @@ public class OtherCommandModule implements CommandModuleSecondary {
} }
public List<String> onTabComplete(CommandSender sender, String[] args) { public List<String> onTabComplete(CommandSender sender, String[] args) {
List<String> completions = new ArrayList<String>(); List<String> completions = new ArrayList<>();
if (args.length < 2) { if (args.length < 2) {
List<String> playerNames = new ArrayList<String>(); List<String> playerNames = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
playerNames.add(player.getName()); playerNames.add(player.getName());

View file

@ -27,7 +27,7 @@ public class ParticleCommandHandler implements CommandExecutor, TabCompleter {
private static CommandModuleSecondary ppoCommand; private static CommandModuleSecondary ppoCommand;
static { static {
commands = new ArrayList<CommandModule>(); commands = new ArrayList<>();
commands.add(new AddCommandModule()); commands.add(new AddCommandModule());
commands.add(new DataCommandModule()); commands.add(new DataCommandModule());
@ -78,7 +78,7 @@ public class ParticleCommandHandler implements CommandExecutor, TabCompleter {
* @return All available command names * @return All available command names
*/ */
public static List<String> getCommandNames() { public static List<String> getCommandNames() {
List<String> commandNames = new ArrayList<String>(); List<String> commandNames = new ArrayList<>();
for (CommandModule cmd : commands) for (CommandModule cmd : commands)
commandNames.add(cmd.getName()); commandNames.add(cmd.getName());
return commandNames; return commandNames;
@ -137,15 +137,15 @@ public class ParticleCommandHandler implements CommandExecutor, TabCompleter {
*/ */
public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) { public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) {
if (cmd.getName().equalsIgnoreCase("pp")) { if (cmd.getName().equalsIgnoreCase("pp")) {
if (!(sender instanceof Player)) return new ArrayList<String>(); if (!(sender instanceof Player)) return new ArrayList<>();
PPlayer pplayer = DataManager.getPPlayer(((Player) sender).getUniqueId()); PPlayer pplayer = DataManager.getPPlayer(((Player) sender).getUniqueId());
if (pplayer == null) return new ArrayList<String>(); if (pplayer == null) return new ArrayList<>();
if (args.length <= 1) { if (args.length <= 1) {
CommandModule commandModule = findMatchingCommand(""); // Get the default command module CommandModule commandModule = findMatchingCommand(""); // Get the default command module
return commandModule.onTabComplete(pplayer, args); return commandModule.onTabComplete(pplayer, args);
} else if (args.length >= 2) { } else {
CommandModule commandModule = findMatchingCommand(args[0]); CommandModule commandModule = findMatchingCommand(args[0]);
if (commandModule != null) { if (commandModule != null) {
String[] cmdArgs = Arrays.copyOfRange(args, 1, args.length); String[] cmdArgs = Arrays.copyOfRange(args, 1, args.length);
@ -156,7 +156,7 @@ public class ParticleCommandHandler implements CommandExecutor, TabCompleter {
return ppoCommand.onTabComplete(sender, args); return ppoCommand.onTabComplete(sender, args);
} }
return new ArrayList<String>(); return new ArrayList<>();
} }
} }

View file

@ -22,7 +22,7 @@ public class ReloadCommandModule implements CommandModule {
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return new ArrayList<String>(); return new ArrayList<>();
} }
public String getName() { public String getName() {

View file

@ -26,7 +26,7 @@ public class RemoveCommandModule implements CommandModule {
} }
if (StringUtils.isNumeric(args[0])) { // Removing by ID if (StringUtils.isNumeric(args[0])) { // Removing by ID
int id = -1; int id;
try { try {
id = Integer.parseInt(args[0]); id = Integer.parseInt(args[0]);
} catch (Exception ex) { } catch (Exception ex) {
@ -99,8 +99,8 @@ public class RemoveCommandModule implements CommandModule {
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
List<String> matches = new ArrayList<String>(); List<String> matches = new ArrayList<>();
Set<String> removeBy = new HashSet<String>(); Set<String> removeBy = new HashSet<>();
for (ParticlePair particle : pplayer.getActiveParticles()) { for (ParticlePair particle : pplayer.getActiveParticles()) {
removeBy.add(String.valueOf(particle.getId())); removeBy.add(String.valueOf(particle.getId()));
@ -108,7 +108,7 @@ public class RemoveCommandModule implements CommandModule {
removeBy.add(particle.getStyle().getName()); removeBy.add(particle.getStyle().getName());
} }
if (args.length == 0) return new ArrayList<String>(removeBy); if (args.length == 0) return new ArrayList<>(removeBy);
StringUtil.copyPartialMatches(args[0], removeBy, matches); StringUtil.copyPartialMatches(args[0], removeBy, matches);
return matches; return matches;

View file

@ -18,7 +18,7 @@ public class ResetCommandModule implements CommandModule {
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return new ArrayList<String>(); return new ArrayList<>();
} }
public String getName() { public String getName() {

View file

@ -16,20 +16,20 @@ public class StylesCommandModule implements CommandModule {
Player p = pplayer.getPlayer(); Player p = pplayer.getPlayer();
List<String> styleNames = PermissionManager.getStyleNamesUserHasPermissionFor(p); List<String> styleNames = PermissionManager.getStyleNamesUserHasPermissionFor(p);
String toSend = ""; StringBuilder toSend = new StringBuilder();
for (String name : styleNames) { for (String name : styleNames) {
toSend += name + ", "; toSend.append(name).append(", ");
} }
if (toSend.endsWith(", ")) { if (toSend.toString().endsWith(", ")) {
toSend = toSend.substring(0, toSend.length() - 2); toSend = new StringBuilder(toSend.substring(0, toSend.length() - 2));
} }
LangManager.sendMessage(pplayer, Lang.STYLE_LIST, toSend); LangManager.sendMessage(pplayer, Lang.STYLE_LIST, toSend.toString());
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return new ArrayList<String>(); return new ArrayList<>();
} }
public String getName() { public String getName() {

View file

@ -22,7 +22,7 @@ public class ToggleCommandModule implements CommandModule {
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return new ArrayList<String>(); return new ArrayList<>();
} }
public String getName() { public String getName() {

View file

@ -18,7 +18,7 @@ public class VersionCommandModule implements CommandModule {
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return new ArrayList<String>(); return new ArrayList<>();
} }
public String getName() { public String getName() {

View file

@ -16,17 +16,17 @@ public class WorldsCommandModule implements CommandModule {
return; return;
} }
String worlds = ""; StringBuilder worlds = new StringBuilder();
for (String s : PermissionManager.getDisabledWorlds()) { for (String s : PermissionManager.getDisabledWorlds()) {
worlds += s + ", "; worlds.append(s).append(", ");
} }
if (worlds.length() > 2) worlds = worlds.substring(0, worlds.length() - 2); if (worlds.length() > 2) worlds = new StringBuilder(worlds.substring(0, worlds.length() - 2));
LangManager.sendCustomMessage(pplayer, LangManager.getText(Lang.DISABLED_WORLDS) + " " + worlds); LangManager.sendCustomMessage(pplayer, LangManager.getText(Lang.DISABLED_WORLDS) + " " + worlds);
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return new ArrayList<String>(); return new ArrayList<>();
} }
public String getName() { public String getName() {

View file

@ -10,25 +10,25 @@ public interface DatabaseConnector {
* *
* @return If the connection is created or not * @return If the connection is created or not
*/ */
public boolean isInitialized(); boolean isInitialized();
/** /**
* Closes all open connections to the database * Closes all open connections to the database
*/ */
public void closeConnection(); void closeConnection();
/** /**
* Executes a callback with a Connection passed and automatically closes it when finished * Executes a callback with a Connection passed and automatically closes it when finished
* *
* @param callback The callback to execute once the connection is retrieved * @param callback The callback to execute once the connection is retrieved
*/ */
public void connect(ConnectionCallback callback); void connect(ConnectionCallback callback);
/** /**
* Allows Lambda expressions to be used to reduce duplicated code for getting connections * Allows Lambda expressions to be used to reduce duplicated code for getting connections
*/ */
public static interface ConnectionCallback { interface ConnectionCallback {
public void execute(Connection connection) throws SQLException; void execute(Connection connection) throws SQLException;
} }
} }

View file

@ -11,7 +11,7 @@ import com.zaxxer.hikari.HikariDataSource;
public class MySqlDatabaseConnector implements DatabaseConnector { public class MySqlDatabaseConnector implements DatabaseConnector {
private HikariDataSource hikari; private HikariDataSource hikari;
private boolean initializedSuccessfully = false; private boolean initializedSuccessfully;
public MySqlDatabaseConnector() { public MySqlDatabaseConnector() {
String hostname = PSetting.DATABASE_HOSTNAME.getString(); String hostname = PSetting.DATABASE_HOSTNAME.getString();
@ -19,12 +19,13 @@ public class MySqlDatabaseConnector implements DatabaseConnector {
String database = PSetting.DATABASE_NAME.getString(); String database = PSetting.DATABASE_NAME.getString();
String user = PSetting.DATABASE_USER_NAME.getString(); String user = PSetting.DATABASE_USER_NAME.getString();
String pass = PSetting.DATABASE_USER_PASSWORD.getString(); String pass = PSetting.DATABASE_USER_PASSWORD.getString();
boolean useSSL = PSetting.DATABASE_USE_SSL.getBoolean();
HikariConfig config = new HikariConfig(); HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://" + hostname + ":" + port + "/" + database); config.setJdbcUrl("jdbc:mysql://" + hostname + ":" + port + "/" + database + "?useSSL=" + useSSL);
config.setUsername(user); config.setUsername(user);
config.setPassword(pass); config.setPassword(pass);
config.setMaximumPoolSize(5); config.setMaximumPoolSize(3);
try { try {
this.hikari = new HikariDataSource(config); this.hikari = new HikariDataSource(config);

View file

@ -98,7 +98,6 @@ public class GuiActionButton {
* *
* @return The icon ItemStack for the GUI * @return The icon ItemStack for the GUI
*/ */
@SuppressWarnings("deprecation")
public ItemStack getIcon() { public ItemStack getIcon() {
ItemStack itemStack; ItemStack itemStack;
if (this.icons != null) { if (this.icons != null) {
@ -112,12 +111,12 @@ public class GuiActionButton {
} }
ItemMeta itemMeta = itemStack.getItemMeta(); ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta != null) {
itemMeta.setDisplayName(this.name); itemMeta.setDisplayName(this.name);
itemMeta.setLore(parseLore(this.lore)); itemMeta.setLore(parseLore(this.lore));
itemMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_POTION_EFFECTS); itemMeta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_POTION_EFFECTS);
itemStack.setItemMeta(itemMeta); itemStack.setItemMeta(itemMeta);
}
return itemStack; return itemStack;
} }
@ -125,10 +124,9 @@ public class GuiActionButton {
/** /**
* Executes the onClick callback passed in the constructor * Executes the onClick callback passed in the constructor
* *
* @param button The button that was clicked
* @param isShiftClick If the player was holding shift when they clicked * @param isShiftClick If the player was holding shift when they clicked
*/ */
public void handleClick(GuiActionButton button, boolean isShiftClick) { public void handleClick(boolean isShiftClick) {
if (this.onClick != null) if (this.onClick != null)
this.onClick.execute(this, isShiftClick); this.onClick.execute(this, isShiftClick);
} }
@ -158,7 +156,7 @@ public class GuiActionButton {
* @return A parsed list of lore text * @return A parsed list of lore text
*/ */
public static List<String> parseLore(String... lore) { public static List<String> parseLore(String... lore) {
List<String> parsedLore = new ArrayList<String>(); List<String> parsedLore = new ArrayList<>();
for (String line : lore) { for (String line : lore) {
// Try to maintain the color going to the next line if it's split // Try to maintain the color going to the next line if it's split
// If there is no color, just ignore it // If there is no color, just ignore it
@ -181,8 +179,8 @@ public class GuiActionButton {
* Allows button click callbacks as parameters * Allows button click callbacks as parameters
*/ */
@FunctionalInterface @FunctionalInterface
public static interface GuiActionButtonClickCallback { public interface GuiActionButtonClickCallback {
public void execute(GuiActionButton button, boolean isShiftClick); void execute(GuiActionButton button, boolean isShiftClick);
} }
} }

View file

@ -23,7 +23,7 @@ import com.esophose.playerparticles.particles.PPlayer;
*/ */
public class GuiHandler extends BukkitRunnable implements Listener { public class GuiHandler extends BukkitRunnable implements Listener {
private static List<GuiInventory> guiInventories = new ArrayList<GuiInventory>(); private static List<GuiInventory> guiInventories = new ArrayList<>();
private static BukkitTask guiTask = null; private static BukkitTask guiTask = null;
/** /**
@ -40,7 +40,7 @@ public class GuiHandler extends BukkitRunnable implements Listener {
* Removes entries from playerGuiInventories if the player no longer has the inventory open or is offline * Removes entries from playerGuiInventories if the player no longer has the inventory open or is offline
*/ */
public void run() { public void run() {
List<GuiInventory> toRemoveList = new ArrayList<GuiInventory>(); List<GuiInventory> toRemoveList = new ArrayList<>();
for (GuiInventory inventory : guiInventories) { for (GuiInventory inventory : guiInventories) {
PPlayer pplayer = DataManager.getPPlayer(inventory.getPPlayer().getUniqueId()); PPlayer pplayer = DataManager.getPPlayer(inventory.getPPlayer().getUniqueId());

View file

@ -24,12 +24,13 @@ public abstract class GuiInventory implements InventoryHolder {
ORANGE(1, "ORANGE_STAINED_GLASS_PANE"), ORANGE(1, "ORANGE_STAINED_GLASS_PANE"),
RED(14, "RED_STAINED_GLASS_PANE"), RED(14, "RED_STAINED_GLASS_PANE"),
BROWN(12, "BROWN_STAINED_GLASS_PANE"), BROWN(12, "BROWN_STAINED_GLASS_PANE"),
GREEN(13, "GREEN_STAINED_GLASS_PANE"); GREEN(13, "GREEN_STAINED_GLASS_PANE"),
YELLOW(4, "YELLOW_STAINED_GLASS_PANE");
private short data; private short data;
private Material material; private Material material;
private BorderColor(int data, String materialName) { BorderColor(int data, String materialName) {
this.data = (short)data; this.data = (short)data;
this.material = ParticleUtils.closestMatch(materialName); this.material = ParticleUtils.closestMatch(materialName);
} }
@ -44,9 +45,11 @@ public abstract class GuiInventory implements InventoryHolder {
} }
ItemMeta meta = borderIcon.getItemMeta(); ItemMeta meta = borderIcon.getItemMeta();
if (meta != null) {
meta.setDisplayName(" "); meta.setDisplayName(" ");
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_ENCHANTS); meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_ENCHANTS);
borderIcon.setItemMeta(meta); borderIcon.setItemMeta(meta);
}
return borderIcon; return borderIcon;
} }
@ -60,7 +63,7 @@ public abstract class GuiInventory implements InventoryHolder {
public GuiInventory(PPlayer pplayer, Inventory inventory) { public GuiInventory(PPlayer pplayer, Inventory inventory) {
this.pplayer = pplayer; this.pplayer = pplayer;
this.inventory = inventory; this.inventory = inventory;
this.actionButtons = new ArrayList<GuiActionButton>(); this.actionButtons = new ArrayList<>();
} }
/** /**
@ -110,7 +113,7 @@ public abstract class GuiInventory implements InventoryHolder {
* Populates the Inventory with the contents of actionButtons * Populates the Inventory with the contents of actionButtons
*/ */
protected void populate() { protected void populate() {
for (GuiActionButton button : actionButtons) { for (GuiActionButton button : this.actionButtons) {
this.inventory.setItem(button.getSlot(), button.getIcon()); this.inventory.setItem(button.getSlot(), button.getIcon());
} }
} }
@ -140,21 +143,19 @@ public abstract class GuiInventory implements InventoryHolder {
for (GuiActionButton button : this.actionButtons) { for (GuiActionButton button : this.actionButtons) {
if (button.getSlot() == slot) { if (button.getSlot() == slot) {
button.handleClick(button, isShiftClick); button.handleClick(isShiftClick);
if (PSetting.GUI_BUTTON_SOUND.getBoolean()) { if (PSetting.GUI_BUTTON_SOUND.getBoolean() && event.getWhoClicked() instanceof Player) {
if (event.getWhoClicked() instanceof Player) {
Player player = (Player) event.getWhoClicked(); Player player = (Player) event.getWhoClicked();
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 0.5f, 1); player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 0.5f, 1);
} }
}
break; break;
} }
} }
} }
@FunctionalInterface @FunctionalInterface
public static interface GuiInventoryEditFinishedCallback { public interface GuiInventoryEditFinishedCallback {
public void execute(); void execute();
} }
} }

View file

@ -1,14 +1,5 @@
package com.esophose.playerparticles.gui; package com.esophose.playerparticles.gui;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.SkullType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import com.esophose.playerparticles.manager.DataManager; import com.esophose.playerparticles.manager.DataManager;
import com.esophose.playerparticles.manager.LangManager; import com.esophose.playerparticles.manager.LangManager;
import com.esophose.playerparticles.manager.LangManager.Lang; import com.esophose.playerparticles.manager.LangManager.Lang;
@ -20,6 +11,14 @@ import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty;
import com.esophose.playerparticles.particles.ParticleGroup; import com.esophose.playerparticles.particles.ParticleGroup;
import com.esophose.playerparticles.particles.ParticlePair; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.util.ParticleUtils; import com.esophose.playerparticles.util.ParticleUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.SkullType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class GuiInventoryDefault extends GuiInventory { public class GuiInventoryDefault extends GuiInventory {
@ -39,8 +38,9 @@ public class GuiInventoryDefault extends GuiInventory {
} }
SkullMeta currentIconMeta = (SkullMeta) headIcon.getItemMeta(); SkullMeta currentIconMeta = (SkullMeta) headIcon.getItemMeta();
if (currentIconMeta != null) {
currentIconMeta.setDisplayName(LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + pplayer.getPlayer().getName()); currentIconMeta.setDisplayName(LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + pplayer.getPlayer().getName());
String[] currentIconLore = new String[] { String[] currentIconLore = new String[]{
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_ACTIVE_PARTICLES, pplayer.getActiveParticles().size()), LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_ACTIVE_PARTICLES, pplayer.getActiveParticles().size()),
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SAVED_GROUPS, pplayer.getParticleGroups().size() - 1), LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SAVED_GROUPS, pplayer.getParticleGroups().size() - 1),
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_FIXED_EFFECTS, pplayer.getFixedEffectIds().size()), LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_FIXED_EFFECTS, pplayer.getFixedEffectIds().size()),
@ -50,6 +50,7 @@ public class GuiInventoryDefault extends GuiInventory {
currentIconMeta.setLore(GuiActionButton.parseLore(currentIconLore)); currentIconMeta.setLore(GuiActionButton.parseLore(currentIconLore));
currentIconMeta.setOwner(pplayer.getPlayer().getName()); currentIconMeta.setOwner(pplayer.getPlayer().getName());
headIcon.setItemMeta(currentIconMeta); headIcon.setItemMeta(currentIconMeta);
}
this.inventory.setItem(13, headIcon); this.inventory.setItem(13, headIcon);
@ -73,36 +74,33 @@ public class GuiInventoryDefault extends GuiInventory {
} }
// Manage Your Particles button // Manage Your Particles button
GuiActionButton manageYourParticlesButton = new GuiActionButton(manageParticlesSlot, GuiActionButton manageYourParticlesButton = new GuiActionButton(
manageParticlesSlot,
GuiIcon.PARTICLES.get(), GuiIcon.PARTICLES.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_MANAGE_YOUR_PARTICLES), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_MANAGE_YOUR_PARTICLES),
new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_MANAGE_YOUR_PARTICLES_DESCRIPTION) }, new String[]{LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_MANAGE_YOUR_PARTICLES_DESCRIPTION)},
(button, isShiftClick) -> { (button, isShiftClick) -> GuiHandler.transition(new GuiInventoryManageParticles(pplayer)));
GuiHandler.transition(new GuiInventoryManageParticles(pplayer));
});
this.actionButtons.add(manageYourParticlesButton); this.actionButtons.add(manageYourParticlesButton);
// Manage Your Groups button // Manage Your Groups button
if (manageGroupsVisible) { if (manageGroupsVisible) {
GuiActionButton manageYourGroupsButton = new GuiActionButton(manageGroupsSlot, GuiActionButton manageYourGroupsButton = new GuiActionButton(
manageGroupsSlot,
GuiIcon.GROUPS.get(), GuiIcon.GROUPS.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_MANAGE_YOUR_GROUPS), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_MANAGE_YOUR_GROUPS),
new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_MANAGE_YOUR_GROUPS_DESCRIPTION) }, new String[]{LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_MANAGE_YOUR_GROUPS_DESCRIPTION)},
(button, isShiftClick) -> { (button, isShiftClick) -> GuiHandler.transition(new GuiInventoryManageGroups(pplayer)));
GuiHandler.transition(new GuiInventoryManageGroups(pplayer));
});
this.actionButtons.add(manageYourGroupsButton); this.actionButtons.add(manageYourGroupsButton);
} }
// Load Preset Groups // Load Preset Groups
if (loadPresetGroupVisible) { if (loadPresetGroupVisible) {
GuiActionButton loadPresetGroups = new GuiActionButton(loadPresetGroupSlot, GuiActionButton loadPresetGroups = new GuiActionButton(
loadPresetGroupSlot,
GuiIcon.PRESET_GROUPS.get(), GuiIcon.PRESET_GROUPS.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_LOAD_A_PRESET_GROUP), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_LOAD_A_PRESET_GROUP),
new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_LOAD_A_PRESET_GROUP_DESCRIPTION) }, new String[]{LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_LOAD_A_PRESET_GROUP_DESCRIPTION)},
(button, isShiftClick) -> { (button, isShiftClick) -> GuiHandler.transition(new GuiInventoryLoadPresetGroups(pplayer, false)));
GuiHandler.transition(new GuiInventoryLoadPresetGroups(pplayer, false));
});
this.actionButtons.add(loadPresetGroups); this.actionButtons.add(loadPresetGroups);
} }
@ -111,12 +109,13 @@ public class GuiInventoryDefault extends GuiInventory {
boolean doesEffectUseData = editingParticle.getEffect().hasProperty(ParticleProperty.COLORABLE) || editingParticle.getEffect().hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA); boolean doesEffectUseData = editingParticle.getEffect().hasProperty(ParticleProperty.COLORABLE) || editingParticle.getEffect().hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA);
// Edit Primary Effect // Edit Primary Effect
GuiActionButton editPrimaryEffect = new GuiActionButton(38, GuiActionButton editPrimaryEffect = new GuiActionButton(
38,
GuiIcon.EDIT_EFFECT.get(), GuiIcon.EDIT_EFFECT.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_EFFECT), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_EFFECT),
new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_EFFECT_DESCRIPTION) }, new String[]{LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_EFFECT_DESCRIPTION)},
(button, isShiftClick) -> { (button, isShiftClick) -> {
List<GuiInventoryEditFinishedCallback> callbacks = new ArrayList<GuiInventoryEditFinishedCallback>(); List<GuiInventoryEditFinishedCallback> callbacks = new ArrayList<>();
callbacks.add(() -> GuiHandler.transition(new GuiInventoryDefault(pplayer))); callbacks.add(() -> GuiHandler.transition(new GuiInventoryDefault(pplayer)));
callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditEffect(pplayer, editingParticle, callbacks, 1))); callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditEffect(pplayer, editingParticle, callbacks, 1)));
callbacks.add(() -> { callbacks.add(() -> {
@ -143,21 +142,22 @@ public class GuiInventoryDefault extends GuiInventory {
// Edit Primary Style // Edit Primary Style
String[] editPrimaryStyleLore; String[] editPrimaryStyleLore;
if (canEditPrimaryStyleAndData) { if (canEditPrimaryStyleAndData) {
editPrimaryStyleLore = new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_STYLE_DESCRIPTION) }; editPrimaryStyleLore = new String[]{LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_STYLE_DESCRIPTION)};
} else { } else {
editPrimaryStyleLore = new String[] { editPrimaryStyleLore = new String[]{
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_STYLE_DESCRIPTION), LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_STYLE_DESCRIPTION),
LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_STYLE_MISSING_EFFECT) LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_STYLE_MISSING_EFFECT)
}; };
} }
GuiActionButton editPrimaryStyle = new GuiActionButton(40, GuiActionButton editPrimaryStyle = new GuiActionButton(
40,
GuiIcon.EDIT_STYLE.get(), GuiIcon.EDIT_STYLE.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_STYLE), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_STYLE),
editPrimaryStyleLore, editPrimaryStyleLore,
(button, isShiftClick) -> { (button, isShiftClick) -> {
if (!canEditPrimaryStyleAndData) return; if (!canEditPrimaryStyleAndData) return;
List<GuiInventoryEditFinishedCallback> callbacks = new ArrayList<GuiInventoryEditFinishedCallback>(); List<GuiInventoryEditFinishedCallback> callbacks = new ArrayList<>();
callbacks.add(() -> GuiHandler.transition(new GuiInventoryDefault(pplayer))); callbacks.add(() -> GuiHandler.transition(new GuiInventoryDefault(pplayer)));
callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditStyle(pplayer, editingParticle, callbacks, 1))); callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditStyle(pplayer, editingParticle, callbacks, 1)));
callbacks.add(() -> { callbacks.add(() -> {
@ -180,26 +180,27 @@ public class GuiInventoryDefault extends GuiInventory {
// Edit Primary Data // Edit Primary Data
String[] editPrimaryDataLore; String[] editPrimaryDataLore;
if (canEditPrimaryStyleAndData && doesEffectUseData) { if (canEditPrimaryStyleAndData && doesEffectUseData) {
editPrimaryDataLore = new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_DATA_DESCRIPTION) }; editPrimaryDataLore = new String[]{LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_DATA_DESCRIPTION)};
} else if (canEditPrimaryStyleAndData) { } else if (canEditPrimaryStyleAndData) {
editPrimaryDataLore = new String[] { editPrimaryDataLore = new String[]{
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_DATA_DESCRIPTION), LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_DATA_DESCRIPTION),
LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_DATA_UNAVAILABLE) LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_DATA_UNAVAILABLE)
}; };
} else { } else {
editPrimaryDataLore = new String[] { editPrimaryDataLore = new String[]{
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_DATA_DESCRIPTION), LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_DATA_DESCRIPTION),
LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_DATA_MISSING_EFFECT) LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_DATA_MISSING_EFFECT)
}; };
} }
GuiActionButton editPrimaryData = new GuiActionButton(42, GuiActionButton editPrimaryData = new GuiActionButton(
42,
GuiIcon.EDIT_DATA.get(), GuiIcon.EDIT_DATA.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_DATA), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_EDIT_PRIMARY_DATA),
editPrimaryDataLore, editPrimaryDataLore,
(button, isShiftClick) -> { (button, isShiftClick) -> {
if (!canEditPrimaryStyleAndData || !doesEffectUseData) return; if (!canEditPrimaryStyleAndData || !doesEffectUseData) return;
List<GuiInventoryEditFinishedCallback> callbacks = new ArrayList<GuiInventoryEditFinishedCallback>(); List<GuiInventoryEditFinishedCallback> callbacks = new ArrayList<>();
callbacks.add(() -> GuiHandler.transition(new GuiInventoryDefault(pplayer))); callbacks.add(() -> GuiHandler.transition(new GuiInventoryDefault(pplayer)));
callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditData(pplayer, editingParticle, callbacks, 1))); callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditData(pplayer, editingParticle, callbacks, 1)));
callbacks.add(() -> { callbacks.add(() -> {

View file

@ -1,18 +1,5 @@
package com.esophose.playerparticles.gui; package com.esophose.playerparticles.gui;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import com.esophose.playerparticles.manager.LangManager; import com.esophose.playerparticles.manager.LangManager;
import com.esophose.playerparticles.manager.LangManager.Lang; import com.esophose.playerparticles.manager.LangManager.Lang;
import com.esophose.playerparticles.manager.SettingManager.GuiIcon; import com.esophose.playerparticles.manager.SettingManager.GuiIcon;
@ -23,6 +10,18 @@ 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.particles.ParticlePair;
import com.esophose.playerparticles.util.ParticleUtils; import com.esophose.playerparticles.util.ParticleUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class GuiInventoryEditData extends GuiInventory { public class GuiInventoryEditData extends GuiInventory {
@ -34,26 +33,26 @@ public class GuiInventoryEditData extends GuiInventory {
private static ColorData[] noteColorMapping; private static ColorData[] noteColorMapping;
static { static {
colorMapping = new ColorData[] { colorMapping = new ColorData[]{
new ColorData(DyeColor.RED, ParticleUtils.closestMatch("ROSE_RED"), new OrdinaryColor(255, 0, 0), Lang.GUI_EDIT_DATA_COLOR_RED), new ColorData(DyeColor.RED, ParticleUtils.closestMatchWithFallback(false, "RED_DYE", "ROSE_RED"), new OrdinaryColor(255, 0, 0), Lang.GUI_EDIT_DATA_COLOR_RED),
new ColorData(DyeColor.ORANGE, ParticleUtils.closestMatch("ORANGE_DYE"), new OrdinaryColor(255, 140, 0), Lang.GUI_EDIT_DATA_COLOR_ORANGE), new ColorData(DyeColor.ORANGE, ParticleUtils.closestMatchWithFallback(false, "ORANGE_DYE"), new OrdinaryColor(255, 140, 0), Lang.GUI_EDIT_DATA_COLOR_ORANGE),
new ColorData(DyeColor.YELLOW, ParticleUtils.closestMatch("DANDELION_YELLOW"), new OrdinaryColor(255, 255, 0), Lang.GUI_EDIT_DATA_COLOR_YELLOW), new ColorData(DyeColor.YELLOW, ParticleUtils.closestMatchWithFallback(false, "YELLOW_DYE", "DANDELION_YELLOW"), new OrdinaryColor(255, 255, 0), Lang.GUI_EDIT_DATA_COLOR_YELLOW),
new ColorData(DyeColor.LIME, ParticleUtils.closestMatch("LIME_DYE"), new OrdinaryColor(50, 205, 50), Lang.GUI_EDIT_DATA_COLOR_LIME_GREEN), new ColorData(DyeColor.LIME, ParticleUtils.closestMatchWithFallback(false, "LIME_DYE"), new OrdinaryColor(50, 205, 50), Lang.GUI_EDIT_DATA_COLOR_LIME_GREEN),
new ColorData(DyeColor.GREEN, ParticleUtils.closestMatch("CACTUS_GREEN"), new OrdinaryColor(0, 128, 0), Lang.GUI_EDIT_DATA_COLOR_GREEN), new ColorData(DyeColor.GREEN, ParticleUtils.closestMatchWithFallback(false, "GREEN_DYE", "CACTUS_GREEN"), new OrdinaryColor(0, 128, 0), Lang.GUI_EDIT_DATA_COLOR_GREEN),
new ColorData(DyeColor.BLUE, ParticleUtils.closestMatch("LAPIS_LAZULI"), new OrdinaryColor(0, 0, 255), Lang.GUI_EDIT_DATA_COLOR_BLUE), new ColorData(DyeColor.BLUE, ParticleUtils.closestMatchWithFallback(false, "BLUE_DYE", "LAPIS_LAZULI"), new OrdinaryColor(0, 0, 255), Lang.GUI_EDIT_DATA_COLOR_BLUE),
new ColorData(DyeColor.CYAN, ParticleUtils.closestMatch("CYAN_DYE"), new OrdinaryColor(0, 139, 139), Lang.GUI_EDIT_DATA_COLOR_CYAN), new ColorData(DyeColor.CYAN, ParticleUtils.closestMatchWithFallback(false, "CYAN_DYE"), new OrdinaryColor(0, 139, 139), Lang.GUI_EDIT_DATA_COLOR_CYAN),
new ColorData(DyeColor.LIGHT_BLUE, ParticleUtils.closestMatch("LIGHT_BLUE_DYE"), new OrdinaryColor(173, 216, 230), Lang.GUI_EDIT_DATA_COLOR_LIGHT_BLUE), new ColorData(DyeColor.LIGHT_BLUE, ParticleUtils.closestMatchWithFallback(false, "LIGHT_BLUE_DYE"), new OrdinaryColor(173, 216, 230), Lang.GUI_EDIT_DATA_COLOR_LIGHT_BLUE),
new ColorData(DyeColor.PURPLE, ParticleUtils.closestMatch("PURPLE_DYE"), new OrdinaryColor(138, 43, 226), Lang.GUI_EDIT_DATA_COLOR_PURPLE), new ColorData(DyeColor.PURPLE, ParticleUtils.closestMatchWithFallback(false, "PURPLE_DYE"), new OrdinaryColor(138, 43, 226), Lang.GUI_EDIT_DATA_COLOR_PURPLE),
new ColorData(DyeColor.MAGENTA, ParticleUtils.closestMatch("MAGENTA_DYE"), new OrdinaryColor(202, 31, 123), Lang.GUI_EDIT_DATA_COLOR_MAGENTA), new ColorData(DyeColor.MAGENTA, ParticleUtils.closestMatchWithFallback(false, "MAGENTA_DYE"), new OrdinaryColor(202, 31, 123), Lang.GUI_EDIT_DATA_COLOR_MAGENTA),
new ColorData(DyeColor.PINK, ParticleUtils.closestMatch("PINK_DYE"), new OrdinaryColor(255, 182, 193), Lang.GUI_EDIT_DATA_COLOR_PINK), new ColorData(DyeColor.PINK, ParticleUtils.closestMatchWithFallback(false, "PINK_DYE"), new OrdinaryColor(255, 182, 193), Lang.GUI_EDIT_DATA_COLOR_PINK),
new ColorData(DyeColor.BROWN, ParticleUtils.closestMatch("COCOA_BEANS"), new OrdinaryColor(139, 69, 19), Lang.GUI_EDIT_DATA_COLOR_BROWN), new ColorData(DyeColor.BROWN, ParticleUtils.closestMatchWithFallback(false, "BROWN_DYE", "COCOA_BEANS"), new OrdinaryColor(139, 69, 19), Lang.GUI_EDIT_DATA_COLOR_BROWN),
new ColorData(DyeColor.BLACK, ParticleUtils.closestMatch("INK_SAC"), new OrdinaryColor(0, 0, 0), Lang.GUI_EDIT_DATA_COLOR_BLACK), new ColorData(DyeColor.BLACK, ParticleUtils.closestMatchWithFallback(false, "BLACK_DYE", "INK_SAC"), new OrdinaryColor(0, 0, 0), Lang.GUI_EDIT_DATA_COLOR_BLACK),
new ColorData(DyeColor.GRAY, ParticleUtils.closestMatch("GRAY_DYE"), new OrdinaryColor(128, 128, 128), Lang.GUI_EDIT_DATA_COLOR_GRAY), new ColorData(DyeColor.GRAY, ParticleUtils.closestMatchWithFallback(false, "GRAY_DYE"), new OrdinaryColor(128, 128, 128), Lang.GUI_EDIT_DATA_COLOR_GRAY),
new ColorData(DyeColor.getByDyeData((byte)7), ParticleUtils.closestMatch("LIGHT_GRAY_DYE"), new OrdinaryColor(192, 192, 192), Lang.GUI_EDIT_DATA_COLOR_LIGHT_GRAY), new ColorData(DyeColor.getByDyeData((byte) 7), ParticleUtils.closestMatchWithFallback(false, "LIGHT_GRAY_DYE"), new OrdinaryColor(192, 192, 192), Lang.GUI_EDIT_DATA_COLOR_LIGHT_GRAY),
new ColorData(DyeColor.WHITE, ParticleUtils.closestMatch("BONE_MEAL"), new OrdinaryColor(255, 255, 255), Lang.GUI_EDIT_DATA_COLOR_WHITE), new ColorData(DyeColor.WHITE, ParticleUtils.closestMatchWithFallback(false, "WHITE_DYE", "BONE_MEAL"), new OrdinaryColor(255, 255, 255), Lang.GUI_EDIT_DATA_COLOR_WHITE),
}; };
rainbowColorMapping = new ColorData[] { rainbowColorMapping = new ColorData[]{
colorMapping[0], // Red colorMapping[0], // Red
colorMapping[1], // Orange colorMapping[1], // Orange
colorMapping[2], // Yellow colorMapping[2], // Yellow
@ -64,7 +63,7 @@ public class GuiInventoryEditData extends GuiInventory {
}; };
// Note: This is supposed to be a rainbow but there's actually a bug in Minecraft since 1.8 that makes a bunch of them gray // Note: This is supposed to be a rainbow but there's actually a bug in Minecraft since 1.8 that makes a bunch of them gray
noteColorMapping = new ColorData[] { noteColorMapping = new ColorData[]{
colorMapping[7], // Light Blue colorMapping[7], // Light Blue
colorMapping[7], // Light Blue colorMapping[7], // Light Blue
colorMapping[13], // Gray colorMapping[13], // Gray
@ -92,8 +91,8 @@ public class GuiInventoryEditData extends GuiInventory {
colorMapping[7] // Light Blue colorMapping[7] // Light Blue
}; };
BLOCK_MATERIALS = new ArrayList<Material>(); BLOCK_MATERIALS = new ArrayList<>();
ITEM_MATERIALS = new ArrayList<Material>(); ITEM_MATERIALS = new ArrayList<>();
Inventory tempInventory = Bukkit.createInventory(null, 9); Inventory tempInventory = Bukkit.createInventory(null, 9);
for (Material mat : Material.values()) { for (Material mat : Material.values()) {
@ -130,9 +129,12 @@ public class GuiInventoryEditData extends GuiInventory {
} }
// Back Button // Back Button
GuiActionButton backButton = new GuiActionButton(INVENTORY_SIZE - 1, GuiIcon.BACK.get(), LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_BACK_BUTTON), new String[] {}, (button, isShiftClick) -> { GuiActionButton backButton = new GuiActionButton(
callbackList.get(callbackListPosition - 1).execute(); INVENTORY_SIZE - 1,
}); GuiIcon.BACK.get(),
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_BACK_BUTTON),
new String[]{},
(button, isShiftClick) -> callbackList.get(callbackListPosition - 1).execute());
this.actionButtons.add(backButton); this.actionButtons.add(backButton);
this.populate(); this.populate();
@ -153,10 +155,11 @@ public class GuiInventoryEditData extends GuiInventory {
String formattedDisplayColor = ChatColor.RED.toString() + colorData.getOrdinaryColor().getRed() + " " + ChatColor.GREEN + colorData.getOrdinaryColor().getGreen() + " " + ChatColor.AQUA + colorData.getOrdinaryColor().getBlue(); String formattedDisplayColor = ChatColor.RED.toString() + colorData.getOrdinaryColor().getRed() + " " + ChatColor.GREEN + colorData.getOrdinaryColor().getGreen() + " " + ChatColor.AQUA + colorData.getOrdinaryColor().getBlue();
// Color Data Buttons // Color Data Buttons
GuiActionButton setColorButton = new GuiActionButton(index, GuiActionButton setColorButton = new GuiActionButton(
index,
colorData, colorData,
colorData.getName(), colorData.getName(),
new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SELECT_DATA_DESCRIPTION, formattedDisplayColor) }, new String[]{LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SELECT_DATA_DESCRIPTION, formattedDisplayColor)},
(button, isShiftClick) -> { (button, isShiftClick) -> {
editingParticle.setColor(colorData.getOrdinaryColor()); editingParticle.setColor(colorData.getOrdinaryColor());
callbackList.get(callbackListPosition + 1).execute(); callbackList.get(callbackListPosition + 1).execute();
@ -171,10 +174,11 @@ public class GuiInventoryEditData extends GuiInventory {
} }
// Rainbow Color Data Button // Rainbow Color Data Button
GuiActionButton setRainbowColorButton = new GuiActionButton(39, GuiActionButton setRainbowColorButton = new GuiActionButton(
39,
rainbowColorMapping, rainbowColorMapping,
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.RAINBOW), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.RAINBOW),
new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SELECT_DATA_DESCRIPTION, LangManager.getText(Lang.RAINBOW)) }, new String[]{LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SELECT_DATA_DESCRIPTION, LangManager.getText(Lang.RAINBOW))},
(button, isShiftClick) -> { (button, isShiftClick) -> {
editingParticle.setColor(new OrdinaryColor(999, 999, 999)); editingParticle.setColor(new OrdinaryColor(999, 999, 999));
callbackList.get(callbackListPosition + 1).execute(); callbackList.get(callbackListPosition + 1).execute();
@ -189,7 +193,7 @@ public class GuiInventoryEditData extends GuiInventory {
GuiActionButton setRandomColorButton = new GuiActionButton(41, GuiActionButton setRandomColorButton = new GuiActionButton(41,
randomizedColors, randomizedColors,
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.RANDOM), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.RANDOM),
new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SELECT_DATA_DESCRIPTION, LangManager.getText(Lang.RANDOM)) }, new String[]{LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SELECT_DATA_DESCRIPTION, LangManager.getText(Lang.RANDOM))},
(button, isShiftClick) -> { (button, isShiftClick) -> {
editingParticle.setColor(new OrdinaryColor(998, 998, 998)); editingParticle.setColor(new OrdinaryColor(998, 998, 998));
callbackList.get(callbackListPosition + 1).execute(); callbackList.get(callbackListPosition + 1).execute();
@ -212,10 +216,11 @@ public class GuiInventoryEditData extends GuiInventory {
// Note Color Buttons // Note Color Buttons
int noteIndex = i; int noteIndex = i;
GuiActionButton setColorButton = new GuiActionButton(i, GuiActionButton setColorButton = new GuiActionButton(
i,
colorData, colorData,
formattedDisplayName, formattedDisplayName,
new String[] { formattedDescription }, new String[]{formattedDescription},
(button, isShiftClick) -> { (button, isShiftClick) -> {
editingParticle.setNoteColor(new NoteColor(noteIndex)); editingParticle.setNoteColor(new NoteColor(noteIndex));
callbackList.get(callbackListPosition + 1).execute(); callbackList.get(callbackListPosition + 1).execute();
@ -224,10 +229,11 @@ public class GuiInventoryEditData extends GuiInventory {
} }
// Rainbow Note Data Button // Rainbow Note Data Button
GuiActionButton setRainbowColorButton = new GuiActionButton(39, GuiActionButton setRainbowColorButton = new GuiActionButton(
39,
rainbowColorMapping, rainbowColorMapping,
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.RAINBOW), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.RAINBOW),
new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SELECT_DATA_DESCRIPTION, LangManager.getText(Lang.RAINBOW)) }, new String[]{LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SELECT_DATA_DESCRIPTION, LangManager.getText(Lang.RAINBOW))},
(button, isShiftClick) -> { (button, isShiftClick) -> {
editingParticle.setNoteColor(new NoteColor(99)); editingParticle.setNoteColor(new NoteColor(99));
callbackList.get(callbackListPosition + 1).execute(); callbackList.get(callbackListPosition + 1).execute();
@ -239,10 +245,11 @@ public class GuiInventoryEditData extends GuiInventory {
Collections.shuffle(randomizedColorsList); Collections.shuffle(randomizedColorsList);
ColorData[] randomizedColors = new ColorData[randomizedColorsList.size()]; ColorData[] randomizedColors = new ColorData[randomizedColorsList.size()];
randomizedColors = randomizedColorsList.toArray(randomizedColors); randomizedColors = randomizedColorsList.toArray(randomizedColors);
GuiActionButton setRandomColorButton = new GuiActionButton(41, GuiActionButton setRandomColorButton = new GuiActionButton(
41,
randomizedColors, randomizedColors,
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.RANDOM), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.RANDOM),
new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SELECT_DATA_DESCRIPTION, LangManager.getText(Lang.RANDOM)) }, new String[]{LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SELECT_DATA_DESCRIPTION, LangManager.getText(Lang.RANDOM))},
(button, isShiftClick) -> { (button, isShiftClick) -> {
editingParticle.setNoteColor(new NoteColor(98)); editingParticle.setNoteColor(new NoteColor(98));
callbackList.get(callbackListPosition + 1).execute(); callbackList.get(callbackListPosition + 1).execute();
@ -258,7 +265,7 @@ public class GuiInventoryEditData extends GuiInventory {
* @param callbackListPosition The index of the callbackList we're currently at * @param callbackListPosition The index of the callbackList we're currently at
*/ */
private void populateItemData(ParticlePair editingParticle, List<GuiInventoryEditFinishedCallback> callbackList, int callbackListPosition) { private void populateItemData(ParticlePair editingParticle, List<GuiInventoryEditFinishedCallback> callbackList, int callbackListPosition) {
List<Material> materialBag = new ArrayList<Material>(); List<Material> materialBag = new ArrayList<>();
while (materialBag.size() < 36) { // Grab 36 random materials that are an item while (materialBag.size() < 36) { // Grab 36 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()));
if (!materialBag.contains(randomMaterial)) materialBag.add(randomMaterial); if (!materialBag.contains(randomMaterial)) materialBag.add(randomMaterial);
@ -267,10 +274,11 @@ public class GuiInventoryEditData extends GuiInventory {
for (int i = 0; i < materialBag.size(); i++) { for (int i = 0; i < materialBag.size(); i++) {
// Item Data Button // Item Data Button
Material material = materialBag.get(i); Material material = materialBag.get(i);
GuiActionButton setRainbowColorButton = new GuiActionButton(i, GuiActionButton setRainbowColorButton = new GuiActionButton(
i,
material, material,
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + material.name().toLowerCase(), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + material.name().toLowerCase(),
new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SELECT_DATA_DESCRIPTION, material.name().toLowerCase()) }, new String[]{LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SELECT_DATA_DESCRIPTION, material.name().toLowerCase())},
(button, isShiftClick) -> { (button, isShiftClick) -> {
editingParticle.setItemMaterial(material); editingParticle.setItemMaterial(material);
callbackList.get(callbackListPosition + 1).execute(); callbackList.get(callbackListPosition + 1).execute();
@ -279,10 +287,11 @@ public class GuiInventoryEditData extends GuiInventory {
} }
// Randomize Button, re-randomizes the icons // Randomize Button, re-randomizes the icons
GuiActionButton randomizeButton = new GuiActionButton(45, GuiActionButton randomizeButton = new GuiActionButton(
45,
GuiIcon.RANDOMIZE.get(), GuiIcon.RANDOMIZE.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_SELECT_DATA_RANDOMIZE_ITEMS), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_SELECT_DATA_RANDOMIZE_ITEMS),
new String[] { LangManager.getText(Lang.GUI_COLOR_SUBTEXT) + LangManager.getText(Lang.GUI_SELECT_DATA_RANDOMIZE_ITEMS_DESCRIPTION) }, new String[]{LangManager.getText(Lang.GUI_COLOR_SUBTEXT) + LangManager.getText(Lang.GUI_SELECT_DATA_RANDOMIZE_ITEMS_DESCRIPTION)},
(block, isShiftClick) -> { (block, isShiftClick) -> {
callbackList.get(callbackListPosition).execute(); // Just reopen the same inventory callbackList.get(callbackListPosition).execute(); // Just reopen the same inventory
}); });
@ -297,7 +306,7 @@ public class GuiInventoryEditData extends GuiInventory {
* @param callbackListPosition The index of the callbackList we're currently at * @param callbackListPosition The index of the callbackList we're currently at
*/ */
private void populateBlockData(ParticlePair editingParticle, List<GuiInventoryEditFinishedCallback> callbackList, int callbackListPosition) { private void populateBlockData(ParticlePair editingParticle, List<GuiInventoryEditFinishedCallback> callbackList, int callbackListPosition) {
List<Material> materialBag = new ArrayList<Material>(); List<Material> materialBag = new ArrayList<>();
while (materialBag.size() < 36) { // Grab 36 random materials that are an item while (materialBag.size() < 36) { // Grab 36 random materials that are an item
Material randomMaterial = BLOCK_MATERIALS.get(RANDOM.nextInt(BLOCK_MATERIALS.size())); Material randomMaterial = BLOCK_MATERIALS.get(RANDOM.nextInt(BLOCK_MATERIALS.size()));
if (!materialBag.contains(randomMaterial)) materialBag.add(randomMaterial); if (!materialBag.contains(randomMaterial)) materialBag.add(randomMaterial);
@ -306,10 +315,11 @@ public class GuiInventoryEditData extends GuiInventory {
for (int i = 0; i < materialBag.size(); i++) { for (int i = 0; i < materialBag.size(); i++) {
// Item Data Button // Item Data Button
Material material = materialBag.get(i); Material material = materialBag.get(i);
GuiActionButton setRainbowColorButton = new GuiActionButton(i, GuiActionButton setRainbowColorButton = new GuiActionButton(
i,
material, material,
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + material.name().toLowerCase(), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + material.name().toLowerCase(),
new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SELECT_DATA_DESCRIPTION, material.name().toLowerCase()) }, new String[]{LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SELECT_DATA_DESCRIPTION, material.name().toLowerCase())},
(button, isShiftClick) -> { (button, isShiftClick) -> {
editingParticle.setBlockMaterial(material); editingParticle.setBlockMaterial(material);
callbackList.get(callbackListPosition + 1).execute(); callbackList.get(callbackListPosition + 1).execute();
@ -318,10 +328,11 @@ public class GuiInventoryEditData extends GuiInventory {
} }
// Randomize Button, re-randomizes the icons // Randomize Button, re-randomizes the icons
GuiActionButton randomizeButton = new GuiActionButton(45, GuiActionButton randomizeButton = new GuiActionButton(
45,
GuiIcon.RANDOMIZE.get(), GuiIcon.RANDOMIZE.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_SELECT_DATA_RANDOMIZE_BLOCKS), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_SELECT_DATA_RANDOMIZE_BLOCKS),
new String[] { LangManager.getText(Lang.GUI_COLOR_SUBTEXT) + LangManager.getText(Lang.GUI_SELECT_DATA_RANDOMIZE_BLOCKS_DESCRIPTION) }, new String[]{LangManager.getText(Lang.GUI_COLOR_SUBTEXT) + LangManager.getText(Lang.GUI_SELECT_DATA_RANDOMIZE_BLOCKS_DESCRIPTION)},
(block, isShiftClick) -> { (block, isShiftClick) -> {
callbackList.get(callbackListPosition).execute(); // Just reopen the same inventory callbackList.get(callbackListPosition).execute(); // Just reopen the same inventory
}); });

View file

@ -1,9 +1,5 @@
package com.esophose.playerparticles.gui; package com.esophose.playerparticles.gui;
import java.util.List;
import org.bukkit.Bukkit;
import com.esophose.playerparticles.manager.LangManager; import com.esophose.playerparticles.manager.LangManager;
import com.esophose.playerparticles.manager.LangManager.Lang; import com.esophose.playerparticles.manager.LangManager.Lang;
import com.esophose.playerparticles.manager.PermissionManager; import com.esophose.playerparticles.manager.PermissionManager;
@ -12,6 +8,9 @@ import com.esophose.playerparticles.particles.PPlayer;
import com.esophose.playerparticles.particles.ParticleEffect; import com.esophose.playerparticles.particles.ParticleEffect;
import com.esophose.playerparticles.particles.ParticlePair; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.util.ParticleUtils; import com.esophose.playerparticles.util.ParticleUtils;
import org.bukkit.Bukkit;
import java.util.List;
public class GuiInventoryEditEffect extends GuiInventory { public class GuiInventoryEditEffect extends GuiInventory {
@ -21,11 +20,13 @@ public class GuiInventoryEditEffect extends GuiInventory {
// Select Effect Buttons // Select Effect Buttons
List<ParticleEffect> effectsUserHasPermissionFor = PermissionManager.getEffectsUserHasPermissionFor(pplayer.getPlayer()); List<ParticleEffect> effectsUserHasPermissionFor = PermissionManager.getEffectsUserHasPermissionFor(pplayer.getPlayer());
for (int i = 0; i < effectsUserHasPermissionFor.size(); i++) { for (int i = 0; i < effectsUserHasPermissionFor.size(); i++) {
// TODO: Paginate when there are more effects than will fit normally
ParticleEffect effect = effectsUserHasPermissionFor.get(i); ParticleEffect effect = effectsUserHasPermissionFor.get(i);
GuiActionButton selectButton = new GuiActionButton(i, GuiActionButton selectButton = new GuiActionButton(
i,
GuiIcon.EFFECT.get(effect.getName()), GuiIcon.EFFECT.get(effect.getName()),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + ParticleUtils.formatName(effect.getName()), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + ParticleUtils.formatName(effect.getName()),
new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SELECT_EFFECT_DESCRIPTION, ParticleUtils.formatName(effect.getName())) }, new String[]{LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SELECT_EFFECT_DESCRIPTION, ParticleUtils.formatName(effect.getName()))},
(button, isShiftClick) -> { (button, isShiftClick) -> {
editingParticle.setEffect(effect); editingParticle.setEffect(effect);
callbackList.get(callbackListPosition + 1).execute(); callbackList.get(callbackListPosition + 1).execute();
@ -34,9 +35,12 @@ public class GuiInventoryEditEffect extends GuiInventory {
} }
// Back Button // Back Button
GuiActionButton backButton = new GuiActionButton(INVENTORY_SIZE - 1, GuiIcon.BACK.get(), LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_BACK_BUTTON), new String[] {}, (button, isShiftClick) -> { GuiActionButton backButton = new GuiActionButton(
callbackList.get(callbackListPosition - 1).execute(); INVENTORY_SIZE - 1,
}); GuiIcon.BACK.get(),
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_BACK_BUTTON),
new String[]{},
(button, isShiftClick) -> callbackList.get(callbackListPosition - 1).execute());
this.actionButtons.add(backButton); this.actionButtons.add(backButton);
this.populate(); this.populate();

View file

@ -1,10 +1,5 @@
package com.esophose.playerparticles.gui; package com.esophose.playerparticles.gui;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import com.esophose.playerparticles.manager.DataManager; import com.esophose.playerparticles.manager.DataManager;
import com.esophose.playerparticles.manager.LangManager; import com.esophose.playerparticles.manager.LangManager;
import com.esophose.playerparticles.manager.LangManager.Lang; import com.esophose.playerparticles.manager.LangManager.Lang;
@ -13,6 +8,10 @@ import com.esophose.playerparticles.particles.PPlayer;
import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty; import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty;
import com.esophose.playerparticles.particles.ParticleGroup; import com.esophose.playerparticles.particles.ParticleGroup;
import com.esophose.playerparticles.particles.ParticlePair; import com.esophose.playerparticles.particles.ParticlePair;
import org.bukkit.Bukkit;
import java.util.ArrayList;
import java.util.List;
public class GuiInventoryEditParticle extends GuiInventory { public class GuiInventoryEditParticle extends GuiInventory {
@ -23,20 +22,22 @@ public class GuiInventoryEditParticle extends GuiInventory {
// Particle Info Icon // Particle Info Icon
String particleInfo = LangManager.getText(Lang.GUI_PARTICLE_INFO, editingParticle.getId(), editingParticle.getEffect().getName(), editingParticle.getStyle().getName(), editingParticle.getDataString()); String particleInfo = LangManager.getText(Lang.GUI_PARTICLE_INFO, editingParticle.getId(), editingParticle.getEffect().getName(), editingParticle.getStyle().getName(), editingParticle.getDataString());
GuiActionButton particleInfoIcon = new GuiActionButton(13, GuiActionButton particleInfoIcon = new GuiActionButton(
13,
GuiIcon.PARTICLES.get(), GuiIcon.PARTICLES.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_PARTICLE_NAME, editingParticle.getId()), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_PARTICLE_NAME, editingParticle.getId()),
new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + particleInfo }, new String[]{LangManager.getText(Lang.GUI_COLOR_INFO) + particleInfo},
(button, isShiftClick) -> {}); (button, isShiftClick) -> { });
this.actionButtons.add(particleInfoIcon); this.actionButtons.add(particleInfoIcon);
// Edit Effect Button // Edit Effect Button
GuiActionButton editEffectButton = new GuiActionButton(38, GuiActionButton editEffectButton = new GuiActionButton(
38,
GuiIcon.EDIT_EFFECT.get(), GuiIcon.EDIT_EFFECT.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_EDIT_EFFECT), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_EDIT_EFFECT),
new String[] { LangManager.getText(Lang.GUI_COLOR_SUBTEXT) + LangManager.getText(Lang.GUI_EDIT_EFFECT_DESCRIPTION) }, new String[]{LangManager.getText(Lang.GUI_COLOR_SUBTEXT) + LangManager.getText(Lang.GUI_EDIT_EFFECT_DESCRIPTION)},
(button, isShiftClick) -> { (button, isShiftClick) -> {
List<GuiInventoryEditFinishedCallback> callbacks = new ArrayList<GuiInventoryEditFinishedCallback>(); List<GuiInventoryEditFinishedCallback> callbacks = new ArrayList<>();
callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditParticle(pplayer, editingParticle))); callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditParticle(pplayer, editingParticle)));
callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditEffect(pplayer, editingParticle, callbacks, 1))); callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditEffect(pplayer, editingParticle, callbacks, 1)));
callbacks.add(() -> { callbacks.add(() -> {
@ -60,9 +61,9 @@ public class GuiInventoryEditParticle extends GuiInventory {
GuiActionButton editStyleButton = new GuiActionButton(40, GuiActionButton editStyleButton = new GuiActionButton(40,
GuiIcon.EDIT_STYLE.get(), GuiIcon.EDIT_STYLE.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_EDIT_STYLE), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_EDIT_STYLE),
new String[] { LangManager.getText(Lang.GUI_COLOR_SUBTEXT) + LangManager.getText(Lang.GUI_EDIT_STYLE_DESCRIPTION) }, new String[]{LangManager.getText(Lang.GUI_COLOR_SUBTEXT) + LangManager.getText(Lang.GUI_EDIT_STYLE_DESCRIPTION)},
(button, isShiftClick) -> { (button, isShiftClick) -> {
List<GuiInventoryEditFinishedCallback> callbacks = new ArrayList<GuiInventoryEditFinishedCallback>(); List<GuiInventoryEditFinishedCallback> callbacks = new ArrayList<>();
callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditParticle(pplayer, editingParticle))); callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditParticle(pplayer, editingParticle)));
callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditStyle(pplayer, editingParticle, callbacks, 1))); callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditStyle(pplayer, editingParticle, callbacks, 1)));
callbacks.add(() -> { callbacks.add(() -> {
@ -87,11 +88,11 @@ public class GuiInventoryEditParticle extends GuiInventory {
GuiActionButton editDataButton = new GuiActionButton(42, GuiActionButton editDataButton = new GuiActionButton(42,
GuiIcon.EDIT_DATA.get(), GuiIcon.EDIT_DATA.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_EDIT_DATA), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_EDIT_DATA),
usesData ? new String[] { LangManager.getText(Lang.GUI_COLOR_SUBTEXT) + LangManager.getText(Lang.GUI_EDIT_DATA_DESCRIPTION) } : usesData ? new String[]{LangManager.getText(Lang.GUI_COLOR_SUBTEXT) + LangManager.getText(Lang.GUI_EDIT_DATA_DESCRIPTION)} :
new String[] { LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_EDIT_DATA_UNAVAILABLE) }, new String[]{LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_EDIT_DATA_UNAVAILABLE)},
(button, isShiftClick) -> { (button, isShiftClick) -> {
if (usesData) { if (usesData) {
List<GuiInventoryEditFinishedCallback> callbacks = new ArrayList<GuiInventoryEditFinishedCallback>(); List<GuiInventoryEditFinishedCallback> callbacks = new ArrayList<>();
callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditParticle(pplayer, editingParticle))); callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditParticle(pplayer, editingParticle)));
callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditData(pplayer, editingParticle, callbacks, 1))); callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditData(pplayer, editingParticle, callbacks, 1)));
callbacks.add(() -> { callbacks.add(() -> {
@ -116,9 +117,12 @@ public class GuiInventoryEditParticle extends GuiInventory {
this.actionButtons.add(editDataButton); this.actionButtons.add(editDataButton);
// Back Button // Back Button
GuiActionButton backButton = new GuiActionButton(INVENTORY_SIZE - 1, GuiIcon.BACK.get(), LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_BACK_BUTTON), new String[] {}, (button, isShiftClick) -> { GuiActionButton backButton = new GuiActionButton(
GuiHandler.transition(new GuiInventoryManageParticles(pplayer)); INVENTORY_SIZE - 1,
}); GuiIcon.BACK.get(),
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_BACK_BUTTON),
new String[]{},
(button, isShiftClick) -> GuiHandler.transition(new GuiInventoryManageParticles(pplayer)));
this.actionButtons.add(backButton); this.actionButtons.add(backButton);
this.populate(); this.populate();

View file

@ -1,9 +1,5 @@
package com.esophose.playerparticles.gui; package com.esophose.playerparticles.gui;
import java.util.List;
import org.bukkit.Bukkit;
import com.esophose.playerparticles.manager.LangManager; import com.esophose.playerparticles.manager.LangManager;
import com.esophose.playerparticles.manager.LangManager.Lang; import com.esophose.playerparticles.manager.LangManager.Lang;
import com.esophose.playerparticles.manager.PermissionManager; import com.esophose.playerparticles.manager.PermissionManager;
@ -12,6 +8,9 @@ import com.esophose.playerparticles.particles.PPlayer;
import com.esophose.playerparticles.particles.ParticlePair; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.ParticleStyle; import com.esophose.playerparticles.styles.api.ParticleStyle;
import com.esophose.playerparticles.util.ParticleUtils; import com.esophose.playerparticles.util.ParticleUtils;
import org.bukkit.Bukkit;
import java.util.List;
public class GuiInventoryEditStyle extends GuiInventory { public class GuiInventoryEditStyle extends GuiInventory {
@ -22,10 +21,11 @@ public class GuiInventoryEditStyle extends GuiInventory {
List<ParticleStyle> stylesUserHasPermissionFor = PermissionManager.getStylesUserHasPermissionFor(pplayer.getPlayer()); List<ParticleStyle> stylesUserHasPermissionFor = PermissionManager.getStylesUserHasPermissionFor(pplayer.getPlayer());
for (int i = 0; i < stylesUserHasPermissionFor.size(); i++) { for (int i = 0; i < stylesUserHasPermissionFor.size(); i++) {
ParticleStyle style = stylesUserHasPermissionFor.get(i); ParticleStyle style = stylesUserHasPermissionFor.get(i);
GuiActionButton selectButton = new GuiActionButton(i, GuiActionButton selectButton = new GuiActionButton(
i,
GuiIcon.STYLE.get(style.getName()), GuiIcon.STYLE.get(style.getName()),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + ParticleUtils.formatName(style.getName()), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + ParticleUtils.formatName(style.getName()),
new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SELECT_EFFECT_DESCRIPTION, ParticleUtils.formatName(style.getName())) }, new String[]{LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SELECT_EFFECT_DESCRIPTION, ParticleUtils.formatName(style.getName()))},
(button, isShiftClick) -> { (button, isShiftClick) -> {
editingParticle.setStyle(style); editingParticle.setStyle(style);
callbackList.get(callbackListPosition + 1).execute(); callbackList.get(callbackListPosition + 1).execute();
@ -34,9 +34,12 @@ public class GuiInventoryEditStyle extends GuiInventory {
} }
// Back Button // Back Button
GuiActionButton backButton = new GuiActionButton(INVENTORY_SIZE - 1, GuiIcon.BACK.get(), LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_BACK_BUTTON), new String[] {}, (button, isShiftClick) -> { GuiActionButton backButton = new GuiActionButton(
callbackList.get(callbackListPosition - 1).execute(); INVENTORY_SIZE - 1,
}); GuiIcon.BACK.get(),
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_BACK_BUTTON),
new String[]{},
(button, isShiftClick) -> callbackList.get(callbackListPosition - 1).execute());
this.actionButtons.add(backButton); this.actionButtons.add(backButton);
this.populate(); this.populate();

View file

@ -1,10 +1,5 @@
package com.esophose.playerparticles.gui; package com.esophose.playerparticles.gui;
import java.util.Comparator;
import java.util.List;
import org.bukkit.Bukkit;
import com.esophose.playerparticles.manager.DataManager; import com.esophose.playerparticles.manager.DataManager;
import com.esophose.playerparticles.manager.LangManager; import com.esophose.playerparticles.manager.LangManager;
import com.esophose.playerparticles.manager.LangManager.Lang; import com.esophose.playerparticles.manager.LangManager.Lang;
@ -16,6 +11,10 @@ import com.esophose.playerparticles.particles.ParticleGroup;
import com.esophose.playerparticles.particles.ParticleGroupPreset; import com.esophose.playerparticles.particles.ParticleGroupPreset;
import com.esophose.playerparticles.particles.ParticlePair; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.util.ParticleUtils; import com.esophose.playerparticles.util.ParticleUtils;
import org.bukkit.Bukkit;
import java.util.Comparator;
import java.util.List;
public class GuiInventoryLoadPresetGroups extends GuiInventory { public class GuiInventoryLoadPresetGroups extends GuiInventory {
@ -64,16 +63,19 @@ public class GuiInventoryLoadPresetGroups extends GuiInventory {
if (!isEndPoint) { if (!isEndPoint) {
// Back Button // Back Button
GuiActionButton backButton = new GuiActionButton(INVENTORY_SIZE - 1, GuiIcon.BACK.get(), LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_BACK_BUTTON), new String[] {}, (button, isShiftClick) -> { GuiActionButton backButton = new GuiActionButton(
GuiHandler.transition(new GuiInventoryDefault(pplayer)); INVENTORY_SIZE - 1, GuiIcon.BACK.get(),
}); LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_BACK_BUTTON),
new String[]{},
(button, isShiftClick) -> GuiHandler.transition(new GuiInventoryDefault(pplayer)));
this.actionButtons.add(backButton); this.actionButtons.add(backButton);
} else { } else {
// Reset Particles Button // Reset Particles Button
GuiActionButton resetParticles = new GuiActionButton(49, GuiActionButton resetParticles = new GuiActionButton(
49,
GuiIcon.RESET.get(), GuiIcon.RESET.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_RESET_PARTICLES), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_RESET_PARTICLES),
new String[] { LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_RESET_PARTICLES_DESCRIPTION) }, new String[]{LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_RESET_PARTICLES_DESCRIPTION)},
(button, isShiftClick) -> { (button, isShiftClick) -> {
// Reset particles // Reset particles
DataManager.saveParticleGroup(pplayer.getUniqueId(), ParticleGroup.getDefaultGroup()); DataManager.saveParticleGroup(pplayer.getUniqueId(), ParticleGroup.getDefaultGroup());

View file

@ -0,0 +1,165 @@
package com.esophose.playerparticles.gui;
import com.esophose.playerparticles.gui.hook.PlayerChatHook;
import com.esophose.playerparticles.gui.hook.PlayerChatHookData;
import com.esophose.playerparticles.manager.DataManager;
import com.esophose.playerparticles.manager.LangManager;
import com.esophose.playerparticles.manager.LangManager.Lang;
import com.esophose.playerparticles.manager.PermissionManager;
import com.esophose.playerparticles.manager.SettingManager.GuiIcon;
import com.esophose.playerparticles.manager.SettingManager.PSetting;
import com.esophose.playerparticles.particles.PPlayer;
import com.esophose.playerparticles.particles.ParticleGroup;
import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.util.ParticleUtils;
import org.bukkit.Bukkit;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
public class GuiInventoryManageFixedEffects extends GuiInventory {
public GuiInventoryManageFixedEffects(PPlayer pplayer) {
super(pplayer, Bukkit.createInventory(pplayer.getPlayer(), INVENTORY_SIZE, LangManager.getText(Lang.GUI_MANAGE_YOUR_GROUPS)));
this.fillBorder(BorderColor.YELLOW);
int index = 10;
int nextWrap = 17;
int maxIndex = 35;
List<ParticleGroup> groups = pplayer.getParticleGroups();
groups.sort(Comparator.comparing(ParticleGroup::getName));
for (ParticleGroup group : groups) {
if (group.getName().equals(ParticleGroup.DEFAULT_NAME)) continue;
List<ParticlePair> particles = group.getParticles();
particles.sort(Comparator.comparingInt(ParticlePair::getId));
String[] lore = new String[particles.size() + 2];
lore[0] = LangManager.getText(Lang.GUI_COLOR_SUBTEXT) + LangManager.getText(Lang.GUI_CLICK_TO_LOAD, particles.size());
int i = 1;
for (ParticlePair particle : particles) {
lore[i] = LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_PARTICLE_INFO, particle.getId(), ParticleUtils.formatName(particle.getEffect().getName()), ParticleUtils.formatName(particle.getStyle().getName()), particle.getDataString());
i++;
}
lore[i] = LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_SHIFT_CLICK_TO_DELETE);
// Load Group Buttons
GuiActionButton groupButton = new GuiActionButton(
index, GuiIcon.GROUPS.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + group.getName(),
lore,
(button, isShiftClick) -> {
if (isShiftClick) {
DataManager.removeParticleGroup(pplayer.getUniqueId(), group);
this.actionButtons.remove(button);
this.inventory.setItem(button.getSlot(), null);
} else {
ParticleGroup activeGroup = pplayer.getActiveParticleGroup();
activeGroup.getParticles().clear();
for (ParticlePair particle : particles)
activeGroup.getParticles().add(particle.clone());
DataManager.saveParticleGroup(pplayer.getUniqueId(), activeGroup);
if (PSetting.GUI_CLOSE_AFTER_GROUP_SELECTED.getBoolean()) {
pplayer.getPlayer().closeInventory();
}
}
});
this.actionButtons.add(groupButton);
index++;
if (index == nextWrap) { // Loop around border
nextWrap += 9;
index += 2;
}
if (index > maxIndex) break; // Overflowed the available space
}
boolean hasReachedMax = PermissionManager.hasPlayerReachedMaxGroups(pplayer);
boolean hasParticles = !pplayer.getActiveParticles().isEmpty();
String[] lore;
if (hasReachedMax) {
lore = new String[]{
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SAVE_GROUP_DESCRIPTION),
LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_SAVE_GROUP_FULL)
};
} else if (!hasParticles) {
lore = new String[]{
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SAVE_GROUP_DESCRIPTION),
LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_SAVE_GROUP_NO_PARTICLES)
};
} else {
lore = new String[]{LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SAVE_GROUP_DESCRIPTION)};
}
// Save Group Button
GuiActionButton saveGroupButton = new GuiActionButton(
40,
GuiIcon.CREATE.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_SAVE_GROUP),
lore,
(button, isShiftClick) -> {
if (hasReachedMax || !hasParticles)
return;
PlayerChatHook.addHook(new PlayerChatHookData(pplayer.getUniqueId(), 15, (textEntered) -> {
if (textEntered == null || textEntered.equalsIgnoreCase("cancel")) {
GuiHandler.transition(new GuiInventoryManageGroups(pplayer));
} else {
String groupName = textEntered.split(" ")[0];
// Check that the groupName isn't the reserved name
if (groupName.equalsIgnoreCase(ParticleGroup.DEFAULT_NAME)) {
LangManager.sendMessage(pplayer, Lang.GROUP_RESERVED);
return;
}
// The database column can only hold up to 100 characters, cut it off there
if (groupName.length() >= 100) {
groupName = groupName.substring(0, 100);
}
// Use the existing group if available, otherwise create a new one
ParticleGroup group = pplayer.getParticleGroupByName(groupName);
boolean groupUpdated = false;
if (group == null) {
List<ParticlePair> particles = new ArrayList<ParticlePair>();
for (ParticlePair particle : pplayer.getActiveParticles())
particles.add(particle.clone()); // Make sure the ParticlePairs aren't the same references in both the active and saved group
group = new ParticleGroup(groupName, particles);
} else {
groupUpdated = true;
}
// Apply changes and notify player
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
if (groupUpdated) {
LangManager.sendMessage(pplayer, Lang.GROUP_SAVE_SUCCESS_OVERWRITE, groupName);
} else {
LangManager.sendMessage(pplayer, Lang.GROUP_SAVE_SUCCESS, groupName);
}
GuiHandler.transition(new GuiInventoryManageGroups(pplayer));
}
}));
pplayer.getPlayer().closeInventory();
});
this.actionButtons.add(saveGroupButton);
// Back Button
GuiActionButton backButton = new GuiActionButton(
INVENTORY_SIZE - 1,
GuiIcon.BACK.get(),
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_BACK_BUTTON),
new String[]{},
(button, isShiftClick) -> GuiHandler.transition(new GuiInventoryDefault(pplayer)));
this.actionButtons.add(backButton);
this.populate();
}
}

View file

@ -1,23 +1,22 @@
package com.esophose.playerparticles.gui; package com.esophose.playerparticles.gui;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import org.bukkit.Bukkit;
import com.esophose.playerparticles.gui.hook.PlayerChatHook; import com.esophose.playerparticles.gui.hook.PlayerChatHook;
import com.esophose.playerparticles.gui.hook.PlayerChatHookData; import com.esophose.playerparticles.gui.hook.PlayerChatHookData;
import com.esophose.playerparticles.manager.DataManager; import com.esophose.playerparticles.manager.DataManager;
import com.esophose.playerparticles.manager.LangManager; import com.esophose.playerparticles.manager.LangManager;
import com.esophose.playerparticles.manager.PermissionManager;
import com.esophose.playerparticles.manager.LangManager.Lang; import com.esophose.playerparticles.manager.LangManager.Lang;
import com.esophose.playerparticles.manager.PermissionManager;
import com.esophose.playerparticles.manager.SettingManager.GuiIcon; import com.esophose.playerparticles.manager.SettingManager.GuiIcon;
import com.esophose.playerparticles.manager.SettingManager.PSetting; import com.esophose.playerparticles.manager.SettingManager.PSetting;
import com.esophose.playerparticles.particles.PPlayer; import com.esophose.playerparticles.particles.PPlayer;
import com.esophose.playerparticles.particles.ParticleGroup; import com.esophose.playerparticles.particles.ParticleGroup;
import com.esophose.playerparticles.particles.ParticlePair; import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.util.ParticleUtils; import com.esophose.playerparticles.util.ParticleUtils;
import org.bukkit.Bukkit;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
public class GuiInventoryManageGroups extends GuiInventory { public class GuiInventoryManageGroups extends GuiInventory {
@ -48,7 +47,12 @@ public class GuiInventoryManageGroups extends GuiInventory {
lore[i] = LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_SHIFT_CLICK_TO_DELETE); lore[i] = LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_SHIFT_CLICK_TO_DELETE);
// Load Group Buttons // Load Group Buttons
GuiActionButton groupButton = new GuiActionButton(index, GuiIcon.GROUPS.get(), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + group.getName(), lore, (button, isShiftClick) -> { GuiActionButton groupButton = new GuiActionButton(
index,
GuiIcon.GROUPS.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + group.getName(),
lore,
(button, isShiftClick) -> {
if (isShiftClick) { if (isShiftClick) {
DataManager.removeParticleGroup(pplayer.getUniqueId(), group); DataManager.removeParticleGroup(pplayer.getUniqueId(), group);
@ -80,21 +84,22 @@ public class GuiInventoryManageGroups extends GuiInventory {
boolean hasParticles = !pplayer.getActiveParticles().isEmpty(); boolean hasParticles = !pplayer.getActiveParticles().isEmpty();
String[] lore; String[] lore;
if (hasReachedMax) { if (hasReachedMax) {
lore = new String[] { lore = new String[]{
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SAVE_GROUP_DESCRIPTION), LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SAVE_GROUP_DESCRIPTION),
LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_SAVE_GROUP_FULL) LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_SAVE_GROUP_FULL)
}; };
} else if (!hasParticles) { } else if (!hasParticles) {
lore = new String[] { lore = new String[]{
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SAVE_GROUP_DESCRIPTION), LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SAVE_GROUP_DESCRIPTION),
LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_SAVE_GROUP_NO_PARTICLES) LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_SAVE_GROUP_NO_PARTICLES)
}; };
} else { } else {
lore = new String[] { LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SAVE_GROUP_DESCRIPTION) }; lore = new String[]{LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_SAVE_GROUP_DESCRIPTION)};
} }
// Save Group Button // Save Group Button
GuiActionButton saveGroupButton = new GuiActionButton(40, GuiActionButton saveGroupButton = new GuiActionButton(
40,
GuiIcon.CREATE.get(), GuiIcon.CREATE.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_SAVE_GROUP), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_SAVE_GROUP),
lore, lore,
@ -146,9 +151,12 @@ public class GuiInventoryManageGroups extends GuiInventory {
this.actionButtons.add(saveGroupButton); this.actionButtons.add(saveGroupButton);
// Back Button // Back Button
GuiActionButton backButton = new GuiActionButton(INVENTORY_SIZE - 1, GuiIcon.BACK.get(), LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_BACK_BUTTON), new String[] {}, (button, isShiftClick) -> { GuiActionButton backButton = new GuiActionButton(
GuiHandler.transition(new GuiInventoryDefault(pplayer)); INVENTORY_SIZE - 1,
}); GuiIcon.BACK.get(),
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_BACK_BUTTON),
new String[]{},
(button, isShiftClick) -> GuiHandler.transition(new GuiInventoryDefault(pplayer)));
this.actionButtons.add(backButton); this.actionButtons.add(backButton);
this.populate(); this.populate();

View file

@ -1,22 +1,21 @@
package com.esophose.playerparticles.gui; package com.esophose.playerparticles.gui;
import com.esophose.playerparticles.manager.DataManager;
import com.esophose.playerparticles.manager.LangManager;
import com.esophose.playerparticles.manager.LangManager.Lang;
import com.esophose.playerparticles.manager.PermissionManager;
import com.esophose.playerparticles.manager.SettingManager.GuiIcon;
import com.esophose.playerparticles.particles.PPlayer;
import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty;
import com.esophose.playerparticles.particles.ParticleGroup;
import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.util.ParticleUtils;
import org.bukkit.Bukkit;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit;
import com.esophose.playerparticles.manager.DataManager;
import com.esophose.playerparticles.manager.LangManager;
import com.esophose.playerparticles.manager.PermissionManager;
import com.esophose.playerparticles.manager.LangManager.Lang;
import com.esophose.playerparticles.manager.SettingManager.GuiIcon;
import com.esophose.playerparticles.particles.PPlayer;
import com.esophose.playerparticles.particles.ParticleGroup;
import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty;
import com.esophose.playerparticles.util.ParticleUtils;
public class GuiInventoryManageParticles extends GuiInventory { public class GuiInventoryManageParticles extends GuiInventory {
public GuiInventoryManageParticles(PPlayer pplayer) { public GuiInventoryManageParticles(PPlayer pplayer) {
@ -32,10 +31,11 @@ public class GuiInventoryManageParticles extends GuiInventory {
int nextWrap = 17; int nextWrap = 17;
int maxIndex = 35; int maxIndex = 35;
for (ParticlePair particle : particles) { for (ParticlePair particle : particles) {
GuiActionButton selectButton = new GuiActionButton(index, GuiActionButton selectButton = new GuiActionButton(
index,
GuiIcon.PARTICLES.get(), GuiIcon.PARTICLES.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_PARTICLE_NAME, particle.getId()), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_PARTICLE_NAME, particle.getId()),
new String[] { new String[]{
LangManager.getText(Lang.GUI_COLOR_SUBTEXT) + LangManager.getText(Lang.GUI_CLICK_TO_EDIT_PARTICLE, particles.size()), LangManager.getText(Lang.GUI_COLOR_SUBTEXT) + LangManager.getText(Lang.GUI_CLICK_TO_EDIT_PARTICLE, particles.size()),
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_PARTICLE_INFO, particle.getId(), ParticleUtils.formatName(particle.getEffect().getName()), ParticleUtils.formatName(particle.getStyle().getName()), particle.getDataString()), LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_PARTICLE_INFO, particle.getId(), ParticleUtils.formatName(particle.getEffect().getName()), ParticleUtils.formatName(particle.getStyle().getName()), particle.getDataString()),
LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_SHIFT_CLICK_TO_DELETE) LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_SHIFT_CLICK_TO_DELETE)
@ -72,14 +72,15 @@ public class GuiInventoryManageParticles extends GuiInventory {
// Create New Particle Button // Create New Particle Button
boolean canCreate = pplayer.getActiveParticles().size() < PermissionManager.getMaxParticlesAllowed(pplayer.getPlayer()); boolean canCreate = pplayer.getActiveParticles().size() < PermissionManager.getMaxParticlesAllowed(pplayer.getPlayer());
String lore = LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_CREATE_PARTICLE_DESCRIPTION); String lore = LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_CREATE_PARTICLE_DESCRIPTION);
GuiActionButton createNewParticle = new GuiActionButton(38, GuiActionButton createNewParticle = new GuiActionButton(
38,
GuiIcon.CREATE.get(), GuiIcon.CREATE.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_CREATE_PARTICLE), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_CREATE_PARTICLE),
canCreate ? new String[] { lore } : new String[] { lore, LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_CREATE_PARTICLE_UNAVAILABLE) }, canCreate ? new String[]{lore} : new String[]{lore, LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_CREATE_PARTICLE_UNAVAILABLE)},
(button, isShiftClick) -> { (button, isShiftClick) -> {
if (!canCreate) return; if (!canCreate) return;
ParticlePair editingParticle = ParticlePair.getNextDefault(pplayer); ParticlePair editingParticle = ParticlePair.getNextDefault(pplayer);
List<GuiInventoryEditFinishedCallback> callbacks = new ArrayList<GuiInventoryEditFinishedCallback>(); List<GuiInventoryEditFinishedCallback> callbacks = new ArrayList<>();
callbacks.add(() -> GuiHandler.transition(new GuiInventoryManageParticles(pplayer))); callbacks.add(() -> GuiHandler.transition(new GuiInventoryManageParticles(pplayer)));
callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditEffect(pplayer, editingParticle, callbacks, 1))); callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditEffect(pplayer, editingParticle, callbacks, 1)));
callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditStyle(pplayer, editingParticle, callbacks, 2))); callbacks.add(() -> GuiHandler.transition(new GuiInventoryEditStyle(pplayer, editingParticle, callbacks, 2)));
@ -107,7 +108,7 @@ public class GuiInventoryManageParticles extends GuiInventory {
GuiActionButton resetParticles = new GuiActionButton(42, GuiActionButton resetParticles = new GuiActionButton(42,
GuiIcon.RESET.get(), GuiIcon.RESET.get(),
LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_RESET_PARTICLES), LangManager.getText(Lang.GUI_COLOR_ICON_NAME) + LangManager.getText(Lang.GUI_RESET_PARTICLES),
new String[] { LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_RESET_PARTICLES_DESCRIPTION) }, new String[]{LangManager.getText(Lang.GUI_COLOR_UNAVAILABLE) + LangManager.getText(Lang.GUI_RESET_PARTICLES_DESCRIPTION)},
(button, isShiftClick) -> { (button, isShiftClick) -> {
// Reset particles // Reset particles
DataManager.saveParticleGroup(pplayer.getUniqueId(), ParticleGroup.getDefaultGroup()); DataManager.saveParticleGroup(pplayer.getUniqueId(), ParticleGroup.getDefaultGroup());
@ -118,9 +119,12 @@ public class GuiInventoryManageParticles extends GuiInventory {
this.actionButtons.add(resetParticles); this.actionButtons.add(resetParticles);
// Back Button // Back Button
GuiActionButton backButton = new GuiActionButton(INVENTORY_SIZE - 1, GuiIcon.BACK.get(), LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_BACK_BUTTON), new String[] {}, (button, isShiftClick) -> { GuiActionButton backButton = new GuiActionButton(
GuiHandler.transition(new GuiInventoryDefault(pplayer)); INVENTORY_SIZE - 1,
}); GuiIcon.BACK.get(),
LangManager.getText(Lang.GUI_COLOR_INFO) + LangManager.getText(Lang.GUI_BACK_BUTTON),
new String[]{},
(button, isShiftClick) -> GuiHandler.transition(new GuiInventoryDefault(pplayer)));
this.actionButtons.add(backButton); this.actionButtons.add(backButton);
this.populate(); this.populate();

View file

@ -27,13 +27,12 @@ public class PlayerChatHook extends BukkitRunnable implements Listener {
* Initializes all the static values for this class * Initializes all the static values for this class
*/ */
public static void setup() { public static void setup() {
hooks = new HashSet<PlayerChatHookData>(); hooks = new HashSet<>();
if (hookTask != null) if (hookTask != null)
hookTask.cancel(); hookTask.cancel();
hookTask = new PlayerChatHook().runTaskTimer(PlayerParticles.getPlugin(), 0, 20); hookTask = new PlayerChatHook().runTaskTimer(PlayerParticles.getPlugin(), 0, 20);
} }
/** /**
* Called when a player sends a message in chat * Called when a player sends a message in chat
* *
@ -55,7 +54,7 @@ public class PlayerChatHook extends BukkitRunnable implements Listener {
* Ticked every second to decrease the seconds remaining on each hook * Ticked every second to decrease the seconds remaining on each hook
*/ */
public void run() { public void run() {
Set<PlayerChatHookData> hooksToRemove = new HashSet<PlayerChatHookData>(); Set<PlayerChatHookData> hooksToRemove = new HashSet<>();
for (PlayerChatHookData hook : hooks) { for (PlayerChatHookData hook : hooks) {
hook.decrementHookLength(); hook.decrementHookLength();
@ -84,7 +83,7 @@ public class PlayerChatHook extends BukkitRunnable implements Listener {
*/ */
public static void addHook(PlayerChatHookData newHook) { public static void addHook(PlayerChatHookData newHook) {
for (PlayerChatHookData hook : hooks) { for (PlayerChatHookData hook : hooks) {
if (hook.getPlayerUUID().equals(hook.getPlayerUUID())) { if (hook.getPlayerUUID().equals(newHook.getPlayerUUID())) {
hooks.remove(hook); hooks.remove(hook);
break; break;
} }

View file

@ -61,8 +61,8 @@ public class PlayerChatHookData {
* Allows simple hooking into the player chat for a specific time interval * Allows simple hooking into the player chat for a specific time interval
*/ */
@FunctionalInterface @FunctionalInterface
public static interface PlayerChatHookCallback { public interface PlayerChatHookCallback {
public void onPlayerChat(String textEntered); void onPlayerChat(String textEntered);
} }
} }

View file

@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
@ -105,8 +106,8 @@ public class DataManager {
int id = result.getInt("id"); int id = result.getInt("id");
ParticleEffect effect = ParticleEffect.fromName(result.getString("effect")); ParticleEffect effect = ParticleEffect.fromName(result.getString("effect"));
ParticleStyle style = ParticleStyle.fromName(result.getString("style")); ParticleStyle style = ParticleStyle.fromName(result.getString("style"));
Material itemMaterial = ParticleUtils.closestMatchWithFallback(result.getString("item_material")); Material itemMaterial = ParticleUtils.closestMatchWithFallback(true, result.getString("item_material"));
Material blockMaterial = ParticleUtils.closestMatchWithFallback(result.getString("block_material")); Material blockMaterial = ParticleUtils.closestMatchWithFallback(true, result.getString("block_material"));
NoteColor noteColor = new NoteColor(result.getInt("note")); NoteColor noteColor = new NoteColor(result.getInt("note"));
OrdinaryColor color = new OrdinaryColor(result.getInt("r"), result.getInt("g"), result.getInt("b")); OrdinaryColor color = new OrdinaryColor(result.getInt("r"), result.getInt("g"), result.getInt("b"));
ParticlePair particle = new ParticlePair(playerUUID, id, effect, style, itemMaterial, blockMaterial, color, noteColor); ParticlePair particle = new ParticlePair(playerUUID, id, effect, style, itemMaterial, blockMaterial, color, noteColor);
@ -123,7 +124,7 @@ public class DataManager {
// Add the particle to a new group if one didn't already exist // Add the particle to a new group if one didn't already exist
if (!groupAlreadyExists) { if (!groupAlreadyExists) {
List<ParticlePair> particles = new ArrayList<ParticlePair>(); List<ParticlePair> particles = new ArrayList<>();
particles.add(particle); particles.add(particle);
ParticleGroup newGroup = new ParticleGroup(groupName, particles); ParticleGroup newGroup = new ParticleGroup(groupName, particles);
groups.add(newGroup); groups.add(newGroup);
@ -151,8 +152,8 @@ public class DataManager {
int particleId = result.getInt("p_id"); int particleId = result.getInt("p_id");
ParticleEffect effect = ParticleEffect.fromName(result.getString("effect")); ParticleEffect effect = ParticleEffect.fromName(result.getString("effect"));
ParticleStyle style = ParticleStyle.fromName(result.getString("style")); ParticleStyle style = ParticleStyle.fromName(result.getString("style"));
Material itemMaterial = ParticleUtils.closestMatchWithFallback(result.getString("item_material")); Material itemMaterial = ParticleUtils.closestMatchWithFallback(true, result.getString("item_material"));
Material blockMaterial = ParticleUtils.closestMatchWithFallback(result.getString("block_material")); Material blockMaterial = ParticleUtils.closestMatchWithFallback(true, result.getString("block_material"));
NoteColor noteColor = new NoteColor(result.getInt("note")); NoteColor noteColor = new NoteColor(result.getInt("note"));
OrdinaryColor color = new OrdinaryColor(result.getInt("r"), result.getInt("g"), result.getInt("b")); OrdinaryColor color = new OrdinaryColor(result.getInt("r"), result.getInt("g"), result.getInt("b"));
ParticlePair particle = new ParticlePair(playerUUID, particleId, effect, style, itemMaterial, blockMaterial, color, noteColor); ParticlePair particle = new ParticlePair(playerUUID, particleId, effect, style, itemMaterial, blockMaterial, color, noteColor);
@ -171,7 +172,7 @@ public class DataManager {
} }
if (!activeGroupExists) { if (!activeGroupExists) {
ParticleGroup activeGroup = new ParticleGroup(ParticleGroup.DEFAULT_NAME, new ArrayList<ParticlePair>()); ParticleGroup activeGroup = new ParticleGroup(ParticleGroup.DEFAULT_NAME, new ArrayList<>());
saveParticleGroup(playerUUID, activeGroup); saveParticleGroup(playerUUID, activeGroup);
groups.add(activeGroup); groups.add(activeGroup);
} }
@ -194,20 +195,16 @@ public class DataManager {
* Loads all PPlayers from the database that own FixedParticleEffects * Loads all PPlayers from the database that own FixedParticleEffects
*/ */
public static void loadFixedEffects() { public static void loadFixedEffects() {
async(() -> { async(() -> PlayerParticles.getPlugin().getDBConnector().connect((connection) -> {
PlayerParticles.getPlugin().getDBConnector().connect((connection) -> {
String query = "SELECT DISTINCT owner_uuid FROM pp_fixed"; String query = "SELECT DISTINCT owner_uuid FROM pp_fixed";
try (PreparedStatement statement = connection.prepareStatement(query)) { try (PreparedStatement statement = connection.prepareStatement(query)) {
ResultSet result = statement.executeQuery(); ResultSet result = statement.executeQuery();
while (result.next()) { while (result.next()) {
UUID playerUUID = UUID.fromString(result.getString("owner_uuid")); UUID playerUUID = UUID.fromString(result.getString("owner_uuid"));
sync(() -> { sync(() -> getPPlayer(playerUUID, (pplayer) -> { }));
getPPlayer(playerUUID, (pplayer) -> { });
});
} }
} }
}); }));
});
} }
/** /**
@ -217,8 +214,7 @@ public class DataManager {
* @param particlesHidden True if the particles should be hidden, otherwise False * @param particlesHidden True if the particles should be hidden, otherwise False
*/ */
public static void updateSettingParticlesHidden(UUID playerUUID, boolean particlesHidden) { public static void updateSettingParticlesHidden(UUID playerUUID, boolean particlesHidden) {
async(() -> { async(() -> PlayerParticles.getPlugin().getDBConnector().connect((connection) -> {
PlayerParticles.getPlugin().getDBConnector().connect((connection) -> {
String updateQuery = "UPDATE pp_settings SET particles_hidden = ? WHERE player_uuid = ?"; String updateQuery = "UPDATE pp_settings SET particles_hidden = ? WHERE player_uuid = ?";
try (PreparedStatement updateStatement = connection.prepareStatement(updateQuery)) { try (PreparedStatement updateStatement = connection.prepareStatement(updateQuery)) {
updateStatement.setBoolean(1, particlesHidden); updateStatement.setBoolean(1, particlesHidden);
@ -226,12 +222,9 @@ public class DataManager {
updateStatement.executeUpdate(); updateStatement.executeUpdate();
} }
}); }));
});
getPPlayer(playerUUID, (pplayer) -> { getPPlayer(playerUUID, (pplayer) -> pplayer.setParticlesHidden(particlesHidden));
pplayer.setParticlesHidden(particlesHidden);
});
} }
/** /**
@ -241,9 +234,8 @@ public class DataManager {
* @param group The group to create/update * @param group The group to create/update
*/ */
public static void saveParticleGroup(UUID playerUUID, ParticleGroup group) { public static void saveParticleGroup(UUID playerUUID, ParticleGroup group) {
async(() -> { async(() -> PlayerParticles.getPlugin().getDBConnector().connect((connection) -> {
PlayerParticles.getPlugin().getDBConnector().connect((connection) -> { String groupUUID;
String groupUUID = null;
String groupUUIDQuery = "SELECT uuid FROM pp_group WHERE owner_uuid = ? AND name = ?"; String groupUUIDQuery = "SELECT uuid FROM pp_group WHERE owner_uuid = ? AND name = ?";
try (PreparedStatement statement = connection.prepareStatement(groupUUIDQuery)) { try (PreparedStatement statement = connection.prepareStatement(groupUUIDQuery)) {
@ -292,8 +284,7 @@ public class DataManager {
particlesStatement.executeBatch(); particlesStatement.executeBatch();
} }
}); }));
});
getPPlayer(playerUUID, (pplayer) -> { getPPlayer(playerUUID, (pplayer) -> {
for (ParticleGroup existing : pplayer.getParticleGroups()) { for (ParticleGroup existing : pplayer.getParticleGroups()) {
@ -313,8 +304,7 @@ public class DataManager {
* @param group The group to remove * @param group The group to remove
*/ */
public static void removeParticleGroup(UUID playerUUID, ParticleGroup group) { public static void removeParticleGroup(UUID playerUUID, ParticleGroup group) {
async(() -> { async(() -> PlayerParticles.getPlugin().getDBConnector().connect((connection) -> {
PlayerParticles.getPlugin().getDBConnector().connect((connection) -> {
String groupQuery = "SELECT * FROM pp_group WHERE owner_uuid = ? AND name = ?"; String groupQuery = "SELECT * FROM pp_group WHERE owner_uuid = ? AND name = ?";
String particleDeleteQuery = "DELETE FROM pp_particle WHERE group_uuid = ?"; String particleDeleteQuery = "DELETE FROM pp_particle WHERE group_uuid = ?";
String groupDeleteQuery = "DELETE FROM pp_group WHERE uuid = ?"; String groupDeleteQuery = "DELETE FROM pp_group WHERE uuid = ?";
@ -344,12 +334,9 @@ public class DataManager {
statement.executeUpdate(); statement.executeUpdate();
} }
}); }));
});
getPPlayer(playerUUID, (pplayer) -> { getPPlayer(playerUUID, (pplayer) -> pplayer.getParticleGroups().remove(group));
pplayer.getParticleGroups().remove(group);
});
} }
/** /**
@ -359,8 +346,7 @@ public class DataManager {
* @param fixedEffect The fixed effect to save * @param fixedEffect The fixed effect to save
*/ */
public static void saveFixedEffect(FixedParticleEffect fixedEffect) { public static void saveFixedEffect(FixedParticleEffect fixedEffect) {
async(() -> { async(() -> PlayerParticles.getPlugin().getDBConnector().connect((connection) -> {
PlayerParticles.getPlugin().getDBConnector().connect((connection) -> {
String particleUUID = UUID.randomUUID().toString(); String particleUUID = UUID.randomUUID().toString();
String particleQuery = "INSERT INTO pp_particle (uuid, group_uuid, id, effect, style, item_material, block_material, note, r, g, b) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; String particleQuery = "INSERT INTO pp_particle (uuid, group_uuid, id, effect, style, item_material, block_material, note, r, g, b) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
@ -391,12 +377,9 @@ public class DataManager {
statement.setDouble(7, fixedEffect.getLocation().getZ()); statement.setDouble(7, fixedEffect.getLocation().getZ());
statement.executeUpdate(); statement.executeUpdate();
} }
}); }));
});
getPPlayer(fixedEffect.getOwnerUniqueId(), (pplayer) -> { getPPlayer(fixedEffect.getOwnerUniqueId(), (pplayer) -> pplayer.addFixedEffect(fixedEffect));
pplayer.addFixedEffect(fixedEffect);
});
} }
/** /**
@ -405,8 +388,7 @@ public class DataManager {
* @param fixedEffect The fixed effect to update * @param fixedEffect The fixed effect to update
*/ */
public static void updateFixedEffect(FixedParticleEffect fixedEffect) { public static void updateFixedEffect(FixedParticleEffect fixedEffect) {
async(() -> { async(() -> PlayerParticles.getPlugin().getDBConnector().connect((connection) -> {
PlayerParticles.getPlugin().getDBConnector().connect((connection) -> {
// Update fixed effect // Update fixed effect
String fixedEffectQuery = "UPDATE pp_fixed SET xPos = ?, yPos = ?, zPos = ? WHERE owner_uuid = ? AND id = ?"; String fixedEffectQuery = "UPDATE pp_fixed SET xPos = ?, yPos = ?, zPos = ? WHERE owner_uuid = ? AND id = ?";
try (PreparedStatement statement = connection.prepareStatement(fixedEffectQuery)) { try (PreparedStatement statement = connection.prepareStatement(fixedEffectQuery)) {
@ -436,8 +418,7 @@ public class DataManager {
statement.setInt(10, fixedEffect.getId()); statement.setInt(10, fixedEffect.getId());
statement.executeUpdate(); statement.executeUpdate();
} }
}); }));
});
getPPlayer(fixedEffect.getOwnerUniqueId(), (pplayer) -> { getPPlayer(fixedEffect.getOwnerUniqueId(), (pplayer) -> {
pplayer.removeFixedEffect(fixedEffect.getId()); pplayer.removeFixedEffect(fixedEffect.getId());
@ -453,8 +434,7 @@ public class DataManager {
* @param id The id of the effect to remove * @param id The id of the effect to remove
*/ */
public static void removeFixedEffect(UUID playerUUID, int id) { public static void removeFixedEffect(UUID playerUUID, int id) {
async(() -> { async(() -> PlayerParticles.getPlugin().getDBConnector().connect((connection) -> {
PlayerParticles.getPlugin().getDBConnector().connect((connection) -> {
String particleUUID = null; String particleUUID = null;
String particleUUIDQuery = "SELECT particle_uuid FROM pp_fixed WHERE owner_uuid = ? AND id = ?"; String particleUUIDQuery = "SELECT particle_uuid FROM pp_fixed WHERE owner_uuid = ? AND id = ?";
@ -482,12 +462,9 @@ public class DataManager {
statement.executeUpdate(); statement.executeUpdate();
} }
}); }));
});
getPPlayer(playerUUID, (pplayer) -> { getPPlayer(playerUUID, (pplayer) -> pplayer.removeFixedEffect(id));
pplayer.removeFixedEffect(id);
});
} }
/** /**
@ -520,16 +497,16 @@ public class DataManager {
* Provides an easy way to run a section of code either synchronously or asynchronously using a callback * Provides an easy way to run a section of code either synchronously or asynchronously using a callback
*/ */
@FunctionalInterface @FunctionalInterface
private static interface SyncInterface { private interface SyncInterface {
public void execute(); void execute();
} }
/** /**
* Allows callbacks to be passed between configuration methods and executed for returning objects after database queries * Allows callbacks to be passed between configuration methods and executed for returning objects after database queries
*/ */
@FunctionalInterface @FunctionalInterface
public static interface ConfigurationCallback<T> { public interface ConfigurationCallback<T> {
public void execute(T obj); void execute(T obj);
} }
} }

View file

@ -375,7 +375,7 @@ public class LangManager {
File targetLangFile = new File(pluginDataFolder.getAbsolutePath() + "/lang/" + langFileName); File targetLangFile = new File(pluginDataFolder.getAbsolutePath() + "/lang/" + langFileName);
// TODO: Move this somewhere else // TODO: Move this somewhere else
Set<String> defaultLangFileNames = new HashSet<String>(); Set<String> defaultLangFileNames = new HashSet<>();
defaultLangFileNames.add("en_US.lang"); defaultLangFileNames.add("en_US.lang");
defaultLangFileNames.add("fr_FR.lang"); defaultLangFileNames.add("fr_FR.lang");
defaultLangFileNames.add("vi_VN.lang"); defaultLangFileNames.add("vi_VN.lang");

View file

@ -42,7 +42,7 @@ public class ParticleGroupPresetManager {
* Loads the preset groups from the preset_groups.yml file * Loads the preset groups from the preset_groups.yml file
*/ */
public static void reload() { public static void reload() {
presetGroups = new ArrayList<ParticleGroupPreset>(); presetGroups = new ArrayList<>();
File pluginDataFolder = PlayerParticles.getPlugin().getDataFolder(); File pluginDataFolder = PlayerParticles.getPlugin().getDataFolder();
File groupsFile = new File(pluginDataFolder.getAbsolutePath() + File.separator + FILE_NAME); File groupsFile = new File(pluginDataFolder.getAbsolutePath() + File.separator + FILE_NAME);
@ -61,7 +61,7 @@ public class ParticleGroupPresetManager {
Set<String> groupNames = groupsYaml.getKeys(false); Set<String> groupNames = groupsYaml.getKeys(false);
for (String groupName : groupNames) { for (String groupName : groupNames) {
try { try {
List<ParticlePair> particles = new ArrayList<ParticlePair>(); List<ParticlePair> particles = new ArrayList<>();
String displayName = ""; String displayName = "";
Material guiIcon = Material.ENDER_CHEST; Material guiIcon = Material.ENDER_CHEST;
String permission = ""; String permission = "";
@ -120,7 +120,7 @@ public class ParticleGroupPresetManager {
if (args[0].equalsIgnoreCase("rainbow")) { if (args[0].equalsIgnoreCase("rainbow")) {
noteColorData = new NoteColor(99); noteColorData = new NoteColor(99);
} else { } else {
int note = -1; int note;
try { try {
note = Integer.parseInt(args[0]); note = Integer.parseInt(args[0]);
} catch (Exception e) { } catch (Exception e) {
@ -139,9 +139,7 @@ public class ParticleGroupPresetManager {
if (args[0].equalsIgnoreCase("rainbow")) { if (args[0].equalsIgnoreCase("rainbow")) {
colorData = new OrdinaryColor(999, 999, 999); colorData = new OrdinaryColor(999, 999, 999);
} else { } else {
int r = -1; int r, g, b;
int g = -1;
int b = -1;
try { try {
r = Integer.parseInt(args[0]); r = Integer.parseInt(args[0]);
@ -181,7 +179,7 @@ public class ParticleGroupPresetManager {
} }
} }
particles.add(new ParticlePair(null, id, effect, style, blockData, blockData, colorData, noteColorData)); particles.add(new ParticlePair(null, id, effect, style, itemData, blockData, colorData, noteColorData));
} }
presetGroups.add(new ParticleGroupPreset(displayName, guiIcon, permission, allowPermissionOverride, new ParticleGroup(groupName, particles))); presetGroups.add(new ParticleGroupPreset(displayName, guiIcon, permission, allowPermissionOverride, new ParticleGroup(groupName, particles)));

View file

@ -32,7 +32,7 @@ public class ParticleManager extends BukkitRunnable implements Listener {
/** /**
* The list containing all the loaded PPlayer info * The list containing all the loaded PPlayer info
*/ */
private static List<PPlayer> particlePlayers = new ArrayList<PPlayer>(); private static List<PPlayer> particlePlayers = new ArrayList<>();
/** /**
* Rainbow particle effect hue and note color used for rainbow colorable effects * Rainbow particle effect hue and note color used for rainbow colorable effects
@ -106,15 +106,15 @@ public class ParticleManager extends BukkitRunnable implements Listener {
// Don't show their particles if they are in spectator mode // Don't show their particles if they are in spectator mode
// Don't spawn particles if the world doesn't allow it // Don't spawn particles if the world doesn't allow it
if (player != null && player.getGameMode() != GameMode.SPECTATOR && !PermissionManager.isWorldDisabled(player.getWorld().getName())) if (player != null && player.getGameMode() != GameMode.SPECTATOR && PermissionManager.isWorldEnabled(player.getWorld().getName()))
for (ParticlePair particles : pplayer.getActiveParticles()) for (ParticlePair particles : pplayer.getActiveParticles())
displayParticles(pplayer, particles, player.getLocation().clone().add(0, 1, 0)); this.displayParticles(pplayer, particles, player.getLocation().clone().add(0, 1, 0));
// Loop for FixedParticleEffects // Loop for FixedParticleEffects
// Don't spawn particles if the world doesn't allow it // Don't spawn particles if the world doesn't allow it
for (FixedParticleEffect effect : pplayer.getFixedParticles()) for (FixedParticleEffect effect : pplayer.getFixedParticles())
if (!PermissionManager.isWorldDisabled(effect.getLocation().getWorld().getName())) if (PermissionManager.isWorldEnabled(effect.getLocation().getWorld().getName()))
displayFixedParticleEffect(effect); this.displayFixedParticleEffect(effect);
} }
} }

View file

@ -37,7 +37,7 @@ public class PermissionManager {
private final String permissionString; private final String permissionString;
private PPermission(String permissionString) { PPermission(String permissionString) {
this.permissionString = permissionString; this.permissionString = permissionString;
} }
@ -149,13 +149,13 @@ public class PermissionManager {
} }
/** /**
* Checks if a world is disabled for particles to spawn in * Checks if a world is enabled for particles to spawn in
* *
* @param world The world name to check * @param world The world name to check
* @return True if the world is disabled * @return True if the world is disabled
*/ */
public static boolean isWorldDisabled(String world) { public static boolean isWorldEnabled(String world) {
return getDisabledWorlds().contains(world); return !getDisabledWorlds().contains(world);
} }
/** /**
@ -200,7 +200,7 @@ public class PermissionManager {
* @return A String List of all effect names the given player has permission for * @return A String List of all effect names the given player has permission for
*/ */
public static List<String> getEffectNamesUserHasPermissionFor(Player p) { public static List<String> getEffectNamesUserHasPermissionFor(Player p) {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<>();
for (ParticleEffect pe : ParticleEffect.getSupportedEffects()) for (ParticleEffect pe : ParticleEffect.getSupportedEffects())
if (hasEffectPermission(p, pe)) if (hasEffectPermission(p, pe))
list.add(pe.getName()); list.add(pe.getName());
@ -214,7 +214,7 @@ public class PermissionManager {
* @return A String List of all style names the given player has permission for * @return A String List of all style names the given player has permission for
*/ */
public static List<String> getStyleNamesUserHasPermissionFor(Player p) { public static List<String> getStyleNamesUserHasPermissionFor(Player p) {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<>();
for (ParticleStyle ps : ParticleStyleManager.getStyles()) for (ParticleStyle ps : ParticleStyleManager.getStyles())
if (hasStylePermission(p, ps)) if (hasStylePermission(p, ps))
list.add(ps.getName()); list.add(ps.getName());
@ -228,7 +228,7 @@ public class PermissionManager {
* @return A String List of all fixable style names the given player has permission for * @return A String List of all fixable style names the given player has permission for
*/ */
public static List<String> getFixableStyleNamesUserHasPermissionFor(Player p) { public static List<String> getFixableStyleNamesUserHasPermissionFor(Player p) {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<>();
for (ParticleStyle ps : ParticleStyleManager.getStyles()) for (ParticleStyle ps : ParticleStyleManager.getStyles())
if (ps.canBeFixed() && hasStylePermission(p, ps)) if (ps.canBeFixed() && hasStylePermission(p, ps))
list.add(ps.getName()); list.add(ps.getName());
@ -242,7 +242,7 @@ public class PermissionManager {
* @return A List of all effects the given player has permission for * @return A List of all effects the given player has permission for
*/ */
public static List<ParticleEffect> getEffectsUserHasPermissionFor(Player p) { public static List<ParticleEffect> getEffectsUserHasPermissionFor(Player p) {
List<ParticleEffect> list = new ArrayList<ParticleEffect>(); List<ParticleEffect> list = new ArrayList<>();
for (ParticleEffect pe : ParticleEffect.getSupportedEffects()) for (ParticleEffect pe : ParticleEffect.getSupportedEffects())
if (hasEffectPermission(p, pe)) if (hasEffectPermission(p, pe))
list.add(pe); list.add(pe);
@ -256,7 +256,7 @@ public class PermissionManager {
* @return A List of all styles the given player has permission for * @return A List of all styles the given player has permission for
*/ */
public static List<ParticleStyle> getStylesUserHasPermissionFor(Player p) { public static List<ParticleStyle> getStylesUserHasPermissionFor(Player p) {
List<ParticleStyle> list = new ArrayList<ParticleStyle>(); List<ParticleStyle> list = new ArrayList<>();
for (ParticleStyle ps : ParticleStyleManager.getStyles()) for (ParticleStyle ps : ParticleStyleManager.getStyles())
if (hasStylePermission(p, ps)) if (hasStylePermission(p, ps))
list.add(ps); list.add(ps);

View file

@ -54,6 +54,7 @@ public class SettingManager {
DATABASE_NAME(PSettingType.STRING), DATABASE_NAME(PSettingType.STRING),
DATABASE_USER_NAME(PSettingType.STRING), DATABASE_USER_NAME(PSettingType.STRING),
DATABASE_USER_PASSWORD(PSettingType.STRING), DATABASE_USER_PASSWORD(PSettingType.STRING),
DATABASE_USE_SSL(PSettingType.BOOLEAN),
MAX_FIXED_EFFECTS(PSettingType.INTEGER), MAX_FIXED_EFFECTS(PSettingType.INTEGER),
MAX_FIXED_EFFECT_CREATION_DISTANCE(PSettingType.INTEGER), MAX_FIXED_EFFECT_CREATION_DISTANCE(PSettingType.INTEGER),
@ -71,7 +72,7 @@ public class SettingManager {
private final PSettingType settingType; private final PSettingType settingType;
private Object value = null; private Object value = null;
private PSetting(PSettingType settingType) { PSetting(PSettingType settingType) {
this.settingType = settingType; this.settingType = settingType;
} }
@ -199,8 +200,8 @@ public class SettingManager {
private Map<String, Material> materials; private Map<String, Material> materials;
private GuiIcon() { GuiIcon() {
this.materials = new HashMap<String, Material>(); this.materials = new HashMap<>();
} }
/** /**
@ -264,7 +265,7 @@ public class SettingManager {
* Resets the setting's value so it will be fetched from the config the next time it's needed * Resets the setting's value so it will be fetched from the config the next time it's needed
*/ */
private void resetDefault() { private void resetDefault() {
this.materials = new HashMap<String, Material>(); this.materials = new HashMap<>();
} }
} }

View file

@ -168,7 +168,7 @@ public class PPlayer {
* @return A List of ParticlePairs with a matching style * @return A List of ParticlePairs with a matching style
*/ */
public List<ParticlePair> getActiveParticlesForStyle(ParticleStyle style) { public List<ParticlePair> getActiveParticlesForStyle(ParticleStyle style) {
List<ParticlePair> matches = new ArrayList<ParticlePair>(); List<ParticlePair> matches = new ArrayList<>();
for (ParticlePair pair : this.getActiveParticles()) for (ParticlePair pair : this.getActiveParticles())
if (pair.getStyle().equals(style)) if (pair.getStyle().equals(style))
matches.add(pair); matches.add(pair);
@ -216,7 +216,7 @@ public class PPlayer {
* @return A List of Integer ids this player's fixed effects have * @return A List of Integer ids this player's fixed effects have
*/ */
public List<Integer> getFixedEffectIds() { public List<Integer> getFixedEffectIds() {
List<Integer> ids = new ArrayList<Integer>(); List<Integer> ids = new ArrayList<>();
for (FixedParticleEffect fixedEffect : this.fixedParticles) for (FixedParticleEffect fixedEffect : this.fixedParticles)
ids.add(fixedEffect.getId()); ids.add(fixedEffect.getId());
return ids; return ids;

View file

@ -6,11 +6,11 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit;
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 org.bukkit.scheduler.BukkitRunnable;
import com.esophose.playerparticles.PlayerParticles; import com.esophose.playerparticles.PlayerParticles;
import com.esophose.playerparticles.manager.DataManager; import com.esophose.playerparticles.manager.DataManager;
@ -19,31 +19,29 @@ import com.esophose.playerparticles.manager.SettingManager.PSetting;
public class PPlayerMovementListener implements Listener { public class PPlayerMovementListener implements Listener {
private static final int CHECK_INTERVAL = 3; private static final int CHECK_INTERVAL = 3;
private Map<UUID, Integer> timeSinceLastMovement = new HashMap<UUID, Integer>(); private Map<UUID, Integer> timeSinceLastMovement = new HashMap<>();
public PPlayerMovementListener() { public PPlayerMovementListener() {
new BukkitRunnable() { Bukkit.getScheduler().runTaskTimer(PlayerParticles.getPlugin(), () -> {
public void run() {
if (!PSetting.TOGGLE_ON_MOVE.getBoolean()) return; if (!PSetting.TOGGLE_ON_MOVE.getBoolean()) return;
List<UUID> toRemove = new ArrayList<UUID>(); List<UUID> toRemove = new ArrayList<>();
for (UUID uuid : timeSinceLastMovement.keySet()) { for (UUID uuid : this.timeSinceLastMovement.keySet()) {
PPlayer pplayer = DataManager.getPPlayer(uuid); PPlayer pplayer = DataManager.getPPlayer(uuid);
if (pplayer == null) { if (pplayer == null) {
toRemove.add(uuid); toRemove.add(uuid);
} else { } else {
int standingTime = timeSinceLastMovement.get(uuid); int standingTime = this.timeSinceLastMovement.get(uuid);
pplayer.setMoving(standingTime < PSetting.TOGGLE_ON_MOVE_DELAY.getInt()); pplayer.setMoving(standingTime < PSetting.TOGGLE_ON_MOVE_DELAY.getInt());
if (standingTime < PSetting.TOGGLE_ON_MOVE_DELAY.getInt()) if (standingTime < PSetting.TOGGLE_ON_MOVE_DELAY.getInt())
timeSinceLastMovement.replace(uuid, standingTime + CHECK_INTERVAL); this.timeSinceLastMovement.replace(uuid, standingTime + CHECK_INTERVAL);
} }
} }
for (UUID uuid : toRemove) for (UUID uuid : toRemove)
timeSinceLastMovement.remove(uuid); this.timeSinceLastMovement.remove(uuid);
} }, 0, CHECK_INTERVAL);
}.runTaskTimer(PlayerParticles.getPlugin(), 0, CHECK_INTERVAL);
} }
/** /**
@ -57,10 +55,10 @@ public class PPlayerMovementListener implements Listener {
if (event.getTo().getBlockX() == event.getFrom().getBlockX() && event.getTo().getBlockY() == event.getFrom().getBlockY() && event.getTo().getBlockZ() == event.getFrom().getBlockZ()) return; if (event.getTo().getBlockX() == event.getFrom().getBlockX() && event.getTo().getBlockY() == event.getFrom().getBlockY() && event.getTo().getBlockZ() == event.getFrom().getBlockZ()) return;
UUID playerUUID = event.getPlayer().getUniqueId(); UUID playerUUID = event.getPlayer().getUniqueId();
if (!timeSinceLastMovement.containsKey(playerUUID)) { if (!this.timeSinceLastMovement.containsKey(playerUUID)) {
timeSinceLastMovement.put(playerUUID, 0); this.timeSinceLastMovement.put(playerUUID, 0);
} else { } else {
timeSinceLastMovement.replace(playerUUID, 0); this.timeSinceLastMovement.replace(playerUUID, 0);
} }
} }

View file

@ -32,7 +32,10 @@ public enum ParticleEffect {
BUBBLE("WATER_BUBBLE", "WATER_BUBBLE"), BUBBLE("WATER_BUBBLE", "WATER_BUBBLE"),
BUBBLE_COLUMN_UP("BUBBLE_COLUMN_UP", null), BUBBLE_COLUMN_UP("BUBBLE_COLUMN_UP", null),
BUBBLE_POP("BUBBLE_POP", null), BUBBLE_POP("BUBBLE_POP", null),
CAMPFIRE_COSY_SMOKE("CAMPFIRE_COSY_SMOKE", null),
CAMPFIRE_SIGNAL_SMOKE("CAMPFIRE_SIGNAL_SMOKE", null),
CLOUD("CLOUD", "CLOUD"), CLOUD("CLOUD", "CLOUD"),
COMPOSTER("COMPOSTER", null),
CRIT("CRIT", "CRIT"), CRIT("CRIT", "CRIT"),
CURRENT_DOWN("CURRENT_DOWN", null), CURRENT_DOWN("CURRENT_DOWN", null),
DAMAGE_INDICATOR("DAMAGE_INDICATOR", "DAMAGE_INDICATOR"), DAMAGE_INDICATOR("DAMAGE_INDICATOR", "DAMAGE_INDICATOR"),
@ -49,9 +52,12 @@ public enum ParticleEffect {
EXPLOSION("EXPLOSION_LARGE", "EXPLOSION_LARGE"), EXPLOSION("EXPLOSION_LARGE", "EXPLOSION_LARGE"),
EXPLOSION_EMITTER("EXPLOSION_HUGE", "EXPLOSION_HUGE"), EXPLOSION_EMITTER("EXPLOSION_HUGE", "EXPLOSION_HUGE"),
FALLING_DUST("FALLING_DUST", "FALLING_DUST", ParticleProperty.REQUIRES_MATERIAL_DATA), FALLING_DUST("FALLING_DUST", "FALLING_DUST", ParticleProperty.REQUIRES_MATERIAL_DATA),
FALLING_LAVA("FALLING_LAVA", null),
FALLING_WATER("FALLING_WATER", null),
FIREWORK("FIREWORKS_SPARK", "FIREWORKS_SPARK"), FIREWORK("FIREWORKS_SPARK", "FIREWORKS_SPARK"),
FISHING("WATER_WAKE", "WATER_WAKE"), FISHING("WATER_WAKE", "WATER_WAKE"),
FLAME("FLAME", "FLAME"), FLAME("FLAME", "FLAME"),
// FLASH("FLASH", null), // Also no thank you
FOOTSTEP(null, "FOOTSTEP"), // Removed in Minecraft 1.13 :( FOOTSTEP(null, "FOOTSTEP"), // Removed in Minecraft 1.13 :(
HAPPY_VILLAGER("VILLAGER_HAPPY", "VILLAGER_HAPPY"), HAPPY_VILLAGER("VILLAGER_HAPPY", "VILLAGER_HAPPY"),
HEART("HEART", "HEART"), HEART("HEART", "HEART"),
@ -59,6 +65,7 @@ public enum ParticleEffect {
ITEM("ITEM_CRACK", "ITEM_CRACK", ParticleProperty.REQUIRES_MATERIAL_DATA), ITEM("ITEM_CRACK", "ITEM_CRACK", ParticleProperty.REQUIRES_MATERIAL_DATA),
ITEM_SLIME("SLIME", "SLIME"), ITEM_SLIME("SLIME", "SLIME"),
ITEM_SNOWBALL("SNOWBALL", "SNOWBALL"), ITEM_SNOWBALL("SNOWBALL", "SNOWBALL"),
LANDING_LAVA("LANDING_LAVA", null),
LARGE_SMOKE("SMOKE_LARGE", "SMOKE_LARGE"), LARGE_SMOKE("SMOKE_LARGE", "SMOKE_LARGE"),
LAVA("LAVA", "LAVA"), LAVA("LAVA", "LAVA"),
MYCELIUM("TOWN_AURA", "TOWN_AURA"), MYCELIUM("TOWN_AURA", "TOWN_AURA"),
@ -68,6 +75,7 @@ public enum ParticleEffect {
PORTAL("PORTAL", "PORTAL"), PORTAL("PORTAL", "PORTAL"),
RAIN("WATER_DROP", "WATER_DROP"), RAIN("WATER_DROP", "WATER_DROP"),
SMOKE("SMOKE_NORMAL", "SMOKE_NORMAL"), SMOKE("SMOKE_NORMAL", "SMOKE_NORMAL"),
SNEEZE("SNEEZE", null),
SPELL("SPELL", "SPELL"), // The Minecraft internal name for this is actually "effect", but that's the command name, so it's SPELL for the plugin instead SPELL("SPELL", "SPELL"), // The Minecraft internal name for this is actually "effect", but that's the command name, so it's SPELL for the plugin instead
SPIT("SPIT", "SPIT"), SPIT("SPIT", "SPIT"),
SPLASH("WATER_SPLASH", "WATER_SPLASH"), SPLASH("WATER_SPLASH", "WATER_SPLASH"),
@ -78,7 +86,7 @@ public enum ParticleEffect {
WITCH("SPELL_WITCH", "SPELL_WTICH"); WITCH("SPELL_WITCH", "SPELL_WTICH");
public static boolean VERSION_13; // This is a particle unique to Minecraft 1.13, this is a reliable way of telling what server version is running public static boolean VERSION_13; // This is a particle unique to Minecraft 1.13, this is a reliable way of telling what server version is running
private static final Map<String, ParticleEffect> NAME_MAP = new HashMap<String, ParticleEffect>(); private static final Map<String, ParticleEffect> NAME_MAP = new HashMap<>();
private static Constructor<?> DustOptions_CONSTRUCTOR; private static Constructor<?> DustOptions_CONSTRUCTOR;
private static Method createBlockData_METHOD; private static Method createBlockData_METHOD;
private final Particle internalEnum; private final Particle internalEnum;
@ -87,12 +95,13 @@ public enum ParticleEffect {
// Initialize map for quick name and id lookup // Initialize map for quick name and id lookup
// Initialize Minecraft 1.13 related variables // Initialize Minecraft 1.13 related variables
static { static {
for (ParticleEffect effect : values()) { for (ParticleEffect effect : values())
if (effect.isSupported())
NAME_MAP.put(effect.getName(), effect); NAME_MAP.put(effect.getName(), effect);
}
try { try {
VERSION_13 = Particle.valueOf("NAUTILUS") != null; Particle.valueOf("NAUTILUS");
VERSION_13 = true;
DustOptions_CONSTRUCTOR = Particle.REDSTONE.getDataType().getConstructor(Color.class, float.class); DustOptions_CONSTRUCTOR = Particle.REDSTONE.getDataType().getConstructor(Color.class, float.class);
createBlockData_METHOD = Material.class.getMethod("createBlockData"); createBlockData_METHOD = Material.class.getMethod("createBlockData");
} catch (Exception e) { } catch (Exception e) {
@ -109,7 +118,7 @@ public enum ParticleEffect {
* @param enumNameLegacy Name of the Particle Enum when the server version is less than 1.13 * @param enumNameLegacy Name of the Particle Enum when the server version is less than 1.13
* @param properties Properties of this particle effect * @param properties Properties of this particle effect
*/ */
private ParticleEffect(String enumName, String enumNameLegacy, ParticleProperty... properties) { ParticleEffect(String enumName, String enumNameLegacy, ParticleProperty... properties) {
this.properties = Arrays.asList(properties); this.properties = Arrays.asList(properties);
Particle matchingEnum = null; Particle matchingEnum = null;
@ -167,9 +176,10 @@ public enum ParticleEffect {
* @return Supported effects * @return Supported effects
*/ */
public static List<ParticleEffect> getSupportedEffects() { public static List<ParticleEffect> getSupportedEffects() {
List<ParticleEffect> effects = new ArrayList<ParticleEffect>(); List<ParticleEffect> effects = new ArrayList<>();
for (ParticleEffect pe : values()) for (ParticleEffect pe : values())
if (pe.isSupported()) effects.add(pe); if (pe.isSupported())
effects.add(pe);
return effects; return effects;
} }
@ -222,12 +232,12 @@ public enum ParticleEffect {
* @throws ParticleDataException If the particle effect requires additional data * @throws ParticleDataException If the particle effect requires additional data
*/ */
public void display(double offsetX, double offsetY, double offsetZ, double speed, int amount, Location center, boolean isFixedEffect) throws ParticleDataException { public void display(double offsetX, double offsetY, double offsetZ, double speed, int amount, Location center, boolean isFixedEffect) throws ParticleDataException {
if (hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) { if (this.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
throw new ParticleDataException("This particle effect requires additional data"); throw new ParticleDataException("This particle effect requires additional data");
} }
for (Player player : getPlayersInRange(center, isFixedEffect)) { for (Player player : this.getPlayersInRange(center, isFixedEffect)) {
player.spawnParticle(internalEnum, center.getX(), center.getY(), center.getZ(), amount, offsetX, offsetY, offsetZ, speed); player.spawnParticle(this.internalEnum, center.getX(), center.getY(), center.getZ(), amount, offsetX, offsetY, offsetZ, speed);
} }
} }
@ -240,7 +250,7 @@ public enum ParticleEffect {
* @throws ParticleColorException If the particle effect is not colorable or the color type is incorrect * @throws ParticleColorException If the particle effect is not colorable or the color type is incorrect
*/ */
public void display(ParticleColor color, Location center, boolean isFixedEffect) throws ParticleColorException { public void display(ParticleColor color, Location center, boolean isFixedEffect) throws ParticleColorException {
if (!hasProperty(ParticleProperty.COLORABLE)) { if (!this.hasProperty(ParticleProperty.COLORABLE)) {
throw new ParticleColorException("This particle effect is not colorable"); throw new ParticleColorException("This particle effect is not colorable");
} }
@ -249,17 +259,15 @@ public enum ParticleEffect {
Object dustData = null; Object dustData = null;
try { // The DustData class doesn't exist in Minecraft versions less than 1.13... so this is disgusting... but it works great try { // The DustData class doesn't exist in Minecraft versions less than 1.13... so this is disgusting... but it works great
dustData = DustOptions_CONSTRUCTOR.newInstance(Color.fromRGB(dustColor.getRed(), dustColor.getGreen(), dustColor.getBlue()), 1); // Wait, you can change the size of these now??? AWESOME! I might implement this in the future! dustData = DustOptions_CONSTRUCTOR.newInstance(Color.fromRGB(dustColor.getRed(), dustColor.getGreen(), dustColor.getBlue()), 1); // Wait, you can change the size of these now??? AWESOME! I might implement this in the future!
} catch (Exception e) { } catch (Exception ignored) { }
} for (Player player : this.getPlayersInRange(center, isFixedEffect)) {
player.spawnParticle(this.internalEnum, center.getX(), center.getY(), center.getZ(), 1, 0, 0, 0, 0, dustData);
for (Player player : getPlayersInRange(center, isFixedEffect)) {
player.spawnParticle(internalEnum, center.getX(), center.getY(), center.getZ(), 1, 0, 0, 0, 0, dustData);
} }
} else { } else {
for (Player player : getPlayersInRange(center, isFixedEffect)) { for (Player player : this.getPlayersInRange(center, isFixedEffect)) {
// Minecraft clients require that you pass a non-zero value if the Red value should be zero // Minecraft clients require that you pass a non-zero value if the Red value should be zero
player.spawnParticle(internalEnum, center.getX(), center.getY(), center.getZ(), 0, this == ParticleEffect.DUST && color.getValueX() == 0 ? Float.MIN_VALUE : color.getValueX(), color.getValueY(), color.getValueZ(), 1); player.spawnParticle(this.internalEnum, center.getX(), center.getY(), center.getZ(), 0, this == ParticleEffect.DUST && color.getValueX() == 0 ? Float.MIN_VALUE : color.getValueX(), color.getValueY(), color.getValueZ(), 1);
} }
} }
} }
@ -280,27 +288,23 @@ public enum ParticleEffect {
* @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(Material spawnMaterial, double offsetX, double offsetY, double offsetZ, double speed, int amount, Location center, boolean isFixedEffect) throws ParticleDataException { public void display(Material spawnMaterial, double offsetX, double offsetY, double offsetZ, double speed, int amount, Location center, boolean isFixedEffect) throws ParticleDataException {
if (!hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) { if (!this.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");
} }
Object extraData = null; Object extraData = null;
if (internalEnum.getDataType().getTypeName().equals("org.bukkit.block.data.BlockData")) { if (this.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(spawnMaterial); extraData = createBlockData_METHOD.invoke(spawnMaterial);
} catch (Exception e) { } catch (Exception ignored) { }
} else if (this.internalEnum.getDataType() == ItemStack.class) {
}
} else if (internalEnum.getDataType() == ItemStack.class) {
extraData = new ItemStack(spawnMaterial); extraData = new ItemStack(spawnMaterial);
} else if (internalEnum.getDataType() == MaterialData.class) { } else if (this.internalEnum.getDataType() == MaterialData.class) {
extraData = new MaterialData(spawnMaterial); // Deprecated, only used in versions < 1.13 extraData = new MaterialData(spawnMaterial); // Deprecated, only used in versions < 1.13
} else {
extraData = null;
} }
for (Player player : getPlayersInRange(center, isFixedEffect)) for (Player player : this.getPlayersInRange(center, isFixedEffect))
player.spawnParticle(internalEnum, center.getX(), center.getY(), center.getZ(), amount, offsetX, offsetY, offsetZ, speed, extraData); player.spawnParticle(this.internalEnum, center.getX(), center.getY(), center.getZ(), amount, offsetX, offsetY, offsetZ, speed, extraData);
} }
/** /**
@ -311,7 +315,7 @@ public enum ParticleEffect {
* @return A List of Players within the particle display range * @return A List of Players within the particle display range
*/ */
private List<Player> getPlayersInRange(Location center, boolean isFixedEffect) { private List<Player> getPlayersInRange(Location center, boolean isFixedEffect) {
List<Player> players = new ArrayList<Player>(); List<Player> players = new ArrayList<>();
int range = !isFixedEffect ? PSetting.PARTICLE_RENDER_RANGE_PLAYER.getInt() : PSetting.PARTICLE_RENDER_RANGE_FIXED_EFFECT.getInt(); int range = !isFixedEffect ? PSetting.PARTICLE_RENDER_RANGE_PLAYER.getInt() : PSetting.PARTICLE_RENDER_RANGE_FIXED_EFFECT.getInt();
for (PPlayer pplayer : ParticleManager.getPPlayers()) { for (PPlayer pplayer : ParticleManager.getPPlayers()) {
@ -333,7 +337,7 @@ public enum ParticleEffect {
* @author DarkBlade12 * @author DarkBlade12
* @since 1.7 * @since 1.7
*/ */
public static enum ParticleProperty { public enum ParticleProperty {
/** /**
* The particle effect requires block or item material data to be displayed * The particle effect requires block or item material data to be displayed
*/ */
@ -341,7 +345,7 @@ public enum ParticleEffect {
/** /**
* The particle effect uses the offsets as color values * The particle effect uses the offsets as color values
*/ */
COLORABLE; COLORABLE
} }
/** /**
@ -438,7 +442,7 @@ public enum ParticleEffect {
* @return The red value * @return The red value
*/ */
public int getRed() { public int getRed() {
return red; return this.red;
} }
/** /**
@ -447,7 +451,7 @@ public enum ParticleEffect {
* @return The green value * @return The green value
*/ */
public int getGreen() { public int getGreen() {
return green; return this.green;
} }
/** /**
@ -456,7 +460,7 @@ public enum ParticleEffect {
* @return The blue value * @return The blue value
*/ */
public int getBlue() { public int getBlue() {
return blue; return this.blue;
} }
/** /**
@ -466,8 +470,8 @@ public enum ParticleEffect {
*/ */
@Override @Override
public float getValueX() { public float getValueX() {
if (red == 999 || red == 998) return 0F; if (this.red == 999 || this.red == 998) return 0F;
return (float) red / 255F; return (float) this.red / 255F;
} }
/** /**
@ -477,8 +481,8 @@ public enum ParticleEffect {
*/ */
@Override @Override
public float getValueY() { public float getValueY() {
if (green == 999 || green == 998) return 0F; if (this.green == 999 || this.green == 998) return 0F;
return (float) green / 255F; return (float) this.green / 255F;
} }
/** /**
@ -488,8 +492,8 @@ public enum ParticleEffect {
*/ */
@Override @Override
public float getValueZ() { public float getValueZ() {
if (blue == 999 || blue == 998) return 0F; if (this.blue == 999 || this.blue == 998) return 0F;
return (float) blue / 255F; return (float) this.blue / 255F;
} }
} }

View file

@ -40,7 +40,7 @@ public class ParticleGroup {
* @return The default empty active ParticleGroup * @return The default empty active ParticleGroup
*/ */
public static ParticleGroup getDefaultGroup() { public static ParticleGroup getDefaultGroup() {
return new ParticleGroup(DEFAULT_NAME, new ArrayList<ParticlePair>()); return new ParticleGroup(DEFAULT_NAME, new ArrayList<>());
} }
} }

View file

@ -280,7 +280,7 @@ public class ParticlePair {
-1, -1,
ParticleEffect.FLAME, ParticleEffect.FLAME,
DefaultStyles.NORMAL, DefaultStyles.NORMAL,
ParticleUtils.closestMatchWithFallback("IRON_SHOVEL", "IRON_SPADE"), ParticleUtils.closestMatchWithFallback(true, "IRON_SHOVEL", "IRON_SPADE"),
Material.STONE, Material.STONE,
new OrdinaryColor(0, 0, 0), new OrdinaryColor(0, 0, 0),
new NoteColor(0)); // @formatter:on new NoteColor(0)); // @formatter:on
@ -297,7 +297,7 @@ public class ParticlePair {
pplayer.getNextActiveParticleId(), pplayer.getNextActiveParticleId(),
ParticleEffect.FLAME, ParticleEffect.FLAME,
DefaultStyles.NORMAL, DefaultStyles.NORMAL,
ParticleUtils.closestMatchWithFallback("IRON_SHOVEL", "IRON_SPADE"), ParticleUtils.closestMatchWithFallback(true, "IRON_SHOVEL", "IRON_SPADE"),
Material.STONE, Material.STONE,
new OrdinaryColor(0, 0, 0), new OrdinaryColor(0, 0, 0),
new NoteColor(0)); // @formatter:on new NoteColor(0)); // @formatter:on

View file

@ -41,13 +41,13 @@ public class ParticleStyleCelebration implements ParticleStyle {
Random random = new Random(); Random random = new Random();
for (PPlayer pplayer : ParticleManager.getPPlayers()) { for (PPlayer pplayer : ParticleManager.getPPlayers()) {
Player player = pplayer.getPlayer(); Player player = pplayer.getPlayer();
if (player != null && player.getGameMode() != GameMode.SPECTATOR && !PermissionManager.isWorldDisabled(player.getWorld().getName())) if (player != null && player.getGameMode() != GameMode.SPECTATOR && PermissionManager.isWorldEnabled(player.getWorld().getName()))
for (ParticlePair particle : pplayer.getActiveParticles()) for (ParticlePair particle : pplayer.getActiveParticles())
if (particle.getStyle() == this) if (particle.getStyle() == this)
spawnFirework(player.getLocation(), pplayer, particle, random); spawnFirework(player.getLocation(), pplayer, particle, random);
for (FixedParticleEffect fixedEffect : pplayer.getFixedParticles()) for (FixedParticleEffect fixedEffect : pplayer.getFixedParticles())
if (fixedEffect.getParticlePair().getStyle() == this && !PermissionManager.isWorldDisabled(fixedEffect.getLocation().getWorld().getName())) if (fixedEffect.getParticlePair().getStyle() == this && PermissionManager.isWorldEnabled(fixedEffect.getLocation().getWorld().getName()))
spawnFirework(fixedEffect.getLocation(), pplayer, fixedEffect.getParticlePair(), random); spawnFirework(fixedEffect.getLocation(), pplayer, fixedEffect.getParticlePair(), random);
} }
} }

View file

@ -15,40 +15,40 @@ public interface ParticleStyle {
* @param location The central location of the particles * @param location The central location of the particles
* @return A List of PParticles to spawn * @return A List of PParticles to spawn
*/ */
public List<PParticle> getParticles(ParticlePair particle, Location location); 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
*/ */
public void updateTimers(); void updateTimers();
/** /**
* The name of the style * The name of the style
* *
* @return The style's name * @return The style's name
*/ */
public String getName(); String getName();
/** /**
* Gets if the style can be used in a FixedParticleEffect * Gets if the style can be used in a FixedParticleEffect
* *
* @return If the style can be used in a FixedParticleEffect * @return If the style can be used in a FixedParticleEffect
*/ */
public boolean canBeFixed(); boolean canBeFixed();
/** /**
* Gets if the style can be replaced with DefaultStyles.FEET when the player is moving * Gets if the style can be replaced with DefaultStyles.FEET when the player is moving
* *
* @return True if it can be, otherwise False * @return True if it can be, otherwise False
*/ */
public boolean canToggleWithMovement(); boolean canToggleWithMovement();
/** /**
* The Y-axis offset to be applied when using '/pp fixed create looking' * The Y-axis offset to be applied when using '/pp fixed create looking'
* *
* @return How far to move the style up or down to get it centered on the block properly * @return How far to move the style up or down to get it centered on the block properly
*/ */
public double getFixedEffectOffset(); double getFixedEffectOffset();
/** /**
* Gets the ParticleStyle with the name given, returns null if not found * Gets the ParticleStyle with the name given, returns null if not found
@ -56,7 +56,7 @@ public interface ParticleStyle {
* @param styleName The name of the style to search for * @param styleName The name of the style to search for
* @return The ParticleStyle with a matching name * @return The ParticleStyle with a matching name
*/ */
public static ParticleStyle fromName(String styleName) { static ParticleStyle fromName(String styleName) {
for (ParticleStyle style : ParticleStyleManager.getStyles()) for (ParticleStyle style : ParticleStyleManager.getStyles())
if (style.getName().equalsIgnoreCase(styleName)) if (style.getName().equalsIgnoreCase(styleName))
return style; return style;

View file

@ -10,8 +10,8 @@ public class ParticleStyleManager {
/** /**
* Arrays that contain all registered styles * Arrays that contain all registered styles
*/ */
private static List<ParticleStyle> styles = new ArrayList<ParticleStyle>(); private static List<ParticleStyle> styles = new ArrayList<>();
private static List<ParticleStyle> customHandledStyles = new ArrayList<ParticleStyle>(); private static List<ParticleStyle> customHandledStyles = new ArrayList<>();
/** /**
* Registers a style that is put into the plugin's update loop * Registers a style that is put into the plugin's update loop

View file

@ -1,7 +1,9 @@
package com.esophose.playerparticles; package com.esophose.playerparticles.updater;
import java.sql.Statement; import java.sql.Statement;
import com.esophose.playerparticles.PlayerParticles;
/** /**
* This class handles updating the SQLite or MySQL data from older versions to the current version * This class handles updating the SQLite or MySQL data from older versions to the current version
* Everything is purposely done on the main thread to prevent the plugin from starting before all the data is updated * Everything is purposely done on the main thread to prevent the plugin from starting before all the data is updated
@ -12,7 +14,7 @@ public class DataUpdater {
* Checks to make sure all the correct database tables exist * Checks to make sure all the correct database tables exist
* If they don't, create them * If they don't, create them
*/ */
protected static void tryCreateTables() { public static void tryCreateTables() {
PlayerParticles.getPlugin().getDBConnector().connect((connection) -> { PlayerParticles.getPlugin().getDBConnector().connect((connection) -> {
try (Statement createStatement = connection.createStatement()) { try (Statement createStatement = connection.createStatement()) {
createStatement.addBatch("CREATE TABLE IF NOT EXISTS pp_settings (player_uuid VARCHAR(36), particles_hidden TINYINT)"); createStatement.addBatch("CREATE TABLE IF NOT EXISTS pp_settings (player_uuid VARCHAR(36), particles_hidden TINYINT)");
@ -30,7 +32,7 @@ public class DataUpdater {
* @param configVersion The old version of the plugin * @param configVersion The old version of the plugin
* @param currentVersion The current version of the plugin * @param currentVersion The current version of the plugin
*/ */
protected static void updateData(double configVersion, double currentVersion) { public static void updateData(double configVersion, double currentVersion) {
if (configVersion == currentVersion) return; if (configVersion == currentVersion) return;
PlayerParticles.getPlugin().getLogger().warning("Starting to update SQLite/MySQL data from " + (configVersion < 5.3 ? "a legacy version" : "v" + configVersion) + " to v" + PlayerParticles.getPlugin().getDescription().getVersion() + ", this may take a while..."); PlayerParticles.getPlugin().getLogger().warning("Starting to update SQLite/MySQL data from " + (configVersion < 5.3 ? "a legacy version" : "v" + configVersion) + " to v" + PlayerParticles.getPlugin().getDescription().getVersion() + ", this may take a while...");

View file

@ -1,12 +1,11 @@
package com.esophose.playerparticles.updater; package com.esophose.playerparticles.updater;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import com.esophose.playerparticles.PlayerParticles; import com.esophose.playerparticles.PlayerParticles;
import com.esophose.playerparticles.manager.LangManager; import com.esophose.playerparticles.manager.LangManager;
import com.esophose.playerparticles.manager.LangManager.Lang; import com.esophose.playerparticles.manager.LangManager.Lang;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class PluginUpdateListener implements Listener { public class PluginUpdateListener implements Listener {
@ -18,7 +17,11 @@ public class PluginUpdateListener implements Listener {
@EventHandler @EventHandler
public void onPlayerJoin(PlayerJoinEvent e) { public void onPlayerJoin(PlayerJoinEvent e) {
if (e.getPlayer().isOp() && PlayerParticles.getPlugin().getUpdateVersion() != null) { if (e.getPlayer().isOp() && PlayerParticles.getPlugin().getUpdateVersion() != null) {
LangManager.sendCommandSenderMessage(e.getPlayer(), Lang.UPDATE_AVAILABLE, PlayerParticles.getPlugin().getUpdateVersion(), PlayerParticles.getPlugin().getDescription().getVersion()); LangManager.sendCommandSenderMessage(
e.getPlayer(),
Lang.UPDATE_AVAILABLE,
PlayerParticles.getPlugin().getUpdateVersion(),
PlayerParticles.getPlugin().getDescription().getVersion());
} }
} }

View file

@ -50,16 +50,19 @@ public class ParticleUtils {
* Finds a block/item as a material from a list of possible strings * Finds a block/item as a material from a list of possible strings
* Contains a fallback to the barrier icon just in case * Contains a fallback to the barrier icon just in case
* *
* @param barrierFallback If the material should fall back to barrier
* @param input A list of material names * @param input A list of material names
* @return The first matching material * @return The first matching material
*/ */
public static Material closestMatchWithFallback(String... input) { public static Material closestMatchWithFallback(boolean barrierFallback, String... input) {
Material mat = null; Material mat = null;
for (String name : input) { for (String name : input) {
mat = closestMatch(name); mat = closestMatch(name);
if (mat != null) return mat; if (mat != null)
return mat;
} }
if (mat == null) mat = Material.BARRIER; if (barrierFallback)
mat = Material.BARRIER;
return mat; return mat;
} }

View file

@ -157,6 +157,11 @@ database-user-name: ''
# Default: '' # Default: ''
database-user-password: '' database-user-password: ''
# If the database connection should use SSL
# You should enable this if your database supports SSL
# Default: false
database-use-ssl: false
# =================================================================== # # =================================================================== #
# GUI ICON SETTINGS # # GUI ICON SETTINGS #
# This configuration option allows you to change any of the GUI # # This configuration option allows you to change any of the GUI #
@ -212,9 +217,15 @@ gui-icon:
- MAGMA_BLOCK - MAGMA_BLOCK
bubble_pop: bubble_pop:
- BUBBLE_CORAL_FAN - BUBBLE_CORAL_FAN
campfire_cosy_smoke:
- CAMPFIRE
campfire_signal_smoke:
- REDSTONE_TORCH
cloud: cloud:
- WHITE_WOOL - WHITE_WOOL
- WOOL - WOOL
composter:
- COMPOSTER
crit: crit:
- IRON_SWORD - IRON_SWORD
current_down: current_down:
@ -248,6 +259,10 @@ gui-icon:
- TNT - TNT
falling_dust: falling_dust:
- SAND - SAND
falling_lava:
- RED_DYE
falling_water:
- BLUE_DYE
firework: firework:
- FIREWORK_ROCKET - FIREWORK_ROCKET
- FIREWORK - FIREWORK
@ -275,6 +290,8 @@ gui-icon:
large_smoke: large_smoke:
- COBWEB - COBWEB
- WEB - WEB
landing_lava:
- ORANGE_DYE
lava: lava:
- MAGMA_CREAM - MAGMA_CREAM
mycelium: mycelium:
@ -294,6 +311,8 @@ gui-icon:
- LAPIS_BLOCK - LAPIS_BLOCK
smoke: smoke:
- TORCH - TORCH
sneeze:
- BAMBOO
spell: spell:
- POTION - POTION
- GLASS_BOTTLE - GLASS_BOTTLE

View file

@ -2,7 +2,7 @@ name: PlayerParticles
main: com.esophose.playerparticles.PlayerParticles main: com.esophose.playerparticles.PlayerParticles
version: 6.4 version: 6.4
api-version: 1.13 api-version: 1.13
description: Display particles around your player using customized styles and data! description: Display particles around your player and blocks using customized styles and data!
author: Esophose author: Esophose
website: https://www.spigotmc.org/resources/playerparticles.40261/ website: https://www.spigotmc.org/resources/playerparticles.40261/
commands: commands:
@ -10,3 +10,4 @@ commands:
description: The main PlayerParticles command. By default, opens the GUI. description: The main PlayerParticles command. By default, opens the GUI.
ppo: ppo:
description: Allows executing a /pp command for another player. description: Allows executing a /pp command for another player.
permission: playerparticles.other