Fix inconsistencies in whitespace formatting

Only use 4 spaces, no tabs.
This commit is contained in:
Esophose 2018-09-27 18:16:50 -06:00
parent 8cbb588d18
commit 6871b7e3d2
50 changed files with 1652 additions and 1689 deletions

View file

@ -40,7 +40,7 @@ import com.esophose.playerparticles.updater.Updater;
public class PlayerParticles extends JavaPlugin { public class PlayerParticles extends JavaPlugin {
private static Plugin pluginInstance; private static Plugin pluginInstance;
/** /**
* The version a new update has, will be null if the config has it disabled * The version a new update has, will be null if the config has it disabled
@ -65,7 +65,7 @@ public class PlayerParticles extends JavaPlugin {
* Checks for any updates if checking is enabled in the config * Checks for any updates if checking is enabled in the config
*/ */
public void onEnable() { public void onEnable() {
pluginInstance = Bukkit.getServer().getPluginManager().getPlugin("PlayerParticles"); pluginInstance = Bukkit.getServer().getPluginManager().getPlugin("PlayerParticles");
getCommand("pp").setTabCompleter(new ParticleCommandHandler()); getCommand("pp").setTabCompleter(new ParticleCommandHandler());
getCommand("pp").setExecutor(new ParticleCommandHandler()); getCommand("pp").setExecutor(new ParticleCommandHandler());
@ -143,21 +143,21 @@ public class PlayerParticles extends JavaPlugin {
* Creates new tables if they don't exist * Creates new tables if they don't exist
*/ */
private void configureDatabase(boolean useMySql) { private void configureDatabase(boolean useMySql) {
if (useMySql) { if (useMySql) {
databaseConnector = new MySqlDatabaseConnector(this.getConfig()); databaseConnector = new MySqlDatabaseConnector(this.getConfig());
} else { } else {
databaseConnector = new SqliteDatabaseConnector(this.getDataFolder().getAbsolutePath()); databaseConnector = new SqliteDatabaseConnector(this.getDataFolder().getAbsolutePath());
} }
if (!databaseConnector.isInitialized()) { if (!databaseConnector.isInitialized()) {
getLogger().severe("Unable to connect to the MySQL database! Is your login information correct? Falling back to SQLite database instead."); getLogger().severe("Unable to connect to the MySQL database! Is your login information correct? Falling back to SQLite database instead.");
configureDatabase(false); configureDatabase(false);
return; return;
} }
databaseConnector.connect((connection) -> { databaseConnector.connect((connection) -> {
// Check if pp_users exists, if it does, this is an old database schema that needs to be deleted // Check if pp_users exists, if it does, this is an old database schema that needs to be deleted
try { // @formatter:off try { // @formatter:off
try (Statement statement = connection.createStatement()) { try (Statement statement = connection.createStatement()) {
String pp_usersQuery; String pp_usersQuery;
if (useMySql) { if (useMySql) {

View file

@ -7,28 +7,28 @@ import com.esophose.playerparticles.particles.PPlayer;
public class AddCommandModule implements CommandModule { public class AddCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null; return null;
} }
public String getName() { public String getName() {
return "add"; return "add";
} }
public String getDescription() { public String getDescription() {
return Lang.ADD_COMMAND_DESCRIPTION.get(); return Lang.ADD_COMMAND_DESCRIPTION.get();
} }
public String getArguments() { public String getArguments() {
return "<effect> <style> [data]"; return "<effect> <style> [data]";
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return true; return true;
} }
} }

View file

@ -10,54 +10,54 @@ import com.esophose.playerparticles.particles.ParticleEffect.ParticleProperty;
public class DataCommandModule implements CommandModule { public class DataCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
if (args.length > 0) { if (args.length > 0) {
ParticleEffect effect = ParticleEffect.fromName(args[0]); ParticleEffect effect = ParticleEffect.fromName(args[0]);
if ((!effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA) && !effect.hasProperty(ParticleProperty.COLORABLE)) || args.length == 0) { if ((!effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA) && !effect.hasProperty(ParticleProperty.COLORABLE)) || args.length == 0) {
if (effect.hasProperty(ParticleProperty.COLORABLE)) { if (effect.hasProperty(ParticleProperty.COLORABLE)) {
if (effect == ParticleEffect.NOTE) { if (effect == ParticleEffect.NOTE) {
LangManager.sendMessage(pplayer, Lang.DATA_USAGE, "note"); LangManager.sendMessage(pplayer, Lang.DATA_USAGE, "note");
LangManager.sendCustomMessage(pplayer, Lang.USAGE.get() + " " + Lang.NOTE_DATA_USAGE.get()); LangManager.sendCustomMessage(pplayer, Lang.USAGE.get() + " " + Lang.NOTE_DATA_USAGE.get());
} else { } else {
LangManager.sendMessage(pplayer, Lang.DATA_USAGE, "color"); LangManager.sendMessage(pplayer, Lang.DATA_USAGE, "color");
LangManager.sendCustomMessage(pplayer, Lang.USAGE.get() + " " + Lang.COLOR_DATA_USAGE.get()); LangManager.sendCustomMessage(pplayer, Lang.USAGE.get() + " " + Lang.COLOR_DATA_USAGE.get());
} }
} else if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) { } else if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
if (effect == ParticleEffect.ITEM) { if (effect == ParticleEffect.ITEM) {
LangManager.sendMessage(pplayer, Lang.DATA_USAGE, "item"); LangManager.sendMessage(pplayer, Lang.DATA_USAGE, "item");
LangManager.sendCustomMessage(pplayer, Lang.USAGE.get() + " " + Lang.ITEM_DATA_USAGE.get()); LangManager.sendCustomMessage(pplayer, Lang.USAGE.get() + " " + Lang.ITEM_DATA_USAGE.get());
} else { } else {
LangManager.sendMessage(pplayer, Lang.DATA_USAGE, "block"); LangManager.sendMessage(pplayer, Lang.DATA_USAGE, "block");
LangManager.sendCustomMessage(pplayer, Lang.USAGE.get() + " " + Lang.BLOCK_DATA_USAGE.get()); LangManager.sendCustomMessage(pplayer, Lang.USAGE.get() + " " + Lang.BLOCK_DATA_USAGE.get());
} }
} else { } else {
LangManager.sendMessage(pplayer, Lang.NO_DATA_USAGE); LangManager.sendMessage(pplayer, Lang.NO_DATA_USAGE);
} }
} }
} else { } else {
LangManager.sendMessage(pplayer, Lang.INVALID_TYPE); LangManager.sendMessage(pplayer, Lang.INVALID_TYPE);
} }
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null; return null;
} }
public String getName() { public String getName() {
return "data"; return "data";
} }
public String getDescription() { public String getDescription() {
return Lang.DATA_COMMAND_DESCRIPTION.get(); return Lang.DATA_COMMAND_DESCRIPTION.get();
} }
public String getArguments() { public String getArguments() {
return "<effect>"; return "<effect>";
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return true; return true;
} }
} }

View file

@ -7,29 +7,29 @@ import com.esophose.playerparticles.particles.PPlayer;
public class DefaultCommandModule implements CommandModule { public class DefaultCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
// The default command just opens the GUI, execute the GUICommandModule // The default command just opens the GUI, execute the GUICommandModule
ParticleCommandHandler.findMatchingCommand("gui").onCommandExecute(pplayer, args); ParticleCommandHandler.findMatchingCommand("gui").onCommandExecute(pplayer, args);
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null; return null;
} }
public String getName() { public String getName() {
return ""; return "";
} }
public String getDescription() { public String getDescription() {
return Lang.DEFAULT_COMMAND_DESCRIPTION.get(); return Lang.DEFAULT_COMMAND_DESCRIPTION.get();
} }
public String getArguments() { public String getArguments() {
return ""; return "";
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return true; return true;
} }
} }

View file

@ -7,28 +7,28 @@ import com.esophose.playerparticles.particles.PPlayer;
public class EditCommandModule implements CommandModule { public class EditCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null; return null;
} }
public String getName() { public String getName() {
return "edit"; return "edit";
} }
public String getDescription() { public String getDescription() {
return Lang.EDIT_COMMAND_DESCRIPTION.get(); return Lang.EDIT_COMMAND_DESCRIPTION.get();
} }
public String getArguments() { public String getArguments() {
return ""; return "";
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return true; return true;
} }
} }

View file

@ -8,28 +8,28 @@ import com.esophose.playerparticles.particles.PPlayer;
public class EffectCommandModule implements CommandModule { public class EffectCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
LangManager.sendMessage(pplayer, Lang.COMMAND_REMOVED); LangManager.sendMessage(pplayer, Lang.COMMAND_REMOVED);
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null; return null;
} }
public String getName() { public String getName() {
return "effect"; return "effect";
} }
public String getDescription() { public String getDescription() {
return Lang.EFFECT_COMMAND_DESCRIPTION.get(); return Lang.EFFECT_COMMAND_DESCRIPTION.get();
} }
public String getArguments() { public String getArguments() {
return ""; return "";
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return true; return true;
} }
} }

View file

@ -12,10 +12,10 @@ import com.esophose.playerparticles.particles.ParticleEffect;
public class EffectsCommandModule implements CommandModule { public class EffectsCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
Player p = pplayer.getPlayer(); Player p = pplayer.getPlayer();
if (PermissionManager.getEffectsUserHasPermissionFor(p).size() == 1) { if (PermissionManager.getEffectsUserHasPermissionFor(p).size() == 1) {
LangManager.sendMessage(p, Lang.NO_PARTICLES); LangManager.sendMessage(p, Lang.NO_PARTICLES);
return; return;
} }
@ -33,26 +33,26 @@ public class EffectsCommandModule implements CommandModule {
LangManager.sendCustomMessage(p, toSend); LangManager.sendCustomMessage(p, toSend);
LangManager.sendCustomMessage(p, Lang.USAGE.get() + " " + Lang.PARTICLE_USAGE.get()); LangManager.sendCustomMessage(p, Lang.USAGE.get() + " " + Lang.PARTICLE_USAGE.get());
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null; return null;
} }
public String getName() { public String getName() {
return "effects"; return "effects";
} }
public String getDescription() { public String getDescription() {
return Lang.EFFECTS_COMMAND_DESCRIPTION.get(); return Lang.EFFECTS_COMMAND_DESCRIPTION.get();
} }
public String getArguments() { public String getArguments() {
return ""; return "";
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return false; return false;
} }
} }

View file

