diff --git a/MAStaff-API/src/main/java/com/nookure/mast/api/event/BukkitListener.java b/MAStaff-API/src/main/java/com/nookure/mast/api/event/BukkitListener.java new file mode 100644 index 00000000..ff855ff3 --- /dev/null +++ b/MAStaff-API/src/main/java/com/nookure/mast/api/event/BukkitListener.java @@ -0,0 +1,9 @@ +package com.nookure.mast.api.event; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public interface BukkitListener extends Listener { + @EventHandler + void handle(T event); +} diff --git a/MAStaff-API/src/main/java/com/nookure/mast/api/manager/FreezeManager.java b/MAStaff-API/src/main/java/com/nookure/mast/api/manager/FreezeManager.java new file mode 100644 index 00000000..d16e0d54 --- /dev/null +++ b/MAStaff-API/src/main/java/com/nookure/mast/api/manager/FreezeManager.java @@ -0,0 +1,91 @@ +package com.nookure.mast.api.manager; + +import com.google.inject.Singleton; +import es.angelillo15.mast.api.IStaffPlayer; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.HashMap; + +@Singleton +public class FreezeManager { + public HashMap frozenPlayers = new HashMap<>(); + + /** + * Freeze the player + * @param staff IStaffPlayer who freeze the player + * @param target Player to freeze + */ + public void freezePlayer(IStaffPlayer staff, Player target) { + freezePlayer(staff, target, -1); + } + + /** + * Freeze the player + * @param staff IStaffPlayer who freeze the player + * @param target Player to freeze + * @param time Time to freeze expire + */ + public void freezePlayer(IStaffPlayer staff, Player target, long time) { + frozenPlayers.put(target.getName(), new FreezeVector(staff, target, time)); + } + + /** + * Unfreeze the player + * @param target Player + */ + public void unfreezePlayer(Player target) { + frozenPlayers.remove(target.getName()); + } + + /** + * Unfreeze the player + * @param target Player + */ + public void unfreezePlayer(String target) { + frozenPlayers.remove(target); + } + + /** + * Check if the player is frozen + * @param target Player + * @return boolean + */ + public boolean isFrozen(Player target) { + return frozenPlayers.containsKey(target.getName()); + } + + /** + * Check if the player is frozen + * @param target Player + * @return boolean + */ + public boolean isFrozen(String target) { + return frozenPlayers.containsKey(target); + } + + /** + * Gets the frozen players list + * @return ArrayList of OfflinePlayer + */ + public ArrayList getFrozenPlayers() { + ArrayList frozen = new ArrayList<>(); + frozenPlayers.forEach((name, vector) -> frozen.add(vector.getTarget())); + return frozen; + } + + /** + * Gets the frozen players list + * @return ArrayList of FreezeVector with the frozen players + */ + public ArrayList getFreezeVectors() { + ArrayList frozen = new ArrayList<>(); + frozenPlayers.forEach((name, vector) -> frozen.add(vector)); + return frozen; + } + + public FreezeVector getFreezeVector(Player target) { + return frozenPlayers.get(target.getName()); + } +} diff --git a/MAStaff-API/src/main/java/com/nookure/mast/api/manager/FreezeVector.java b/MAStaff-API/src/main/java/com/nookure/mast/api/manager/FreezeVector.java new file mode 100644 index 00000000..3b5169f6 --- /dev/null +++ b/MAStaff-API/src/main/java/com/nookure/mast/api/manager/FreezeVector.java @@ -0,0 +1,48 @@ +package com.nookure.mast.api.manager; + +import es.angelillo15.mast.api.IStaffPlayer; +import org.bukkit.OfflinePlayer; + + +public class FreezeVector { + private final IStaffPlayer staffPlayer; + private final OfflinePlayer target; + private long timeLeft; + private boolean hasTalked = false; + + public FreezeVector(IStaffPlayer staffPlayer, OfflinePlayer target, long timeLeft) { + this.staffPlayer = staffPlayer; + this.target = target; + this.timeLeft = timeLeft; + } + + public IStaffPlayer getStaffPlayer() { + return staffPlayer; + } + + public OfflinePlayer getTarget() { + return target; + } + + /** + * Get the time left to unfreeze the player + * -1 disabled + * -2 expired + * @return long time left + */ + public long getTimeLeft() { + return timeLeft; + } + + public void setTimeLeft(int timeLeft) { + this.timeLeft = timeLeft; + } + + public boolean hasTalked() { + return hasTalked; + } + + public void setHasTalked(boolean hasTalked) { + this.hasTalked = hasTalked; + } +} diff --git a/MAStaff-API/src/main/java/es/angelillo15/mast/api/IStaffPlayer.java b/MAStaff-API/src/main/java/es/angelillo15/mast/api/IStaffPlayer.java index f74483f7..9a8db7c2 100644 --- a/MAStaff-API/src/main/java/es/angelillo15/mast/api/IStaffPlayer.java +++ b/MAStaff-API/src/main/java/es/angelillo15/mast/api/IStaffPlayer.java @@ -200,4 +200,12 @@ public interface IStaffPlayer { default String getName() { return getPlayer().getName(); } + + /** + * Send a message to the player + * @param message - message to send + */ + default void sendMessage(String message) { + TextUtils.sendMessage(getPlayer(), TextUtils.toMM(message)); + } } diff --git a/MAStaff-API/src/main/java/es/angelillo15/mast/api/config/bukkit/Config.java b/MAStaff-API/src/main/java/es/angelillo15/mast/api/config/bukkit/Config.java index 6d1a2652..4d7213fa 100644 --- a/MAStaff-API/src/main/java/es/angelillo15/mast/api/config/bukkit/Config.java +++ b/MAStaff-API/src/main/java/es/angelillo15/mast/api/config/bukkit/Config.java @@ -1,6 +1,8 @@ package es.angelillo15.mast.api.config.bukkit; +import es.angelillo15.mast.api.utils.NumberUtils; + import java.util.List; public class Config { @@ -108,6 +110,18 @@ public static boolean askToExecuteCommands() { public static List commands() { return ConfigLoader.getConfig().getConfig().getStringList("Freeze.commands"); } + + public static boolean freezeChat() { + return ConfigLoader.getConfig().getConfig().getBoolean("Freeze.freezeChat"); + } + + public static long freezeTimer() { + String value = ConfigLoader.getConfig().getConfig().getString("Freeze.freezeTimer"); + if (value == null) return -1; + if (value.equals("false")) return -1; + + return NumberUtils.parseToMilis(value); + } } public static class Addons { diff --git a/MAStaff-API/src/main/java/es/angelillo15/mast/api/config/bukkit/Messages.java b/MAStaff-API/src/main/java/es/angelillo15/mast/api/config/bukkit/Messages.java index 40be39a2..fc7f9641 100644 --- a/MAStaff-API/src/main/java/es/angelillo15/mast/api/config/bukkit/Messages.java +++ b/MAStaff-API/src/main/java/es/angelillo15/mast/api/config/bukkit/Messages.java @@ -143,6 +143,22 @@ public static String GET_FREEZE_CANNOT_FREEZE_THAT_PLAYER_MESSAGE() { return TextUtils.parseBukkitMessage(messages.getString("Freeze.freezeBypassMessage")); } + public static String FREEZE_CHAT_FORMAT() { + return TextUtils.parseBukkitMessage(messages.getString("Freeze.freezeChatFormat")); + } + + public static String FREEZE_STAFF_CHAT_FORMAT() { + return TextUtils.parseBukkitMessage(messages.getString("Freeze.freezeStaffChatFormat")); + } + + public static String FREEZE_CHAT_USAGE() { + return TextUtils.parseBukkitMessage(messages.getString("Freeze.freezeChatUsage")); + } + + public static String FREEZE_CHAT_NOT_FROZEN() { + return TextUtils.parseBukkitMessage(messages.getString("Freeze.freezeChatNotFrozen")); + } + public static class StaffVault { public static String itemSaved() { return TextUtils.parseBukkitMessage(messages.getString("StaffVault.itemSaved")); diff --git a/MAStaff-API/src/main/java/es/angelillo15/mast/api/managers/freeze/FreezeManager.java b/MAStaff-API/src/main/java/es/angelillo15/mast/api/managers/freeze/FreezeManager.java index ad50ed66..44c86dfd 100644 --- a/MAStaff-API/src/main/java/es/angelillo15/mast/api/managers/freeze/FreezeManager.java +++ b/MAStaff-API/src/main/java/es/angelillo15/mast/api/managers/freeze/FreezeManager.java @@ -1,13 +1,20 @@ package es.angelillo15.mast.api.managers.freeze; +import com.google.inject.Inject; +import com.nookure.mast.api.manager.FreezeVector; import es.angelillo15.mast.api.IStaffPlayer; import java.util.ArrayList; -import java.util.HashMap; import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; +/** + * This class is deprecated, use {@link com.nookure.mast.api.manager.FreezeManager} instead + * @since 3.0.0 + */ +@Deprecated public class FreezeManager { - public static HashMap frozenPlayers = new HashMap<>(); + @Inject + private static com.nookure.mast.api.manager.FreezeManager freezeManager; /** * Freeze the player @@ -15,7 +22,17 @@ public class FreezeManager { * @param target Player to freeze */ public static void freezePlayer(IStaffPlayer staff, Player target) { - frozenPlayers.put(target.getName(), new FreezeVector(staff, target)); + freezeManager.freezePlayer(staff, target, -1); + } + + /** + * Freeze the player + * @param staff IStaffPlayer who freeze the player + * @param target Player to freeze + * @param time Time to freeze the player (in ms) + */ + public static void freezePlayer(IStaffPlayer staff, Player target, long time) { + freezeManager.freezePlayer(staff, target, time); } /** @@ -23,7 +40,7 @@ public static void freezePlayer(IStaffPlayer staff, Player target) { * @param target Player */ public static void unfreezePlayer(Player target) { - frozenPlayers.remove(target.getName()); + freezeManager.unfreezePlayer(target); } /** @@ -31,7 +48,7 @@ public static void unfreezePlayer(Player target) { * @param target Player */ public static void unfreezePlayer(String target) { - frozenPlayers.remove(target); + freezeManager.unfreezePlayer(target); } /** @@ -40,7 +57,7 @@ public static void unfreezePlayer(String target) { * @return boolean */ public static boolean isFrozen(Player target) { - return frozenPlayers.containsKey(target.getName()); + return freezeManager.isFrozen(target); } /** @@ -49,7 +66,7 @@ public static boolean isFrozen(Player target) { * @return boolean */ public static boolean isFrozen(String target) { - return frozenPlayers.containsKey(target); + return freezeManager.isFrozen(target); } /** @@ -57,12 +74,10 @@ public static boolean isFrozen(String target) { * @return ArrayList of OfflinePlayer */ public static ArrayList getFrozenPlayers() { - ArrayList frozen = new ArrayList<>(); - frozenPlayers.forEach((name, vector) -> frozen.add(vector.getTarget())); - return frozen; + return freezeManager.getFrozenPlayers(); } public static FreezeVector getFreezeVector(Player target) { - return frozenPlayers.get(target.getName()); + return freezeManager.getFreezeVector(target); } } diff --git a/MAStaff-API/src/main/java/es/angelillo15/mast/api/managers/freeze/FreezeVector.java b/MAStaff-API/src/main/java/es/angelillo15/mast/api/managers/freeze/FreezeVector.java deleted file mode 100644 index 52f64860..00000000 --- a/MAStaff-API/src/main/java/es/angelillo15/mast/api/managers/freeze/FreezeVector.java +++ /dev/null @@ -1,13 +0,0 @@ -package es.angelillo15.mast.api.managers.freeze; - -import es.angelillo15.mast.api.IStaffPlayer; -import lombok.AllArgsConstructor; -import lombok.Data; -import org.bukkit.OfflinePlayer; - -@Data -@AllArgsConstructor -public class FreezeVector { - IStaffPlayer staffPlayer; - OfflinePlayer target; -} diff --git a/MAStaff-API/src/main/java/es/angelillo15/mast/api/nms/VersionSupport.kt b/MAStaff-API/src/main/java/es/angelillo15/mast/api/nms/VersionSupport.kt index 54c6e766..71c2ff3f 100644 --- a/MAStaff-API/src/main/java/es/angelillo15/mast/api/nms/VersionSupport.kt +++ b/MAStaff-API/src/main/java/es/angelillo15/mast/api/nms/VersionSupport.kt @@ -1,5 +1,6 @@ package es.angelillo15.mast.api.nms +import net.kyori.adventure.text.Component import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack @@ -32,4 +33,11 @@ abstract class VersionSupport { * @param key The key to remove. */ abstract fun removeTag(item: ItemStack, key: String): ItemStack + + /** + * Send an action bar message to a player. + * @param player The player to send the action bar message to. + * @param message The message to send. + */ + abstract fun sendActionBar(player: Player, message: Component) } \ No newline at end of file diff --git a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/MAStaff.java b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/MAStaff.java index 4ddd1160..15a0e041 100644 --- a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/MAStaff.java +++ b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/MAStaff.java @@ -18,12 +18,14 @@ import es.angelillo15.mast.api.managers.LegacyStaffPlayersManagers; import es.angelillo15.mast.api.managers.LegacyUserDataManager; import es.angelillo15.mast.api.managers.StaffManager; +import es.angelillo15.mast.api.managers.freeze.FreezeManager; import es.angelillo15.mast.api.nms.VersionSupport; import es.angelillo15.mast.api.thread.AsyncThreadKt; import es.angelillo15.mast.api.utils.BukkitUtils; import es.angelillo15.mast.api.utils.PermsUtils; import es.angelillo15.mast.bukkit.addons.AddonsLoader; import es.angelillo15.mast.bukkit.cmd.FreezeCMD; +import es.angelillo15.mast.bukkit.cmd.FreezeChat; import es.angelillo15.mast.bukkit.cmd.VanishCMD; import es.angelillo15.mast.bukkit.cmd.mast.MASTParent; import es.angelillo15.mast.bukkit.cmd.staff.StaffParent; @@ -33,7 +35,9 @@ import es.angelillo15.mast.bukkit.legacy.BukkitLegacyLoader; import es.angelillo15.mast.bukkit.listener.OnAddonDisable; import es.angelillo15.mast.bukkit.listener.CommandManagerHandler; -import es.angelillo15.mast.bukkit.listener.FreezeListener; +import es.angelillo15.mast.bukkit.listener.freeze.FreezeChatPaperListener; +import es.angelillo15.mast.bukkit.listener.freeze.FreezeLegacyPaperListener; +import es.angelillo15.mast.bukkit.listener.freeze.FreezeListener; import es.angelillo15.mast.bukkit.listener.OnJoin; import es.angelillo15.mast.bukkit.listener.clickListeners.OnItemClick; import es.angelillo15.mast.bukkit.listener.clickListeners.OnItemClickInteract; @@ -45,7 +49,8 @@ import es.angelillo15.mast.bukkit.loaders.GlowLoader; import es.angelillo15.mast.bukkit.loaders.LegacyItemsLoader; import es.angelillo15.mast.bukkit.loaders.PunishmentGUILoader; -import es.angelillo15.mast.bukkit.utils.FreezeUtils; +import es.angelillo15.mast.bukkit.task.FreezeSpamTask; +import es.angelillo15.mast.bukkit.task.FreezeTimerTask; import es.angelillo15.mast.bukkit.utils.Logger; import es.angelillo15.mast.bukkit.utils.Metrics; import es.angelillo15.mast.bukkit.utils.NMSUtils; @@ -151,6 +156,8 @@ public void registerCommands() { registerCommand(injector.getInstance(VanishCMD.class)); if (Config.Freeze.enabled()) Objects.requireNonNull(getCommand("freeze")).setExecutor(injector.getInstance(FreezeCMD.class)); + if (Config.Freeze.enabled() && Config.Freeze.freezeChat()) + registerCommand(injector.getInstance(FreezeChat.class)); } @Override @@ -184,7 +191,22 @@ public void registerListeners() { registerListener(injector.getInstance(OnStaffLegacyTalk.class)); } - FreezeUtils.setupMessageSender(); + if (Config.Freeze.enabled() && Config.Freeze.freezeChat()) { + if (version >= 16 && PaperLib.isPaper()) { + registerListener(injector.getInstance(FreezeChatPaperListener.class)); + } else { + registerListener(injector.getInstance(FreezeLegacyPaperListener.class)); + } + } + + if (Config.Freeze.enabled() && Config.Freeze.freezeTimer() > 0) { + Bukkit.getScheduler().runTaskTimerAsynchronously(this, injector.getInstance(FreezeTimerTask.class), 0, 20); + } + + if (Config.Freeze.enabled()) { + Bukkit.getScheduler().runTaskTimerAsynchronously(this, injector.getInstance(FreezeSpamTask.class), 0, 20 * 5); + } + this.getServer().getMessenger().registerOutgoingPluginChannel(this, "mastaff:staff"); this.getServer().getMessenger().registerOutgoingPluginChannel(this, "mastaff:commands"); } @@ -375,12 +397,13 @@ public void checkUpdates() { logger.warn(TextUtils.colorize("You are using a development version!")); } - @SuppressWarnings("Deprecated") + @SuppressWarnings({"Deprecated", "deprecation"}) public void inject() { getPLogger().debug("Injecting..."); injector = Guice.createInjector(new BukkitInjector()); StaticMembersInjector.injectStatics(injector, LegacyStaffPlayersManagers.class); StaticMembersInjector.injectStatics(injector, LegacyUserDataManager.class); + StaticMembersInjector.injectStatics(injector, FreezeManager.class); } public void registerPlaceholderAPI() { diff --git a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/StaffPlayer.java b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/StaffPlayer.java index 95174c09..037f29e8 100644 --- a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/StaffPlayer.java +++ b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/StaffPlayer.java @@ -22,7 +22,7 @@ import es.angelillo15.mast.api.event.bukkit.staff.StaffEnableEvent; import es.angelillo15.mast.api.items.StaffItem; import es.angelillo15.mast.api.managers.ItemsManager; -import es.angelillo15.mast.api.managers.freeze.FreezeManager; +import com.nookure.mast.api.manager.FreezeManager; import es.angelillo15.mast.api.nms.VersionSupport; import es.angelillo15.mast.api.player.IGlowPlayer; import es.angelillo15.mast.api.player.IVanishPlayer; @@ -64,6 +64,8 @@ public class StaffPlayer implements IStaffPlayer { private StaffFeatureManager featureManager; @Inject private EventManager eventManager; + @Inject + private FreezeManager freezeManager; private final Map items = new HashMap<>(); @Getter @@ -427,7 +429,9 @@ public void openStaffVault() { @Override public void freezePlayer(Player player) { - FreezeManager.freezePlayer(this, player); + long timer = Config.Freeze.freezeTimer(); + freezeManager.freezePlayer(this, player, timer > 0 ? System.currentTimeMillis() + timer : -1); + TextUtils.sendMessage(player, Messages.GET_FREEZE_FROZEN_MESSAGE()); StaffUtils.asyncStaffBroadcastMessage( @@ -441,7 +445,7 @@ public void freezePlayer(Player player) { @Override public void unfreezePlayer(String player) { - FreezeManager.unfreezePlayer(player); + freezeManager.unfreezePlayer(player); StaffUtils.asyncStaffBroadcastMessage( Messages.GET_FREEZE_UNFROZEN_BY_MESSAGE() @@ -472,7 +476,7 @@ public void executeFreezedPunishments(String player) { punishment.replace("{player}", player).replace("{staff}", this.player.getName())); }); - FreezeManager.unfreezePlayer(player); + freezeManager.unfreezePlayer(player); } @Override @@ -503,7 +507,7 @@ public void sendQuitCommands() { @Override public boolean isFreezed(Player player) { - return FreezeManager.isFrozen(player); + return freezeManager.isFrozen(player); } @Override diff --git a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/cmd/FreezeCMD.java b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/cmd/FreezeCMD.java index e47fed03..43bdcd8f 100644 --- a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/cmd/FreezeCMD.java +++ b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/cmd/FreezeCMD.java @@ -5,7 +5,7 @@ import es.angelillo15.mast.api.TextUtils; import es.angelillo15.mast.api.config.bukkit.Messages; import es.angelillo15.mast.api.managers.StaffManager; -import es.angelillo15.mast.api.managers.freeze.FreezeManager; +import com.nookure.mast.api.manager.FreezeManager; import es.angelillo15.mast.bukkit.gui.SelectTargetGUI; import java.util.Objects; import org.bukkit.Bukkit; @@ -17,17 +17,19 @@ public class FreezeCMD implements CommandExecutor { @Inject private StaffManager staffManager; + @Inject + private FreezeManager freezeManager; @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) return false; - - Player p = (Player) sender; + if(!(sender instanceof Player p)) return false; if (!staffManager.isStaffPlayer(p.getName())) return false; IStaffPlayer staff = staffManager.getStaffPlayer(p.getName()); + assert staff != null; + if(!p.hasPermission("mast.freeze")){ TextUtils.colorize(Messages.GET_NO_PERMISSION_MESSAGE(), p); return true; @@ -42,13 +44,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St } if (args[0].equalsIgnoreCase("/remove")) { - if (FreezeManager.isFrozen(args[1])) + if (freezeManager.isFrozen(args[1])) staff.unfreezePlayer(args[1]); return true; } if (args[0].equalsIgnoreCase("/exec")) { - if (FreezeManager.isFrozen(args[1])) + if (freezeManager.isFrozen(args[1])) staff.executeFreezedPunishments(args[1]); return true; } diff --git a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/cmd/FreezeChat.java b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/cmd/FreezeChat.java new file mode 100644 index 00000000..d419a894 --- /dev/null +++ b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/cmd/FreezeChat.java @@ -0,0 +1,69 @@ +package es.angelillo15.mast.bukkit.cmd; + +import com.google.inject.Inject; +import com.nookure.mast.api.cmd.CommandData; +import com.nookure.mast.api.cmd.StaffCommand; +import com.nookure.mast.api.cmd.sender.CommandSender; +import com.nookure.mast.api.manager.FreezeManager; +import es.angelillo15.mast.api.IServerUtils; +import es.angelillo15.mast.api.IStaffPlayer; +import es.angelillo15.mast.api.config.bukkit.Messages; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +@CommandData( + name = "freeze-chat", + aliases = {"freezec"}, + permission = "mast.freeze" +) +public class FreezeChat extends StaffCommand { + @Inject + private FreezeManager freezeManager; + @Inject + private IServerUtils serverUtils; + + @Override + public void onStaffCommand(@NotNull IStaffPlayer sender, @NotNull String label, @NotNull String @NotNull [] args) { + if (args.length < 2) { + sender.sendMessage(Messages.FREEZE_CHAT_USAGE()); + } + + Player target = Bukkit.getPlayer(args[0]); + + if (target == null) { + sender.sendMessage(Messages.GET_NO_PLAYER_FOUND_MESSAGE()); + return; + } + + if (!freezeManager.isFrozen(target)) { + sender.sendMessage(Messages.FREEZE_CHAT_NOT_FROZEN()); + return; + } + + String message = String.join(" ", args) + .replaceFirst(args[0], "") + .replaceFirst(" ", ""); + + String finalMessage = Messages.FREEZE_STAFF_CHAT_FORMAT() + .replace("{player}", target.getName()) + .replace("{message}", message); + + serverUtils.broadcastMessage(finalMessage, "mast.freeze"); + + if (target.hasPermission("mast.freeze")) { + return; + } + + target.sendMessage(finalMessage); + } + + @NotNull + @Override + public List onTabComplete(@NotNull CommandSender sender, @NotNull String @NotNull [] args) { + return freezeManager.getFrozenPlayers().stream().map(OfflinePlayer::getName).toList(); + } +} diff --git a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/inject/BukkitInjector.java b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/inject/BukkitInjector.java index 2bdc0d22..00f4c93f 100644 --- a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/inject/BukkitInjector.java +++ b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/inject/BukkitInjector.java @@ -2,6 +2,7 @@ import com.nookure.mast.addon.ServerAddonManager; import com.nookure.mast.api.addons.AddonManager; +import com.nookure.mast.api.manager.FreezeManager; import com.nookure.mast.api.staff.StaffFeatureManager; import es.angelillo15.mast.api.IServerUtils; import com.nookure.mast.api.manager.cmd.CommandBukkitSenderManager; @@ -31,5 +32,6 @@ protected void configure() { bind(CommandBukkitSenderManager.class).asEagerSingleton(); bind(AddonManager.class).to(ServerAddonManager.class).asEagerSingleton(); bind(StaffFeatureManager.class).to(BukkitStaffFeatureManager.class).asEagerSingleton(); + bind(FreezeManager.class).asEagerSingleton(); } } diff --git a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/listener/freeze/FreezeChatPaperListener.java b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/listener/freeze/FreezeChatPaperListener.java new file mode 100644 index 00000000..b344de6d --- /dev/null +++ b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/listener/freeze/FreezeChatPaperListener.java @@ -0,0 +1,13 @@ +package es.angelillo15.mast.bukkit.listener.freeze; + +import com.nookure.mast.api.event.BukkitListener; +import io.papermc.paper.event.player.AsyncChatEvent; +import org.bukkit.event.EventHandler; + +public class FreezeChatPaperListener extends FreezeCommonChatListener implements BukkitListener { + @Override + @EventHandler + public void handle(AsyncChatEvent event) { + if (handleMessage(event.getPlayer(), event.message())) event.setCancelled(true); + } +} diff --git a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/listener/freeze/FreezeCommonChatListener.java b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/listener/freeze/FreezeCommonChatListener.java new file mode 100644 index 00000000..2c5dcd11 --- /dev/null +++ b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/listener/freeze/FreezeCommonChatListener.java @@ -0,0 +1,37 @@ +package es.angelillo15.mast.bukkit.listener.freeze; + +import com.google.inject.Inject; +import com.nookure.mast.api.manager.FreezeManager; +import es.angelillo15.mast.api.IServerUtils; +import es.angelillo15.mast.api.config.bukkit.Messages; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.bukkit.entity.Player; + +public abstract class FreezeCommonChatListener { + @Inject + private IServerUtils serverUtils; + + @Inject + private FreezeManager freezeManager; + + public boolean handleMessage(Player player, String message) { + if (!freezeManager.isFrozen(player)) { + return false; + } + + String formattedMessage = Messages.FREEZE_CHAT_FORMAT() + .replace("{player}", player.getName()) + .replace("{message}", message); + + serverUtils.broadcastMessage(formattedMessage, "mast.freeze"); + player.sendMessage(formattedMessage); + + freezeManager.getFreezeVector(player).setHasTalked(true); + return true; + } + + public boolean handleMessage(Player player, Component cmp) { + return handleMessage(player, LegacyComponentSerializer.legacySection().serialize(cmp)); + } +} diff --git a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/listener/freeze/FreezeLegacyPaperListener.java b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/listener/freeze/FreezeLegacyPaperListener.java new file mode 100644 index 00000000..ccefca47 --- /dev/null +++ b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/listener/freeze/FreezeLegacyPaperListener.java @@ -0,0 +1,14 @@ +package es.angelillo15.mast.bukkit.listener.freeze; + +import com.nookure.mast.api.event.BukkitListener; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.AsyncPlayerChatEvent; + +@SuppressWarnings("deprecation") +public class FreezeLegacyPaperListener extends FreezeCommonChatListener implements BukkitListener { + @Override + @EventHandler + public void handle(AsyncPlayerChatEvent event) { + if (handleMessage(event.getPlayer(), event.getMessage())) event.setCancelled(true); + } +} diff --git a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/listener/FreezeListener.java b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/listener/freeze/FreezeListener.java similarity index 69% rename from MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/listener/FreezeListener.java rename to MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/listener/freeze/FreezeListener.java index 909241da..ea712589 100644 --- a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/listener/FreezeListener.java +++ b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/listener/freeze/FreezeListener.java @@ -1,12 +1,13 @@ -package es.angelillo15.mast.bukkit.listener; +package es.angelillo15.mast.bukkit.listener.freeze; +import com.google.inject.Inject; import es.angelillo15.mast.api.IStaffPlayer; import es.angelillo15.mast.api.TextUtils; import es.angelillo15.mast.api.config.bukkit.Config; import es.angelillo15.mast.api.config.bukkit.Messages; import es.angelillo15.mast.api.event.bukkit.freeze.FreezeMessageEvent; -import es.angelillo15.mast.api.managers.freeze.FreezeManager; -import es.angelillo15.mast.api.managers.freeze.FreezeVector; +import com.nookure.mast.api.manager.FreezeManager; +import com.nookure.mast.api.manager.FreezeVector; import es.angelillo15.mast.bukkit.MAStaff; import io.papermc.lib.PaperLib; import org.bukkit.Location; @@ -18,9 +19,12 @@ import org.bukkit.event.player.PlayerQuitEvent; public class FreezeListener implements Listener { + @Inject + private FreezeManager freezeManager; + @EventHandler public void onFreezeEvent(PlayerMoveEvent event) { - if (FreezeManager.isFrozen(event.getPlayer())) { + if (freezeManager.isFrozen(event.getPlayer())) { if (event.getFrom().getX() != event.getTo().getX() || event.getFrom().getY() != event.getTo().getY() || event.getFrom().getZ() != event.getTo().getZ()) { @@ -31,22 +35,9 @@ public void onFreezeEvent(PlayerMoveEvent event) { } } - @EventHandler - public void onFreezeMessage(FreezeMessageEvent e) { - Player player = e.getPlayer(); - if (player == null || !player.isOnline()) { - return; - } - - for (String message : Messages.spamMessage()) { - if (message == null) continue; - TextUtils.colorize(message, player); - } - } - @EventHandler public void onInteract(PlayerInteractEvent event) { - if (FreezeManager.isFrozen(event.getPlayer())) { + if (freezeManager.isFrozen(event.getPlayer())) { event.setCancelled(true); } } @@ -54,16 +45,16 @@ public void onInteract(PlayerInteractEvent event) { @EventHandler public void freezedPlayerExit(PlayerQuitEvent event) { if (!Config.Freeze.executeCommandOnExit()) { - FreezeManager.unfreezePlayer(event.getPlayer()); + freezeManager.unfreezePlayer(event.getPlayer()); return; } - if (!FreezeManager.isFrozen(event.getPlayer())) return; + if (!freezeManager.isFrozen(event.getPlayer())) return; if (MAStaff.isFree()) return; Player player = event.getPlayer(); - FreezeVector vector = FreezeManager.getFreezeVector(player); + FreezeVector vector = freezeManager.getFreezeVector(player); if (vector == null) return; @@ -72,7 +63,7 @@ public void freezedPlayerExit(PlayerQuitEvent event) { if (staffPlayer == null) return; if (!Config.Freeze.askToExecuteCommands()) { - FreezeManager.unfreezePlayer(player); + freezeManager.unfreezePlayer(player); staffPlayer.executeFreezedPunishments(player.getName()); diff --git a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/task/FreezeSpamTask.java b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/task/FreezeSpamTask.java new file mode 100644 index 00000000..f259064b --- /dev/null +++ b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/task/FreezeSpamTask.java @@ -0,0 +1,33 @@ +package es.angelillo15.mast.bukkit.task; + +import com.google.inject.Inject; +import com.nookure.mast.api.manager.FreezeManager; +import es.angelillo15.mast.api.TextUtils; +import es.angelillo15.mast.api.config.bukkit.Messages; +import org.bukkit.entity.Player; + +public class FreezeSpamTask implements Runnable { + @Inject + private FreezeManager freezeManager; + + @Override + public void run() { + freezeManager.getFreezeVectors().forEach(player -> { + if (player.hasTalked()) return; + + Messages.spamMessage().forEach(message -> { + if (message == null) return; + + message = message.replace( + "{time}", + player.getTimeLeft() == -1 ? "∞" : TextUtils.formatUptime(player.getTimeLeft() - System.currentTimeMillis()) + ); + + if (player.getTarget() instanceof Player bp) { + TextUtils.colorize(message, bp); + } + }); + + }); + } +} diff --git a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/task/FreezeTimerTask.java b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/task/FreezeTimerTask.java new file mode 100644 index 00000000..ba5e1fa2 --- /dev/null +++ b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/task/FreezeTimerTask.java @@ -0,0 +1,46 @@ +package es.angelillo15.mast.bukkit.task; + +import com.google.inject.Inject; +import com.nookure.mast.api.manager.FreezeManager; +import es.angelillo15.mast.api.TextUtils; +import es.angelillo15.mast.api.config.bukkit.Messages; +import es.angelillo15.mast.api.nms.VersionSupport; +import es.angelillo15.mast.bukkit.MAStaff; +import net.kyori.adventure.text.Component; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class FreezeTimerTask implements Runnable { + @Inject + private FreezeManager freezeManager; + @Inject + private VersionSupport versionSupport; + + @Override + public void run() { + freezeManager.getFreezeVectors().forEach(player -> { + if (player.getTimeLeft() != -1 && player.getTimeLeft() < System.currentTimeMillis()) { + if (player instanceof Player bp) { + freezeManager.unfreezePlayer(bp); + } + + Bukkit.getScheduler().runTaskLater(MAStaff.getPlugin(), () -> { + if (player.getTimeLeft() == -2) return; + + player.getStaffPlayer().executeFreezedPunishments(player.getTarget().getName()); + player.setTimeLeft(-2); + }, 1L); + } + + if (player.getTimeLeft() != -1 && player.getTarget() instanceof Player bp) { + if (MAStaff.isFree()) return; + + Component cmp = TextUtils.toComponent( + "" + TextUtils.formatUptime(player.getTimeLeft() - System.currentTimeMillis()) + ); + + versionSupport.sendActionBar(bp, cmp); + } + }); + } +} diff --git a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/utils/FreezeUtils.java b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/utils/FreezeUtils.java deleted file mode 100644 index 88fb51b1..00000000 --- a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/utils/FreezeUtils.java +++ /dev/null @@ -1,24 +0,0 @@ -package es.angelillo15.mast.bukkit.utils; - -import es.angelillo15.mast.api.event.bukkit.freeze.FreezeMessageEvent; -import es.angelillo15.mast.api.managers.freeze.FreezeManager; -import es.angelillo15.mast.bukkit.utils.scheduler.Scheduler; -import org.bukkit.Bukkit; - -public class FreezeUtils { - public static void setupMessageSender() { - Scheduler.executeTimerAsync( - () -> { - FreezeManager.getFrozenPlayers() - .forEach( - player -> { - if (player.isOnline()) { - Bukkit.getPluginManager() - .callEvent(new FreezeMessageEvent(player.getPlayer())); - } - }); - }, - 0, - 20 * 5); - } -} diff --git a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/utils/NMSUtils.java b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/utils/NMSUtils.java index 1d10063a..82b493f3 100644 --- a/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/utils/NMSUtils.java +++ b/MAStaff-Bukkit/src/main/java/es/angelillo15/mast/bukkit/utils/NMSUtils.java @@ -1,7 +1,7 @@ package es.angelillo15.mast.bukkit.utils; import es.angelillo15.bukkit.nms.V1_12_2_R0; -import es.angelillo15.bukkit.nms.V1_8_8_R0; +import es.angelillo15.mast.bukkit.nms.V1_8_8_R0; import es.angelillo15.mast.bukkit.MAStaff; import es.angelillo15.mast.api.nms.VersionSupport; import es.angelillo15.mast.bukkit.nms.*; diff --git a/MAStaff-Bukkit/src/main/resources/Bukkit/config.yml b/MAStaff-Bukkit/src/main/resources/Bukkit/config.yml index de720873..5373e531 100644 --- a/MAStaff-Bukkit/src/main/resources/Bukkit/config.yml +++ b/MAStaff-Bukkit/src/main/resources/Bukkit/config.yml @@ -100,6 +100,14 @@ Freeze: # If you want the command to be executed as bungee console, add a "bungee:" prefix. commands: - "ban {player} &cYou have been perm-banned for leaving the server while you were frozen." + # Enable or disable the freeze chat. + # This is only available for MAStaff Premium version + freezeChat: true + # Freeze timer + # This is only available for MAStaff Premium version + # The value is with the following format: 1h 1m 1s + # Set false to disable the freeze timer. + freezeTimer: 3m # # Database configuration for the plugin. With the Bungee version, you must use MariaDB or MySQL. # diff --git a/MAStaff-Bukkit/src/main/resources/Bukkit/lang/english.yml b/MAStaff-Bukkit/src/main/resources/Bukkit/lang/english.yml index 0dce3f4a..74236ecf 100644 --- a/MAStaff-Bukkit/src/main/resources/Bukkit/lang/english.yml +++ b/MAStaff-Bukkit/src/main/resources/Bukkit/lang/english.yml @@ -48,17 +48,17 @@ StaffMode: nightVisionOff: '{prefix} &7You have &adisabled &7the night vision.' Freeze: # Message sent when the command is not used correctly. - correctUse: '{prefix} &7You must use &a/freeze &7.' + correctUse: '&3&lFreeze &8&l» &r&7You must use &a/freeze &7.' # Message sent when the command is not used correctly. - correctUseOther: '{prefix} &7You must use &a/freeze &7.' + correctUseOther: '&3&lFreeze &8&l» &r&7You must use &a/freeze &7.' # Message sent when the player is frozen. - frozen: '{prefix} &7You have been &afrozen&7.' + frozen: '&3&lFreeze &8&l» &r&7You have been &afrozen&7.' # Message sent when the player is unfrozen. - unfrozen: '{prefix} &7You have been &aunfrozen&7.' + unfrozen: '&3&lFreeze &8&l» &r&7You have been &aunfrozen&7.' # Message sent when the player is unfrozen by a staff. - unfrozenBy: '{prefix} &7The player &a{player} &7has been &aunfrozen &7by &a{staff}&7.' + unfrozenBy: '&3&lFreeze &8&l» &r&7The player &a{player} &7has been &aunfrozen &7by &a{staff}&7.' # Message sent when the player is frozen by a staff. - frozenByOther: '{prefix} &7The player &a{player} &7has been &afrozen &7by &a{staff}&7.' + frozenByOther: '&3&lFreeze &8&l» &r&7The player &a{player} &7has been &afrozen &7by &a{staff}&7.' # Message sent to the player chat when he is frozen. playerSpamMessage: - '' @@ -68,7 +68,7 @@ Freeze: - '&7██&c█&6█&0█&6█&c█&7██ You have been frozen!' - '&7█&c█&6██&0█&6██&c█&7█ Join our discord server:' - '&7█&c█&6█████&c█&7█ http:/discord.example.com' - - '&c█&6███&0█&6███&c█' + - '&c█&6███&0█&6███&c█ You have {time} to join.' - '&c█████████' - '' # Message sent to the staff if he wants to punish the player. @@ -78,7 +78,15 @@ Freeze: Do you want to execute the commands specified when a player leaves ? [x] [✔] # Message sent when a staff tries to freeze a player with mast.freeze.bypass permission. - freezeBypassMessage: '{prefix} &7You can not freeze that player.' + freezeBypassMessage: '&3&lFreeze &8&l» &r&7You can not freeze that player.' + # Chat format for frozen players. + freezeChatFormat: '&r{player} &7(&3frozen&7) &8&l» &r&7{message}' + # Chat format for staff members that are talking to frozen players. + freezeStaffChatFormat: '&r{player} &7(&astaff&7) &8&l» &r&7{message}' + # FreezeChat command usage. + freezeChatUsage: '&3&lFreeze &8&l» &r&7You must use &a/freezechat &7.' + # Freeze Chat when a player isn't frozen and you try to use it. + freezeChatNotFrozen: '&3&lFreeze &8&l» &r&7That player is not frozen.' StaffList: # Title of the Staff List GUI. title: '&a&lSTAFF &8&l» &7Online Staff' diff --git a/MAStaff-Bukkit/src/main/resources/Bukkit/lang/spanish.yml b/MAStaff-Bukkit/src/main/resources/Bukkit/lang/spanish.yml index a599b820..05ba7c4f 100644 --- a/MAStaff-Bukkit/src/main/resources/Bukkit/lang/spanish.yml +++ b/MAStaff-Bukkit/src/main/resources/Bukkit/lang/spanish.yml @@ -48,17 +48,17 @@ StaffMode: nightVisionOff: '{prefix} &7Has desactivado la &bvisión nocturna&7.' Freeze: # Mensaje enviado cuando el comando no se utiliza correctamente. - correctUse: '{prefix} &7Debes de usar &a/freeze &7.' + correctUse: '&3&lFreeze &8&l» &7Debes de usar &a/freeze &7.' # Mensaje enviado cuando el comando no se utiliza correctamente. - correctUseOther: '{prefix} &7Debes de usar &a/freeze &7.' + correctUseOther: '&3&lFreeze &8&l» &7Debes de usar &a/freeze &7.' # Mensaje enviado cuando el jugador es congelado. - frozen: '{prefix} &7Has sido &acongelado&7.' + frozen: '&3&lFreeze &8&l» &7Has sido &acongelado&7.' # Mensaje enviado cuando el jugador es descongelado. - unfrozen: '{prefix} &7Has sido &adescongelado&7.' + unfrozen: '&3&lFreeze &8&l» &7Has sido &adescongelado&7.' # Mensaje enviado cuando un jugador es descongelado por un staff. - unfrozenBy: '{prefix} &7El jugador &a{player} &7ha sido &adescongelado &7por &a{staff}&7.' + unfrozenBy: '&3&lFreeze &8&l» &7El jugador &a{player} &7ha sido &adescongelado &7por &a{staff}&7.' # Mensaje enviado cuando un jugador es congelado por un staff. - frozenByOther: '{prefix} &7El jugador &a{player} &7ha sido &afrozen &7por &a{staff}&7.' + frozenByOther: '&3&lFreeze &8&l» &7El jugador &a{player} &7ha sido &afrozen &7por &a{staff}&7.' # Mensaje enviado cuando un jugador es congelado por un staff. playerSpamMessage: - '' @@ -78,7 +78,15 @@ Freeze: ¿Quieres ejecutar los comandos especificados para cuando un jugador abandona estando congelado? [x] [✔] # Mensaje que se manda cuando un staff intenta congelar a uu jugador con el permiso mast.freeze.bypass - freezeBypassMessage: '{prefix} &7No puedes congelar a este jugador.' + freezeBypassMessage: '&3&lFreeze &8&l» &r&7No puedes congelar a ese jugador.' + # Formato de chat para los jugadores que estan conectados + freezeChatFormat: '&r{player} &7(&3congelado&7) &8&l» &r&7{message}' + # Formato de chat para los staffs que han congelado a un jugador + freezeStaffChatFormat: '&r{player} &7(&astaff&7) &8&l» &r&7{message}' + # FreezeChat uso de comando incorrecto + freezeChatUsage: '&3&lFreeze &8&l» &r&7Tienes que usar &a/freezechat &7.' + # Mensaje que se manda cuando un jugador intenta usar el comando /freezechat y el jugador no esta congelado + freezeChatNotFrozen: '&3&lFreeze &8&l» &r&7Ese jugador no esta congelado' StaffList: # El título de la lista de Staff. title: '&a&lSTAFF &8&l» &7Online Staff' diff --git a/MAStaff-NMS/NMS-1.12.2_R0/src/main/java/es/angelillo15/bukkit/nms/V1_12_2_R0.kt b/MAStaff-NMS/NMS-1.12.2_R0/src/main/java/es/angelillo15/bukkit/nms/V1_12_2_R0.kt index 22a54f86..a524e96b 100644 --- a/MAStaff-NMS/NMS-1.12.2_R0/src/main/java/es/angelillo15/bukkit/nms/V1_12_2_R0.kt +++ b/MAStaff-NMS/NMS-1.12.2_R0/src/main/java/es/angelillo15/bukkit/nms/V1_12_2_R0.kt @@ -2,6 +2,10 @@ package es.angelillo15.bukkit.nms import es.angelillo15.mast.api.nms.VersionSupport import es.angelillo15.mast.api.utils.MAStaffInject +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer +import net.md_5.bungee.api.ChatMessageType +import net.md_5.bungee.api.chat.TextComponent import net.minecraft.server.v1_12_R1.ItemStack import net.minecraft.server.v1_12_R1.NBTTagCompound import net.minecraft.server.v1_12_R1.NBTTagString @@ -83,4 +87,11 @@ class V1_12_2_R0(val instance: MAStaffInject) : VersionSupport() { private fun getCraftPlayer(player: Player): CraftPlayer { return player as CraftPlayer } + + override fun sendActionBar(player: Player, message: Component) { + player.spigot().sendMessage( + ChatMessageType.ACTION_BAR, + TextComponent.fromLegacyText(LegacyComponentSerializer.legacySection().serialize(message))[0] + ) + } } \ No newline at end of file diff --git a/MAStaff-NMS/NMS-1.16.5_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_16_5_R0.kt b/MAStaff-NMS/NMS-1.16.5_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_16_5_R0.kt index 905de378..56297d75 100644 --- a/MAStaff-NMS/NMS-1.16.5_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_16_5_R0.kt +++ b/MAStaff-NMS/NMS-1.16.5_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_16_5_R0.kt @@ -2,6 +2,10 @@ package es.angelillo15.mast.bukkit.nms import es.angelillo15.mast.api.nms.VersionSupport import es.angelillo15.mast.api.utils.MAStaffInject +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer +import net.md_5.bungee.api.ChatMessageType +import net.md_5.bungee.api.chat.TextComponent import net.minecraft.server.v1_16_R3.ItemStack import net.minecraft.server.v1_16_R3.NBTTagCompound import net.minecraft.server.v1_16_R3.NBTTagString @@ -18,9 +22,9 @@ class V1_16_5_R0(val instance: MAStaffInject) : VersionSupport() { } override fun setTag( - item: org.bukkit.inventory.ItemStack, - key: String, - value: String + item: org.bukkit.inventory.ItemStack, + key: String, + value: String ): org.bukkit.inventory.ItemStack { val nmsItemStack = getNmsItemCopy(item) val tag = nmsItemStack.tag ?: NBTTagCompound() @@ -48,7 +52,7 @@ class V1_16_5_R0(val instance: MAStaffInject) : VersionSupport() { private fun initializeTag(itemStack: org.bukkit.inventory.ItemStack): NBTTagCompound { val i = CraftItemStack.asNMSCopy(itemStack) - ?: throw RuntimeException("Cannot convert given item to a NMS item") + ?: throw RuntimeException("Cannot convert given item to a NMS item") return initializeTag(i) } @@ -84,4 +88,11 @@ class V1_16_5_R0(val instance: MAStaffInject) : VersionSupport() { private fun getCraftPlayer(player: Player): CraftPlayer { return player as CraftPlayer } + + override fun sendActionBar(player: Player, message: Component) { + player.spigot().sendMessage( + ChatMessageType.ACTION_BAR, + TextComponent.fromLegacyText(LegacyComponentSerializer.legacySection().serialize(message))[0] + ) + } } \ No newline at end of file diff --git a/MAStaff-NMS/NMS-1.17.1_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_17_1_R0.kt b/MAStaff-NMS/NMS-1.17.1_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_17_1_R0.kt index ff91a259..d4fb0548 100644 --- a/MAStaff-NMS/NMS-1.17.1_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_17_1_R0.kt +++ b/MAStaff-NMS/NMS-1.17.1_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_17_1_R0.kt @@ -2,6 +2,7 @@ package es.angelillo15.mast.bukkit.nms import es.angelillo15.mast.api.nms.VersionSupport import es.angelillo15.mast.api.utils.MAStaffInject +import net.kyori.adventure.text.Component import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.StringTag import net.minecraft.network.protocol.Packet @@ -90,4 +91,8 @@ class V1_17_1_R0(val instance: MAStaffInject) : VersionSupport() { private fun getCraftPlayer(player: Player): CraftPlayer { return player as CraftPlayer } + + override fun sendActionBar(player: Player, message: Component) { + player.sendActionBar(message) + } } \ No newline at end of file diff --git a/MAStaff-NMS/NMS-1.18.2_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_18_2_R0.kt b/MAStaff-NMS/NMS-1.18.2_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_18_2_R0.kt index 74be3074..edc84fcc 100644 --- a/MAStaff-NMS/NMS-1.18.2_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_18_2_R0.kt +++ b/MAStaff-NMS/NMS-1.18.2_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_18_2_R0.kt @@ -2,6 +2,7 @@ package es.angelillo15.mast.bukkit.nms import es.angelillo15.mast.api.nms.VersionSupport import es.angelillo15.mast.api.utils.MAStaffInject +import net.kyori.adventure.text.Component import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.StringTag import net.minecraft.network.protocol.Packet @@ -91,4 +92,8 @@ class V1_18_2_R0(val instance: MAStaffInject) : VersionSupport() { private fun getCraftPlayer(player: Player): CraftPlayer { return player as CraftPlayer } + + override fun sendActionBar(player: Player, message: Component) { + player.sendActionBar(message) + } } \ No newline at end of file diff --git a/MAStaff-NMS/NMS-1.19.4_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_19_4_R0.kt b/MAStaff-NMS/NMS-1.19.4_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_19_4_R0.kt index b3af7ded..2460856f 100644 --- a/MAStaff-NMS/NMS-1.19.4_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_19_4_R0.kt +++ b/MAStaff-NMS/NMS-1.19.4_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_19_4_R0.kt @@ -2,6 +2,7 @@ package es.angelillo15.mast.bukkit.nms import es.angelillo15.mast.api.nms.VersionSupport import es.angelillo15.mast.api.utils.MAStaffInject +import net.kyori.adventure.text.Component import net.minecraft.nbt.CompoundTag import net.minecraft.network.protocol.Packet import net.minecraft.world.item.ItemStack @@ -89,4 +90,8 @@ class V1_19_4_R0(val instance: MAStaffInject) : VersionSupport() { private fun getCraftPlayer(player: Player): CraftPlayer { return player as CraftPlayer } + + override fun sendActionBar(player: Player, message: Component) { + player.sendActionBar(message) + } } \ No newline at end of file diff --git a/MAStaff-NMS/NMS-1.20.1_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_20_1_R0.kt b/MAStaff-NMS/NMS-1.20.1_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_20_1_R0.kt index f64e4971..3b2dd9ca 100644 --- a/MAStaff-NMS/NMS-1.20.1_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_20_1_R0.kt +++ b/MAStaff-NMS/NMS-1.20.1_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_20_1_R0.kt @@ -2,6 +2,7 @@ package es.angelillo15.mast.bukkit.nms import es.angelillo15.mast.api.nms.VersionSupport import es.angelillo15.mast.api.utils.MAStaffInject +import net.kyori.adventure.text.Component import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.StringTag import net.minecraft.network.protocol.Packet @@ -91,4 +92,8 @@ class V1_20_1_R0(val instance: MAStaffInject) : VersionSupport() { private fun getCraftPlayer(player: Player): CraftPlayer { return player as CraftPlayer } + + override fun sendActionBar(player: Player, message: Component) { + player.sendActionBar(message) + } } \ No newline at end of file diff --git a/MAStaff-NMS/NMS-1.20.2_R0/src/main/java/com/nookure/mast/bukkit/nms/V1_20_2_R0.kt b/MAStaff-NMS/NMS-1.20.2_R0/src/main/java/com/nookure/mast/bukkit/nms/V1_20_2_R0.kt index 66d4ccf1..3b462b17 100644 --- a/MAStaff-NMS/NMS-1.20.2_R0/src/main/java/com/nookure/mast/bukkit/nms/V1_20_2_R0.kt +++ b/MAStaff-NMS/NMS-1.20.2_R0/src/main/java/com/nookure/mast/bukkit/nms/V1_20_2_R0.kt @@ -2,6 +2,7 @@ package com.nookure.mast.bukkit.nms import es.angelillo15.mast.api.nms.VersionSupport import es.angelillo15.mast.api.utils.MAStaffInject +import net.kyori.adventure.text.Component import net.minecraft.nbt.CompoundTag import net.minecraft.network.protocol.Packet import net.minecraft.world.item.ItemStack @@ -88,4 +89,8 @@ class V1_20_2_R0(val instance: MAStaffInject) : VersionSupport() { private fun getCraftPlayer(player: Player): CraftPlayer { return player as CraftPlayer } + + override fun sendActionBar(player: Player, message: Component) { + player.sendActionBar(message) + } } \ No newline at end of file diff --git a/MAStaff-NMS/NMS-1.8.8_R0/src/main/java/es/angelillo15/bukkit/nms/V1_8_8_R0.kt b/MAStaff-NMS/NMS-1.8.8_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_8_8_R0.kt similarity index 81% rename from MAStaff-NMS/NMS-1.8.8_R0/src/main/java/es/angelillo15/bukkit/nms/V1_8_8_R0.kt rename to MAStaff-NMS/NMS-1.8.8_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_8_8_R0.kt index 343b4301..e5b8dd72 100644 --- a/MAStaff-NMS/NMS-1.8.8_R0/src/main/java/es/angelillo15/bukkit/nms/V1_8_8_R0.kt +++ b/MAStaff-NMS/NMS-1.8.8_R0/src/main/java/es/angelillo15/mast/bukkit/nms/V1_8_8_R0.kt @@ -1,11 +1,17 @@ -package es.angelillo15.bukkit.nms +package es.angelillo15.mast.bukkit.nms import es.angelillo15.mast.api.nms.VersionSupport import es.angelillo15.mast.api.utils.MAStaffInject +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer +import net.md_5.bungee.api.ChatMessageType +import net.md_5.bungee.api.chat.TextComponent +import net.minecraft.server.v1_8_R3.IChatBaseComponent import net.minecraft.server.v1_8_R3.ItemStack import net.minecraft.server.v1_8_R3.NBTTagCompound import net.minecraft.server.v1_8_R3.NBTTagString import net.minecraft.server.v1_8_R3.Packet +import net.minecraft.server.v1_8_R3.PacketPlayOutChat import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack import org.bukkit.entity.Player @@ -84,4 +90,12 @@ class V1_8_8_R0(val instance: MAStaffInject) : VersionSupport() { return player as CraftPlayer } + override fun sendActionBar(player: Player, message: Component) { + val packet = PacketPlayOutChat( + IChatBaseComponent.ChatSerializer.a( + "{\"text\":\"" + LegacyComponentSerializer.legacySection().serialize(message) + "\"}" + ), 2.toByte() + ) + sendPacket(player, packet) + } } \ No newline at end of file diff --git a/MAStaff-NMS/build.gradle.kts b/MAStaff-NMS/build.gradle.kts index c438a46f..d3f200e5 100644 --- a/MAStaff-NMS/build.gradle.kts +++ b/MAStaff-NMS/build.gradle.kts @@ -11,6 +11,8 @@ subprojects { dependencies { compileOnly(project(":MAStaff-NMS")) compileOnly(project(":MAStaff-API")) + compileOnly(rootProject.libs.adventureApi) + compileOnly(rootProject.libs.adventureLegacy) } repositories {