More minor tweaks

This commit is contained in:
Olof Larsson 2013-04-25 16:54:55 +02:00
parent ea06c468fc
commit fffdf07178
11 changed files with 149 additions and 113 deletions

View File

@ -53,6 +53,7 @@ permissions:
factions.show: {description: show faction information, default: false} factions.show: {description: show faction information, default: false}
factions.name: {description: set faction name, default: false} factions.name: {description: set faction name, default: false}
factions.title: {description: set player title, default: false} factions.title: {description: set player title, default: false}
factions.title.color: {description: set player title with color, default: false}
factions.unclaim: {description: unclaim land where you stand, default: false} factions.unclaim: {description: unclaim land where you stand, default: false}
factions.unclaimall: {description: unclaim all land, default: false} factions.unclaimall: {description: unclaim all land, default: false}
factions.version: {description: see plugin version, default: false} factions.version: {description: see plugin version, default: false}
@ -98,6 +99,7 @@ permissions:
factions.show: true factions.show: true
factions.name: true factions.name: true
factions.title: true factions.title: true
factions.title.color: true
factions.unclaim: true factions.unclaim: true
factions.unclaimall: true factions.unclaimall: true
factions.version: true factions.version: true
@ -168,6 +170,7 @@ permissions:
factions.show: true factions.show: true
factions.name: true factions.name: true
factions.title: true factions.title: true
factions.title.color: true
factions.unclaim: true factions.unclaim: true
factions.unclaimall: true factions.unclaimall: true
factions.version: true factions.version: true

View File

@ -54,6 +54,7 @@ public enum Perm
SHOW("show"), SHOW("show"),
NAME("name"), NAME("name"),
TITLE("title"), TITLE("title"),
TITLE_COLOR("title.color"),
UNCLAIM("unclaim"), UNCLAIM("unclaim"),
UNCLAIM_ALL("unclaimall"), UNCLAIM_ALL("unclaimall"),
VERSION("version"), VERSION("version"),

View File

@ -0,0 +1,35 @@
package com.massivecraft.factions;
import java.util.Comparator;
import com.massivecraft.factions.entity.UPlayer;
public class PlayerRoleComparator implements Comparator<UPlayer>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static PlayerRoleComparator i = new PlayerRoleComparator();
public static PlayerRoleComparator get() { return i; }
// -------------------------------------------- //
// OVERRIDE: COMPARATOR
// -------------------------------------------- //
@Override
public int compare(UPlayer o1, UPlayer o2)
{
int ret = 0;
// Null
if (o1 == null && o2 == null) ret = 0;
if (o1 == null) ret = -1;
if (o2 == null) ret = +1;
if (ret != 0) return ret;
// Rank
return o2.getRole().getValue() - o1.getRole().getValue();
}
}

View File

@ -27,7 +27,9 @@ public enum Rel
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
// TODO: Are not enums sorted without this?
private final int value; private final int value;
public int getValue() { return this.value; }
// Used for friendly fire. // Used for friendly fire.
private final boolean friend; private final boolean friend;

View File

@ -183,7 +183,7 @@ public class TerritoryAccess
public boolean subjectAccessIsRestricted(Object testSubject) public boolean subjectAccessIsRestricted(Object testSubject)
{ {
Faction hostFaction = FactionColls.get().get(testSubject).get(this.getHostFactionId()); Faction hostFaction = FactionColls.get().get(testSubject).get(this.getHostFactionId());
return ( ! this.isHostFactionAllowed() && this.doesHostFactionMatch(testSubject) && ! FPerm.ACCESS.has(testSubject, hostFaction)); return ( ! this.isHostFactionAllowed() && this.doesHostFactionMatch(testSubject) && ! FPerm.ACCESS.has(testSubject, hostFaction, false));
} }
//----------------------------------------------// //----------------------------------------------//

View File