@ -27,263 +27,249 @@ import com.esophose.playerparticles.util.ParticleUtils;
public class FixedCommandModule implements CommandModule { public class FixedCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
Player p = pplayer.getPlayer(); Player p = pplayer.getPlayer();
if (!PermissionManager.canUseFixedEffects(p)) { if (!PermissionManager.canUseFixedEffects(p)) {
LangManager.sendMessage(p, Lang.NO_PERMISSION_FIXED); LangManager.sendMessage(p, Lang.NO_PERMISSION_FIXED);
return; return;
} }
if (args.length == 0) { // General information on command if (args.length == 0) { // General information on command
LangManager.sendMessage(p, Lang.INVALID_FIXED_COMMAND); LangManager.sendMessage(p, Lang.INVALID_FIXED_COMMAND);
LangManager.sendMessage(p, Lang.FIXED_COMMAND_DESC_CREATE); LangManager.sendMessage(p, Lang.FIXED_COMMAND_DESC_CREATE);
LangManager.sendMessage(p, Lang.FIXED_COMMAND_DESC_REMOVE); LangManager.sendMessage(p, Lang.FIXED_COMMAND_DESC_REMOVE);
LangManager.sendMessage(p, Lang.FIXED_COMMAND_DESC_LIST); LangManager.sendMessage(p, Lang.FIXED_COMMAND_DESC_LIST);
LangManager.sendMessage(p, Lang.FIXED_COMMAND_DESC_INFO); LangManager.sendMessage(p, Lang.FIXED_COMMAND_DESC_INFO);
if (p.hasPermission("playerparticles.fixed.clear")) if (p.hasPermission("playerparticles.fixed.clear")) LangManager.sendMessage(p, Lang.FIXED_COMMAND_DESC_CLEAR);
LangManager.sendMessage(p, Lang.FIXED_COMMAND_DESC_CLEAR); return;
return; }
}
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++) { for (int i = 1; i < args.length; i++) {
cmdArgs[i - 1] = args[i]; cmdArgs[i - 1] = args[i];
} }
args = cmdArgs; args = cmdArgs;
if (cmd.equalsIgnoreCase("create")) { if (cmd.equalsIgnoreCase("create")) {
boolean reachedMax = DataManager.hasPlayerReachedMaxFixedEffects(pplayer); boolean reachedMax = DataManager.hasPlayerReachedMaxFixedEffects(pplayer);
if (reachedMax) { if (reachedMax) {
LangManager.sendMessage(p, Lang.MAX_FIXED_EFFECTS_REACHED); LangManager.sendMessage(p, Lang.MAX_FIXED_EFFECTS_REACHED);
return; return;
} }
if (args.length < 5) { if (args.length < 5) {
LangManager.sendMessage(p, Lang.CREATE_FIXED_MISSING_ARGS, (5 - args.length) + ""); LangManager.sendMessage(p, Lang.CREATE_FIXED_MISSING_ARGS, (5 - args.length) + "");
return; return;
} }
double xPos = -1, yPos = -1, zPos = -1; double xPos = -1, yPos = -1, zPos = -1;
try { try {
if (args[0].startsWith("~")) { if (args[0].startsWith("~")) {
if (args[0].equals("~")) if (args[0].equals("~")) xPos = p.getLocation().getX();
xPos = p.getLocation().getX(); else xPos = p.getLocation().getX() + Double.parseDouble(args[0].substring(1));
else } else {
xPos = p.getLocation().getX() + Double.parseDouble(args[0].substring(1)); xPos = Double.parseDouble(args[0]);
} else { }
xPos = Double.parseDouble(args[0]);
}
if (args[1].startsWith("~")) { if (args[1].startsWith("~")) {
if (args[1].equals("~")) if (args[1].equals("~")) yPos = p.getLocation().getY() + 1;
yPos = p.getLocation().getY() + 1; else yPos = p.getLocation().getY() + 1 + Double.parseDouble(args[1].substring(1));
else } else {
yPos = p.getLocation().getY() + 1 + Double.parseDouble(args[1].substring(1)); yPos = Double.parseDouble(args[1]);
} else { }
yPos = Double.parseDouble(args[1]);
}
if (args[2].startsWith("~")) { if (args[2].startsWith("~")) {
if (args[2].equals("~")) if (args[2].equals("~")) zPos = p.getLocation().getZ();
zPos = p.getLocation().getZ(); else zPos = p.getLocation().getZ() + Double.parseDouble(args[2].substring(1));
else } else {
zPos = p.getLocation().getZ() + Double.parseDouble(args[2].substring(1)); zPos = Double.parseDouble(args[2]);
} else { }
zPos = Double.parseDouble(args[2]); } catch (Exception e) {
} LangManager.sendMessage(p, Lang.CREATE_FIXED_INVALID_COORDS);
} catch (Exception e) { return;
LangManager.sendMessage(p, Lang.CREATE_FIXED_INVALID_COORDS); }
return;
}
double distanceFromEffect = p.getLocation().distance(new Location(p.getWorld(), xPos, yPos, zPos)); double distanceFromEffect = p.getLocation().distance(new Location(p.getWorld(), xPos, yPos, zPos));
int maxCreationDistance = DataManager.getMaxFixedEffectCreationDistance(); int maxCreationDistance = DataManager.getMaxFixedEffectCreationDistance();
if (maxCreationDistance != 0 && distanceFromEffect > maxCreationDistance) { if (maxCreationDistance != 0 && distanceFromEffect > maxCreationDistance) {
LangManager.sendMessage(p, Lang.CREATE_FIXED_OUT_OF_RANGE, maxCreationDistance + ""); LangManager.sendMessage(p, Lang.CREATE_FIXED_OUT_OF_RANGE, maxCreationDistance + "");
return; return;
} }
ParticleEffect effect = ParticleManager.effectFromString(args[3]); ParticleEffect effect = ParticleManager.effectFromString(args[3]);
if (effect == null) { if (effect == null) {
LangManager.sendMessage(p, Lang.CREATE_FIXED_INVALID_EFFECT, args[3]); LangManager.sendMessage(p, Lang.CREATE_FIXED_INVALID_EFFECT, args[3]);
return; return;
} else if (!PermissionManager.hasEffectPermission(p, effect)) { } else if (!PermissionManager.hasEffectPermission(p, effect)) {
LangManager.sendMessage(p, Lang.CREATE_FIXED_NO_PERMISSION_EFFECT, effect.getName()); LangManager.sendMessage(p, Lang.CREATE_FIXED_NO_PERMISSION_EFFECT, effect.getName());
return; return;
} }
ParticleStyle style = ParticleStyleManager.styleFromString(args[4]); ParticleStyle style = ParticleStyleManager.styleFromString(args[4]);
if (style == null) { if (style == null) {
LangManager.sendMessage(p, Lang.CREATE_FIXED_INVALID_STYLE, args[4]); LangManager.sendMessage(p, Lang.CREATE_FIXED_INVALID_STYLE, args[4]);
return; return;
} else if (!PermissionManager.hasStylePermission(p, style)) { } else if (!PermissionManager.hasStylePermission(p, style)) {
LangManager.sendMessage(p, Lang.CREATE_FIXED_NO_PERMISSION_STYLE, args[4]); LangManager.sendMessage(p, Lang.CREATE_FIXED_NO_PERMISSION_STYLE, args[4]);
return; return;
} }
if (!style.canBeFixed()) { if (!style.canBeFixed()) {
LangManager.sendMessage(p, Lang.CREATE_FIXED_NON_FIXABLE_STYLE, style.getName()); LangManager.sendMessage(p, Lang.CREATE_FIXED_NON_FIXABLE_STYLE, style.getName());
return; return;
} }
Material itemData = null; Material itemData = null;
Material blockData = null; Material blockData = null;
OrdinaryColor colorData = null; OrdinaryColor colorData = null;
NoteColor noteColorData = null; NoteColor noteColorData = null;
if (args.length > 5) { if (args.length > 5) {
if (effect.hasProperty(ParticleProperty.COLORABLE)) { if (effect.hasProperty(ParticleProperty.COLORABLE)) {
if (effect == ParticleEffect.NOTE) { if (effect == ParticleEffect.NOTE) {
if (args[5].equalsIgnoreCase("rainbow")) { if (args[5].equalsIgnoreCase("rainbow")) {
noteColorData = new NoteColor(99); noteColorData = new NoteColor(99);
} else { } else {
int note = -1; int note = -1;
try { try {
note = Integer.parseInt(args[5]); note = Integer.parseInt(args[5]);
} catch (Exception e) { } catch (Exception e) {
LangManager.sendMessage(p, Lang.CREATE_FIXED_DATA_ERROR, "note"); LangManager.sendMessage(p, Lang.CREATE_FIXED_DATA_ERROR, "note");
return; return;
} }
if (note < 0 || note > 23) { if (note < 0 || note > 23) {
LangManager.sendMessage(p, Lang.CREATE_FIXED_DATA_ERROR, "note"); LangManager.sendMessage(p, Lang.CREATE_FIXED_DATA_ERROR, "note");
return; return;
} }
noteColorData = new NoteColor(note); noteColorData = new NoteColor(note);
} }
} else { } else {
if (args[5].equalsIgnoreCase("rainbow")) { if (args[5].equalsIgnoreCase("rainbow")) {
colorData = new OrdinaryColor(999, 999, 999); colorData = new OrdinaryColor(999, 999, 999);
} else { } else {
int r = -1; int r = -1;
int g = -1; int g = -1;
int b = -1; int b = -1;
try { try {
r = Integer.parseInt(args[5]); r = Integer.parseInt(args[5]);
g = Integer.parseInt(args[6]); g = Integer.parseInt(args[6]);
b = Integer.parseInt(args[7]); b = Integer.parseInt(args[7]);
} catch (Exception e) { } catch (Exception e) {
LangManager.sendMessage(p, Lang.CREATE_FIXED_DATA_ERROR, "color"); LangManager.sendMessage(p, Lang.CREATE_FIXED_DATA_ERROR, "color");
return; return;
} }
if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) { if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
LangManager.sendMessage(p, Lang.CREATE_FIXED_DATA_ERROR, "color"); LangManager.sendMessage(p, Lang.CREATE_FIXED_DATA_ERROR, "color");
return; return;
} }
colorData = new OrdinaryColor(r, g, b); colorData = new OrdinaryColor(r, g, b);
} }
} }
} 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 = null;
try { try {
material = ParticleUtils.closestMatch(args[5]); material = ParticleUtils.closestMatch(args[5]);
if (material == null) if (material == null) material = Material.matchMaterial(args[5]);
material = Material.matchMaterial(args[5]); if (material == null) throw new Exception();
if (material == null) } catch (Exception e) {
throw new Exception(); LangManager.sendMessage(p, Lang.CREATE_FIXED_DATA_ERROR, "block");
} catch (Exception e) { return;
LangManager.sendMessage(p, Lang.CREATE_FIXED_DATA_ERROR, "block"); }
return;
}
blockData = material; blockData = material;
} else if (effect == ParticleEffect.ITEM) { } else if (effect == ParticleEffect.ITEM) {
Material material = null; Material material = null;
try { try {
material = ParticleUtils.closestMatch(args[5]); material = ParticleUtils.closestMatch(args[5]);
if (material == null) if (material == null) material = Material.matchMaterial(args[5]);
material = Material.matchMaterial(args[5]); if (material == null) throw new Exception();
if (material == null) } catch (Exception e) {
throw new Exception(); LangManager.sendMessage(p, Lang.CREATE_FIXED_DATA_ERROR, "item");
} catch (Exception e) { return;
LangManager.sendMessage(p, Lang.CREATE_FIXED_DATA_ERROR, "item"); }
return;
}
itemData = material; itemData = material;
} }
} }
} }
int nextFixedEffectId = pplayer.getNextFixedEffectId(); int nextFixedEffectId = pplayer.getNextFixedEffectId();
ParticlePair particle = new ParticlePair(pplayer.getUniqueId(), nextFixedEffectId, effect, style, itemData, blockData, colorData, noteColorData); ParticlePair particle = new ParticlePair(pplayer.getUniqueId(), nextFixedEffectId, effect, style, itemData, blockData, colorData, noteColorData);
FixedParticleEffect fixedEffect = new FixedParticleEffect(p.getUniqueId(), nextFixedEffectId, p.getLocation().getWorld().getName(), xPos, yPos, zPos, particle); FixedParticleEffect fixedEffect = new FixedParticleEffect(p.getUniqueId(), nextFixedEffectId, p.getLocation().getWorld().getName(), xPos, yPos, zPos, particle);
LangManager.sendMessage(p, Lang.CREATE_FIXED_SUCCESS); LangManager.sendMessage(p, Lang.CREATE_FIXED_SUCCESS);
DataManager.saveFixedEffect(fixedEffect); DataManager.saveFixedEffect(fixedEffect);
} else if (cmd.equalsIgnoreCase("remove")) { } else if (cmd.equalsIgnoreCase("remove")) {
if (args.length < 1) { if (args.length < 1) {
LangManager.sendMessage(p, Lang.REMOVE_FIXED_NO_ARGS); LangManager.sendMessage(p, Lang.REMOVE_FIXED_NO_ARGS);
return; return;
} }
int id = -1; int id = -1;
try { try {
id = Integer.parseInt(args[0]); id = Integer.parseInt(args[0]);
} catch (Exception e) { } catch (Exception e) {
LangManager.sendMessage(p, Lang.REMOVE_FIXED_INVALID_ARGS); LangManager.sendMessage(p, Lang.REMOVE_FIXED_INVALID_ARGS);
return; return;
} }
if (pplayer.getFixedEffectById(id) != null) { if (pplayer.getFixedEffectById(id) != null) {
DataManager.removeFixedEffect(pplayer.getUniqueId(), id); DataManager.removeFixedEffect(pplayer.getUniqueId(), id);
LangManager.sendMessage(p, Lang.REMOVE_FIXED_SUCCESS, id + ""); LangManager.sendMessage(p, Lang.REMOVE_FIXED_SUCCESS, id + "");
} else { } else {
LangManager.sendMessage(p, Lang.REMOVE_FIXED_NONEXISTANT, id + ""); LangManager.sendMessage(p, Lang.REMOVE_FIXED_NONEXISTANT, id + "");
} }
} else if (cmd.equalsIgnoreCase("list")) { } else if (cmd.equalsIgnoreCase("list")) {
List<Integer> ids = pplayer.getFixedEffectIds(); List<Integer> ids = pplayer.getFixedEffectIds();
Collections.sort(ids); Collections.sort(ids);
if (ids.isEmpty()) { if (ids.isEmpty()) {
LangManager.sendMessage(p, Lang.LIST_FIXED_NONE); LangManager.sendMessage(p, Lang.LIST_FIXED_NONE);
return; return;
} }
String msg = Lang.LIST_FIXED_SUCCESS.get(); String msg = Lang.LIST_FIXED_SUCCESS.get();
boolean first = true; boolean first = true;
for (int id : ids) { for (int id : ids) {
if (!first) if (!first) msg += ", ";
msg += ", "; else first = false;
else msg += id;
first = false; }
msg += id;
}
LangManager.sendCustomMessage(p, msg); LangManager.sendCustomMessage(p, msg);
} else if (cmd.equalsIgnoreCase("info")) { } else if (cmd.equalsIgnoreCase("info")) {
if (args.length < 1) { if (args.length < 1) {
LangManager.sendMessage(p, Lang.INFO_FIXED_NO_ARGS); LangManager.sendMessage(p, Lang.INFO_FIXED_NO_ARGS);
return; return;
} }
int id = -1; int id = -1;
try { try {
id = Integer.parseInt(args[0]); id = Integer.parseInt(args[0]);
} catch (Exception e) { } catch (Exception e) {
LangManager.sendMessage(p, Lang.INFO_FIXED_INVALID_ARGS); LangManager.sendMessage(p, Lang.INFO_FIXED_INVALID_ARGS);
return; return;
} }
FixedParticleEffect fixedEffect = pplayer.getFixedEffectById(id); FixedParticleEffect fixedEffect = pplayer.getFixedEffectById(id);
if (fixedEffect == null) { if (fixedEffect == null) {
LangManager.sendMessage(p, Lang.INFO_FIXED_NONEXISTANT, id + ""); LangManager.sendMessage(p, Lang.INFO_FIXED_NONEXISTANT, id + "");
return; return;
} }
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 String listMessage = Lang.INFO_FIXED_INFO.get() // @formatter:off
String listMessage = Lang.INFO_FIXED_INFO.get() // @formatter:off
.replaceAll("\\{0\\}", fixedEffect.getId() + "") .replaceAll("\\{0\\}", fixedEffect.getId() + "")
.replaceAll("\\{1\\}", fixedEffect.getLocation().getWorld().getName()) .replaceAll("\\{1\\}", fixedEffect.getLocation().getWorld().getName())
.replaceAll("\\{2\\}", df.format(fixedEffect.getLocation().getX()) + "") .replaceAll("\\{2\\}", df.format(fixedEffect.getLocation().getX()) + "")
@ -292,70 +278,67 @@ public class FixedCommandModule implements CommandModule {
.replaceAll("\\{5\\}", particle.getEffect().getName()) .replaceAll("\\{5\\}", particle.getEffect().getName())
.replaceAll("\\{6\\}", particle.getStyle().getName()) .replaceAll("\\{6\\}", particle.getStyle().getName())
.replaceAll("\\{7\\}", particle.getDataString()); // @formatter:on .replaceAll("\\{7\\}", particle.getDataString()); // @formatter:on
LangManager.sendCustomMessage(p, listMessage); LangManager.sendCustomMessage(p, listMessage);
} else if (cmd.equalsIgnoreCase("clear")) { } else if (cmd.equalsIgnoreCase("clear")) {
if (!p.hasPermission("playerparticles.fixed.clear")) { if (!p.hasPermission("playerparticles.fixed.clear")) {
LangManager.sendMessage(p, Lang.CLEAR_FIXED_NO_PERMISSION); LangManager.sendMessage(p, Lang.CLEAR_FIXED_NO_PERMISSION);
return; return;
} }
if (args.length < 1) { if (args.length < 1) {
LangManager.sendMessage(p, Lang.CLEAR_FIXED_NO_ARGS); LangManager.sendMessage(p, Lang.CLEAR_FIXED_NO_ARGS);
return; return;
} }
int radius = -1; int radius = -1;
try { try {
radius = Math.abs(Integer.parseInt(args[0])); radius = Math.abs(Integer.parseInt(args[0]));
} catch (Exception e) { } catch (Exception e) {
LangManager.sendMessage(p, Lang.CLEAR_FIXED_INVALID_ARGS); LangManager.sendMessage(p, Lang.CLEAR_FIXED_INVALID_ARGS);
return; return;
} }
ArrayList<FixedParticleEffect> fixedEffectsToRemove = new ArrayList<FixedParticleEffect>(); ArrayList<FixedParticleEffect> fixedEffectsToRemove = new ArrayList<FixedParticleEffect>();
for (PPlayer ppl : ParticleManager.getPPlayers()) for (PPlayer ppl : ParticleManager.getPPlayers())
for (FixedParticleEffect fixedEffect : ppl.getFixedParticles()) for (FixedParticleEffect fixedEffect : ppl.getFixedParticles())
if (fixedEffect.getLocation().getWorld().equals(p.getLocation().getWorld()) if (fixedEffect.getLocation().getWorld().equals(p.getLocation().getWorld()) && fixedEffect.getLocation().distance(p.getLocation()) <= radius) fixedEffectsToRemove.add(fixedEffect);
&& fixedEffect.getLocation().distance(p.getLocation()) <= radius)
fixedEffectsToRemove.add(fixedEffect);
for (FixedParticleEffect fixedEffect : fixedEffectsToRemove) for (FixedParticleEffect fixedEffect : fixedEffectsToRemove)
DataManager.removeFixedEffect(fixedEffect.getOwnerUniqueId(), fixedEffect.getId()); DataManager.removeFixedEffect(fixedEffect.getOwnerUniqueId(), fixedEffect.getId());
String clearMessage = Lang.CLEAR_FIXED_SUCCESS.get() // @formatter:off String clearMessage = Lang.CLEAR_FIXED_SUCCESS.get() // @formatter:off
.replaceAll("\\{0\\}", fixedEffectsToRemove.size() + "").replaceAll("\\{1\\}", radius + ""); // @formatter:on .replaceAll("\\{0\\}", fixedEffectsToRemove.size() + "").replaceAll("\\{1\\}", radius + ""); // @formatter:on
LangManager.sendCustomMessage(pplayer, clearMessage); LangManager.sendCustomMessage(pplayer, clearMessage);
return; return;
} else { } else {
LangManager.sendMessage(pplayer, Lang.INVALID_FIXED_COMMAND); LangManager.sendMessage(pplayer, Lang.INVALID_FIXED_COMMAND);
LangManager.sendMessage(pplayer, Lang.FIXED_COMMAND_DESC_CREATE); LangManager.sendMessage(pplayer, Lang.FIXED_COMMAND_DESC_CREATE);
LangManager.sendMessage(pplayer, Lang.FIXED_COMMAND_DESC_REMOVE); LangManager.sendMessage(pplayer, Lang.FIXED_COMMAND_DESC_REMOVE);
LangManager.sendMessage(pplayer, Lang.FIXED_COMMAND_DESC_LIST); LangManager.sendMessage(pplayer, Lang.FIXED_COMMAND_DESC_LIST);
LangManager.sendMessage(pplayer, Lang.FIXED_COMMAND_DESC_INFO); LangManager.sendMessage(pplayer, Lang.FIXED_COMMAND_DESC_INFO);
if (p.hasPermission("playerparticles.fixed.clear")) if (p.hasPermission("playerparticles.fixed.clear")) LangManager.sendMessage(p, Lang.FIXED_COMMAND_DESC_CLEAR);
LangManager.sendMessage(p, Lang.FIXED_COMMAND_DESC_CLEAR); }
} }
}
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null; return null;
} }
public String getName() { public String getName() {
return "fixed"; return "fixed";
} }
public String getDescription() { public String getDescription() {
return Lang.FIXED_COMMAND_DESCRIPTION.get(); return Lang.FIXED_COMMAND_DESCRIPTION.get();
} }
public String getArguments() { public String getArguments() {
return "<args>"; return "<args>";
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return true; return true;
} }
} }

View file

