This repository has been archived by the owner on Nov 5, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8322528
commit 8e13c1c
Showing
9 changed files
with
288 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/com/massivecraft/factions/PlayerInactivityComparator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.massivecraft.factions; | ||
|
||
import java.util.Comparator; | ||
|
||
import com.massivecraft.factions.entity.MPlayer; | ||
|
||
public class PlayerInactivityComparator implements Comparator<MPlayer> | ||
{ | ||
// -------------------------------------------- // | ||
// INSTANCE & CONSTRUCT | ||
// -------------------------------------------- // | ||
|
||
private static PlayerInactivityComparator i = new PlayerInactivityComparator(); | ||
public static PlayerInactivityComparator get() { return i; } | ||
|
||
// -------------------------------------------- // | ||
// OVERRIDE: COMPARATOR | ||
// -------------------------------------------- // | ||
|
||
@Override | ||
public int compare(MPlayer m1, MPlayer m2) | ||
{ | ||
// Null | ||
if (m1 == null && m2 == null) return 0; | ||
else if (m1 == null) return -1; | ||
else if (m2 == null) return +1; | ||
|
||
// Online | ||
boolean o1 = m1.isOnline(); | ||
boolean o2 = m2.isOnline(); | ||
|
||
if (o1 && o2) return 0; | ||
else if (o1) return -1; | ||
else if (o2) return +1; | ||
|
||
// Inactivity Time | ||
long r1 = m1.getLastActivityMillis(); | ||
long r2 = m2.getLastActivityMillis(); | ||
|
||
return (int) (r1 - r2); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.massivecraft.factions; | ||
|
||
import java.util.Comparator; | ||
|
||
import com.massivecraft.factions.entity.MPlayer; | ||
|
||
public class PlayerPowerComparator implements Comparator<MPlayer> | ||
{ | ||
// -------------------------------------------- // | ||
// INSTANCE & CONSTRUCT | ||
// -------------------------------------------- // | ||
|
||
private static PlayerPowerComparator i = new PlayerPowerComparator(); | ||
public static PlayerPowerComparator get() { return i; } | ||
|
||
// -------------------------------------------- // | ||
// OVERRIDE: COMPARATOR | ||
// -------------------------------------------- // | ||
|
||
@Override | ||
public int compare(MPlayer m1, MPlayer m2) | ||
{ | ||
int ret = 0; | ||
|
||
// Null | ||
if (m1 == null && m2 == null) return 0; | ||
else if (m1 == null) return -1; | ||
else if (m2 == null) return +1; | ||
|
||
// Power | ||
int p1 = m1.getPowerRounded(); | ||
int p2 = m2.getPowerRounded(); | ||
ret = p1 - p2; | ||
if (ret != 0) return ret; | ||
|
||
// MaxPower | ||
int max1 = m1.getPowerMaxRounded(); | ||
int max2 = m2.getPowerMaxRounded(); | ||
ret = max1 - max2; | ||
|
||
return ret; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
src/com/massivecraft/factions/cmd/CmdFactionsStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package com.massivecraft.factions.cmd; | ||
|
||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
|
||
import com.massivecraft.factions.Perm; | ||
import com.massivecraft.factions.PlayerInactivityComparator; | ||
import com.massivecraft.factions.cmd.arg.ARFaction; | ||
import com.massivecraft.factions.cmd.arg.ARSortMPlayer; | ||
import com.massivecraft.factions.entity.Faction; | ||
import com.massivecraft.factions.entity.MPerm; | ||
import com.massivecraft.factions.entity.MPlayer; | ||
import com.massivecraft.massivecore.cmd.MassiveCommandException; | ||
import com.massivecraft.massivecore.cmd.arg.ARInteger; | ||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm; | ||
import com.massivecraft.massivecore.pager.PagerSimple; | ||
import com.massivecraft.massivecore.pager.Stringifier; | ||
import com.massivecraft.massivecore.util.TimeDiffUtil; | ||
import com.massivecraft.massivecore.util.TimeUnit; | ||
import com.massivecraft.massivecore.util.Txt; | ||
|
||
|
||
public class CmdFactionsStatus extends FactionsCommand | ||
{ | ||
// -------------------------------------------- // | ||
// CONSTRUCT | ||
// -------------------------------------------- // | ||
|
||
public CmdFactionsStatus() | ||
{ | ||
// Aliases | ||
this.addAliases("s", "status"); | ||
|
||
// Args | ||
this.addOptionalArg("page", "1"); | ||
this.addOptionalArg("faction", "you"); | ||
this.addOptionalArg("sort by", "time"); | ||
|
||
// Requirements | ||
this.addRequirements(ReqHasPerm.get(Perm.STATUS.node)); | ||
} | ||
|
||
// -------------------------------------------- // | ||
// OVERRIDE | ||
// -------------------------------------------- // | ||
|
||
@Override | ||
public void perform() throws MassiveCommandException | ||
{ | ||
// Args | ||
Integer pageHumanBased = this.arg(0, ARInteger.get(), 1); | ||
Faction faction = this.arg(1, ARFaction.get(), msenderFaction); | ||
Comparator<MPlayer> sortedBy = this.arg(2, ARSortMPlayer.get(), PlayerInactivityComparator.get()); | ||
|
||
// MPerm | ||
if ( ! MPerm.getPermStatus().has(msender, faction, true)) return; | ||
|
||
// Sort list | ||
final List<MPlayer> mplayers = faction.getMPlayers(); | ||
Collections.sort(mplayers, sortedBy); | ||
|
||
// Create Pager | ||
final PagerSimple<MPlayer> pager = new PagerSimple<MPlayer>(mplayers, sender); | ||
String pagerTitle = Txt.parse("<i>Status of %s<i>.", faction.describeTo(msender, true)); | ||
|
||
// Use Pager | ||
List<String> messages = pager.getPageTxt(pageHumanBased, pagerTitle, new Stringifier<MPlayer>(){ | ||
|
||
@Override | ||
public String toString(MPlayer mplayer) | ||
{ | ||
// Name | ||
String displayName = mplayer.getNameAndSomething(msender.getColorTo(mplayer).toString(), ""); | ||
int length = 15 - displayName.length(); | ||
length = length <= 0 ? 1 : length; | ||
String whiteSpace = Txt.repeat(" ", length); | ||
|
||
// Power | ||
double currentPower = mplayer.getPower(); | ||
double maxPower = mplayer.getPowerMax(); | ||
String color; | ||
double percent = currentPower / maxPower; | ||
|
||
if (percent > 0.75) | ||
{ | ||
color = "<green>"; | ||
} | ||
else if (percent > 0.5) | ||
{ | ||
color = "<yellow>"; | ||
} | ||
else if (percent > 0.25) | ||
{ | ||
color = "<rose>"; | ||
} | ||
else | ||
{ | ||
color = "<red>"; | ||
} | ||
|
||
String power = Txt.parse("<art>Power: %s%.0f<gray>/<green>%.0f", Txt.parse(color), currentPower, maxPower); | ||
|
||
// Time | ||
long lastActiveMillis = mplayer.getLastActivityMillis() - System.currentTimeMillis(); | ||
LinkedHashMap<TimeUnit, Long> activeTimes = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(lastActiveMillis, TimeUnit.getAllButMillis()), 3); | ||
String lastActive = mplayer.isOnline() ? Txt.parse("<lime>Online right now.") : Txt.parse("<i>Last active: " + TimeDiffUtil.formatedMinimal(activeTimes, "<i>")); | ||
|
||
return Txt.parse("%s%s %s %s", displayName, whiteSpace, power, lastActive); | ||
} | ||
|
||
}); | ||
|
||
// Send message | ||
sendMessage(messages); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.massivecraft.factions.cmd.arg; | ||
|
||
import java.util.Collection; | ||
import java.util.Comparator; | ||
|
||
import org.bukkit.command.CommandSender; | ||
|
||
import com.massivecraft.factions.PlayerInactivityComparator; | ||
import com.massivecraft.factions.PlayerPowerComparator; | ||
import com.massivecraft.factions.PlayerRoleComparator; | ||
import com.massivecraft.factions.entity.MPlayer; | ||
import com.massivecraft.massivecore.cmd.arg.ARAbstractSelect; | ||
import com.massivecraft.massivecore.util.MUtil; | ||
|
||
public class ARSortMPlayer extends ARAbstractSelect<Comparator<MPlayer>> | ||
{ | ||
// -------------------------------------------- // | ||
// INSTANCE & CONSTRUCT | ||
// -------------------------------------------- // | ||
|
||
private static ARSortMPlayer i = new ARSortMPlayer(); | ||
public static ARSortMPlayer get() { return i; } | ||
|
||
// -------------------------------------------- // | ||
// OVERRIDE | ||
// -------------------------------------------- // | ||
|
||
@Override | ||
public String typename() | ||
{ | ||
return "player sorter"; | ||
} | ||
|
||
@Override | ||
public Comparator<MPlayer> select(String sortedBy, CommandSender sender) | ||
{ | ||
sortedBy = sortedBy.toLowerCase(); | ||
|
||
if (sortedBy.startsWith("r")) | ||
{ | ||
// Sort by rank | ||
return PlayerRoleComparator.get(); | ||
} | ||
else if (sortedBy.startsWith("p")) | ||
{ | ||
// Sort by power | ||
return PlayerPowerComparator.get(); | ||
} | ||
else if (sortedBy.startsWith("t")) | ||
{ | ||
// Sort by time | ||
return PlayerInactivityComparator.get(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public Collection<String> altNames(CommandSender sender) | ||
{ | ||
return MUtil.list("rank", "power", "time"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters