Fixed interactive chat colors + added interactive pages to sponge.

This commit is contained in:
boy0001 2015-08-25 02:28:32 +10:00
parent 83d0b8cebb
commit 68df5b1930
8 changed files with 161 additions and 164 deletions

View File

@ -7,6 +7,7 @@ import com.intellectualcrafters.plot.generator.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.AbstractTitle; import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChatManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
@ -68,6 +69,12 @@ public interface IPlotMain {
*/ */
SchematicHandler initSchematicHandler(); SchematicHandler initSchematicHandler();
/**
* Get the schematic handler
* @return
*/
ChatManager initChatManager();
/** /**
* The task manager will run and manage minecraft tasks * The task manager will run and manage minecraft tasks
* @return * @return

View File

@ -60,6 +60,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.AbstractTitle; import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChatManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.ClusterManager;
import com.intellectualcrafters.plot.util.CommentManager; import com.intellectualcrafters.plot.util.CommentManager;
@ -211,6 +212,8 @@ public class PS {
SchematicHandler.manager = IMP.initSchematicHandler(); SchematicHandler.manager = IMP.initSchematicHandler();
// Titles // Titles
AbstractTitle.TITLE_CLASS = IMP.initTitleManager(); AbstractTitle.TITLE_CLASS = IMP.initTitleManager();
// Chat
ChatManager.manager = IMP.initChatManager();
// Check for updates // Check for updates
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {

View File

@ -38,6 +38,7 @@ import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotMessage;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.Rating; import com.intellectualcrafters.plot.object.Rating;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EconHandler;
@ -47,7 +48,6 @@ import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.StringComparison;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.chat.FancyMessage;
import com.plotsquared.bukkit.object.BukkitPlayer; import com.plotsquared.bukkit.object.BukkitPlayer;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
@ -388,76 +388,68 @@ public class list extends SubCommand {
} }
} }
i++; i++;
if (!ConsolePlayer.isConsole(player) && Settings.FANCY_CHAT) { String color;
ChatColor color;
if (plot.owner == null) { if (plot.owner == null) {
color = ChatColor.GOLD; color = "$3";
} }
else if (plot.isOwner(player.getUUID())) { else if (plot.isOwner(player.getUUID())) {
color = ChatColor.BLUE; color = "$1";
} }
else if (plot.isAdded(player.getUUID())) { else if (plot.isAdded(player.getUUID())) {
color = ChatColor.DARK_GREEN; color = "$4";
} }
else if (plot.isDenied(player.getUUID())) { else if (plot.isDenied(player.getUUID())) {
color = ChatColor.RED; color = "$2";
} }
else { else {
color = ChatColor.GOLD; color = "$1";
} }
FancyMessage trusted = PlotMessage trusted =
new FancyMessage( new PlotMessage()
ChatColor.stripColor( .text(C.color(C.PLOT_INFO_TRUSTED.s().replaceAll("%trusted%", Info.getPlayerList(plot.getTrusted()))))
ChatColor.translateAlternateColorCodes('&', .color("$1");
C.PLOT_INFO_TRUSTED.s().replaceAll("%trusted%", Info.getPlayerList(plot.getTrusted())))))
.color(ChatColor.GOLD); PlotMessage members =
new PlotMessage()
.text(C.color(C.PLOT_INFO_MEMBERS.s().replaceAll("%members%", Info.getPlayerList(plot.getMembers()))))
.color("$1");
FancyMessage members =
new FancyMessage(
ChatColor.stripColor(
ChatColor.translateAlternateColorCodes('&',
C.PLOT_INFO_MEMBERS.s().replaceAll("%members%", Info.getPlayerList(plot.getMembers())))))
.color(ChatColor.GOLD);
String strFlags = StringMan.join(plot.getSettings().flags.values(), ","); String strFlags = StringMan.join(plot.getSettings().flags.values(), ",");
if (strFlags.length() == 0) { if (strFlags.length() == 0) {
strFlags = C.NONE.s(); strFlags = C.NONE.s();
} }
FancyMessage flags =
new FancyMessage(
ChatColor.stripColor(
ChatColor.translateAlternateColorCodes('&',
C.PLOT_INFO_FLAGS.s().replaceAll("%flags%", strFlags))))
.color(ChatColor.GOLD);
FancyMessage message = new FancyMessage("") PlotMessage flags =
.then("[") new PlotMessage()
.color(ChatColor.DARK_GRAY) .text(C.color(C.PLOT_INFO_FLAGS.s().replaceAll("%flags%", strFlags)))
.then(i + "") .color("$1");
PlotMessage message = new PlotMessage()
.text("[")
.color("$3")
.text(i + "")
.command("/plot visit " + plot.world + ";" + plot.id) .command("/plot visit " + plot.world + ";" + plot.id)
.tooltip("/plot visit " + plot.world + ";" + plot.id) .tooltip("/plot visit " + plot.world + ";" + plot.id)
.color(ChatColor.GOLD) .color("$1")
.then("]") .text("]")
.color("$3")
.text(" " + plot.toString())
// teleport tooltip .tooltip(trusted, members, flags)
.color(ChatColor.DARK_GRAY)
.then(" " + plot.toString())
.formattedTooltip(trusted, members, flags)
.command("/plot info " + plot.world + ";" + plot.id) .command("/plot info " + plot.world + ";" + plot.id)
.color(color) .color(color)
.then(" - ") .text(" - ")
.color(ChatColor.GRAY); .color("$2");
String prefix = ""; String prefix = "";
for (UUID uuid : plot.getOwners()) { for (UUID uuid : plot.getOwners()) {
String name = UUIDHandler.getName(uuid); String name = UUIDHandler.getName(uuid);
if (name == null) { if (name == null) {
message = message message = message
.then(prefix) .text(prefix)
.color(ChatColor.DARK_GRAY) .color("$4")
.then("unknown") .text("unknown")
.color(ChatColor.GRAY) .color("$2")
.tooltip(uuid.toString()) .tooltip(uuid.toString())
.suggest(uuid.toString()); .suggest(uuid.toString());
} }
@ -465,91 +457,70 @@ public class list extends SubCommand {
PlotPlayer pp = UUIDHandler.getPlayer(uuid); PlotPlayer pp = UUIDHandler.getPlayer(uuid);
if (pp != null) { if (pp != null) {
message = message message = message
.then(prefix) .text(prefix)
.color(ChatColor.DARK_GRAY) .color("$4")
.then(name).color(ChatColor.GOLD) .text(name).color("$1")
.formattedTooltip(new FancyMessage("Online").color(ChatColor.DARK_GREEN)); .tooltip(new PlotMessage("Online").color("$4"));
} }
else { else {
message = message message = message
.then(prefix) .text(prefix)
.color(ChatColor.DARK_GRAY) .color("$4")
.then(name).color(ChatColor.GOLD) .text(name).color("$1")
.formattedTooltip(new FancyMessage("Offline").color(ChatColor.RED)); .tooltip(new PlotMessage("Offline").color("$3"));
} }
} }
prefix = ", "; prefix = ", ";
} }
message.send(((BukkitPlayer) player).player); message.send(player);
} }
else {
String message = C.PLOT_LIST_ITEM.s()
.replaceAll("%in", i + 1 + "")
.replaceAll("%id", plot.id.toString())
.replaceAll("%world", plot.world)
.replaceAll("%owner", getName(plot.owner))
// Unused
.replaceAll("%trusted%", "")
.replaceAll("%members%", "")
.replaceAll("%tp%", "");
MainUtil.sendMessage(player, message);
}
}
if (!ConsolePlayer.isConsole(player) && Settings.FANCY_CHAT) {
if (page < totalPages && page > 0) { if (page < totalPages && page > 0) {
// back | next // back | next
new FancyMessage("") new PlotMessage()
.then("<-") .text("<-")
.color(ChatColor.GOLD) .color("$1")
.command("/plot list " + args[0] + " " + (page)) .command("/plot list " + args[0] + " " + (page))
.then(" | ") .text(" | ")
.color(ChatColor.DARK_GRAY) .color("$3")
.then("->") .text("->")
.color(ChatColor.GOLD) .color("$1")
.command("/plot list " + args[0] + " " + (page + 2)) .command("/plot list " + args[0] + " " + (page + 2))
.then(C.CLICKABLE.s()) .text(C.CLICKABLE.s())
.color(ChatColor.GRAY) .color("$2")
.send(((BukkitPlayer) player).player); .send(player);
return; return;
} }
if (page == 0 && totalPages != 0) { if (page == 0 && totalPages != 0) {
// next // next
new FancyMessage("") new PlotMessage()
.then("<-") .text("<-")
.color(ChatColor.DARK_GRAY) .color("$3")
.then(" | ") .text(" | ")
.color(ChatColor.DARK_GRAY) .color("$3")
.then("->") .text("->")
.color(ChatColor.GOLD) .color("$1")
.command("/plot list " + args[0] + " " + (page + 2)) .command("/plot list " + args[0] + " " + (page + 2))
.then(C.CLICKABLE.s()) .text(C.CLICKABLE.s())
.color(ChatColor.GRAY) .color("$2")
.send(((BukkitPlayer) player).player); .send(player);
return; return;
} }
if (page == totalPages && totalPages != 0) { if (page == totalPages && totalPages != 0) {
// back // back
new FancyMessage("") new PlotMessage()
.then("<-") .text("<-")
.color(ChatColor.GOLD) .color("$1")
.command("/plot list " + args[0] + " " + (page)) .command("/plot list " + args[0] + " " + (page))
.then(" | ") .text(" | ")
.color(ChatColor.DARK_GRAY) .color("$3")
.then("->") .text("->")
.color(ChatColor.DARK_GRAY) .color("$3")
.then(C.CLICKABLE.s()) .text(C.CLICKABLE.s())
.color(ChatColor.GRAY) .color("$2")
.send(((BukkitPlayer) player).player); .send(player);
return; return;
} }
} }
else {
String footer = C.PLOT_LIST_FOOTER.s().replaceAll("%word%", "There is").replaceAll("%num%", plots.size() + "").replaceAll("%plot%", plots.size() == 1 ? "plot" : "plots");
MainUtil.sendMessage(player, footer);
}
}
private String getArgumentList(final String[] strings) { private String getArgumentList(final String[] strings) {
final StringBuilder builder = new StringBuilder(); final StringBuilder builder = new StringBuilder();

View File

@ -35,6 +35,7 @@ import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.AbstractTitle; import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.BlockUpdateUtil; import com.intellectualcrafters.plot.util.BlockUpdateUtil;
import com.intellectualcrafters.plot.util.ChatManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.ConsoleColors; import com.intellectualcrafters.plot.util.ConsoleColors;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EconHandler;
@ -64,12 +65,14 @@ import com.plotsquared.bukkit.listeners.WorldEvents;
import com.plotsquared.bukkit.listeners.worldedit.WEListener; import com.plotsquared.bukkit.listeners.worldedit.WEListener;
import com.plotsquared.bukkit.listeners.worldedit.WESubscriber; import com.plotsquared.bukkit.listeners.worldedit.WESubscriber;
import com.plotsquared.bukkit.titles.DefaultTitle; import com.plotsquared.bukkit.titles.DefaultTitle;
import com.plotsquared.bukkit.util.BukkitChatManager;
import com.plotsquared.bukkit.util.BukkitChunkManager; import com.plotsquared.bukkit.util.BukkitChunkManager;
import com.plotsquared.bukkit.util.BukkitCommand; import com.plotsquared.bukkit.util.BukkitCommand;
import com.plotsquared.bukkit.util.BukkitEconHandler; import com.plotsquared.bukkit.util.BukkitEconHandler;
import com.plotsquared.bukkit.util.BukkitEventUtil; import com.plotsquared.bukkit.util.BukkitEventUtil;
import com.plotsquared.bukkit.util.BukkitHybridUtils; import com.plotsquared.bukkit.util.BukkitHybridUtils;
import com.plotsquared.bukkit.util.BukkitInventoryUtil; import com.plotsquared.bukkit.util.BukkitInventoryUtil;
import com.plotsquared.bukkit.util.BukkitPlainChatManager;
import com.plotsquared.bukkit.util.BukkitSchematicHandler; import com.plotsquared.bukkit.util.BukkitSchematicHandler;
import com.plotsquared.bukkit.util.BukkitSetBlockManager; import com.plotsquared.bukkit.util.BukkitSetBlockManager;
import com.plotsquared.bukkit.util.BukkitSetupUtils; import com.plotsquared.bukkit.util.BukkitSetupUtils;
@ -637,4 +640,14 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
PS.debug("Unknown NMS package: " + StringMan.getString(pas)); PS.debug("Unknown NMS package: " + StringMan.getString(pas));
return "1_8_R3"; return "1_8_R3";
} }
@Override
public ChatManager<?> initChatManager() {
if (Settings.FANCY_CHAT) {
return new BukkitChatManager();
}
else {
return new BukkitPlainChatManager();
}
}
} }

View File

@ -35,6 +35,7 @@ import com.google.gson.JsonParser;
import com.google.gson.stream.JsonWriter; import com.google.gson.stream.JsonWriter;
import com.intellectualcrafters.configuration.serialization.ConfigurationSerializable; import com.intellectualcrafters.configuration.serialization.ConfigurationSerializable;
import com.intellectualcrafters.configuration.serialization.ConfigurationSerialization; import com.intellectualcrafters.configuration.serialization.ConfigurationSerialization;
import com.intellectualcrafters.plot.config.C;
/** /**
* Represents a formattable message. Such messages can use elements such as colors, formatting codes, hover and click data, and other features provided by the vanilla Minecraft <a href="http://minecraft.gamepedia.com/Tellraw#Raw_JSON_Text">JSON message formatter</a>. * Represents a formattable message. Such messages can use elements such as colors, formatting codes, hover and click data, and other features provided by the vanilla Minecraft <a href="http://minecraft.gamepedia.com/Tellraw#Raw_JSON_Text">JSON message formatter</a>.
@ -134,9 +135,6 @@ public class FancyMessage implements JsonRepresentedObject, Cloneable, Iterable<
* @exception IllegalArgumentException If the specified {@code ChatColor} enumeration value is not a color (but a format value). * @exception IllegalArgumentException If the specified {@code ChatColor} enumeration value is not a color (but a format value).
*/ */
public FancyMessage color(final ChatColor color) { public FancyMessage color(final ChatColor color) {
if (!color.isColor()) {
throw new IllegalArgumentException(color.name() + " is not a color");
}
latest().color = color; latest().color = color;
dirty = true; dirty = true;
return this; return this;

View File

@ -152,7 +152,7 @@ public class BukkitPlayer extends PlotPlayer {
@Override @Override
public void setAttribute(String key) { public void setAttribute(String key) {
key = "plotsquared_user_attributes." + key; key = "plotsquared_user_attributes." + key;
if (EconHandler.manager == null) { if (EconHandler.manager == null || player.hasPermission("plotsquared_user_attributes.*")) {
setMeta(key, true); setMeta(key, true);
return; return;
} }

View File

@ -50,6 +50,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.AbstractTitle; import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChatManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EconHandler;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
@ -66,6 +67,7 @@ import com.plotsquared.sponge.generator.WorldModify;
import com.plotsquared.sponge.listener.MainListener; import com.plotsquared.sponge.listener.MainListener;
import com.plotsquared.sponge.util.KillRoadMobs; import com.plotsquared.sponge.util.KillRoadMobs;
import com.plotsquared.sponge.util.SpongeBlockManager; import com.plotsquared.sponge.util.SpongeBlockManager;
import com.plotsquared.sponge.util.SpongeChatManager;
import com.plotsquared.sponge.util.SpongeChunkManager; import com.plotsquared.sponge.util.SpongeChunkManager;
import com.plotsquared.sponge.util.SpongeCommand; import com.plotsquared.sponge.util.SpongeCommand;
import com.plotsquared.sponge.util.SpongeEventUtil; import com.plotsquared.sponge.util.SpongeEventUtil;
@ -229,10 +231,6 @@ public class SpongeMain implements IPlotMain, PluginContainer {
PS.instance = new PS(this, "Sponge"); PS.instance = new PS(this, "Sponge");
// TODO Until P^2 has json chat stuff for sponge, disable this
Settings.FANCY_CHAT = false;
// done
registerBlocks(); registerBlocks();
ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds"); ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds");
@ -638,4 +636,9 @@ public class SpongeMain implements IPlotMain, PluginContainer {
public String getNMSPackage() { public String getNMSPackage() {
return "1_8_R3"; return "1_8_R3";
} }
@Override
public ChatManager<?> initChatManager() {
return new SpongeChatManager();
}
} }

View File

@ -10,7 +10,9 @@ import org.spongepowered.api.data.value.mutable.Value;
import org.spongepowered.api.entity.player.Player; import org.spongepowered.api.entity.player.Player;
import org.spongepowered.api.entity.player.gamemode.GameMode; import org.spongepowered.api.entity.player.gamemode.GameMode;
import org.spongepowered.api.entity.player.gamemode.GameModes; import org.spongepowered.api.entity.player.gamemode.GameModes;
import org.spongepowered.api.text.TextBuilder;
import org.spongepowered.api.text.Texts; import org.spongepowered.api.text.Texts;
import org.spongepowered.api.text.action.HoverAction;
import org.spongepowered.api.text.chat.ChatTypes; import org.spongepowered.api.text.chat.ChatTypes;
import com.flowpowered.math.vector.Vector3d; import com.flowpowered.math.vector.Vector3d;