area effect clouds

This commit is contained in:
Gerrygames 2018-02-18 20:54:45 +01:00
parent 419649578d
commit edf96fdbec
3 changed files with 70 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package de.gerrygames.viarewind.legacysupport; package de.gerrygames.viarewind.legacysupport;
import de.gerrygames.viarewind.legacysupport.injector.LilyPadFixer; 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.BounceListener;
import de.gerrygames.viarewind.legacysupport.listener.BrewingListener; import de.gerrygames.viarewind.legacysupport.listener.BrewingListener;
import de.gerrygames.viarewind.legacysupport.listener.ElytraListener; import de.gerrygames.viarewind.legacysupport.listener.ElytraListener;
@ -35,6 +36,8 @@ public class BukkitPlugin extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new BounceListener(), this); Bukkit.getPluginManager().registerEvents(new BounceListener(), this);
if (ProtocolRegistry.SERVER_PROTOCOL>76 && config.getBoolean("elytra-fix")) if (ProtocolRegistry.SERVER_PROTOCOL>76 && config.getBoolean("elytra-fix"))
Bukkit.getPluginManager().registerEvents(new ElytraListener(), this); 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(); if (config.getBoolean("versioninfo.active")) new VersionInformer();
}); });
} }

View File

@ -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<AreaEffectCloud> effectClouds = new ArrayList<>();
public AreaEffectCloudListener() {
Bukkit.getScheduler().runTaskTimer(BukkitPlugin.getInstance(), () -> {
Set<Player> 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());
}
}

View File

@ -10,6 +10,8 @@ sound-fix: true
slime-fix: true slime-fix: true
#If this plugin should apply velocity to 1.8 and lower clients to emulate elytra flight #If this plugin should apply velocity to 1.8 and lower clients to emulate elytra flight
elytra-fix: true elytra-fix: true
#
area-effect-cloud-particles: true
#Inform your players that they are using an outdated minecraft version #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 #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. #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.