diff --git a/Lobby/src/main/java/tc/oc/lobby/bukkit/LobbyManifest.java b/Lobby/src/main/java/tc/oc/lobby/bukkit/LobbyManifest.java index e2bf3c8..d42154d 100644 --- a/Lobby/src/main/java/tc/oc/lobby/bukkit/LobbyManifest.java +++ b/Lobby/src/main/java/tc/oc/lobby/bukkit/LobbyManifest.java @@ -6,6 +6,7 @@ import org.bukkit.World; import tc.oc.commons.core.inject.HybridManifest; import tc.oc.commons.core.plugin.PluginFacetBinder; 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.halloween.ghost.GhostGizmo; import tc.oc.lobby.bukkit.listeners.PlayerListener; @@ -26,6 +27,7 @@ public class LobbyManifest extends HybridManifest { requestStaticInjection(GizmoUtils.class); requestStaticInjection(GunGizmo.class); requestStaticInjection(GhostGizmo.class); + requestStaticInjection(ChristmasTreeGizmo.class); } @Provides World world(Server server) { diff --git a/Lobby/src/main/java/tc/oc/lobby/bukkit/gizmos/Gizmos.java b/Lobby/src/main/java/tc/oc/lobby/bukkit/gizmos/Gizmos.java index f2be47d..cbf467c 100644 --- a/Lobby/src/main/java/tc/oc/lobby/bukkit/gizmos/Gizmos.java +++ b/Lobby/src/main/java/tc/oc/lobby/bukkit/gizmos/Gizmos.java @@ -36,7 +36,6 @@ public class Gizmos implements Listener { // 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 GhostGizmo ghostGizmo = new GhostGizmo("Ghosts", ChatColor.RED.toString(), "Surround yourself in ghosts!", Material.BONE); - // Christmas public static ChristmasTreeGizmo treeGizmo = new ChristmasTreeGizmo("Christmas Tree", ChatColor.AQUA.toString(), "Get in the holiday spirit!", Material.COAL); diff --git a/Lobby/src/main/java/tc/oc/lobby/bukkit/gizmos/christmas/tree/ChristmasTreeGizmo.java b/Lobby/src/main/java/tc/oc/lobby/bukkit/gizmos/christmas/tree/ChristmasTreeGizmo.java index d35c189..59a1940 100644 --- a/Lobby/src/main/java/tc/oc/lobby/bukkit/gizmos/christmas/tree/ChristmasTreeGizmo.java +++ b/Lobby/src/main/java/tc/oc/lobby/bukkit/gizmos/christmas/tree/ChristmasTreeGizmo.java @@ -1,7 +1,11 @@ package tc.oc.lobby.bukkit.gizmos.christmas.tree; import com.google.common.collect.Range; +import java.time.Duration; +import java.time.Instant; import java.time.MonthDay; +import javax.inject.Inject; +import net.md_5.bungee.api.chat.TranslatableComponent; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -10,12 +14,19 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerInteractEvent; 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.gizmos.Gizmos; import tc.oc.lobby.bukkit.gizmos.christmas.ChristmasGizmo; public class ChristmasTreeGizmo extends ChristmasGizmo { + private final OnlinePlayerMapAdapter 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) { super(name, prefix, description, icon); } @@ -37,45 +48,51 @@ public class ChristmasTreeGizmo extends ChristmasGizmo { Player player = e.getPlayer(); Location loc = e.getPlayer().getLocation(); - new BukkitRunnable(){ - private double phi; - private int i; + if (coolDowns.get(player) == null || coolDowns.get(player).isBefore(Instant.now().minus(COOLDOWN))) { + coolDowns.put(player, Instant.now()); - @Override - public void run() { - phi += Math.PI/16; - i++; + new BukkitRunnable(){ + private double phi; + private int i; - for(double t = 0; t <= (2 * Math.PI); t += Math.PI/8){ // 16 iterations - for(double d = 0; d <= 1; d += 1){ // 2 iterations - 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); + @Override + public void run() { + phi += Math.PI/16; + i++; + + for(double t = 0; t <= (2 * Math.PI); t += Math.PI/8){ // 16 iterations + for(double d = 0; d <= 1; d += 1){ // 2 iterations + 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 - 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); + 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)){ + 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)){ - cancel(); - } - - } - }.runTaskTimer(Lobby.get(), 0 , 1); + }.runTaskTimer(Lobby.get(), 0 , 1); + } else { + audiences.get(player).sendWarning(new TranslatableComponent("gizmo.use.cooldown"), true); + } } }