Add 30 second cooldown to Christmas gizmo

This commit is contained in:
Austin Mayes 2018-12-24 19:35:20 -06:00
parent 152401f631
commit 63b3ac4c75
3 changed files with 52 additions and 34 deletions

View File

@ -6,6 +6,7 @@ import org.bukkit.World;
import tc.oc.commons.core.inject.HybridManifest; import tc.oc.commons.core.inject.HybridManifest;
import tc.oc.commons.core.plugin.PluginFacetBinder; import tc.oc.commons.core.plugin.PluginFacetBinder;
import tc.oc.lobby.bukkit.gizmos.GizmoUtils; import tc.oc.lobby.bukkit.gizmos.GizmoUtils;
import tc.oc.lobby.bukkit.gizmos.christmas.tree.ChristmasTreeGizmo;
import tc.oc.lobby.bukkit.gizmos.gun.GunGizmo; import tc.oc.lobby.bukkit.gizmos.gun.GunGizmo;
import tc.oc.lobby.bukkit.gizmos.halloween.ghost.GhostGizmo; import tc.oc.lobby.bukkit.gizmos.halloween.ghost.GhostGizmo;
import tc.oc.lobby.bukkit.listeners.PlayerListener; import tc.oc.lobby.bukkit.listeners.PlayerListener;
@ -26,6 +27,7 @@ public class LobbyManifest extends HybridManifest {
requestStaticInjection(GizmoUtils.class); requestStaticInjection(GizmoUtils.class);
requestStaticInjection(GunGizmo.class); requestStaticInjection(GunGizmo.class);
requestStaticInjection(GhostGizmo.class); requestStaticInjection(GhostGizmo.class);
requestStaticInjection(ChristmasTreeGizmo.class);
} }
@Provides World world(Server server) { @Provides World world(Server server) {

View File

@ -36,7 +36,6 @@ public class Gizmos implements Listener {
// Halloween // Halloween
public static HeadlessHorsemanGizmo headlessHorsemanGizmo = new HeadlessHorsemanGizmo("The Headless Horseman", ChatColor.RED.toString(), "You have been taken over by the darkness...", Material.NETHER_STAR); public static HeadlessHorsemanGizmo headlessHorsemanGizmo = new HeadlessHorsemanGizmo("The Headless Horseman", ChatColor.RED.toString(), "You have been taken over by the darkness...", Material.NETHER_STAR);
public static GhostGizmo ghostGizmo = new GhostGizmo("Ghosts", ChatColor.RED.toString(), "Surround yourself in ghosts!", Material.BONE); public static GhostGizmo ghostGizmo = new GhostGizmo("Ghosts", ChatColor.RED.toString(), "Surround yourself in ghosts!", Material.BONE);
// Christmas // Christmas
public static ChristmasTreeGizmo treeGizmo = new ChristmasTreeGizmo("Christmas Tree", ChatColor.AQUA.toString(), "Get in the holiday spirit!", Material.COAL); public static ChristmasTreeGizmo treeGizmo = new ChristmasTreeGizmo("Christmas Tree", ChatColor.AQUA.toString(), "Get in the holiday spirit!", Material.COAL);

View File

@ -1,7 +1,11 @@
package tc.oc.lobby.bukkit.gizmos.christmas.tree; package tc.oc.lobby.bukkit.gizmos.christmas.tree;
import com.google.common.collect.Range; import com.google.common.collect.Range;
import java.time.Duration;
import java.time.Instant;
import java.time.MonthDay; import java.time.MonthDay;
import javax.inject.Inject;
import net.md_5.bungee.api.chat.TranslatableComponent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -10,12 +14,19 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import tc.oc.commons.bukkit.chat.Audiences;
import tc.oc.commons.bukkit.util.OnlinePlayerMapAdapter;
import tc.oc.lobby.bukkit.Lobby; import tc.oc.lobby.bukkit.Lobby;
import tc.oc.lobby.bukkit.gizmos.Gizmos; import tc.oc.lobby.bukkit.gizmos.Gizmos;
import tc.oc.lobby.bukkit.gizmos.christmas.ChristmasGizmo; import tc.oc.lobby.bukkit.gizmos.christmas.ChristmasGizmo;
public class ChristmasTreeGizmo extends ChristmasGizmo { public class ChristmasTreeGizmo extends ChristmasGizmo {
private final OnlinePlayerMapAdapter<Instant> coolDowns = new OnlinePlayerMapAdapter<>(Lobby.get());
private static final Duration COOLDOWN = Duration.ofSeconds(30);
@Inject private static Audiences audiences;
public ChristmasTreeGizmo(String name, String prefix, String description, Material icon) { public ChristmasTreeGizmo(String name, String prefix, String description, Material icon) {
super(name, prefix, description, icon); super(name, prefix, description, icon);
} }
@ -37,45 +48,51 @@ public class ChristmasTreeGizmo extends ChristmasGizmo {
Player player = e.getPlayer(); Player player = e.getPlayer();
Location loc = e.getPlayer().getLocation(); Location loc = e.getPlayer().getLocation();
new BukkitRunnable(){ if (coolDowns.get(player) == null || coolDowns.get(player).isBefore(Instant.now().minus(COOLDOWN))) {
private double phi; coolDowns.put(player, Instant.now());
private int i;
@Override new BukkitRunnable(){
public void run() { private double phi;
phi += Math.PI/16; private int i;
i++;
for(double t = 0; t <= (2 * Math.PI); t += Math.PI/8){ // 16 iterations @Override
for(double d = 0; d <= 1; d += 1){ // 2 iterations public void run() {
double x = 0.3 * ((2 * Math.PI) - t) * 0.5 * StrictMath.cos(t + phi + (d * Math.PI)); phi += Math.PI/16;
double y = 0.5 * t; i++;
double z = 0.3 * ((2 * Math.PI) - t) * 0.5 * StrictMath.sin(t + phi + (d * Math.PI));
loc.add(x,y,z); for(double t = 0; t <= (2 * Math.PI); t += Math.PI/8){ // 16 iterations
player.getWorld().spawnParticle(Particle.CRIT_MAGIC, loc, 1, 0, 0, 0, 0); for(double d = 0; d <= 1; d += 1){ // 2 iterations
loc.subtract(x,y,z); double x = 0.3 * ((2 * Math.PI) - t) * 0.5 * StrictMath.cos(t + phi + (d * Math.PI));
double y = 0.5 * t;
double z = 0.3 * ((2 * Math.PI) - t) * 0.5 * StrictMath.sin(t + phi + (d * Math.PI));
loc.add(x,y,z);
player.getWorld().spawnParticle(Particle.CRIT_MAGIC, loc, 1, 0, 0, 0, 0);
loc.subtract(x,y,z);
}
for (double d = 0; d <= 1; d += 1) { // 2 iterations
double x = 0.2 * ((2 * Math.PI) - t) * 0.5 * StrictMath.cos(t + phi + (d * Math.PI));
double y = 0.45 * t;
double z = 0.2 * ((2 * Math.PI) - t) * 0.5 * StrictMath.sin(t + phi + (d * Math.PI));
loc.add(x, y, z);
player.getWorld().spawnParticle(Particle.ENCHANTMENT_TABLE, loc, 1, 0, 0, 0, 0);
loc.subtract(x, y, z);
}
} }
for (double d = 0; d <= 1; d += 1) { // 2 iterations if ((i % 4) == 0) {
double x = 0.2 * ((2 * Math.PI) - t) * 0.5 * StrictMath.cos(t + phi + (d * Math.PI)); loc.add(0, 3.25, 0);
double y = 0.45 * t; player.getWorld().spawnParticle(Particle.FLAME, loc, 1, 0, 0, 0, 0);
double z = 0.2 * ((2 * Math.PI) - t) * 0.5 * StrictMath.sin(t + phi + (d * Math.PI)); loc.subtract(0, 3.25, 0);
loc.add(x, y, z); }
player.getWorld().spawnParticle(Particle.ENCHANTMENT_TABLE, loc, 1, 0, 0, 0, 0); if(phi > (10 * Math.PI)){
loc.subtract(x, y, z); cancel();
} }
}
if ((i % 4) == 0) {
loc.add(0, 3.25, 0);
player.getWorld().spawnParticle(Particle.FLAME, loc, 1, 0, 0, 0, 0);
loc.subtract(0, 3.25, 0);
} }
if(phi > (10 * Math.PI)){ }.runTaskTimer(Lobby.get(), 0 , 1);
cancel(); } else {
} audiences.get(player).sendWarning(new TranslatableComponent("gizmo.use.cooldown"), true);
}
}
}.runTaskTimer(Lobby.get(), 0 , 1);
} }
} }