Skip to content

Instantly share code, notes, and snippets.

@grimmdev
Last active December 8, 2016 08:13
Show Gist options
  • Save grimmdev/0edb138f2353933822d0f880fea80c03 to your computer and use it in GitHub Desktop.
Save grimmdev/0edb138f2353933822d0f880fea80c03 to your computer and use it in GitHub Desktop.
Welcome Plugin, developed for Scriptcraft Minecraft Server Plugin. Perfect example getting commands/options/arguments.
// Welcome Plugin
// 1.0
// Sean Loper
// Displays a message on player join with custom setting to change it to another message.
var VERSION = '1.0';
var COLOR = '\u00A79';
var WELCOME_MSG = 'Welcome To The Server!';
function myPlayerJoinHook( event ){
var player = event.player;
echo( player, WELCOME_MSG);
}
events.playerJoin( myPlayerJoinHook );
function myPlayerCommandHook( event ){
var player = event.player;
var msg = event.message.substring(1, event.message.length);
var commands = msg.split(" ");
if(commands.length > 0)
var cmd = commands[0].toLowerCase();
if(commands.length > 1)
var option = commands[1].toLowerCase();
if(commands.length > 2)
var arg = event.message.substring((3 + cmd.length + option.length), event.message.length);
if(cmd == 'welcome') {
if(commands.length == 1) {
echo(player, COLOR + 'Type /Welcome Help. For a list of commands.');
}
if(commands.length == 2) {
if(option == 'version')
echo(player, COLOR + 'Version: ' + VERSION);
if(option == 'help')
echo(player, COLOR + 'COMMANDS\n/Welcome Version - Displays the current Version of this Plugin.\n/Welcome Set <Message> - Sets the current message players see when they join.');
}
if(commands.length >= 3)
{
if(option == 'set') {
if(isOp(player)) {
WELCOME_MSG = arg;
echo(player, COLOR + 'Player Join Message Set.');
} else {
echo(player, COLOR + 'You must be OP to use this.');
}
}
}
}
}
// Canary Version Below, uncomment and comment the one beneath it for Canary.
// events.playerCommand( myPlayerCommandHook );
events.playerCommandPreprocess( myPlayerCommandHook );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment