9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2026-01-06 15:51:50 +00:00
Files
Custom-Fishing/src/main/java/net/momirealms/customfishing/util/AdventureUtil.java
2022-10-19 23:15:08 +08:00

81 lines
3.3 KiB
Java

/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.util;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.title.Title;
import net.momirealms.customfishing.CustomFishing;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.time.Duration;
public class AdventureUtil {
public static void sendMessage(CommandSender sender, String s) {
if (sender instanceof Player player) playerMessage(player, s);
else consoleMessage(s);
}
public static void consoleMessage(String s) {
Audience au = CustomFishing.adventure.sender(Bukkit.getConsoleSender());
MiniMessage mm = MiniMessage.miniMessage();
Component parsed = mm.deserialize(ItemStackUtil.replaceLegacy(s));
au.sendMessage(parsed);
}
public static void playerMessage(Player player, String s) {
Audience au = CustomFishing.adventure.player(player);
MiniMessage mm = MiniMessage.miniMessage();
Component parsed = mm.deserialize(ItemStackUtil.replaceLegacy(s));
au.sendMessage(parsed);
}
public static void playerTitle(Player player, String s1, String s2, int in, int duration, int out) {
Audience au = CustomFishing.adventure.player(player);
MiniMessage mm = MiniMessage.miniMessage();
Title.Times times = Title.Times.times(Duration.ofMillis(in), Duration.ofMillis(duration), Duration.ofMillis(out));
Title title = Title.title(mm.deserialize(ItemStackUtil.replaceLegacy(s1)), mm.deserialize(ItemStackUtil.replaceLegacy(s2)), times);
au.showTitle(title);
}
public static void playerTitle(Player player, Component s1, Component s2, int in, int duration, int out) {
Audience au = CustomFishing.adventure.player(player);
Title.Times times = Title.Times.times(Duration.ofMillis(in), Duration.ofMillis(duration), Duration.ofMillis(out));
Title title = Title.title(s1, s2, times);
au.showTitle(title);
}
public static void playerActionbar(Player player, String s) {
Audience au = CustomFishing.adventure.player(player);
MiniMessage mm = MiniMessage.miniMessage();
au.sendActionBar(mm.deserialize(ItemStackUtil.replaceLegacy(s)));
}
public static void playerSound(Player player, Sound.Source source, Key key, float volume, float pitch) {
Sound sound = Sound.sound(key, source, volume, pitch);
Audience au = CustomFishing.adventure.player(player);
au.playSound(sound);
}
}