mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 14:46:45 +01:00
Implement console messages
This commit is contained in:
parent
4d61a345c6
commit
078b776f60
@ -41,7 +41,6 @@ import com.plotsquared.bukkit.placeholder.Placeholders;
|
|||||||
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
import com.plotsquared.bukkit.player.BukkitPlayerManager;
|
||||||
import com.plotsquared.bukkit.queue.BukkitLocalQueue;
|
import com.plotsquared.bukkit.queue.BukkitLocalQueue;
|
||||||
import com.plotsquared.bukkit.schematic.BukkitSchematicHandler;
|
import com.plotsquared.bukkit.schematic.BukkitSchematicHandler;
|
||||||
import com.plotsquared.bukkit.util.BukkitChatManager;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitChunkManager;
|
import com.plotsquared.bukkit.util.BukkitChunkManager;
|
||||||
import com.plotsquared.bukkit.util.BukkitEconHandler;
|
import com.plotsquared.bukkit.util.BukkitEconHandler;
|
||||||
import com.plotsquared.bukkit.util.BukkitInventoryUtil;
|
import com.plotsquared.bukkit.util.BukkitInventoryUtil;
|
||||||
@ -81,7 +80,6 @@ import com.plotsquared.core.plot.PlotArea;
|
|||||||
import com.plotsquared.core.plot.PlotAreaTerrainType;
|
import com.plotsquared.core.plot.PlotAreaTerrainType;
|
||||||
import com.plotsquared.core.plot.PlotAreaType;
|
import com.plotsquared.core.plot.PlotAreaType;
|
||||||
import com.plotsquared.core.plot.PlotId;
|
import com.plotsquared.core.plot.PlotId;
|
||||||
import com.plotsquared.core.plot.message.PlainChatManager;
|
|
||||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||||
import com.plotsquared.core.plot.world.SinglePlotArea;
|
import com.plotsquared.core.plot.world.SinglePlotArea;
|
||||||
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
|
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
|
||||||
@ -112,6 +110,7 @@ import com.sk89q.worldedit.extension.platform.Actor;
|
|||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -1101,14 +1100,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
|||||||
return name.substring(name.lastIndexOf('.') + 1);
|
return name.substring(name.lastIndexOf('.') + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public ChatManager<?> initChatManager() {
|
|
||||||
if (Settings.Chat.INTERACTIVE) {
|
|
||||||
return new BukkitChatManager();
|
|
||||||
} else {
|
|
||||||
return new PlainChatManager();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public GeneratorWrapper<?> wrapPlotGenerator(@Nullable final String world,
|
@Override public GeneratorWrapper<?> wrapPlotGenerator(@Nullable final String world,
|
||||||
@NonNull final IndependentPlotGenerator generator) {
|
@NonNull final IndependentPlotGenerator generator) {
|
||||||
return new BukkitPlotGenerator(world, generator);
|
return new BukkitPlotGenerator(world, generator);
|
||||||
@ -1136,4 +1127,8 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
|
|||||||
return this.playerManager;
|
return this.playerManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override @NotNull public Audience getConsoleAudience() {
|
||||||
|
return BukkitUtil.BUKKIT_AUDIENCES.audience(Bukkit.getConsoleSender());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ package com.plotsquared.bukkit.player;
|
|||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.plotsquared.bukkit.BukkitMain;
|
|
||||||
import com.plotsquared.bukkit.util.BukkitUtil;
|
import com.plotsquared.bukkit.util.BukkitUtil;
|
||||||
import com.plotsquared.core.PlotSquared;
|
import com.plotsquared.core.PlotSquared;
|
||||||
import com.plotsquared.core.configuration.Caption;
|
import com.plotsquared.core.configuration.Caption;
|
||||||
@ -46,7 +45,6 @@ import com.sk89q.worldedit.world.item.ItemType;
|
|||||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.Template;
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
@ -78,7 +76,6 @@ import static com.sk89q.worldedit.world.gamemode.GameModes.SURVIVAL;
|
|||||||
public class BukkitPlayer extends PlotPlayer<Player> {
|
public class BukkitPlayer extends PlotPlayer<Player> {
|
||||||
|
|
||||||
private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build();
|
private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build();
|
||||||
private static final BukkitAudiences BUKKIT_AUDIENCES = BukkitAudiences.create(BukkitMain.getPlugin(BukkitMain.class));
|
|
||||||
|
|
||||||
private static boolean CHECK_EFFECTIVE = true;
|
private static boolean CHECK_EFFECTIVE = true;
|
||||||
public final Player player;
|
public final Player player;
|
||||||
@ -240,7 +237,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
final int fadeIn, final int stay, final int fadeOut, @NotNull final Template ... replacements) {
|
final int fadeIn, final int stay, final int fadeOut, @NotNull final Template ... replacements) {
|
||||||
final Component titleComponent = MINI_MESSAGE.parse(title.getComponent(this), replacements);
|
final Component titleComponent = MINI_MESSAGE.parse(title.getComponent(this), replacements);
|
||||||
final Component subtitleComponent = MINI_MESSAGE.parse(subtitle.getComponent(this), replacements);
|
final Component subtitleComponent = MINI_MESSAGE.parse(subtitle.getComponent(this), replacements);
|
||||||
final Audience audience = BUKKIT_AUDIENCES.player(this.player);
|
final Audience audience = BukkitUtil.BUKKIT_AUDIENCES.player(this.player);
|
||||||
audience.showTitle(Title.of(titleComponent, subtitleComponent, Duration.of(fadeIn * 50,
|
audience.showTitle(Title.of(titleComponent, subtitleComponent, Duration.of(fadeIn * 50,
|
||||||
ChronoUnit.MILLIS), Duration.of(stay * 50, ChronoUnit.MILLIS), Duration.of(fadeOut * 50, ChronoUnit.MILLIS)));
|
ChronoUnit.MILLIS), Duration.of(stay * 50, ChronoUnit.MILLIS), Duration.of(fadeOut * 50, ChronoUnit.MILLIS)));
|
||||||
}
|
}
|
||||||
@ -259,7 +256,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
|
|||||||
if (!Objects.equal(component, this.getMeta("lastMessage")) || System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000) {
|
if (!Objects.equal(component, this.getMeta("lastMessage")) || System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000) {
|
||||||
setMeta("lastMessage", component);
|
setMeta("lastMessage", component);
|
||||||
setMeta("lastMessageTime", System.currentTimeMillis());
|
setMeta("lastMessageTime", System.currentTimeMillis());
|
||||||
BUKKIT_AUDIENCES.player(player).sendMessage(component);
|
BukkitUtil.BUKKIT_AUDIENCES.player(player).sendMessage(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ import com.sk89q.worldedit.world.block.BlockType;
|
|||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -110,6 +111,8 @@ import java.util.stream.Stream;
|
|||||||
@SuppressWarnings({"unused", "WeakerAccess"})
|
@SuppressWarnings({"unused", "WeakerAccess"})
|
||||||
public class BukkitUtil extends WorldUtil {
|
public class BukkitUtil extends WorldUtil {
|
||||||
|
|
||||||
|
public static final BukkitAudiences BUKKIT_AUDIENCES = BukkitAudiences.create(BukkitMain.getPlugin(BukkitMain.class));
|
||||||
|
|
||||||
private static String lastString = null;
|
private static String lastString = null;
|
||||||
private static World lastWorld = null;
|
private static World lastWorld = null;
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ import com.plotsquared.core.util.WorldUtil;
|
|||||||
import com.plotsquared.core.util.logger.ILogger;
|
import com.plotsquared.core.util.logger.ILogger;
|
||||||
import com.plotsquared.core.util.task.TaskManager;
|
import com.plotsquared.core.util.task.TaskManager;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@ -133,13 +134,6 @@ public interface IPlotMain<P> extends ILogger {
|
|||||||
*/
|
*/
|
||||||
SchematicHandler initSchematicHandler();
|
SchematicHandler initSchematicHandler();
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the {@link ChatManager}.
|
|
||||||
*
|
|
||||||
* @return the ChatManager
|
|
||||||
*/
|
|
||||||
ChatManager initChatManager();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The task manager will run and manage Minecraft tasks.
|
* The task manager will run and manage Minecraft tasks.
|
||||||
*
|
*
|
||||||
@ -293,4 +287,11 @@ public interface IPlotMain<P> extends ILogger {
|
|||||||
*/
|
*/
|
||||||
@NotNull PlayerManager<? extends PlotPlayer<P>, ? extends P> getPlayerManager();
|
@NotNull PlayerManager<? extends PlotPlayer<P>, ? extends P> getPlayerManager();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the platform specific console {@link Audience}
|
||||||
|
*
|
||||||
|
* @return Console audience
|
||||||
|
*/
|
||||||
|
@NotNull Audience getConsoleAudience();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,8 @@ package com.plotsquared.core.player;
|
|||||||
|
|
||||||
import com.plotsquared.core.PlotSquared;
|
import com.plotsquared.core.PlotSquared;
|
||||||
import com.plotsquared.core.command.RequiredType;
|
import com.plotsquared.core.command.RequiredType;
|
||||||
|
import com.plotsquared.core.configuration.Caption;
|
||||||
|
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||||
import com.plotsquared.core.database.DBFunc;
|
import com.plotsquared.core.database.DBFunc;
|
||||||
import com.plotsquared.core.events.TeleportCause;
|
import com.plotsquared.core.events.TeleportCause;
|
||||||
import com.plotsquared.core.location.Location;
|
import com.plotsquared.core.location.Location;
|
||||||
@ -37,12 +39,17 @@ import com.sk89q.worldedit.regions.CuboidRegion;
|
|||||||
import com.sk89q.worldedit.world.gamemode.GameMode;
|
import com.sk89q.worldedit.world.gamemode.GameMode;
|
||||||
import com.sk89q.worldedit.world.gamemode.GameModes;
|
import com.sk89q.worldedit.world.gamemode.GameModes;
|
||||||
import com.sk89q.worldedit.world.item.ItemType;
|
import com.sk89q.worldedit.world.item.ItemType;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ConsolePlayer extends PlotPlayer<Actor> {
|
public class ConsolePlayer extends PlotPlayer<Actor> {
|
||||||
|
|
||||||
|
private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build();
|
||||||
private static ConsolePlayer instance;
|
private static ConsolePlayer instance;
|
||||||
|
|
||||||
private ConsolePlayer() {
|
private ConsolePlayer() {
|
||||||
@ -80,7 +87,8 @@ public class ConsolePlayer extends PlotPlayer<Actor> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendTitle(String title, String subtitle, int fadeIn, int stay, int fadeOut) {
|
public void sendTitle(@NotNull final Caption title, @NotNull final Caption subtitle,
|
||||||
|
final int fadeIn, final int stay, final int fadeOut, @NotNull final Template... replacements) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull @Override public Location getLocation() {
|
@NotNull @Override public Location getLocation() {
|
||||||
@ -107,8 +115,17 @@ public class ConsolePlayer extends PlotPlayer<Actor> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void sendMessage(String message) {
|
@Override public void sendMessage(@NotNull final Caption caption, @NotNull final Template... replacements) {
|
||||||
PlotSquared.log(message);
|
final String message = caption.getComponent(this);
|
||||||
|
if (message.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Create the template list, and add the prefix as a replacement
|
||||||
|
final List<Template> templates = Arrays.asList(replacements);
|
||||||
|
templates.add(Template.of("prefix", MINI_MESSAGE.parse(
|
||||||
|
TranslatableCaption.of("core.prefix").getComponent(this))));
|
||||||
|
// Parse the message
|
||||||
|
PlotSquared.imp().getConsoleAudience().sendMessage(MINI_MESSAGE.parse(message, templates));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void teleport(Location location, TeleportCause cause) {
|
@Override public void teleport(Location location, TeleportCause cause) {
|
||||||
|
Loading…
Reference in New Issue
Block a user