Skip to content

Commit

Permalink
Fully replace Fanciful with Chat Component API
Browse files Browse the repository at this point in the history
  • Loading branch information
nsporillo committed May 6, 2016
1 parent 1ed30e4 commit 96bec9a
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 113 deletions.
24 changes: 18 additions & 6 deletions src/main/java/com/massivecraft/factions/cmd/CmdDeinvite.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
import mkremins.fanciful.FancyMessage;
import org.bukkit.ChatColor;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;

public class CmdDeinvite extends FCommand {

Expand All @@ -30,14 +33,23 @@ public CmdDeinvite() {
@Override
public void perform() {
FPlayer you = this.argAsBestFPlayerMatch(0);

if (you == null) {
FancyMessage msg = new FancyMessage(TL.COMMAND_DEINVITE_CANDEINVITE.toString()).color(ChatColor.GOLD);
TextComponent base = new TextComponent(TL.COMMAND_DEINVITE_CANDEINVITE.toString());
base.setColor(ChatColor.GOLD);

for (String id : myFaction.getInvites()) {
FPlayer fp = FPlayers.getInstance().getById(id);
String name = fp != null ? fp.getName() : id;
msg.then(name + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_DEINVITE_CLICKTODEINVITE.format(name)).command("/" + Conf.baseCommandAliases.get(0) + " deinvite " + name);
String s = fp != null ? fp.getName() : id;

TextComponent text = new TextComponent(s + " ");
text.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + Conf.baseCommandAliases.get(0) + " deinvite " + s));
text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(TL.COMMAND_DEINVITE_CLICKTODEINVITE.format(s)).create()));
text.setColor(ChatColor.WHITE);
base.addExtra(text);
}
sendFancyMessage(msg);

fme.getPlayer().spigot().sendMessage(base);
return;
}

Expand Down
21 changes: 16 additions & 5 deletions src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.LazyLocation;
import com.massivecraft.factions.zcore.util.TL;
import mkremins.fanciful.FancyMessage;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

import java.util.Map;
Expand All @@ -31,12 +34,20 @@ public CmdFWarp() {
public void perform() {
//TODO: check if in combat.
if (args.size() == 0) {
FancyMessage msg = new FancyMessage(TL.COMMAND_FWARP_WARPS.toString()).color(ChatColor.GOLD);
TextComponent base = new TextComponent(TL.COMMAND_FWARP_WARPS.toString());
base.setColor(net.md_5.bungee.api.ChatColor.GOLD);

Map<String, LazyLocation> warps = myFaction.getWarps();

for (String s : warps.keySet()) {
msg.then(s + " ").tooltip(TL.COMMAND_FWARP_CLICKTOWARP.toString()).command("/" + Conf.baseCommandAliases.get(0) + " warp " + s).color(ChatColor.WHITE);
TextComponent warp = new TextComponent(s + " ");
warp.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(TL.COMMAND_FWARP_CLICKTOWARP.toString()).create()));
warp.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + Conf.baseCommandAliases.get(0) + " warp " + s));
warp.setColor(ChatColor.WHITE);
base.addExtra(warp);
}
sendFancyMessage(msg);

fme.getPlayer().spigot().sendMessage(base);
} else if (args.size() > 1) {
fme.msg(TL.COMMAND_FWARP_COMMANDFORMAT);
} else {
Expand Down
27 changes: 22 additions & 5 deletions src/main/java/com/massivecraft/factions/cmd/CmdInvite.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
import mkremins.fanciful.FancyMessage;
import org.bukkit.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;

public class CmdInvite extends FCommand {

Expand Down Expand Up @@ -56,10 +58,25 @@ public void perform() {
return;
}

// Tooltips, colors, and commands only apply to the string immediately before it.
FancyMessage message = new FancyMessage(fme.describeTo(you, true)).tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()).command("/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag()).then(TL.COMMAND_INVITE_INVITEDYOU.toString()).color(ChatColor.YELLOW).tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()).command(Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag()).then(myFaction.describeTo(you)).tooltip(TL.COMMAND_INVITE_CLICKTOJOIN.toString()).command(Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag());
HoverEvent tooltip = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(TL.COMMAND_INVITE_CLICKTOJOIN.toString()).create());
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + Conf.baseCommandAliases.get(0) + " join " + myFaction.getTag());

