Fix all styles that were broken

This commit is contained in:
Esophose 2018-10-06 21:41:39 -06:00
parent e637e7591e
commit 7876079ca4
18 changed files with 61 additions and 75 deletions

View file

@ -3,34 +3,26 @@ package com.esophose.playerparticles.database;
import java.sql.Connection;
import java.sql.SQLException;
public abstract class DatabaseConnector {
public interface DatabaseConnector {
/**
* Checks if the connection to the database has been created
*
* @return If the connection is created or not
*/
public abstract boolean isInitialized();
public boolean isInitialized();
/**
* Closes all open connections to the database
*/
public abstract void closeConnection();
public 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 void connect(ConnectionCallback callback);
/**
* Allows Lambda expressions to be used to reduce duplicated code for getting connections

View file

@ -9,7 +9,7 @@ import com.esophose.playerparticles.PlayerParticles;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
public class MySqlDatabaseConnector extends DatabaseConnector {
public class MySqlDatabaseConnector implements DatabaseConnector {
private HikariDataSource hikari;
private boolean initializedSuccessfully = false;
@ -44,15 +44,11 @@ public class MySqlDatabaseConnector extends DatabaseConnector {
}
public void connect(ConnectionCallback callback) {
try (Connection connection = this.getConnection()) {
try (Connection connection = hikari.getConnection()) {
callback.execute(connection);
} catch (SQLException ex) {
PlayerParticles.getPlugin().getLogger().severe("An error occurred retrieving a mysql database connection: " + ex.getMessage());
}
}
protected Connection getConnection() throws SQLException {
return hikari.getConnection();
}
}

View file

@ -7,7 +7,7 @@ import java.sql.SQLException;
import com.esophose.playerparticles.PlayerParticles;
public class SqliteDatabaseConnector extends DatabaseConnector {
public class SqliteDatabaseConnector implements DatabaseConnector {
private final String connectionString;
@ -24,15 +24,11 @@ public class SqliteDatabaseConnector extends DatabaseConnector {
}
public void connect(ConnectionCallback callback) {
try (Connection connection = this.getConnection()) {
try (Connection connection = DriverManager.getConnection(this.connectionString)) {
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

@ -66,8 +66,6 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
DATA
} // @formatter:on
public static final String rainbowName = ChatColor.RED + "r" + ChatColor.GOLD + "a" + ChatColor.YELLOW + "i" + ChatColor.GREEN + "n" + ChatColor.AQUA + "b" + ChatColor.BLUE + "o" + ChatColor.LIGHT_PURPLE + "w";
private static final int INVENTORY_SIZE = 54;
private static HashMap<UUID, GuiInventory> playerGuiInventories;
private static boolean guiEnabled;
@ -188,13 +186,13 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
// 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;
if (particles.isEmpty()) return ParticleEffect.FLAME;
return particles.get(0).getEffect();
}
private static ParticleStyle getPPlayerStyle(PPlayer pplayer) {
List<ParticlePair> particles = pplayer.getActiveParticles();
if (particles.isEmpty()) return DefaultStyles.NONE;
if (particles.isEmpty()) return DefaultStyles.NORMAL;
return particles.get(0).getStyle();
}
@ -719,14 +717,14 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
ParticleEffect pe = getPPlayerEffect(pplayer);
if (pe.hasProperty(ParticleProperty.COLORABLE)) {
if (pe == ParticleEffect.NOTE) {
if (clicked.getItemMeta().getDisplayName().equals(rainbowName)) {
if (clicked.getItemMeta().getDisplayName().equals(LangManager.getText(Lang.RAINBOW))) {
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)) {
if (clicked.getItemMeta().getDisplayName().equals(LangManager.getText(Lang.RAINBOW))) {
setPPlayerColor(pplayer, new OrdinaryColor(999, 999, 999));
} else {
for (int i = 0; i < colorMapping.length; i++) {
@ -892,13 +890,13 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
}
ItemMeta rainbowIconMeta = rainbowIcon.getItemMeta();
rainbowIconMeta.setDisplayName(rainbowName);
rainbowIconMeta.setDisplayName(LangManager.getText(Lang.RAINBOW));
if (currentColor.getRed() == 999 && currentColor.getGreen() == 999 && currentColor.getBlue() == 999) {
rainbowIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "color data") + rainbowName, LangManager.getText(Lang.GUI_ICON_CURRENT_ACTIVE, "color data")));
rainbowIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "color data") + LangManager.getText(Lang.RAINBOW), LangManager.getText(Lang.GUI_ICON_CURRENT_ACTIVE, "color data")));
rainbowIconMeta.addEnchant(Enchantment.ARROW_INFINITE, -1, true);
rainbowIconMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
} else {
rainbowIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "color data") + rainbowName));
rainbowIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "color data") + LangManager.getText(Lang.RAINBOW)));
}
rainbowIcon.setItemMeta(rainbowIconMeta);
@ -920,13 +918,13 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
}
ItemMeta rainbowIconMeta = rainbowIcon.getItemMeta();
rainbowIconMeta.setDisplayName(rainbowName);
rainbowIconMeta.setDisplayName(LangManager.getText(Lang.RAINBOW));
if (currentColor.getValueX() * 24 == 99) {
rainbowIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "note data") + rainbowName, LangManager.getText(Lang.GUI_ICON_CURRENT_ACTIVE, "note data")));
rainbowIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "note data") + LangManager.getText(Lang.RAINBOW), LangManager.getText(Lang.GUI_ICON_CURRENT_ACTIVE, "note data")));
rainbowIconMeta.addEnchant(Enchantment.ARROW_INFINITE, -1, true);
rainbowIconMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
} else {
rainbowIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "note data") + rainbowName));
rainbowIconMeta.setLore(Arrays.asList(LangManager.getText(Lang.GUI_ICON_SETS_TO, "note data") + LangManager.getText(Lang.RAINBOW)));
}
rainbowIcon.setItemMeta(rainbowIconMeta);

View file

@ -62,6 +62,9 @@ public class LangManager {
// Data Command
COMMAND_DATA_NO_ARGS,
// Rainbow
RAINBOW,
// Effects
EFFECT_NO_PERMISSION,
EFFECT_INVALID,

View file

@ -152,7 +152,6 @@ public class ParticleManager extends BukkitRunnable implements Listener {
private void displayParticles(ParticlePair particle, Location location) {
if (!ParticleStyleManager.isCustomHandled(particle.getStyle())) {
ParticleEffect effect = particle.getEffect();
if (effect == ParticleEffect.NONE) return;
for (PParticle pparticle : particle.getStyle().getParticles(particle, location)) {
if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
effect.display(particle.getSpawnMaterial(), pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), 1, pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)));
@ -173,7 +172,6 @@ public class ParticleManager extends BukkitRunnable implements Listener {
*/
public static void displayParticles(ParticlePair particle, List<PParticle> particles) {
ParticleEffect effect = particle.getEffect();
if (effect == ParticleEffect.NONE) return;
for (PParticle pparticle : particles) {
if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
effect.display(particle.getSpawnMaterial(), pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), 1, pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)));

View file

@ -23,7 +23,6 @@ public class PermissionManager {
public static boolean hasEffectPermission(Player player, ParticleEffect effect) {
if (player.hasPermission("playerparticles.*") || player.hasPermission("playerparticles.effect.*")) return true;
if (player.hasPermission("playerparticles.effect." + effect.getName())) return true;
if (effect == ParticleEffect.NONE) return true;
return false;
}
@ -38,7 +37,7 @@ public class PermissionManager {
public static boolean hasStylePermission(Player player, ParticleStyle style) {
if (player.hasPermission("playerparticles.*") || player.hasPermission("playerparticles.style.*")) return true;
if (player.hasPermission("playerparticles.style." + style.getName())) return true;
if (style == DefaultStyles.NONE) return true;
if (style == DefaultStyles.NORMAL) return true;
return false;
}

View file

@ -22,7 +22,6 @@ import org.bukkit.material.MaterialData;
public enum ParticleEffect {
// Ordered and named by their Minecraft 1.13 internal names
NONE("", ""), // Custom effect to represent none selected, always display first
AMBIENT_ENTITY_EFFECT("SPELL_MOB_AMBIENT", "SPELL_MOB_AMBIENT", ParticleProperty.COLORABLE),
ANGRY_VILLAGER("VILLAGER_ANGRY", "VILLAGER_ANGRY"),
BARRIER("BARRIER", "BARRIER"),
@ -157,7 +156,7 @@ public enum ParticleEffect {
* @return Whether the particle effect is supported or not
*/
public boolean isSupported() {
return this == NONE || this.internalEnum != null;
return this.internalEnum != null;
}
/**

View file

@ -5,7 +5,8 @@ import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import com.esophose.playerparticles.gui.PlayerParticlesGui;
import com.esophose.playerparticles.manager.LangManager;
import com.esophose.playerparticles.manager.LangManager.Lang;
import com.esophose.playerparticles.manager.ParticleManager;
import com.esophose.playerparticles.particles.ParticleEffect.NoteColor;
import com.esophose.playerparticles.particles.ParticleEffect.OrdinaryColor;
@ -49,7 +50,7 @@ public class ParticlePair {
* @param effect The player's new particle effect
*/
public void setEffect(ParticleEffect effect) {
if (effect == null) effect = ParticleEffect.NONE;
if (effect == null) effect = ParticleEffect.FLAME;
this.effect = effect;
}
@ -59,7 +60,7 @@ public class ParticlePair {
* @param style The player's new particle style
*/
public void setStyle(ParticleStyle style) {
if (style == null) style = DefaultStyles.NONE;
if (style == null) style = DefaultStyles.NORMAL;
this.style = style;
}
@ -227,12 +228,12 @@ public class ParticlePair {
} else if (this.effect.hasProperty(ParticleProperty.COLORABLE)) {
if (this.effect == ParticleEffect.NOTE) {
if (this.noteColor.getValueX() * 24 == 99) {
return PlayerParticlesGui.rainbowName;
return LangManager.getText(Lang.RAINBOW);
}
return "note #" + (int) (this.noteColor.getValueX() * 24);
} else {
if (this.color.getRed() == 999 && this.color.getGreen() == 999 && this.color.getBlue() == 999) {
return PlayerParticlesGui.rainbowName;
return LangManager.getText(Lang.RAINBOW);
} else {
return ChatColor.RED + "" + this.color.getRed() + " " + ChatColor.GREEN + this.color.getGreen() + " " + ChatColor.AQUA + this.color.getBlue();
}
@ -246,11 +247,12 @@ public class ParticlePair {
*
* @return A ParticlePair with default values
*/
@Deprecated // TODO: REMOVE ONCE NEW GUI IS DONE
public static ParticlePair getDefault() {
return new ParticlePair(null, // @formatter:off
-1,
ParticleEffect.NONE,
DefaultStyles.NONE,
ParticleEffect.FLAME,
DefaultStyles.NORMAL,
ParticleUtils.closestMatchWithFallback("IRON_SHOVEL", "IRON_SPADE"),
Material.STONE,
new OrdinaryColor(0, 0, 0),
@ -262,11 +264,12 @@ public class ParticlePair {
*
* @return A ParticlePair with default values
*/
@Deprecated // TODO: REMOVE ONCE NEW GUI IS DONE
public static ParticlePair getDefault(UUID ownerUUID) {
return new ParticlePair(ownerUUID, // @formatter:off
1,
ParticleEffect.NONE,
DefaultStyles.NONE,
ParticleEffect.FLAME,
DefaultStyles.NORMAL,
ParticleUtils.closestMatchWithFallback("IRON_SHOVEL", "IRON_SPADE"),
Material.STONE,
new OrdinaryColor(0, 0, 0),

View file

@ -24,7 +24,7 @@ public class DefaultStyles {
public static final ParticleStyle HALO = new ParticleStyleHalo();
public static final ParticleStyle HURT = new ParticleStyleHurt();
public static final ParticleStyle MOVE = new ParticleStyleMove();
public static final ParticleStyle NONE = new ParticleStyleNone();
public static final ParticleStyle NORMAL = new ParticleStyleNormal();
public static final ParticleStyle ORBIT = new ParticleStyleOrbit();
public static final ParticleStyle POINT = new ParticleStylePoint();
public static final ParticleStyle QUADHELIX = new ParticleStyleQuadhelix();
@ -40,7 +40,7 @@ public class DefaultStyles {
* Registered in alphabetical order
*/
public static void registerStyles() {
ParticleStyleManager.registerStyle(NONE); // Always display none first
ParticleStyleManager.registerStyle(NORMAL); // Always display none first
ParticleStyleManager.registerStyle(ARROWS);
ParticleStyleManager.registerStyle(BEAM);
ParticleStyleManager.registerCustomHandledStyle(BLOCKBREAK);

View file

@ -70,7 +70,7 @@ public class ParticleStyleCube implements ParticleStyle {
VectorUtils.rotateAroundAxisX(v, angleX);
VectorUtils.rotateAroundAxisY(v, angleY);
VectorUtils.rotateVector(v, xRotation, yRotation, zRotation);
pparticles.add(new PParticle(location.add(v)));
pparticles.add(new PParticle(location.clone().add(v)));
}
}
for (int p = 0; p <= particles; p++) {
@ -78,7 +78,7 @@ public class ParticleStyleCube implements ParticleStyle {
v.setY(edgeLength * p / particles - a);
VectorUtils.rotateAroundAxisY(v, angleY);
VectorUtils.rotateVector(v, xRotation, yRotation, zRotation);
pparticles.add(new PParticle(location.add(v)));
pparticles.add(new PParticle(location.clone().add(v)));
}
}
}

View file

@ -18,7 +18,7 @@ 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);
return DefaultStyles.NORMAL.getParticles(particle, location);
}
public void updateTimers() {

View file

@ -11,7 +11,7 @@ import com.esophose.playerparticles.particles.ParticlePair;
import com.esophose.playerparticles.styles.api.PParticle;
import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleNone implements ParticleStyle {
public class ParticleStyleNormal implements ParticleStyle {
public List<PParticle> getParticles(ParticlePair particle, Location location) {
ParticleEffect particleEffect = particle.getEffect();
@ -33,7 +33,7 @@ public class ParticleStyleNone implements ParticleStyle {
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));
return Collections.singletonList(new PParticle(location, 0.0, 0.0, 0.0, 0.0));
case CRIT:
return Collections.singletonList(new PParticle(location, 0.4, 0.4, 0.4, 0.0));
case CURRENT_DOWN:
@ -94,8 +94,6 @@ public class ParticleStyleNone implements ParticleStyle {
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:

View file

@ -12,31 +12,33 @@ import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleQuadhelix implements ParticleStyle {
private int stepX = 0;
private int maxStepX = 90;
private int stepY = 0;
private int maxStepY = 60;
private boolean reverse = false;
public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<PParticle>();
for (int i = 0; i < 4; i++) {
double dx = -(Math.cos((stepX / 90D) * (Math.PI * 2) + ((Math.PI / 2) * i))) * ((60 - Math.abs(stepY)) / 60);
double dy = (stepY / 60D) * 1.5;
double dz = -(Math.sin((stepX / 90D) * (Math.PI * 2) + ((Math.PI / 2) * i))) * ((60 - Math.abs(stepY)) / 60);
particles.add(new PParticle(new Location(location.getWorld(), location.getX() + dx, location.getY() + dy, location.getZ() + dz)));
double dx = -(Math.cos((stepX / (double)maxStepX) * (Math.PI * 2) + ((Math.PI / 2) * i))) * ((60 - Math.abs(stepY)) / (double)maxStepY);
double dy = (stepY / (double)maxStepY) * 1.5;
double dz = -(Math.sin((stepX / (double)maxStepX) * (Math.PI * 2) + ((Math.PI / 2) * i))) * ((60 - Math.abs(stepY)) / (double)maxStepY);
particles.add(new PParticle(location.clone().add(dx, dy, dz)));
}
return particles;
}
public void updateTimers() {
stepX++;
if (stepX > 90) {
if (stepX > maxStepX) {
stepX = 0;
}
if (reverse) {
stepY++;
if (stepY > 60) reverse = false;
if (stepY > maxStepY) reverse = false;
} else {
stepY--;
if (stepY < -60) reverse = true;
if (stepY < -maxStepY) reverse = true;
}
}

View file

@ -16,10 +16,10 @@ public class ParticleStyleSpiral implements ParticleStyle {
public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> particles = new ArrayList<PParticle>();
for (int stepY = -60; stepY < 60; stepY += 10) {
double dx = -(Math.cos(((stepX + stepY) / 90) * Math.PI * 2)) * 0.8;
double dx = -(Math.cos(((stepX + stepY) / 90D) * Math.PI * 2)) * 0.8;
double dy = stepY / 45D;
double dz = -(Math.sin(((stepX + stepY) / 90) * Math.PI * 2)) * 0.8;
particles.add(new PParticle(new Location(location.getWorld(), location.getX() + dx, location.getY() + dy, location.getZ() + dz)));
double dz = -(Math.sin(((stepX + stepY) / 90D) * Math.PI * 2)) * 0.8;
particles.add(new PParticle(location.clone().add(dx, dy, dz)));
}
return particles;
}

View file

@ -12,9 +12,9 @@ import com.esophose.playerparticles.styles.api.ParticleStyle;
public class ParticleStyleThick implements ParticleStyle {
public List<PParticle> getParticles(ParticlePair particle, Location location) {
List<PParticle> baseParticles = DefaultStyles.NONE.getParticles(particle, location);
List<PParticle> baseParticles = DefaultStyles.NORMAL.getParticles(particle, location);
int multiplyingFactor = 10; // Uses the same logic as ParticleStyleNone except multiplies the resulting particles by 10x
int multiplyingFactor = 10; // Uses the same logic as ParticleStyleNormal except multiplies the resulting particles by 10x
List<PParticle> particles = new ArrayList<PParticle>();
for (int i = 0; i < baseParticles.size() * multiplyingFactor; i++) {
particles.add(baseParticles.get(i % baseParticles.size()));

View file

@ -22,8 +22,7 @@ public class ParticleStyleWings implements ParticleStyle {
double x = Math.sin(t) * (Math.pow(Math.E, Math.cos(t)) - 2 * Math.cos(t * 4) - Math.pow(Math.sin(t / 12), 5)) / 2;
double y = Math.cos(t) * (Math.pow(Math.E, Math.cos(t)) - 2 * Math.cos(t * 4) - Math.pow(Math.sin(t / 12), 5)) / 2;
Vector v = VectorUtils.rotateAroundAxisY(new Vector(x, y, -0.3), -Math.toRadians(location.getYaw()));
Location loc = new Location(location.getWorld(), location.getX() + v.getX(), location.getY() + v.getY(), location.getZ() + v.getZ());
particles.add(new PParticle(loc));
particles.add(new PParticle(location.clone().add(v.getX(), v.getY(), v.getZ())));
}
}
return particles;

View file

@ -48,6 +48,9 @@ command-add-particle-applied: '&aA new particle has been applied with the effect
# Data Command
command-data-no-args: '&cMissing argument for effect. Command usage: &b/pp data <effect>'
# Rainbow
rainbow: '&cr&6a&ei&an&bb&9o&dw'
# Effects
effect-no-permission: '&cYou do not have permission to use the effect &b{0} &c!'
effect-invalid: '&cThe effect &b{0} &cdoes not exist. Use &b/pp effects &cfor a list of effects you can use.'
@ -78,7 +81,7 @@ disabled-worlds: '&eParticles are disabled in these worlds: &b{0}'
disabled-worlds-none: '&eParticles are not disabled in any worlds!'
# Reset
reset-success: '&aRemoved &b{0} &aactive particles.'
reset-success: '&aRemoved &b{0} &aactive particle(s)!'
# Fixed Effects
fixed-create-missing-args: '&cUnable to create fixed effect, you are missing &b{0} &crequired arguments!'