Make particle render distance configurable

This commit is contained in:
Esophose 2018-11-01 17:55:41 -06:00
parent 3077ddaa35
commit 323a316668
6 changed files with 38 additions and 27 deletions

View file

@ -1,12 +1,7 @@
/*
* TODO: v5.3
* + Add new style 'tornado'
* * Setting in config.yml for max number of particle groups, default 10
* * Permission to allow players to overrule the max particle groups allowed in the config playerparticles.groups.unlimited
* * Setting in config.yml to disable non-event styles while the player is moving
* * Setting in config.yml for max particles allowed per player, default 3
* * Permission to allow players to overrule the max particles allowed in the config.yml
* - playerparticles.particles.max.unlimited
*/
package com.esophose.playerparticles;
@ -68,7 +63,7 @@ public class PlayerParticles extends JavaPlugin {
*/
public void onEnable() {
pluginInstance = Bukkit.getServer().getPluginManager().getPlugin("PlayerParticles");
getCommand("pp").setTabCompleter(new ParticleCommandHandler());
getCommand("pp").setExecutor(new ParticleCommandHandler());

View file

@ -34,6 +34,7 @@ import com.esophose.playerparticles.manager.DataManager;
import com.esophose.playerparticles.manager.LangManager;
import com.esophose.playerparticles.manager.LangManager.Lang;
import com.esophose.playerparticles.manager.PermissionManager;
import com.esophose.playerparticles.manager.SettingManager.PSetting;
import com.esophose.playerparticles.particles.PPlayer;
import com.esophose.playerparticles.particles.ParticleEffect;
import com.esophose.playerparticles.particles.ParticleEffect.NoteColor;
@ -67,7 +68,6 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
private static final int INVENTORY_SIZE = 54;
private static HashMap<UUID, GuiInventory> playerGuiInventories;
private static boolean guiEnabled;
/**
* Cached icons to prevent calling config over and over
@ -147,8 +147,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
public static void setup() {
FileConfiguration config = PlayerParticles.getPlugin().getConfig();
guiEnabled = config.getBoolean("gui-enabled");
if (!guiEnabled) return;
if (!PSetting.GUI_ENABLED.getBoolean()) return;
playerGuiInventories = new HashMap<UUID, GuiInventory>();
effectIcons = new HashMap<String, Material>();
@ -369,7 +368,7 @@ public class PlayerParticlesGui extends BukkitRunnable implements Listener {
* @return True if the GUI is disabled
*/
public static boolean isGuiDisabled() {
return !guiEnabled;
return !PSetting.GUI_ENABLED.getBoolean();
}
/**

View file

@ -123,7 +123,7 @@ public class ParticleManager extends BukkitRunnable implements Listener {
private void displayParticles(ParticlePair particle, Location location) {
if (!ParticleStyleManager.isCustomHandled(particle.getStyle()))
for (PParticle pparticle : particle.getStyle().getParticles(particle, location))
ParticleEffect.display(particle, pparticle);
ParticleEffect.display(particle, pparticle, false);
}
/**
@ -134,7 +134,7 @@ public class ParticleManager extends BukkitRunnable implements Listener {
*/
public static void displayParticles(ParticlePair particle, List<PParticle> particles) {
for (PParticle pparticle : particles)
ParticleEffect.display(particle, pparticle);
ParticleEffect.display(particle, pparticle, false);
}
/**
@ -145,7 +145,7 @@ public class ParticleManager extends BukkitRunnable implements Listener {
private void displayFixedParticleEffect(FixedParticleEffect fixedEffect) {
ParticlePair particle = fixedEffect.getParticlePair();
for (PParticle pparticle : particle.getStyle().getParticles(particle, fixedEffect.getLocation()))
ParticleEffect.display(particle, pparticle);
ParticleEffect.display(particle, pparticle, true);
}
public static OrdinaryColor getRainbowParticleColor() {

View file

@ -19,6 +19,10 @@ public class SettingManager {
VERSION(PSettingType.DOUBLE),
TICKS_PER_PARTICLE(PSettingType.LONG),
CHECK_UPDATES(PSettingType.BOOLEAN),
GUI_ENABLED(PSettingType.BOOLEAN),
PARTICLE_RENDER_RANGE_PLAYER(PSettingType.INTEGER),
PARTICLE_RENDER_RANGE_FIXED_EFFECT(PSettingType.INTEGER),
MESSAGES_ENABLED(PSettingType.BOOLEAN),
USE_MESSAGE_PREFIX(PSettingType.BOOLEAN),

View file

@ -18,6 +18,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import com.esophose.playerparticles.manager.SettingManager.PSetting;
import com.esophose.playerparticles.styles.api.PParticle;
@SuppressWarnings("deprecation")
@ -76,7 +77,6 @@ public enum ParticleEffect {
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
private static Constructor<?> DustOptions_CONSTRUCTOR;
@ -194,17 +194,18 @@ public enum ParticleEffect {
*
* @param particle The ParticlePair, given the effect/style/data
* @param pparticle The particle spawn information
* @param isFixedEffect If the particle is spawned from a fixed effect
*/
public static void display(ParticlePair particle, PParticle pparticle) {
public static void display(ParticlePair particle, PParticle pparticle, boolean isFixedEffect) {
ParticleEffect effect = particle.getEffect();
int count = pparticle.isDirectional() ? 0 : 1;
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)));
effect.display(particle.getSpawnMaterial(), pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), 1, pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)), isFixedEffect);
} else if (effect.hasProperty(ParticleProperty.COLORABLE)) {
effect.display(particle.getSpawnColor(), pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)));
effect.display(particle.getSpawnColor(), pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)), isFixedEffect);
} else {
effect.display(pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), count, pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)));
effect.display(pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), count, pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)), isFixedEffect);
}
}
@ -217,14 +218,15 @@ public enum ParticleEffect {
* @param speed Display speed of the particles
* @param amount Amount of particles
* @param center Center location of the effect
* @param isFixedEffect If the particle is spawned from a fixed effect
* @throws ParticleDataException If the particle effect requires additional data
*/
public void display(double offsetX, double offsetY, double offsetZ, double speed, int amount, Location center) throws ParticleDataException {
public void display(double offsetX, double offsetY, double offsetZ, double speed, int amount, Location center, boolean isFixedEffect) throws ParticleDataException {
if (hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
throw new ParticleDataException("This particle effect requires additional data");
}
for (Player player : getPlayersInRange(center)) {
for (Player player : getPlayersInRange(center, isFixedEffect)) {
player.spawnParticle(internalEnum, center.getX(), center.getY(), center.getZ(), amount, offsetX, offsetY, offsetZ, speed);
}
}
@ -234,9 +236,10 @@ public enum ParticleEffect {
*
* @param color Color of the particle
* @param center Center location of the effect
* @param isFixedEffect If the particle is spawned from a fixed effect
* @throws ParticleColorException If the particle effect is not colorable or the color type is incorrect
*/
public void display(ParticleColor color, Location center) throws ParticleColorException {
public void display(ParticleColor color, Location center, boolean isFixedEffect) throws ParticleColorException {
if (!hasProperty(ParticleProperty.COLORABLE)) {
throw new ParticleColorException("This particle effect is not colorable");
}
@ -250,11 +253,11 @@ public enum ParticleEffect {
}
for (Player player : getPlayersInRange(center)) {
for (Player player : getPlayersInRange(center, isFixedEffect)) {
player.spawnParticle(internalEnum, center.getX(), center.getY(), center.getZ(), 1, 0, 0, 0, 0, dustData);
}
} else {
for (Player player : getPlayersInRange(center)) {
for (Player player : getPlayersInRange(center, isFixedEffect)) {
// 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);
}
@ -273,9 +276,10 @@ public enum ParticleEffect {
* @param speed Display speed of the particles
* @param amount Amount of particles
* @param center Center location of the effect
* @param isFixedEffect If the particle is spawned from a fixed effect
* @throws ParticleDataException If the particle effect does not require additional data or if the data type is incorrect
*/
public void display(Material spawnMaterial, double offsetX, double offsetY, double offsetZ, double speed, int amount, Location center) throws ParticleDataException {
public void display(Material spawnMaterial, double offsetX, double offsetY, double offsetZ, double speed, int amount, Location center, boolean isFixedEffect) throws ParticleDataException {
if (!hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
throw new ParticleDataException("This particle effect does not require additional data");
}
@ -295,7 +299,7 @@ public enum ParticleEffect {
extraData = null;
}
for (Player player : getPlayersInRange(center))
for (Player player : getPlayersInRange(center, isFixedEffect))
player.spawnParticle(internalEnum, center.getX(), center.getY(), center.getZ(), amount, offsetX, offsetY, offsetZ, speed, extraData);
}
@ -305,11 +309,12 @@ public enum ParticleEffect {
* @param center The center of the radius to check around
* @return A List of Players within the particle display range
*/
private List<Player> getPlayersInRange(Location center) {
private List<Player> getPlayersInRange(Location center, boolean isFixedEffect) {
List<Player> players = new ArrayList<Player>();
int range = isFixedEffect ? PSetting.PARTICLE_RENDER_RANGE_PLAYER.getInt() : PSetting.PARTICLE_RENDER_RANGE_FIXED_EFFECT.getInt();
for (Player p : Bukkit.getOnlinePlayers())
if (p.getWorld().equals(center.getWorld()) && center.distanceSquared(p.getLocation()) <= PARTICLE_DISPLAY_RANGE_SQUARED)
if (p.getWorld().equals(center.getWorld()) && center.distanceSquared(p.getLocation()) <= range * range)
players.add(p);
return players;

View file

@ -74,6 +74,14 @@ max-fixed-effect-creation-distance: 32
# Default: 1
ticks-per-particle: 1
# From how many blocks away should a player be able to see the particles from another player?
# Default: 48
particle-render-range-player: 48
# From how many blocks away should a player be able to see the particles from a fixed effect?
# Default: 192
particle-render-range-fixed-effect: 192
# ================================================================ #
# DATABASE CONFIGURATION #
# Information: #