mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-12-02 15:13:33 +01:00
Merge branch 'util/particle' of https://github.com/Dariasc/Factions into Dariasc-util/particle
This commit is contained in:
commit
592a2a6445
@ -12,6 +12,9 @@ import com.massivecraft.factions.integration.dynmap.EngineDynmap;
|
||||
import com.massivecraft.factions.listeners.*;
|
||||
import com.massivecraft.factions.struct.ChatMode;
|
||||
import com.massivecraft.factions.util.*;
|
||||
import com.massivecraft.factions.util.particle.BukkitParticleProvider;
|
||||
import com.massivecraft.factions.util.particle.PacketParticleProvider;
|
||||
import com.massivecraft.factions.util.particle.ParticleProvider;
|
||||
import com.massivecraft.factions.zcore.MPlugin;
|
||||
import com.massivecraft.factions.zcore.fperms.Access;
|
||||
import com.massivecraft.factions.zcore.fperms.Permissable;
|
||||
@ -66,6 +69,7 @@ public class P extends MPlugin {
|
||||
private boolean mvdwPlaceholderAPIManager = false;
|
||||
|
||||
public SeeChunkUtil seeChunkUtil;
|
||||
public ParticleProvider particleProvider;
|
||||
|
||||
public P() {
|
||||
p = this;
|
||||
@ -135,6 +139,13 @@ public class P extends MPlugin {
|
||||
// since some other plugins execute commands directly through this command interface, provide it
|
||||
this.getCommand(this.refCommand).setExecutor(this);
|
||||
|
||||
if (Bukkit.getVersion().contains("1.8")) {
|
||||
particleProvider = new PacketParticleProvider();
|
||||
} else {
|
||||
particleProvider = new BukkitParticleProvider();
|
||||
}
|
||||
log(Level.INFO, "Using %1s as a particle provider", particleProvider.name());
|
||||
|
||||
if (getConfig().getBoolean("f-fly.enable", false)) {
|
||||
double delay = getConfig().getDouble("f-fly.radius-check", 1) * 20;
|
||||
// Only run FlightUtil if not 0
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.massivecraft.factions.util;
|
||||
|
||||
import com.darkblade12.particleeffect.ParticleEffect;
|
||||
import com.massivecraft.factions.*;
|
||||
import com.massivecraft.factions.util.particle.ParticleColor;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@ -11,24 +11,19 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.darkblade12.particleeffect.ParticleEffect.REDSTONE;
|
||||
import static com.darkblade12.particleeffect.ParticleEffect.fromName;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class SeeChunkUtil extends BukkitRunnable {
|
||||
|
||||
private Set<UUID> playersSeeingChunks = new HashSet<>();
|
||||
private boolean useColor;
|
||||
private ParticleEffect effect;
|
||||
private Object effect;
|
||||
|
||||
public SeeChunkUtil() {
|
||||
String effectName = P.p.getConfig().getString("see-chunk.particle", "REDSTONE");
|
||||
this.effect = fromName(effectName.toUpperCase());
|
||||
if (this.effect == null) {
|
||||
this.effect = REDSTONE;
|
||||
}
|
||||
this.useColor = this.effect.hasProperty(ParticleEffect.ParticleProperty.COLORABLE) && P.p.getConfig().getBoolean("see-chunk.relational-useColor", true);
|
||||
this.effect = P.p.particleProvider.effectFromString(effectName);
|
||||
this.useColor = P.p.getConfig().getBoolean("see-chunk.relational-useColor", true);
|
||||
|
||||
P.p.log(Level.INFO, "Using %s as the ParticleEffect for /f sc", effect.getName());
|
||||
P.p.log(Level.INFO, "Using %s as the ParticleEffect for /f sc", P.p.particleProvider.effectName(effect));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,16 +47,16 @@ public class SeeChunkUtil extends BukkitRunnable {
|
||||
}
|
||||
}
|
||||
|
||||
public static void showPillars(Player me, FPlayer fme, ParticleEffect particleEffect, boolean useColor) {
|
||||
public static void showPillars(Player me, FPlayer fme, Object effect, boolean useColor) {
|
||||
World world = me.getWorld();
|
||||
FLocation flocation = new FLocation(me);
|
||||
int chunkX = (int) flocation.getX();
|
||||
int chunkZ = (int) flocation.getZ();
|
||||
|
||||
ParticleEffect.ParticleColor color = null;
|
||||
ParticleColor color = null;
|
||||
if (useColor) {
|
||||
ChatColor chatColor = Board.getInstance().getFactionAt(flocation).getRelationTo(fme).getColor();
|
||||
color = RelationalParticleColor.fromChatColor(chatColor);
|
||||
color = ParticleColor.fromChatColor(chatColor);
|
||||
}
|
||||
|
||||
int blockX;
|
||||
@ -69,22 +64,22 @@ public class SeeChunkUtil extends BukkitRunnable {
|
||||
|
||||
blockX = chunkX * 16;
|
||||
blockZ = chunkZ * 16;
|
||||
showPillar(me, world, blockX, blockZ, particleEffect, color);
|
||||
showPillar(me, world, blockX, blockZ, effect, color);
|
||||
|
||||
blockX = chunkX * 16 + 16;
|
||||
blockZ = chunkZ * 16;
|
||||
showPillar(me, world, blockX, blockZ, particleEffect, color);
|
||||
showPillar(me, world, blockX, blockZ, effect, color);
|
||||
|
||||
blockX = chunkX * 16;
|
||||
blockZ = chunkZ * 16 + 16;
|
||||
showPillar(me, world, blockX, blockZ, particleEffect, color);
|
||||
showPillar(me, world, blockX, blockZ, effect, color);
|
||||
|
||||
blockX = chunkX * 16 + 16;
|
||||
blockZ = chunkZ * 16 + 16;
|
||||
showPillar(me, world, blockX, blockZ, particleEffect, color);
|
||||
showPillar(me, world, blockX, blockZ, effect, color);
|
||||
}
|
||||
|
||||
public static void showPillar(Player player, World world, int blockX, int blockZ, ParticleEffect effect, ParticleEffect.ParticleColor color) {
|
||||
public static void showPillar(Player player, World world, int blockX, int blockZ, Object effect, ParticleColor color) {
|
||||
// Lets start at the player's Y spot -30 to optimize
|
||||
for (int blockY = player.getLocation().getBlockY() - 30; blockY < player.getLocation().getBlockY() + 30; blockY++) {
|
||||
Location loc = new Location(world, blockX, blockY, blockZ);
|
||||
@ -94,9 +89,9 @@ public class SeeChunkUtil extends BukkitRunnable {
|
||||
|
||||
if (effect != null) {
|
||||
if (color == null) {
|
||||
effect.display(0, 0, 0, 10, 1, loc, player);
|
||||
P.p.particleProvider.playerSpawn(player, effect, loc, 1);
|
||||
} else {
|
||||
effect.display(color, loc, player);
|
||||
P.p.particleProvider.playerSpawn(player, effect, loc, color);
|
||||
}
|
||||
} else {
|
||||
Material mat = blockY % 5 == 0 ? Material.REDSTONE_LAMP : Material.GLASS_PANE;
|
||||
@ -105,41 +100,4 @@ public class SeeChunkUtil extends BukkitRunnable {
|
||||
}
|
||||
}
|
||||
|
||||
public enum RelationalParticleColor {
|
||||
BLACK(new ParticleEffect.OrdinaryColor(0, 0, 0)),
|
||||
DARK_BLUE(new ParticleEffect.OrdinaryColor(0, 0, 190)),
|
||||
DARK_GREEN(new ParticleEffect.OrdinaryColor(0, 190, 0)),
|
||||
DARK_AQUA(new ParticleEffect.OrdinaryColor(0, 190, 190)),
|
||||
DARK_RED(new ParticleEffect.OrdinaryColor(190, 0, 0)),
|
||||
DARK_PURPLE(new ParticleEffect.OrdinaryColor(190, 0, 190)),
|
||||
GOLD(new ParticleEffect.OrdinaryColor(217, 163, 52)),
|
||||
GRAY(new ParticleEffect.OrdinaryColor(190, 190, 190)),
|
||||
DARK_GRAY(new ParticleEffect.OrdinaryColor(63, 63, 63)),
|
||||
BLUE(new ParticleEffect.OrdinaryColor(63, 63, 254)),
|
||||
GREEN(new ParticleEffect.OrdinaryColor(63, 254, 63)),
|
||||
AQUA(new ParticleEffect.OrdinaryColor(63, 254, 254)),
|
||||
RED(new ParticleEffect.OrdinaryColor(254, 63, 63)),
|
||||
LIGHT_PURPLE(new ParticleEffect.OrdinaryColor(254, 63, 254)),
|
||||
YELLOW(new ParticleEffect.OrdinaryColor(254, 254, 63)),
|
||||
WHITE(new ParticleEffect.OrdinaryColor(255, 255, 255));
|
||||
|
||||
private ParticleEffect.OrdinaryColor ordinaryColor;
|
||||
|
||||
RelationalParticleColor(ParticleEffect.OrdinaryColor ordinaryColor) {
|
||||
this.ordinaryColor = ordinaryColor;
|
||||
}
|
||||
|
||||
public ParticleEffect.OrdinaryColor getOrdinaryColor() {
|
||||
return ordinaryColor;
|
||||
}
|
||||
|
||||
public static ParticleEffect.OrdinaryColor fromChatColor(ChatColor chatColor) {
|
||||
for (RelationalParticleColor relational : values()) {
|
||||
if (relational.name().equals(chatColor.name())) {
|
||||
return relational.getOrdinaryColor();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
package com.massivecraft.factions.util.particle;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BukkitParticleProvider implements ParticleProvider<Particle> {
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "BUKKIT";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void spawn(Particle effect, Location location, int count) {
|
||||
location.getWorld().spawnParticle(effect, location, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerSpawn(Player player, Particle effect, Location location, int count) {
|
||||
player.spawnParticle(effect, location, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawn(Particle particle, Location location, int count, double speed, double offsetX, double offsetY, double offsetZ) {
|
||||
location.getWorld().spawnParticle(particle, location, count, offsetX, offsetY, offsetZ, speed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerSpawn(Player player, Particle particle, Location location, int count, double speed, double offsetX, double offsetY, double offsetZ) {
|
||||
player.spawnParticle(particle, location, count, offsetX, offsetY, offsetZ, speed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawn(Particle particle, Location location, ParticleColor color) {
|
||||
location.getWorld().spawnParticle(particle, location, 1, new Particle.DustOptions(color.getColor(), 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerSpawn(Player player, Particle particle, Location location, ParticleColor color) {
|
||||
player.spawnParticle(particle, location, 1, new Particle.DustOptions(color.getColor(), 1.5f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle effectFromString(String string) {
|
||||
for (Particle particle : Particle.values()) {
|
||||
if (particle.name().equalsIgnoreCase(string)) {
|
||||
return particle;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String effectName(Particle particle) {
|
||||
return particle.name();
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package com.massivecraft.factions.util.particle;
|
||||
|
||||
import com.darkblade12.particleeffect.ParticleEffect;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class PacketParticleProvider implements ParticleProvider<ParticleEffect> {
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "PACKETS";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void spawn(ParticleEffect particleEffect, Location location, int count) {
|
||||
particleEffect.display(0, 0, 0, 1, count, location, new ArrayList<>(Bukkit.getOnlinePlayers()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerSpawn(Player player, ParticleEffect particleEffect, Location location, int count) {
|
||||
particleEffect.display(0, 0, 0, 1, count, location, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawn(ParticleEffect particleEffect, Location location, int count, double speed, double offsetX, double offsetY, double offsetZ) {
|
||||
particleEffect.display((float) offsetX, (float) offsetY, (float) offsetZ, (float) speed, count, location, new ArrayList<>(Bukkit.getOnlinePlayers()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerSpawn(Player player, ParticleEffect particleEffect, Location location, int count, double speed, double offsetX, double offsetY, double offsetZ) {
|
||||
particleEffect.display((float) offsetX, (float) offsetY, (float) offsetZ, (float) speed, count, location, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawn(ParticleEffect particleEffect, Location location, ParticleColor color) {
|
||||
spawn(particleEffect, location, 0, 1, color.getOffsetX(), color.getOffsetY(), color.getOffsetZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerSpawn(Player player, ParticleEffect particleEffect, Location location, ParticleColor color) {
|
||||
playerSpawn(player, particleEffect, location, 0 ,1, color.getOffsetX(), color.getOffsetY(), color.getOffsetZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParticleEffect effectFromString(String string) {
|
||||
return ParticleEffect.fromName(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String effectName(ParticleEffect particleEffect) {
|
||||
return particleEffect.name();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package com.massivecraft.factions.util.particle;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
|
||||
public class ParticleColor {
|
||||
|
||||
private Color color;
|
||||
|
||||
private float red;
|
||||
private float green;
|
||||
private float blue;
|
||||
|
||||
ParticleColor(Color color) {
|
||||
this.color = color;
|
||||
this.red = color.getRed();
|
||||
this.green = color.getGreen();
|
||||
this.blue = color.getBlue();
|
||||
}
|
||||
|
||||
public float getOffsetX() {
|
||||
if (red == 0) {
|
||||
return Float.MIN_VALUE;
|
||||
}
|
||||
return red/255;
|
||||
}
|
||||
|
||||
public float getOffsetY() {
|
||||
return green/255;
|
||||
}
|
||||
|
||||
public float getOffsetZ() {
|
||||
return blue/255;
|
||||
}
|
||||
|
||||
// Why Spigot?
|
||||
public static ParticleColor fromChatColor(ChatColor chatColor) {
|
||||
switch (chatColor) {
|
||||
case AQUA:
|
||||
return new ParticleColor(Color.AQUA);
|
||||
case BLACK:
|
||||
return new ParticleColor(Color.BLACK);
|
||||
case BLUE:
|
||||
return new ParticleColor(Color.BLUE);
|
||||
case DARK_AQUA:
|
||||
return new ParticleColor(Color.BLUE);
|
||||
case DARK_BLUE:
|
||||
return new ParticleColor(Color.BLUE);
|
||||
case DARK_GRAY:
|
||||
return new ParticleColor(Color.GRAY);
|
||||
case DARK_GREEN:
|
||||
return new ParticleColor(Color.GREEN);
|
||||
case DARK_PURPLE:
|
||||
return new ParticleColor(Color.PURPLE);
|
||||
case DARK_RED:
|
||||
return new ParticleColor(Color.RED);
|
||||
case GOLD:
|
||||
return new ParticleColor(Color.YELLOW);
|
||||
case GRAY:
|
||||
return new ParticleColor(Color.GRAY);
|
||||
case GREEN:
|
||||
return new ParticleColor(Color.LIME);
|
||||
case LIGHT_PURPLE:
|
||||
return new ParticleColor(Color.PURPLE);
|
||||
case RED:
|
||||
return new ParticleColor(Color.RED);
|
||||
case WHITE:
|
||||
return new ParticleColor(Color.WHITE);
|
||||
case YELLOW:
|
||||
return new ParticleColor(Color.YELLOW);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.massivecraft.factions.util.particle;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface ParticleProvider<Effect> {
|
||||
|
||||
String name();
|
||||
|
||||
void spawn(Effect effect, Location location, int count);
|
||||
|
||||
void playerSpawn(Player player, Effect effect, Location location, int count);
|
||||
|
||||
public void spawn(Effect effect, Location location, int count, double speed, double offsetX, double offsetY, double offsetZ);
|
||||
|
||||
void playerSpawn(Player player, Effect effect, Location location, int count, double speed, double offsetX, double offsetY, double offsetZ);
|
||||
|
||||
void spawn(Effect effect, Location location, ParticleColor color);
|
||||
|
||||
void playerSpawn(Player player, Effect effect, Location location, ParticleColor color);
|
||||
|
||||
Effect effectFromString(String string);
|
||||
|
||||
String effectName(Effect effect);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user