@ -57,7 +57,7 @@ public class CmdFactionsKick extends FCommand
// FPerm // FPerm
Faction uplayerFaction = uplayer.getFaction(); Faction uplayerFaction = uplayer.getFaction();
if (!FPerm.KICK.has(sender, uplayerFaction)) return; if (!FPerm.KICK.has(sender, uplayerFaction, true)) return;
// Event // Event
FactionsEventMembershipChange event = new FactionsEventMembershipChange(sender, uplayer, FactionColls.get().get(uplayer).getNone(), MembershipChangeReason.KICK); FactionsEventMembershipChange event = new FactionsEventMembershipChange(sender, uplayer, FactionColls.get().get(uplayer).getNone(), MembershipChangeReason.KICK);

View File

@ -1,7 +1,7 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -15,6 +15,7 @@ import com.massivecraft.factions.event.FactionsEventChunkChangeType;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.PlayerRoleComparator;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.mixin.Mixin; import com.massivecraft.mcore.mixin.Mixin;
@ -38,35 +39,29 @@ public class CmdFactionsShow extends FCommand
@Override @Override
public void perform() public void perform()
{ {
// Args
Faction faction = this.arg(0, ARFaction.get(usenderFaction), usenderFaction); Faction faction = this.arg(0, ARFaction.get(usenderFaction), usenderFaction);
if (faction == null) return; if (faction == null) return;
// Data precalculation
UConf uconf = UConf.get(faction); UConf uconf = UConf.get(faction);
//boolean none = faction.isNone();
boolean normal = faction.isNormal();
// INFO: Description // INFO: Description
msg(Txt.titleize(faction.getName(usender))); msg(Txt.titleize(faction.getName(usender)));
msg("<a>Description: <i>%s", faction.getDescription()); msg("<a>Description: <i>%s", faction.getDescription());
if (normal)
{
// INFO: Age // INFO: Age
long ageMillis = faction.getCreatedAtMillis() - System.currentTimeMillis(); long ageMillis = faction.getCreatedAtMillis() - System.currentTimeMillis();
LinkedHashMap<TimeUnit, Long> ageUnitcounts = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(ageMillis, TimeUnit.getAllButMillis()), 3); LinkedHashMap<TimeUnit, Long> ageUnitcounts = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(ageMillis, TimeUnit.getAllButMillis()), 3);
String ageString = TimeDiffUtil.formatedVerboose(ageUnitcounts, "<i>"); String ageString = TimeDiffUtil.formatedVerboose(ageUnitcounts, "<i>");
msg("<a>Age: <i>%s", ageString); msg("<a>Age: <i>%s", ageString);
// Display important flags
// TODO: Find the non default flags, and display them instead.
if (faction.getFlag(FFlag.PERMANENT))
{
msg("<a>This faction is permanent - remaining even with no members.");
}
if (faction.getFlag(FFlag.PEACEFUL))
{
msg("<a>This faction is peaceful - in truce with everyone.");
}
// INFO: Open // INFO: Open
msg("<a>Open: <i>"+(faction.isOpen() ? "<lime>Yes <i>- anyone can join" : "<rose>No <i>- only invited people can join")); msg("<a>Open: <i>"+(faction.isOpen() ? "<lime>Yes<i>, anyone can join" : "<rose>No<i>, only invited people can join"));
// INFO: Power // INFO: Power
double powerBoost = faction.getPowerBoost(); double powerBoost = faction.getPowerBoost();
@ -105,6 +100,19 @@ public class CmdFactionsShow extends FCommand
} }
} }
// Display important flags
// TODO: Find the non default flags, and display them instead.
if (faction.getFlag(FFlag.PERMANENT))
{
msg("<a>This faction is permanent - remaining even with no followers.");
}
if (faction.getFlag(FFlag.PEACEFUL))
{
msg("<a>This faction is peaceful - in truce with everyone.");
}
}
String sepparator = Txt.parse("<i>")+", "; String sepparator = Txt.parse("<i>")+", ";
// List the relations to other factions // List the relations to other factions
@ -119,68 +127,35 @@ public class CmdFactionsShow extends FCommand
sendMessage(Txt.parse("<a>In Truce with: ") + Txt.implode(relationNames.get(Rel.TRUCE), sepparator)); sendMessage(Txt.parse("<a>In Truce with: ") + Txt.implode(relationNames.get(Rel.TRUCE), sepparator));
} }
sendMessage(Txt.parse("<a>Allied to: ") + Txt.implode(relationNames.get(Rel.ALLY), sepparator)); sendMessage(Txt.parse("<a>Allies: ") + Txt.implode(relationNames.get(Rel.ALLY), sepparator));
sendMessage(Txt.parse("<a>Enemies: ") + Txt.implode(relationNames.get(Rel.ENEMY), sepparator)); sendMessage(Txt.parse("<a>Enemies: ") + Txt.implode(relationNames.get(Rel.ENEMY), sepparator));
// List the members... // List the followers...
List<String> followerNamesOnline = new ArrayList<String>();
List<String> followerNamesOffline = new ArrayList<String>();
Collection<UPlayer> leaders = faction.getUPlayersWhereRole(Rel.LEADER); List<UPlayer> followers = faction.getUPlayers();
Collection<UPlayer> officers = faction.getUPlayersWhereRole(Rel.OFFICER); Collections.sort(followers, PlayerRoleComparator.get());
Collection<UPlayer> normals = faction.getUPlayersWhereRole(Rel.MEMBER);
Collection<UPlayer> recruits = faction.getUPlayersWhereRole(Rel.RECRUIT);
List<String> memberOnlineNames = new ArrayList<String>(); for (UPlayer follower : followers)
List<String> memberOfflineNames = new ArrayList<String>();
for (UPlayer follower : leaders)
{ {
if (follower.isOnline() && Mixin.isVisible(me, follower.getId())) if (follower.isOnline() && Mixin.isVisible(sender, follower.getId()))
{ {
memberOnlineNames.add(follower.getNameAndTitle(usender)); followerNamesOnline.add(follower.getNameAndTitle(usender));
} }
else else if (normal)
{ {
memberOfflineNames.add(follower.getNameAndTitle(usender)); // For the non-faction we skip the offline members since they are far to many (infinate almost)
followerNamesOffline.add(follower.getNameAndTitle(usender));
} }
} }
for (UPlayer follower : officers) sendMessage(Txt.parse("<a>Followers online (%s): ", followerNamesOnline.size()) + Txt.implode(followerNamesOnline, sepparator));
if (normal)
{ {
if (follower.isOnline() && Mixin.isVisible(me, follower.getId())) sendMessage(Txt.parse("<a>Followers offline (%s): ", followerNamesOffline.size()) + Txt.implode(followerNamesOffline, sepparator));
{
memberOnlineNames.add(follower.getNameAndTitle(usender));
}
else
{
memberOfflineNames.add(follower.getNameAndTitle(usender));
} }
} }
for (UPlayer follower : normals)
{
if (follower.isOnline() && Mixin.isVisible(me, follower.getId()))
{
memberOnlineNames.add(follower.getNameAndTitle(usender));
}
else
{
memberOfflineNames.add(follower.getNameAndTitle(usender));
}
}
for (UPlayer follower : recruits)
{
if (follower.isOnline())
{
memberOnlineNames.add(follower.getNameAndTitle(usender));
}
else
{
memberOfflineNames.add(follower.getNameAndTitle(usender));
}
}
sendMessage(Txt.parse("<a>Members online: ") + Txt.implode(memberOnlineNames, sepparator));
sendMessage(Txt.parse("<a>Members offline: ") + Txt.implode(memberOfflineNames, sepparator));
}
} }

