Reworked /health, should be thread-safe now

Updated version number to reflect latest changes
This commit is contained in:
JeromSar 2013-08-09 15:40:08 +02:00
parent 95afb51321
commit d40c143afc
7 changed files with 87 additions and 79 deletions

View File

@ -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.VERSION=2.22
program.BUILDNUM=375 program.BUILDNUM=378
program.BUILDDATE=08/03/2013 02\:59 PM program.BUILDDATE=08/09/2013 03\:38 PM

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Sat Aug 03 14:59:27 EDT 2013 #Fri Aug 09 15:38:23 CEST 2013
build.number=376 build.number=379

View File

@ -1,4 +1,4 @@
# TotalFreedomMod v2.21 Configuration # TotalFreedomMod v2.22 Configuration
# by Madgeek1450 and DarthSalamon # by Madgeek1450 and DarthSalamon
# Block placement prevention: # Block placement prevention:

View File

@ -1,8 +1,15 @@
package me.StevenLawson.TotalFreedomMod.Commands; 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.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH) @CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
@CommandParameters(description = "View ticks-per-second", usage = "/<command>") @CommandParameters(description = "View ticks-per-second", usage = "/<command>")
@ -11,39 +18,45 @@ public class Command_health extends TFM_Command
@Override @Override
public boolean run(final CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) 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.
// new BukkitRunnable()
// Runnable task; {
// task = new Runnable() // async
// { @Override
// @Override public void run()
// public void run() {
// { try
// try {
// { final TFM_TickMeter meter = new TFM_TickMeter(plugin);
// TFM_TickMeter meter = new TFM_TickMeter(plugin); meter.startTicking();
// meter.startTicking(); Thread.sleep(1000); // per second
// Thread.sleep(1000); // per second meter.stopTicking();
// meter.stopTicking();
// final Runtime runtime = Runtime.getRuntime();
// Runtime runtime = Runtime.getRuntime(); final int mb = 1048576; // 1024 * 1024
// int mb = 1048576; // 1024 * 1024
// final float usedMem = runtime.totalMemory() - runtime.freeMemory();
// float usedMem = runtime.totalMemory() - runtime.freeMemory();
// new BukkitRunnable()
// playerMsg("Reserved Memory: " + runtime.totalMemory() / mb + "mb"); {
// playerMsg("Used Memory: " + new DecimalFormat("#").format(usedMem / mb) + "mb (" + new DecimalFormat("#").format(usedMem / runtime.totalMemory() * 100) + "%)"); @Override
// playerMsg("Max Memory: " + runtime.maxMemory() / mb + "mb"); public void run() {
// playerMsg("Ticks per second: " + (meter.getTicks() == 20 ? ChatColor.GREEN : ChatColor.RED) + meter.getTicks()); playerMsg("Reserved Memory: " + runtime.totalMemory() / mb + "mb");
// } playerMsg("Used Memory: " + new DecimalFormat("#").format(usedMem / mb) + "mb (" + new DecimalFormat("#").format((usedMem / runtime.totalMemory()) * 100) + "%)");
// catch (Exception iex) playerMsg("Max Memory: " + runtime.maxMemory() / mb + "mb");
// { playerMsg("Ticks per second: " + (meter.getTicks() == 20 ? ChatColor.GREEN : ChatColor.RED) + meter.getTicks());
// TFM_Log.warning("Exception in TFM_TickMeter: Thread was interupted in sleeping process."); }
// TFM_Log.warning(ExceptionUtils.getStackTrace(iex)); }.runTask(TotalFreedomMod.plugin);
// } }
// } catch (Exception iex)
// }; {
// new Thread(task, "TickMeter").start(); TFM_Log.warning("Exception in TFM_TickMeter: Thread was interupted in sleeping process.");
TFM_Log.warning(ExceptionUtils.getStackTrace(iex));
}
}
}.runTaskAsynchronously(TotalFreedomMod.plugin);
return true; return true;
} }
} }

View File

@ -94,7 +94,6 @@ public class TFM_BlockListener implements Listener
if (TFM_ProtectedArea.isInProtectedArea(block_pos)) if (TFM_ProtectedArea.isInProtectedArea(block_pos))
{ {
event.setCancelled(true); event.setCancelled(true);
return;
} }
} }
} }
@ -185,7 +184,6 @@ public class TFM_BlockListener implements Listener
p.sendMessage(ChatColor.GRAY + "Lava placement is currently disabled."); p.sendMessage(ChatColor.GRAY + "Lava placement is currently disabled.");
event.setCancelled(true); event.setCancelled(true);
return;
} }
break; break;
} }
@ -204,7 +202,6 @@ public class TFM_BlockListener implements Listener
p.sendMessage(ChatColor.GRAY + "Water placement is currently disabled."); p.sendMessage(ChatColor.GRAY + "Water placement is currently disabled.");
event.setCancelled(true); event.setCancelled(true);
return;
} }
break; break;
} }
@ -222,7 +219,6 @@ public class TFM_BlockListener implements Listener
p.sendMessage(ChatColor.GRAY + "Fire placement is currently disabled."); p.sendMessage(ChatColor.GRAY + "Fire placement is currently disabled.");
event.setCancelled(true); event.setCancelled(true);
return;
} }
break; break;
} }
@ -240,7 +236,6 @@ public class TFM_BlockListener implements Listener
p.sendMessage(ChatColor.GRAY + "TNT is currently disabled."); p.sendMessage(ChatColor.GRAY + "TNT is currently disabled.");
event.setCancelled(true); event.setCancelled(true);
return;
} }
break; break;
} }

View File

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

View File

@ -1,6 +1,6 @@
name: TotalFreedomMod name: TotalFreedomMod
main: me.StevenLawson.TotalFreedomMod.TotalFreedomMod main: me.StevenLawson.TotalFreedomMod.TotalFreedomMod
version: 2.21 version: 2.22
description: Plugin for the Total Freedom server. description: Plugin for the Total Freedom server.
authors: [StevenLawson / Madgeek1450, JeromSar / DarthSalamon] authors: [StevenLawson / Madgeek1450, JeromSar / DarthSalamon]