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

@ -39,8 +39,8 @@ import com.esophose.playerparticles.updater.PluginUpdateListener;
import com.esophose.playerparticles.updater.Updater;
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
@ -65,15 +65,15 @@ public class PlayerParticles extends JavaPlugin {
* Checks for any updates if checking is enabled in the config
*/
public void onEnable() {
pluginInstance = Bukkit.getServer().getPluginManager().getPlugin("PlayerParticles");
pluginInstance = Bukkit.getServer().getPluginManager().getPlugin("PlayerParticles");
getCommand("pp").setTabCompleter(new ParticleCommandHandler());
getCommand("pp").setExecutor(new ParticleCommandHandler());
Bukkit.getPluginManager().registerEvents(new ParticleManager(), this);
Bukkit.getPluginManager().registerEvents(new PluginUpdateListener(), this);
Bukkit.getPluginManager().registerEvents(new PlayerParticlesGui(), this);
saveDefaultConfig();
double configVersion = getConfig().getDouble("version");
if (configVersion < Double.parseDouble(getDescription().getVersion())) {
@ -85,10 +85,10 @@ public class PlayerParticles extends JavaPlugin {
reloadConfig();
getLogger().warning("The config.yml has been updated to v" + getDescription().getVersion() + "!");
}
DefaultStyles.registerStyles();
LangManager.setup();
configureDatabase(getConfig().getBoolean("database-enable"));
startParticleTask();
@ -143,21 +143,21 @@ public class PlayerParticles extends JavaPlugin {
* Creates new tables if they don't exist
*/
private void configureDatabase(boolean useMySql) {
if (useMySql) {
databaseConnector = new MySqlDatabaseConnector(this.getConfig());
} else {
databaseConnector = new SqliteDatabaseConnector(this.getDataFolder().getAbsolutePath());
}
if (!databaseConnector.isInitialized()) {
getLogger().severe("Unable to connect to the MySQL database! Is your login information correct? Falling back to SQLite database instead.");
configureDatabase(false);
return;
}
databaseConnector.connect((connection) -> {
// Check if pp_users exists, if it does, this is an old database schema that needs to be deleted
try { // @formatter:off
if (useMySql) {
databaseConnector = new MySqlDatabaseConnector(this.getConfig());
} else {
databaseConnector = new SqliteDatabaseConnector(this.getDataFolder().getAbsolutePath());
}
if (!databaseConnector.isInitialized()) {
getLogger().severe("Unable to connect to the MySQL database! Is your login information correct? Falling back to SQLite database instead.");
configureDatabase(false);
return;
}
databaseConnector.connect((connection) -> {
// Check if pp_users exists, if it does, this is an old database schema that needs to be deleted
try { // @formatter:off
try (Statement statement = connection.createStatement()) {
String pp_usersQuery;
if (useMySql) {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -12,14 +12,14 @@ import com.esophose.playerparticles.particles.ParticleEffect;
public class EffectsCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) {
Player p = pplayer.getPlayer();
if (PermissionManager.getEffectsUserHasPermissionFor(p).size() == 1) {
public void onCommandExecute(PPlayer pplayer, String[] args) {
Player p = pplayer.getPlayer();
if (PermissionManager.getEffectsUserHasPermissionFor(p).size() == 1) {
LangManager.sendMessage(p, Lang.NO_PARTICLES);
return;
}
String toSend = Lang.USE.get() + " ";
for (ParticleEffect effect : ParticleEffect.getSupportedEffects()) {
if (PermissionManager.hasEffectPermission(p, effect)) {
@ -30,29 +30,29 @@ public class EffectsCommandModule implements CommandModule {
if (toSend.endsWith(", ")) {
toSend = toSend.substring(0, toSend.length() - 2);
}
LangManager.sendCustomMessage(p, toSend);
LangManager.sendCustomMessage(p, Lang.USAGE.get() + " " + Lang.PARTICLE_USAGE.get());
}
}
public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null;
}
public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null;
}
public String getName() {
return "effects";
}
public String getName() {
return "effects";
}
public String getDescription() {
return Lang.EFFECTS_COMMAND_DESCRIPTION.get();
}
public String getDescription() {
return Lang.EFFECTS_COMMAND_DESCRIPTION.get();
}
public String getArguments() {
return "";
}
public boolean requiresEffects() {
return false;
}
public String getArguments() {
return "";
}
public boolean requiresEffects() {
return false;
}
}

View file

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

View file

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

View file

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

View file

@ -7,30 +7,30 @@ import com.esophose.playerparticles.manager.LangManager.Lang;
import com.esophose.playerparticles.particles.PPlayer;
public class HelpCommandModule implements CommandModule {
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
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.COMMAND_USAGE);
}
}
public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null;
}
public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null;
}
public String getName() {
return "help";
}
public String getName() {
return "help";
}
public String getDescription() {
return Lang.HELP_COMMAND_DESCRIPTION.get();
}
public String getDescription() {
return Lang.HELP_COMMAND_DESCRIPTION.get();
}
public String getArguments() {
return "";
}
public boolean requiresEffects() {
return false;
}
public String getArguments() {
return "";
}
public boolean requiresEffects() {
return false;
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -13,14 +13,14 @@ import com.esophose.playerparticles.styles.api.ParticleStyleManager;
public class StylesCommandModule implements CommandModule {
public void onCommandExecute(PPlayer pplayer, String[] args) {
Player p = pplayer.getPlayer();
if (PermissionManager.getStylesUserHasPermissionFor(p).size() == 1) {
public void onCommandExecute(PPlayer pplayer, String[] args) {
Player p = pplayer.getPlayer();
if (PermissionManager.getStylesUserHasPermissionFor(p).size() == 1) {
LangManager.sendMessage(pplayer, Lang.NO_STYLES);
return;
}
String toSend = Lang.USE.get() + " ";
for (ParticleStyle style : ParticleStyleManager.getStyles()) {
if (PermissionManager.hasStylePermission(p, style)) {
@ -31,29 +31,29 @@ public class StylesCommandModule implements CommandModule {
if (toSend.endsWith(", ")) {
toSend = toSend.substring(0, toSend.length() - 2);
}
LangManager.sendCustomMessage(p, toSend);
LangManager.sendCustomMessage(p, Lang.USAGE.get() + " " + Lang.STYLE_USAGE.get());
}
}
public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null;
}
public List<String> onTabComplete(PPlayer pplayer, String[] args) {
return null;
}
public String getName() {
return "styles";
}
public String getName() {
return "styles";
}
public String getDescription() {
return Lang.STYLES_COMMAND_DESCRIPTION.get();
}
public String getDescription() {
return Lang.STYLES_COMMAND_DESCRIPTION.get();
}
public String getArguments() {
return "";
}
public boolean requiresEffects() {
return false;
}
public String getArguments() {
return "";
}
public boolean requiresEffects() {
return false;
}
}

View file

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

View file

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

View file

@ -4,35 +4,35 @@ import java.sql.Connection;
import java.sql.SQLException;
public abstract class DatabaseConnector {
/**
/**
* Checks if the connection to the database has been created
*
* @return If the connection is created or not
*/
public abstract boolean isInitialized();
/**
public abstract boolean isInitialized();
/**
* 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
*
* @param callback The callback to execute once the connection is retrieved
*/
public abstract void connect(ConnectionCallback callback);
/**
* Gets a connection to the database
*
* @return A Connection to the database
* @throws SQLException If an SQL problem occurs getting the connection
*/
protected abstract Connection getConnection() throws SQLException;
/**
public abstract void connect(ConnectionCallback callback);
/**
* Gets a connection to the database
*
* @return A Connection to the database
* @throws SQLException If an SQL problem occurs getting the connection
*/
protected abstract Connection getConnection() throws SQLException;
/**
* Allows Lambda expressions to be used to reduce duplicated code for getting connections
*/
public static interface ConnectionCallback {

View file

@ -11,7 +11,7 @@ import com.zaxxer.hikari.HikariDataSource;
public class MySqlDatabaseConnector extends DatabaseConnector {
private HikariDataSource hikari;
private HikariDataSource hikari;
private boolean initializedSuccessfully = false;
public MySqlDatabaseConnector(FileConfiguration pluginConfig) {
@ -20,13 +20,13 @@ public class MySqlDatabaseConnector extends DatabaseConnector {
String database = pluginConfig.getString("database-name");
String user = pluginConfig.getString("database-user-name");
String pass = pluginConfig.getString("database-user-password");
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://" + hostname + ":" + port + "/" + database);
config.setUsername(user);
config.setPassword(pass);
config.setMaximumPoolSize(5);
try {
hikari = new HikariDataSource(config);
initializedSuccessfully = true;
@ -34,15 +34,15 @@ public class MySqlDatabaseConnector extends DatabaseConnector {
initializedSuccessfully = false;
}
}
public boolean isInitialized() {
return initializedSuccessfully;
}
public void closeConnection() {
hikari.close();
}
public void connect(ConnectionCallback callback) {
try (Connection connection = this.getConnection()) {
callback.execute(connection);
@ -50,9 +50,9 @@ public class MySqlDatabaseConnector extends DatabaseConnector {
PlayerParticles.getPlugin().getLogger().severe("An error occurred retrieving a mysql database connection: " + ex.getMessage());
}
}
protected Connection getConnection() throws SQLException {
return hikari.getConnection();
return hikari.getConnection();
}
}

View file

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

View file

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

View file

@ -97,7 +97,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
*/
private static DyeColor[] rainbowColors;
private static int rainbowColorsIndex = 0;
/**
* Cached material data
*/
@ -167,7 +167,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
defaultMenuIcons[0] = ParticleUtils.closestMatchWithFallback(config.getString("gui-icon.main-menu.EFFECT"));
defaultMenuIcons[1] = ParticleUtils.closestMatchWithFallback(config.getString("gui-icon.main-menu.STYLE"));
defaultMenuIcons[2] = ParticleUtils.closestMatchWithFallback(config.getString("gui-icon.main-menu.DATA"));
// Grab a different effect icon set based on if the Minecraft version is >= 1.13 or not
String legacy;
try {
@ -191,156 +191,144 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
new PlayerParticlesGui().runTaskTimer(PlayerParticles.getPlugin(), 0, 10);
}
// TODO: Delete these specialized getter methods once the new GUI is finished
private static ParticleEffect getPPlayerEffect(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticleEffect.NONE;
return particles.get(0).getEffect();
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticleEffect.NONE;
return particles.get(0).getEffect();
}
private static ParticleStyle getPPlayerStyle(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return DefaultStyles.NONE;
return particles.get(0).getStyle();
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return DefaultStyles.NONE;
return particles.get(0).getStyle();
}
private static Material getPPlayerItemMaterial(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getItemMaterial();
return particles.get(0).getItemMaterial();
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getItemMaterial();
return particles.get(0).getItemMaterial();
}
private static Material getPPlayerBlockMaterial(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getBlockMaterial();
return particles.get(0).getBlockMaterial();
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getBlockMaterial();
return particles.get(0).getBlockMaterial();
}
private static OrdinaryColor getPPlayerColor(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getColor();
return particles.get(0).getColor();
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getColor();
return particles.get(0).getColor();
}
private static NoteColor getPPlayerNoteColor(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getNoteColor();
return particles.get(0).getNoteColor();
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getNoteColor();
return particles.get(0).getNoteColor();
}
private static Material getPPlayerSpawnMaterial(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getSpawnMaterial();
return particles.get(0).getSpawnMaterial();
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getSpawnMaterial();
return particles.get(0).getSpawnMaterial();
}
private static ParticleColor getPPlayerSpawnColor(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getSpawnColor();
return particles.get(0).getSpawnColor();
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getSpawnColor();
return particles.get(0).getSpawnColor();
}
private static String getPPlayerDataString(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getDataString();
return particles.get(0).getDataString();
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return ParticlePair.getDefault().getDataString();
return particles.get(0).getDataString();
}
private static void setPPlayerEffect(PPlayer pplayer, ParticleEffect effect) {
List<ParticlePair> particles = pplayer.getActiveParticles();
ParticlePair particle;
if (particles.isEmpty())
particle = ParticlePair.getDefault(pplayer.getUniqueId());
else
particle = particles.get(0);
particle.setEffect(effect);
particles.clear();
particles.add(particle);
ParticleGroup group = new ParticleGroup(null, particles);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
List<ParticlePair> particles = pplayer.getActiveParticles();
ParticlePair particle;
if (particles.isEmpty()) particle = ParticlePair.getDefault(pplayer.getUniqueId());
else particle = particles.get(0);
particle.setEffect(effect);
particles.clear();
particles.add(particle);
ParticleGroup group = new ParticleGroup(null, particles);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
}
private static void setPPlayerStyle(PPlayer pplayer, ParticleStyle style) {
List<ParticlePair> particles = pplayer.getActiveParticles();
ParticlePair particle;
if (particles.isEmpty())
particle = ParticlePair.getDefault(pplayer.getUniqueId());
else
particle = particles.get(0);
particle.setStyle(style);
particles.clear();
particles.add(particle);
ParticleGroup group = new ParticleGroup(null, particles);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
List<ParticlePair> particles = pplayer.getActiveParticles();
ParticlePair particle;
if (particles.isEmpty()) particle = ParticlePair.getDefault(pplayer.getUniqueId());
else particle = particles.get(0);
particle.setStyle(style);
particles.clear();
particles.add(particle);
ParticleGroup group = new ParticleGroup(null, particles);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
}
private static void setPPlayerItemMaterial(PPlayer pplayer, Material material) {
List<ParticlePair> particles = pplayer.getActiveParticles();
ParticlePair particle;
if (particles.isEmpty())
particle = ParticlePair.getDefault(pplayer.getUniqueId());
else
particle = particles.get(0);
particle.setItemMaterial(material);
particles.clear();
particles.add(particle);
ParticleGroup group = new ParticleGroup(null, particles);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
List<ParticlePair> particles = pplayer.getActiveParticles();
ParticlePair particle;
if (particles.isEmpty()) particle = ParticlePair.getDefault(pplayer.getUniqueId());
else particle = particles.get(0);
particle.setItemMaterial(material);
particles.clear();
particles.add(particle);
ParticleGroup group = new ParticleGroup(null, particles);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
}
private static void setPPlayerBlockMaterial(PPlayer pplayer, Material material) {
List<ParticlePair> particles = pplayer.getActiveParticles();
ParticlePair particle;
if (particles.isEmpty())
particle = ParticlePair.getDefault(pplayer.getUniqueId());
else
particle = particles.get(0);
particle.setBlockMaterial(material);
particles.clear();
particles.add(particle);
ParticleGroup group = new ParticleGroup(null, particles);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
List<ParticlePair> particles = pplayer.getActiveParticles();
ParticlePair particle;
if (particles.isEmpty()) particle = ParticlePair.getDefault(pplayer.getUniqueId());
else particle = particles.get(0);
particle.setBlockMaterial(material);
particles.clear();
particles.add(particle);
ParticleGroup group = new ParticleGroup(null, particles);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
}
private static void setPPlayerColor(PPlayer pplayer, OrdinaryColor color) {
List<ParticlePair> particles = pplayer.getActiveParticles();
ParticlePair particle;
if (particles.isEmpty())
particle = ParticlePair.getDefault(pplayer.getUniqueId());
else
particle = particles.get(0);
particle.setColor(color);
particles.clear();
particles.add(particle);
ParticleGroup group = new ParticleGroup(null, particles);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
List<ParticlePair> particles = pplayer.getActiveParticles();
ParticlePair particle;
if (particles.isEmpty()) particle = ParticlePair.getDefault(pplayer.getUniqueId());
else particle = particles.get(0);
particle.setColor(color);
particles.clear();
particles.add(particle);
ParticleGroup group = new ParticleGroup(null, particles);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
}
private static void setPPlayerNoteColor(PPlayer pplayer, NoteColor noteColor) {
List<ParticlePair> particles = pplayer.getActiveParticles();
ParticlePair particle;
if (particles.isEmpty())
particle = ParticlePair.getDefault(pplayer.getUniqueId());
else
particle = particles.get(0);
particle.setNoteColor(noteColor);
particles.clear();
particles.add(particle);
ParticleGroup group = new ParticleGroup(null, particles);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
List<ParticlePair> particles = pplayer.getActiveParticles();
ParticlePair particle;
if (particles.isEmpty()) particle = ParticlePair.getDefault(pplayer.getUniqueId());
else particle = particles.get(0);
particle.setNoteColor(noteColor);
particles.clear();
particles.add(particle);
ParticleGroup group = new ParticleGroup(null, particles);
DataManager.saveParticleGroup(pplayer.getUniqueId(), group);
}
/**
@ -425,9 +413,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
public static void changeState(PPlayer pplayer, GuiState state) {
Player player = pplayer.getPlayer();
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;
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;
// 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
@ -473,11 +459,11 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
ItemStack currentIcon;
Material playerHead = ParticleUtils.closestMatch("PLAYER_HEAD");
if (playerHead != null) {
currentIcon = new ItemStack(playerHead, 1);
currentIcon = new ItemStack(playerHead, 1);
} 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();
currentIconMeta.setDisplayName(ChatColor.GREEN + player.getName());
String[] currentIconLore = new String[3];
@ -486,7 +472,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
currentIconLore[2] = ChatColor.YELLOW + "Active Data: " + ChatColor.AQUA + getPPlayerDataString(pplayer);
currentIconMeta.setLore(Arrays.asList(currentIconLore));
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);
ItemStack effectIcon = new ItemStack(defaultMenuIcons[0], 1);
@ -626,16 +612,15 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
} else if (pe.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
List<Material> materialBag = new ArrayList<Material>();
int materialIndex = 0;
if (pe == ParticleEffect.ITEM) { // Item data
Material currentItemMaterial = getPPlayerItemMaterial(pplayer);
while (materialBag.size() < 28) { // Grab 28 random materials that are an item
Material randomMaterial = ITEM_MATERIALS.get(RANDOM.nextInt(ITEM_MATERIALS.size()));
if (!materialBag.contains(randomMaterial))
materialBag.add(randomMaterial);
if (!materialBag.contains(randomMaterial)) materialBag.add(randomMaterial);
}
for (int i = 10; i <= 16; i++) { // Top row
inventory.setItem(i, getItemForMaterialData(currentItemMaterial, "item", materialBag.get(materialIndex)));
materialIndex++;
@ -654,13 +639,12 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
}
} else { // Block data
Material currentBlockMaterial = getPPlayerBlockMaterial(pplayer);
while (materialBag.size() < 28) { // Grab 28 random materials that are an item
Material randomMaterial = BLOCK_MATERIALS.get(RANDOM.nextInt(BLOCK_MATERIALS.size()));
if (!materialBag.contains(randomMaterial))
materialBag.add(randomMaterial);
if (!materialBag.contains(randomMaterial)) materialBag.add(randomMaterial);
}
for (int i = 10; i <= 16; i++) { // Top row
inventory.setItem(i, getItemForMaterialData(currentBlockMaterial, "block", materialBag.get(materialIndex)));
materialIndex++;
@ -692,7 +676,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
@EventHandler
public void onInventoryInteract(InventoryClickEvent e) {
if (isGuiDisabled()) return; // Don't worry about processing anything if the GUI is disabled
if (!(e.getWhoClicked() instanceof Player)) return; // Not sure if I actually have to check this
Player player = (Player) e.getWhoClicked();
@ -701,7 +685,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
if (guiInventory == null || !guiInventory.getInventory().equals(e.getView().getTopInventory())) return; // Make sure it is the right inventory
e.setCancelled(true); // In the PlayerParticles GUI, can't let them take anything out
if (!guiInventory.getInventory().equals(e.getClickedInventory())) return; // Clicked bottom inventory
PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
@ -731,11 +715,11 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
}
break;
case EFFECT:
setPPlayerEffect(pplayer, ParticleManager.effectFromString(name));
setPPlayerEffect(pplayer, ParticleManager.effectFromString(name));
changeState(pplayer, GuiState.DEFAULT);
break;
case STYLE:
setPPlayerStyle(pplayer, ParticleStyleManager.styleFromString(name));
setPPlayerStyle(pplayer, ParticleStyleManager.styleFromString(name));
changeState(pplayer, GuiState.DEFAULT);
break;
case DATA:
@ -743,14 +727,14 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
if (pe.hasProperty(ParticleProperty.COLORABLE)) {
if (pe == ParticleEffect.NOTE) {
if (clicked.getItemMeta().getDisplayName().equals(rainbowName)) {
setPPlayerNoteColor(pplayer, new NoteColor(99));
setPPlayerNoteColor(pplayer, new NoteColor(99));
} else {
int note = Integer.parseInt(ChatColor.stripColor(clicked.getItemMeta().getDisplayName()).substring(6));
setPPlayerNoteColor(pplayer, new NoteColor(note));
}
} else {
if (clicked.getItemMeta().getDisplayName().equals(rainbowName)) {
setPPlayerColor(pplayer, new OrdinaryColor(999, 999, 999));
setPPlayerColor(pplayer, new OrdinaryColor(999, 999, 999));
} else {
for (int i = 0; i < colorMapping.length; i++) {
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)) {
Material clickedMaterial = clicked.getType(); // All preset materials have a data value of 0
if (pe == ParticleEffect.ITEM) {
setPPlayerItemMaterial(pplayer, clickedMaterial);
setPPlayerItemMaterial(pplayer, clickedMaterial);
} else {
setPPlayerBlockMaterial(pplayer, clickedMaterial);
setPPlayerBlockMaterial(pplayer, clickedMaterial);
}
}
@ -851,15 +835,15 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
* @param colorIndex What color to use
* @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];
String formattedDisplayColor = ChatColor.RED.toString() + colorData.getOrdinaryColor().getRed() + " " + ChatColor.GREEN + colorData.getOrdinaryColor().getGreen() + " " + ChatColor.AQUA + colorData.getOrdinaryColor().getBlue();
ItemStack colorIcon;
if (colorData.getMaterial() != null) { // Use 1.13 materials
colorIcon = new ItemStack(colorData.getMaterial());
colorIcon = new ItemStack(colorData.getMaterial());
} else { // Use < 1.13 dye colors
colorIcon = new Dye(colorData.getDyeColor()).toItemStack(1);
colorIcon = new Dye(colorData.getDyeColor()).toItemStack(1);
}
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
*/
private static ItemStack getItemForRainbowColorData(OrdinaryColor currentColor, DyeColor dyeColor) {
ColorData colorData = getColorDataFromOrdinaryColor(dyeColor);
ItemStack rainbowIcon;
private static ItemStack getItemForRainbowColorData(OrdinaryColor currentColor, DyeColor dyeColor) {
ColorData colorData = getColorDataFromOrdinaryColor(dyeColor);
ItemStack rainbowIcon;
if (colorData.getMaterial() != null) { // Use 1.13 materials
rainbowIcon = new ItemStack(colorData.getMaterial());
rainbowIcon = new ItemStack(colorData.getMaterial());
} else { // Use < 1.13 dye colors
rainbowIcon = new Dye(colorData.getDyeColor()).toItemStack(1);
rainbowIcon = new Dye(colorData.getDyeColor()).toItemStack(1);
}
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
*/
private static ItemStack getItemForRainbowNoteData(NoteColor currentColor, DyeColor dyeColor) {
ColorData colorData = getColorDataFromOrdinaryColor(dyeColor);
ItemStack rainbowIcon;
private static ItemStack getItemForRainbowNoteData(NoteColor currentColor, DyeColor dyeColor) {
ColorData colorData = getColorDataFromOrdinaryColor(dyeColor);
ItemStack rainbowIcon;
if (colorData.getMaterial() != null) { // Use 1.13 materials
rainbowIcon = new ItemStack(colorData.getMaterial());
rainbowIcon = new ItemStack(colorData.getMaterial());
} else { // Use < 1.13 dye colors
rainbowIcon = new Dye(colorData.getDyeColor()).toItemStack(1);
rainbowIcon = new Dye(colorData.getDyeColor()).toItemStack(1);
}
ItemMeta rainbowIconMeta = rainbowIcon.getItemMeta();
@ -969,7 +953,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
return icon;
}
/**
* Gets a ColorData object from its DyeColor
*
@ -977,10 +961,9 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
* @return The found ColorData object, null if not found
*/
private static ColorData getColorDataFromOrdinaryColor(DyeColor color) {
for (ColorData colorData : colorMapping)
if (colorData.getDyeColor().equals(color))
return colorData;
return null;
for (ColorData colorData : colorMapping)
if (colorData.getDyeColor().equals(color)) return colorData;
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,
* rather than directly on the PPlayer object
*/
public class DataManager { // @formatter:off
public class DataManager {
/**
* The disabled worlds cached for quick access
@ -53,8 +53,10 @@ public class DataManager { // @formatter:off
/**
* This is not instantiable
*/
private DataManager() { }
private DataManager() {
}
/**
* Gets a PPlayer from cache
* This method should be used over the other one unless you absolutely need the PPlayer and you don't care about waiting
@ -64,9 +66,8 @@ public class DataManager { // @formatter:off
* @return The PPlayer from cache
*/
public static PPlayer getPPlayer(UUID playerUUID) {
for (PPlayer pp : ParticleManager.particlePlayers)
if (pp.getUniqueId() == playerUUID)
return pp;
for (PPlayer pp : ParticleManager.particlePlayers)
if (pp.getUniqueId() == playerUUID) return pp;
return null;
}
@ -74,7 +75,7 @@ public class DataManager { // @formatter:off
* Gets a player from the save data, creates one if it doesn't exist and caches it
*
* @param playerUUID The pplayer to get
* @param callback The callback to execute with the found pplayer, or a newly generated one
* @param callback The callback to execute with the found pplayer, or a newly generated one
*/
public static void getPPlayer(UUID playerUUID, ConfigurationCallback<PPlayer> callback) {
// Try to get them from cache first
@ -83,98 +84,98 @@ public class DataManager { // @formatter:off
callback.execute(fromCache);
return;
}
async(() -> {
List<ParticleGroup> groups = new ArrayList<ParticleGroup>();
List<FixedParticleEffect> fixedParticles = new ArrayList<FixedParticleEffect>();
PlayerParticles.databaseConnector.connect((connection) -> {
// Load particle groups
String groupQuery = "SELECT * FROM pp_group g " +
List<ParticleGroup> groups = new ArrayList<ParticleGroup>();
List<FixedParticleEffect> fixedParticles = new ArrayList<FixedParticleEffect>();
PlayerParticles.databaseConnector.connect((connection) -> {
// Load particle groups
String groupQuery = "SELECT * FROM pp_group g " + // @formatter:off
"JOIN pp_particle p ON g.uuid = p.group_uuid " +
"WHERE g.owner_uuid = ?";
try (PreparedStatement statement = connection.prepareStatement(groupQuery)) {
statement.setString(1, playerUUID.toString());
ResultSet result = statement.executeQuery();
while (result.next()) {
// Group properties
String groupName = result.getString("name");
// Particle properties
int id = result.getInt("id");
ParticleEffect effect = ParticleEffect.fromName(result.getString("effect"));
ParticleStyle style = ParticleStyleManager.styleFromString(result.getString("style"));
Material itemMaterial = ParticleUtils.closestMatchWithFallback(result.getString("item_material"));
Material blockMaterial = ParticleUtils.closestMatchWithFallback(result.getString("block_material"));
NoteColor noteColor = new NoteColor(result.getInt("note"));
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);
// Try to add particle to an existing group
boolean groupAlreadyExists = false;
for (ParticleGroup group : groups) {
if (group.getName().equalsIgnoreCase(groupName)) {
group.getParticles().add(particle);
groupAlreadyExists = true;
break;
}
}
// Add the particle to a new group if one didn't already exist
if (!groupAlreadyExists) {
List<ParticlePair> particles = new ArrayList<ParticlePair>();
particles.add(particle);
ParticleGroup newGroup = new ParticleGroup(groupName, particles);
groups.add(newGroup);
}
}
}
// 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 " +
"WHERE g.owner_uuid = ?"; // @formatter:on
try (PreparedStatement statement = connection.prepareStatement(groupQuery)) {
statement.setString(1, playerUUID.toString());
ResultSet result = statement.executeQuery();
while (result.next()) {
// Group properties
String groupName = result.getString("name");
// Particle properties
int id = result.getInt("id");
ParticleEffect effect = ParticleEffect.fromName(result.getString("effect"));
ParticleStyle style = ParticleStyleManager.styleFromString(result.getString("style"));
Material itemMaterial = ParticleUtils.closestMatchWithFallback(result.getString("item_material"));
Material blockMaterial = ParticleUtils.closestMatchWithFallback(result.getString("block_material"));
NoteColor noteColor = new NoteColor(result.getInt("note"));
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);
// Try to add particle to an existing group
boolean groupAlreadyExists = false;
for (ParticleGroup group : groups) {
if (group.getName().equalsIgnoreCase(groupName)) {
group.getParticles().add(particle);
groupAlreadyExists = true;
break;
}
}
// Add the particle to a new group if one didn't already exist
if (!groupAlreadyExists) {
List<ParticlePair> particles = new ArrayList<ParticlePair>();
particles.add(particle);
ParticleGroup newGroup = new ParticleGroup(groupName, particles);
groups.add(newGroup);
}
}
}
// 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 " + // @formatter:off
"JOIN pp_particle p ON f.particle_uuid = p.uuid " +
"WHERE f.owner_uuid = ?";
try (PreparedStatement statement = connection.prepareStatement(fixedQuery)) {
statement.setString(1, playerUUID.toString());
ResultSet result = statement.executeQuery();
while (result.next()) {
// Fixed effect properties
int fixedEffectId = result.getInt("f_id");
String worldName = result.getString("world");
double xPos = result.getDouble("xPos");
double yPos = result.getDouble("yPos");
double zPos = result.getDouble("zPos");
// Particle properties
int particleId = result.getInt("p_id");
ParticleEffect effect = ParticleEffect.fromName(result.getString("effect"));
ParticleStyle style = ParticleStyleManager.styleFromString(result.getString("style"));
Material itemMaterial = ParticleUtils.closestMatchWithFallback(result.getString("item_material"));
Material blockMaterial = ParticleUtils.closestMatchWithFallback(result.getString("block_material"));
NoteColor noteColor = new NoteColor(result.getInt("note"));
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);
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
ParticleGroup activeGroup = new ParticleGroup(null, new ArrayList<ParticlePair>());
saveParticleGroup(playerUUID, activeGroup);
groups.add(activeGroup);
}
PPlayer loadedPPlayer = new PPlayer(playerUUID, groups, fixedParticles);
ParticleManager.particlePlayers.add(loadedPPlayer);
sync(() -> callback.execute(loadedPPlayer));
});
"WHERE f.owner_uuid = ?"; // @formatter:on
try (PreparedStatement statement = connection.prepareStatement(fixedQuery)) {
statement.setString(1, playerUUID.toString());
ResultSet result = statement.executeQuery();
while (result.next()) {
// Fixed effect properties
int fixedEffectId = result.getInt("f_id");
String worldName = result.getString("world");
double xPos = result.getDouble("xPos");
double yPos = result.getDouble("yPos");
double zPos = result.getDouble("zPos");
// Particle properties
int particleId = result.getInt("p_id");
ParticleEffect effect = ParticleEffect.fromName(result.getString("effect"));
ParticleStyle style = ParticleStyleManager.styleFromString(result.getString("style"));
Material itemMaterial = ParticleUtils.closestMatchWithFallback(result.getString("item_material"));
Material blockMaterial = ParticleUtils.closestMatchWithFallback(result.getString("block_material"));
NoteColor noteColor = new NoteColor(result.getInt("note"));
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);
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
ParticleGroup activeGroup = new ParticleGroup(null, new ArrayList<ParticlePair>());
saveParticleGroup(playerUUID, activeGroup);
groups.add(activeGroup);
}
PPlayer loadedPPlayer = new PPlayer(playerUUID, groups, fixedParticles);
ParticleManager.particlePlayers.add(loadedPPlayer);
sync(() -> callback.execute(loadedPPlayer));
});
});
}
/**
* Saves a ParticleGroup. If it already exists, update it.
*
@ -182,70 +183,70 @@ public class DataManager { // @formatter:off
* @param group The group to create/update
*/
public static void saveParticleGroup(UUID playerUUID, ParticleGroup group) {
async(() -> {
PlayerParticles.databaseConnector.connect((connection) -> {
String groupUUIDQuery = "SELECT uuid FROM pp_group WHERE owner_uuid = ? AND name = ?";
try (PreparedStatement statement = connection.prepareStatement(groupUUIDQuery)) {
statement.setString(1, playerUUID.toString());
statement.setString(2, group.getName());
String groupUUID = null;
ResultSet result = statement.executeQuery();
if (result.next()) { // Clear out particles from existing group
groupUUID = result.getString("uuid");
String particlesDeleteQuery = "DELETE FROM pp_particle WHERE group_uuid = ?";
PreparedStatement particlesDeleteStatement = connection.prepareStatement(particlesDeleteQuery);
particlesDeleteStatement.setString(1, result.getString("uuid"));
particlesDeleteStatement.executeUpdate();
} else { // Create new group
groupUUID = UUID.randomUUID().toString();
String groupCreateQuery = "INSERT INTO pp_group (uuid, owner_uuid, name) VALUES (?, ?, ?)";
PreparedStatement groupCreateStatement = connection.prepareStatement(groupCreateQuery);
groupCreateStatement.setString(1, groupUUID);
groupCreateStatement.setString(2, playerUUID.toString());
groupCreateStatement.setString(3, group.getName());
groupCreateStatement.executeUpdate();
}
// 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement particlesStatement = connection.prepareStatement(createParticlesQuery);
for (ParticlePair particle : group.getParticles()) {
particlesStatement.setString(1, UUID.randomUUID().toString());
particlesStatement.setString(2, groupUUID);
particlesStatement.setInt(3, particle.getId());
particlesStatement.setString(4, particle.getEffect().getName());
particlesStatement.setString(5, particle.getStyle().getName());
particlesStatement.setString(6, particle.getItemMaterial().name());
particlesStatement.setString(7, particle.getBlockMaterial().name());
particlesStatement.setInt(8, particle.getNoteColor().getNote());
particlesStatement.setInt(9, particle.getColor().getRed());
particlesStatement.setInt(10, particle.getColor().getGreen());
particlesStatement.setInt(11, particle.getColor().getBlue());
particlesStatement.addBatch();
}
}
});
});
getPPlayer(playerUUID, (pplayer) -> {
String groupName = group.getName() == null ? "" : group.getName();
for (ParticleGroup existing : pplayer.getParticles()) {
String existingName = existing.getName() == null ? "" : existing.getName();
if (groupName.equalsIgnoreCase(existingName)) {
pplayer.getParticles().remove(existing);
break;
}
}
pplayer.getParticles().add(group);
});
async(() -> {
PlayerParticles.databaseConnector.connect((connection) -> {
String groupUUIDQuery = "SELECT uuid FROM pp_group WHERE owner_uuid = ? AND name = ?";
try (PreparedStatement statement = connection.prepareStatement(groupUUIDQuery)) {
statement.setString(1, playerUUID.toString());
statement.setString(2, group.getName());
String groupUUID = null;
ResultSet result = statement.executeQuery();
if (result.next()) { // Clear out particles from existing group
groupUUID = result.getString("uuid");
String particlesDeleteQuery = "DELETE FROM pp_particle WHERE group_uuid = ?";
PreparedStatement particlesDeleteStatement = connection.prepareStatement(particlesDeleteQuery);
particlesDeleteStatement.setString(1, result.getString("uuid"));
particlesDeleteStatement.executeUpdate();
} else { // Create new group
groupUUID = UUID.randomUUID().toString();
String groupCreateQuery = "INSERT INTO pp_group (uuid, owner_uuid, name) VALUES (?, ?, ?)";
PreparedStatement groupCreateStatement = connection.prepareStatement(groupCreateQuery);
groupCreateStatement.setString(1, groupUUID);
groupCreateStatement.setString(2, playerUUID.toString());
groupCreateStatement.setString(3, group.getName());
groupCreateStatement.executeUpdate();
}
// 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement particlesStatement = connection.prepareStatement(createParticlesQuery);
for (ParticlePair particle : group.getParticles()) {
particlesStatement.setString(1, UUID.randomUUID().toString());
particlesStatement.setString(2, groupUUID);
particlesStatement.setInt(3, particle.getId());
particlesStatement.setString(4, particle.getEffect().getName());
particlesStatement.setString(5, particle.getStyle().getName());
particlesStatement.setString(6, particle.getItemMaterial().name());
particlesStatement.setString(7, particle.getBlockMaterial().name());
particlesStatement.setInt(8, particle.getNoteColor().getNote());
particlesStatement.setInt(9, particle.getColor().getRed());
particlesStatement.setInt(10, particle.getColor().getGreen());
particlesStatement.setInt(11, particle.getColor().getBlue());
particlesStatement.addBatch();
}
}
});
});
getPPlayer(playerUUID, (pplayer) -> {
String groupName = group.getName() == null ? "" : group.getName();
for (ParticleGroup existing : pplayer.getParticles()) {
String existingName = existing.getName() == null ? "" : existing.getName();
if (groupName.equalsIgnoreCase(existingName)) {
pplayer.getParticles().remove(existing);
break;
}
}
pplayer.getParticles().add(group);
});
}
/**
* Removes a ParticleGroup
*
@ -253,41 +254,41 @@ public class DataManager { // @formatter:off
* @param group The group to remove
*/
public static void removeParticleGroup(UUID playerUUID, ParticleGroup group) {
async(() -> {
PlayerParticles.databaseConnector.connect((connection) -> {
String groupQuery = "SELECT * FROM pp_group WHERE owner_uuid = ? AND name = ?";
String particleDeleteQuery = "DELETE FROM pp_particle WHERE group_uuid = ?";
String groupDeleteQuery = "DELETE FROM pp_group WHERE uuid = ?";
// Execute group uuid query
String groupUUID = null;
try (PreparedStatement statement = connection.prepareStatement(groupQuery)) {
statement.setString(1, playerUUID.toString());
statement.setString(2, group.getName());
ResultSet result = statement.executeQuery();
groupUUID = result.getString("uuid");
}
// Execute particle delete update
try (PreparedStatement statement = connection.prepareStatement(particleDeleteQuery)) {
statement.setString(1, groupUUID);
statement.executeUpdate();
}
// Execute group delete update
try (PreparedStatement statement = connection.prepareStatement(groupDeleteQuery)) {
statement.setString(1, groupUUID);
statement.executeUpdate();
}
});
});
getPPlayer(playerUUID, (pplayer) -> {
pplayer.getParticles().remove(group);
});
async(() -> {
PlayerParticles.databaseConnector.connect((connection) -> {
String groupQuery = "SELECT * FROM pp_group WHERE owner_uuid = ? AND name = ?";
String particleDeleteQuery = "DELETE FROM pp_particle WHERE group_uuid = ?";
String groupDeleteQuery = "DELETE FROM pp_group WHERE uuid = ?";
// Execute group uuid query
String groupUUID = null;
try (PreparedStatement statement = connection.prepareStatement(groupQuery)) {
statement.setString(1, playerUUID.toString());
statement.setString(2, group.getName());
ResultSet result = statement.executeQuery();
groupUUID = result.getString("uuid");
}
// Execute particle delete update
try (PreparedStatement statement = connection.prepareStatement(particleDeleteQuery)) {
statement.setString(1, groupUUID);
statement.executeUpdate();
}
// Execute group delete update
try (PreparedStatement statement = connection.prepareStatement(groupDeleteQuery)) {
statement.setString(1, groupUUID);
statement.executeUpdate();
}
});
});
getPPlayer(playerUUID, (pplayer) -> {
pplayer.getParticles().remove(group);
});
}
/**
@ -297,44 +298,44 @@ public class DataManager { // @formatter:off
* @param fixedEffect The fixed effect to save
*/
public static void saveFixedEffect(FixedParticleEffect fixedEffect) {
async(() -> {
async(() -> {
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
try (PreparedStatement statement = connection.prepareStatement(particleQuery)) {
ParticlePair particle = fixedEffect.getParticlePair();
statement.setString(1, particleUUID);
statement.setString(2, null);
statement.setInt(3, fixedEffect.getId());
statement.setString(4, particle.getEffect().getName());
statement.setString(5, particle.getStyle().getName());
statement.setString(6, particle.getItemMaterial().name());
statement.setString(7, particle.getBlockMaterial().name());
statement.setInt(8, particle.getNoteColor().getNote());
statement.setInt(9, particle.getColor().getRed());
statement.setInt(10, particle.getColor().getGreen());
statement.setInt(11, particle.getColor().getBlue());
statement.executeUpdate();
ParticlePair particle = fixedEffect.getParticlePair();
statement.setString(1, particleUUID);
statement.setString(2, null);
statement.setInt(3, fixedEffect.getId());
statement.setString(4, particle.getEffect().getName());
statement.setString(5, particle.getStyle().getName());
statement.setString(6, particle.getItemMaterial().name());
statement.setString(7, particle.getBlockMaterial().name());
statement.setInt(8, particle.getNoteColor().getNote());
statement.setInt(9, particle.getColor().getRed());
statement.setInt(10, particle.getColor().getGreen());
statement.setInt(11, particle.getColor().getBlue());
statement.executeUpdate();
}
String fixedEffectQuery = "INSERT INTO pp_fixed (owner_uuid, id, particle_uuid, world, xPos, yPos, zPos) VALUES (?, ?, ?, ?, ?, ?, ?)";
try (PreparedStatement statement = connection.prepareStatement(fixedEffectQuery)) {
statement.setString(1, fixedEffect.getOwnerUniqueId().toString());
statement.setInt(2, fixedEffect.getId());
statement.setString(3, particleUUID);
statement.setString(4, fixedEffect.getLocation().getWorld().getName());
statement.setDouble(5, fixedEffect.getLocation().getX());
statement.setDouble(6, fixedEffect.getLocation().getY());
statement.setDouble(7, fixedEffect.getLocation().getZ());
statement.executeUpdate();
statement.setString(1, fixedEffect.getOwnerUniqueId().toString());
statement.setInt(2, fixedEffect.getId());
statement.setString(3, particleUUID);
statement.setString(4, fixedEffect.getLocation().getWorld().getName());
statement.setDouble(5, fixedEffect.getLocation().getX());
statement.setDouble(6, fixedEffect.getLocation().getY());
statement.setDouble(7, fixedEffect.getLocation().getZ());
statement.executeUpdate();
}
});
});
getPPlayer(fixedEffect.getOwnerUniqueId(), (pplayer) -> {
pplayer.addFixedEffect(fixedEffect);
});
getPPlayer(fixedEffect.getOwnerUniqueId(), (pplayer) -> {
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
*/
public static void removeFixedEffect(UUID playerUUID, int id) {
async(() -> {
async(() -> {
PlayerParticles.databaseConnector.connect((connection) -> {
String particleUUID = null;
String particleUUID = null;
String particleUUIDQuery = "SELECT particle_uuid FROM pp_fixed WHERE owner_uuid = ? AND id = ?";
try (PreparedStatement statement = connection.prepareStatement(particleUUIDQuery)) {
statement.setString(1, playerUUID.toString());
statement.setInt(2, id);
ResultSet result = statement.executeQuery();
particleUUID = result.getString("particle_uuid");
statement.setString(1, playerUUID.toString());
statement.setInt(2, id);
ResultSet result = statement.executeQuery();
particleUUID = result.getString("particle_uuid");
}
String particleDeleteQuery = "DELETE FROM pp_particle WHERE uuid = ?";
try (PreparedStatement statement = connection.prepareStatement(particleDeleteQuery)) {
statement.setString(1, particleUUID);
statement.executeUpdate();
statement.setString(1, particleUUID);
statement.executeUpdate();
}
String fixedEffectDeleteQuery = "DELETE FROM pp_fixed WHERE owner_uuid = ? AND id = ?";
try (PreparedStatement statement = connection.prepareStatement(fixedEffectDeleteQuery)) {
statement.setString(1, playerUUID.toString());
statement.setInt(2, id);
statement.executeUpdate();
statement.setString(1, playerUUID.toString());
statement.setInt(2, id);
statement.executeUpdate();
}
});
});
getPPlayer(playerUUID, (pplayer) -> {
pplayer.removeFixedEffect(id);
});
getPPlayer(playerUUID, (pplayer) -> {
pplayer.removeFixedEffect(id);
});
}
/**
* Checks if the given player has reached the max number of fixed effects
*
* @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) {
if (maxFixedEffects == -1) { // Initialize on the fly
maxFixedEffects = PlayerParticles.getPlugin().getConfig().getInt("max-fixed-effects");
}
if (pplayer.getPlayer().hasPermission("playerparticles.fixed.unlimited"))
return false;
if (pplayer.getPlayer().hasPermission("playerparticles.fixed.unlimited")) return false;
return pplayer.getFixedEffectIds().size() >= maxFixedEffects;
}
@ -430,7 +430,7 @@ public class DataManager { // @formatter:off
}
return disabledWorlds;
}
/**
* Asynchronizes the callback with it's own thread
*
@ -443,7 +443,7 @@ public class DataManager { // @formatter:off
}
}.runTaskAsynchronously(PlayerParticles.getPlugin());
}
/**
* Synchronizes the callback with the main thread
*
@ -456,14 +456,14 @@ public class DataManager { // @formatter:off
}
}.runTask(PlayerParticles.getPlugin());
}
/**
* Provides an easy way to run a section of code either synchronously or asynchronously using a callback
*/
private static interface SyncInterface {
public void execute();
}
/**
* Allows callbacks to be passed between configuration methods and executed for returning objects after database queries
*/
@ -471,4 +471,4 @@ public class DataManager { // @formatter:off
public void execute(T obj);
}
} // @formatter:on
}

View file

@ -28,28 +28,28 @@ public class LangManager {
* Contains the location in the .lang file of every chat message
*/
public static enum Lang {
// Command Descriptions
ADD_COMMAND_DESCRIPTION("add-command-description"),
DATA_COMMAND_DESCRIPTION("data-command-description"),
DEFAULT_COMMAND_DESCRIPTION("default-command-description"),
EDIT_COMMAND_DESCRIPTION("edit-command-description"),
EFFECT_COMMAND_DESCRIPTION("effect-command-description"),
EFFECTS_COMMAND_DESCRIPTION("effects-command-description"),
FIXED_COMMAND_DESCRIPTION("fixed-command-description"),
GROUP_COMMAND_DESCRIPTION("group-command-description"),
GUI_COMMAND_DESCRIPTION("gui-command-description"),
HELP_COMMAND_DESCRIPTION("help-command-description"),
INFO_COMMAND_DESCRIPTION("info-command-description"),
LIST_COMMAND_DESCRIPTION("list-command-description"),
REMOVE_COMMAND_DESCRIPTION("remove-command-description"),
RESET_COMMAND_DESCRIPTION("reset-command-description"),
STYLE_COMMAND_DESCRIPTION("style-command-description"),
STYLES_COMMAND_DESCRIPTION("styles-command-description"),
VERSION_COMMAND_DESCRIPTION("version-command-description"),
WORLDS_COMMAND_DESCRIPTION("worlds-command-description"),
COMMAND_REMOVED("command-removed"),
// Command Descriptions
ADD_COMMAND_DESCRIPTION("add-command-description"),
DATA_COMMAND_DESCRIPTION("data-command-description"),
DEFAULT_COMMAND_DESCRIPTION("default-command-description"),
EDIT_COMMAND_DESCRIPTION("edit-command-description"),
EFFECT_COMMAND_DESCRIPTION("effect-command-description"),
EFFECTS_COMMAND_DESCRIPTION("effects-command-description"),
FIXED_COMMAND_DESCRIPTION("fixed-command-description"),
GROUP_COMMAND_DESCRIPTION("group-command-description"),
GUI_COMMAND_DESCRIPTION("gui-command-description"),
HELP_COMMAND_DESCRIPTION("help-command-description"),
INFO_COMMAND_DESCRIPTION("info-command-description"),
LIST_COMMAND_DESCRIPTION("list-command-description"),
REMOVE_COMMAND_DESCRIPTION("remove-command-description"),
RESET_COMMAND_DESCRIPTION("reset-command-description"),
STYLE_COMMAND_DESCRIPTION("style-command-description"),
STYLES_COMMAND_DESCRIPTION("styles-command-description"),
VERSION_COMMAND_DESCRIPTION("version-command-description"),
WORLDS_COMMAND_DESCRIPTION("worlds-command-description"),
COMMAND_REMOVED("command-removed"),
// Particles
NO_PERMISSION("message-no-permission"),
@ -166,7 +166,7 @@ public class LangManager {
* @return The message
*/
public String get(String... replacements) {
return String.format(this.message, (Object[])replacements);
return String.format(this.message, (Object[]) replacements);
}
/**
@ -199,20 +199,20 @@ public class LangManager {
* calling it multiple times wont affect anything negatively
*/
public static void setup() {
FileConfiguration config = PlayerParticles.getPlugin().getConfig();
FileConfiguration config = PlayerParticles.getPlugin().getConfig();
messagesEnabled = config.getBoolean("messages-enabled");
prefixEnabled = config.getBoolean("use-message-prefix");
messagePrefix = parseColors(config.getString("message-prefix"));
YamlConfiguration lang = configureLangFile(config);
if (lang == null) {
messagesEnabled = false;
} else {
for (Lang messageType : Lang.values())
messageType.setMessage(lang);
}
if (lang == null) {
messagesEnabled = false;
} else {
for (Lang messageType : Lang.values())
messageType.setMessage(lang);
}
}
/**
* Loads the target .lang file as defined in the config and grabs its YamlConfiguration
* If it doesn't exist, default to en_US.lang
@ -222,31 +222,31 @@ public class LangManager {
* @return The YamlConfiguration of the target .lang file
*/
private static YamlConfiguration configureLangFile(FileConfiguration config) {
File pluginDataFolder = PlayerParticles.getPlugin().getDataFolder();
langFileName = config.getString("lang-file");
File targetLangFile = new File(pluginDataFolder.getAbsolutePath() + "/lang/" + langFileName);
if (!targetLangFile.exists()) { // Target .lang file didn't exist, default to en_US.lang
if (!langFileName.equals("en_US.lang")) {
PlayerParticles.getPlugin().getLogger().warning("Couldn't find lang file '" + langFileName + "', defaulting to en_US.lang");
}
langFileName = "en_US.lang";
targetLangFile = new File(pluginDataFolder.getAbsolutePath() + "/lang/" + langFileName);
if (!targetLangFile.exists()) { // en_US.lang didn't exist, create it
try (InputStream stream = PlayerParticles.getPlugin().getResource("lang/en_US.lang")) {
targetLangFile.getParentFile().mkdir(); // Make sure the directory always exists
Files.copy(stream, Paths.get(targetLangFile.getAbsolutePath()));
return YamlConfiguration.loadConfiguration(targetLangFile);
} catch (IOException ex) {
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!");
return null;
}
}
}
return YamlConfiguration.loadConfiguration(targetLangFile);
File pluginDataFolder = PlayerParticles.getPlugin().getDataFolder();
langFileName = config.getString("lang-file");
File targetLangFile = new File(pluginDataFolder.getAbsolutePath() + "/lang/" + langFileName);
if (!targetLangFile.exists()) { // Target .lang file didn't exist, default to en_US.lang
if (!langFileName.equals("en_US.lang")) {
PlayerParticles.getPlugin().getLogger().warning("Couldn't find lang file '" + langFileName + "', defaulting to en_US.lang");
}
langFileName = "en_US.lang";
targetLangFile = new File(pluginDataFolder.getAbsolutePath() + "/lang/" + langFileName);
if (!targetLangFile.exists()) { // en_US.lang didn't exist, create it
try (InputStream stream = PlayerParticles.getPlugin().getResource("lang/en_US.lang")) {
targetLangFile.getParentFile().mkdir(); // Make sure the directory always exists
Files.copy(stream, Paths.get(targetLangFile.getAbsolutePath()));
return YamlConfiguration.loadConfiguration(targetLangFile);
} catch (IOException ex) {
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!");
return null;
}
}
}
return YamlConfiguration.loadConfiguration(targetLangFile);
}
/**
@ -260,7 +260,7 @@ public class LangManager {
String message = messageType.get();
if (message.length() == 0) return;
if (prefixEnabled) {
message = messagePrefix + " " + message;
}
@ -269,7 +269,7 @@ public class LangManager {
player.sendMessage(message);
}
/**
* Sends a message to the given PPlayer
*
@ -277,7 +277,7 @@ public class LangManager {
* @param messageType The message to send to the player
*/
public static void sendMessage(PPlayer pplayer, Lang messageType) {
sendMessage(pplayer.getPlayer(), messageType);
sendMessage(pplayer.getPlayer(), messageType);
}
/**
@ -292,14 +292,14 @@ public class LangManager {
String message = messageType.getMessageReplaced(typeReplacement);
if (message.trim().length() == 0) return;
if (prefixEnabled) {
message = messagePrefix + " " + message;
}
player.sendMessage(message);
}
/**
* Sends a message to the given PPlayer and allows for replacing {TYPE}
*
@ -320,7 +320,7 @@ public class LangManager {
*/
public static void sendCustomMessage(Player player, String message) {
if (!messagesEnabled) return;
if (message.trim().length() == 0) return;
if (prefixEnabled) {
@ -329,7 +329,7 @@ public class LangManager {
player.sendMessage(message);
}
/**
* Sends a custom message to a PPlayer
* Used in cases of string building

View file

@ -54,7 +54,8 @@ public class ParticleManager extends BukkitRunnable implements Listener {
*/
@EventHandler(priority = EventPriority.MONITOR)
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,17 +66,16 @@ public class ParticleManager extends BukkitRunnable implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent e) {
PPlayer pplayer = DataManager.getPPlayer(e.getPlayer().getUniqueId());
if (pplayer != null)
particlePlayers.remove(pplayer);
if (pplayer != null) particlePlayers.remove(pplayer);
}
/**
* Gets the PPlayers that are loaded
*
* @return The loaded PPlayers
*/
public static List<PPlayer> getPPlayers() {
return particlePlayers;
return particlePlayers;
}
/**
@ -83,8 +83,9 @@ public class ParticleManager extends BukkitRunnable implements Listener {
*/
public static void refreshPPlayers() {
particlePlayers.clear();
for (Player player : Bukkit.getOnlinePlayers())
DataManager.getPPlayer(player.getUniqueId(), (pplayer) -> {}); // Loads the PPlayer from the database
for (Player player : Bukkit.getOnlinePlayers())
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 spawn particles if the world doesn't allow it
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);
for (ParticlePair particles : pplayer.getActiveParticles())
displayParticles(particles, loc);
for (ParticlePair particles : pplayer.getActiveParticles())
displayParticles(particles, loc);
}
// Loop for FixedParticleEffects
// Don't spawn particles if the world doesn't allow it
for (FixedParticleEffect effect : pplayer.getFixedParticles())
if (!DataManager.isWorldDisabled(effect.getLocation().getWorld().getName()))
displayFixedParticleEffect(effect);
if (!DataManager.isWorldDisabled(effect.getLocation().getWorld().getName())) displayFixedParticleEffect(effect);
}
}
@ -201,7 +201,7 @@ public class ParticleManager extends BukkitRunnable implements Listener {
* @param fixedEffect The fixed effect to display
*/
private void displayFixedParticleEffect(FixedParticleEffect fixedEffect) {
ParticlePair particle = fixedEffect.getParticlePair();
ParticlePair particle = fixedEffect.getParticlePair();
ParticleEffect effect = particle.getEffect();
for (PParticle pparticle : particle.getStyle().getParticles(particle, fixedEffect.getLocation())) {
if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {

View file

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

View file

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

View file

@ -29,7 +29,7 @@ public class PPlayer {
* A List<ParticleGroup> of all particle groups this player has, the active particle group has an id of null
*/
private List<ParticleGroup> particleGroups;
/**
* A List<FixedParticleEffect> of all fixed particles this user has applied
*/
@ -39,7 +39,7 @@ public class PPlayer {
* Constructs a new PPlayer
*
* @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
*/
public PPlayer(UUID uuid, List<ParticleGroup> particleGroups, List<FixedParticleEffect> fixedParticles) {
@ -65,16 +65,16 @@ public class PPlayer {
public Player getPlayer() {
return Bukkit.getPlayer(this.playerUUID);
}
/**
* Get a List<ParticleGroup> of all particles this user has saved
*
* @return A list of all particle groups this player has
*/
public List<ParticleGroup> getParticles() {
return this.particleGroups;
return this.particleGroups;
}
/**
* Gets a ParticleGroup this player has by its name
*
@ -82,24 +82,22 @@ public class PPlayer {
* @return The target named ParticleGroup
*/
public ParticleGroup getParticlesByName(String name) {
for (ParticleGroup group : this.particleGroups)
if (group.getName().equalsIgnoreCase(name))
return group;
return null;
for (ParticleGroup group : this.particleGroups)
if (group.getName().equalsIgnoreCase(name)) return group;
return null;
}
/**
* Get the effect/style/data for particles this player has set
*
* @return A List<ParticlePair> of all particles this player has set
*/
public List<ParticlePair> getActiveParticles() {
for (ParticleGroup group : this.particleGroups)
if (group.getName() == null)
return group.getParticles();
return null; // This should never return null, there will always be at least one ParticleGroup
for (ParticleGroup group : this.particleGroups)
if (group.getName() == null) return group.getParticles();
return null; // This should never return null, there will always be at least one ParticleGroup
}
/**
* Get all ParticlePairs with a style matching the input
*
@ -107,13 +105,12 @@ public class PPlayer {
* @return A List<ParticlePair> with a matching style
*/
public List<ParticlePair> getActiveParticlesForStyle(ParticleStyle style) {
List<ParticlePair> matches = new ArrayList<ParticlePair>();
for (ParticlePair pair : this.getActiveParticles())
if (pair.getStyle().equals(style))
matches.add(pair);
return matches;
List<ParticlePair> matches = new ArrayList<ParticlePair>();
for (ParticlePair pair : this.getActiveParticles())
if (pair.getStyle().equals(style)) matches.add(pair);
return matches;
}
/**
* Get a ParticlePair by its id
*
@ -121,21 +118,20 @@ public class PPlayer {
* @return A ParticlePair with the given id, otherwise null
*/
public ParticlePair getActiveParticle(int id) {
for (ParticlePair particle : this.getActiveParticles())
if (particle.getId() == id)
return particle;
return null;
for (ParticlePair particle : this.getActiveParticles())
if (particle.getId() == id) return particle;
return null;
}
/**
* Get the effect/style/data for all fixed particles this has has set
*
* @return A List<FixedParticleEffect> of all fixed particles this player has set
*/
public List<FixedParticleEffect> getFixedParticles() {
return this.fixedParticles;
return this.fixedParticles;
}
/**
* Get a FixedParticleEffect this player owns by id
*
@ -143,22 +139,21 @@ public class PPlayer {
* @return The FixedParticleEffect the player owns
*/
public FixedParticleEffect getFixedEffectById(int id) {
for (FixedParticleEffect fixedEffect : this.fixedParticles)
if (fixedEffect.getId() == id)
return fixedEffect;
return null;
for (FixedParticleEffect fixedEffect : this.fixedParticles)
if (fixedEffect.getId() == id) return fixedEffect;
return null;
}
/**
* Gets a list of ids of all fixed effect this player has
*
* @return A List<Integer> of ids this player's fixed effects have
*/
public List<Integer> getFixedEffectIds() {
List<Integer> ids = new ArrayList<Integer>();
for (FixedParticleEffect fixedEffect : this.fixedParticles)
ids.add(fixedEffect.getId());
return ids;
List<Integer> ids = new ArrayList<Integer>();
for (FixedParticleEffect fixedEffect : this.fixedParticles)
ids.add(fixedEffect.getId());
return ids;
}
/**
@ -176,11 +171,10 @@ public class PPlayer {
* @param id The id of the fixed effect to remove
*/
public void removeFixedEffect(int id) {
for (int i = this.fixedParticles.size() - 1; i >= 0; i--)
if (this.fixedParticles.get(i).getId() == id)
this.fixedParticles.remove(i);
for (int i = this.fixedParticles.size() - 1; i >= 0; i--)
if (this.fixedParticles.get(i).getId() == id) this.fixedParticles.remove(i);
}
/**
* Gets the next Id for a player's fixed effects
*
@ -188,11 +182,11 @@ public class PPlayer {
* @return The next available fixed effect id
*/
public int getNextFixedEffectId() {
List<Integer> fixedEffectIds = this.getFixedEffectIds();
int[] ids = new int[fixedEffectIds.size()];
for (int i = 0; i < fixedEffectIds.size(); i++)
ids[i] = fixedEffectIds.get(i);
return ParticleUtils.getSmallestPositiveInt(ids);
List<Integer> fixedEffectIds = this.getFixedEffectIds();
int[] ids = new int[fixedEffectIds.size()];
for (int i = 0; i < fixedEffectIds.size(); i++)
ids[i] = fixedEffectIds.get(i);
return ParticleUtils.getSmallestPositiveInt(ids);
}
}

View file

@ -28,9 +28,9 @@ import org.bukkit.material.MaterialData;
@SuppressWarnings("deprecation")
public enum ParticleEffect {
// 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),
ANGRY_VILLAGER("VILLAGER_ANGRY", "VILLAGER_ANGRY"),
BARRIER("BARRIER", "BARRIER"),
@ -47,7 +47,7 @@ public enum ParticleEffect {
DRIPPING_LAVA("DRIP_LAVA", "DRIP_LAVA"),
DRIPPING_WATER("DRIP_WATER", "DRIP_WATER"),
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"),
ENCHANTED_HIT("CRIT_MAGIC", "CRIT_MAGIC"),
END_ROD("END_ROD", "END_ROD"),
@ -62,7 +62,7 @@ public enum ParticleEffect {
HAPPY_VILLAGER("VILLAGER_HAPPY", "VILLAGER_HAPPY"),
HEART("HEART", "HEART"),
INSTANT_EFFECT("SPELL_INSTANT", "SPELL_INSTANT"),
ITEM("ITEM_CRACK", "ITEM_CRACK", ParticleProperty.REQUIRES_MATERIAL_DATA),
ITEM("ITEM_CRACK", "ITEM_CRACK", ParticleProperty.REQUIRES_MATERIAL_DATA),
ITEM_SLIME("SLIME", "SLIME"),
ITEM_SNOWBALL("SNOWBALL", "SNOWBALL"),
LARGE_SMOKE("SMOKE_LARGE", "SMOKE_LARGE"),
@ -82,7 +82,7 @@ public enum ParticleEffect {
TOTEM_OF_UNDYING("TOTEM", "TOTEM"),
UNDERWATER("SUSPENDED_DEPTH", "SUSPENDED_DEPTH"),
WITCH("SPELL_WITCH", "SPELL_WTICH");
private static final int PARTICLE_DISPLAY_RANGE_SQUARED = 36864; // (12 chunks * 16 blocks per chunk)^2
private static final Map<String, ParticleEffect> NAME_MAP = new HashMap<String, ParticleEffect>();
private static boolean VERSION_13; // This is a particle unique to Minecraft 1.13, this is a reliable way of telling what server version is running
@ -97,12 +97,12 @@ public enum ParticleEffect {
for (ParticleEffect effect : values()) {
NAME_MAP.put(effect.getName(), effect);
}
try {
VERSION_13 = Particle.valueOf("NAUTILUS") != null;
DustOptions_CONSTRUCTOR = Particle.REDSTONE.getDataType().getConstructor(Color.class, float.class);
createBlockData_METHOD = Material.class.getMethod("createBlockData");
} catch (Exception e) {
} catch (Exception e) {
DustOptions_CONSTRUCTOR = null;
createBlockData_METHOD = null;
VERSION_13 = false;
@ -126,7 +126,7 @@ public enum ParticleEffect {
break;
}
}
this.internalEnum = matchingEnum; // Will be null if this server's version doesn't support this particle type
}
@ -211,11 +211,11 @@ public enum ParticleEffect {
if (hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
throw new ParticleDataException("This particle effect requires additional data");
}
for (Player player : getPlayersInRange(center)) {
player.spawnParticle(internalEnum, center.getX(), center.getY(), center.getZ(), amount, offsetX, offsetY, offsetZ, speed);
}
}
/**
@ -231,18 +231,20 @@ public enum ParticleEffect {
}
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;
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!
} catch (Exception e) { }
} catch (Exception e) {
}
for (Player player : getPlayersInRange(center)) {
player.spawnParticle(internalEnum, center.getX(), center.getY(), center.getZ(), 1, 0, 0, 0, 0, dustData);
}
} else {
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);
}
}
@ -266,12 +268,14 @@ public enum ParticleEffect {
if (!hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
throw new ParticleDataException("This particle effect does not require additional data");
}
Object extraData = null;
if (internalEnum.getDataType().getTypeName().equals("org.bukkit.block.data.BlockData")) {
if (internalEnum.getDataType().getTypeName().equals("org.bukkit.block.data.BlockData")) {
try { // The Material.createBlockData() method doesn't exist in Minecraft versions less than 1.13... so this is disgusting... but it works great
extraData = createBlockData_METHOD.invoke(spawnMaterial);
} catch (Exception e) { }
} catch (Exception e) {
}
} else if (internalEnum.getDataType() == ItemStack.class) {
extraData = new ItemStack(spawnMaterial);
} else if (internalEnum.getDataType() == MaterialData.class) {
@ -280,11 +284,11 @@ public enum ParticleEffect {
System.out.println(internalEnum.getDataType());
extraData = null;
}
for (Player player : getPlayersInRange(center))
player.spawnParticle(internalEnum, center.getX(), center.getY(), center.getZ(), amount, offsetX, offsetY, offsetZ, speed, extraData);
}
/**
* Gets a List<Player> of players within the particle display range
*
@ -293,11 +297,11 @@ public enum ParticleEffect {
*/
private List<Player> getPlayersInRange(Location center) {
List<Player> players = new ArrayList<Player>();
for (Player p : Bukkit.getOnlinePlayers())
for (Player p : Bukkit.getOnlinePlayers())
if (p.getWorld().equals(center.getWorld()) && center.distanceSquared(p.getLocation()) <= PARTICLE_DISPLAY_RANGE_SQUARED)
players.add(p);
return players;
}
@ -502,14 +506,14 @@ public enum ParticleEffect {
this.note = note;
}
}
/**
* Returns the note value
*
* @return The note value
*/
public int getNote() {
return this.note;
return this.note;
}
/**

View file

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

View file

@ -16,34 +16,34 @@ import com.esophose.playerparticles.styles.api.ParticleStyle;
import com.esophose.playerparticles.util.ParticleUtils;
public class ParticlePair {
private UUID ownerUUID;
private int id;
private ParticleEffect effect;
private ParticleStyle style;
private Material itemMaterial;
private UUID ownerUUID;
private int id;
private ParticleEffect effect;
private ParticleStyle style;
private Material itemMaterial;
private Material blockMaterial;
private OrdinaryColor color;
private NoteColor noteColor;
public ParticlePair(UUID ownerUUID, int id, ParticleEffect effect, ParticleStyle style, Material itemMaterial, Material blockMaterial, OrdinaryColor color, NoteColor noteColor) {
this.ownerUUID = ownerUUID;
this.id = id;
this.effect = effect;
this.style = style;
this.setEffect(effect);
public ParticlePair(UUID ownerUUID, int id, ParticleEffect effect, ParticleStyle style, Material itemMaterial, Material blockMaterial, OrdinaryColor color, NoteColor noteColor) {
this.ownerUUID = ownerUUID;
this.id = id;
this.effect = effect;
this.style = style;
this.setEffect(effect);
this.setStyle(style);
this.setItemMaterial(itemMaterial);
this.setBlockMaterial(blockMaterial);
this.setColor(color);
this.setNoteColor(noteColor);
}
/**
}
/**
* Sets the player's particle effect
*
* @param effect The player's new particle effect
@ -102,79 +102,79 @@ public class ParticlePair {
if (noteColorData == null) noteColorData = new NoteColor(0);
this.noteColor = noteColorData;
}
/**
* Get the UUID of the PPlayer that owns this ParticlePair
*
* @return The owner's UUID
*/
public UUID getOwnerUniqueId() {
return this.ownerUUID;
}
/**
* Get the id of this particle
*
* @return The id of this particle
*/
public int getId() {
return this.id;
}
/**
* Get the ParticleEffect that this ParticlePair represents
*
* @return The effect
*/
public ParticleEffect getEffect() {
return this.effect;
}
/**
* Get the ParticleStyle that this ParticlePair represents
*
* @return The style
*/
public ParticleStyle getStyle() {
return this.style;
}
/**
* Get the item Material this particle uses
*
* @return The item Material
*/
public Material getItemMaterial() {
return this.itemMaterial;
}
/**
* Get the block Material this particle uses
*
* @return The block Material
*/
public Material getBlockMaterial() {
return this.blockMaterial;
}
/**
* Get the color this particle uses
*
* @return The color
*/
public OrdinaryColor getColor() {
return this.color;
}
/**
* Get the note color this particle uses
*
* @return The note color
*/
public NoteColor getNoteColor() {
return this.noteColor;
}
* Get the UUID of the PPlayer that owns this ParticlePair
*
* @return The owner's UUID
*/
public UUID getOwnerUniqueId() {
return this.ownerUUID;
}
/**
* Get the id of this particle
*
* @return The id of this particle
*/
public int getId() {
return this.id;
}
/**
* Get the ParticleEffect that this ParticlePair represents
*
* @return The effect
*/
public ParticleEffect getEffect() {
return this.effect;
}
/**
* Get the ParticleStyle that this ParticlePair represents
*
* @return The style
*/
public ParticleStyle getStyle() {
return this.style;
}
/**
* Get the item Material this particle uses
*
* @return The item Material
*/
public Material getItemMaterial() {
return this.itemMaterial;
}
/**
* Get the block Material this particle uses
*
* @return The block Material
*/
public Material getBlockMaterial() {
return this.blockMaterial;
}
/**
* Get the color this particle uses
*
* @return The color
*/
public OrdinaryColor getColor() {
return this.color;
}
/**
* Get the note color this particle uses
*
* @return The note color
*/
public NoteColor getNoteColor() {
return this.noteColor;
}
/**
* Gets the color the current particle effect will spawn with
*
@ -197,7 +197,7 @@ public class ParticlePair {
}
return null;
}
/**
* Gets the material the current particle effect will spawn with
*
@ -240,14 +240,14 @@ public class ParticlePair {
}
return "none";
}
/**
* Gets a ParticlePair with the default values applied
*
* @return A ParticlePair with default values
*/
public static ParticlePair getDefault() {
return new ParticlePair(null, // @formatter:off
return new ParticlePair(null, // @formatter:off
-1,
ParticleEffect.NONE,
DefaultStyles.NONE,
@ -256,14 +256,14 @@ public class ParticlePair {
new OrdinaryColor(0, 0, 0),
new NoteColor(0)); // @formatter:on
}
/**
* Gets a ParticlePair with the default values applied
*
* @return A ParticlePair with default values
*/
public static ParticlePair getDefault(UUID ownerUUID) {
return new ParticlePair(ownerUUID, // @formatter:off
return new ParticlePair(ownerUUID, // @formatter:off
1,
ParticleEffect.NONE,
DefaultStyles.NONE,
@ -272,5 +272,5 @@ public class ParticlePair {
new OrdinaryColor(0, 0, 0),
new NoteColor(0)); // @formatter:on
}
}

View file

@ -40,7 +40,7 @@ public class DefaultStyles {
* Registered in alphabetical order
*/
public static void registerStyles() {
ParticleStyleManager.registerStyle(NONE); // Always display none first
ParticleStyleManager.registerStyle(NONE); // Always display none first
ParticleStyleManager.registerStyle(ARROWS);
ParticleStyleManager.registerStyle(BEAM);
ParticleStyleManager.registerCustomHandledStyle(BLOCKBREAK);
@ -60,7 +60,7 @@ public class DefaultStyles {
ParticleStyleManager.registerCustomHandledStyle(SWORDS);
ParticleStyleManager.registerStyle(THICK);
ParticleStyleManager.registerStyle(WINGS);
PluginManager manager = Bukkit.getPluginManager();
Plugin playerParticles = PlayerParticles.getPlugin();
manager.registerEvents((Listener) ARROWS, playerParticles);

View file

@ -22,14 +22,14 @@ public class ParticleStyleBlockBreak implements ParticleStyle, Listener {
public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<PParticle>();
for (int i = 0; i < 15; i++)
for (int i = 0; i < 15; i++)
particles.add(new PParticle(location.clone().add(0.5, 0.5, 0.5), 0.5F, 0.5F, 0.5F, 0.05F));
return particles;
}
public void updateTimers() {
}
public String getName() {
@ -39,16 +39,16 @@ public class ParticleStyleBlockBreak implements ParticleStyle, Listener {
public boolean canBeFixed() {
return false;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKBREAK)) {
Location loc = event.getBlock().getLocation();
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKBREAK)) {
Location loc = event.getBlock().getLocation();
ParticleManager.displayParticles(particle, DefaultStyles.BLOCKBREAK.getParticles(particle, loc));
}
}
}
}

View file

@ -25,7 +25,7 @@ public class ParticleStyleBlockEdit implements ParticleStyle, Listener {
}
public void updateTimers() {
}
public String getName() {
@ -35,28 +35,28 @@ public class ParticleStyleBlockEdit implements ParticleStyle, Listener {
public boolean canBeFixed() {
return false;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKEDIT)) {
Location loc = event.getBlock().getLocation();
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKEDIT)) {
Location loc = event.getBlock().getLocation();
ParticleManager.displayParticles(particle, DefaultStyles.BLOCKBREAK.getParticles(particle, loc));
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKEDIT)) {
Location loc = event.getBlock().getLocation();
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKEDIT)) {
Location loc = event.getBlock().getLocation();
ParticleManager.displayParticles(particle, DefaultStyles.BLOCKPLACE.getParticles(particle, loc));
}
}
}
}

View file

@ -22,7 +22,7 @@ public class ParticleStyleBlockPlace implements ParticleStyle, Listener {
public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<PParticle>();
for (int i = 0; i < 15; i++)
for (int i = 0; i < 15; i++)
particles.add(new PParticle(location.clone().add(0.5, 0.5, 0.5), 0.75F, 0.75F, 0.75F, 0.05F));
return particles;
@ -45,10 +45,10 @@ public class ParticleStyleBlockPlace implements ParticleStyle, Listener {
Player player = event.getPlayer();
PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKPLACE)) {
Location loc = event.getBlock().getLocation();
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.BLOCKPLACE)) {
Location loc = event.getBlock().getLocation();
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 List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<PParticle>();
particles.add(new PParticle(location.subtract(0, 0.95, 0), 0.4F, 0.0F, 0.4F, 0.0F));
List<PParticle> particles = new ArrayList<PParticle>();
particles.add(new PParticle(location.subtract(0, 0.95, 0), 0.4F, 0.0F, 0.4F, 0.0F));
return particles;
}

View file

@ -15,7 +15,7 @@ public class ParticleStyleHalo implements ParticleStyle {
public List<PParticle> getParticles(ParticlePair particle, Location location) {
if (step % 2 == 0) return new ArrayList<PParticle>();
int points = 16;
double radius = .65;
double slice = 2 * Math.PI / points;

View file

@ -32,7 +32,7 @@ public class ParticleStyleHurt implements ParticleStyle, Listener {
}
public void updateTimers() {
}
public String getName() {
@ -42,19 +42,19 @@ public class ParticleStyleHurt implements ParticleStyle, Listener {
public boolean canBeFixed() {
return false;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityDamage(EntityDamageEvent event) {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.HURT)) {
Location loc = player.getLocation().clone().add(0, 1, 0);
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.HURT)) {
Location loc = player.getLocation().clone().add(0, 1, 0);
ParticleManager.displayParticles(particle, DefaultStyles.HURT.getParticles(particle, loc));
}
}
}
}
}
}
}

View file

@ -16,13 +16,13 @@ import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleMove implements ParticleStyle, Listener {
public List<PParticle> getParticles(ParticlePair particle, Location location) {
return DefaultStyles.NONE.getParticles(particle, location);
}
public void updateTimers() {
}
public String getName() {
@ -32,16 +32,16 @@ public class ParticleStyleMove implements ParticleStyle, Listener {
public boolean canBeFixed() {
return false;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerMove(PlayerMoveEvent e) {
PPlayer pplayer = DataManager.getPPlayer(e.getPlayer().getUniqueId());
if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.MOVE)) {
Location loc = e.getPlayer().getLocation();
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.MOVE)) {
Location loc = e.getPlayer().getLocation();
loc.setY(loc.getY() + 0.05);
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 List<PParticle> getParticles(ParticlePair particle, Location location) {
ParticleEffect particleEffect = particle.getEffect();
List<PParticle> particles = new ArrayList<PParticle>();
public List<PParticle> getParticles(ParticlePair particle, Location location) {
ParticleEffect particleEffect = particle.getEffect();
List<PParticle> particles = new ArrayList<PParticle>();
switch (particleEffect) {
case AMBIENT_ENTITY_EFFECT:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case ANGRY_VILLAGER:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case BARRIER:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case BLOCK:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case BUBBLE:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case BUBBLE_COLUMN_UP:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case BUBBLE_POP:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case CLOUD:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case CRIT:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case CURRENT_DOWN:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case DAMAGE_INDICATOR:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case DOLPHIN:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case DRAGON_BREATH:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case DRIPPING_LAVA:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case DRIPPING_WATER:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case DUST:
return Collections.singletonList(new PParticle(location, 0.5, 0.5, 0.5, 0.0));
case ENCHANT:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.05));
case ENCHANTED_HIT:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case END_ROD:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case ENTITY_EFFECT:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case EXPLOSION:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case EXPLOSION_EMITTER:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case FALLING_DUST:
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));
return particles;
case FIREWORK:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case FISHING:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case FLAME:
return Collections.singletonList(new PParticle(location, 0.1, 0.1, 0.1, 0.05));
case FOOTSTEP:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case HAPPY_VILLAGER:
return Collections.singletonList(new PParticle(location, 0.5, 0.5, 0.5, 0.0));
case HEART:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case INSTANT_EFFECT:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case ITEM:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case ITEM_SLIME:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case ITEM_SNOWBALL:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case LARGE_SMOKE:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case LAVA:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case MYCELIUM:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case NAUTILUS:
return Collections.singletonList(new PParticle(location, 0.5, 0.5, 0.5, 0.05));
case NONE:
return particles;
case NOTE:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case POOF:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case PORTAL:
return Collections.singletonList(new PParticle(location, 0.5, 0.5, 0.5, 0.05));
case RAIN:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case SMOKE:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case SPELL:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case SPIT:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case SPLASH:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case SQUID_INK:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case SWEEP_ATTACK:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case TOTEM_OF_UNDYING:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case UNDERWATER:
for (int i = 0; i < 5; i++)
particles.add(new PParticle(location, 0.5, 0.5, 0.5, 0.0));
return particles;
case WITCH:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
default:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
}
}
switch (particleEffect) {
case AMBIENT_ENTITY_EFFECT:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case ANGRY_VILLAGER:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case BARRIER:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case BLOCK:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case BUBBLE:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case BUBBLE_COLUMN_UP:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case BUBBLE_POP:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case CLOUD:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case CRIT:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case CURRENT_DOWN:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case DAMAGE_INDICATOR:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case DOLPHIN:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case DRAGON_BREATH:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case DRIPPING_LAVA:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case DRIPPING_WATER:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case DUST:
return Collections.singletonList(new PParticle(location, 0.5, 0.5, 0.5, 0.0));
case ENCHANT:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.05));
case ENCHANTED_HIT:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case END_ROD:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case ENTITY_EFFECT:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case EXPLOSION:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case EXPLOSION_EMITTER:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case FALLING_DUST:
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));
return particles;
case FIREWORK:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case FISHING:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case FLAME:
return Collections.singletonList(new PParticle(location, 0.1, 0.1, 0.1, 0.05));
case FOOTSTEP:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case HAPPY_VILLAGER:
return Collections.singletonList(new PParticle(location, 0.5, 0.5, 0.5, 0.0));
case HEART:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case INSTANT_EFFECT:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case ITEM:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case ITEM_SLIME:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case ITEM_SNOWBALL:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case LARGE_SMOKE:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case LAVA:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case MYCELIUM:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case NAUTILUS:
return Collections.singletonList(new PParticle(location, 0.5, 0.5, 0.5, 0.05));
case NONE:
return particles;
case NOTE:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case POOF:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case PORTAL:
return Collections.singletonList(new PParticle(location, 0.5, 0.5, 0.5, 0.05));
case RAIN:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case SMOKE:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case SPELL:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case SPIT:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case SPLASH:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case SQUID_INK:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case SWEEP_ATTACK:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case TOTEM_OF_UNDYING:
return Collections.singletonList(new PParticle(location, 0.6, 0.6, 0.6, 0.0));
case UNDERWATER:
for (int i = 0; i < 5; i++)
particles.add(new PParticle(location, 0.5, 0.5, 0.5, 0.0));
return particles;
case WITCH:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
default:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
}
}
public void updateTimers() {
public void updateTimers() {
}
}
public String getName() {
return "none";
}
public String getName() {
return "none";
}
public boolean canBeFixed() {
return true;
}
public boolean canBeFixed() {
return true;
}
}

View file

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

View file

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

View file

@ -20,9 +20,9 @@ import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleSwords implements ParticleStyle, Listener {
private static final List<String> SWORD_NAMES;
static {
SWORD_NAMES = new ArrayList<String>();
SWORD_NAMES.addAll(Arrays.asList("WOOD_SWORD", "STONE_SWORD", "IRON_SWORD", "GOLD_SWORD", "GOLDEN_SWORD", "DIAMOND_SWORD", "TRIDENT"));
@ -41,7 +41,7 @@ public class ParticleStyleSwords implements ParticleStyle, Listener {
}
public void updateTimers() {
}
public String getName() {
@ -51,7 +51,7 @@ public class ParticleStyleSwords implements ParticleStyle, Listener {
public boolean canBeFixed() {
return false;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityDamageEntity(EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof Player && event.getEntity() instanceof LivingEntity) {
@ -59,12 +59,12 @@ public class ParticleStyleSwords implements ParticleStyle, Listener {
LivingEntity entity = (LivingEntity) event.getEntity();
PPlayer pplayer = DataManager.getPPlayer(player.getUniqueId());
if (pplayer != null) {
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.SWORDS)) {
Location loc = entity.getLocation().clone().add(0, 1, 0);
for (ParticlePair particle : pplayer.getActiveParticlesForStyle(DefaultStyles.SWORDS)) {
Location loc = entity.getLocation().clone().add(0, 1, 0);
ParticleManager.displayParticles(particle, DefaultStyles.SWORDS.getParticles(particle, loc));
}
}
}
}
}
}
}

View file

@ -30,7 +30,7 @@ public class ParticleStyleThick implements ParticleStyle {
public String getName() {
return "thick";
}
public boolean canBeFixed() {
return true;
}

View file

@ -28,8 +28,8 @@ public class PluginUpdateListener implements Listener {
if (e.getPlayer().isOp()) {
if (PlayerParticles.updateVersion != null) { // @formatter:off
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 +
". https://dev.bukkit.org/projects/playerparticles");
"You are running " + ChatColor.AQUA + "v" + PlayerParticles.getPlugin().getDescription().getVersion() + ChatColor.YELLOW +
". https://dev.bukkit.org/projects/playerparticles");
} // @formatter:on
}
}

View file

@ -34,7 +34,7 @@ public class ParticleUtils {
return material;
return null;
} // @formatter:on
/**
* Finds a block/item as a material from a list of possible strings
* Contains a fallback to the barrier icon just in case
@ -46,26 +46,24 @@ public class ParticleUtils {
Material mat = null;
for (String name : input) {
mat = closestMatch(name);
if (mat != null)
return mat;
if (mat != null) return mat;
}
if (mat == null)
mat = Material.BARRIER;
if (mat == null) mat = Material.BARRIER;
return mat;
}
public static List<String> getAllBlockMaterials() {
List<String> materials = new ArrayList<String>();
for (Material mat : Material.values())
if (mat.isBlock())
if (mat.isBlock())
materials.add(mat.name().toLowerCase());
return materials;
}
public static List<String> getAllItemMaterials() {
List<String> materials = new ArrayList<String>();
for (Material mat : Material.values())
if (!mat.isBlock())
if (!mat.isBlock())
materials.add(mat.name().toLowerCase());
return materials;
}
@ -86,7 +84,8 @@ public class ParticleUtils {
}
}
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;
}

View file

@ -32,7 +32,7 @@ public final class VectorUtils {
* Not instantiable
*/
private VectorUtils() {
}
/**