mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-28 03:57:48 +01:00
Add a LagMeter (ticks per second) to the /gc command. This command can now be accessed with /lag as well. Also added a simple /vanish command, with the extra node essentials.vanish.see
If you require a more advanced vanish solution checkout VanishNoPacket from mbaxter.
This commit is contained in:
parent
fee3d7c0d3
commit
1247401a5f
@ -84,6 +84,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
private transient ExecuteTimer execTimer;
|
||||
private transient I18n i18n;
|
||||
private transient Metrics metrics;
|
||||
private transient LagMeter lagMeter;
|
||||
|
||||
@Override
|
||||
public ISettings getSettings()
|
||||
@ -240,6 +241,10 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
|
||||
final EssentialsTimer timer = new EssentialsTimer(this);
|
||||
getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 100);
|
||||
|
||||
lagMeter = new LagMeter();
|
||||
getScheduler().scheduleSyncRepeatingTask(this, lagMeter, 0, 40);
|
||||
|
||||
Economy.setEss(this);
|
||||
execTimer.mark("RegListeners");
|
||||
|
||||
@ -264,6 +269,13 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
for (Player p : getServer().getOnlinePlayers())
|
||||
{
|
||||
if (getUser(p).isVanished())
|
||||
{
|
||||
p.sendMessage(ChatColor.RED + _("unvanishedReload"));
|
||||
}
|
||||
}
|
||||
i18n.onDisable();
|
||||
Economy.setEss(null);
|
||||
Trade.closeLog();
|
||||
@ -614,6 +626,10 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
return i18n;
|
||||
}
|
||||
|
||||
public LagMeter getLagMeter()
|
||||
{
|
||||
return lagMeter;
|
||||
}
|
||||
|
||||
private static class EssentialsWorldListener implements Listener, Runnable
|
||||
{
|
||||
|
@ -71,4 +71,5 @@ public interface IEssentials extends Plugin
|
||||
|
||||
void setMetrics(Metrics metrics);
|
||||
|
||||
LagMeter getLagMeter();
|
||||
}
|
||||
|
44
Essentials/src/com/earth2me/essentials/LagMeter.java
Normal file
44
Essentials/src/com/earth2me/essentials/LagMeter.java
Normal file
@ -0,0 +1,44 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
|
||||
public class LagMeter implements Runnable
|
||||
{
|
||||
private transient long lastPoll = System.currentTimeMillis() - 3000;
|
||||
private final transient LinkedList<Float> history = new LinkedList<Float>();
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
long timeSpent = (now - lastPoll) / 1000;
|
||||
if (timeSpent == 0)
|
||||
{
|
||||
timeSpent = 1;
|
||||
}
|
||||
if (history.size() > 10)
|
||||
{
|
||||
history.remove();
|
||||
}
|
||||
float tps = 40f / timeSpent;
|
||||
if (tps <= 20)
|
||||
{
|
||||
history.add(tps);
|
||||
}
|
||||
lastPoll = now;
|
||||
}
|
||||
|
||||
public float getAverageTPS()
|
||||
{
|
||||
float avg = 0;
|
||||
for (Float f : history)
|
||||
{
|
||||
if (f != null)
|
||||
{
|
||||
avg += f;
|
||||
}
|
||||
}
|
||||
return avg / history.size();
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
private CommandSender replyTo = null;
|
||||
private transient User teleportRequester;
|
||||
private transient boolean teleportRequestHere;
|
||||
private transient boolean vanished;
|
||||
private transient final Teleport teleport;
|
||||
private transient long teleportRequestTime;
|
||||
private transient long lastOnlineActivity;
|
||||
@ -640,4 +641,14 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
|
||||
{
|
||||
return teleportInvulnerabilityTimestamp != 0 && teleportInvulnerabilityTimestamp >= System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public boolean isVanished()
|
||||
{
|
||||
return vanished;
|
||||
}
|
||||
|
||||
public void toggleVanished()
|
||||
{
|
||||
vanished = !vanished;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -16,6 +17,21 @@ public class Commandgc extends EssentialsCommand
|
||||
@Override
|
||||
protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
float tps = ess.getLagMeter().getAverageTPS();
|
||||
ChatColor color;
|
||||
if (tps >= 18)
|
||||
{
|
||||
color = ChatColor.GREEN;
|
||||
}
|
||||
else if (tps >= 15)
|
||||
{
|
||||
color = ChatColor.YELLOW;
|
||||
}
|
||||
else
|
||||
{
|
||||
color = ChatColor.RED;
|
||||
}
|
||||
sender.sendMessage(_("tps", "" + color + tps));
|
||||
sender.sendMessage(_("gcmax", (Runtime.getRuntime().maxMemory() / 1024 / 1024)));
|
||||
sender.sendMessage(_("gctotal", (Runtime.getRuntime().totalMemory() / 1024 / 1024)));
|
||||
sender.sendMessage(_("gcfree", (Runtime.getRuntime().freeMemory() / 1024 / 1024)));
|
||||
|
@ -0,0 +1,40 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public class Commandvanish extends EssentialsCommand
|
||||
{
|
||||
public Commandvanish()
|
||||
{
|
||||
super("vanish");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception
|
||||
{
|
||||
if (user.isVanished())
|
||||
{
|
||||
for (Player p : server.getOnlinePlayers())
|
||||
{
|
||||
p.showPlayer(user);
|
||||
}
|
||||
user.sendMessage(ChatColor.GREEN + _("vanished"));
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Player p : server.getOnlinePlayers())
|
||||
{
|
||||
if (!ess.getUser(p).isAuthorized("essentials.vanish.see"))
|
||||
{
|
||||
p.hidePlayer(user);
|
||||
}
|
||||
user.sendMessage(ChatColor.GREEN + _("unvanished"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -364,6 +364,7 @@ tradeSignEmptyOwner=There is nothing to collect from this trade sign.
|
||||
treeFailure=\u00a7cTree generation failure. Try again on grass or dirt.
|
||||
treeSpawned=\u00a77Tree spawned.
|
||||
true=true
|
||||
tps=Current TPS = {0}
|
||||
typeTpaccept=\u00a77To teleport, type \u00a7c/tpaccept\u00a77.
|
||||
typeTpdeny=\u00a77To deny this request, type \u00a7c/tpdeny\u00a77.
|
||||
typeWorldName=\u00a77You can also type the name of a specific world.
|
||||
@ -377,6 +378,8 @@ unknownItemName=Unknown item name: {0}
|
||||
unlimitedItemPermission=\u00a7cNo permission for unlimited item {0}.
|
||||
unlimitedItems=Unlimited items:
|
||||
unmutedPlayer=Player {0} unmuted.
|
||||
unvanished=You are once again visible.
|
||||
unvanishedReload=A reload has forced you to become visible.
|
||||
upgradingFilesError=Error while upgrading the files
|
||||
userDoesNotExist=The user {0} does not exist.
|
||||
userIsAway={0} is now AFK
|
||||
@ -386,6 +389,7 @@ userUsedPortal={0} used an existing exit portal.
|
||||
userdataMoveBackError=Failed to move userdata/{0}.tmp to userdata/{1}
|
||||
userdataMoveError=Failed to move userdata/{0} to userdata/{1}.tmp
|
||||
usingTempFolderForTesting=Using temp folder for testing:
|
||||
vanished=You have now been vanished.
|
||||
versionMismatch=Version mismatch! Please update {0} to the same version.
|
||||
versionMismatchAll=Version mismatch! Please update all Essentials jars to the same version.
|
||||
voiceSilenced=\u00a77Your voice has been silenced
|
||||
|
@ -119,9 +119,9 @@ commands:
|
||||
usage: /<command> [player]
|
||||
aliases: [coords,egetpos,position,eposition,whereami,ewhereami]
|
||||
gc:
|
||||
description: Reports garbage collection info; useful to developers.
|
||||
description: Reports garbage collection and tick info; useful to developers.
|
||||
usage: /<command>
|
||||
aliases: [mem,memory,egc,emem,ememory]
|
||||
aliases: [elag,lag,mem,memory,egc,emem,ememory]
|
||||
give:
|
||||
description: Give a player an item.
|
||||
usage: /<command> <player> <item|numeric> [amount <enchantmentname[:level]> ...]
|
||||
@ -405,6 +405,10 @@ commands:
|
||||
description: Allows the unlimited placing of items.
|
||||
usage: /<command> <list|item|clear> [player]
|
||||
aliases: [eunlimited,ul,unl,eul,eunl]
|
||||
vanish:
|
||||
description: Hide yourself from other players.
|
||||
usage: /<command>
|
||||
aliases: [evanish]
|
||||
warp:
|
||||
description: List all warps or warp to the specified location.
|
||||
usage: /<command> <pagenumber|warp> [player]
|
||||
|
Loading…
Reference in New Issue
Block a user