Added blocktype drone extension for creating words from blocks

This commit is contained in:
walterhiggins 2013-01-20 21:02:56 +00:00
parent 74fbe24f8d
commit 42b1ac2b74
4 changed files with 329 additions and 320 deletions

View file

@ -108,8 +108,9 @@ ready(function()
break;
case 2:
projectile.remove();
var teleportCause =org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
shooter.teleport(projectile.location,
org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.ENDER_PEARL);
teleportCause.PLUGIN);
break;
case 3:
projectile.remove();

View file

@ -291,6 +291,8 @@ var Drone = Drone || {
}else{
this.dir = dir%4;
}
// for debugging
//__self.sendMessage("New Drone " + this.toString());
if (usePlayerCoords){
this.fwd(3);
}
@ -575,13 +577,13 @@ var Drone = Drone || {
// wph 20130114 more efficient esp. for large cylinders/spheres
if (yo < 0){
drone
.fwd(yo).right(xo)
.box(block,1,height,Math.abs(yo*2)+1)
.back(yo).left(xo);
.fwd(yo).right(xo)
.box(block,1,height,Math.abs(yo*2)+1)
.back(yo).left(xo);
}
}else{
gotoxy(xo,yo).box(block,1,height,1).move('center');
}
gotoxy(xo,yo).box(block,1,height,1).move('center');
}
};
//
// credit: Following code is copied almost verbatim from
@ -763,18 +765,18 @@ var Drone = Drone || {
return this.box(randomized,w,h,d);
};
var _trees = {oak: org.bukkit.TreeType.BIG_TREE ,
spruce: org.bukkit.TreeType.REDWOOD ,
birch: org.bukkit.TreeType.BIRCH ,
jungle: org.bukkit.TreeType.JUNGLE };
spruce: org.bukkit.TreeType.REDWOOD ,
birch: org.bukkit.TreeType.BIRCH ,
jungle: org.bukkit.TreeType.JUNGLE };
for (var p in _trees)
{
{
Drone.prototype[p] = function(v){
return function(){
var treeLoc = new org.bukkit.Location(__self.world,this.x,this.y,this.z);
treeLoc.world.generateTree(treeLoc,v);
return this;
};
}(_trees[p]);
return function(){
var treeLoc = new org.bukkit.Location(__self.world,this.x,this.y,this.z);
treeLoc.world.generateTree(treeLoc,v);
return this;
};
}(_trees[p]);
}
Drone.prototype.garden = function(w,d)

View file