@ -11,13 +11,13 @@ import com.esophose.playerparticles.particles.PPlayer;
public class GUICommandModule implements CommandModule { public class GUICommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
boolean byDefault = false; boolean byDefault = false;
if (args.length > 0 && args[0].equals("byDefault")) { if (args.length > 0 && args[0].equals("byDefault")) {
byDefault = true; byDefault = true;
} }
if (PlayerParticlesGui.isGuiDisabled()) { if (PlayerParticlesGui.isGuiDisabled()) {
if (byDefault) { if (byDefault) {
LangManager.sendMessage(pplayer, Lang.INVALID_ARGUMENTS); LangManager.sendMessage(pplayer, Lang.INVALID_ARGUMENTS);
} else { } else {
@ -28,7 +28,7 @@ public class GUICommandModule implements CommandModule {
if (PermissionManager.getEffectsUserHasPermissionFor(pplayer.getPlayer()).size() == 1) { if (PermissionManager.getEffectsUserHasPermissionFor(pplayer.getPlayer()).size() == 1) {
if (byDefault) { if (byDefault) {
LangManager.sendMessage(pplayer, Lang.INVALID_ARGUMENTS); LangManager.sendMessage(pplayer, Lang.INVALID_ARGUMENTS);
} else { } else {
LangManager.sendMessage(pplayer, Lang.NO_PARTICLES); LangManager.sendMessage(pplayer, Lang.NO_PARTICLES);
} }
@ -40,26 +40,26 @@ public class GUICommandModule implements CommandModule {
} }
PlayerParticlesGui.changeState(pplayer, GuiState.DEFAULT); PlayerParticlesGui.changeState(pplayer, GuiState.DEFAULT);
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null; return null;
} }
public String getName() { public String getName() {
return "gui"; return "gui";
} }
public String getDescription() { public String getDescription() {
return Lang.GUI_COMMAND_DESCRIPTION.get(); return Lang.GUI_COMMAND_DESCRIPTION.get();
} }
public String getArguments() { public String getArguments() {
return ""; return "";
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return true; return true;
} }
} }

View file

@ -7,28 +7,28 @@ import com.esophose.playerparticles.particles.PPlayer;
public class GroupCommandModule implements CommandModule { public class GroupCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null; return null;
} }
public String getName() { public String getName() {
return "group"; return "group";
} }
public String getDescription() { public String getDescription() {
return Lang.GROUP_COMMAND_DESCRIPTION.get(); return Lang.GROUP_COMMAND_DESCRIPTION.get();
} }
public String getArguments() { public String getArguments() {
return "<args>"; return "<args>";
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return true; return true;
} }
} }

View file

@ -8,29 +8,29 @@ import com.esophose.playerparticles.particles.PPlayer;
public class HelpCommandModule implements CommandModule { public class HelpCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
LangManager.sendMessage(pplayer, Lang.AVAILABLE_COMMANDS); // TODO: Rewrite to be dynamically generated from the ParticleCommandHandler's registered CommandModules LangManager.sendMessage(pplayer, Lang.AVAILABLE_COMMANDS); // TODO: Rewrite to be dynamically generated from the ParticleCommandHandler's registered CommandModules
LangManager.sendMessage(pplayer, Lang.COMMAND_USAGE); LangManager.sendMessage(pplayer, Lang.COMMAND_USAGE);
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null; return null;
} }
public String getName() { public String getName() {
return "help"; return "help";
} }
public String getDescription() { public String getDescription() {
return Lang.HELP_COMMAND_DESCRIPTION.get(); return Lang.HELP_COMMAND_DESCRIPTION.get();
} }
public String getArguments() { public String getArguments() {
return ""; return "";
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return false; return false;
} }
} }

View file

@ -7,28 +7,28 @@ import com.esophose.playerparticles.particles.PPlayer;
public class InfoCommandModule implements CommandModule { public class InfoCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null; return null;
} }
public String getName() { public String getName() {
return "info"; return "info";
} }
public String getDescription() { public String getDescription() {
return Lang.INFO_COMMAND_DESCRIPTION.get(); return Lang.INFO_COMMAND_DESCRIPTION.get();
} }
public String getArguments() { public String getArguments() {
return "<id>"; return "<id>";
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return true; return true;
} }
} }

View file

@ -7,28 +7,28 @@ import com.esophose.playerparticles.particles.PPlayer;
public class ListCommandModule implements CommandModule { public class ListCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null; return null;
} }
public String getName() { public String getName() {
return "list"; return "list";
} }
public String getDescription() { public String getDescription() {
return Lang.LIST_COMMAND_DESCRIPTION.get(); return Lang.LIST_COMMAND_DESCRIPTION.get();
} }
public String getArguments() { public String getArguments() {
return ""; return "";
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return true; return true;
} }
} }

View file

@ -168,7 +168,7 @@ public class ParticleCommandHandler implements CommandExecutor, TabCompleter {
// } else { // } else {
// List<String> commands = new ArrayList<String>(Arrays.asList(COMMANDS)); // List<String> commands = new ArrayList<String>(Arrays.asList(COMMANDS));
// StringUtil.copyPartialMatches(args[0], commands, completions); // StringUtil.copyPartialMatches(args[0], commands, completions);
} }
} }
return null; return null;
} }

View file

@ -7,28 +7,28 @@ import com.esophose.playerparticles.particles.PPlayer;
public class RemoveCommandModule implements CommandModule { public class RemoveCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null; return null;
} }
public String getName() { public String getName() {
return "remove"; return "remove";
} }
public String getDescription() { public String getDescription() {
return Lang.REMOVE_COMMAND_DESCRIPTION.get(); return Lang.REMOVE_COMMAND_DESCRIPTION.get();
} }
public String getArguments() { public String getArguments() {
return "<id>"; return "<id>";
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return true; return true;
} }
} }

View file

@ -14,19 +14,19 @@ import com.esophose.playerparticles.particles.ParticleGroup;
public class ResetCommandModule implements CommandModule { public class ResetCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
if (args.length >= 1) { if (args.length >= 1) {
String altPlayerName = args[0]; String altPlayerName = args[0];
if (!PermissionManager.canUseForceReset(pplayer.getPlayer())) { if (!PermissionManager.canUseForceReset(pplayer.getPlayer())) {
LangManager.sendMessage(pplayer, Lang.FAILED_EXECUTE_NO_PERMISSION, altPlayerName); LangManager.sendMessage(pplayer, Lang.FAILED_EXECUTE_NO_PERMISSION, altPlayerName);
} else { } else {
Player targetPlayer = null; Player targetPlayer = null;
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
if (p.getName().toLowerCase().contains(altPlayerName.toLowerCase())) { if (p.getName().toLowerCase().contains(altPlayerName.toLowerCase())) {
targetPlayer = p; targetPlayer = p;
break; break;
} }
} }
if (targetPlayer == null) { if (targetPlayer == null) {
LangManager.sendMessage(pplayer, Lang.FAILED_EXECUTE_NOT_FOUND, altPlayerName); LangManager.sendMessage(pplayer, Lang.FAILED_EXECUTE_NOT_FOUND, altPlayerName);
@ -41,26 +41,26 @@ public class ResetCommandModule implements CommandModule {
DataManager.saveParticleGroup(pplayer.getUniqueId(), ParticleGroup.getDefaultGroup()); DataManager.saveParticleGroup(pplayer.getUniqueId(), ParticleGroup.getDefaultGroup());
LangManager.sendMessage(pplayer, Lang.RESET); LangManager.sendMessage(pplayer, Lang.RESET);
} }
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null; return null;
} }
public String getName() { public String getName() {
return "reset"; return "reset";
} }
public String getDescription() { public String getDescription() {
return Lang.RESET_COMMAND_DESCRIPTION.get(); return Lang.RESET_COMMAND_DESCRIPTION.get();
} }
public String getArguments() { public String getArguments() {
return ""; return "";
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return false; return false;
} }
} }

View file

@ -8,28 +8,28 @@ import com.esophose.playerparticles.particles.PPlayer;
public class StyleCommandModule implements CommandModule { public class StyleCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
LangManager.sendMessage(pplayer, Lang.COMMAND_REMOVED); LangManager.sendMessage(pplayer, Lang.COMMAND_REMOVED);
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null; return null;
} }
public String getName() { public String getName() {
return "style"; return "style";
} }
public String getDescription() { public String getDescription() {
return Lang.STYLE_COMMAND_DESCRIPTION.get(); return Lang.STYLE_COMMAND_DESCRIPTION.get();
} }
public String getArguments() { public String getArguments() {
return ""; return "";
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return true; return true;
} }
} }

View file

@ -13,10 +13,10 @@ import com.esophose.playerparticles.styles.api.ParticleStyleManager;
public class StylesCommandModule implements CommandModule { public class StylesCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
Player p = pplayer.getPlayer(); Player p = pplayer.getPlayer();
if (PermissionManager.getStylesUserHasPermissionFor(p).size() == 1) { if (PermissionManager.getStylesUserHasPermissionFor(p).size() == 1) {
LangManager.sendMessage(pplayer, Lang.NO_STYLES); LangManager.sendMessage(pplayer, Lang.NO_STYLES);
return; return;
} }
@ -34,26 +34,26 @@ public class StylesCommandModule implements CommandModule {
LangManager.sendCustomMessage(p, toSend); LangManager.sendCustomMessage(p, toSend);
LangManager.sendCustomMessage(p, Lang.USAGE.get() + " " + Lang.STYLE_USAGE.get()); LangManager.sendCustomMessage(p, Lang.USAGE.get() + " " + Lang.STYLE_USAGE.get());
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null; return null;
} }
public String getName() { public String getName() {
return "styles"; return "styles";
} }
public String getDescription() { public String getDescription() {
return Lang.STYLES_COMMAND_DESCRIPTION.get(); return Lang.STYLES_COMMAND_DESCRIPTION.get();
} }
public String getArguments() { public String getArguments() {
return ""; return "";
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return false; return false;
} }
} }

View file

@ -11,29 +11,29 @@ import com.esophose.playerparticles.particles.PPlayer;
public class VersionCommandModule implements CommandModule { public class VersionCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
LangManager.sendCustomMessage(pplayer, ChatColor.GOLD + "Running PlayerParticles v" + PlayerParticles.getPlugin().getDescription().getVersion()); LangManager.sendCustomMessage(pplayer, ChatColor.GOLD + "Running PlayerParticles v" + PlayerParticles.getPlugin().getDescription().getVersion());
LangManager.sendCustomMessage(pplayer, ChatColor.GOLD + "Plugin created by: Esophose"); LangManager.sendCustomMessage(pplayer, ChatColor.GOLD + "Plugin created by: Esophose");
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null; return null;
} }
public String getName() { public String getName() {
return "version"; return "version";
} }
public String getDescription() { public String getDescription() {
return Lang.VERSION_COMMAND_DESCRIPTION.get(); return Lang.VERSION_COMMAND_DESCRIPTION.get();
} }
public String getArguments() { public String getArguments() {
return ""; return "";
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return false; return false;
} }
} }

View file

@ -9,8 +9,8 @@ import com.esophose.playerparticles.particles.PPlayer;
public class WorldsCommandModule implements CommandModule { public class WorldsCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) { public void onCommandExecute(PPlayer pplayer, String[] args) {
if (DataManager.getDisabledWorlds() == null || DataManager.getDisabledWorlds().isEmpty()) { if (DataManager.getDisabledWorlds() == null || DataManager.getDisabledWorlds().isEmpty()) {
LangManager.sendMessage(pplayer, Lang.DISABLED_WORLDS_NONE); LangManager.sendMessage(pplayer, Lang.DISABLED_WORLDS_NONE);
return; return;
} }
@ -22,26 +22,26 @@ public class WorldsCommandModule implements CommandModule {
if (worlds.length() > 2) worlds = worlds.substring(0, worlds.length() - 2); if (worlds.length() > 2) worlds = worlds.substring(0, worlds.length() - 2);
LangManager.sendCustomMessage(pplayer, Lang.DISABLED_WORLDS.get() + " " + worlds); LangManager.sendCustomMessage(pplayer, Lang.DISABLED_WORLDS.get() + " " + worlds);
} }
public List<String> onTabComplete(PPlayer pplayer, String[] args) { public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null; return null;
} }
public String getName() { public String getName() {
return "worlds"; return "worlds";
} }
public String getDescription() { public String getDescription() {
return Lang.WORLDS_COMMAND_DESCRIPTION.get(); return Lang.WORLDS_COMMAND_DESCRIPTION.get();
} }
public String getArguments() { public String getArguments() {
return ""; return "";
} }
public boolean requiresEffects() { public boolean requiresEffects() {
return false; return false;
} }
} }

View file

@ -5,34 +5,34 @@ import java.sql.SQLException;
public abstract class DatabaseConnector { public abstract class DatabaseConnector {
/** /**
* Checks if the connection to the database has been created * Checks if the connection to the database has been created
* *
* @return If the connection is created or not * @return If the connection is created or not
*/ */
public abstract boolean isInitialized(); public abstract boolean isInitialized();
/** /**
* Closes all open connections to the database * Closes all open connections to the database
*/ */
public abstract void closeConnection(); public abstract 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 abstract void connect(ConnectionCallback callback); public abstract void connect(ConnectionCallback callback);
/** /**
* Gets a connection to the database * Gets a connection to the database
* *
* @return A Connection to the database * @return A Connection to the database
* @throws SQLException If an SQL problem occurs getting the connection * @throws SQLException If an SQL problem occurs getting the connection
*/ */
protected abstract Connection getConnection() throws SQLException; protected abstract Connection getConnection() throws SQLException;
/** /**
* 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 { public static interface ConnectionCallback {

View file

@ -11,7 +11,7 @@ import com.zaxxer.hikari.HikariDataSource;
public class MySqlDatabaseConnector extends DatabaseConnector { public class MySqlDatabaseConnector extends DatabaseConnector {
private HikariDataSource hikari; private HikariDataSource hikari;
private boolean initializedSuccessfully = false; private boolean initializedSuccessfully = false;
public MySqlDatabaseConnector(FileConfiguration pluginConfig) { public MySqlDatabaseConnector(FileConfiguration pluginConfig) {
@ -52,7 +52,7 @@ public class MySqlDatabaseConnector extends DatabaseConnector {
} }
protected Connection getConnection() throws SQLException { protected Connection getConnection() throws SQLException {
return hikari.getConnection(); return hikari.getConnection();
} }
} }

View file

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

View file

@ -6,51 +6,51 @@ import org.bukkit.Material;
import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor; import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
public class ColorData { public class ColorData {
private DyeColor dyeColor; private DyeColor dyeColor;
private Material material; private Material material;
private OrdinaryColor ordinaryColor; private OrdinaryColor ordinaryColor;
private String name; private String name;
public ColorData(DyeColor dyeColor, Material material, OrdinaryColor ordinaryColor, String name) { public ColorData(DyeColor dyeColor, Material material, OrdinaryColor ordinaryColor, String name) {
this.dyeColor = dyeColor; this.dyeColor = dyeColor;
this.material = material; this.material = material;
this.ordinaryColor = ordinaryColor; this.ordinaryColor = ordinaryColor;
this.name = name; this.name = name;
} }
/** /**
* Get the DyeColor * Get the DyeColor
* *
* @return The DyeColor * @return The DyeColor
*/ */
public DyeColor getDyeColor() { public DyeColor getDyeColor() {
return this.dyeColor; return this.dyeColor;
} }
/** /**
* Get the Material representing this color * Get the Material representing this color
* *
* @return The Material * @return The Material
*/ */
public Material getMaterial() { public Material getMaterial() {
return this.material; return this.material;
} }
/** /**
* Get the OrdinaryColor representing this color * Get the OrdinaryColor representing this color
* *
* @return The OrdinaryColor * @return The OrdinaryColor
*/ */
public OrdinaryColor getOrdinaryColor() { public OrdinaryColor getOrdinaryColor() {
return this.ordinaryColor; return this.ordinaryColor;
} }
/** /**
* Get the name of this color * Get the name of this color
* *
* @return The name of this color * @return The name of this color
*/ */
public String getName() { public String getName() {
return this.name; return this.name;
} }
} }

View file

@ -194,153 +194,141 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
// TODO: Delete these specialized getter methods once the new GUI is finished // TODO: Delete these specialized getter methods once the new GUI is finished
private static ParticleEffect getPPlayerEffect(PPlayer pplayer) { private static ParticleEffect getPPlayerEffect(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles(); List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticleEffect.NONE; if (particles.isEmpty()) return ParticleEffect.NONE;
return particles.get(0).getEffect(); return particles.get(0).getEffect();
} }
private static ParticleStyle getPPlayerStyle(PPlayer pplayer) { private static ParticleStyle getPPlayerStyle(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles(); List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return DefaultStyles.NONE; if (particles.isEmpty()) return DefaultStyles.NONE;
return particles.get(0).getStyle(); return particles.get(0).getStyle();
} }
private static Material getPPlayerItemMaterial(PPlayer pplayer) { private static Material getPPlayerItemMaterial(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles(); List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getItemMaterial(); if (particles.isEmpty()) return ParticlePair.getDefault().getItemMaterial();
return particles.get(0).getItemMaterial(); return particles.get(0).getItemMaterial();
} }
private static Material getPPlayerBlockMaterial(PPlayer pplayer) { private static Material getPPlayerBlockMaterial(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles(); List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getBlockMaterial(); if (particles.isEmpty()) return ParticlePair.getDefault().getBlockMaterial();
return particles.get(0).getBlockMaterial(); return particles.get(0).getBlockMaterial();
} }
private static OrdinaryColor getPPlayerColor(PPlayer pplayer) { private static OrdinaryColor getPPlayerColor(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles(); List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getColor(); if (particles.isEmpty()) return ParticlePair.getDefault().getColor();
return particles.get(0).getColor(); return particles.get(0).getColor();
} }
private static NoteColor getPPlayerNoteColor(PPlayer pplayer) { private static NoteColor getPPlayerNoteColor(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles(); List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getNoteColor(); if (particles.isEmpty()) return ParticlePair.getDefault().getNoteColor();
return particles.get(0).getNoteColor(); return particles.get(0).getNoteColor();
} }
private static Material getPPlayerSpawnMaterial(PPlayer pplayer) { private static Material getPPlayerSpawnMaterial(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles(); List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getSpawnMaterial(); if (particles.isEmpty()) return ParticlePair.getDefault().getSpawnMaterial();
return particles.get(0).getSpawnMaterial(); return particles.get(0).getSpawnMaterial();
} }
private static ParticleColor getPPlayerSpawnColor(PPlayer pplayer) { private static ParticleColor getPPlayerSpawnColor(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles(); List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getSpawnColor(); if (particles.isEmpty()) return ParticlePair.getDefault().getSpawnColor();
return particles.get(0).getSpawnColor(); return particles.get(0).getSpawnColor();
} }
private static String getPPlayerDataString(PPlayer pplayer) { private static String getPPlayerDataString(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles(); List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getDataString(); if (particles.isEmpty()) return ParticlePair.getDefault().getDataString();
return particles.get(0).getDataString(); return particles.get(0).getDataString();
} }
private static void setPPlayerEffect(PPlayer pplayer, ParticleEffect effect) { private static void setPPlayerEffect(PPlayer pplayer, ParticleEffect effect) {
List<ParticlePair> particles = pplayer.getActiveParticles(); List<ParticlePair> particles = pplayer.getActiveParticles();
ParticlePair particle; ParticlePair particle;
if (particles.isEmpty()) if (particles.isEmpty()) particle = ParticlePair.getDefault(pplayer.getUniqueId());
particle = ParticlePair.getDefault(pplayer.getUniqueId()); else particle = particles.get(0);
else
particle = particles.get(0);
particle.setEffect(effect); particle.setEffect(effect);
particles.clear(); particles.clear();
particles.add(particle); particles.add(particle);
ParticleGroup group = new ParticleGroup(null, particles); ParticleGroup group = new ParticleGroup(null, particles);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group); DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
} }
private static void setPPlayerStyle(PPlayer pplayer, ParticleStyle style) { private static void setPPlayerStyle(PPlayer pplayer, ParticleStyle style) {
List<ParticlePair> particles = pplayer.getActiveParticles(); List<ParticlePair> particles = pplayer.getActiveParticles();
ParticlePair particle; ParticlePair particle;
if (particles.isEmpty()) if (particles.isEmpty()) particle = ParticlePair.getDefault(pplayer.getUniqueId());
particle = ParticlePair.getDefault(pplayer.getUniqueId()); else particle = particles.get(0);
else
particle = particles.get(0);
particle.setStyle(style); particle.setStyle(style);
particles.clear(); particles.clear();
particles.add(particle); particles.add(particle);
ParticleGroup group = new ParticleGroup(null, particles); ParticleGroup group = new ParticleGroup(null, particles);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group); DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
} }
private static void setPPlayerItemMaterial(PPlayer pplayer, Material material) { private static void setPPlayerItemMaterial(PPlayer pplayer, Material material) {
List<ParticlePair> particles = pplayer.getActiveParticles(); List<ParticlePair> particles = pplayer.getActiveParticles();
ParticlePair particle; ParticlePair particle;
if (particles.isEmpty()) if (particles.isEmpty()) particle = ParticlePair.getDefault(pplayer.getUniqueId());
particle = ParticlePair.getDefault(pplayer.getUniqueId()); else particle = particles.get(0);
else
particle = particles.get(0);
particle.setItemMaterial(material); particle.setItemMaterial(material);
particles.clear(); particles.clear();
particles.add(particle); particles.add(particle);
ParticleGroup group = new ParticleGroup(null, particles); ParticleGroup group = new ParticleGroup(null, particles);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group); DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
} }
private static void setPPlayerBlockMaterial(PPlayer pplayer, Material material) { private static void setPPlayerBlockMaterial(PPlayer pplayer, Material material) {
List<ParticlePair> particles = pplayer.getActiveParticles(); List<ParticlePair> particles = pplayer.getActiveParticles();
ParticlePair particle; ParticlePair particle;
if (particles.isEmpty()) if (particles.isEmpty()) particle = ParticlePair.getDefault(pplayer.getUniqueId());
particle = ParticlePair.getDefault(pplayer.getUniqueId()); else particle = particles.get(0);
else
particle = particles.get(0);
particle.setBlockMaterial(material); particle.setBlockMaterial(material);
particles.clear(); particles.clear();
particles.add(particle); particles.add(particle);
ParticleGroup group = new ParticleGroup(null, particles); ParticleGroup group = new ParticleGroup(null, particles);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group); DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
} }
private static void setPPlayerColor(PPlayer pplayer, OrdinaryColor color) { private static void setPPlayerColor(PPlayer pplayer, OrdinaryColor color) {
List<ParticlePair> particles = pplayer.getActiveParticles(); List<ParticlePair> particles = pplayer.getActiveParticles();
ParticlePair particle; ParticlePair particle;
if (particles.isEmpty()) if (particles.isEmpty()) particle = ParticlePair.getDefault(pplayer.getUniqueId());
particle = ParticlePair.getDefault(pplayer.getUniqueId()); else particle = particles.get(0);
else
particle = particles.get(0);
particle.setColor(color); particle.setColor(color);
particles.clear(); particles.clear();
particles.add(particle); particles.add(particle);
ParticleGroup group = new ParticleGroup(null, particles); ParticleGroup group = new ParticleGroup(null, particles);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group); DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
} }
private static void setPPlayerNoteColor(PPlayer pplayer, NoteColor noteColor) { private static void setPPlayerNoteColor(PPlayer pplayer, NoteColor noteColor) {
List<ParticlePair> particles = pplayer.getActiveParticles(); List<ParticlePair> particles = pplayer.getActiveParticles();
ParticlePair particle; ParticlePair particle;
if (particles.isEmpty()) if (particles.isEmpty()) particle = ParticlePair.getDefault(pplayer.getUniqueId());
particle = ParticlePair.getDefault(pplayer.getUniqueId()); else particle = particles.get(0);
else
particle = particles.get(0);
particle.setNoteColor(noteColor); particle.setNoteColor(noteColor);
particles.clear(); particles.clear();
particles.add(particle); particles.add(particle);
ParticleGroup group = new ParticleGroup(null, particles); ParticleGroup group = new ParticleGroup(null, particles);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group); DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
} }
/** /**
@ -425,9 +413,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
public static void changeState(PPlayer pplayer, GuiState state) { public static void changeState(PPlayer pplayer, GuiState state) {
Player player = pplayer.getPlayer(); Player player = pplayer.getPlayer();
if ((state == GuiState.EFFECT && PermissionManager.getEffectsUserHasPermissionFor(player).size() == 1) || if ((state == GuiState.EFFECT && PermissionManager.getEffectsUserHasPermissionFor(player).size() == 1) || (state == GuiState.STYLE && PermissionManager.getStylesUserHasPermissionFor(player).size() == 1) || (state == GuiState.DATA && getPPlayerSpawnMaterial(pplayer) == null && getPPlayerSpawnColor(pplayer) == null)) return;
(state == GuiState.STYLE && PermissionManager.getStylesUserHasPermissionFor(player).size() == 1) ||
(state == GuiState.DATA && getPPlayerSpawnMaterial(pplayer) == null && getPPlayerSpawnColor(pplayer) == null)) return;
// Update the state and create an inventory for the player if one isn't already open for them // Update the state and create an inventory for the player if one isn't already open for them
// If they have the wrong inventory open for some reason, create a new one and open it for them // If they have the wrong inventory open for some reason, create a new one and open it for them
@ -473,9 +459,9 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
ItemStack currentIcon; ItemStack currentIcon;
Material playerHead = ParticleUtils.closestMatch("PLAYER_HEAD"); Material playerHead = ParticleUtils.closestMatch("PLAYER_HEAD");
if (playerHead != null) { if (playerHead != null) {
currentIcon = new ItemStack(playerHead, 1); currentIcon = new ItemStack(playerHead, 1);
} else { } else {
currentIcon = new ItemStack(ParticleUtils.closestMatch("SKULL_ITEM"), 1, (short) SkullType.PLAYER.ordinal()); currentIcon = new ItemStack(ParticleUtils.closestMatch("SKULL_ITEM"), 1, (short) SkullType.PLAYER.ordinal());
} }
SkullMeta currentIconMeta = (SkullMeta) currentIcon.getItemMeta(); SkullMeta currentIconMeta = (SkullMeta) currentIcon.getItemMeta();
@ -486,7 +472,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
currentIconLore[2] = ChatColor.YELLOW + "Active Data: " + ChatColor.AQUA + getPPlayerDataString(pplayer); currentIconLore[2] = ChatColor.YELLOW + "Active Data: " + ChatColor.AQUA + getPPlayerDataString(pplayer);
currentIconMeta.setLore(Arrays.asList(currentIconLore)); currentIconMeta.setLore(Arrays.asList(currentIconLore));
currentIconMeta.setOwner(player.getName()); currentIconMeta.setOwner(player.getName());
//currentIconMeta.setOwningPlayer(Bukkit.getOfflinePlayer(player.getUniqueId())); // This doesn't exist in 1.9 // currentIconMeta.setOwningPlayer(Bukkit.getOfflinePlayer(player.getUniqueId())); // This doesn't exist in 1.9
currentIcon.setItemMeta(currentIconMeta); currentIcon.setItemMeta(currentIconMeta);
ItemStack effectIcon = new ItemStack(defaultMenuIcons[0], 1); ItemStack effectIcon = new ItemStack(defaultMenuIcons[0], 1);
@ -632,8 +618,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
while (materialBag.size() < 28) { // Grab 28 random materials that are an item while (materialBag.size() < 28) { // Grab 28 random materials that are an item
Material randomMaterial = ITEM_MATERIALS.get(RANDOM.nextInt(ITEM_MATERIALS.size())); Material randomMaterial = ITEM_MATERIALS.get(RANDOM.nextInt(ITEM_MATERIALS.size()));
if (!materialBag.contains(randomMaterial)) if (!materialBag.contains(randomMaterial)) materialBag.add(randomMaterial);
materialBag.add(randomMaterial);
} }
for (int i = 10; i <= 16; i++) { // Top row for (int i = 10; i <= 16; i++) { // Top row
@ -657,8 +642,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
while (materialBag.size() < 28) { // Grab 28 random materials that are an item while (materialBag.size() < 28) { // Grab 28 random materials that are an item
Material randomMaterial = BLOCK_MATERIALS.get(RANDOM.nextInt(BLOCK_MATERIALS.size())); Material randomMaterial = BLOCK_MATERIALS.get(RANDOM.nextInt(BLOCK_MATERIALS.size()));
if (!materialBag.contains(randomMaterial)) if (!materialBag.contains(randomMaterial)) materialBag.add(randomMaterial);
materialBag.add(randomMaterial);
} }
for (int i = 10; i <= 16; i++) { // Top row for (int i = 10; i <= 16; i++) { // Top row
@ -731,11 +715,11 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
} }
break; break;
case EFFECT: case EFFECT:
setPPlayerEffect(pplayer, ParticleManager.effectFromString(name)); setPPlayerEffect(pplayer, ParticleManager.effectFromString(name));
changeState(pplayer, GuiState.DEFAULT); changeState(pplayer, GuiState.DEFAULT);
break; break;
case STYLE: case STYLE:
setPPlayerStyle(pplayer, ParticleStyleManager.styleFromString(name)); setPPlayerStyle(pplayer, ParticleStyleManager.styleFromString(name));
changeState(pplayer, GuiState.DEFAULT); changeState(pplayer, GuiState.DEFAULT);
break; break;
case DATA: case DATA:
@ -743,14 +727,14 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
if (pe.hasProperty(ParticleProperty.COLORABLE)) { if (pe.hasProperty(ParticleProperty.COLORABLE)) {
if (pe == ParticleEffect.NOTE) { if (pe == ParticleEffect.NOTE) {
if (clicked.getItemMeta().getDisplayName().equals(rainbowName)) { if (clicked.getItemMeta().getDisplayName().equals(rainbowName)) {
setPPlayerNoteColor(pplayer, new NoteColor(99)); setPPlayerNoteColor(pplayer, new NoteColor(99));
} else { } else {
int note = Integer.parseInt(ChatColor.stripColor(clicked.getItemMeta().getDisplayName()).substring(6)); int note = Integer.parseInt(ChatColor.stripColor(clicked.getItemMeta().getDisplayName()).substring(6));
setPPlayerNoteColor(pplayer, new NoteColor(note)); setPPlayerNoteColor(pplayer, new NoteColor(note));
} }
} else { } else {
if (clicked.getItemMeta().getDisplayName().equals(rainbowName)) { if (clicked.getItemMeta().getDisplayName().equals(rainbowName)) {
setPPlayerColor(pplayer, new OrdinaryColor(999, 999, 999)); setPPlayerColor(pplayer, new OrdinaryColor(999, 999, 999));
} else { } else {
for (int i = 0; i < colorMapping.length; i++) { for (int i = 0; i < colorMapping.length; i++) {
if (clicked.getItemMeta().getDisplayName().equals(colorMapping[i].getName())) { if (clicked.getItemMeta().getDisplayName().equals(colorMapping[i].getName())) {
@ -762,9 +746,9 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
} else if (pe.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) { } else if (pe.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
Material clickedMaterial = clicked.getType(); // All preset materials have a data value of 0 Material clickedMaterial = clicked.getType(); // All preset materials have a data value of 0
if (pe == ParticleEffect.ITEM) { if (pe == ParticleEffect.ITEM) {
setPPlayerItemMaterial(pplayer, clickedMaterial); setPPlayerItemMaterial(pplayer, clickedMaterial);
} else { } else {
setPPlayerBlockMaterial(pplayer, clickedMaterial); setPPlayerBlockMaterial(pplayer, clickedMaterial);
} }
} }
@ -851,15 +835,15 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
* @param colorIndex What color to use * @param colorIndex What color to use
* @return An ItemStack formatted to be displayed in the GUI * @return An ItemStack formatted to be displayed in the GUI
*/ */
private static ItemStack getItemForColorData(OrdinaryColor currentColor, int colorIndex) { private static ItemStack getItemForColorData(OrdinaryColor currentColor, int colorIndex) {
ColorData colorData = colorMapping[colorIndex]; ColorData colorData = colorMapping[colorIndex];
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();
ItemStack colorIcon; ItemStack colorIcon;
if (colorData.getMaterial() != null) { // Use 1.13 materials if (colorData.getMaterial() != null) { // Use 1.13 materials
colorIcon = new ItemStack(colorData.getMaterial()); colorIcon = new ItemStack(colorData.getMaterial());
} else { // Use < 1.13 dye colors } else { // Use < 1.13 dye colors
colorIcon = new Dye(colorData.getDyeColor()).toItemStack(1); colorIcon = new Dye(colorData.getDyeColor()).toItemStack(1);
} }
ItemMeta colorIconMeta = colorIcon.getItemMeta(); ItemMeta colorIconMeta = colorIcon.getItemMeta();
@ -905,13 +889,13 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
* *
* @return An ItemStack formatted to be displayed in the GUI * @return An ItemStack formatted to be displayed in the GUI
*/ */
private static ItemStack getItemForRainbowColorData(OrdinaryColor currentColor, DyeColor dyeColor) { private static ItemStack getItemForRainbowColorData(OrdinaryColor currentColor, DyeColor dyeColor) {
ColorData colorData = getColorDataFromOrdinaryColor(dyeColor); ColorData colorData = getColorDataFromOrdinaryColor(dyeColor);
ItemStack rainbowIcon; ItemStack rainbowIcon;
if (colorData.getMaterial() != null) { // Use 1.13 materials if (colorData.getMaterial() != null) { // Use 1.13 materials
rainbowIcon = new ItemStack(colorData.getMaterial()); rainbowIcon = new ItemStack(colorData.getMaterial());
} else { // Use < 1.13 dye colors } else { // Use < 1.13 dye colors
rainbowIcon = new Dye(colorData.getDyeColor()).toItemStack(1); rainbowIcon = new Dye(colorData.getDyeColor()).toItemStack(1);
} }
ItemMeta rainbowIconMeta = rainbowIcon.getItemMeta(); ItemMeta rainbowIconMeta = rainbowIcon.getItemMeta();
@ -933,13 +917,13 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
* *
* @return An ItemStack formatted to be displayed in the GUI * @return An ItemStack formatted to be displayed in the GUI
*/ */
private static ItemStack getItemForRainbowNoteData(NoteColor currentColor, DyeColor dyeColor) { private static ItemStack getItemForRainbowNoteData(NoteColor currentColor, DyeColor dyeColor) {
ColorData colorData = getColorDataFromOrdinaryColor(dyeColor); ColorData colorData = getColorDataFromOrdinaryColor(dyeColor);
ItemStack rainbowIcon; ItemStack rainbowIcon;
if (colorData.getMaterial() != null) { // Use 1.13 materials if (colorData.getMaterial() != null) { // Use 1.13 materials
rainbowIcon = new ItemStack(colorData.getMaterial()); rainbowIcon = new ItemStack(colorData.getMaterial());
} else { // Use < 1.13 dye colors } else { // Use < 1.13 dye colors
rainbowIcon = new Dye(colorData.getDyeColor()).toItemStack(1); rainbowIcon = new Dye(colorData.getDyeColor()).toItemStack(1);
} }
ItemMeta rainbowIconMeta = rainbowIcon.getItemMeta(); ItemMeta rainbowIconMeta = rainbowIcon.getItemMeta();
@ -977,10 +961,9 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
* @return The found ColorData object, null if not found * @return The found ColorData object, null if not found
*/ */
private static ColorData getColorDataFromOrdinaryColor(DyeColor color) { private static ColorData getColorDataFromOrdinaryColor(DyeColor color) {
for (ColorData colorData : colorMapping) for (ColorData colorData : colorMapping)
if (colorData.getDyeColor().equals(color)) if (colorData.getDyeColor().equals(color)) return colorData;
return colorData; return null;
return null;
} }
} }

View file

@ -33,7 +33,7 @@ import com.esophose.playerparticles.util.ParticleUtils;
* All data changes to PPlayers such as group or fixed effect changes must be done through here, * All data changes to PPlayers such as group or fixed effect changes must be done through here,
* rather than directly on the PPlayer object * rather than directly on the PPlayer object
*/ */
public class DataManager { // @formatter:off public class DataManager {
/** /**
* The disabled worlds cached for quick access * The disabled worlds cached for quick access
@ -53,7 +53,9 @@ public class DataManager { // @formatter:off
/** /**
* This is not instantiable * This is not instantiable
*/ */
private DataManager() { } private DataManager() {
}
/** /**
* Gets a PPlayer from cache * Gets a PPlayer from cache
@ -65,8 +67,7 @@ public class DataManager { // @formatter:off
*/ */
public static PPlayer getPPlayer(UUID playerUUID) { public static PPlayer getPPlayer(UUID playerUUID) {
for (PPlayer pp : ParticleManager.particlePlayers) for (PPlayer pp : ParticleManager.particlePlayers)
if (pp.getUniqueId() == playerUUID) if (pp.getUniqueId() == playerUUID) return pp;
return pp;
return null; return null;
} }
@ -85,93 +86,93 @@ public class DataManager { // @formatter:off
} }
async(() -> { async(() -> {
List<ParticleGroup> groups = new ArrayList<ParticleGroup>(); List<ParticleGroup> groups = new ArrayList<ParticleGroup>();
List<FixedParticleEffect> fixedParticles = new ArrayList<FixedParticleEffect>(); List<FixedParticleEffect> fixedParticles = new ArrayList<FixedParticleEffect>();
PlayerParticles.databaseConnector.connect((connection) -> { PlayerParticles.databaseConnector.connect((connection) -> {
// Load particle groups // Load particle groups
String groupQuery = "SELECT * FROM pp_group g " + String groupQuery = "SELECT * FROM pp_group g " + // @formatter:off
"JOIN pp_particle p ON g.uuid = p.group_uuid " + "JOIN pp_particle p ON g.uuid = p.group_uuid " +
"WHERE g.owner_uuid = ?"; "WHERE g.owner_uuid = ?"; // @formatter:on
try (PreparedStatement statement = connection.prepareStatement(groupQuery)) { try (PreparedStatement statement = connection.prepareStatement(groupQuery)) {
statement.setString(1, playerUUID.toString()); statement.setString(1, playerUUID.toString());
ResultSet result = statement.executeQuery(); ResultSet result = statement.executeQuery();
while (result.next()) { while (result.next()) {
// Group properties // Group properties
String groupName = result.getString("name"); String groupName = result.getString("name");
// Particle properties // Particle properties
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 = ParticleStyleManager.styleFromString(result.getString("style")); ParticleStyle style = ParticleStyleManager.styleFromString(result.getString("style"));
Material itemMaterial = ParticleUtils.closestMatchWithFallback(result.getString("item_material")); Material itemMaterial = ParticleUtils.closestMatchWithFallback(result.getString("item_material"));
Material blockMaterial = ParticleUtils.closestMatchWithFallback(result.getString("block_material")); Material blockMaterial = ParticleUtils.closestMatchWithFallback(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);
// Try to add particle to an existing group // Try to add particle to an existing group
boolean groupAlreadyExists = false; boolean groupAlreadyExists = false;
for (ParticleGroup group : groups) { for (ParticleGroup group : groups) {
if (group.getName().equalsIgnoreCase(groupName)) { if (group.getName().equalsIgnoreCase(groupName)) {
group.getParticles().add(particle); group.getParticles().add(particle);
groupAlreadyExists = true; groupAlreadyExists = true;
break; break;
} }
} }
// 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<ParticlePair>();
particles.add(particle); particles.add(particle);
ParticleGroup newGroup = new ParticleGroup(groupName, particles); ParticleGroup newGroup = new ParticleGroup(groupName, particles);
groups.add(newGroup); groups.add(newGroup);
} }
} }
} }
// Load fixed effects // Load fixed effects
String fixedQuery = "SELECT f.id AS f_id, f.world, f.xPos, f.yPos, f.zPos, p.id AS p_id, p.effect, p.style, p.item_material, p.block_material, p.note, p.r, p.g, p.b FROM pp_fixed f " + String fixedQuery = "SELECT f.id AS f_id, f.world, f.xPos, f.yPos, f.zPos, p.id AS p_id, p.effect, p.style, p.item_material, p.block_material, p.note, p.r, p.g, p.b FROM pp_fixed f " + // @formatter:off
"JOIN pp_particle p ON f.particle_uuid = p.uuid " + "JOIN pp_particle p ON f.particle_uuid = p.uuid " +
"WHERE f.owner_uuid = ?"; "WHERE f.owner_uuid = ?"; // @formatter:on
try (PreparedStatement statement = connection.prepareStatement(fixedQuery)) { try (PreparedStatement statement = connection.prepareStatement(fixedQuery)) {
statement.setString(1, playerUUID.toString()); statement.setString(1, playerUUID.toString());
ResultSet result = statement.executeQuery(); ResultSet result = statement.executeQuery();
while (result.next()) { while (result.next()) {
// Fixed effect properties // Fixed effect properties
int fixedEffectId = result.getInt("f_id"); int fixedEffectId = result.getInt("f_id");
String worldName = result.getString("world"); String worldName = result.getString("world");
double xPos = result.getDouble("xPos"); double xPos = result.getDouble("xPos");
double yPos = result.getDouble("yPos"); double yPos = result.getDouble("yPos");
double zPos = result.getDouble("zPos"); double zPos = result.getDouble("zPos");
// Particle properties // Particle properties
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 = ParticleStyleManager.styleFromString(result.getString("style")); ParticleStyle style = ParticleStyleManager.styleFromString(result.getString("style"));
Material itemMaterial = ParticleUtils.closestMatchWithFallback(result.getString("item_material")); Material itemMaterial = ParticleUtils.closestMatchWithFallback(result.getString("item_material"));
Material blockMaterial = ParticleUtils.closestMatchWithFallback(result.getString("block_material")); Material blockMaterial = ParticleUtils.closestMatchWithFallback(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);
fixedParticles.add(new FixedParticleEffect(playerUUID, fixedEffectId, worldName, xPos, yPos, zPos, particle)); fixedParticles.add(new FixedParticleEffect(playerUUID, fixedEffectId, worldName, xPos, yPos, zPos, particle));
} }
} }
if (groups.size() == 0) { // If there aren't any groups then this is a brand new PPlayer and we need to save a new active group for them if (groups.size() == 0) { // If there aren't any groups then this is a brand new PPlayer and we need to save a new active group for them
ParticleGroup activeGroup = new ParticleGroup(null, new ArrayList<ParticlePair>()); ParticleGroup activeGroup = new ParticleGroup(null, new ArrayList<ParticlePair>());
saveParticleGroup(playerUUID, activeGroup); saveParticleGroup(playerUUID, activeGroup);
groups.add(activeGroup); groups.add(activeGroup);
} }
PPlayer loadedPPlayer = new PPlayer(playerUUID, groups, fixedParticles); PPlayer loadedPPlayer = new PPlayer(playerUUID, groups, fixedParticles);
ParticleManager.particlePlayers.add(loadedPPlayer); ParticleManager.particlePlayers.add(loadedPPlayer);
sync(() -> callback.execute(loadedPPlayer)); sync(() -> callback.execute(loadedPPlayer));
}); });
}); });
} }
@ -182,68 +183,68 @@ public class DataManager { // @formatter:off
* @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.databaseConnector.connect((connection) -> { PlayerParticles.databaseConnector.connect((connection) -> {
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)) {
statement.setString(1, playerUUID.toString()); statement.setString(1, playerUUID.toString());
statement.setString(2, group.getName()); statement.setString(2, group.getName());
String groupUUID = null; String groupUUID = null;
ResultSet result = statement.executeQuery(); ResultSet result = statement.executeQuery();
if (result.next()) { // Clear out particles from existing group if (result.next()) { // Clear out particles from existing group
groupUUID = result.getString("uuid"); groupUUID = result.getString("uuid");
String particlesDeleteQuery = "DELETE FROM pp_particle WHERE group_uuid = ?"; String particlesDeleteQuery = "DELETE FROM pp_particle WHERE group_uuid = ?";
PreparedStatement particlesDeleteStatement = connection.prepareStatement(particlesDeleteQuery); PreparedStatement particlesDeleteStatement = connection.prepareStatement(particlesDeleteQuery);
particlesDeleteStatement.setString(1, result.getString("uuid")); particlesDeleteStatement.setString(1, result.getString("uuid"));
particlesDeleteStatement.executeUpdate(); particlesDeleteStatement.executeUpdate();
} else { // Create new group } else { // Create new group
groupUUID = UUID.randomUUID().toString(); groupUUID = UUID.randomUUID().toString();
String groupCreateQuery = "INSERT INTO pp_group (uuid, owner_uuid, name) VALUES (?, ?, ?)"; String groupCreateQuery = "INSERT INTO pp_group (uuid, owner_uuid, name) VALUES (?, ?, ?)";
PreparedStatement groupCreateStatement = connection.prepareStatement(groupCreateQuery); PreparedStatement groupCreateStatement = connection.prepareStatement(groupCreateQuery);
groupCreateStatement.setString(1, groupUUID); groupCreateStatement.setString(1, groupUUID);
groupCreateStatement.setString(2, playerUUID.toString()); groupCreateStatement.setString(2, playerUUID.toString());
groupCreateStatement.setString(3, group.getName()); groupCreateStatement.setString(3, group.getName());
groupCreateStatement.executeUpdate(); groupCreateStatement.executeUpdate();
} }
// Fill group with new particles // Fill group with new particles
String createParticlesQuery = "INSERT INTO pp_particle (uuid, group_uuid, id, effect, style, item_material, block_material, note, r, g, b) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; String createParticlesQuery = "INSERT INTO pp_particle (uuid, group_uuid, id, effect, style, item_material, block_material, note, r, g, b) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement particlesStatement = connection.prepareStatement(createParticlesQuery); PreparedStatement particlesStatement = connection.prepareStatement(createParticlesQuery);
for (ParticlePair particle : group.getParticles()) { for (ParticlePair particle : group.getParticles()) {
particlesStatement.setString(1, UUID.randomUUID().toString()); particlesStatement.setString(1, UUID.randomUUID().toString());
particlesStatement.setString(2, groupUUID); particlesStatement.setString(2, groupUUID);
particlesStatement.setInt(3, particle.getId()); particlesStatement.setInt(3, particle.getId());
particlesStatement.setString(4, particle.getEffect().getName()); particlesStatement.setString(4, particle.getEffect().getName());
particlesStatement.setString(5, particle.getStyle().getName()); particlesStatement.setString(5, particle.getStyle().getName());
particlesStatement.setString(6, particle.getItemMaterial().name()); particlesStatement.setString(6, particle.getItemMaterial().name());
particlesStatement.setString(7, particle.getBlockMaterial().name()); particlesStatement.setString(7, particle.getBlockMaterial().name());
particlesStatement.setInt(8, particle.getNoteColor().getNote()); particlesStatement.setInt(8, particle.getNoteColor().getNote());
particlesStatement.setInt(9, particle.getColor().getRed()); particlesStatement.setInt(9, particle.getColor().getRed());
particlesStatement.setInt(10, particle.getColor().getGreen()); particlesStatement.setInt(10, particle.getColor().getGreen());
particlesStatement.setInt(11, particle.getColor().getBlue()); particlesStatement.setInt(11, particle.getColor().getBlue());
particlesStatement.addBatch(); particlesStatement.addBatch();
} }
} }
}); });
}); });
getPPlayer(playerUUID, (pplayer) -> { getPPlayer(playerUUID, (pplayer) -> {
String groupName = group.getName() == null ? "" : group.getName(); String groupName = group.getName() == null ? "" : group.getName();
for (ParticleGroup existing : pplayer.getParticles()) { for (ParticleGroup existing : pplayer.getParticles()) {
String existingName = existing.getName() == null ? "" : existing.getName(); String existingName = existing.getName() == null ? "" : existing.getName();
if (groupName.equalsIgnoreCase(existingName)) { if (groupName.equalsIgnoreCase(existingName)) {
pplayer.getParticles().remove(existing); pplayer.getParticles().remove(existing);
break; break;
} }
} }
pplayer.getParticles().add(group); pplayer.getParticles().add(group);
}); });
} }
/** /**
@ -253,41 +254,41 @@ public class DataManager { // @formatter:off
* @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.databaseConnector.connect((connection) -> { PlayerParticles.databaseConnector.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 = ?";
// Execute group uuid query // Execute group uuid query
String groupUUID = null; String groupUUID = null;
try (PreparedStatement statement = connection.prepareStatement(groupQuery)) { try (PreparedStatement statement = connection.prepareStatement(groupQuery)) {
statement.setString(1, playerUUID.toString()); statement.setString(1, playerUUID.toString());
statement.setString(2, group.getName()); statement.setString(2, group.getName());
ResultSet result = statement.executeQuery(); ResultSet result = statement.executeQuery();
groupUUID = result.getString("uuid"); groupUUID = result.getString("uuid");
} }
// Execute particle delete update // Execute particle delete update
try (PreparedStatement statement = connection.prepareStatement(particleDeleteQuery)) { try (PreparedStatement statement = connection.prepareStatement(particleDeleteQuery)) {
statement.setString(1, groupUUID); statement.setString(1, groupUUID);
statement.executeUpdate(); statement.executeUpdate();
} }
// Execute group delete update // Execute group delete update
try (PreparedStatement statement = connection.prepareStatement(groupDeleteQuery)) { try (PreparedStatement statement = connection.prepareStatement(groupDeleteQuery)) {
statement.setString(1, groupUUID); statement.setString(1, groupUUID);
statement.executeUpdate(); statement.executeUpdate();
} }
}); });
}); });
getPPlayer(playerUUID, (pplayer) -> { getPPlayer(playerUUID, (pplayer) -> {
pplayer.getParticles().remove(group); pplayer.getParticles().remove(group);
}); });
} }
/** /**
@ -297,44 +298,44 @@ public class DataManager { // @formatter:off
* @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.databaseConnector.connect((connection) -> { PlayerParticles.databaseConnector.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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
try (PreparedStatement statement = connection.prepareStatement(particleQuery)) { try (PreparedStatement statement = connection.prepareStatement(particleQuery)) {
ParticlePair particle = fixedEffect.getParticlePair(); ParticlePair particle = fixedEffect.getParticlePair();
statement.setString(1, particleUUID); statement.setString(1, particleUUID);
statement.setString(2, null); statement.setString(2, null);
statement.setInt(3, fixedEffect.getId()); statement.setInt(3, fixedEffect.getId());
statement.setString(4, particle.getEffect().getName()); statement.setString(4, particle.getEffect().getName());
statement.setString(5, particle.getStyle().getName()); statement.setString(5, particle.getStyle().getName());
statement.setString(6, particle.getItemMaterial().name()); statement.setString(6, particle.getItemMaterial().name());
statement.setString(7, particle.getBlockMaterial().name()); statement.setString(7, particle.getBlockMaterial().name());
statement.setInt(8, particle.getNoteColor().getNote()); statement.setInt(8, particle.getNoteColor().getNote());
statement.setInt(9, particle.getColor().getRed()); statement.setInt(9, particle.getColor().getRed());
statement.setInt(10, particle.getColor().getGreen()); statement.setInt(10, particle.getColor().getGreen());
statement.setInt(11, particle.getColor().getBlue()); statement.setInt(11, particle.getColor().getBlue());
statement.executeUpdate(); statement.executeUpdate();
} }
String fixedEffectQuery = "INSERT INTO pp_fixed (owner_uuid, id, particle_uuid, world, xPos, yPos, zPos) VALUES (?, ?, ?, ?, ?, ?, ?)"; String fixedEffectQuery = "INSERT INTO pp_fixed (owner_uuid, id, particle_uuid, world, xPos, yPos, zPos) VALUES (?, ?, ?, ?, ?, ?, ?)";
try (PreparedStatement statement = connection.prepareStatement(fixedEffectQuery)) { try (PreparedStatement statement = connection.prepareStatement(fixedEffectQuery)) {
statement.setString(1, fixedEffect.getOwnerUniqueId().toString()); statement.setString(1, fixedEffect.getOwnerUniqueId().toString());
statement.setInt(2, fixedEffect.getId()); statement.setInt(2, fixedEffect.getId());
statement.setString(3, particleUUID); statement.setString(3, particleUUID);
statement.setString(4, fixedEffect.getLocation().getWorld().getName()); statement.setString(4, fixedEffect.getLocation().getWorld().getName());
statement.setDouble(5, fixedEffect.getLocation().getX()); statement.setDouble(5, fixedEffect.getLocation().getX());
statement.setDouble(6, fixedEffect.getLocation().getY()); statement.setDouble(6, fixedEffect.getLocation().getY());
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);
}); });
} }
/** /**
@ -346,54 +347,53 @@ public class DataManager { // @formatter:off
* @param callback The callback to execute with if the fixed effect was removed or not * @param callback The callback to execute with if the fixed effect was removed or not
*/ */
public static void removeFixedEffect(UUID playerUUID, int id) { public static void removeFixedEffect(UUID playerUUID, int id) {
async(() -> { async(() -> {
PlayerParticles.databaseConnector.connect((connection) -> { PlayerParticles.databaseConnector.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 = ?";
try (PreparedStatement statement = connection.prepareStatement(particleUUIDQuery)) { try (PreparedStatement statement = connection.prepareStatement(particleUUIDQuery)) {
statement.setString(1, playerUUID.toString()); statement.setString(1, playerUUID.toString());
statement.setInt(2, id); statement.setInt(2, id);
ResultSet result = statement.executeQuery(); ResultSet result = statement.executeQuery();
particleUUID = result.getString("particle_uuid"); particleUUID = result.getString("particle_uuid");
} }
String particleDeleteQuery = "DELETE FROM pp_particle WHERE uuid = ?"; String particleDeleteQuery = "DELETE FROM pp_particle WHERE uuid = ?";
try (PreparedStatement statement = connection.prepareStatement(particleDeleteQuery)) { try (PreparedStatement statement = connection.prepareStatement(particleDeleteQuery)) {
statement.setString(1, particleUUID); statement.setString(1, particleUUID);
statement.executeUpdate(); statement.executeUpdate();
} }
String fixedEffectDeleteQuery = "DELETE FROM pp_fixed WHERE owner_uuid = ? AND id = ?"; String fixedEffectDeleteQuery = "DELETE FROM pp_fixed WHERE owner_uuid = ? AND id = ?";
try (PreparedStatement statement = connection.prepareStatement(fixedEffectDeleteQuery)) { try (PreparedStatement statement = connection.prepareStatement(fixedEffectDeleteQuery)) {
statement.setString(1, playerUUID.toString()); statement.setString(1, playerUUID.toString());
statement.setInt(2, id); statement.setInt(2, id);
statement.executeUpdate(); statement.executeUpdate();
} }
}); });
}); });
getPPlayer(playerUUID, (pplayer) -> { getPPlayer(playerUUID, (pplayer) -> {
pplayer.removeFixedEffect(id); pplayer.removeFixedEffect(id);
}); });
} }
/** /**
* Checks if the given player has reached the max number of fixed effects * Checks if the given player has reached the max number of fixed effects
* *
* @param pplayerUUID The player to check * @param pplayerUUID The player to check
* @return If the player has reached the max number of fixed effects * @return If the player has reached the max number of fixed effects
*/ */
public static boolean hasPlayerReachedMaxFixedEffects(PPlayer pplayer) { public static boolean hasPlayerReachedMaxFixedEffects(PPlayer pplayer) {
if (maxFixedEffects == -1) { // Initialize on the fly if (maxFixedEffects == -1) { // Initialize on the fly
maxFixedEffects = PlayerParticles.getPlugin().getConfig().getInt("max-fixed-effects"); maxFixedEffects = PlayerParticles.getPlugin().getConfig().getInt("max-fixed-effects");
} }
if (pplayer.getPlayer().hasPermission("playerparticles.fixed.unlimited")) if (pplayer.getPlayer().hasPermission("playerparticles.fixed.unlimited")) return false;
return false;
return pplayer.getFixedEffectIds().size() >= maxFixedEffects; return pplayer.getFixedEffectIds().size() >= maxFixedEffects;
} }
@ -471,4 +471,4 @@ public class DataManager { // @formatter:off
public void execute(T obj); public void execute(T obj);
} }
} // @formatter:on }

