Skip to content

Commit

Permalink
unmodule some other moduled code
Browse files Browse the repository at this point in the history
Particle, faceLocation, chest sounds, boss bars
  • Loading branch information
mcmonkey4eva committed Mar 23, 2019
1 parent fce8526 commit fbfe208
Show file tree
Hide file tree
Showing 31 changed files with 135 additions and 597 deletions.
Expand Up @@ -28,8 +28,6 @@
* @author one4me
*/

import net.aufdemrand.denizen.nms.NMSHandler;
import net.aufdemrand.denizen.nms.NMSVersion;
import net.aufdemrand.denizen.nms.util.jnbt.CompoundTag;
import net.aufdemrand.denizen.nms.util.jnbt.DoubleTag;
import net.aufdemrand.denizen.nms.util.jnbt.FloatTag;
Expand Down
Expand Up @@ -8,7 +8,33 @@
import java.util.List;
import java.util.Map;

public abstract class ParticleHelper {
public class ParticleHelper {

public ParticleHelper() {
for (org.bukkit.Particle particle : org.bukkit.Particle.values()) {
register(particle.name(), new Particle(particle));
}
register("SMOKE", new Particle(org.bukkit.Particle.SMOKE_NORMAL));
register("HUGE_EXPLOSION", new Particle(org.bukkit.Particle.EXPLOSION_HUGE));
register("LARGE_EXPLODE", new Particle(org.bukkit.Particle.EXPLOSION_LARGE));
register("BUBBLE", new Particle(org.bukkit.Particle.WATER_BUBBLE));
register("SUSPEND", new Particle(org.bukkit.Particle.SUSPENDED));
register("DEPTH_SUSPEND", new Particle(org.bukkit.Particle.SUSPENDED_DEPTH));
register("CRIT", new Particle(org.bukkit.Particle.CRIT));
register("MAGIC_CRIT", new Particle(org.bukkit.Particle.CRIT_MAGIC));
register("MOB_SPELL", new Particle(org.bukkit.Particle.SPELL_MOB));
register("MOB_SPELL_AMBIENT", new Particle(org.bukkit.Particle.SPELL_MOB_AMBIENT));
register("INSTANT_SPELL", new Particle(org.bukkit.Particle.SPELL_INSTANT));
register("WITCH_MAGIC", new Particle(org.bukkit.Particle.SPELL_WITCH));
register("STEP_SOUND", new Particle(org.bukkit.Particle.HEART));
register("EXPLODE", new Particle(org.bukkit.Particle.EXPLOSION_NORMAL));
register("SPLASH", new Particle(org.bukkit.Particle.WATER_SPLASH));
register("LARGE_SMOKE", new Particle(org.bukkit.Particle.SMOKE_LARGE));
register("RED_DUST", new Particle(org.bukkit.Particle.REDSTONE));
register("SNOWBALL_POOF", new Particle(org.bukkit.Particle.SNOWBALL));
register("ANGRY_VILLAGER", new Particle(org.bukkit.Particle.VILLAGER_ANGRY));
register("HAPPY_VILLAGER", new Particle(org.bukkit.Particle.VILLAGER_HAPPY));
}

public HashMap<String, Effect> effectRemap = new HashMap<>();
private final Map<String, Particle> particles = new HashMap<>();
Expand Down
Expand Up @@ -306,7 +306,15 @@ public Location faceLocation(Location from, Location at) {
* @param from The Entity whose yaw and pitch you want to change.
* @param at The Location it should be looking at.
*/
public abstract void faceLocation(Entity from, Location at);
public void faceLocation(Entity from, Location at) {
if (from.getWorld() != at.getWorld()) {
return;
}
Location origin = from instanceof LivingEntity ? ((LivingEntity) from).getEyeLocation()
: from.getLocation().getBlock().getLocation().add(0.5, 0.5, 0.5);
Location rotated = faceLocation(origin, at);
rotate(from, rotated.getYaw(), rotated.getPitch());
}

/**
* Changes an entity's yaw and pitch to make it face another entity.
Expand Down
Expand Up @@ -4,17 +4,36 @@
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;

public interface Particle {
public class Particle {

void playFor(Player player, Location location, int count, Vector offset, double extra);
public org.bukkit.Particle particle;

<T> void playFor(Player player, Location location, int count, Vector offset, double extra, T data);
public Particle(org.bukkit.Particle particle) {
this.particle = particle;
}

public void playFor(Player player, Location location, int count, Vector offset, double extra) {
player.spawnParticle(particle, location, count, offset.getX(), offset.getY(), offset.getZ(), extra);
}

boolean isVisible();
public <T> void playFor(Player player, Location location, int count, Vector offset, double extra, T data) {
player.spawnParticle(particle, location, count, offset.getX(), offset.getY(), offset.getZ(), extra, data);
}

String getName();
public boolean isVisible() {
return particle != org.bukkit.Particle.SUSPENDED && particle != org.bukkit.Particle.SUSPENDED_DEPTH
&& particle != org.bukkit.Particle.WATER_BUBBLE;
}

public String getName() {
return particle.name();
}

default Class neededData() {
return null;
public Class neededData() {
Class clazz = particle.getDataType();
if (clazz == Void.class) {
return null;
}
return clazz;
}
}
Expand Up @@ -5,35 +5,31 @@
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;

import java.util.UUID;
import java.util.*;

public interface PlayerHelper {
public abstract class PlayerHelper {

float getAbsorption(Player player);
public abstract float getAbsorption(Player player);

void setAbsorption(Player player, float value);
public abstract void setAbsorption(Player player, float value);

int ticksPassedDuringCooldown(Player player);
public abstract int ticksPassedDuringCooldown(Player player);

float getMaxAttackCooldownTicks(Player player);
public abstract float getMaxAttackCooldownTicks(Player player);

float getAttackCooldownPercent(Player player);
public abstract float getAttackCooldownPercent(Player player);

void setAttackCooldown(Player player, int ticks);
public abstract void setAttackCooldown(Player player, int ticks);

boolean hasChunkLoaded(Player player, Chunk chunk);
public abstract boolean hasChunkLoaded(Player player, Chunk chunk);

int getPing(Player player);
public abstract int getPing(Player player);

void setTemporaryOp(Player player, boolean op);
public abstract void setTemporaryOp(Player player, boolean op);

void showEndCredits(Player player);
public abstract void showEndCredits(Player player);

ImprovedOfflinePlayer getOfflineData(UUID uuid);
public abstract ImprovedOfflinePlayer getOfflineData(UUID uuid);

ImprovedOfflinePlayer getOfflineData(OfflinePlayer offlinePlayer);

void showSimpleBossBar(Player player, String title, double progress);

void removeSimpleBossBar(Player player);
public abstract ImprovedOfflinePlayer getOfflineData(OfflinePlayer offlinePlayer);
}
Expand Up @@ -49,10 +49,6 @@ public interface SoundHelper {

Sound getDefaultMidiInstrument();

Sound getChestOpen();

Sound getChestClose();

default void playSound(Player player, Location location, String sound, float volume, float pitch, String category) {
if (player == null) {
location.getWorld().playSound(location, sound, volume, pitch);
Expand Down
Expand Up @@ -14,6 +14,7 @@
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.aufdemrand.denizen.utilities.entity.BossBarHelper;
import net.aufdemrand.denizen.utilities.packets.ItemChangeMessage;
import net.aufdemrand.denizencore.objects.*;
import net.aufdemrand.denizencore.tags.Attribute;
Expand All @@ -23,7 +24,6 @@
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.*;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.block.Block;
import org.bukkit.block.banner.PatternType;
import org.bukkit.entity.Entity;
Expand Down Expand Up @@ -2921,14 +2921,14 @@ else if (split.length > 1 && new Element(split[1]).isBoolean()) {
if (!mechanism.getValue().asString().isEmpty()) {
String[] split = mechanism.getValue().asString().split("[\\|" + dList.internal_escape + "]", 2);
if (split.length == 2 && new Element(split[0]).isDouble()) {
NMSHandler.getInstance().getPlayerHelper().showSimpleBossBar(getPlayerEntity(), split[1], new Element(split[0]).asDouble() * (1.0 / 200.0));
BossBarHelper.showSimpleBossBar(getPlayerEntity(), split[1], new Element(split[0]).asDouble() * (1.0 / 200.0));
}
else {
NMSHandler.getInstance().getPlayerHelper().showSimpleBossBar(getPlayerEntity(), split[0], 1.0);
BossBarHelper.showSimpleBossBar(getPlayerEntity(), split[0], 1.0);
}
}
else {
NMSHandler.getInstance().getPlayerHelper().removeSimpleBossBar(getPlayerEntity());
BossBarHelper.removeSimpleBossBar(getPlayerEntity());
}
}

Expand Down
@@ -1,7 +1,5 @@
package net.aufdemrand.denizen.objects.properties.item;

import net.aufdemrand.denizen.nms.NMSHandler;
import net.aufdemrand.denizen.nms.NMSVersion;
import net.aufdemrand.denizen.objects.dColor;
import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizencore.objects.Mechanism;
Expand Down
Expand Up @@ -12,6 +12,7 @@
import net.aufdemrand.denizencore.objects.dList;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand;
import org.bukkit.Sound;
import org.bukkit.entity.Player;

import java.util.Arrays;
Expand Down Expand Up @@ -96,7 +97,7 @@ public void execute(ScriptEntry scriptEntry) {
Player ent = player.getPlayerEntity();
if (sound.asBoolean()) {
NMSHandler.getInstance().getSoundHelper().playSound(ent, location,
NMSHandler.getInstance().getSoundHelper().getChestOpen(), 1, 1, "BLOCKS");
Sound.BLOCK_CHEST_OPEN, 1, 1, "BLOCKS");
}
packetHelper.showBlockAction(ent, location, 1, 1);
}
Expand All @@ -107,7 +108,7 @@ public void execute(ScriptEntry scriptEntry) {
Player ent = player.getPlayerEntity();
if (sound.asBoolean()) {
NMSHandler.getInstance().getSoundHelper().playSound(ent, location,
NMSHandler.getInstance().getSoundHelper().getChestClose(), 1, 1, "BLOCKS");
Sound.BLOCK_CHEST_CLOSE, 1, 1, "BLOCKS");
}
packetHelper.showBlockAction(ent, location, 1, 0);
}
Expand Down
@@ -0,0 +1,47 @@
package net.aufdemrand.denizen.utilities.entity;

import org.bukkit.Bukkit;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.entity.Player;

import java.util.*;

public class BossBarHelper {

private static final Map<UUID, List<BossBar>> bossBars = new HashMap<>();

public static void showSimpleBossBar(Player player, String title, double progress) {
UUID uuid = player.getUniqueId();
if (!bossBars.containsKey(uuid)) {
bossBars.put(uuid, new ArrayList<>());
}
List<BossBar> playerBars = bossBars.get(uuid);
if (!playerBars.isEmpty()) {
Iterator<BossBar> iterator = playerBars.iterator();
while (iterator.hasNext()) {
BossBar bossBar = iterator.next();
bossBar.removePlayer(player);
iterator.remove();
}
}
BossBar bossBar = Bukkit.createBossBar(title, BarColor.PURPLE, BarStyle.SOLID);
bossBar.setProgress(progress);
bossBar.addPlayer(player);
bossBar.setVisible(true);
playerBars.add(bossBar);
}

public static void removeSimpleBossBar(Player player) {
UUID uuid = player.getUniqueId();
if (bossBars.containsKey(uuid) && !bossBars.get(uuid).isEmpty()) {
Iterator<BossBar> iterator = bossBars.get(uuid).iterator();
while (iterator.hasNext()) {
BossBar bossBar = iterator.next();
bossBar.removePlayer(player);
iterator.remove();
}
}
}
}
Expand Up @@ -483,17 +483,6 @@ public Location getImpactNormal(Location start, Vector direction, double range)
return null;
}

@Override
public void faceLocation(Entity from, Location at) {
if (from.getWorld() != at.getWorld()) {
return;
}
Location origin = from instanceof LivingEntity ? ((LivingEntity) from).getEyeLocation()
: from.getLocation().getBlock().getLocation().add(0.5, 0.5, 0.5);
Location rotated = faceLocation(origin, at);
rotate(from, rotated.getYaw(), rotated.getPitch());
}

@Override
public void move(Entity entity, Vector vector) {
((CraftEntity) entity).getHandle().move(vector.getX(), vector.getY(), vector.getZ());
Expand Down
@@ -1,37 +1,12 @@
package net.aufdemrand.denizen.nms.helpers;

import net.aufdemrand.denizen.nms.abstracts.ParticleHelper;
import net.aufdemrand.denizen.nms.impl.effects.Particle_v1_10_R1;
import org.bukkit.Effect;
import org.bukkit.Particle;

public class ParticleHelper_v1_10_R1 extends ParticleHelper {

public ParticleHelper_v1_10_R1() {
for (Particle particle : Particle.values()) {
register(particle.name(), new Particle_v1_10_R1(particle));
}
effectRemap.put("DRIP_WATER", Effect.WATERDRIP);
effectRemap.put("DRIP_LAVA", Effect.LAVADRIP);
register("SMOKE", new Particle_v1_10_R1(Particle.SMOKE_NORMAL));
register("HUGE_EXPLOSION", new Particle_v1_10_R1(Particle.EXPLOSION_HUGE));
register("LARGE_EXPLODE", new Particle_v1_10_R1(Particle.EXPLOSION_LARGE));
register("BUBBLE", new Particle_v1_10_R1(Particle.WATER_BUBBLE));
register("SUSPEND", new Particle_v1_10_R1(Particle.SUSPENDED));
register("DEPTH_SUSPEND", new Particle_v1_10_R1(Particle.SUSPENDED_DEPTH));
register("CRIT", new Particle_v1_10_R1(Particle.CRIT));
register("MAGIC_CRIT", new Particle_v1_10_R1(Particle.CRIT_MAGIC));
register("MOB_SPELL", new Particle_v1_10_R1(Particle.SPELL_MOB));
register("MOB_SPELL_AMBIENT", new Particle_v1_10_R1(Particle.SPELL_MOB_AMBIENT));
register("INSTANT_SPELL", new Particle_v1_10_R1(Particle.SPELL_INSTANT));
register("WITCH_MAGIC", new Particle_v1_10_R1(Particle.SPELL_WITCH));
register("STEP_SOUND", new Particle_v1_10_R1(Particle.HEART));
register("EXPLODE", new Particle_v1_10_R1(Particle.EXPLOSION_NORMAL));
register("SPLASH", new Particle_v1_10_R1(Particle.WATER_SPLASH));
register("LARGE_SMOKE", new Particle_v1_10_R1(Particle.SMOKE_LARGE));
register("RED_DUST", new Particle_v1_10_R1(Particle.REDSTONE));
register("SNOWBALL_POOF", new Particle_v1_10_R1(Particle.SNOWBALL));
register("ANGRY_VILLAGER", new Particle_v1_10_R1(Particle.VILLAGER_ANGRY));
register("HAPPY_VILLAGER", new Particle_v1_10_R1(Particle.VILLAGER_HAPPY));
}
}

0 comments on commit fbfe208

Please sign in to comment.