diff --git a/docs/api.md b/docs/api.md index a00b8aa..e7b4ef2 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1,3 +1,34 @@ +classroom Module +================ +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. + +classroom.allowScripting() function +=================================== +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. + +Parameters +---------- + + * canScript : true or false + +Example +------- +To allow all players (and any players who connect to the server) to +use the `js` and `jsp` commands... + + /js classroom.allowScripting(true) + +To disallow scripting (and prevent players who join the server from using the commands)... + + /js classroom.allowScripting(false) + +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. + ScriptCraft API Reference ========================= diff --git a/src/main/javascript/classroom/classroom.js b/src/main/javascript/classroom/classroom.js new file mode 100644 index 0000000..cb09960 --- /dev/null +++ b/src/main/javascript/classroom/classroom.js @@ -0,0 +1,71 @@ +/************************************************************************ +classroom Module +================ +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. + +***/ + +/************************************************************************* +classroom.allowScripting() function +=================================== +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. + +Parameters +---------- + + * canScript : true or false + +Example +------- +To allow all players (and any players who connect to the server) to +use the `js` and `jsp` commands... + + /js classroom.allowScripting(true) + +To disallow scripting (and prevent players who join the server from using the commands)... + + /js classroom.allowScripting(false) + +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. + +***/ +var classroom = { + allowScripting: function(/* boolean: true or false */ canScript){} +}; + +ready(function(){ + classroom.allowScripting = function(canScript) + { + /* + only operators should be allowed run this function + */ + if (!self.isOp()) + return; + + if (canScript){ + utils.foreach( server.onlinePlayers, function (player) { + player.addAttachment(__plugin, "scriptcraft.*", true); + }); + }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(); + } + }); + }); + } + classroom.canScript = canScript; + }; + events.on("player.PlayerLoginEvent", function(listener, event) { + var player = event.player; + if (classroom.canScript) + player.addAttachment(__plugin, "scriptcraft.*", true); + }, "HIGHEST"); +});