diff --git a/src/main/java/de/gerrygames/viarewind/legacysupport/BukkitPlugin.java b/src/main/java/de/gerrygames/viarewind/legacysupport/BukkitPlugin.java index fcc87ff..b1c8f45 100644 --- a/src/main/java/de/gerrygames/viarewind/legacysupport/BukkitPlugin.java +++ b/src/main/java/de/gerrygames/viarewind/legacysupport/BukkitPlugin.java @@ -1,6 +1,7 @@ package de.gerrygames.viarewind.legacysupport; import de.gerrygames.viarewind.legacysupport.injector.LilyPadFixer; +import de.gerrygames.viarewind.legacysupport.listener.AreaEffectCloudListener; import de.gerrygames.viarewind.legacysupport.listener.BounceListener; import de.gerrygames.viarewind.legacysupport.listener.BrewingListener; import de.gerrygames.viarewind.legacysupport.listener.ElytraListener; @@ -35,6 +36,8 @@ public class BukkitPlugin extends JavaPlugin { Bukkit.getPluginManager().registerEvents(new BounceListener(), this); if (ProtocolRegistry.SERVER_PROTOCOL>76 && config.getBoolean("elytra-fix")) Bukkit.getPluginManager().registerEvents(new ElytraListener(), this); + if (ProtocolRegistry.SERVER_PROTOCOL>54 && config.getBoolean("area-effect-cloud-particles")) + Bukkit.getPluginManager().registerEvents(new AreaEffectCloudListener(), this); if (config.getBoolean("versioninfo.active")) new VersionInformer(); }); } diff --git a/src/main/java/de/gerrygames/viarewind/legacysupport/listener/AreaEffectCloudListener.java b/src/main/java/de/gerrygames/viarewind/legacysupport/listener/AreaEffectCloudListener.java new file mode 100644 index 0000000..63fc9ed --- /dev/null +++ b/src/main/java/de/gerrygames/viarewind/legacysupport/listener/AreaEffectCloudListener.java @@ -0,0 +1,65 @@ +package de.gerrygames.viarewind.legacysupport.listener; + +import de.gerrygames.viarewind.legacysupport.BukkitPlugin; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.World; +import org.bukkit.entity.AreaEffectCloud; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.LingeringPotionSplashEvent; +import us.myles.ViaVersion.api.Via; + +import java.util.ArrayList; +import java.util.Set; +import java.util.stream.Collectors; + +public class AreaEffectCloudListener implements Listener { + private ArrayList effectClouds = new ArrayList<>(); + + public AreaEffectCloudListener() { + Bukkit.getScheduler().runTaskTimer(BukkitPlugin.getInstance(), () -> { + Set players = Bukkit.getOnlinePlayers() + .stream() + .filter(p -> Via.getAPI().getPlayerVersion(p) <= 54) + .collect(Collectors.toSet()); + effectClouds.removeIf(e -> !e.isValid()); + effectClouds.forEach(cloud -> { + World world = cloud.getWorld(); + Particle particle = cloud.getParticle(); + Location loc = cloud.getLocation(); + + float radius = cloud.getRadius(); + + float area = (float) Math.PI * radius * radius; + + for(int i = 0; i < area; i++) { + float f1 = (float)Math.random() * 6.2831855F; + float f2 = (float)Math.sqrt(Math.random()) * radius; + float f3 = (float)Math.cos(f1) * f2; + float f6 = (float)Math.sin(f1) * f2; + if (particle == Particle.SPELL_MOB) { + int color = cloud.getColor().asRGB(); + int r = color >> 16 & 255; + int g = color >> 8 & 255; + int b = color & 255; + players.forEach(player -> { + if (player.getWorld()!=loc.getWorld()) return; + player.spawnParticle(particle, loc.getX() + f3, loc.getY(), loc.getZ() + f6, 0, r / 255f, g / 255f, b / 255f); + }); + } else { + //TODO particles with data + //world.spawnParticle(particle, loc.getX() + f3, loc.getY(), loc.getZ() + f6, 1, (0.5 - Math.random()) * 0.15, 0.009999999776482582D, (0.5 - Math.random()) * 0.15d, ); + } + } + }); + }, 1L, 1L); + } + + @EventHandler + public void onEntitySpawn(LingeringPotionSplashEvent e) { + effectClouds.add(e.getAreaEffectCloud()); + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 69a1512..a4fbe7e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -10,6 +10,8 @@ sound-fix: true slime-fix: true #If this plugin should apply velocity to 1.8 and lower clients to emulate elytra flight elytra-fix: true +# +area-effect-cloud-particles: true #Inform your players that they are using an outdated minecraft version #max-version specifies the maximum protocol version of players being notified. See http://wiki.vg/Protocol_version_numbers for protocol version numbers #interval can be set to JOIN to notify players when joining the server. If you set it to any integer number it will broadcast the message every x ticks.