message.send(you.getPlayer());
TextComponent base = new TextComponent(fme.describeTo(you, true));
base.setHoverEvent(tooltip);
base.setClickEvent(clickEvent);

TextComponent next = new TextComponent(TL.COMMAND_INVITE_INVITEDYOU.toString());
next.setColor(net.md_5.bungee.api.ChatColor.YELLOW);
next.setHoverEvent(tooltip);
next.setClickEvent(clickEvent);
base.addExtra(next);

TextComponent next2 = new TextComponent(myFaction.describeTo(you));
next2.setHoverEvent(tooltip);
next2.setClickEvent(clickEvent);
base.addExtra(next2);

you.getPlayer().spigot().sendMessage(base);

//you.msg("%s<i> invited you to %s", fme.describeTo(you, true), myFaction.describeTo(you));
myFaction.msg(TL.COMMAND_INVITE_INVITED, fme.describeTo(myFaction, true), you.describeTo(myFaction));
Expand Down
29 changes: 23 additions & 6 deletions src/main/java/com/massivecraft/factions/cmd/CmdKick.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.util.TL;
import mkremins.fanciful.FancyMessage;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

public class CmdKick extends FCommand {

Expand All @@ -34,19 +37,33 @@ public CmdKick() {
public void perform() {
FPlayer toKick = this.argIsSet(0) ? this.argAsBestFPlayerMatch(0) : null;
if (toKick == null) {
FancyMessage msg = new FancyMessage(TL.COMMAND_KICK_CANDIDATES.toString()).color(ChatColor.GOLD);
TextComponent base = new TextComponent(TL.COMMAND_KICK_CANDIDATES.toString());
base.setColor(ChatColor.GOLD);

for (FPlayer player : myFaction.getFPlayersWhereRole(Role.NORMAL)) {
String s = player.getName();
msg.then(s + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_KICK_CLICKTOKICK.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " kick " + s);

TextComponent normal = new TextComponent(s + " ");
normal.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(TL.COMMAND_KICK_CLICKTOKICK.toString() + s).create()));
normal.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + Conf.baseCommandAliases.get(0) + " kick " + s));
normal.setColor(ChatColor.WHITE);
base.addExtra(normal);

}

if (fme.getRole() == Role.ADMIN) {
for (FPlayer player : myFaction.getFPlayersWhereRole(Role.MODERATOR)) {
String s = player.getName();
msg.then(s + " ").color(ChatColor.GRAY).tooltip(TL.COMMAND_KICK_CLICKTOKICK.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " kick " + s);

TextComponent admin = new TextComponent(s + " ");
admin.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(TL.COMMAND_KICK_CLICKTOKICK.toString() + s).create()));
admin.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + Conf.baseCommandAliases.get(0) + " kick " + s));
admin.setColor(ChatColor.GRAY);
base.addExtra(admin);
}
}

sendFancyMessage(msg);
fme.getPlayer().spigot().sendMessage(base);
return;
}

Expand Down
21 changes: 16 additions & 5 deletions src/main/java/com/massivecraft/factions/cmd/CmdMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.util.TL;
import mkremins.fanciful.FancyMessage;
import org.bukkit.ChatColor;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;

public class CmdMod extends FCommand {

Expand All @@ -30,14 +33,22 @@ public CmdMod() {
@Override
public void perform() {
FPlayer you = this.argAsBestFPlayerMatch(0);

if (you == null) {
FancyMessage msg = new FancyMessage(TL.COMMAND_MOD_CANDIDATES.toString()).color(ChatColor.GOLD);
TextComponent base = new TextComponent(TL.COMMAND_MOD_CANDIDATES.toString());
base.setColor(ChatColor.GOLD);

for (FPlayer player : myFaction.getFPlayersWhereRole(Role.NORMAL)) {
String s = player.getName();
msg.then(s + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_MOD_CLICKTOPROMOTE.toString() + s).command("/" + Conf.baseCommandAliases.get(0) + " mod " + s);

TextComponent text = new TextComponent(s + " ");
text.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + Conf.baseCommandAliases.get(0) + " mod " + s));
text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(TL.COMMAND_MOD_CLICKTOPROMOTE.toString() + s).create()));
text.setColor(ChatColor.WHITE);
base.addExtra(text);
}

