-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrows.js
171 lines (151 loc) · 4.55 KB
/
arrows.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
'use strict';
/*global require, __plugin, exports, events, setTimeout */
/*************************************************************************
## Arrows Plugin
The arrows mod adds fancy arrows to the game. Arrows which ...
* Launch fireworks.
* Explode on impact.
* Force Lightning to strike where they land.
* Teleport the player to the landing spot.
* Spawn Trees at the landing spot.
### Usage:
* `/js arrows.firework(self)` - A firework launches where the the arrow lands.
* `/js arrows.lightning(self)` - lightning strikes where the arrow lands.
* `/js arrows.teleport(self)` - makes player teleport to where arrow has landed.
* `/js arrows.flourish(self)` - makes a tree grow where the arrow lands.
* `/js arrows.explosive(self)` - makes arrows explode.
* `/js arrows.normal(self)` sets arrow type to normal.
* `/js arrows.sign(self)` turns a targeted sign into an Arrows menu
All of the above functions can take an optional player object or name
as a parameter. For example: `/js arrows.explosive('player23')` makes
player23's arrows explosive.
***/
var Drone = require('drone'),
teleport = require('teleport'),
signs = require('signs'),
fireworks = require('fireworks'),
utils = require('utils'),
bkArrow = org.bukkit.entity.Arrow,
bkPlayer = org.bukkit.entity.Player,
EXPLOSIVE_YIELD = 2.5,
store = persist('arrows',{ players: { } }),
arrows = {},
i,
type,
_types = [ 'Normal', 'Explosive', 'Teleport', 'Flourish', 'Lightning', 'Firework' ];
exports.arrows = arrows;
for ( i = 0; i < _types.length; i++ ) {
type = _types[i].toLowerCase();
// iife (immediately-invoked function expression)
arrows[ type ] = ( function( n ) {
return function( player ) {
player = utils.player( player );
if ( player ) {
store.players[ player.name ] = n;
} else {
console.warn('arrows.' + n + ' No player ' + player);
}
};
} )( i );
}
/*
called when the player chooses an arrow option from a menu sign
*/
var _onMenuChoice = function( event ) {
store.players[ event.player.name ] = event.number;
};
var convertToArrowSign = signs.menu( 'Arrow', _types, _onMenuChoice );
/*
turn a sign into a menu of arrow choices
*/
arrows.sign = function( cmdSender ) {
var sign = signs.getTargetedBy( cmdSender );
if ( !sign ) {
throw new Error( 'You must first look at a sign!' );
}
return convertToArrowSign( sign, true );
};
/*
event handler called when a projectile hits something
*/
function onBukkitArrowHit( event ) {
var projectile = event.entity,
world = projectile.world,
shooter = projectile.shooter,
fireworkCount = 5,
arrowType;
function launch(){
fireworks.firework( projectile.location );
if ( --fireworkCount ) {
setTimeout( launch, 2000 );
}
}
if (projectile instanceof bkArrow
&& shooter instanceof bkPlayer) {
arrowType = store.players[ shooter.name ];
switch ( arrowType ) {
case 1:
projectile.remove();
world.createExplosion( projectile.location, EXPLOSIVE_YIELD );
break;
case 2:
projectile.remove();
teleport(shooter, projectile.location);
break;
case 3:
projectile.remove();
new Drone(projectile.location).oak();
break;
case 4:
projectile.remove();
world.strikeLightning( projectile.location );
break;
case 5:
projectile.remove();
launch();
break;
}
}
}
function onCanaryArrowHit( event ) {
var projectile = event.projectile,
world = projectile.world,
shooter = projectile.owner,
fireworkCount = 5,
arrowType,
cmArrow = Packages.net.canarymod.api.entity.Arrow,
cmPlayer = Packages.net.canarymod.api.entity.living.humanoid.Player,
loc = projectile.location,
launch = function( ) {
fireworks.firework( loc);
if ( --fireworkCount ) {
setTimeout( launch, 2000 );
}
};
if (projectile instanceof cmArrow && shooter instanceof cmPlayer) {
arrowType = store.players[ shooter.name ];
switch ( arrowType ) {
case 1:
projectile.destroy();
world.makeExplosion( shooter, loc, EXPLOSIVE_YIELD, true );
break;
case 2:
projectile.destroy();
teleport(shooter, loc);
break;
case 3:
projectile.destroy();
new Drone( loc ).oak();
break;
case 4:
projectile.destroy();
world.makeLightningBolt( loc );
break;
case 5:
projectile.destroy();
launch();
break;
}
}
}
events.projectileHit( __plugin.bukkit ? onBukkitArrowHit : onCanaryArrowHit);