View file

@ -29,27 +29,27 @@ public class LangManager {
*/ */
public static enum Lang { public static enum Lang {
// Command Descriptions // Command Descriptions
ADD_COMMAND_DESCRIPTION("add-command-description"), ADD_COMMAND_DESCRIPTION("add-command-description"),
DATA_COMMAND_DESCRIPTION("data-command-description"), DATA_COMMAND_DESCRIPTION("data-command-description"),
DEFAULT_COMMAND_DESCRIPTION("default-command-description"), DEFAULT_COMMAND_DESCRIPTION("default-command-description"),
EDIT_COMMAND_DESCRIPTION("edit-command-description"), EDIT_COMMAND_DESCRIPTION("edit-command-description"),
EFFECT_COMMAND_DESCRIPTION("effect-command-description"), EFFECT_COMMAND_DESCRIPTION("effect-command-description"),
EFFECTS_COMMAND_DESCRIPTION("effects-command-description"), EFFECTS_COMMAND_DESCRIPTION("effects-command-description"),
FIXED_COMMAND_DESCRIPTION("fixed-command-description"), FIXED_COMMAND_DESCRIPTION("fixed-command-description"),
GROUP_COMMAND_DESCRIPTION("group-command-description"), GROUP_COMMAND_DESCRIPTION("group-command-description"),
GUI_COMMAND_DESCRIPTION("gui-command-description"), GUI_COMMAND_DESCRIPTION("gui-command-description"),
HELP_COMMAND_DESCRIPTION("help-command-description"), HELP_COMMAND_DESCRIPTION("help-command-description"),
INFO_COMMAND_DESCRIPTION("info-command-description"), INFO_COMMAND_DESCRIPTION("info-command-description"),
LIST_COMMAND_DESCRIPTION("list-command-description"), LIST_COMMAND_DESCRIPTION("list-command-description"),
REMOVE_COMMAND_DESCRIPTION("remove-command-description"), REMOVE_COMMAND_DESCRIPTION("remove-command-description"),
RESET_COMMAND_DESCRIPTION("reset-command-description"), RESET_COMMAND_DESCRIPTION("reset-command-description"),
STYLE_COMMAND_DESCRIPTION("style-command-description"), STYLE_COMMAND_DESCRIPTION("style-command-description"),
STYLES_COMMAND_DESCRIPTION("styles-command-description"), STYLES_COMMAND_DESCRIPTION("styles-command-description"),
VERSION_COMMAND_DESCRIPTION("version-command-description"), VERSION_COMMAND_DESCRIPTION("version-command-description"),
WORLDS_COMMAND_DESCRIPTION("worlds-command-description"), WORLDS_COMMAND_DESCRIPTION("worlds-command-description"),
COMMAND_REMOVED("command-removed"), COMMAND_REMOVED("command-removed"),
// Particles // Particles
NO_PERMISSION("message-no-permission"), NO_PERMISSION("message-no-permission"),
@ -166,7 +166,7 @@ public class LangManager {
* @return The message * @return The message
*/ */
public String get(String... replacements) { public String get(String... replacements) {
return String.format(this.message, (Object[])replacements); return String.format(this.message, (Object[]) replacements);
} }
/** /**
@ -199,18 +199,18 @@ public class LangManager {
* calling it multiple times wont affect anything negatively * calling it multiple times wont affect anything negatively
*/ */
public static void setup() { public static void setup() {
FileConfiguration config = PlayerParticles.getPlugin().getConfig(); FileConfiguration config = PlayerParticles.getPlugin().getConfig();
messagesEnabled = config.getBoolean("messages-enabled"); messagesEnabled = config.getBoolean("messages-enabled");
prefixEnabled = config.getBoolean("use-message-prefix"); prefixEnabled = config.getBoolean("use-message-prefix");
messagePrefix = parseColors(config.getString("message-prefix")); messagePrefix = parseColors(config.getString("message-prefix"));
YamlConfiguration lang = configureLangFile(config); YamlConfiguration lang = configureLangFile(config);
if (lang == null) { if (lang == null) {
messagesEnabled = false; messagesEnabled = false;
} else { } else {
for (Lang messageType : Lang.values()) for (Lang messageType : Lang.values())
messageType.setMessage(lang); messageType.setMessage(lang);
} }
} }
/** /**
@ -222,31 +222,31 @@ public class LangManager {
* @return The YamlConfiguration of the target .lang file * @return The YamlConfiguration of the target .lang file
*/ */
private static YamlConfiguration configureLangFile(FileConfiguration config) { private static YamlConfiguration configureLangFile(FileConfiguration config) {
File pluginDataFolder = PlayerParticles.getPlugin().getDataFolder(); File pluginDataFolder = PlayerParticles.getPlugin().getDataFolder();
langFileName = config.getString("lang-file"); langFileName = config.getString("lang-file");
File targetLangFile = new File(pluginDataFolder.getAbsolutePath() + "/lang/" + langFileName); File targetLangFile = new File(pluginDataFolder.getAbsolutePath() + "/lang/" + langFileName);
if (!targetLangFile.exists()) { // Target .lang file didn't exist, default to en_US.lang if (!targetLangFile.exists()) { // Target .lang file didn't exist, default to en_US.lang
if (!langFileName.equals("en_US.lang")) { if (!langFileName.equals("en_US.lang")) {
PlayerParticles.getPlugin().getLogger().warning("Couldn't find lang file '" + langFileName + "', defaulting to en_US.lang"); PlayerParticles.getPlugin().getLogger().warning("Couldn't find lang file '" + langFileName + "', defaulting to en_US.lang");
} }
langFileName = "en_US.lang"; langFileName = "en_US.lang";
targetLangFile = new File(pluginDataFolder.getAbsolutePath() + "/lang/" + langFileName); targetLangFile = new File(pluginDataFolder.getAbsolutePath() + "/lang/" + langFileName);
if (!targetLangFile.exists()) { // en_US.lang didn't exist, create it if (!targetLangFile.exists()) { // en_US.lang didn't exist, create it
try (InputStream stream = PlayerParticles.getPlugin().getResource("lang/en_US.lang")) { try (InputStream stream = PlayerParticles.getPlugin().getResource("lang/en_US.lang")) {
targetLangFile.getParentFile().mkdir(); // Make sure the directory always exists targetLangFile.getParentFile().mkdir(); // Make sure the directory always exists
Files.copy(stream, Paths.get(targetLangFile.getAbsolutePath())); Files.copy(stream, Paths.get(targetLangFile.getAbsolutePath()));
return YamlConfiguration.loadConfiguration(targetLangFile); return YamlConfiguration.loadConfiguration(targetLangFile);
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
PlayerParticles.getPlugin().getLogger().severe("Unable to write en_US.lang to disk! All messages for the plugin have been disabled until this is fixed!"); PlayerParticles.getPlugin().getLogger().severe("Unable to write en_US.lang to disk! All messages for the plugin have been disabled until this is fixed!");
return null; return null;
} }
} }
} }
return YamlConfiguration.loadConfiguration(targetLangFile); return YamlConfiguration.loadConfiguration(targetLangFile);
} }
/** /**
@ -277,7 +277,7 @@ public class LangManager {
* @param messageType The message to send to the player * @param messageType The message to send to the player
*/ */
public static void sendMessage(PPlayer pplayer, Lang messageType) { public static void sendMessage(PPlayer pplayer, Lang messageType) {
sendMessage(pplayer.getPlayer(), messageType); sendMessage(pplayer.getPlayer(), messageType);
} }
/** /**

View file

@ -54,7 +54,8 @@ public class ParticleManager extends BukkitRunnable implements Listener {
*/ */
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent e) { public void onPlayerJoin(PlayerJoinEvent e) {
DataManager.getPPlayer(e.getPlayer().getUniqueId(), (pplayer) -> {}); // Loads the PPlayer from the database DataManager.getPPlayer(e.getPlayer().getUniqueId(), (pplayer) -> {
}); // Loads the PPlayer from the database
} }
/** /**
@ -65,8 +66,7 @@ public class ParticleManager extends BukkitRunnable implements Listener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent e) { public void onPlayerQuit(PlayerQuitEvent e) {
PPlayer pplayer = DataManager.getPPlayer(e.getPlayer().getUniqueId()); PPlayer pplayer = DataManager.getPPlayer(e.getPlayer().getUniqueId());
if (pplayer != null) if (pplayer != null) particlePlayers.remove(pplayer);
particlePlayers.remove(pplayer);
} }
/** /**
@ -75,7 +75,7 @@ public class ParticleManager extends BukkitRunnable implements Listener {
* @return The loaded PPlayers * @return The loaded PPlayers
*/ */
public static List<PPlayer> getPPlayers() { public static List<PPlayer> getPPlayers() {
return particlePlayers; return particlePlayers;
} }
/** /**
@ -84,7 +84,8 @@ public class ParticleManager extends BukkitRunnable implements Listener {
public static void refreshPPlayers() { public static void refreshPPlayers() {
particlePlayers.clear(); particlePlayers.clear();
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
DataManager.getPPlayer(player.getUniqueId(), (pplayer) -> {}); // Loads the PPlayer from the database DataManager.getPPlayer(player.getUniqueId(), (pplayer) -> {
}); // Loads the PPlayer from the database
} }
/** /**
@ -138,18 +139,17 @@ 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 && !DataManager.isWorldDisabled(player.getWorld().getName())) { if (player != null && player.getGameMode() != GameMode.SPECTATOR && !DataManager.isWorldDisabled(player.getWorld().getName())) {
Location loc = player.getLocation(); Location loc = player.getLocation();
loc.setY(loc.getY() + 1); loc.setY(loc.getY() + 1);
for (ParticlePair particles : pplayer.getActiveParticles()) for (ParticlePair particles : pplayer.getActiveParticles())
displayParticles(particles, loc); displayParticles(particles, loc);
} }
// 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 (!DataManager.isWorldDisabled(effect.getLocation().getWorld().getName())) if (!DataManager.isWorldDisabled(effect.getLocation().getWorld().getName())) displayFixedParticleEffect(effect);
displayFixedParticleEffect(effect);
} }
} }
@ -201,7 +201,7 @@ public class ParticleManager extends BukkitRunnable implements Listener {
* @param fixedEffect The fixed effect to display * @param fixedEffect The fixed effect to display
*/ */
private void displayFixedParticleEffect(FixedParticleEffect fixedEffect) { private void displayFixedParticleEffect(FixedParticleEffect fixedEffect) {
ParticlePair particle = fixedEffect.getParticlePair(); ParticlePair particle = fixedEffect.getParticlePair();
ParticleEffect effect = particle.getEffect(); ParticleEffect effect = particle.getEffect();
for (PParticle pparticle : particle.getStyle().getParticles(particle, fixedEffect.getLocation())) { for (PParticle pparticle : particle.getStyle().getParticles(particle, fixedEffect.getLocation())) {
if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) { if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {

View file

@ -60,7 +60,7 @@ public class PermissionManager {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
for (ParticleEffect pe : ParticleEffect.getSupportedEffects()) for (ParticleEffect pe : ParticleEffect.getSupportedEffects())
if (hasEffectPermission(p, pe)) if (hasEffectPermission(p, pe))
list.add(pe.getName()); list.add(pe.getName());
return list; return list;
} }
@ -74,7 +74,7 @@ public class PermissionManager {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<String>();
for (ParticleStyle ps : ParticleStyleManager.getStyles()) for (ParticleStyle ps : ParticleStyleManager.getStyles())
if (hasStylePermission(p, ps)) if (hasStylePermission(p, ps))
list.add(ps.getName()); list.add(ps.getName());
return list; return list;
} }

View file

@ -85,7 +85,7 @@ public class FixedParticleEffect {
* @return The ParticlePair that represents this FixedParticleEffect's appearance * @return The ParticlePair that represents this FixedParticleEffect's appearance
*/ */
public ParticlePair getParticlePair() { public ParticlePair getParticlePair() {
return this.particlePair; return this.particlePair;
} }
/** /**

View file

@ -39,7 +39,7 @@ public class PPlayer {
* Constructs a new PPlayer * Constructs a new PPlayer
* *
* @param uuid The player UUID * @param uuid The player UUID
* @param particlePairs The ParticlePairs this PPlayer has * @param particlePairs The ParticlePairs this PPlayer has
* @param fixedParticles2 The fixed ParticlePairs this PPlayer has * @param fixedParticles2 The fixed ParticlePairs this PPlayer has
*/ */
public PPlayer(UUID uuid, List<ParticleGroup> particleGroups, List<FixedParticleEffect> fixedParticles) { public PPlayer(UUID uuid, List<ParticleGroup> particleGroups, List<FixedParticleEffect> fixedParticles) {
@ -72,7 +72,7 @@ public class PPlayer {
* @return A list of all particle groups this player has * @return A list of all particle groups this player has
*/ */
public List<ParticleGroup> getParticles() { public List<ParticleGroup> getParticles() {
return this.particleGroups; return this.particleGroups;
} }
/** /**
@ -82,10 +82,9 @@ public class PPlayer {
* @return The target named ParticleGroup * @return The target named ParticleGroup
*/ */
public ParticleGroup getParticlesByName(String name) { public ParticleGroup getParticlesByName(String name) {
for (ParticleGroup group : this.particleGroups) for (ParticleGroup group : this.particleGroups)
if (group.getName().equalsIgnoreCase(name)) if (group.getName().equalsIgnoreCase(name)) return group;
return group; return null;
return null;
} }
/** /**
@ -94,10 +93,9 @@ public class PPlayer {
* @return A List<ParticlePair> of all particles this player has set * @return A List<ParticlePair> of all particles this player has set
*/ */
public List<ParticlePair> getActiveParticles() { public List<ParticlePair> getActiveParticles() {
for (ParticleGroup group : this.particleGroups) for (ParticleGroup group : this.particleGroups)
if (group.getName() == null) if (group.getName() == null) return group.getParticles();
return group.getParticles(); return null; // This should never return null, there will always be at least one ParticleGroup
return null; // This should never return null, there will always be at least one ParticleGroup
} }
/** /**
@ -107,11 +105,10 @@ public class PPlayer {
* @return A List<ParticlePair> with a matching style * @return A List<ParticlePair> 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<ParticlePair>();
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); return matches;
return matches;
} }
/** /**
@ -121,10 +118,9 @@ public class PPlayer {
* @return A ParticlePair with the given id, otherwise null * @return A ParticlePair with the given id, otherwise null
*/ */
public ParticlePair getActiveParticle(int id) { public ParticlePair getActiveParticle(int id) {
for (ParticlePair particle : this.getActiveParticles()) for (ParticlePair particle : this.getActiveParticles())
if (particle.getId() == id) if (particle.getId() == id) return particle;
return particle; return null;
return null;
} }
/** /**
@ -133,7 +129,7 @@ public class PPlayer {
* @return A List<FixedParticleEffect> of all fixed particles this player has set * @return A List<FixedParticleEffect> of all fixed particles this player has set
*/ */
public List<FixedParticleEffect> getFixedParticles() { public List<FixedParticleEffect> getFixedParticles() {
return this.fixedParticles; return this.fixedParticles;
} }
/** /**
@ -143,10 +139,9 @@ public class PPlayer {
* @return The FixedParticleEffect the player owns * @return The FixedParticleEffect the player owns
*/ */
public FixedParticleEffect getFixedEffectById(int id) { public FixedParticleEffect getFixedEffectById(int id) {
for (FixedParticleEffect fixedEffect : this.fixedParticles) for (FixedParticleEffect fixedEffect : this.fixedParticles)
if (fixedEffect.getId() == id) if (fixedEffect.getId() == id) return fixedEffect;
return fixedEffect; return null;
return null;
} }
/** /**
@ -155,10 +150,10 @@ public class PPlayer {
* @return A List<Integer> of ids this player's fixed effects have * @return A List<Integer> of 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<Integer>();
for (FixedParticleEffect fixedEffect : this.fixedParticles) for (FixedParticleEffect fixedEffect : this.fixedParticles)
ids.add(fixedEffect.getId()); ids.add(fixedEffect.getId());
return ids; return ids;
} }
/** /**
@ -177,8 +172,7 @@ public class PPlayer {
*/ */
public void removeFixedEffect(int id) { public void removeFixedEffect(int id) {
for (int i = this.fixedParticles.size() - 1; i >= 0; i--) for (int i = this.fixedParticles.size() - 1; i >= 0; i--)
if (this.fixedParticles.get(i).getId() == id) if (this.fixedParticles.get(i).getId() == id) this.fixedParticles.remove(i);
this.fixedParticles.remove(i);
} }
/** /**
@ -188,11 +182,11 @@ public class PPlayer {
* @return The next available fixed effect id * @return The next available fixed effect id
*/ */
public int getNextFixedEffectId() { public int getNextFixedEffectId() {
List<Integer> fixedEffectIds = this.getFixedEffectIds(); List<Integer> fixedEffectIds = this.getFixedEffectIds();
int[] ids = new int[fixedEffectIds.size()]; int[] ids = new int[fixedEffectIds.size()];
for (int i = 0; i < fixedEffectIds.size(); i++) for (int i = 0; i < fixedEffectIds.size(); i++)
ids[i] = fixedEffectIds.get(i); ids[i] = fixedEffectIds.get(i);
return ParticleUtils.getSmallestPositiveInt(ids); return ParticleUtils.getSmallestPositiveInt(ids);
} }
} }

View file

@ -30,7 +30,7 @@ import org.bukkit.material.MaterialData;
public enum ParticleEffect { public enum ParticleEffect {
// Ordered and named by their Minecraft 1.13 internal names // Ordered and named by their Minecraft 1.13 internal names
NONE("", ""), // Custom effect to represent none selected, always display first NONE("", ""), // Custom effect to represent none selected, always display first
AMBIENT_ENTITY_EFFECT("SPELL_MOB_AMBIENT", "SPELL_MOB_AMBIENT", ParticleProperty.COLORABLE), AMBIENT_ENTITY_EFFECT("SPELL_MOB_AMBIENT", "SPELL_MOB_AMBIENT", ParticleProperty.COLORABLE),
ANGRY_VILLAGER("VILLAGER_ANGRY", "VILLAGER_ANGRY"), ANGRY_VILLAGER("VILLAGER_ANGRY", "VILLAGER_ANGRY"),
BARRIER("BARRIER", "BARRIER"), BARRIER("BARRIER", "BARRIER"),
@ -47,7 +47,7 @@ public enum ParticleEffect {
DRIPPING_LAVA("DRIP_LAVA", "DRIP_LAVA"), DRIPPING_LAVA("DRIP_LAVA", "DRIP_LAVA"),
DRIPPING_WATER("DRIP_WATER", "DRIP_WATER"), DRIPPING_WATER("DRIP_WATER", "DRIP_WATER"),
DUST("REDSTONE", "REDSTONE", ParticleProperty.COLORABLE), DUST("REDSTONE", "REDSTONE", ParticleProperty.COLORABLE),
//ELDER_GUARDIAN("MOB_APPEARANCE", "MOB_APPEARANCE"), // No thank you // ELDER_GUARDIAN("MOB_APPEARANCE", "MOB_APPEARANCE"), // No thank you
ENCHANT("ENCHANTMENT_TABLE", "ENCHANTMENT_TABLE"), ENCHANT("ENCHANTMENT_TABLE", "ENCHANTMENT_TABLE"),
ENCHANTED_HIT("CRIT_MAGIC", "CRIT_MAGIC"), ENCHANTED_HIT("CRIT_MAGIC", "CRIT_MAGIC"),
END_ROD("END_ROD", "END_ROD"), END_ROD("END_ROD", "END_ROD"),
@ -231,18 +231,20 @@ public enum ParticleEffect {
} }
if (this == DUST && VERSION_13) { // DUST uses a special data object for spawning in 1.13 if (this == DUST && VERSION_13) { // DUST uses a special data object for spawning in 1.13
OrdinaryColor dustColor = (OrdinaryColor)color; OrdinaryColor dustColor = (OrdinaryColor) color;
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 e) {
}
for (Player player : getPlayersInRange(center)) { for (Player player : getPlayersInRange(center)) {
player.spawnParticle(internalEnum, center.getX(), center.getY(), center.getZ(), 1, 0, 0, 0, 0, dustData); player.spawnParticle(internalEnum, center.getX(), center.getY(), center.getZ(), 1, 0, 0, 0, 0, dustData);
} }
} else { } else {
for (Player player : getPlayersInRange(center)) { for (Player player : getPlayersInRange(center)) {
// 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(internalEnum, center.getX(), center.getY(), center.getZ(), 0, this == ParticleEffect.DUST && color.getValueX() == 0 ? Float.MIN_VALUE : color.getValueX(), color.getValueY(), color.getValueZ(), 1);
} }
} }
@ -271,7 +273,9 @@ public enum ParticleEffect {
if (internalEnum.getDataType().getTypeName().equals("org.bukkit.block.data.BlockData")) { if (internalEnum.getDataType().getTypeName().equals("org.bukkit.block.data.BlockData")) {
try { // The Material.createBlockData() method doesn't exist in Minecraft versions less than 1.13... so this is disgusting... but it works great try { // The Material.createBlockData() method doesn't exist in Minecraft versions less than 1.13... so this is disgusting... but it works great
extraData = createBlockData_METHOD.invoke(spawnMaterial); extraData = createBlockData_METHOD.invoke(spawnMaterial);
} catch (Exception e) { } } catch (Exception e) {
}
} else if (internalEnum.getDataType() == ItemStack.class) { } else if (internalEnum.getDataType() == ItemStack.class) {
extraData = new ItemStack(spawnMaterial); extraData = new ItemStack(spawnMaterial);
} else if (internalEnum.getDataType() == MaterialData.class) { } else if (internalEnum.getDataType() == MaterialData.class) {
@ -509,7 +513,7 @@ public enum ParticleEffect {
* @return The note value * @return The note value
*/ */
public int getNote() { public int getNote() {
return this.note; return this.note;
} }
/** /**

View file

@ -5,40 +5,40 @@ import java.util.List;
public class ParticleGroup { public class ParticleGroup {
private String name; private String name;
private List<ParticlePair> particles; private List<ParticlePair> particles;
public ParticleGroup(String name, List<ParticlePair> particles) { public ParticleGroup(String name, List<ParticlePair> particles) {
this.name = name; this.name = name;
this.particles = particles; this.particles = particles;
} }
/** /**
* Get the player-given name of this ParticleGroup * Get the player-given name of this ParticleGroup
* This will be null if it's the player's active ParticleGroup * This will be null if it's the player's active ParticleGroup
* *
* @return The name of this group * @return The name of this group
*/ */
public String getName() { public String getName() {
return this.name; return this.name;
} }
/** /**
* Get the List<ParticlePair> of particles in this group * Get the List<ParticlePair> of particles in this group
* *
* @return The particles in this group * @return The particles in this group
*/ */
public List<ParticlePair> getParticles() { public List<ParticlePair> getParticles() {
return this.particles; return this.particles;
} }
/** /**
* Gets an empty ParticleGroup * Gets an empty ParticleGroup
* *
* @return The default empty active ParticleGroup * @return The default empty active ParticleGroup
*/ */
public static ParticleGroup getDefaultGroup() { public static ParticleGroup getDefaultGroup() {
return new ParticleGroup(null, new ArrayList<ParticlePair>()); return new ParticleGroup(null, new ArrayList<ParticlePair>());
} }
} }

View file

@ -17,33 +17,33 @@ import com.esophose.playerparticles.util.ParticleUtils;
public class ParticlePair { public class ParticlePair {
private UUID ownerUUID; private UUID ownerUUID;
private int id; private int id;
private ParticleEffect effect; private ParticleEffect effect;
private ParticleStyle style; private ParticleStyle style;
private Material itemMaterial; private Material itemMaterial;
private Material blockMaterial; private Material blockMaterial;
private OrdinaryColor color; private OrdinaryColor color;
private NoteColor noteColor; private NoteColor noteColor;
public ParticlePair(UUID ownerUUID, int id, ParticleEffect effect, ParticleStyle style, Material itemMaterial, Material blockMaterial, OrdinaryColor color, NoteColor noteColor) { public ParticlePair(UUID ownerUUID, int id, ParticleEffect effect, ParticleStyle style, Material itemMaterial, Material blockMaterial, OrdinaryColor color, NoteColor noteColor) {
this.ownerUUID = ownerUUID; this.ownerUUID = ownerUUID;
this.id = id; this.id = id;
this.effect = effect; this.effect = effect;
this.style = style; this.style = style;
this.setEffect(effect); this.setEffect(effect);
this.setStyle(style); this.setStyle(style);
this.setItemMaterial(itemMaterial); this.setItemMaterial(itemMaterial);
this.setBlockMaterial(blockMaterial); this.setBlockMaterial(blockMaterial);
this.setColor(color); this.setColor(color);
this.setNoteColor(noteColor); this.setNoteColor(noteColor);
} }
/** /**
* Sets the player's particle effect * Sets the player's particle effect
* *
* @param effect The player's new particle effect * @param effect The player's new particle effect
@ -104,76 +104,76 @@ public class ParticlePair {
} }
/** /**
* Get the UUID of the PPlayer that owns this ParticlePair * Get the UUID of the PPlayer that owns this ParticlePair
* *
* @return The owner's UUID * @return The owner's UUID
*/ */
public UUID getOwnerUniqueId() { public UUID getOwnerUniqueId() {
return this.ownerUUID; return this.ownerUUID;
} }
/** /**
* Get the id of this particle * Get the id of this particle
* *
* @return The id of this particle * @return The id of this particle
*/ */
public int getId() { public int getId() {
return this.id; return this.id;
} }
/** /**
* Get the ParticleEffect that this ParticlePair represents * Get the ParticleEffect that this ParticlePair represents
* *
* @return The effect * @return The effect
*/ */
public ParticleEffect getEffect() { public ParticleEffect getEffect() {
return this.effect; return this.effect;
} }
/** /**
* Get the ParticleStyle that this ParticlePair represents * Get the ParticleStyle that this ParticlePair represents
* *
* @return The style * @return The style
*/ */
public ParticleStyle getStyle() { public ParticleStyle getStyle() {
return this.style; return this.style;
} }
/** /**
* Get the item Material this particle uses * Get the item Material this particle uses
* *
* @return The item Material * @return The item Material
*/ */
public Material getItemMaterial() { public Material getItemMaterial() {
return this.itemMaterial; return this.itemMaterial;
} }
/** /**
* Get the block Material this particle uses * Get the block Material this particle uses
* *
* @return The block Material * @return The block Material
*/ */
public Material getBlockMaterial() { public Material getBlockMaterial() {
return this.blockMaterial; return this.blockMaterial;
} }
/** /**
* Get the color this particle uses * Get the color this particle uses
* *
* @return The color * @return The color
*/ */
public OrdinaryColor getColor() { public OrdinaryColor getColor() {
return this.color; return this.color;
} }
/** /**
* Get the note color this particle uses * Get the note color this particle uses
* *
* @return The note color * @return The note color
*/ */
public NoteColor getNoteColor() { public NoteColor getNoteColor() {
return this.noteColor; return this.noteColor;
} }
/** /**
* Gets the color the current particle effect will spawn with * Gets the color the current particle effect will spawn with
@ -247,7 +247,7 @@ public class ParticlePair {
* @return A ParticlePair with default values * @return A ParticlePair with default values
*/ */
public static ParticlePair getDefault() { public static ParticlePair getDefault() {
return new ParticlePair(null, // @formatter:off return new ParticlePair(null, // @formatter:off
-1, -1,
ParticleEffect.NONE, ParticleEffect.NONE,
DefaultStyles.NONE, DefaultStyles.NONE,
@ -263,7 +263,7 @@ public class ParticlePair {
* @return A ParticlePair with default values * @return A ParticlePair with default values
*/ */
public static ParticlePair getDefault(UUID ownerUUID) { public static ParticlePair getDefault(UUID ownerUUID) {
return new ParticlePair(ownerUUID, // @formatter:off return new ParticlePair(ownerUUID, // @formatter:off
1, 1,
ParticleEffect.NONE, ParticleEffect.NONE,
DefaultStyles.NONE, DefaultStyles.NONE,

View file

@ -40,7 +40,7 @@ public class DefaultStyles {
* Registered in alphabetical order * Registered in alphabetical order
*/ */
public static void registerStyles() { public static void registerStyles() {
ParticleStyleManager.registerStyle(NONE); // Always display none first ParticleStyleManager.registerStyle(NONE); // Always display none first
ParticleStyleManager.registerStyle(ARROWS); ParticleStyleManager.registerStyle(ARROWS);
ParticleStyleManager.registerStyle(BEAM); ParticleStyleManager.registerStyle(BEAM);
ParticleStyleManager.registerCustomHandledStyle(BLOCKBREAK); ParticleStyleManager.registerCustomHandledStyle(BLOCKBREAK);

View file

@ -45,10 +45,10 @@ public class ParticleStyleBlockBreak implements ParticleStyle, Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId()); PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
if (pplayer != null) { if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKBREAK)) { for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKBREAK)) {
Location loc = event.getBlock().getLocation(); Location loc = event.getBlock().getLocation();
ParticleManager.displayParticles(particle, DefaultStyles.BLOCKBREAK.getParticles(particle, loc)); ParticleManager.displayParticles(particle, DefaultStyles.BLOCKBREAK.getParticles(particle, loc));
} }
} }
} }

View file

@ -41,10 +41,10 @@ public class ParticleStyleBlockEdit implements ParticleStyle, Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId()); PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
if (pplayer != null) { if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKEDIT)) { for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKEDIT)) {
Location loc = event.getBlock().getLocation(); Location loc = event.getBlock().getLocation();
ParticleManager.displayParticles(particle, DefaultStyles.BLOCKBREAK.getParticles(particle, loc)); ParticleManager.displayParticles(particle, DefaultStyles.BLOCKBREAK.getParticles(particle, loc));
} }
} }
} }
@ -53,10 +53,10 @@ public class ParticleStyleBlockEdit implements ParticleStyle, Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId()); PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
if (pplayer != null) { if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKEDIT)) { for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKEDIT)) {
Location loc = event.getBlock().getLocation(); Location loc = event.getBlock().getLocation();
ParticleManager.displayParticles(particle, DefaultStyles.BLOCKPLACE.getParticles(particle, loc)); ParticleManager.displayParticles(particle, DefaultStyles.BLOCKPLACE.getParticles(particle, loc));
} }
} }
} }

