2013-12-24 01:18:43 +01:00
|
|
|
var utils = require('utils');
|
|
|
|
|
2013-06-07 01:01:46 +02:00
|
|
|
/************************************************************************
|
2014-01-04 19:39:49 +01:00
|
|
|
## Classroom Plugin
|
2013-12-28 09:44:40 +01:00
|
|
|
|
2013-06-07 20:50:12 +02:00
|
|
|
The `classroom` object contains a couple of utility functions for use
|
|
|
|
in a classroom setting. The goal of these functions is to make it
|
|
|
|
easier for tutors to facilitate ScriptCraft for use by students in a
|
|
|
|
classroom environment. Although granting ScriptCraft access to
|
|
|
|
students on a shared server is potentially risky (Students can
|
|
|
|
potentially abuse it), it is slighlty less risky than granting
|
|
|
|
operator privileges to each student. (Enterprising students will
|
|
|
|
quickly realise how to grant themselves and others operator privileges
|
|
|
|
once they have access to ScriptCraft).
|
|
|
|
|
|
|
|
The goal of this module is not so much to enforce restrictions
|
|
|
|
(security or otherwise) but to make it easier for tutors to setup a shared server
|
|
|
|
so students can learn Javascript.
|
2013-06-07 01:01:46 +02:00
|
|
|
|
2013-12-28 09:44:40 +01:00
|
|
|
### classroom.allowScripting() function
|
|
|
|
|
2013-06-07 01:01:46 +02:00
|
|
|
Allow or disallow anyone who connects to the server (or is already
|
|
|
|
connected) to use ScriptCraft. This function is preferable to granting 'ops' privileges
|
|
|
|
to every student in a Minecraft classroom environment.
|
|
|
|
|
2013-12-28 09:44:40 +01:00
|
|
|
#### Parameters
|
2013-06-07 01:01:46 +02:00
|
|
|
|
|
|
|
* canScript : true or false
|
|
|
|
|
2013-12-28 09:44:40 +01:00
|
|
|
#### Example
|
|
|
|
|
2013-06-07 01:01:46 +02:00
|
|
|
To allow all players (and any players who connect to the server) to
|
|
|
|
use the `js` and `jsp` commands...
|
|
|
|
|
2013-12-30 22:33:12 +01:00
|
|
|
/js classroom.allowScripting(true,self)
|
2013-06-07 01:01:46 +02:00
|
|
|
|
|
|
|
To disallow scripting (and prevent players who join the server from using the commands)...
|
|
|
|
|
2013-12-30 22:33:12 +01:00
|
|
|
/js classroom.allowScripting(false,self)
|
2013-06-07 01:01:46 +02:00
|
|
|
|
|
|
|
Only ops users can run the classroom.allowScripting() function - this is so that students
|
|
|
|
don't try to bar themselves and each other from scripting.
|
|
|
|
|
|
|
|
***/
|
2013-12-24 23:47:57 +01:00
|
|
|
var _store = {enableScripting: false};
|
|
|
|
var classroom = plugin("classroom", {
|
2013-12-30 22:33:12 +01:00
|
|
|
allowScripting: function (/* boolean: true or false */ canScript, sender) {
|
|
|
|
if (typeof sender == 'undefined'){
|
|
|
|
console.log("Attempt to set classroom scripting without credentials");
|
2014-01-12 12:26:26 +01:00
|
|
|
console.log("classroom.allowScripting(boolean, sender)");
|
2013-12-30 22:33:12 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!sender.op){
|
|
|
|
console.log("Attempt to set classroom scripting without credentials: " + sender.name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-07 01:01:46 +02:00
|
|
|
/*
|
|
|
|
only operators should be allowed run this function
|
2013-12-24 01:18:43 +01:00
|
|
|
*/
|
2013-12-30 22:33:12 +01:00
|
|
|
if (!sender.isOp())
|
2013-06-07 01:01:46 +02:00
|
|
|
return;
|
|
|
|
if (canScript){
|
2013-12-30 22:33:12 +01:00
|
|
|
utils.foreach( server.onlinePlayers, function (player) {
|
|
|
|
player.addAttachment(__plugin, "scriptcraft.*", true);
|
|
|
|
});
|
2013-06-07 01:01:46 +02:00
|
|
|
}else{
|
|
|
|
utils.foreach( server.onlinePlayers, function(player) {
|
|
|
|
utils.foreach(player.getEffectivePermissions(), function(perm) {
|
|
|
|
if ((""+perm.permission).indexOf("scriptcraft.") == 0){
|
|
|
|
if (perm.attachment)
|
|
|
|
perm.attachment.remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2013-12-24 23:47:57 +01:00
|
|
|
_store.enableScripting = canScript;
|
|
|
|
},
|
|
|
|
store: _store
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
exports.classroom = classroom;
|
|
|
|
|
2013-12-24 01:18:43 +01:00
|
|
|
events.on('player.PlayerLoginEvent', function(listener, event) {
|
|
|
|
var player = event.player;
|
2013-12-25 08:48:10 +01:00
|
|
|
if (_store.enableScripting){
|
2013-12-24 01:18:43 +01:00
|
|
|
player.addAttachment(__plugin, "scriptcraft.*", true);
|
|
|
|
}
|
2013-12-28 09:44:40 +01:00
|
|
|
}, 'HIGHEST');
|
2013-12-24 01:18:43 +01:00
|
|
|
|