From 13b7bd5581a8e97170c17d812cffa2c8f73ff885 Mon Sep 17 00:00:00 2001 From: ulumulu1510 Date: Tue, 8 Sep 2015 19:18:45 +0200 Subject: [PATCH] Implement Mson UsageTemplate. --- .../factions/cmd/CmdFactionsCreate.java | 5 ++- .../factions/cmd/CmdFactionsInviteAdd.java | 15 ++++++- .../factions/cmd/CmdFactionsInviteRemove.java | 42 +++++++++++++++++-- .../factions/cmd/CmdFactionsJoin.java | 23 +++++++++- .../factions/cmd/CmdFactionsKick.java | 5 ++- .../cmd/CmdFactionsRelationAbstract.java | 23 ++++++++-- .../massivecraft/factions/entity/Faction.java | 6 +-- .../massivecraft/factions/entity/MPerm.java | 2 +- 8 files changed, 106 insertions(+), 15 deletions(-) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java index 9d7a02b9..a4f9a45d 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java @@ -2,6 +2,8 @@ package com.massivecraft.factions.cmd; import java.util.ArrayList; +import org.bukkit.ChatColor; + import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; @@ -15,6 +17,7 @@ import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipC import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.cmd.arg.ARString; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.mson.Mson; import com.massivecraft.massivecore.store.MStore; public class CmdFactionsCreate extends FactionsCommand @@ -81,7 +84,7 @@ public class CmdFactionsCreate extends FactionsCommand // Inform msg("You created the faction %s", faction.getName(msender)); - msg("You should now: %s", Factions.get().getOuterCmdFactions().cmdFactionsDescription.getUseageTemplate()); + message(Mson.mson(mson("You should now: ").color(ChatColor.YELLOW), Factions.get().getOuterCmdFactions().cmdFactionsDescription.getUseageTemplate())); // Log if (MConf.get().logFactionCreate) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsInviteAdd.java b/src/com/massivecraft/factions/cmd/CmdFactionsInviteAdd.java index 26825baf..9e9067af 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsInviteAdd.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsInviteAdd.java @@ -2,6 +2,8 @@ package com.massivecraft.factions.cmd; import java.util.Collection; +import org.bukkit.ChatColor; + import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARMPlayer; @@ -11,6 +13,8 @@ import com.massivecraft.factions.event.EventFactionsInvitedChange; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.cmd.arg.ARSet; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.util.Txt; public class CmdFactionsInviteAdd extends FactionsCommand { @@ -71,9 +75,18 @@ public class CmdFactionsInviteAdd extends FactionsCommand } else { + // Mson + String command = Factions.get().getOuterCmdFactions().cmdFactionsInvite.cmdFactionsInviteRemove.getCommandLine(mplayer.getName()); + String tooltip = Txt.parse("Click to %s.", command); + + Mson remove = Mson.mson( + mson("You might want to remove him. ").color(ChatColor.YELLOW), + mson("Click to " + command).color(ChatColor.RED).tooltip(tooltip).suggest(command) + ); + // Inform msg("%s is already invited to %s.", mplayer.getName(), msenderFaction.getName()); - msg("You might want to: " + Factions.get().getOuterCmdFactions().cmdFactionsInvite.cmdFactionsInviteRemove.getUseageTemplate(false)); + message(remove); } } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsInviteRemove.java b/src/com/massivecraft/factions/cmd/CmdFactionsInviteRemove.java index dea2deb8..7791db3e 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsInviteRemove.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsInviteRemove.java @@ -1,9 +1,12 @@ package com.massivecraft.factions.cmd; +import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; +import org.bukkit.ChatColor; + import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARMPlayer; @@ -13,6 +16,8 @@ import com.massivecraft.factions.event.EventFactionsInvitedChange; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.cmd.arg.ARSet; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.util.Txt; public class CmdFactionsInviteRemove extends FactionsCommand { @@ -67,8 +72,18 @@ public class CmdFactionsInviteRemove extends FactionsCommand // Already member? if (mplayer.getFaction() == msenderFaction) { + // Mson + String command = Factions.get().getOuterCmdFactions().cmdFactionsKick.getCommandLine(mplayer.getName()); + String tooltip = Txt.parse("Click to %s.", command); + + Mson kick = Mson.mson( + mson("You might want to kick him. ").color(ChatColor.YELLOW), + mson(ChatColor.RED.toString() + tooltip).tooltip(ChatColor.YELLOW.toString() + tooltip).suggest(command) + ); + + // Inform msg("%s is already a member of %s.", mplayer.getName(), msenderFaction.getName()); - msg("You might want to: " + Factions.get().getOuterCmdFactions().cmdFactionsKick.getUseageTemplate(false)); + message(kick); continue; } @@ -97,16 +112,37 @@ public class CmdFactionsInviteRemove extends FactionsCommand } else { + // Mson + String command = Factions.get().getOuterCmdFactions().cmdFactionsInvite.cmdFactionsInviteAdd.getCommandLine(mplayer.getName()); + String tooltip = Txt.parse("Click to %s.", command); + + Mson invite = Mson.mson( + mson("You might want to invite him. ").color(ChatColor.YELLOW), + mson(ChatColor.GREEN.toString() + tooltip).tooltip(ChatColor.YELLOW.toString() + tooltip).suggest(command) + ); + // Inform msg("%s is not invited to %s.", mplayer.describeTo(msender, true), msenderFaction.describeTo(mplayer)); - msg("You might want to: " + Factions.get().getOuterCmdFactions().cmdFactionsInvite.cmdFactionsInviteAdd.getUseageTemplate(false)); + message(invite); } } // Inform Faction if all if (all) { - msenderFaction.msg("%s revoked all %s pending invitations from your faction.", msender.describeTo(msenderFaction), mplayers.size()); + List names = new ArrayList(); + for (MPlayer mplayer : mplayers) + { + names.add(mplayer.describeTo(msender, true)); + } + + Mson factionsRevokeAll = mson( + Mson.parse("%s revoked ", msender.describeTo(msenderFaction)), + Mson.parse("all %s pending invitations", mplayers.size()).tooltip(names), + mson(" from your faction.").color(ChatColor.YELLOW) + ); + + msenderFaction.sendMessage(factionsRevokeAll); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java index 52c2317b..f7e72634 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java @@ -1,5 +1,7 @@ package com.massivecraft.factions.cmd; +import org.bukkit.ChatColor; + import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARMPlayer; @@ -12,6 +14,7 @@ import com.massivecraft.factions.event.EventFactionsMembershipChange; import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.mson.Mson; import com.massivecraft.massivecore.util.Txt; public class CmdFactionsJoin extends FactionsCommand @@ -57,7 +60,15 @@ public class CmdFactionsJoin extends FactionsCommand if (faction == mplayerFaction) { - msg("%s %s already a member of %s.", mplayer.describeTo(msender, true), (samePlayer ? "are" : "is"), faction.getName(msender)); + String command = Factions.get().getOuterCmdFactions().cmdFactionsKick.getCommandLine(mplayer.getName()); + + // Mson creation + Mson alreadyMember = Mson.mson( + Mson.parse(mplayer.describeTo(msender, true)), + mson((samePlayer ? " are" : " is") + " already a member of " + faction.getName(msender) + ".").color(ChatColor.YELLOW) + ); + + message(alreadyMember.suggest(command).tooltip(Txt.parse("Click to %s.", command))); return; } @@ -69,7 +80,15 @@ public class CmdFactionsJoin extends FactionsCommand if (mplayerFaction.isNormal()) { - msg("%s must leave %s current faction first.", mplayer.describeTo(msender, true), (samePlayer ? "your" : "their")); + String command = Factions.get().getOuterCmdFactions().cmdFactionsLeave.getCommandLine(mplayer.getName()); + + // Mson creation + Mson leaveFirst = Mson.mson( + Mson.parse(mplayer.describeTo(msender, true)), + mson(" must leave " + (samePlayer ? "your" : "their") + " current faction first.").color(ChatColor.RED) + ); + + message(leaveFirst.suggest(command).tooltip(Txt.parse("Click to %s.", command))); return; } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsKick.java b/src/com/massivecraft/factions/cmd/CmdFactionsKick.java index a30c3e78..d25bfb31 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsKick.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsKick.java @@ -1,5 +1,7 @@ package com.massivecraft.factions.cmd; +import org.bukkit.ChatColor; + import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; @@ -13,6 +15,7 @@ import com.massivecraft.factions.event.EventFactionsMembershipChange; import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.mson.Mson; import com.massivecraft.massivecore.util.IdUtil; public class CmdFactionsKick extends FactionsCommand @@ -47,7 +50,7 @@ public class CmdFactionsKick extends FactionsCommand if (msender == mplayer) { msg("You can't kick yourself."); - msg("You might want to: %s", Factions.get().getOuterCmdFactions().cmdFactionsLeave.getUseageTemplate(false)); + message(Mson.mson(mson("You might want to: ").color(ChatColor.YELLOW), Factions.get().getOuterCmdFactions().cmdFactionsLeave.getUseageTemplate(false))); return; } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java index 63196431..a088e7bc 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java @@ -1,16 +1,19 @@ package com.massivecraft.factions.cmd; +import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.cmd.req.ReqHasFaction; import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MFlag; import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.event.EventFactionsRelationChange; import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.cmd.MassiveCommand; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.util.Txt; public abstract class CmdFactionsRelationAbstract extends FactionsCommand { @@ -84,8 +87,22 @@ public abstract class CmdFactionsRelationAbstract extends FactionsCommand // inform the other faction of your request else { - otherFaction.msg("%s wishes to be %s.", msenderFaction.describeTo(otherFaction, true), newRelation.getColor()+newRelation.getDescFactionOne()); - otherFaction.msg("Type /"+MConf.get().aliasesF.get(0)+" "+newRelation+" "+msenderFaction.getName()+" to accept."); + MassiveCommand relationshipCommand = null; + if (newRelation.equals(Rel.NEUTRAL)) relationshipCommand = Factions.get().getOuterCmdFactions().cmdFactionsRelationNeutral; + else if (newRelation.equals(Rel.TRUCE)) relationshipCommand = Factions.get().getOuterCmdFactions().cmdFactionsRelationTruce; + else if (newRelation.equals(Rel.ALLY)) relationshipCommand = Factions.get().getOuterCmdFactions().cmdFactionsRelationAlly; + else if (newRelation.equals(Rel.ENEMY)) relationshipCommand = Factions.get().getOuterCmdFactions().cmdFactionsRelationEnemy; + + String command = relationshipCommand.getCommandLine(msenderFaction.getName()); + String tooltip = Txt.parse("Click to %s.", command); + + // Mson creation + Mson factionsRelationshipChange = mson( + Mson.parse("%s wishes to be %s. ", msenderFaction.describeTo(otherFaction, true), newRelation.getColor()+newRelation.getDescFactionOne()), + mson(tooltip).tooltipParse(tooltip).command(command) + ); + + otherFaction.sendMessage(factionsRelationshipChange); msenderFaction.msg("%s were informed that you wish to be %s.", otherFaction.describeTo(msenderFaction, true), newRelation.getColor()+newRelation.getDescFactionOne()); } diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 55945830..4206d1ce 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -1207,17 +1207,17 @@ public class Faction extends Entity implements EconomyParticipator // CONVENIENCE SEND MESSAGE - public boolean sendMessage(String message) + public boolean sendMessage(Object message) { return Mixin.messagePredictate(new FactionEqualsPredictate(this), message); } - public boolean sendMessage(String... messages) + public boolean sendMessage(Object... messages) { return Mixin.messagePredictate(new FactionEqualsPredictate(this), messages); } - public boolean sendMessage(Collection messages) + public boolean sendMessage(Collection messages) { return Mixin.messagePredictate(new FactionEqualsPredictate(this), messages); } diff --git a/src/com/massivecraft/factions/entity/MPerm.java b/src/com/massivecraft/factions/entity/MPerm.java index 362f912e..39eda97b 100644 --- a/src/com/massivecraft/factions/entity/MPerm.java +++ b/src/com/massivecraft/factions/entity/MPerm.java @@ -297,7 +297,7 @@ public class MPerm extends Entity implements Prioritized, Registerable Player player = mplayer.getPlayer(); if (player != null && Perm.ADMIN.has(player)) { - ret += Txt.parse("\nYou can bypass by using " + Factions.get().getOuterCmdFactions().cmdFactionsAdmin.getUseageTemplate(false)); + ret += Txt.parse("\nYou can bypass by using " + Factions.get().getOuterCmdFactions().cmdFactionsAdmin.getUseageTemplate(false).toPlain(true)); } return ret;