View File

@ -1,5 +1,7 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import org.bukkit.ChatColor;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.arg.ARUPlayer; import com.massivecraft.factions.cmd.arg.ARUPlayer;
@ -9,6 +11,7 @@ import com.massivecraft.factions.entity.UPlayer;
import com.massivecraft.factions.event.FactionsEventTitleChange; import com.massivecraft.factions.event.FactionsEventTitleChange;
import com.massivecraft.mcore.cmd.arg.ARString; import com.massivecraft.mcore.cmd.arg.ARString;
import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.util.Txt;
public class CmdFactionsTitle extends FCommand public class CmdFactionsTitle extends FCommand
{ {
@ -34,6 +37,12 @@ public class CmdFactionsTitle extends FCommand
String newTitle = this.argConcatFrom(1, ARString.get(), ""); String newTitle = this.argConcatFrom(1, ARString.get(), "");
if (newTitle == null) return; if (newTitle == null) return;
newTitle = Txt.parse(newTitle);
if (!Perm.TITLE_COLOR.has(sender, false))
{
newTitle = ChatColor.stripColor(newTitle);
}
// Verify // Verify
if ( ! canIAdministerYou(usender, you)) return; if ( ! canIAdministerYou(usender, you)) return;

View File

@ -284,6 +284,13 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
} }
} }
// NOTE: That we parse the title here is considered part of the 1.8 --> 2.0 migration.
// This should be removed once the migration phase is considered to be over.
if (target != null)
{
target = Txt.parse(target);
}
// Detect Nochange // Detect Nochange
if (MUtil.equals(this.title, target)) return; if (MUtil.equals(this.title, target)) return;
@ -421,44 +428,48 @@ public class UPlayer extends SenderEntity<UPlayer> implements EconomyParticipato
// Base concatenations: // Base concatenations:
public String getNameAndSomething(String something) public String getNameAndSomething(String color, String something)
{ {
String ret = this.getRole().getPrefix(); String ret = "";
ret += color;
ret += this.getRole().getPrefix();
if (something != null && something.length() > 0) if (something != null && something.length() > 0)
{ {
ret += something+" "; ret += something;
ret += " ";
ret += color;
} }
ret += this.getName(); ret += this.getName();
return ret; return ret;
} }
public String getNameAndTitle() public String getNameAndFactionName()
{
return this.getNameAndSomething("", this.getFactionName());
}
public String getNameAndTitle(String color)
{ {
if (this.hasTitle()) if (this.hasTitle())
{ {
return this.getNameAndSomething(this.getTitle()); return this.getNameAndSomething(color, this.getTitle());
} }
else else
{ {
return this.getNameAndSomething(null); return this.getNameAndSomething(color, null);
} }
} }
public String getNameAndFactionName()
{
return this.getNameAndSomething(this.getFactionName());
}
// Colored concatenations: // Colored concatenations:
// These are used in information messages // These are used in information messages
public String getNameAndTitle(Faction faction) public String getNameAndTitle(Faction faction)
{ {
return this.getColorTo(faction)+this.getNameAndTitle(); return this.getNameAndTitle(this.getColorTo(faction).toString());
} }
public String getNameAndTitle(UPlayer uplayer) public String getNameAndTitle(UPlayer uplayer)
{ {
return this.getColorTo(uplayer)+this.getNameAndTitle(); return this.getNameAndTitle(this.getColorTo(uplayer).toString());
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -89,7 +89,7 @@ public class Econ
if (i == fI && fI == fYou) return true; if (i == fI && fI == fYou) return true;
// Factions can be controlled by those that have permissions // Factions can be controlled by those that have permissions
if (you instanceof Faction && FPerm.WITHDRAW.has(i, fYou)) return true; if (you instanceof Faction && FPerm.WITHDRAW.has(i, fYou, false)) return true;
// Otherwise you may not! ;,,; // Otherwise you may not! ;,,;
i.msg("<h>%s<i> lacks permission to control <h>%s's<i> money.", i.describeTo(i, true), you.describeTo(i)); i.msg("<h>%s<i> lacks permission to control <h>%s's<i> money.", i.describeTo(i, true), you.describeTo(i));

View File

@ -47,7 +47,7 @@ public class RelationUtil
} }
else if (thatFaction == myFaction) else if (thatFaction == myFaction)
{ {
ret = uplayerthat.getNameAndTitle(); ret = uplayerthat.getNameAndTitle(myFaction);
} }
else else
{ {