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