Added /health (try 2)

This commit is contained in:
Jerom van der Sar 2012-12-28 00:27:59 +01:00
commit f0ca909069
11 changed files with 251 additions and 35 deletions

View File

@ -134,9 +134,7 @@ is divided into following sections:
</or>
</condition>
<condition property="have.tests">
<or>
<available file="${test.src.dir}"/>
</or>
<or/>
</condition>
<condition property="have.sources">
<or>
@ -229,7 +227,6 @@ is divided into following sections:
</target>
<target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
<fail unless="src.dir">Must set src.dir</fail>
<fail unless="test.src.dir">Must set test.src.dir</fail>
<fail unless="build.dir">Must set build.dir</fail>
<fail unless="dist.dir">Must set dist.dir</fail>
<fail unless="build.classes.dir">Must set build.classes.dir</fail>
@ -403,11 +400,7 @@ is divided into following sections:
<sequential>
<property name="junit.forkmode" value="perTest"/>
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
<batchtest todir="${build.test.results.dir}">
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
<filename name="@{testincludes}"/>
</fileset>
</batchtest>
<batchtest todir="${build.test.results.dir}"/>
<syspropertyset>
<propertyref prefix="test-sys-prop."/>
<mapper from="test-sys-prop.*" to="*" type="glob"/>
@ -432,11 +425,7 @@ is divided into following sections:
<condition else="" property="testng.methods.arg" value="@{testincludes}.@{testmethods}">
<isset property="test.method"/>
</condition>
<union id="test.set">
<fileset dir="${test.src.dir}" excludes="@{excludes},**/*.xml,${excludes}" includes="@{includes}">
<filename name="@{testincludes}"/>
</fileset>
</union>
<union id="test.set"/>
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
<testng classfilesetref="test.set" failureProperty="tests.failed" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="TotalFreedomMod" testname="TestNG tests" workingDir="${work.dir}">
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
@ -544,11 +533,7 @@ is divided into following sections:
<sequential>
<property name="junit.forkmode" value="perTest"/>
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
<batchtest todir="${build.test.results.dir}">
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
<filename name="@{testincludes}"/>
</fileset>
</batchtest>
<batchtest todir="${build.test.results.dir}"/>
<syspropertyset>
<propertyref prefix="test-sys-prop."/>
<mapper from="test-sys-prop.*" to="*" type="glob"/>
@ -1231,13 +1216,11 @@ is divided into following sections:
<!-- You can override this target in the ../build.xml file. -->
</target>
<target if="do.depend.true" name="-compile-test-depend">
<j2seproject3:depend classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/>
<j2seproject3:depend classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir=""/>
</target>
<target depends="init,deps-jar,compile,-pre-pre-compile-test,-pre-compile-test,-compile-test-depend" if="have.tests" name="-do-compile-test">
<j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" processorpath="${javac.test.processorpath}" srcdir="${test.src.dir}"/>
<copy todir="${build.test.classes.dir}">
<fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
</copy>
<j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" processorpath="${javac.test.processorpath}" srcdir=""/>
<copy todir="${build.test.classes.dir}"/>
</target>
<target name="-post-compile-test">
<!-- Empty placeholder for easier customization. -->
@ -1251,10 +1234,8 @@ is divided into following sections:
<target depends="init,deps-jar,compile,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single">
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
<j2seproject3:force-recompile destdir="${build.test.classes.dir}"/>
<j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" excludes="" includes="${javac.includes}" processorpath="${javac.test.processorpath}" sourcepath="${test.src.dir}" srcdir="${test.src.dir}"/>
<copy todir="${build.test.classes.dir}">
<fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
</copy>
<j2seproject3:javac apgeneratedsrcdir="${build.test.classes.dir}" classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" excludes="" includes="${javac.includes}" processorpath="${javac.test.processorpath}" sourcepath="" srcdir=""/>
<copy todir="${build.test.classes.dir}"/>
</target>
<target name="-post-compile-test-single">
<!-- Empty placeholder for easier customization. -->
@ -1397,4 +1378,4 @@ is divided into following sections:
</propertyset>
</ant>
</target>
</project>
</project>

