Date: 2017/01/29 14:53:58 UTC-08:00
Type: Denizen Script
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
public class Demoman implements Kit, Listener {
private static ItemStack FIREWORK = new ItemManager(Material.FIREWORK).name(SimpleUtils.color("&a&lRocket")).build();
private static ItemStack MIRV = new ItemManager(Material.FIREBALL).amount(2).name(SimpleUtils.color("&a&lMIRV")).build();
private HashMap<UUID, String> mirvs = new HashMap<>();
private ArrayList<UUID> do_no_explode = new ArrayList<>();
private ConfigurationSection classConfiguration;
public Demoman() {
classConfiguration = Shift.plugin.getConfig().getConfigurationSection("demoman");
}
@EventHandler
public void onExplode(EntityExplodeEvent e) {
Entity e1 = e.getEntity();
e.blockList().clear();
if (do_no_explode.contains(e1.getUniqueId())) {
e.setYield((float) classConfiguration.getDouble("tnt-power", 4));
do_no_explode.remove(e.getEntity().getUniqueId());
}
}
@EventHandler
public void onFireballHit(ProjectileHitEvent e) {
Entity e1 = e.getEntity();
if (Shift.gs != GameState.STARTED) {
e1.remove();
}
if (!(e1 instanceof Fireball)) {
return;
}
Fireball fb = (Fireball) e1;
System.out.println("MIRVS: " + mirvs);
if (mirvs.containsKey(e1.getUniqueId())) {
Player p = Bukkit.getPlayer(mirvs.remove(e1.getUniqueId()));
if (p != null) {
MIRV(fb.getLocation(), p);
e.getEntity().remove();
}
}
}
@EventHandler
public void onRightClick(PlayerInteractEvent e) {
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
Player p = e.getPlayer();
ItemStack is = p.getItemInHand();
if (is.hasItemMeta() && is.getItemMeta().hasDisplayName()) {
if (is.getItemMeta().getDisplayName().equals(FIREWORK.getItemMeta().getDisplayName())) {
e.setCancelled(true);
return;
}
}
}
if (e.getAction() == Action.RIGHT_CLICK_AIR) {
Player p = e.getPlayer();
ItemStack is = p.getItemInHand();
if (is.hasItemMeta() && is.getItemMeta().hasDisplayName()) {
if (is.getItemMeta().getDisplayName().equals(FIREWORK.getItemMeta().getDisplayName())) {
e.setCancelled(true);
if (Shift.gs != GameState.STARTED) {
return;
}
is.setAmount(is.getAmount() - 1);
p.getInventory().setItemInMainHand(is);
Vector v = p.getLocation().getDirection().multiply(1.3);
Entity e2 = p.getWorld().spawnEntity(p.getLocation(), EntityType.PRIMED_TNT);
e2.setVelocity(v);
e2.setMetadata("thrower", new FixedMetadataValue(Shift.plugin, p.getName()));
((TNTPrimed) e2).setFuseTicks(20);
do_no_explode.add(e2.getUniqueId());
} else if (is.getItemMeta().getDisplayName().equals(MIRV.getItemMeta().getDisplayName())) {
e.setCancelled(true);
if (Shift.gs != GameState.STARTED) {
return;
}
is.setAmount(is.getAmount() - 1);
p.getInventory().setItemInMainHand(is);
Location l = p.getLocation();
l.add(0, 3, 0);
Entity fb1 = l.getWorld().spawnEntity(l, EntityType.FIREBALL);
Fireball fireball = (Fireball) fb1;
fireball.setIsIncendiary(false);
fireball.setBounce(false);
fireball.setDirection(new Vector().zero());
fireball.setCustomNameVisible(true);
fireball.setCustomName(SimpleUtils.color("&eMIRV -- &a" + p.getName()));
mirvs.put(fireball.getUniqueId(), p.getName());
fireball.setDirection(p.getLocation().getDirection());
}
}
}
}
private void MIRV(Location l, Player p) {
Location location = l;
List<Vector> vectorList = new ArrayList<>();
if (classConfiguration != null && classConfiguration.contains("tnt-velocities")) {
for (String configVector : classConfiguration.getStringList("tnt-velocities")) {
if (configVector.contains(":")) {
try {
double x, y, z;
x = Double.parseDouble(configVector.split(":")[0]);
y = Double.parseDouble(configVector.split(":")[1]);
z = Double.parseDouble(configVector.split(":")[2]);
vectorList.add(new Vector(x, y, z));
} catch (NumberFormatException ignore) {
ignore.printStackTrace();
System.out.println(configVector);
}
}
}
}
Vector[] vs = new Vector[]{
new Vector(0, 0, -1),
new Vector(1, 0, 0),
new Vector(-1, 0, 0),
new Vector(0, 0, 1),
new Vector(1, 0, -1),
new Vector(-1, 0, -1),
new Vector(1, 0, 1),
new Vector(-1, 0, 1)
};
if (vectorList.isEmpty()) {
Collections.addAll(vectorList, vs);
System.out.println("Demoman had no configurable vectors, using default values.");
}
int fuse = classConfiguration.getInt("tnt-tick-fuse", 20);
for (Vector v : vectorList) {
Entity entity = l.getWorld().spawnEntity(location, EntityType.PRIMED_TNT);
entity.setVelocity(v);
TNTPrimed tntPrimed = (TNTPrimed) entity;
tntPrimed.setFuseTicks(fuse);
tntPrimed.setMetadata("thrower", new FixedMetadataValue(Shift.plugin, p.getName()));
do_no_explode.add(tntPrimed.getUniqueId());
}
}
@Override
public HashMap<Integer, ItemStack> getSlottedItems(Integer level) {
return null;
}
@Override
public ArrayList<ItemStack> getNormalItems(Integer level) {
ArrayList<ItemStack> items = new ArrayList<>();
ItemStack woodPickaxe = new ItemStack(Material.WOOD_PICKAXE);
woodPickaxe.setAmount(classConfiguration.getInt(level + ".woodPickaxe", 0));
ItemStack firework = FIREWORK.clone();
firework.setAmount(classConfiguration.getInt(level + ".rocket", 0));
ItemStack mirv = MIRV.clone();
mirv.setAmount(classConfiguration.getInt(level + ".mirv", 0));
items.add(woodPickaxe);
items.add(firework);
items.add(mirv);
return items;
}
@Override
public Integer getMaxLevel() {
return 3;
}
@Override
public Integer getPrice(Integer level) {
if (level == 1) {
return 15000;
} else if (level == 2) {
return 40000;
} else if (level == 3) {
return 100000;
} else {
return null;
}
}
@Override
public String getName() {
return "DEMOMAN";
}
@Override
public String getDisplayName(Integer level) {
if (level == 0) {
return SimpleUtils.color("&9Demoman");
}
return SimpleUtils.color("&9Demoman &a" + level);
}
@Override
public Material getGUIItem() {
return Material.TNT;
}
@Override
public String getDisplayLore() {
return SimpleUtils.color("&aAre explosions your thing? Get a wooden pick, and enough explosives to be a master creeper in no time.");
}
}