19162c3688
Some of the plugins are not yet supported. If you're feeling brave you can build from source using ant.
63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
var bkLocation = org.bukkit.Location,
|
|
i = 0,
|
|
bukkit = require('bukkit'),
|
|
foreach = require('utils').foreach,
|
|
allSounds = bukkit.sound.values(),
|
|
len = allSounds.length,
|
|
sound,
|
|
soundName;
|
|
|
|
for ( ; i < len; i++ ) {
|
|
sound = allSounds[i];
|
|
soundName = '' + sound.name();
|
|
var methodName = soundName.toLowerCase().replace(/_(.)/g,function(a,b){ return b.toUpperCase();});
|
|
exports[methodName] = (function(sound){
|
|
return function()
|
|
{
|
|
switch (arguments.length) {
|
|
case 3:
|
|
exports.play(sound, arguments[0], arguments[1], arguments[2]);
|
|
break;
|
|
case 2:
|
|
// TODO: possible combinations:
|
|
// location, volume,
|
|
// volume pitch
|
|
exports.play(sound, arguments[0],arguments[1]);
|
|
break;
|
|
case 1:
|
|
exports.play(sound, arguments[0]);
|
|
break;
|
|
case 0:
|
|
// play the sound at full vol, medium pitch for all players
|
|
//
|
|
foreach(server.onlinePlayers,function(player){
|
|
exports.play(sound, player, 1, 0);
|
|
});
|
|
default:
|
|
}
|
|
};
|
|
})(sound);
|
|
}
|
|
exports.play = function(sound, locationOrHasLocation, volume, pitch) {
|
|
var location = null;
|
|
if (!locationOrHasLocation)
|
|
return;
|
|
if (locationOrHasLocation instanceof bkLocation){
|
|
location = locationOrHasLocation;
|
|
} else {
|
|
locationOrHasLocation = locationOrHasLocation.location;
|
|
if (locationOrHasLocation && locationOrHasLocation instanceof bkLocation ){
|
|
location = locationOrHasLocation;
|
|
}
|
|
}
|
|
if (!location){
|
|
console.warn('sounds.play() needs a location');
|
|
return;
|
|
}
|
|
if (typeof volume == 'undefined')
|
|
volume = 1;
|
|
if (typeof pitch == 'undefined')
|
|
pitch = 1;
|
|
location.world.playSound(location, sound, volume, pitch);
|
|
};
|