-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAromatherapy.java
More file actions
238 lines (203 loc) · 6.83 KB
/
Copy pathAromatherapy.java
File metadata and controls
238 lines (203 loc) · 6.83 KB
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ability.AddonAbility;
import com.projectkorra.projectkorra.ability.ComboAbility;
import com.projectkorra.projectkorra.ability.CoreAbility;
import com.projectkorra.projectkorra.ability.HealingAbility;
import com.projectkorra.projectkorra.ability.util.ComboManager.AbilityInformation;
import com.projectkorra.projectkorra.attribute.Attribute;
import com.projectkorra.projectkorra.command.Commands;
import com.projectkorra.projectkorra.region.RegionProtection;
import com.projectkorra.projectkorra.util.ClickType;
import com.projectkorra.projectkorra.util.ParticleEffect;
import com.projectkorra.projectkorra.waterbending.healing.HealingWaters;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.ArrayList;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Consumer;
public class Aromatherapy extends HealingAbility implements AddonAbility, ComboAbility {
private final String path = "";
@Attribute(Attribute.COOLDOWN)
private long cooldown;
@Attribute(Attribute.SELECT_RANGE)
private double select_range;
@Attribute(Attribute.RADIUS)
private double max_radius;
private double radius;
private Block target;
private Location origin;
public Aromatherapy(Player player) {
super(player);
if (!bPlayer.canBendIgnoreBindsCooldowns(this)) {
return;
} else if (bPlayer.isOnCooldown(this)) {
return;
} else if (!bPlayer.canWaterHeal() || !bPlayer.canPlantbend()) {
return;
} else if (RegionProtection.isRegionProtected(player, player.getLocation(), this)) {
return;
}
this.cooldown = ConfigManager.getConfig().getLong(path + "Cooldown");
this.select_range = ConfigManager.getConfig().getDouble(path + "SelectRange");
this.max_radius = ConfigManager.getConfig().getDouble(path + "Radius");
this.target = rayTraceBlock(player, this.select_range);
if (this.target == null) return;
if (RegionProtection.isRegionProtected(player, this.target.getLocation(), this)) {
return;
}
this.origin = this.target.getLocation().clone().add(0.5, 0.5, 0.5);
if (CoreAbility.hasAbility(player, HealingWaters.class)) {
getAbility(player, HealingWaters.class).remove();
}
start();
}
@Override
public void progress() {
if (!player.isSneaking()) {
remove();
return;
}
if (player.getLocation().distanceSquared(this.origin) > this.max_radius * this.max_radius) {
remove();
return;
}
this.radius += 0.1;
if (this.radius > this.max_radius) this.radius = 0;
player.getWorld().spawnParticle(Particle.SPORE_BLOSSOM_AIR, this.origin, 10, this.max_radius / 2.0, this.max_radius / 2.0, this.max_radius / 2.0, 0);
circle(this.origin, this.radius, l -> {
if (ThreadLocalRandom.current().nextInt(80) == 0) {
player.getWorld().spawnParticle(Particle.GLOW, l, 1, 0, 0, 0, 0.1);
ParticleEffect.FALLING_DUST.display(l, 1, 0.35F, 0.35F, 0.35F, 0.01F, l.getBlock().getBlockData());
}
for (Entity entity : GeneralMethods.getEntitiesAroundPoint(l, 1)) {
if (entity instanceof LivingEntity) {
if (entity instanceof Player) {
if (Commands.invincible.contains(entity.getName())) continue;
}
if (!((LivingEntity) entity).hasPotionEffect(PotionEffectType.REGENERATION)) {
if (isFlowers(l.getBlock().getType())) {
((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 75, 1));
} else {
((LivingEntity) entity).addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 150, 0));
}
}
}
}
});
}
private void circle(Location location, double size, Consumer<Location> consumer) {
for (int angle = 0; angle < 180; angle++) {
double x = size * Math.cos(Math.toRadians(angle - 360) * 2);
double z = size * Math.sin(Math.toRadians(angle - 360) * 2);
Location circle = location.clone().add(x, 0, z);
Block top = GeneralMethods.getTopBlock(circle, 3);
if (!RegionProtection.isRegionProtected(player, top.getLocation(), this)) {
if (isPlant(top)) {
consumer.accept(top.getLocation().clone().add(0.5, 0.5, 0.5));
}
}
}
}
public static Block rayTraceBlock(Player player, double range) {
RayTraceResult result = player.getWorld().rayTraceBlocks(player.getEyeLocation().clone(), player.getEyeLocation().getDirection(), range);
if (result != null) {
return result.getHitBlock();
}
return null;
}
public static boolean isFlowers(Material material) {
switch (material) {
case DANDELION:
case POPPY:
case BLUE_ORCHID:
case ALLIUM:
case AZURE_BLUET:
case RED_TULIP:
case ORANGE_TULIP:
case PINK_TULIP:
case WHITE_TULIP:
case OXEYE_DAISY:
case CORNFLOWER:
case LILY_OF_THE_VALLEY:
case WITHER_ROSE:
case SUNFLOWER:
case LILAC:
case ROSE_BUSH:
case PEONY:
return true;
}
return false;
}
public static boolean isFlowers(Block block) {
return isFlowers(block.getType());
}
@Override
public boolean isSneakAbility() {
return true;
}
@Override
public boolean isHarmlessAbility() {
return true;
}
@Override
public long getCooldown() {
return cooldown;
}
@Override
public String getName() {
return "Aromatherapy";
}
@Override
public Location getLocation() {
return null;
}
@Override
public void remove() {
bPlayer.addCooldown(this);
super.remove();
}
@Override
public void load() { }
@Override
public void stop() { }
@Override
public boolean isEnabled() {
return ConfigManager.getConfig().getBoolean("Aromatherapy.Enabled", true);
}
@Override
public String getAuthor() {
return "Prride";
}
@Override
public String getVersion() {
return "1.0.0";
}
@Override
public String getDescription() {
return Element.WATER.getColor() + "Similarly to how waterbenders are able to use water in order to heal people, they are able to "
+ "cause widespread healing with the use of water containing special healing properties within plants and flowers by aromatherapy."
+ "\n(Default: being near plants provide regeneration 1 while flowers provide regeneration 2)";
}
@Override
public String getInstructions() {
return "PlantManipulation (Right click block) > HealingWaters (Hold sneak at a plant block)";
}
@Override
public Object createNewComboInstance(Player player) {
return new Aromatherapy(player);
}
@Override
public ArrayList<AbilityInformation> getCombination() {
ArrayList<AbilityInformation> info = new ArrayList<>();
info.add(new AbilityInformation("PlantManipulation", ClickType.RIGHT_CLICK_BLOCK));
info.add(new AbilityInformation("HealingWaters", ClickType.SHIFT_DOWN));
return info;
}
}