sendFancyMessage(msg);
fme.getPlayer().spigot().sendMessage(base);
return;
}

Expand Down
19 changes: 15 additions & 4 deletions src/main/java/com/massivecraft/factions/cmd/CmdShow.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
import com.massivecraft.factions.zcore.util.TagUtil;
import mkremins.fanciful.FancyMessage;
import net.md_5.bungee.api.chat.TextComponent;

import java.util.List;

Expand All @@ -32,6 +32,7 @@ public void perform() {
if (this.argIsSet(0)) {
faction = this.argAsFaction(0);
}

if (faction == null) {
return;
}
Expand All @@ -49,6 +50,7 @@ public void perform() {
if(faction.isNormal()) {
if (faction.isPermanent() && faction.getFPlayers().size() == 0) {
List<String> perm_show = P.p.getConfig().getStringList("permanent-show");

if (perm_show != null && !perm_show.isEmpty()) {
show = perm_show; // we can show the permanent show from config
}
Expand All @@ -60,21 +62,30 @@ public void perform() {

for (String raw : show) {
String parsed = TagUtil.parsePlain(faction, fme, raw); // use relations

if (parsed == null) {
continue; // line to be ignored, due to minimal show
}

if (TagUtil.hasFancy(parsed)) {
List<FancyMessage> fancy = TagUtil.parseFancy(faction, fme, parsed);
if (fancy != null) {
sendFancyMessage(fancy);
String colorized = p.txt.parse(parsed);
List<TextComponent> components = TagUtil.parseFancy(faction, fme, colorized);

if (components != null) {
for (TextComponent textComponent : components) {
fme.getPlayer().spigot().sendMessage(textComponent);
}
}

continue;
}

if (!parsed.contains("{notFrozen}") && !parsed.contains("{notPermanent}")) {
if (parsed.contains("{ig}")) {
// replaces all variables with no home TL
parsed = parsed.substring(0, parsed.indexOf("{ig}")) + TL.COMMAND_SHOW_NOHOME.toString();
}

// we don't add these entire lines to fshow, wouldn't make any sense to.
// Ex: DTR Freeze: 0 seconds. uhm, what?
msg(p.txt.parse(parsed));
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/com/massivecraft/factions/cmd/CmdShowInvites.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
import mkremins.fanciful.FancyMessage;
import org.bukkit.ChatColor;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;

public class CmdShowInvites extends FCommand {

Expand All @@ -21,14 +24,21 @@ public CmdShowInvites() {

@Override
public void perform() {
FancyMessage msg = new FancyMessage(TL.COMMAND_SHOWINVITES_PENDING.toString()).color(ChatColor.GOLD);
TextComponent base = new TextComponent();
base.setColor(ChatColor.GOLD);

for (String id : myFaction.getInvites()) {
FPlayer fp = FPlayers.getInstance().getById(id);
String name = fp != null ? fp.getName() : id;
msg.then(name + " ").color(ChatColor.WHITE).tooltip(TL.COMMAND_SHOWINVITES_CLICKTOREVOKE.format(name)).command("/" + Conf.baseCommandAliases.get(0) + " deinvite " + name);

TextComponent invite = new TextComponent(name + "");
invite.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(TL.COMMAND_SHOWINVITES_CLICKTOREVOKE.format(name)).create()));
invite.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + Conf.baseCommandAliases.get(0) + " deinvite " + name));
invite.setColor(ChatColor.WHITE);
base.addExtra(invite);
}

sendFancyMessage(msg);
fme.getPlayer().spigot().sendMessage(base);
}

@Override
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/com/massivecraft/factions/zcore/MCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.massivecraft.factions.zcore.util.TL;
import com.massivecraft.factions.zcore.util.TextUtil;
import mkremins.fanciful.FancyMessage;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -262,16 +261,6 @@ public void sendMessage(List<String> msgs) {
}
}

public void sendFancyMessage(FancyMessage message) {
message.send(sender);
}

public void sendFancyMessage(List<FancyMessage> messages) {
for (FancyMessage m : messages) {
sendFancyMessage(m);
}
}

// -------------------------------------------- //
// Argument Readers
// -------------------------------------------- //
Expand Down
Loading

0 comments on commit 96bec9a

Please sign in to comment.