View file

@ -45,10 +45,10 @@ public class ParticleStyleBlockPlace implements ParticleStyle, Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId()); PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
if (pplayer != null) { if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKPLACE)) { for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKPLACE)) {
Location loc = event.getBlock().getLocation(); Location loc = event.getBlock().getLocation();
ParticleManager.displayParticles(particle, DefaultStyles.BLOCKPLACE.getParticles(particle, loc)); ParticleManager.displayParticles(particle, DefaultStyles.BLOCKPLACE.getParticles(particle, loc));
} }
} }
} }

View file

@ -12,8 +12,8 @@ import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleFeet implements ParticleStyle { public class ParticleStyleFeet implements ParticleStyle {
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<PParticle>(); List<PParticle> particles = new ArrayList<PParticle>();
particles.add(new PParticle(location.subtract(0, 0.95, 0), 0.4F, 0.0F, 0.4F, 0.0F)); particles.add(new PParticle(location.subtract(0, 0.95, 0), 0.4F, 0.0F, 0.4F, 0.0F));
return particles; return particles;
} }

View file

@ -49,10 +49,10 @@ public class ParticleStyleHurt implements ParticleStyle, Listener {
Player player = (Player) event.getEntity(); Player player = (Player) event.getEntity();
PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId()); PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
if (pplayer != null) { if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.HURT)) { for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.HURT)) {
Location loc = player.getLocation().clone().add(0, 1, 0); Location loc = player.getLocation().clone().add(0, 1, 0);
ParticleManager.displayParticles(particle, DefaultStyles.HURT.getParticles(particle, loc)); ParticleManager.displayParticles(particle, DefaultStyles.HURT.getParticles(particle, loc));
} }
} }
} }
} }

