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; break;
case 2: case 2:
projectile.remove(); projectile.remove();
var teleportCause =org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
shooter.teleport(projectile.location, shooter.teleport(projectile.location,
org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.ENDER_PEARL); teleportCause.PLUGIN);
break; break;
case 3: case 3:
projectile.remove(); projectile.remove();

View file

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

View file

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

View file

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