View File

@ -82,4 +82,3 @@ run.test.classpath=\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

View File

@ -7,9 +7,7 @@
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
<test-roots/>
</data>
</configuration>
</project>

View File

@ -0,0 +1,56 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_TickMeter;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = ADMIN_LEVEL.SUPER, source = SOURCE_TYPE_ALLOWED.BOTH, ignore_permissions = false)
public class Command_health extends TFM_Command
{
@Override
public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
Runnable task;
task = new Runnable() // async
{
@Override
public void run()
{
try
{
TFM_TickMeter meter = new TFM_TickMeter(plugin);
meter.startTicking();
Thread.sleep(1000); // ticks per second
meter.stopTicking();
Runtime runtime = Runtime.getRuntime();
int mb = 1048576; // 1024 * 1024
float usedMem = runtime.totalMemory() - runtime.freeMemory();
TFM_Util.playerMsg(sender, "Reserved Memory: " + runtime.totalMemory() / mb + "mb");
TFM_Util.playerMsg(sender, "Used Memory: " + new DecimalFormat("#").format(usedMem / mb) + "mb (" + new DecimalFormat("#").format(usedMem/runtime.totalMemory()*100) + "%)");
TFM_Util.playerMsg(sender, "Max Memory: " + runtime.maxMemory() / mb + "mb");
TFM_Util.playerMsg(sender, "Ticks per second: " + (meter.getTicks() == 20 ? ChatColor.GREEN : ChatColor.RED) + meter.getTicks());
}
catch (Exception iex)
{
TFM_Log.warning("Exception in TFM_TickMeter: Thread was interupted in sleeping process.");
TFM_Log.warning(ExceptionUtils.getStackTrace(iex));
}
}
};
new Thread(task, "TickMeter").start();
return true;
}
}

View File

@ -0,0 +1,46 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_UserInfo;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = ADMIN_LEVEL.SUPER, source = SOURCE_TYPE_ALLOWED.BOTH, ignore_permissions = false)
public class Command_lastcmd extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length == 0)
{
return false;
}
Player p;
try
{
p = getPlayer(args[0]);
}
catch (CantFindPlayerException ex)
{
sender.sendMessage(ex.getMessage());
return true;
}
TFM_UserInfo playerdata = TFM_UserInfo.getPlayerData(p);
if (playerdata != null)
{
String last_command = playerdata.getLastCommand();
if (last_command.isEmpty())
{
last_command = "(none)";
}
TFM_Util.playerMsg(sender, p.getName() + " - Last Command: " + last_command, ChatColor.GRAY);
}
return true;
}
}

View File

@ -0,0 +1,67 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import java.io.File;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = ADMIN_LEVEL.SENIOR, source = SOURCE_TYPE_ALLOWED.ONLY_CONSOLE, block_host_console = true, ignore_permissions = false)
public class Command_tfupdate extends TFM_Command
{
public static final String[] FILES =
{
"http://s3.madgeekonline.com/totalfreedom/BukkitHttpd.jar",
"http://s3.madgeekonline.com/totalfreedom/BukkitTelnet.jar",
"http://s3.madgeekonline.com/totalfreedom/Essentials.jar",
"http://s3.madgeekonline.com/totalfreedom/EssentialsSpawn.jar",
"http://s3.madgeekonline.com/totalfreedom/TotalFreedomMod.jar",
"http://s3.madgeekonline.com/totalfreedom/craftbukkit.jar",
"http://s3.madgeekonline.com/totalfreedom/worldedit.jar"
};
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (!sender.getName().equalsIgnoreCase("madgeek1450"))
{
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true;
}
for (final String url : FILES)
{
server.getScheduler().runTaskAsynchronously(plugin, new Runnable()
{
@Override
public void run()
{
try
{
TFM_Log.info("Downloading: " + url);
File file = new File("./updates/" + url.substring(url.lastIndexOf("/") + 1));
if (file.exists())
{
file.delete();
}
if (!file.getParentFile().exists())
{
file.getParentFile().mkdirs();
}
TFM_Util.downloadFile(url, file, true);
}
catch (Exception ex)
{
TFM_Log.severe(ex);
}
}
});
}
return true;
}
}

View File

@ -472,6 +472,8 @@ public class TFM_PlayerListener implements Listener
TFM_Log.info(String.format("[PREPROCESS_COMMAND] %s(%s): %s", p.getName(), ChatColor.stripColor(p.getDisplayName()), command), true);
}
playerdata.setLastCommand(command);
command = command.toLowerCase().trim();
boolean block_command = false;

View File

@ -0,0 +1,40 @@
package me.StevenLawson.TotalFreedomMod;
public class TFM_TickMeter
{
int ticks;
int taskId;
final TotalFreedomMod plugin;
public TFM_TickMeter(TotalFreedomMod plugin)
{
this.plugin = plugin;
}
public int startTicking()
{
int tId = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable()
{
@Override
public void run()
{
ticks += 1;
}
}, 1L, 1L); // ticks (20 in 1 second)
taskId = tId;
return tId;
}
public void stopTicking()
{
plugin.getServer().getScheduler().cancelTask(taskId);
}
public int getTicks()
{
return ticks;
}
}

View File

@ -48,6 +48,7 @@ public class TFM_UserInfo
private boolean in_adminchat = false;
private boolean all_commands_blocked = false;
private Boolean superadmin_id_verified = null;
private String last_command = "";
public TFM_UserInfo(Player player)
{
@ -453,4 +454,14 @@ public class TFM_UserInfo
{
this.superadmin_id_verified = superadmin_id_verified;
}
public String getLastCommand()
{
return last_command;
}
public void setLastCommand(String last_command)
{
this.last_command = last_command;
}
}

View File

@ -937,13 +937,23 @@ public class TFM_Util
return affected;
}
public static void downloadFile(String url, File output_file) throws Exception
public static void downloadFile(String url, File output_file) throws java.lang.Exception
{
downloadFile(url, output_file, false);
}
public static void downloadFile(String url, File output_file, boolean verbose) throws java.lang.Exception
{
URL website = new URL(url);
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(output_file);
fos.getChannel().transferFrom(rbc, 0, 1 << 24);
fos.close();
if (verbose)
{
TFM_Log.info("Downloaded " + url + " to " + output_file.toString() + ".");
}
}
public static void adminChatMessage(CommandSender sender, String message, boolean senderIsConsole)

View File

@ -101,6 +101,9 @@ commands:
landmine:
description: Set a landmine trap.
usage: /<command>
lastcmd:
description: Superadmin command - Show the last command that someone used.
usage: /<command> <player>
lavadmg:
description: Superadmin command - Enable/disable lava damage.
usage: /<command> <on | off>
@ -189,7 +192,7 @@ commands:
usage: /<command> <block> [radius (default=50)] [player]
saconfig:
description: Senior Command - Manage superadmins.
usage: /<command> <list | clean | <add|delete> <username>>
usage: /<command> <list | clean | <add|delete|info> <username>>
say:
description: Broadcasts the given message as the console, includes sender name.
usage: /<command> <message>
@ -230,6 +233,9 @@ commands:
tfipbanlist:
description: Shows all banned IPs. Superadmins may optionally use 'purge' to clear the list.
usage: /<command> [purge]
tfupdate:
description: Madgeek command - Update server files.
usave: /<command>
tossmob:
description: Throw a mob in the direction you are facing when you left click with a stick.
usage: /<command> <mobtype [speed] | off | list>