Added announcements!

Miscellaneous: Optimized imports.
This commit is contained in:
Nicholas Rees 2021-03-17 18:35:52 -05:00
parent b596653faf
commit 20b93acc3b
8 changed files with 130 additions and 4 deletions

@ -0,0 +1,57 @@
package zone.themcgamer.core.announce;
import com.cryptomorin.xseries.XSound;
import com.cryptomorin.xseries.messages.ActionBar;
import com.destroystokyo.paper.Title;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import zone.themcgamer.core.common.Style;
import zone.themcgamer.core.module.Module;
import zone.themcgamer.core.module.ModuleInfo;
import zone.themcgamer.data.jedis.command.JedisCommandHandler;
import zone.themcgamer.data.jedis.command.impl.announce.AnnounceCommand;
import zone.themcgamer.data.jedis.command.impl.announce.AnnounceType;
/**
* @author Nicholas
*/
@ModuleInfo(name = "Announce Manager")
public class AnnounceManager extends Module {
public AnnounceManager(JavaPlugin plugin) {
super(plugin);
registerCommand(new zone.themcgamer.core.announce.command.AnnounceCommand(this));
JedisCommandHandler.getInstance().addListener(command -> {
if (command instanceof AnnounceCommand) {
AnnounceCommand announceCommand = (AnnounceCommand) command;
AnnounceType type = announceCommand.getType();
boolean sendTitle = type == AnnounceType.TITLE || type == AnnounceType.ALL;
boolean sendActionBar = type == AnnounceType.ACTION_BAR || type == AnnounceType.ALL;
boolean sendChat = type == AnnounceType.CHAT || type == AnnounceType.ALL;
if (sendTitle) {
for (Player player : Bukkit.getOnlinePlayers()) {
player.sendTitle(new Title(
"§a§lAnnouncement",
"§7" + Style.color(announceCommand.getMessage()),
20, 3 * 20, 20));
}
}
if (sendActionBar) {
for (Player player : Bukkit.getOnlinePlayers()) {
ActionBar.sendActionBar(player, "§a§lAnnouncement §8» §7" + Style.color(announceCommand.getMessage()));
}
}
if (sendChat) {
Bukkit.broadcastMessage(Style.main("Announcement", announceCommand.getMessage()));
}
for (Player player : Bukkit.getOnlinePlayers()) {
player.playSound(player.getEyeLocation(), XSound.BLOCK_NOTE_BLOCK_PLING.parseSound(), 0.9f, 1f);
}
}
});
}
public void sendAnnouncement(AnnounceType type, String message) {
JedisCommandHandler.getInstance().send(new AnnounceCommand(type, message));
}
}

@ -0,0 +1,48 @@
package zone.themcgamer.core.announce.command;
import lombok.AllArgsConstructor;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import zone.themcgamer.common.EnumUtils;
import zone.themcgamer.core.announce.AnnounceManager;
import zone.themcgamer.core.command.Command;
import zone.themcgamer.core.command.CommandProvider;
import zone.themcgamer.core.common.Style;
import zone.themcgamer.data.Rank;
import zone.themcgamer.data.jedis.command.impl.announce.AnnounceType;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author Nicholas
*/
@AllArgsConstructor
public class AnnounceCommand {
private final AnnounceManager announceManager;
@Command(name = "announce", usage = "<type> <message ...>", description = "Announces a message", ranks = { Rank.ADMIN })
public void onCommand(CommandProvider command) {
CommandSender sender = command.getSender();
String[] args = command.getArgs();
if (args.length < 2) {
sender.sendMessage(Style.main("Announce", "Usage: /" + command.getLabel() + " <type> <message ...>"));
return;
}
if (EnumUtils.fromString(AnnounceType.class, args[0].toUpperCase()) == null) {
sender.sendMessage(Style.error("Announce", "Invalid announcement type!"));
List<AnnounceType> types = Arrays.asList(AnnounceType.values());
sender.sendMessage(Style.main("", "Available Types: §f" +
types.stream().map(AnnounceType::name).collect(Collectors.joining("§7, §f"))));
return;
}
AnnounceType type = AnnounceType.valueOf(args[0].toUpperCase());
String message = Arrays.stream(args).skip(1).collect(Collectors.joining(" "));
if (message.isEmpty() || ChatColor.stripColor(Style.color(message)).isEmpty()) {
sender.sendMessage(Style.error("Announce", "Invalid message!"));
return;
}
announceManager.sendAnnouncement(type, message);
}
}

@ -3,7 +3,6 @@ package zone.themcgamer.core.badSportSystem.command;
import lombok.AllArgsConstructor;
import org.bukkit.entity.Player;
import zone.themcgamer.core.account.AccountManager;
import zone.themcgamer.core.command.Command;
import zone.themcgamer.core.command.CommandProvider;
import zone.themcgamer.data.Rank;

@ -7,6 +7,7 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import zone.themcgamer.core.account.AccountManager;
import zone.themcgamer.core.announce.AnnounceManager;
import zone.themcgamer.core.badSportSystem.BadSportSystem;
import zone.themcgamer.core.command.CommandManager;
import zone.themcgamer.core.common.ServerUtils;
@ -180,6 +181,8 @@ public abstract class MGZPlugin extends JavaPlugin {
badSportSystem = new BadSportSystem(this, mySQLController, accountManager);
AccountManager.addMiniAccount(new TaskManager(this));
new AnnounceManager(this);
// Running the @Startup methods for the plugin
getLogger().info("Running @Startup methods...");
List<Method> methods = Arrays.stream(getClass().getMethods())

@ -1,7 +1,6 @@
package zone.themcgamer.discordbot;
import com.jagrosh.jdautilities.command.CommandClientBuilder;
import com.jagrosh.jdautilities.command.annotation.JDACommand;
import lombok.Getter;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;

@ -1,9 +1,7 @@
package zone.themcgamer.discordbot.command.impl;
import com.jagrosh.jdautilities.command.CommandEvent;
import com.jagrosh.jdautilities.command.annotation.JDACommand;
import net.dv8tion.jda.api.EmbedBuilder;
import zone.themcgamer.core.cooldown.Cooldown;
import zone.themcgamer.discordbot.command.BaseCommand;
import zone.themcgamer.discordbot.guild.Guild;
import zone.themcgamer.discordbot.utilities.EmbedUtils;

@ -0,0 +1,14 @@
package zone.themcgamer.data.jedis.command.impl.announce;
import lombok.AllArgsConstructor;
import lombok.Getter;
import zone.themcgamer.data.jedis.command.JedisCommand;
/**
* @author Nicholas
*/
@AllArgsConstructor @Getter
public class AnnounceCommand extends JedisCommand {
private final AnnounceType type;
private final String message;
}

@ -0,0 +1,8 @@
package zone.themcgamer.data.jedis.command.impl.announce;
/**
* @author Nicholas
*/
public enum AnnounceType {
ALL, TITLE, ACTION_BAR, CHAT
}