-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added missing stat Types ( should have just as many types as MineJMX now
) Added framework for Logging to a stat source
- Loading branch information
Showing
7 changed files
with
135 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/scala/com/dkhenry/minestat/MineStatPlayerListener.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.dkhenry.minestat | ||
|
||
import org.bukkit.Location | ||
import org.bukkit.entity.Player | ||
import org.bukkit.event.EventHandler | ||
import org.bukkit.event.Listener | ||
import org.bukkit.event.player.PlayerJoinEvent | ||
import org.bukkit.event.player.PlayerMoveEvent | ||
import org.bukkit.event.player.PlayerQuitEvent; | ||
import scala.collection.mutable.HashMap | ||
|
||
class MineStatPlayerListener(plugin: MineStatPlugin) extends Listener { | ||
var playerHash = new HashMap[String,Long]() | ||
|
||
@EventHandler | ||
def onPlayerJoin(event: PlayerJoinEvent) = { | ||
def name = event.getPlayer().getName() | ||
plugin.persistance.increment("server",plugin.serverName,"numberOfPlayers",1.0); | ||
plugin.persistance.increment("player",name,"numberOfLogins",1.0); | ||
plugin.persistance.set("player",name,"active",1.0); | ||
playerHash put (name , System.currentTimeMillis()) | ||
} | ||
|
||
@EventHandler | ||
def onPlayerQuit(event: PlayerQuitEvent) = { | ||
def name = event.getPlayer().getName() | ||
plugin.persistance.increment("server",plugin.serverName,"numberOfPlayers",-1.0); | ||
plugin.persistance.set("player",name,"active",0.0); | ||
|
||
playerHash get name map { t => | ||
plugin.persistance.increment("player",name,"timeOnServer",System.currentTimeMillis() - t); | ||
} | ||
} | ||
|
||
@EventHandler | ||
def onPlayerMove(event: PlayerMoveEvent) = { | ||
val player = event.getPlayer(); | ||
val from = event.getFrom() | ||
val to = event.getTo(); | ||
|
||
val distance = Math.sqrt(Math.pow(to.getX() - from.getX(), 2) + Math.pow(to.getY() - from.getY(), 2) + Math.pow(to.getZ() - from.getZ(), 2)); | ||
|
||
// Increment the per-Player stats | ||
plugin.persistance.increment("player",player.getName(),"distanceMoved",distance); | ||
plugin.persistance.increment("server",plugin.serverName,"playerDistanceMoved",distance); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.dkhenry.minestat | ||
import org.bukkit.scheduler.BukkitScheduler | ||
|
||
class MongoLog(plugin: MineStatPlugin) extends Runnable { | ||
|
||
var interval = 300 | ||
var tid = 0 | ||
|
||
def registerWithScheduler(scheduler: BukkitScheduler) { | ||
tid = scheduler.scheduleAsyncRepeatingTask(plugin, this, 0, interval) ; | ||
} | ||
|
||
|
||
@Override | ||
def run() = { | ||
// we need to take a snapshot of persistance and write it to the MongoDB Log | ||
|
||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/scala/com/dkhenry/minestat/ServerTickPoller.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.dkhenry.minestat | ||
|
||
import org.bukkit.scheduler.BukkitScheduler; | ||
|
||
class ServerTickPoller(plugin: MineStatPlugin) extends Runnable { | ||
var interval: Long = 40; | ||
var lastPoll: Long = System.currentTimeMillis() ; | ||
|
||
def registerWithScheduler(scheduler: BukkitScheduler) { | ||
scheduler.scheduleAsyncRepeatingTask(plugin, this, 0, interval) ; | ||
} | ||
|
||
@Override | ||
def run() = { | ||
// Cache the current time | ||
val current = System.currentTimeMillis() ; | ||
|
||
// Calculate the Delta | ||
var delta = current - lastPoll ; | ||
|
||
// Make sure we check for a DivByZero error | ||
if(delta <= 0 ) { | ||
delta = 1 ; | ||
} | ||
|
||
val tickRate = this.interval*1000 / delta ; | ||
|
||
plugin.persistance.set("server",plugin.serverName,"tickRate",tickRate.doubleValue()); | ||
plugin.persistance.increment("server",plugin.serverName,"ticks",tickRate.doubleValue()); | ||
|
||
val active = plugin.getServer().getScheduler().getActiveWorkers().size() ; | ||
plugin.persistance.set("server",plugin.serverName,"activeTasks",active); | ||
val pending = plugin.getServer().getScheduler().getPendingTasks().size() ; | ||
plugin.persistance.set("server",plugin.serverName,"pendingTasks",pending); | ||
|
||
lastPoll = current ; | ||
} | ||
} |