Skip to content

Commit

Permalink
Merge pull request #30 from MrEAlderson/master
Browse files Browse the repository at this point in the history
Added fireball-cooldown-visually: Show cooldown in hotbar in 1.12+ (similar to ender pearls in vanilla)
  • Loading branch information
MetallicGoat authored Jul 29, 2024
2 parents d78555b + 933a65d commit 0a115ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ public class MainConfig {
public static boolean fireball_cooldown_enabled = true;
@Config public static long fireball_cooldown_time = 20L;

@Config(
description = {
"Shows a visual cooldown in the player's hotbar (similar to ender pearls in vanilla)",
"1.12+ only"
}
)
public static boolean fireball_cooldown_visually = true;

@Config(
description = {
"Effects given when a fireball is thrown (Default is like hypixel)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

import de.marcely.bedwars.api.event.player.PlayerUseSpecialItemEvent;
import de.marcely.bedwars.api.game.specialitem.SpecialItemType;
import de.marcely.bedwars.tools.NMSHelper;
import java.util.ArrayList;
import java.util.List;
import me.metallicgoat.tweaksaddon.MBedwarsTweaksPlugin;
import me.metallicgoat.tweaksaddon.config.MainConfig;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;

public class FireballUseCoolDown implements Listener {

Expand All @@ -27,14 +31,26 @@ public void onPlayerUseSpecialItem(PlayerUseSpecialItemEvent event) {
if (player.isInsideVehicle() && player.getVehicle() instanceof LivingEntity)
return;

if (coolDownPlayers.contains(player)) {
if (this.coolDownPlayers.contains(player)) {
event.setCancelled(true);
return;
}

coolDownPlayers.add(player);
this.coolDownPlayers.add(player);

Bukkit.getServer().getScheduler().runTaskLater(MBedwarsTweaksPlugin.getInstance(), () ->
coolDownPlayers.remove(player), MainConfig.fireball_cooldown_time);
this.coolDownPlayers.remove(player), MainConfig.fireball_cooldown_time);

// Visual cooldown
if (MainConfig.fireball_cooldown_visually && NMSHelper.get().getVersion() >= 12) {
final ItemStack is = event.getSpecialItem().getItemStack();

try {
HumanEntity.class.getMethod("setCooldown", Material.class, int.class)
.invoke(player, is.getType(), (int) MainConfig.fireball_cooldown_time);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

0 comments on commit 0a115ea

Please sign in to comment.