mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-11 20:00:46 +00:00
parent
ef49d92c49
commit
879d4913dc
9 changed files with 61 additions and 42 deletions
|
@ -3,6 +3,8 @@ package com.earth2me.essentials.commands;
|
|||
import com.earth2me.essentials.User;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.Util;
|
||||
import com.earth2me.essentials.textreader.ArrayListInput;
|
||||
import com.earth2me.essentials.textreader.TextPager;
|
||||
import java.text.DateFormat;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -19,27 +21,25 @@ public class Commandbalancetop extends EssentialsCommand
|
|||
}
|
||||
private static final int CACHETIME = 2 * 60 * 1000;
|
||||
public static final int MINUSERS = 50;
|
||||
private static List<String> cache = new ArrayList<String>();
|
||||
private static ArrayListInput cache = new ArrayListInput();
|
||||
private static long cacheage = 0;
|
||||
private static ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
||||
|
||||
@Override
|
||||
protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
int max = 10;
|
||||
int page = 0;
|
||||
boolean force = false;
|
||||
if (args.length > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Integer.parseInt(args[0]) < 19)
|
||||
{
|
||||
max = Integer.parseInt(args[0]);
|
||||
}
|
||||
page = Integer.parseInt(args[0]);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
if (args[0].equalsIgnoreCase("force") && sender.isOp()) {
|
||||
if (args[0].equalsIgnoreCase("force") && sender.isOp())
|
||||
{
|
||||
force = true;
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class Commandbalancetop extends EssentialsCommand
|
|||
{
|
||||
if (cacheage > System.currentTimeMillis() - CACHETIME)
|
||||
{
|
||||
outputCache(sender, max);
|
||||
outputCache(sender, page);
|
||||
return;
|
||||
}
|
||||
if (ess.getUserMap().getUniqueUsers() > MINUSERS)
|
||||
|
@ -63,7 +63,7 @@ public class Commandbalancetop extends EssentialsCommand
|
|||
{
|
||||
lock.readLock().unlock();
|
||||
}
|
||||
ess.scheduleAsyncDelayedTask(new Viewer(sender, max, force));
|
||||
ess.scheduleAsyncDelayedTask(new Viewer(sender, page, force));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -71,26 +71,18 @@ public class Commandbalancetop extends EssentialsCommand
|
|||
{
|
||||
sender.sendMessage(_("orderBalances", ess.getUserMap().getUniqueUsers()));
|
||||
}
|
||||
ess.scheduleAsyncDelayedTask(new Viewer(sender, max, force));
|
||||
ess.scheduleAsyncDelayedTask(new Viewer(sender, page, force));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void outputCache(final CommandSender sender, int max)
|
||||
private static void outputCache(final CommandSender sender, int page)
|
||||
{
|
||||
final Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(cacheage);
|
||||
final DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||
sender.sendMessage(_("balanceTop", max, format.format(cal.getTime())));
|
||||
for (String line : cache)
|
||||
{
|
||||
if (max == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
max--;
|
||||
sender.sendMessage(line);
|
||||
}
|
||||
sender.sendMessage(_("balanceTop", format.format(cal.getTime())));
|
||||
new TextPager(cache).showPage(Integer.toString(page), "", "balancetop", sender);
|
||||
}
|
||||
|
||||
|
||||
|
@ -113,7 +105,7 @@ public class Commandbalancetop extends EssentialsCommand
|
|||
{
|
||||
if (force || cacheage <= System.currentTimeMillis() - CACHETIME)
|
||||
{
|
||||
cache.clear();
|
||||
cache.getLines().clear();
|
||||
final Map<String, Double> balances = new HashMap<String, Double>();
|
||||
for (String u : ess.getUserMap().getAllUniqueUsers())
|
||||
{
|
||||
|
@ -133,15 +125,11 @@ public class Commandbalancetop extends EssentialsCommand
|
|||
return -entry1.getValue().compareTo(entry2.getValue());
|
||||
}
|
||||
});
|
||||
int count = 0;
|
||||
int pos = 1;
|
||||
for (Map.Entry<String, Double> entry : sortedEntries)
|
||||
{
|
||||
if (count == 20)
|
||||
{
|
||||
break;
|
||||
}
|
||||
cache.add(entry.getKey() + ", " + Util.formatCurrency(entry.getValue(), ess));
|
||||
count++;
|
||||
cache.getLines().add(pos + ". " + entry.getKey() + ", " + Util.formatCurrency(entry.getValue(), ess));
|
||||
pos++;
|
||||
}
|
||||
cacheage = System.currentTimeMillis();
|
||||
}
|
||||
|
@ -158,13 +146,13 @@ public class Commandbalancetop extends EssentialsCommand
|
|||
private class Viewer implements Runnable
|
||||
{
|
||||
private final transient CommandSender sender;
|
||||
private final transient int max;
|
||||
private final transient int page;
|
||||
private final transient boolean force;
|
||||
|
||||
public Viewer(final CommandSender sender, final int max, final boolean force)
|
||||
public Viewer(final CommandSender sender, final int page, final boolean force)
|
||||
{
|
||||
this.sender = sender;
|
||||
this.max = max;
|
||||
this.page = page;
|
||||
this.force = force;
|
||||
}
|
||||
|
||||
|
@ -176,7 +164,7 @@ public class Commandbalancetop extends EssentialsCommand
|
|||
{
|
||||
if (!force && cacheage > System.currentTimeMillis() - CACHETIME)
|
||||
{
|
||||
outputCache(sender, max);
|
||||
outputCache(sender, page);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -184,7 +172,7 @@ public class Commandbalancetop extends EssentialsCommand
|
|||
{
|
||||
lock.readLock().unlock();
|
||||
}
|
||||
ess.scheduleAsyncDelayedTask(new Calculator(new Viewer(sender, max, force), force));
|
||||
ess.scheduleAsyncDelayedTask(new Calculator(new Viewer(sender, page, force), force));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package com.earth2me.essentials.textreader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class ArrayListInput implements IText
|
||||
{
|
||||
private final transient List<String> lines = new ArrayList<String>();
|
||||
|
||||
@Override
|
||||
public List<String> getLines()
|
||||
{
|
||||
return lines;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getChapters()
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> getBookmarks()
|
||||
{
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
}
|
|
@ -15,7 +15,7 @@ backUsageMsg=\u00a77Teleporterer til tidligere placering.
|
|||
backupFinished=Backup sluttet
|
||||
backupStarted=Backup startet
|
||||
balance=\u00a77Saldo: {0}
|
||||
balanceTop=\u00a77 Top {0} saldoer ({1})
|
||||
balanceTop=\u00a77 Top saldoer ({0})
|
||||
banExempt=\u00a7cDu kan ikke banne den p\u00e5g\u00e6ldende spiller.
|
||||
banIpAddress=\u00a77Bannede IP addresse
|
||||
bannedIpsFileError=Fejl i afl\u00e6sning af banned-ips.txt
|
||||
|
|
|
@ -15,7 +15,7 @@ backUsageMsg=\u00a77Kehre zur letzten Position zur\u00fcck.
|
|||
backupFinished=Backup beendet
|
||||
backupStarted=Backup gestartet
|
||||
balance=\u00a77Geldb\u00f6rse: {0}
|
||||
balanceTop=\u00a77 Top {0} Guthaben ({1})
|
||||
balanceTop=\u00a77 Top Guthaben ({0})
|
||||
banExempt=\u00a7cDu kannst diesen Spieler nicht sperren.
|
||||
banIpAddress=\u00a77IP-Adresse gesperrt.
|
||||
bannedIpsFileError=Fehler beim Lesen von banned-ips.txt
|
||||
|
|
|
@ -15,7 +15,7 @@ backUsageMsg=\u00a77Returning to previous location.
|
|||
backupFinished=Backup finished
|
||||
backupStarted=Backup started
|
||||
balance=\u00a77Balance: {0}
|
||||
balanceTop=\u00a77 Top {0} balances ({1})
|
||||
balanceTop=\u00a77 Top balances ({0})
|
||||
banExempt=\u00a7cYou can not ban that player.
|
||||
banIpAddress=\u00a77Banned IP address
|
||||
bannedIpsFileError=Error reading banned-ips.txt
|
||||
|
|
|
@ -15,7 +15,7 @@ backUsageMsg=\u00a77Volviendo a la localizacion anterior.
|
|||
backupFinished=Copia de seguridad completada
|
||||
backupStarted=Comenzando copia de seguridad
|
||||
balance=\u00a77Cantidad: {0}
|
||||
balanceTop=\u00a77Top {0} cantidades ({1})
|
||||
balanceTop=\u00a77Top cantidades ({0})
|
||||
banExempt=\u00a7cNo puedes banear a ese jugador
|
||||
banIpAddress=\u00a77Direccion IP baneada
|
||||
bannedIpsFileError=Error leyendo banned-ips.txt
|
||||
|
|
|
@ -15,7 +15,7 @@ backUsageMsg=\u00a77Retour \u00e0 votre emplacement pr\u00e9c\u00c3\u00a8dent.
|
|||
backupFinished=Sauvegarde termin\u00e9
|
||||
backupStarted=D\u00e9but de la sauvegarde
|
||||
balance=\u00a77Solde : {0}
|
||||
balanceTop=\u00a77 Meilleurs {0} soldes ({1})
|
||||
balanceTop=\u00a77 Meilleurs soldes ({0})
|
||||
banExempt=\u00a77Vous ne pouvez pas bannir ce joueur.
|
||||
banIpAddress=\u00a77Adresse IP bannie
|
||||
bannedIpsFileError=Erreur de lecture de banned-ips.txt
|
||||
|
|
|
@ -15,7 +15,7 @@ backUsageMsg=\u00a77Naar de vorige locatie aan het gaan.
|
|||
backupFinished=Backup voltooid
|
||||
backupStarted=Backup gestart
|
||||
balance=\u00a77Saldo: {0}
|
||||
balanceTop=\u00a77 Top {0} saldi ({1})
|
||||
balanceTop=\u00a77 Top saldi ({0})
|
||||
banExempt=\u00a77Je kunt deze speler niet verbannen.
|
||||
banIpAddress=\u00a77Verbannen IP-adres
|
||||
bannedIpsFileError=Fout bij het lezen van banned-ips.txt
|
||||
|
|
|
@ -28,8 +28,8 @@ commands:
|
|||
usage: /<command> [player]
|
||||
aliases: [bal,emoney,ebalance,ebal]
|
||||
balancetop:
|
||||
description: Gets the top x balance values. (max 10)
|
||||
usage: /<command> <max>
|
||||
description: Gets the top balance values.
|
||||
usage: /<command> <page>
|
||||
aliases: [baltop,ebaltop,ebalancetop]
|
||||
ban:
|
||||
description: Bans a player.
|
||||
|
|
Loading…
Reference in a new issue