View file

@ -37,11 +37,11 @@ public class ParticleStyleMove implements ParticleStyle, Listener {
public void onPlayerMove(PlayerMoveEvent e) { public void onPlayerMove(PlayerMoveEvent e) {
PPlayer pplayer = DataManager.getPPlayer(e.getPlayer().getUniqueId()); PPlayer pplayer = DataManager.getPPlayer(e.getPlayer().getUniqueId());
if (pplayer != null) { if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.MOVE)) { for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.MOVE)) {
Location loc = e.getPlayer().getLocation(); Location loc = e.getPlayer().getLocation();
loc.setY(loc.getY() + 0.05); loc.setY(loc.getY() + 0.05);
ParticleManager.displayParticles(particle, DefaultStyles.MOVE.getParticles(particle, loc)); ParticleManager.displayParticles(particle, DefaultStyles.MOVE.getParticles(particle, loc));
} }
} }
} }

View file

@ -13,132 +13,132 @@ import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleNone implements ParticleStyle { public class ParticleStyleNone implements ParticleStyle {
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
ParticleEffect particleEffect = particle.getEffect(); ParticleEffect particleEffect = particle.getEffect();
List<PParticle> particles = new ArrayList<PParticle>(); List<PParticle> particles = new ArrayList<PParticle>();
switch (particleEffect) { switch (particleEffect) {
case AMBIENT_ENTITY_EFFECT: case AMBIENT_ENTITY_EFFECT:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0)); return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case ANGRY_VILLAGER: case ANGRY_VILLAGER:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0)); return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case BARRIER: case BARRIER:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0)); return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case BLOCK: case BLOCK:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0)); return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case BUBBLE: case BUBBLE:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case BUBBLE_COLUMN_UP: case BUBBLE_COLUMN_UP:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case BUBBLE_POP: case BUBBLE_POP:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case CLOUD: case CLOUD:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case CRIT: case CRIT:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case CURRENT_DOWN: case CURRENT_DOWN:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case DAMAGE_INDICATOR: case DAMAGE_INDICATOR:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case DOLPHIN: case DOLPHIN:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case DRAGON_BREATH: case DRAGON_BREATH:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case DRIPPING_LAVA: case DRIPPING_LAVA:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0)); return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case DRIPPING_WATER: case DRIPPING_WATER:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0)); return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case DUST: case DUST:
return Collections.singletonList(new PParticle(location, 0.5, 0.5, 0.5, 0.0)); return Collections.singletonList(new PParticle(location, 0.5, 0.5, 0.5, 0.0));
case ENCHANT: case ENCHANT:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.05)); return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.05));
case ENCHANTED_HIT: case ENCHANTED_HIT:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case END_ROD: case END_ROD:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case ENTITY_EFFECT: case ENTITY_EFFECT:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case EXPLOSION: case EXPLOSION:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case EXPLOSION_EMITTER: case EXPLOSION_EMITTER:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case FALLING_DUST: case FALLING_DUST:
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
particles.add(new PParticle(location.add(0, 0.75, 0), 0.6, 0.4, 0.6, 0.0)); particles.add(new PParticle(location.add(0, 0.75, 0), 0.6, 0.4, 0.6, 0.0));
return particles; return particles;
case FIREWORK: case FIREWORK:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case FISHING: case FISHING:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case FLAME: case FLAME:
return Collections.singletonList(new PParticle(location, 0.1, 0.1, 0.1, 0.05)); return Collections.singletonList(new PParticle(location, 0.1, 0.1, 0.1, 0.05));
case FOOTSTEP: case FOOTSTEP:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case HAPPY_VILLAGER: case HAPPY_VILLAGER:
return Collections.singletonList(new PParticle(location, 0.5, 0.5, 0.5, 0.0)); return Collections.singletonList(new PParticle(location, 0.5, 0.5, 0.5, 0.0));
case HEART: case HEART:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0)); return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case INSTANT_EFFECT: case INSTANT_EFFECT:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case ITEM: case ITEM:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0)); return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case ITEM_SLIME: case ITEM_SLIME:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case ITEM_SNOWBALL: case ITEM_SNOWBALL:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case LARGE_SMOKE: case LARGE_SMOKE:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case LAVA: case LAVA:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case MYCELIUM: case MYCELIUM:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case NAUTILUS: case NAUTILUS:
return Collections.singletonList(new PParticle(location, 0.5, 0.5, 0.5, 0.05)); return Collections.singletonList(new PParticle(location, 0.5, 0.5, 0.5, 0.05));
case NONE: case NONE:
return particles; return particles;
case NOTE: case NOTE:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0)); return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case POOF: case POOF:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case PORTAL: case PORTAL:
return Collections.singletonList(new PParticle(location, 0.5, 0.5, 0.5, 0.05)); return Collections.singletonList(new PParticle(location, 0.5, 0.5, 0.5, 0.05));
case RAIN: case RAIN:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case SMOKE: case SMOKE:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case SPELL: case SPELL:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case SPIT: case SPIT:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0)); return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case SPLASH: case SPLASH:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case SQUID_INK: case SQUID_INK:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0)); return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case SWEEP_ATTACK: case SWEEP_ATTACK:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case TOTEM_OF_UNDYING: case TOTEM_OF_UNDYING:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0)); return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case UNDERWATER: case UNDERWATER:
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
particles.add(new PParticle(location, 0.5, 0.5, 0.5, 0.0)); particles.add(new PParticle(location, 0.5, 0.5, 0.5, 0.0));
return particles; return particles;
case WITCH: case WITCH:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
default: default:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0)); return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
} }
} }
public void updateTimers() { public void updateTimers() {
} }
public String getName() { public String getName() {
return "none"; return "none";
} }
public boolean canBeFixed() { public boolean canBeFixed() {
return true; return true;
} }
} }

View file

@ -11,32 +11,32 @@ import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleSpin implements ParticleStyle { public class ParticleStyleSpin implements ParticleStyle {
private int step = 0; private int step = 0;
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
int points = 15; int points = 15;
double radius = .5; double radius = .5;
double slice = 2 * Math.PI / points; double slice = 2 * Math.PI / points;
double angle = slice * (step % 15); double angle = slice * (step % 15);
double newX = location.getX() + radius * Math.cos(angle); double newX = location.getX() + radius * Math.cos(angle);
double newY = location.getY() + 1.5; double newY = location.getY() + 1.5;
double newZ = location.getZ() + radius * Math.sin(angle); double newZ = location.getZ() + radius * Math.sin(angle);
return Collections.singletonList(new PParticle(new Location(location.getWorld(), newX, newY, newZ))); return Collections.singletonList(new PParticle(new Location(location.getWorld(), newX, newY, newZ)));
} }
public void updateTimers() { public void updateTimers() {
step++; step++;
if (step > 30) { if (step > 30) {
step = 0; step = 0;
} }
} }
public String getName() { public String getName() {
return "spin"; return "spin";
} }
public boolean canBeFixed() { public boolean canBeFixed() {
return true; return true;
} }
} }

View file

@ -11,7 +11,7 @@ import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleSpiral implements ParticleStyle { public class ParticleStyleSpiral implements ParticleStyle {
private float stepX = 0; private int stepX = 0;
public List<PParticle> getParticles(ParticlePair particle, Location location) { public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<PParticle>(); List<PParticle> particles = new ArrayList<PParticle>();

View file

@ -59,10 +59,10 @@ public class ParticleStyleSwords implements ParticleStyle, Listener {
LivingEntity entity = (LivingEntity) event.getEntity(); LivingEntity entity = (LivingEntity) event.getEntity();
PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId()); PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
if (pplayer != null) { if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.SWORDS)) { for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.SWORDS)) {
Location loc = entity.getLocation().clone().add(0, 1, 0); Location loc = entity.getLocation().clone().add(0, 1, 0);
ParticleManager.displayParticles(particle, DefaultStyles.SWORDS.getParticles(particle, loc)); ParticleManager.displayParticles(particle, DefaultStyles.SWORDS.getParticles(particle, loc));
} }
} }
} }
} }

View file

@ -28,8 +28,8 @@ public class PluginUpdateListener implements Listener {
if (e.getPlayer().isOp()) { if (e.getPlayer().isOp()) {
if (PlayerParticles.updateVersion != null) { // @formatter:off if (PlayerParticles.updateVersion != null) { // @formatter:off
LangManager.sendCustomMessage(e.getPlayer(), ChatColor.YELLOW + "An update (" + ChatColor.AQUA + "v" + PlayerParticles.updateVersion + ChatColor.YELLOW + ") is available! " + LangManager.sendCustomMessage(e.getPlayer(), ChatColor.YELLOW + "An update (" + ChatColor.AQUA + "v" + PlayerParticles.updateVersion + ChatColor.YELLOW + ") is available! " +
"You are running " + ChatColor.AQUA + "v" + PlayerParticles.getPlugin().getDescription().getVersion() + ChatColor.YELLOW + "You are running " + ChatColor.AQUA + "v" + PlayerParticles.getPlugin().getDescription().getVersion() + ChatColor.YELLOW +
". https://dev.bukkit.org/projects/playerparticles"); ". https://dev.bukkit.org/projects/playerparticles");
} // @formatter:on } // @formatter:on
} }
} }

View file

@ -46,11 +46,9 @@ public class ParticleUtils {
Material mat = null; Material mat = null;
for (String name : input) { for (String name : input) {
mat = closestMatch(name); mat = closestMatch(name);
if (mat != null) if (mat != null) return mat;
return mat;
} }
if (mat == null) if (mat == null) mat = Material.BARRIER;
mat = Material.BARRIER;
return mat; return mat;
} }
@ -86,7 +84,8 @@ public class ParticleUtils {
} }
} }
for (int i = 0; i < n.length; ++i) for (int i = 0; i < n.length; ++i)
if (n[i] != i + 1) return i + 1; if (n[i] != i + 1)
return i + 1;
return n.length + 1; return n.length + 1;
} }