Add 30 second cooldown to Christmas gizmo
This commit is contained in:
parent
152401f631
commit
63b3ac4c75
|
@ -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) {
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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,6 +48,9 @@ public class ChristmasTreeGizmo extends ChristmasGizmo {
|
||||||
Player player = e.getPlayer();
|
Player player = e.getPlayer();
|
||||||
Location loc = e.getPlayer().getLocation();
|
Location loc = e.getPlayer().getLocation();
|
||||||
|
|
||||||
|
if (coolDowns.get(player) == null || coolDowns.get(player).isBefore(Instant.now().minus(COOLDOWN))) {
|
||||||
|
coolDowns.put(player, Instant.now());
|
||||||
|
|
||||||
new BukkitRunnable(){
|
new BukkitRunnable(){
|
||||||
private double phi;
|
private double phi;
|
||||||
private int i;
|
private int i;
|
||||||
|
@ -77,5 +91,8 @@ public class ChristmasTreeGizmo extends ChristmasGizmo {
|
||||||
|
|
||||||
}
|
}
|
||||||
}.runTaskTimer(Lobby.get(), 0 , 1);
|
}.runTaskTimer(Lobby.get(), 0 , 1);
|
||||||
|
} else {
|
||||||
|
audiences.get(player).sendWarning(new TranslatableComponent("gizmo.use.cooldown"), true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue