Giter Site home page Giter Site logo

mcstats's Introduction

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< O V E R V I E W >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

MCStats is a statistics plugin for the hey0 Minecraft server environment. MCStats
periodically generates xml, json, js, and html files containing server statistics. Optionally,
MCStats can also serve these files using an embedded web server.

Using the embedded web server, the html stats report can be served directly from your
Minecraft server. No need for messy apache installs.

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< I N S T A L L A T I O N >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

To use MCStats, place MCStats.jar in the hey0 plugin directory and add it to the
server.properties file.

When first run, MCStats will create the MCStats.config file and a statscache
file. Statscache is the default repository for server statistics. Deleting this
file will reset all statistics.

<<<<<<<<<<<<<<<<<<<<<<<<< P U R G I N G   O L D   P L A Y E R S >>>>>>>>>>>>>>>>>>>>>>>

To purge an inactive or unwanted player from the statistics cache, add their name to
the playersToPurge attribute in the MCStats.properties file. More than one player name
can be added by separating them by spaces. After saving the properties file, reload
MCStats from the server console to execute the purge. You will be notified that the
players were removed when the module reloads. Once the selected players have been
successfully purged from the statistics cache, the playersToPurge property will be
cleared.

MCStats can be configured to ignore players without a group assignment. When 
ignoreGrouplessPlayers is set to true in the config, only players with group assignments
will be added to the statistics cache. This feature can be useful for separating your
recurring players from guests of your server.

If you only want to reset all the player playtimes to zero, set the resetPlaytime flag
to true in the config and reload MCStats. When MCStats reloads, all playtimes will be
reset and the flag will be cleared in the config file.

<<<<<<<<<<<<<<<<<<<<<<<<<<<<< C O N F I G U R A T I O N >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

The following items can be configured in the MCStats.config file.
* statsCacheFile        
- The name of the peristent stats storage file.

* webserverEnabled      
- Enables or dissables the embedded web server.

* statsBaseResource     
- The file name (minus extension) to use when saving/serving stats files.

* resourceSaveDirectory 
- The directory to save stats reports into. For web server integration, set this directory 
  to you web server's wwwroot directory.

* secondsBetweenSaves   
- The number of seconds to wait between saving stats reports and the statscache.

* secondsBetweenPageRefreshes 
- The number of seconds to wait before automatically refreshing the html report in the browser.

* httpServerContextRoot 
- The path part of the embedded web server's url. Must begin and end with a slash (/). 

  Example: /foo/bar/ => http://host.com/foo/bar/mcstats.html
  Note: This property only controls the middle part of the url.
        Not the file name or the server name.

* overwriteHtmlReport
- Default True. Sets or disables the automatic overwriting of the HTML report file. Useful for
  modding the HTML report without installing a complete web server. When set to False, the internal
  web server will continue to serve the generated HTML report, even if it is modified (for a mod,
  for example).

* httpBacklog           
- The number of http requests to queue before dropping requests.

* httpPort              
- The port the embedded web server listens on.

* playersToPurge        
- A list of player names to remove from the stats cache, separated by spaces.

* resetPlaytime
- Default False. If set to true, all player playtimes will be reset to zero.

* ignoreGrouplessPlayers
- Default False. If true, players not assigned to any groups are completely ignored by MCStats.
  Note: If you will still need to purge players who were created before this setting was set to true.

* httpPostUrl
- Default empty. When set to a URL, MCStats will attempt to post its json data to that url
  every time the stats are committed to disk.
  
* httpPostConnectTimeout
- Default 300. The number of milliseconds to wait before giving up on an http post.

* enableSerializerCache
- Default True. When true, stats served up by the internal web server will only be regenerated every
  secondsBetweenSaves seconds. If false, stats are generated in real-time. Setting this to false
  could have a negative affect on server performance.
                          
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< M O D D I N G >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

                    ======= Styling the HTML Report =======
The MCStats html report can be easily modded to incorporate the theme of your website.
To begin, start the plugin and wait for it to generate the default report. If the
statsBaseResource and resourceSaveDirectory properties have been left as their defaults,
this file will be stats/mcstats.html in the hey0 bin/ directory. Once the default html 
file has been generated, make a copy of it and rename the copy.

The following css styles are useful for changing the visual theme of the html report:
* #online
- The ID of the table of online players

* #stats
- The ID of the table of player statistics

* .pName
- The style for player names in the stats table

* .pOnline
- The style for player names in the players online list

* th.header
- The style for unsorted stats table headers

* th.headerSortDown
- The style for stats table headers sorted in ascending order

* th.headerSortUp
- The style for stats table headers sorted in descending order

* .admins, .mods, .vip
- Styles for identifying the standard hey0 roles in the user lists.
  MCStats assigns each user's div tag a css class with the name of each role they are
  assigned. Even custom ones.
  
To remove a column from the html report, you must first remove the column's <th> tag
from the html markup and then remove the corresponding javascript that generates the
column's content. Find the block of code that defines a var with the right name and
delete the entire block of code. 

            ======= Consuming MCStats data in other programs =======
In addition to generating an HTML report, MCStats exports its data in xml, json, and
javascript format. These data feeds are ready for consumption by other programs using
whatever parser your language provides. For your convenience, here are the xml and json
data formats.

Additionally, MCStats can be configured to POST json data to a url, allowing MCStats
to push stats data into your app.

* MCStats.xml *
<mcStats>
	<playersOnline>
		<player>
			<playerName>STRING</playerName>
			<groups>SPACE DELIMITED STRING LIST</groups>
		</player>
	</playersOnline>
	<playerStats>
		<player>
			<blocksDestroyed>INTEGER</blocksDestroyed>
			<blocksPlaced>INTEGER</blocksPlaced>
			<isOnline>BOOLEAN</isOnline>
			<itemsDropped>INTEGER</itemsDropped>
			<lastLogin>STRING ENCODED UNIX EPOCH TIMESTAMP</lastLogin>
			<metersTraveled>INTEGER</metersTraveled>
			<playerName>STRING</playerName>
			<playerSince>STRING ENCODED UNIX EPOCH TIMESTAMP</playerSince>
			<sessionPlaytime>STRING, EMPTY IF NOT ONLINE</sessionPlaytime>
			<sessionPlaytimeSeconds>INTEGER, -1 IF NOT ONLINE</sessionPlaytimeSeconds>
			<totalPlaytime>STRING</totalPlaytime>
			<totalPlaytimeSeconds>INTEGER</totalPlaytimeSeconds>
		</player>
	</playerStats>
</mcStats>

* MCStats.json *
{
	{
    "playerStats": [
        {
            "blocksDestroyed": 11,
            "blocksDestroyedDetails": {			// map between block id and
                "50": 1,						// total destroyed
                "2": 6,
                "18": 3,
                "12": 1
            },
            "blocksPlaced": 41,
            "blocksPlacedDetails": {			// map between block id and
                "50": 41						// total placed
            },
            "isOnline": true,
            "itemsDropped": 1,
            "itemsDroppedDetails": {			// map between item id and
                "50": 1							// total dropped
            },
            "lastLogin": "1290671856505",		// string encoded unix epoch time
            "metersTraveled": 955,
            "playerGroups": [
                "mods"							// array of player's groups
            ],
            "playerName": "deltahat",
            "playerSince": "1290476814776",		// string encoded unix epoch time
            "sessionPlaytime": "0.03 hours",
            "sessionPlaytimeSeconds": "174",
            "totalPlaytime": "3.63 hours",
            "totalPlaytimeSeconds": "13088"
        }
    ],
    "playersOnline": [
        {
            "groups": [							// array of player's groups
                "mods"
            ],
            "playerName": "deltahat"
        }
    ]
}

* MCStats.js *
var mcStatsRawData = {...json data...};

            ======= Notes on Web Servers =======
Assuming you are using the default value for statsBaseResource, you can simply rename 
your mcstats.html file to stats.html and then edit the copy. This will require the 
use of some other web server technology to serve your new file as the embedded 
server only serves mcstats.html.

If you are using the internal web server, MCStats will overwrite any customized html 
report unless you set overwriteHtmlReport to false in the .config file. While setting 
this to false will allow the internal web server to serve a customized html file, 
your html file will no longer get any updates with future versions of MCStats since 
MCStats is now ignoring the file.

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< C O N T A C T >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

MCStats is written by Ryan Michela ([email protected])

Additional code by:
Shaun (sturmeh) - SuperPlugin.java
Jason Morris    - JSONEncoder.java
Christian Bach  - tablesorter.js

mcstats's People

Contributors

hans avatar rmichela avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mcstats's Issues

Investigate jaxb class error

WARNING: duplicate class definition bug occured? Please report this : StatsSerializerMessage$JaxbAccessorM_getPlayerStats_setPlayerStats_[LPlayerStatistics;
java.lang.ClassFormatError: Illegal class name "StatsSerializerMessage$JaxbAccessorM_getPlayerStats_setPlayerStats_[LPlayerStatistics;" in class file StatsSerializerMessage$JaxbAccessorM_getPlayerStats_setPlayerStats_[LPlayerStatistics;
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:789)
at java.lang.ClassLoader.defineClass(ClassLoader.java:631)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:613)
at com.sun.xml.internal.bind.v2.runtime.reflect.opt.Injector.inject(Injector.java:194)
at com.sun.xml.internal.bind.v2.runtime.reflect.opt.Injector.inject(Injector.java:74)
at com.sun.xml.internal.bind.v2.runtime.reflect.opt.AccessorInjector.prepare(AccessorInjector.java:78)
at com.sun.xml.internal.bind.v2.runtime.reflect.opt.OptimizedAccessorFactory.get(OptimizedAccessorFactory.java:103)
at com.sun.xml.internal.bind.v2.runtime.reflect.Accessor$GetterSetterReflection.optimize(Accessor.java:358)
at com.sun.xml.internal.bind.v2.runtime.property.ArrayProperty.(ArrayProperty.java:54)
at com.sun.xml.internal.bind.v2.runtime.property.ArrayERProperty.(ArrayERProperty.java:73)
at com.sun.xml.internal.bind.v2.runtime.property.ArrayElementProperty.(ArrayElementProperty.java:85)
at com.sun.xml.internal.bind.v2.runtime.property.ArrayElementNodeProperty.(ArrayElementNodeProperty.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:530)
at com.sun.xml.internal.bind.v2.runtime.property.PropertyFactory.create(PropertyFactory.java:113)
at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.(ClassBeanInfoImpl.java:168)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.java:504)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.(JAXBContextImpl.java:319)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1129)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:143)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:110)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:613)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:221)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:395)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:638)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:585)
at StatsSerializer.statsAsXml(StatsSerializer.java:46)
at StatsModel.saveUserFiles(StatsModel.java:109)
at StatsPlugin.disableExtra(StatsPlugin.java:94)
at SuperPlugin.disable(SuperPlugin.java:59)
at PluginLoader.disablePlugin(PluginLoader.java:327)
at etc.parseConsoleCommand(etc.java:497)
at Minebot.onMessage(Minebot.java:431)
at org.jibble.pircbot.PircBot.handleLine(PircBot.java:1076)
at org.jibble.pircbot.InputThread.run(InputThread.java:95)

Invalid JSON

JSONLint says that the JSON output is invalid and PHP refuses to parse it with json_decode because there are no quotes around the majority of the keys.

Add additional tracked metrics

Add a metric for group membership, last time online, and current session length.

Use groups as css classes for name labels.

Invalid XML

The mcstats.xml file generated is invalid XML and cannot be parsed.

Online Time Bug

It have some problems stopping counting online time. It says that i have played 13.56 hours, but thats more like how long ago we installed the plugin.

Could be due to client crash.

Add clarification to the modding guide

Assuming you are using the default value for statsBaseResource, you can simply rename your mcstats.html file to stats.html and then edit the copy. This will require the use of some other web server technology to serve your new file as the embedded server only serves mcstats.html.

If you are using the internal web server, MCStats will overwrite any customized html report unless you set overwriteHtmlReport to false in the .config file. While setting this to false will allow the internal web server to serve a customized html file, your html file will no longer get any updates with future versions of MCStats since MCStats is now ignoring the file.

Randomly generated item ID -1 in "blocksPlacedDetails"

An item with ID -1 is randomly generated (we've been unable to determine what is generating it as the only blocks placed are accounted for) in the "blocksPlacedDetails" variable.

This -1 item is making the JSON incompatible as it isn't expecting the dash ("-") sign.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.