add EndCommand

This commit is contained in:
EmrageGHC 2025-02-21 21:37:42 +01:00
parent 6ade7cd2ad
commit 3a9f229d81
3 changed files with 100 additions and 11 deletions

View file

@ -28,26 +28,25 @@ public final class BlazeSMP extends JavaPlugin {
@Getter private BukkitTask tabListUpdateTask;
private boolean isEndOpen;
@Override
public void onLoad() {
this.log=getSLF4JLogger();
this.log = getSLF4JLogger();
this.log.info("Loading BlazeSMP...");
this.log.info("Loading ProtectedBlocks...");
this.protectedBlocks=new ProtectedBlocks();
this.protectedBlocks = new ProtectedBlocks();
this.protectedBlocks.load();
this.log.info("Loaded ProtectedBlocks!");
this.log.info("Loading Clans...");
this.clans=new Clans();
this.clans = new Clans();
this.clans.loadAllClans();
this.log.info("Loaded Clans!");
this.log.info("Loading config...");
saveDefaultConfig();
this.configuration= getConfig();
this.configuration = getConfig();
saveConfig();
this.log.info("Loaded config!");
@ -60,12 +59,13 @@ public final class BlazeSMP extends JavaPlugin {
@Override
public void onEnable() {
BlazeSMP.instance=this;
BlazeSMP.instance = this;
isEndOpen = getConfig().getBoolean("isEndOpen", false);
this.log.info("Enabling BlazeSMP...");
this.log.info("Loading Homes...");
this.homes=new Homes();
this.homes = new Homes();
this.homes.load();
this.log.info("Loaded Homes!");
@ -77,6 +77,7 @@ public final class BlazeSMP extends JavaPlugin {
new DiscordCommand().register();
new ReloadCommand().register();
new VanishCommand().register();
new EventCommand(this).register();
this.log.info("Registered Commands!");
this.log.info("Registering EventListeners...");
@ -125,11 +126,14 @@ public final class BlazeSMP extends JavaPlugin {
this.log.info("Disabling BlazeSMP!");
}
public boolean isEndOpen() {
return isEndOpen;
}
public void setEndOpen(boolean endOpen) {
isEndOpen = endOpen;
getConfig().set("isEndOpen", endOpen);
saveConfig();
}
}
}

View file

@ -0,0 +1,85 @@
package me.freezy.plugins.papermc.blazesmp.command;
import me.freezy.plugins.papermc.blazesmp.BlazeSMP;
import me.freezy.plugins.papermc.blazesmp.command.util.SimpleCommand;
import me.freezy.plugins.papermc.blazesmp.module.manager.L4M4;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.title.Title;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.Duration;
import java.util.List;
public class EventCommand extends SimpleCommand {
private final BlazeSMP plugin;
public EventCommand(BlazeSMP plugin) {
super("event");
this.plugin = plugin;
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length == 1 && args[0].equalsIgnoreCase("open")) {
if (!(sender.getName().equals("BlazeGHC") || sender.getName().equals("EmrageGHC"))) {
sender.sendMessage(MiniMessage.miniMessage().deserialize(L4M4.get("error.no_permission")));
return true;
}
if (plugin.isEndOpen()) {
sender.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "The End is already open!");
return true;
}
if (sender instanceof Player || sender instanceof ConsoleCommandSender) {
for (int i = 10; i > 0; i--) {
int finalI = i;
Bukkit.getScheduler().runTaskLater(plugin, () -> {
String titleMessage = "<red><bold>" + finalI + "</bold></red>";
String subtitleMessage = "<gradient:#ff0000:#ff00ff><bold>The End is opening soon!</bold></gradient>";
Bukkit.getOnlinePlayers().forEach(player -> {
player.showTitle(Title.title(
MiniMessage.miniMessage().deserialize(titleMessage),
MiniMessage.miniMessage().deserialize(subtitleMessage)
));
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1.0f, 1.0f);
});
}, (10 - i) * 20L);
}
Bukkit.getScheduler().runTaskLater(plugin, () -> {
plugin.setEndOpen(true);
plugin.getConfig().set("isEndOpen", true);
plugin.saveConfig();
Bukkit.broadcastMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "The End is now open! Good luck!");
Bukkit.getOnlinePlayers().forEach(player -> {
player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_GROWL, 1.0f, 1.0f);
player.showTitle(Title.title(
MiniMessage.miniMessage().deserialize("<gradient:#ff0000:#ff00ff><bold>Open!</bold></gradient>"),
MiniMessage.miniMessage().deserialize("<gradient:#00ff00:#00ffff><bold>Good luck!</bold></gradient>"),
Title.Times.times(Duration.ofSeconds(1), Duration.ofSeconds(3), Duration.ofSeconds(1))
));
});
}, 10 * 20L);
return true;
} else {
return true;
}
}
return false;
}
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
return List.of();
}
}

View file

@ -1,6 +1,6 @@
package me.freezy.plugins.papermc.blazesmp.listener;
import me.freezy.plugins.papermc.blazeghcsmpclan.Main;
import me.freezy.plugins.papermc.blazesmp.BlazeSMP;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.World.Environment;
@ -11,9 +11,9 @@ import org.bukkit.event.player.PlayerPortalEvent;
public class EndPortalListener implements Listener {
private final Main plugin;
private final BlazeSMP plugin;
public EndPortalListener(Main plugin) {
public EndPortalListener(BlazeSMP plugin) {
this.plugin = plugin;
}