@ -1,44 +1,44 @@
Drone.extend('sphere', function(block,radius)
{
var lastRadius = radius;
var slices = [[radius,0]];
var diameter = radius*2;
var r2 = radius*radius;
for (var i = 0; i <= radius;i++){
var newRadius = Math.round(Math.sqrt(r2 - i*i));
if (newRadius == lastRadius)
slices[slices.length-1][1]++;
else
slices.push([newRadius,1]);
lastRadius = newRadius;
}
this.chkpt('sphere');
//
// mid section
//
this.up(radius - slices[0][1])
.cylinder(block,radius,(slices[0][1]*2)-1)
.down(radius-slices[0][1]);
var yOffset = -1;
for (var i = 1; i < slices.length;i++)
{
yOffset += slices[i-1][1];
var sr = slices[i][0];
var sh = slices[i][1];
var v = radius + yOffset, h = radius-sr;
// northern hemisphere
this.up(v).fwd(h).right(h)
.cylinder(block,sr,sh)
.left(h).back(h).down(v);
// southern hemisphere
v = radius - (yOffset+sh+1);
this.up(v).fwd(h).right(h)
.cylinder(block,sr,sh)
.left(h).back(h). down(v);
}
return this.move('sphere');
var lastRadius = radius;
var slices = [[radius,0]];
var diameter = radius*2;
var r2 = radius*radius;
for (var i = 0; i <= radius;i++){
var newRadius = Math.round(Math.sqrt(r2 - i*i));
if (newRadius == lastRadius)
slices[slices.length-1][1]++;
else
slices.push([newRadius,1]);
lastRadius = newRadius;
}
this.chkpt('sphere');
//
// mid section
//
this.up(radius - slices[0][1])
.cylinder(block,radius,(slices[0][1]*2)-1)
.down(radius-slices[0][1]);
var yOffset = -1;
for (var i = 1; i < slices.length;i++)
{
yOffset += slices[i-1][1];
var sr = slices[i][0];
var sh = slices[i][1];
var v = radius + yOffset, h = radius-sr;
// northern hemisphere
this.up(v).fwd(h).right(h)
.cylinder(block,sr,sh)
.left(h).back(h).down(v);
// southern hemisphere
v = radius - (yOffset+sh+1);
this.up(v).fwd(h).right(h)
.cylinder(block,sr,sh)
.left(h).back(h). down(v);
}
return this.move('sphere');
});
//
// sphere0 creates an empty sphere but the code needs work
@ -46,8 +46,8 @@ Drone.extend('sphere', function(block,radius)
//
Drone.extend('sphere0', function(block,radius)
{
return this.sphere(block,radius)
.fwd().right().up()
.sphere(0,radius-1)
.back().left().down();
return this.sphere(block,radius)
.fwd().right().up()
.sphere(0,radius-1)
.back().left().down();
});

View file

@ -3,273 +3,279 @@
other players to their home and also visit other player's homes.
*/
plugin("homes", {
help: function(){
return [
/* basic functions */
"/jsp home : Return to your own home",
"/jsp home <player> : Go to player's home",
"/jsp home set : Set your current location as home",
"/jsp home delete : Delete your home location",
help: function(){
return [
/* basic functions */
"/jsp home : Return to your own home",
"/jsp home <player> : Go to player's home",
"/jsp home set : Set your current location as home",
"/jsp home delete : Delete your home location",
/* social */
"/jsp home list : List homes you can visit",
"/jsp home ilist : List players who can visit your home",
"/jsp home invite <player> : Invite <player> to your home",
"/jsp home uninvite <player> : Uninvite <player> to your home",
"/jsp home public : Open your home to all players",
"/jsp home private : Make your home private",
/* social */
"/jsp home list : List homes you can visit",
"/jsp home ilist : List players who can visit your home",
"/jsp home invite <player> : Invite <player> to your home",
"/jsp home uninvite <player> : Uninvite <player> to your home",
"/jsp home public : Open your home to all players",
"/jsp home private : Make your home private",
/* administration */
"/jsp home listall : Show all houses (ops only)",
"/jsp home clear <player> : Clears player's home location (ops only)"
];
},
/* ========================================================================
basic functions
======================================================================== */
/* administration */
"/jsp home listall : Show all houses (ops only)",
"/jsp home clear <player> : Clears player's home location (ops only)"
];
},
/* ========================================================================
basic functions
======================================================================== */
go: function(guest, host){
if (typeof host == "undefined")
host = guest;
guest = getPlayerObject(guest);
host = getPlayerObject(host);
var location = this.store.houses[host.name];
if (!location){
guest.sendMessage(host.name + " has no home");
return;
}
if (!this._canVisit(guest,host)){
guest.sendMessage("You can't visit " + host.name + "'s home yet");
return;
}
var worldName = location[0], x = location[1], y = location[2], z=location[3], yaw=location[4];
var homeLoc = new org.bukkit.Location(org.bukkit.Bukkit.getWorld(worldName),x,y,z,yaw,0);
guest.teleport(homeLoc);
},
/*
determine whether a guest is allow visit a host's home
*/
_canVisit: function(guest, host){
if (guest == host)
return true;
if (this.store.openHouses[host.name])
return true;
var invitations = this.store.invites[host.name];
if (invitations)
for (var i = 0;i < invitations.length;i++)
if (invitations[i] == guest.name)
return true;
return false;
},
set: function(player){
player = getPlayerObject(player);
var loc = player.location;
this.store.houses[player.name] = [""+loc.world.name, Math.floor(loc.x), Math.floor(loc.y), Math.floor(loc.z), Math.floor(loc.yaw), Math.floor(loc.pitch)];
},
remove: function(player){
player = getPlayerObject(player);
delete this.store.houses[player.name];
},
/* ========================================================================
social functions
======================================================================== */
/*
list homes which the player can visit
*/
list: function(player){
var result = [];
for (var ohp in this.store.openHouses)
result.push(ohp);
player = getPlayerObject(player);
for (var host in this.store.invites){
var guests = this.store.invites[host];
for (var i = 0;i < guests.length; i++)
if (guests[i] == player.name)
result.push(host);
}
return result;
},
/*
list who can visit the player's home
*/
ilist: function(player){
player = getPlayerObject(player);
var result = [];
// if home is public - all players
if (this.store.openHouses[player.name]){
var online = org.bukkit.Bukkit.getOnlinePlayers();
for (var i = 0;i < online.length; i++)
if (online[i].name != player.name)
result.push(online[i].name);
}else{
result = this.store.invites[player.name] || [];
}
return result;
},
/*
Invite a player to the home
*/
invite: function(host, guest){
host = getPlayerObject(host);
guest = getPlayerObject(guest);
var invitations = this.store.invites[host.name] || [];
invitations.push(guest.name);
this.store.invites[host.name] = invitations;
guest.sendMessage(host.name + " has invited you to their home.");
guest.sendMessage("type '/jsp home " + host.name + "' to accept");
},
/*
Uninvite someone to the home
*/
uninvite: function(host, guest){
host = getPlayerObject(host);
guest = getPlayerObject(guest);
var invitations = this.store.invites[host.name];
if (!invitations)
return;
var revisedInvites = [];
for (var i =0;i < invitations.length; i++)
if (invitations[i] != guest.name)
revisedInvites.push(invitations[i]);
this.store.invites[host.name] = revisedInvites;
},
/*
make the player's house public
*/
open: function(player, optionalMsg){
player = getPlayerObject(player);
this.store.openHouses[player.name] = true;
if (typeof optionalMsg != "undefined")
__plugin.server.broadcastMessage(optionalMsg);
},
/*
make the player's house private
*/
close: function(player){
player = getPlayerObject(player);
delete this.store.openHouses[player.name];
},
/* ========================================================================
admin functions
======================================================================== */
listall: function(){
var result = [];
for (var home in this.store.houses)
result.push(home);
return result;
},
clear: function(player){
player = getPlayerObject(player);
delete this.store.houses[player.name];
delete this.store.openHouses[player.name];
}
go: function(guest, host){
if (typeof host == "undefined")
host = guest;
guest = getPlayerObject(guest);
host = getPlayerObject(host);
var loc = this.store.houses[host.name];
if (!loc){
guest.sendMessage(host.name + " has no home");
return;
}
if (!this._canVisit(guest,host)){
guest.sendMessage("You can't visit " + host.name + "'s home yet");
return;
}
var worldName = loc[0], x = loc[1], y = loc[2], z=loc[3], yaw=loc[4];
var teleportCause = org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
var homeLoc = new org.bukkit.Location(org.bukkit.Bukkit.getWorld(worldName),x,y,z,yaw,0);
guest.teleport(homeLoc, teleportCause.PLUGIN);
},
/*
determine whether a guest is allow visit a host's home
*/
_canVisit: function(guest, host){
if (guest == host)
return true;
if (this.store.openHouses[host.name])
return true;
var invitations = this.store.invites[host.name];
if (invitations)
for (var i = 0;i < invitations.length;i++)
if (invitations[i] == guest.name)
return true;
return false;
},
set: function(player){
player = getPlayerObject(player);
var loc = player.location;
this.store.houses[player.name] = [""+loc.world.name
,Math.floor(loc.x)
,Math.floor(loc.y)
,Math.floor(loc.z)
,Math.floor(loc.yaw)
,Math.floor(loc.pitch)];
},
remove: function(player){
player = getPlayerObject(player);
delete this.store.houses[player.name];
},
/* ========================================================================
social functions
======================================================================== */
/*
list homes which the player can visit
*/
list: function(player){
var result = [];
for (var ohp in this.store.openHouses)
result.push(ohp);
player = getPlayerObject(player);
for (var host in this.store.invites){
var guests = this.store.invites[host];
for (var i = 0;i < guests.length; i++)
if (guests[i] == player.name)
result.push(host);
}
return result;
},
/*
list who can visit the player's home
*/
ilist: function(player){
player = getPlayerObject(player);
var result = [];
// if home is public - all players
if (this.store.openHouses[player.name]){
var online = org.bukkit.Bukkit.getOnlinePlayers();
for (var i = 0;i < online.length; i++)
if (online[i].name != player.name)
result.push(online[i].name);
}else{
result = this.store.invites[player.name] || [];
}
return result;
},
/*
Invite a player to the home
*/
invite: function(host, guest){
host = getPlayerObject(host);
guest = getPlayerObject(guest);
var invitations = this.store.invites[host.name] || [];
invitations.push(guest.name);
this.store.invites[host.name] = invitations;
guest.sendMessage(host.name + " has invited you to their home.");
guest.sendMessage("type '/jsp home " + host.name + "' to accept");
},
/*
Uninvite someone to the home
*/
uninvite: function(host, guest){
host = getPlayerObject(host);
guest = getPlayerObject(guest);
var invitations = this.store.invites[host.name];
if (!invitations)
return;
var revisedInvites = [];
for (var i =0;i < invitations.length; i++)
if (invitations[i] != guest.name)
revisedInvites.push(invitations[i]);
this.store.invites[host.name] = revisedInvites;
},
/*
make the player's house public
*/
open: function(player, optionalMsg){
player = getPlayerObject(player);
this.store.openHouses[player.name] = true;
if (typeof optionalMsg != "undefined")
__plugin.server.broadcastMessage(optionalMsg);
},
/*
make the player's house private
*/
close: function(player){
player = getPlayerObject(player);
delete this.store.openHouses[player.name];
},
/* ========================================================================
admin functions
======================================================================== */
listall: function(){
var result = [];
for (var home in this.store.houses)
result.push(home);
return result;
},
clear: function(player){
player = getPlayerObject(player);
delete this.store.houses[player.name];
delete this.store.openHouses[player.name];
}
}, true);
/*
private implementation
private implementation
*/
(function(){
/*
define a set of command options that can be used by players
*/
var options = {
set: function(){homes.set();},
'delete': function(){ homes.remove();},
help: function(){ __self.sendMessage(homes.help());},
list: function(){
var visitable = homes.list();
if (visitable.length == 0){
__self.sendMessage("There are no homes to visit");
return;
}else{
__self.sendMessage([
"You can visit any of these " + visitable.length + " homes"
,visitable.join(", ")
]);
}
},
ilist: function(){
var potentialVisitors = homes.ilist();
if (potentialVisitors.length == 0)
__self.sendMessage("No one can visit your home");
else
__self.sendMessage([
"These " + potentialVisitors.length + "players can visit your home",
potentialVisitors.join(", ")]);
},
invite: function(params){
if (params.length == 1){
__self.sendMessage("You must provide a player's name");
return;
}
var playerName = params[1];
var guest = getPlayerObject(playerName);
if (!guest)
__self.sendMessage(playerName + " is not here");
else
homes.invite(__self,guest);
},
uninvite: function(params){
if (params.length == 1){
__self.sendMessage("You must provide a player's name");
return;
}
var playerName = params[1];
var guest = getPlayerObject(playerName);
if (!guest)
__self.sendMessage(playerName + " is not here");
else
homes.uninvite(__self,guest);
},
'public': function(params){
homes.open(__self,params.slice(1).join(' '));
__self.sendMessage("Your home is open to the public");
},
'private': function(){
homes.close();
__self.sendMessage("Your home is closed to the public");
},
listall: function(){
if (!__self.isOp())
__self.sendMessage("Only operators can do this");
else
__self.sendMessage(homes.listall().join(", "));
},
clear: function(params){
if (!__self.isOp())
__self.sendMessage("Only operators can do this");
else
homes.clear(params[1]);
}
};
var optionList = [];
for (var o in options)
optionList.push(o);
/*
Expose a set of commands that players can use at the in-game command prompt
*/
command("home", function(params){
if (params.length == 0){
homes.go();
return;
}
var option = options[params[0]];
if (option)
option(params);
else{
var host = getPlayerObject(params[0]);
if (!host)
__self.sendMessage(params[0] + " is not here");
else
homes.go(__self,host);
}
},optionList);
/*
define a set of command options that can be used by players
*/
var options = {
set: function(){homes.set();},
'delete': function(){ homes.remove();},
help: function(){ __self.sendMessage(homes.help());},
list: function(){
var visitable = homes.list();
if (visitable.length == 0){
__self.sendMessage("There are no homes to visit");
return;
}else{
__self.sendMessage([
"You can visit any of these " + visitable.length + " homes"
,visitable.join(", ")
]);
}
},
ilist: function(){
var potentialVisitors = homes.ilist();
if (potentialVisitors.length == 0)
__self.sendMessage("No one can visit your home");
else
__self.sendMessage([
"These " + potentialVisitors.length + "players can visit your home",
potentialVisitors.join(", ")]);
},
invite: function(params){
if (params.length == 1){
__self.sendMessage("You must provide a player's name");
return;
}
var playerName = params[1];
var guest = getPlayerObject(playerName);
if (!guest)
__self.sendMessage(playerName + " is not here");
else
homes.invite(__self,guest);
},
uninvite: function(params){
if (params.length == 1){
__self.sendMessage("You must provide a player's name");
return;
}
var playerName = params[1];
var guest = getPlayerObject(playerName);
if (!guest)
__self.sendMessage(playerName + " is not here");
else
homes.uninvite(__self,guest);
},
'public': function(params){
homes.open(__self,params.slice(1).join(' '));
__self.sendMessage("Your home is open to the public");
},
'private': function(){
homes.close();
__self.sendMessage("Your home is closed to the public");
},
listall: function(){
if (!__self.isOp())
__self.sendMessage("Only operators can do this");
else
__self.sendMessage(homes.listall().join(", "));
},
clear: function(params){
if (!__self.isOp())
__self.sendMessage("Only operators can do this");
else
homes.clear(params[1]);
}
};
var optionList = [];
for (var o in options)
optionList.push(o);
/*
Expose a set of commands that players can use at the in-game command prompt
*/
command("home", function(params){
if (params.length == 0){
homes.go();
return;
}
var option = options[params[0]];
if (option)
option(params);
else{
var host = getPlayerObject(params[0]);
if (!host)
__self.sendMessage(params[0] + " is not here");
else
homes.go(__self,host);
}
},optionList);
/*
initialize the store
*/
homes.store.houses = homes.store.houses || {};
homes.store.openHouses = homes.store.openHouses || {};
homes.store.invites = homes.store.invites || {};
/*
initialize the store
*/
homes.store.houses = homes.store.houses || {};
homes.store.openHouses = homes.store.openHouses || {};
homes.store.invites = homes.store.invites || {};
}());