mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 02:05:41 +00:00
Reworked /health, should be thread-safe now
Updated version number to reflect latest changes
This commit is contained in:
parent
95afb51321
commit
d40c143afc
@ -1,6 +1,6 @@
|
||||
#Sat, 03 Aug 2013 14:59:27 -0400
|
||||
#Fri, 09 Aug 2013 15:38:23 +0200
|
||||
|
||||
program.VERSION=2.21
|
||||
program.BUILDNUM=375
|
||||
program.BUILDDATE=08/03/2013 02\:59 PM
|
||||
program.VERSION=2.22
|
||||
program.BUILDNUM=378
|
||||
program.BUILDDATE=08/09/2013 03\:38 PM
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
#Build Number for ANT. Do not edit!
|
||||
#Sat Aug 03 14:59:27 EDT 2013
|
||||
build.number=376
|
||||
#Fri Aug 09 15:38:23 CEST 2013
|
||||
build.number=379
|
||||
|
@ -1,4 +1,4 @@
|
||||
# TotalFreedomMod v2.21 Configuration
|
||||
# TotalFreedomMod v2.22 Configuration
|
||||
# by Madgeek1450 and DarthSalamon
|
||||
|
||||
# Block placement prevention:
|
||||
|
@ -1,8 +1,15 @@
|
||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Log;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_TickMeter;
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
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;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "View ticks-per-second", usage = "/<command>")
|
||||
@ -11,39 +18,45 @@ 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)
|
||||
{
|
||||
// -- MADGEEK: This is not thread safe. It needs to be rewritten using proper Bukkit scheduler API.
|
||||
//
|
||||
// Runnable task;
|
||||
// task = new Runnable() // async
|
||||
// {
|
||||
// @Override
|
||||
// public void run()
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// TFM_TickMeter meter = new TFM_TickMeter(plugin);
|
||||
// meter.startTicking();
|
||||
// Thread.sleep(1000); // per second
|
||||
// meter.stopTicking();
|
||||
//
|
||||
// Runtime runtime = Runtime.getRuntime();
|
||||
// int mb = 1048576; // 1024 * 1024
|
||||
//
|
||||
// float usedMem = runtime.totalMemory() - runtime.freeMemory();
|
||||
//
|
||||
// playerMsg("Reserved Memory: " + runtime.totalMemory() / mb + "mb");
|
||||
// playerMsg("Used Memory: " + new DecimalFormat("#").format(usedMem / mb) + "mb (" + new DecimalFormat("#").format(usedMem / runtime.totalMemory() * 100) + "%)");
|
||||
// playerMsg("Max Memory: " + runtime.maxMemory() / mb + "mb");
|
||||
// playerMsg("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();
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
final TFM_TickMeter meter = new TFM_TickMeter(plugin);
|
||||
meter.startTicking();
|
||||
Thread.sleep(1000); // per second
|
||||
meter.stopTicking();
|
||||
|
||||
final Runtime runtime = Runtime.getRuntime();
|
||||
final int mb = 1048576; // 1024 * 1024
|
||||
|
||||
final float usedMem = runtime.totalMemory() - runtime.freeMemory();
|
||||
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
playerMsg("Reserved Memory: " + runtime.totalMemory() / mb + "mb");
|
||||
playerMsg("Used Memory: " + new DecimalFormat("#").format(usedMem / mb) + "mb (" + new DecimalFormat("#").format((usedMem / runtime.totalMemory()) * 100) + "%)");
|
||||
playerMsg("Max Memory: " + runtime.maxMemory() / mb + "mb");
|
||||
playerMsg("Ticks per second: " + (meter.getTicks() == 20 ? ChatColor.GREEN : ChatColor.RED) + meter.getTicks());
|
||||
}
|
||||
}.runTask(TotalFreedomMod.plugin);
|
||||
}
|
||||
catch (Exception iex)
|
||||
{
|
||||
TFM_Log.warning("Exception in TFM_TickMeter: Thread was interupted in sleeping process.");
|
||||
TFM_Log.warning(ExceptionUtils.getStackTrace(iex));
|
||||
}
|
||||
}
|
||||
|
||||
}.runTaskAsynchronously(TotalFreedomMod.plugin);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +94,6 @@ public class TFM_BlockListener implements Listener
|
||||
if (TFM_ProtectedArea.isInProtectedArea(block_pos))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -185,7 +184,6 @@ public class TFM_BlockListener implements Listener
|
||||
p.sendMessage(ChatColor.GRAY + "Lava placement is currently disabled.");
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -204,7 +202,6 @@ public class TFM_BlockListener implements Listener
|
||||
p.sendMessage(ChatColor.GRAY + "Water placement is currently disabled.");
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -222,7 +219,6 @@ public class TFM_BlockListener implements Listener
|
||||
p.sendMessage(ChatColor.GRAY + "Fire placement is currently disabled.");
|
||||
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -240,7 +236,6 @@ public class TFM_BlockListener implements Listener
|
||||
|
||||
p.sendMessage(ChatColor.GRAY + "TNT is currently disabled.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -2,37 +2,37 @@ 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;
|
||||
// }
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: TotalFreedomMod
|
||||
main: me.StevenLawson.TotalFreedomMod.TotalFreedomMod
|
||||
version: 2.21
|
||||
version: 2.22
|
||||
description: Plugin for the Total Freedom server.
|
||||
authors: [StevenLawson / Madgeek1450, JeromSar / DarthSalamon]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user