mirror of
https://github.com/TotalFreedomMC/PlayerParticles.git
synced 2024-12-31 20:02:12 +00:00
Code cleanup
This commit is contained in:
parent
e6ca822aed
commit
753b0f823a
11 changed files with 148 additions and 224 deletions
|
@ -271,7 +271,7 @@ public class FixedCommandModule implements CommandModule {
|
|||
|
||||
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);
|
||||
FixedParticleEffect fixedEffect = new FixedParticleEffect(p.getUniqueId(), nextFixedEffectId, p.getLocation().getWorld(), xPos, yPos, zPos, particle);
|
||||
|
||||
localeManager.sendMessage(pplayer, "fixed-create-success");
|
||||
PlayerParticles.getInstance().getManager(DataManager.class).saveFixedEffect(fixedEffect);
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.UUID;
|
|||
import java.util.function.Consumer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
|
||||
/**
|
||||
* All data changes to PPlayers such as group or fixed effect changes must be done through here,
|
||||
|
@ -179,10 +180,15 @@ public class DataManager extends Manager {
|
|||
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");
|
||||
World world = Bukkit.getWorld(result.getString("world"));
|
||||
if (world == null) {
|
||||
// World was deleted, remove the fixed effect as it is no longer valid
|
||||
this.removeFixedEffect(playerUUID, fixedEffectId);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Particle properties
|
||||
int particleId = result.getInt("p_id");
|
||||
|
@ -194,7 +200,7 @@ public class DataManager extends Manager {
|
|||
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));
|
||||
fixedParticles.add(new FixedParticleEffect(playerUUID, fixedEffectId, world, xPos, yPos, zPos, particle));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -385,20 +391,19 @@ public class DataManager extends Manager {
|
|||
this.async(() -> this.databaseConnector.connect((connection) -> {
|
||||
String particleUUID = UUID.randomUUID().toString();
|
||||
|
||||
String particleQuery = "INSERT INTO " + this.getTablePrefix() + "particle (uuid, group_uuid, id, effect, style, item_material, block_material, note, r, g, b) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
String particleQuery = "INSERT INTO " + this.getTablePrefix() + "particle (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.setNull(2, java.sql.Types.VARCHAR);
|
||||
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.setInt(2, fixedEffect.getId());
|
||||
statement.setString(3, particle.getEffect().getName());
|
||||
statement.setString(4, particle.getStyle().getName());
|
||||
statement.setString(5, particle.getItemMaterial().name());
|
||||
statement.setString(6, particle.getBlockMaterial().name());
|
||||
statement.setInt(7, particle.getNoteColor().getNote());
|
||||
statement.setInt(8, particle.getColor().getRed());
|
||||
statement.setInt(9, particle.getColor().getGreen());
|
||||
statement.setInt(10, particle.getColor().getBlue());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package dev.esophose.playerparticles.particles;
|
||||
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
|
@ -33,22 +32,16 @@ public class FixedParticleEffect {
|
|||
*
|
||||
* @param pplayerUUID The UUID of the player who owns the effect
|
||||
* @param id The id this effect has, unique to the owner pplayer
|
||||
* @param worldName The world name this effect will be displayed in
|
||||
* @param world The world this effect will be displayed in
|
||||
* @param xPos The X position in the world
|
||||
* @param yPos The Y position in the world
|
||||
* @param zPos The Z position in the world
|
||||
* @param particlePair The ParticlePair that represents this FixedParticleEffect's appearance
|
||||
*/
|
||||
public FixedParticleEffect(UUID pplayerUUID, int id, String worldName, double xPos, double yPos, double zPos, ParticlePair particlePair) {
|
||||
public FixedParticleEffect(UUID pplayerUUID, int id, World world, double xPos, double yPos, double zPos, ParticlePair particlePair) {
|
||||
this.pplayerUUID = pplayerUUID;
|
||||
this.id = id;
|
||||
this.particlePair = particlePair;
|
||||
|
||||
World world = Bukkit.getWorld(worldName);
|
||||
if (world == null) { // Default to the first world in case it doesn't exist
|
||||
world = Bukkit.getWorlds().get(0); // All servers will have at least one world
|
||||
}
|
||||
|
||||
this.location = new Location(world, xPos, yPos, zPos);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,10 @@ public class OtherPPlayer extends PPlayer {
|
|||
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The CommandSender where messages should be sent to
|
||||
*/
|
||||
public CommandSender getMessageDestination() {
|
||||
return this.sender;
|
||||
}
|
||||
|
|
|
@ -63,19 +63,18 @@ public class PParticle {
|
|||
* @return The location, either as normal or modified with the offsets
|
||||
*/
|
||||
public Location getLocation(boolean colorable) {
|
||||
if (!colorable) {
|
||||
if (!colorable)
|
||||
return this.location;
|
||||
} else {
|
||||
double x = this.location.getX();
|
||||
double y = this.location.getY();
|
||||
double z = this.location.getZ();
|
||||
|
||||
x += this.xOff * 1.75D * (Math.random() > 0.5 ? Math.random() : -Math.random());
|
||||
y += this.yOff * 1.75D * (Math.random() > 0.5 ? Math.random() : -Math.random());
|
||||
z += this.zOff * 1.75D * (Math.random() > 0.5 ? Math.random() : -Math.random());
|
||||
double x = this.location.getX();
|
||||
double y = this.location.getY();
|
||||
double z = this.location.getZ();
|
||||
|
||||
return new Location(this.location.getWorld(), x, y, z);
|
||||
}
|
||||
x += this.xOff * 1.75D * (Math.random() > 0.5 ? Math.random() : -Math.random());
|
||||
y += this.yOff * 1.75D * (Math.random() > 0.5 ? Math.random() : -Math.random());
|
||||
z += this.zOff * 1.75D * (Math.random() > 0.5 ? Math.random() : -Math.random());
|
||||
|
||||
return new Location(this.location.getWorld(), x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,9 +2,9 @@ package dev.esophose.playerparticles.particles;
|
|||
|
||||
import dev.esophose.playerparticles.styles.ParticleStyle;
|
||||
import dev.esophose.playerparticles.util.ParticleUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -132,10 +132,7 @@ public class PPlayer {
|
|||
* @return The target named ParticleGroup
|
||||
*/
|
||||
public ParticleGroup getParticleGroupByName(String name) {
|
||||
for (ParticleGroup group : this.particleGroups)
|
||||
if (group.getName().equalsIgnoreCase(name))
|
||||
return group;
|
||||
return null;
|
||||
return this.particleGroups.stream().filter(x -> x.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -153,10 +150,10 @@ public class PPlayer {
|
|||
* @return A ParticleGroup of this player's active particles
|
||||
*/
|
||||
public ParticleGroup getActiveParticleGroup() {
|
||||
for (ParticleGroup group : this.particleGroups)
|
||||
if (group.getName().equals(ParticleGroup.DEFAULT_NAME))
|
||||
return group;
|
||||
throw new IllegalStateException("Active particle group does not exist for player with UUID: " + this.getUniqueId());
|
||||
return this.particleGroups.stream()
|
||||
.filter(x -> x.getName().equals(ParticleGroup.DEFAULT_NAME))
|
||||
.findFirst()
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -166,11 +163,7 @@ public class PPlayer {
|
|||
* @return A List of ParticlePairs with a matching style
|
||||
*/
|
||||
public List<ParticlePair> getActiveParticlesForStyle(ParticleStyle style) {
|
||||
List<ParticlePair> matches = new ArrayList<>();
|
||||
for (ParticlePair pair : this.getActiveParticles())
|
||||
if (pair.getStyle().equals(style))
|
||||
matches.add(pair);
|
||||
return matches;
|
||||
return this.getActiveParticles().stream().filter(x -> x.getStyle().equals(style)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -180,10 +173,7 @@ 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;
|
||||
return this.getActiveParticles().stream().filter(x -> x.getId() == id).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -202,10 +192,7 @@ 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;
|
||||
return this.fixedParticles.stream().filter(x -> x.getId() == id).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -214,10 +201,7 @@ public class PPlayer {
|
|||
* @return A List of Integer ids this player's fixed effects have
|
||||
*/
|
||||
public List<Integer> getFixedEffectIds() {
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
for (FixedParticleEffect fixedEffect : this.fixedParticles)
|
||||
ids.add(fixedEffect.getId());
|
||||
return ids;
|
||||
return this.fixedParticles.stream().map(FixedParticleEffect::getId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -235,12 +219,7 @@ public class PPlayer {
|
|||
* @param id The id of the fixed effect to remove
|
||||
*/
|
||||
public void removeFixedEffect(int id) {
|
||||
for (FixedParticleEffect fixedEffect : this.fixedParticles) {
|
||||
if (fixedEffect.getId() == id) {
|
||||
this.fixedParticles.remove(fixedEffect);
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.fixedParticles.removeIf(x -> x.getId() == id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -249,11 +228,7 @@ 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);
|
||||
return ParticleUtils.getSmallestPositiveInt(this.fixedParticles.stream().mapToInt(FixedParticleEffect::getId).toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -262,11 +237,7 @@ public class PPlayer {
|
|||
* @return The next available active particle id
|
||||
*/
|
||||
public int getNextActiveParticleId() {
|
||||
List<ParticlePair> activeParticles = this.getActiveParticles();
|
||||
int[] ids = new int[activeParticles.size()];
|
||||
for (int i = 0; i < activeParticles.size(); i++)
|
||||
ids[i] = activeParticles.get(i).getId();
|
||||
return ParticleUtils.getSmallestPositiveInt(ids);
|
||||
return ParticleUtils.getSmallestPositiveInt(this.getActiveParticles().stream().mapToInt(ParticlePair::getId).toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -276,9 +247,8 @@ public class PPlayer {
|
|||
*/
|
||||
public ParticlePair getPrimaryParticle() {
|
||||
ParticlePair primaryParticle = this.getActiveParticle(1);
|
||||
if (primaryParticle == null) {
|
||||
if (primaryParticle == null)
|
||||
primaryParticle = ParticlePair.getNextDefault(this);
|
||||
}
|
||||
return primaryParticle;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,8 @@ public class PPlayerMovementListener implements Listener {
|
|||
DataManager dataManager = PlayerParticles.getInstance().getManager(DataManager.class);
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(PlayerParticles.getInstance(), () -> {
|
||||
if (!Setting.TOGGLE_ON_MOVE.getBoolean()) return;
|
||||
if (!Setting.TOGGLE_ON_MOVE.getBoolean())
|
||||
return;
|
||||
|
||||
List<UUID> toRemove = new ArrayList<>();
|
||||
|
||||
|
@ -51,8 +52,11 @@ public class PPlayerMovementListener implements Listener {
|
|||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if (!Setting.TOGGLE_ON_MOVE.getBoolean()) return;
|
||||
if (event.getTo() != null && event.getTo().getBlock() == event.getFrom().getBlock()) return;
|
||||
if (!Setting.TOGGLE_ON_MOVE.getBoolean())
|
||||
return;
|
||||
|
||||
if (event.getTo() != null && event.getTo().getBlock() == event.getFrom().getBlock())
|
||||
return;
|
||||
|
||||
UUID playerUUID = event.getPlayer().getUniqueId();
|
||||
if (!this.timeSinceLastMovement.containsKey(playerUUID)) {
|
||||
|
|
|
@ -9,7 +9,7 @@ import java.util.Arrays;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Stream;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
@ -23,70 +23,70 @@ import org.bukkit.metadata.MetadataValue;
|
|||
@SuppressWarnings("deprecation")
|
||||
public enum ParticleEffect {
|
||||
|
||||
// Ordered and named by their Minecraft 1.13 internal names
|
||||
AMBIENT_ENTITY_EFFECT("SPELL_MOB_AMBIENT", "SPELL_MOB_AMBIENT", ParticleProperty.COLORABLE),
|
||||
ANGRY_VILLAGER("VILLAGER_ANGRY", "VILLAGER_ANGRY"),
|
||||
BARRIER("BARRIER", "BARRIER"),
|
||||
BLOCK("BLOCK_CRACK", "BLOCK_CRACK", ParticleProperty.REQUIRES_MATERIAL_DATA),
|
||||
BUBBLE("WATER_BUBBLE", "WATER_BUBBLE"),
|
||||
BUBBLE_COLUMN_UP("BUBBLE_COLUMN_UP", null),
|
||||
BUBBLE_POP("BUBBLE_POP", null),
|
||||
CAMPFIRE_COSY_SMOKE("CAMPFIRE_COSY_SMOKE", null),
|
||||
CAMPFIRE_SIGNAL_SMOKE("CAMPFIRE_SIGNAL_SMOKE", null),
|
||||
CLOUD("CLOUD", "CLOUD"),
|
||||
COMPOSTER("COMPOSTER", null),
|
||||
CRIT("CRIT", "CRIT"),
|
||||
CURRENT_DOWN("CURRENT_DOWN", null),
|
||||
DAMAGE_INDICATOR("DAMAGE_INDICATOR", "DAMAGE_INDICATOR"),
|
||||
DOLPHIN("DOLPHIN", null),
|
||||
DRAGON_BREATH("DRAGON_BREATH", "DRAGON_BREATH"),
|
||||
DRIPPING_HONEY("DRIPPING_HONEY", null),
|
||||
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
|
||||
ENCHANT("ENCHANTMENT_TABLE", "ENCHANTMENT_TABLE"),
|
||||
ENCHANTED_HIT("CRIT_MAGIC", "CRIT_MAGIC"),
|
||||
END_ROD("END_ROD", "END_ROD"),
|
||||
ENTITY_EFFECT("SPELL_MOB", "SPELL_MOB", ParticleProperty.COLORABLE),
|
||||
EXPLOSION("EXPLOSION_LARGE", "EXPLOSION_LARGE"),
|
||||
EXPLOSION_EMITTER("EXPLOSION_HUGE", "EXPLOSION_HUGE"),
|
||||
FALLING_DUST("FALLING_DUST", "FALLING_DUST", ParticleProperty.REQUIRES_MATERIAL_DATA),
|
||||
FALLING_HONEY("FALLING_HONEY", null),
|
||||
FALLING_LAVA("FALLING_LAVA", null),
|
||||
FALLING_NECTAR("FALLING_NECTAR", null),
|
||||
FALLING_WATER("FALLING_WATER", null),
|
||||
FIREWORK("FIREWORKS_SPARK", "FIREWORKS_SPARK"),
|
||||
FISHING("WATER_WAKE", "WATER_WAKE"),
|
||||
FLAME("FLAME", "FLAME"),
|
||||
// FLASH("FLASH", null), // Also no thank you
|
||||
FOOTSTEP(null, "FOOTSTEP"), // Removed in Minecraft 1.13 :(
|
||||
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_SLIME("SLIME", "SLIME"),
|
||||
ITEM_SNOWBALL("SNOWBALL", "SNOWBALL"),
|
||||
LANDING_HONEY("LANDING_HONEY", null),
|
||||
LANDING_LAVA("LANDING_LAVA", null),
|
||||
LARGE_SMOKE("SMOKE_LARGE", "SMOKE_LARGE"),
|
||||
LAVA("LAVA", "LAVA"),
|
||||
MYCELIUM("TOWN_AURA", "TOWN_AURA"),
|
||||
NAUTILUS("NAUTILUS", null),
|
||||
NOTE("NOTE", "NOTE", ParticleProperty.COLORABLE),
|
||||
POOF("EXPLOSION_NORMAL", "EXPLOSION_NORMAL"), // The 1.13 combination of explode and showshovel
|
||||
PORTAL("PORTAL", "PORTAL"),
|
||||
RAIN("WATER_DROP", "WATER_DROP"),
|
||||
SMOKE("SMOKE_NORMAL", "SMOKE_NORMAL"),
|
||||
SNEEZE("SNEEZE", null),
|
||||
SPELL("SPELL", "SPELL"), // The Minecraft internal name for this is actually "effect", but that's the command name, so it's SPELL for the plugin instead
|
||||
SPIT("SPIT", "SPIT"),
|
||||
SPLASH("WATER_SPLASH", "WATER_SPLASH"),
|
||||
SQUID_INK("SQUID_INK", null),
|
||||
SWEEP_ATTACK("SWEEP_ATTACK", "SWEEP_ATTACK"),
|
||||
TOTEM_OF_UNDYING("TOTEM", "TOTEM"),
|
||||
UNDERWATER("SUSPENDED_DEPTH", "SUSPENDED_DEPTH"),
|
||||
WITCH("SPELL_WITCH", "SPELL_WTICH");
|
||||
// Ordered and named by their Minecraft 1.13+ internal names
|
||||
AMBIENT_ENTITY_EFFECT("SPELL_MOB_AMBIENT", ParticleProperty.COLORABLE),
|
||||
ANGRY_VILLAGER("VILLAGER_ANGRY"),
|
||||
BARRIER("BARRIER"),
|
||||
BLOCK("BLOCK_CRACK", ParticleProperty.REQUIRES_MATERIAL_DATA),
|
||||
BUBBLE("WATER_BUBBLE"),
|
||||
BUBBLE_COLUMN_UP("BUBBLE_COLUMN_UP"),
|
||||
BUBBLE_POP("BUBBLE_POP"),
|
||||
CAMPFIRE_COSY_SMOKE("CAMPFIRE_COSY_SMOKE"),
|
||||
CAMPFIRE_SIGNAL_SMOKE("CAMPFIRE_SIGNAL_SMOKE"),
|
||||
CLOUD("CLOUD"),
|
||||
COMPOSTER("COMPOSTER"),
|
||||
CRIT("CRIT"),
|
||||
CURRENT_DOWN("CURRENT_DOWN"),
|
||||
DAMAGE_INDICATOR("DAMAGE_INDICATOR"),
|
||||
DOLPHIN("DOLPHIN"),
|
||||
DRAGON_BREATH("DRAGON_BREATH"),
|
||||
DRIPPING_HONEY("DRIPPING_HONEY"),
|
||||
DRIPPING_LAVA("DRIP_LAVA"),
|
||||
DRIPPING_WATER("DRIP_WATER"),
|
||||
DUST("REDSTONE", ParticleProperty.COLORABLE),
|
||||
// ELDER_GUARDIAN("MOB_APPEARANCE"), // No thank you
|
||||
ENCHANT("ENCHANTMENT_TABLE"),
|
||||
ENCHANTED_HIT("CRIT_MAGIC"),
|
||||
END_ROD("END_ROD"),
|
||||
ENTITY_EFFECT("SPELL_MOB", ParticleProperty.COLORABLE),
|
||||
EXPLOSION("EXPLOSION_LARGE"),
|
||||
EXPLOSION_EMITTER("EXPLOSION_HUGE"),
|
||||
FALLING_DUST("FALLING_DUST", ParticleProperty.REQUIRES_MATERIAL_DATA),
|
||||
FALLING_HONEY("FALLING_HONEY"),
|
||||
FALLING_LAVA("FALLING_LAVA"),
|
||||
FALLING_NECTAR("FALLING_NECTAR"),
|
||||
FALLING_WATER("FALLING_WATER"),
|
||||
FIREWORK("FIREWORKS_SPARK"),
|
||||
FISHING("WATER_WAKE"),
|
||||
FLAME("FLAME"),
|
||||
// FLASH("FLASH"), // Also no thank you
|
||||
FOOTSTEP("FOOTSTEP"), // Removed in Minecraft 1.13 :(
|
||||
HAPPY_VILLAGER("VILLAGER_HAPPY"),
|
||||
HEART("HEART"),
|
||||
INSTANT_EFFECT("SPELL_INSTANT"),
|
||||
ITEM("ITEM_CRACK", ParticleProperty.REQUIRES_MATERIAL_DATA),
|
||||
ITEM_SLIME("SLIME"),
|
||||
ITEM_SNOWBALL("SNOWBALL"),
|
||||
LANDING_HONEY("LANDING_HONEY"),
|
||||
LANDING_LAVA("LANDING_LAVA"),
|
||||
LARGE_SMOKE("SMOKE_LARGE"),
|
||||
LAVA("LAVA"),
|
||||
MYCELIUM("TOWN_AURA"),
|
||||
NAUTILUS("NAUTILUS"),
|
||||
NOTE("NOTE", ParticleProperty.COLORABLE),
|
||||
POOF("EXPLOSION_NORMAL"), // The 1.13 combination of explode and showshovel
|
||||
PORTAL("PORTAL"),
|
||||
RAIN("WATER_DROP"),
|
||||
SMOKE("SMOKE_NORMAL"),
|
||||
SNEEZE("SNEEZE"),
|
||||
SPELL("SPELL"), // The Minecraft internal name for this is actually "effect", but that's the command name, so it's SPELL for the plugin instead
|
||||
SPIT("SPIT"),
|
||||
SPLASH("WATER_SPLASH"),
|
||||
SQUID_INK("SQUID_INK"),
|
||||
SWEEP_ATTACK("SWEEP_ATTACK"),
|
||||
TOTEM_OF_UNDYING("TOTEM"),
|
||||
UNDERWATER("SUSPENDED_DEPTH"),
|
||||
WITCH("SPELL_WITCH");
|
||||
|
||||
private static final Map<String, ParticleEffect> NAME_MAP = new HashMap<>();
|
||||
private final Particle internalEnum;
|
||||
|
@ -103,21 +103,13 @@ public enum ParticleEffect {
|
|||
* Construct a new particle effect
|
||||
*
|
||||
* @param enumName Name of the Particle Enum when the server version is greater than or equal to 1.13
|
||||
* @param enumNameLegacy Name of the Particle Enum when the server version is less than 1.13
|
||||
* @param properties Properties of this particle effect
|
||||
*/
|
||||
ParticleEffect(String enumName, String enumNameLegacy, ParticleProperty... properties) {
|
||||
ParticleEffect(String enumName, ParticleProperty... properties) {
|
||||
this.properties = Arrays.asList(properties);
|
||||
|
||||
Particle matchingEnum = null;
|
||||
for (Particle particle : Particle.values()) {
|
||||
if (particle.name().equals(enumName) || particle.name().equals(enumNameLegacy)) {
|
||||
matchingEnum = particle;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.internalEnum = matchingEnum; // Will be null if this server's version doesn't support this particle type
|
||||
// Will be null if this server's version doesn't support this particle type
|
||||
this.internalEnum = Stream.of(Particle.values()).filter(x -> x.name().equals(enumName)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,15 +121,6 @@ public enum ParticleEffect {
|
|||
return this.name().toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Spigot Particle Enum version of this ParticleEffect
|
||||
*
|
||||
* @return The Spigot Particle Enum this ParticleEffect represents
|
||||
*/
|
||||
public Particle getSpigotEnum() {
|
||||
return this.internalEnum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this particle effect has a specific property
|
||||
*
|
||||
|
@ -149,8 +132,7 @@ public enum ParticleEffect {
|
|||
}
|
||||
|
||||
/**
|
||||
* Determine if this particle effect is supported by your current server
|
||||
* version
|
||||
* Determine if this particle effect is supported by the current server version
|
||||
*
|
||||
* @return Whether the particle effect is supported or not
|
||||
*/
|
||||
|
@ -178,13 +160,7 @@ public enum ParticleEffect {
|
|||
* @return The particle effect
|
||||
*/
|
||||
public static ParticleEffect fromName(String name) {
|
||||
for (Entry<String, ParticleEffect> entry : NAME_MAP.entrySet()) {
|
||||
if (!entry.getKey().equalsIgnoreCase(name)) {
|
||||
continue;
|
||||
}
|
||||
return entry.getValue();
|
||||
}
|
||||
return null;
|
||||
return NAME_MAP.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package dev.esophose.playerparticles.particles;
|
||||
|
||||
import dev.esophose.playerparticles.PlayerParticles;
|
||||
import dev.esophose.playerparticles.manager.PermissionManager;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -46,8 +44,6 @@ public class ParticleGroupPreset {
|
|||
* @return True if the player has permission
|
||||
*/
|
||||
public boolean canPlayerUse(Player player) {
|
||||
PermissionManager permissionManager = PlayerParticles.getInstance().getManager(PermissionManager.class);
|
||||
|
||||
// If this particle group has a permission, does the player have it?
|
||||
if (!this.permission.isEmpty())
|
||||
if (!player.hasPermission(this.permission))
|
||||
|
@ -57,20 +53,7 @@ public class ParticleGroupPreset {
|
|||
if (this.allowPermissionOverride)
|
||||
return true;
|
||||
|
||||
// Make sure the player has permission for the number of particles in this group
|
||||
if (permissionManager.getMaxParticlesAllowed(player) < this.group.getParticles().size())
|
||||
return false;
|
||||
|
||||
// Make sure the player has permission for all effects/styles in the group
|
||||
for (ParticlePair particle : this.group.getParticles()) {
|
||||
if (!permissionManager.hasEffectPermission(player, particle.getEffect()))
|
||||
return false;
|
||||
|
||||
if (!permissionManager.hasStylePermission(player, particle.getStyle()))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return this.group.canPlayerUse(player);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,7 @@ package dev.esophose.playerparticles.util;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.Material;
|
||||
|
||||
public final class ParticleUtils {
|
||||
|
@ -21,8 +22,8 @@ public final class ParticleUtils {
|
|||
}
|
||||
}
|
||||
|
||||
private ParticleUtils() {
|
||||
|
||||
private ParticleUtils() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,19 +32,12 @@ public final class ParticleUtils {
|
|||
* @param input The material name as a string
|
||||
* @return The material from the string
|
||||
*/
|
||||
public static Material closestMatch(String input) { // @formatter:off
|
||||
if (input == null) return null;
|
||||
for (Material material : Material.values()) // First check for exact matches
|
||||
if (material.name().equalsIgnoreCase(input) ||
|
||||
material.toString().equalsIgnoreCase(input)) return material;
|
||||
for (Material material : Material.values()) // Then check for partial matches
|
||||
if (material.name().toLowerCase().contains(input.toLowerCase()) ||
|
||||
material.toString().toLowerCase().contains(input.toLowerCase()) ||
|
||||
material.name().replaceAll("_", "").toLowerCase().contains(input.toLowerCase()) ||
|
||||
material.toString().replaceAll("_", "").toLowerCase().contains(input.toLowerCase()))
|
||||
return material;
|
||||
return null;
|
||||
} // @formatter:on
|
||||
public static Material closestMatch(String input) {
|
||||
if (input == null || input.trim().isEmpty())
|
||||
return null;
|
||||
|
||||
return Material.matchMaterial(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a block/item as a material from a list of possible strings
|
||||
|
@ -54,15 +48,16 @@ public final class ParticleUtils {
|
|||
* @return The first matching material
|
||||
*/
|
||||
public static Material closestMatchWithFallback(boolean barrierFallback, String... input) {
|
||||
Material mat = null;
|
||||
for (String name : input) {
|
||||
mat = closestMatch(name);
|
||||
Material mat = closestMatch(name);
|
||||
if (mat != null)
|
||||
return mat;
|
||||
}
|
||||
|
||||
if (barrierFallback)
|
||||
mat = Material.BARRIER;
|
||||
return mat;
|
||||
return Material.BARRIER;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -90,11 +85,7 @@ public final class ParticleUtils {
|
|||
* @return The input string but formatted with each word capitalized
|
||||
*/
|
||||
public static String formatName(String string) {
|
||||
String[] words = string.split("_");
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (String word : words)
|
||||
result.append(Character.toUpperCase(word.charAt(0))).append(word.substring(1).toLowerCase()).append(" ");
|
||||
return result.toString();
|
||||
return WordUtils.capitalizeFully(string.replaceAll("_", " "));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,7 +42,7 @@ public final class VectorUtils {
|
|||
* @param angle How much to rotate
|
||||
* @return The starting vector rotated
|
||||
*/
|
||||
public static final Vector rotateAroundAxisX(Vector v, double angle) {
|
||||
public static Vector rotateAroundAxisX(Vector v, double angle) {
|
||||
double y, z, cos, sin;
|
||||
cos = Math.cos(angle);
|
||||
sin = Math.sin(angle);
|
||||
|
@ -58,7 +58,7 @@ public final class VectorUtils {
|
|||
* @param angle How much to rotate
|
||||
* @return The starting vector rotated
|
||||
*/
|
||||
public static final Vector rotateAroundAxisY(Vector v, double angle) {
|
||||
public static Vector rotateAroundAxisY(Vector v, double angle) {
|
||||
double x, z, cos, sin;
|
||||
cos = Math.cos(angle);
|
||||
sin = Math.sin(angle);
|
||||
|
@ -74,7 +74,7 @@ public final class VectorUtils {
|
|||
* @param angle How much to rotate
|
||||
* @return The starting vector rotated
|
||||
*/
|
||||
public static final Vector rotateAroundAxisZ(Vector v, double angle) {
|
||||
public static Vector rotateAroundAxisZ(Vector v, double angle) {
|
||||
double x, y, cos, sin;
|
||||
cos = Math.cos(angle);
|
||||
sin = Math.sin(angle);
|
||||
|
@ -92,7 +92,7 @@ public final class VectorUtils {
|
|||
* @param angleZ The change angle on Z
|
||||
* @return The starting vector rotated
|
||||
*/
|
||||
public static final Vector rotateVector(Vector v, double angleX, double angleY, double angleZ) {
|
||||
public static Vector rotateVector(Vector v, double angleX, double angleY, double angleZ) {
|
||||
rotateAroundAxisX(v, angleX);
|
||||
rotateAroundAxisY(v, angleY);
|
||||
rotateAroundAxisZ(v, angleZ);
|
||||
|
@ -106,7 +106,7 @@ public final class VectorUtils {
|
|||
* @param location The location to rotate around
|
||||
* @return The starting vector rotated
|
||||
*/
|
||||
public static final Vector rotateVector(Vector v, Location location) {
|
||||
public static Vector rotateVector(Vector v, Location location) {
|
||||
return rotateVector(v, location.getYaw(), location.getPitch());
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ public final class VectorUtils {
|
|||
* @param pitchDegrees The pitch offset in degrees
|
||||
* @return The starting vector rotated
|
||||
*/
|
||||
public static final Vector rotateVector(Vector v, float yawDegrees, float pitchDegrees) {
|
||||
public static Vector rotateVector(Vector v, float yawDegrees, float pitchDegrees) {
|
||||
double yaw = Math.toRadians(-1 * (yawDegrees + 90));
|
||||
double pitch = Math.toRadians(-pitchDegrees);
|
||||
|
||||
|
@ -153,7 +153,7 @@ public final class VectorUtils {
|
|||
* @param vector The vector to check
|
||||
* @return The angle toward the X axis
|
||||
*/
|
||||
public static final double angleToXAxis(Vector vector) {
|
||||
public static double angleToXAxis(Vector vector) {
|
||||
return Math.atan2(vector.getX(), vector.getY());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue