Skip to content

Commit 319573d

Browse files
Merge pull request #403 from VolmitSoftware/Development
Dev Update
2 parents 52d91d5 + 3af52f9 commit 319573d

File tree

9 files changed

+440
-58
lines changed

9 files changed

+440
-58
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ plugins {
2323
id "de.undercouch.download" version "5.0.1"
2424
}
2525

26-
version '1.6.1-1.19.3'
26+
version '1.6.2-1.19.3'
2727
def nmsVersion = "1.19.3" //[NMS]
2828
def apiVersion = '1.19'
2929
def specialSourceVersion = '1.11.0' //[NMS]
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
/*------------------------------------------------------------------------------
2+
- Adapt is a Skill/Integration plugin for Minecraft Bukkit Servers
3+
- Copyright (c) 2022 Arcane Arts (Volmit Software)
4+
-
5+
- This program is free software: you can redistribute it and/or modify
6+
- it under the terms of the GNU General Public License as published by
7+
- the Free Software Foundation, either version 3 of the License, or
8+
- (at your option) any later version.
9+
-
10+
- This program is distributed in the hope that it will be useful,
11+
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
- GNU General Public License for more details.
14+
-
15+
- You should have received a copy of the GNU General Public License
16+
- along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
-----------------------------------------------------------------------------*/
18+
19+
package com.volmit.adapt.content.adaptation.ranged;
20+
21+
import com.volmit.adapt.Adapt;
22+
import com.volmit.adapt.api.adaptation.SimpleAdaptation;
23+
import com.volmit.adapt.api.recipe.AdaptRecipe;
24+
import com.volmit.adapt.api.recipe.MaterialChar;
25+
import com.volmit.adapt.content.item.BoundSnowBall;
26+
import com.volmit.adapt.util.C;
27+
import com.volmit.adapt.util.Element;
28+
import com.volmit.adapt.util.J;
29+
import com.volmit.adapt.util.Localizer;
30+
import lombok.NoArgsConstructor;
31+
import org.bukkit.*;
32+
import org.bukkit.block.Block;
33+
import org.bukkit.block.data.BlockData;
34+
import org.bukkit.entity.Entity;
35+
import org.bukkit.entity.Player;
36+
import org.bukkit.entity.Snowball;
37+
import org.bukkit.event.EventHandler;
38+
import org.bukkit.event.EventPriority;
39+
import org.bukkit.event.block.BlockBreakEvent;
40+
import org.bukkit.event.block.BlockExplodeEvent;
41+
import org.bukkit.event.block.BlockPistonExtendEvent;
42+
import org.bukkit.event.block.BlockPistonRetractEvent;
43+
import org.bukkit.event.entity.EntityExplodeEvent;
44+
import org.bukkit.event.entity.ProjectileHitEvent;
45+
import org.bukkit.event.entity.ProjectileLaunchEvent;
46+
47+
import java.util.*;
48+
49+
public class RangedWebBomb extends SimpleAdaptation<RangedWebBomb.Config> {
50+
private static final BlockData AIR = Material.AIR.createBlockData();
51+
private static final BlockData BLOCK = Material.COBWEB.createBlockData();
52+
private final Map<Entity, Player> activeSnowballs;
53+
private final Set<Block> activeBlocks;
54+
55+
public RangedWebBomb() {
56+
super("ranged-webshot");
57+
registerConfiguration(Config.class);
58+
setDescription(Localizer.dLocalize("ranged", "webshot", "description"));
59+
setDisplayName(Localizer.dLocalize("ranged", "webshot", "name"));
60+
setIcon(Material.COBWEB);
61+
setBaseCost(getConfig().baseCost);
62+
setMaxLevel(getConfig().maxLevel);
63+
setInterval(4900);
64+
setInitialCost(getConfig().initialCost);
65+
setCostFactor(getConfig().costFactor);
66+
registerRecipe(AdaptRecipe.shaped()
67+
.key("ranged-web-bomb")
68+
.ingredient(new MaterialChar('I', Material.COBWEB))
69+
.ingredient(new MaterialChar('S', Material.SNOWBALL))
70+
.shapes(List.of(
71+
"III",
72+
"ISI",
73+
"III"))
74+
.result(BoundSnowBall.io.withData(new BoundSnowBall.Data(null)))
75+
.build());
76+
activeBlocks = new HashSet<>();
77+
activeSnowballs = new HashMap<>();
78+
}
79+
80+
@Override
81+
public void addStats(int level, Element v) {
82+
v.addLore(C.GREEN + "+ " + Localizer.dLocalize("ranged", "webshot", "lore1"));
83+
v.addLore(C.YELLOW + "+ " + level + C.GRAY + " " + Localizer.dLocalize("ranged", "webshot", "lore2"));
84+
}
85+
86+
87+
@EventHandler
88+
public void on(ProjectileHitEvent e) {
89+
if (e.isCancelled()) {
90+
return;
91+
}
92+
Block block;
93+
94+
if (e.getHitEntity() != null) {
95+
block = e.getHitEntity().getLocation().add(0, 1, 0).getBlock();
96+
} else if (e.getHitBlock() != null) {
97+
block = e.getHitBlock().getLocation().add(0, 1, 0).getBlock();
98+
} else {
99+
block = e.getEntity().getLocation().add(0, 1, 0).getBlock();
100+
}
101+
102+
if (e.getEntity().getShooter() instanceof Player p && e.getEntity() instanceof Snowball snowball && hasAdaptation(p)) {
103+
vfxSingleCubeOutline(block, Particle.REVERSE_PORTAL);
104+
Adapt.verbose("Snowball Got: " + snowball.getEntityId() + " " + snowball.getUniqueId());
105+
if (activeSnowballs.containsKey(Bukkit.getEntity(snowball.getUniqueId()))) {
106+
Adapt.verbose("Detected snowball hit");
107+
activeSnowballs.remove(snowball);
108+
snowball.remove();
109+
Set<Block> locs = new HashSet<>();
110+
locs.add(block.getLocation().add(0, 1, 0).getBlock());
111+
locs.add(block.getLocation().add(0, -1, 0).getBlock());
112+
locs.add(block.getLocation().add(0, 0, 1).getBlock());
113+
locs.add(block.getLocation().add(0, 0, -1).getBlock());
114+
locs.add(block.getLocation().add(1, 0, 0).getBlock());
115+
locs.add(block.getLocation().add(-1, 0, 0).getBlock());
116+
117+
for (Block i : locs) {
118+
addFoundation(i, getLevel(p));
119+
}
120+
121+
}
122+
}
123+
}
124+
125+
126+
@EventHandler
127+
public void on(ProjectileLaunchEvent e) {
128+
if (e.isCancelled()) {
129+
return;
130+
}
131+
if (e.getEntity().getShooter() instanceof Player p && e.getEntity() instanceof Snowball snowball && hasAdaptation(p)) {
132+
Adapt.verbose("Snowball Launched: " + snowball.getEntityId() + " " + snowball.getUniqueId());
133+
if (BoundSnowBall.isBindableItem(snowball.getItem())) {
134+
Adapt.verbose("Snowball is bound");
135+
activeSnowballs.put(snowball, p);
136+
} else {
137+
Adapt.verbose("Snowball is not bound");
138+
}
139+
}
140+
}
141+
142+
public void addFoundation(Block block, int seconds) {
143+
if (!block.getType().isAir()) {
144+
return;
145+
}
146+
147+
J.s(() -> {
148+
block.setBlockData(BLOCK);
149+
activeBlocks.add(block);
150+
});
151+
block.getWorld().playSound(block.getLocation(), Sound.BLOCK_ROOTED_DIRT_PLACE, 1.0f, 1.0f);
152+
if (getConfig().showParticles) {
153+
154+
vfxSingleCubeOutline(block, Particle.CLOUD);
155+
vfxSingleCubeOutline(block, Particle.WHITE_ASH);
156+
}
157+
J.a(() -> removeFoundation(block), seconds * 16);
158+
}
159+
160+
public void removeFoundation(Block block) {
161+
if (!block.getBlockData().equals(BLOCK)) {
162+
return;
163+
}
164+
165+
J.s(() -> {
166+
block.setBlockData(AIR);
167+
activeBlocks.remove(block);
168+
});
169+
block.getWorld().playSound(block.getLocation(), Sound.BLOCK_ROOTED_DIRT_BREAK, 1.0f, 1.0f);
170+
if (getConfig().showParticles) {
171+
vfxSingleCubeOutline(block, Particle.ENCHANTMENT_TABLE);
172+
}
173+
}
174+
175+
176+
//prevent piston from moving blocks // Dupe fix
177+
@EventHandler(priority = EventPriority.HIGHEST)
178+
public void on(BlockPistonExtendEvent e) {
179+
if (e.isCancelled()) {
180+
return;
181+
}
182+
e.getBlocks().forEach(b -> {
183+
if (activeBlocks.contains(b)) {
184+
Adapt.verbose("Cancelled Piston Extend on Adaptation Foundation Block");
185+
e.setCancelled(true);
186+
}
187+
});
188+
}
189+
190+
//prevent piston from pulling blocks // Dupe fix
191+
@EventHandler(priority = EventPriority.HIGHEST)
192+
public void on(BlockPistonRetractEvent e) {
193+
if (e.isCancelled()) {
194+
return;
195+
}
196+
e.getBlocks().forEach(b -> {
197+
if (activeBlocks.contains(b)) {
198+
Adapt.verbose("Cancelled Piston Retract on Adaptation Foundation Block");
199+
e.setCancelled(true);
200+
}
201+
});
202+
}
203+
204+
//prevent TNT from destroying blocks // Dupe fix
205+
@EventHandler(priority = EventPriority.HIGHEST)
206+
public void on(BlockExplodeEvent e) {
207+
if (e.isCancelled()) {
208+
return;
209+
}
210+
if (activeBlocks.contains(e.getBlock())) {
211+
Adapt.verbose("Cancelled Block Explosion on Adaptation Foundation Block");
212+
e.setCancelled(true);
213+
}
214+
}
215+
216+
//prevent block from being destroyed // Dupe fix
217+
@EventHandler(priority = EventPriority.HIGHEST)
218+
public void on(BlockBreakEvent e) {
219+
if (activeBlocks.contains(e.getBlock())) {
220+
e.setCancelled(true);
221+
}
222+
}
223+
224+
//prevent Entities from destroying blocks // Dupe fix
225+
@EventHandler(priority = EventPriority.HIGHEST)
226+
public void on(EntityExplodeEvent e) {
227+
if (e.isCancelled()) {
228+
return;
229+
}
230+
e.blockList().removeIf(activeBlocks::contains);
231+
}
232+
233+
234+
@Override
235+
public void onTick() {
236+
237+
}
238+
239+
@Override
240+
public boolean isEnabled() {
241+
return getConfig().enabled;
242+
}
243+
244+
@Override
245+
public boolean isPermanent() {
246+
return getConfig().permanent;
247+
}
248+
249+
@NoArgsConstructor
250+
protected static class Config {
251+
boolean permanent = false;
252+
boolean enabled = true;
253+
boolean showParticles = true;
254+
int baseCost = 5;
255+
int maxLevel = 5;
256+
int initialCost = 1;
257+
double costFactor = 1.5;
258+
}
259+
}

src/main/java/com/volmit/adapt/content/item/BoundEnderPearl.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,16 @@ public static ItemStack withData(Block t) {
5555
}
5656

5757
public static boolean isBindableItem(ItemStack t) {
58-
if (!t.getType().equals(Material.ENDER_PEARL)) {
59-
return false;
60-
}
61-
Adapt.verbose("Checking if item is bindable: " + t.getType().name());
62-
if (t.getItemMeta() == null || t.getItemMeta().getLore() == null) {
63-
Adapt.verbose("Pearl is not bindable: " + t.getType().name());
64-
return false;
65-
}
66-
if (t.getItemMeta().getLore().get(0).contains(Localizer.dLocalize("items", "boundenderperal", "name"))) {
67-
Adapt.verbose("Ender Pearl is bindable: " + t.getType().name());
68-
return true;
69-
} else {
70-
Adapt.verbose("Item is not bindable: " + t.getType().name());
71-
return false;
58+
Adapt.verbose("Checking if item is a bindable enderpearl: " + t.getType().name());
59+
if (t.getType().equals(Material.SNOWBALL)) {
60+
if (t.getItemMeta() != null && t.getItemMeta().getLore() != null) {
61+
if (t.getItemMeta().getLore().get(0).contains(Localizer.dLocalize("items", "boundenderperal", "name"))) {
62+
Adapt.verbose("Enderpearl is bindable: " + t.getType().name());
63+
return true;
64+
}
65+
}
7266
}
67+
return false;
7368
}
7469

7570
@Override

src/main/java/com/volmit/adapt/content/item/BoundRedstoneTorch.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,16 @@ public static ItemStack withData(Location t) {
5555
}
5656

5757
public static boolean isBindableItem(ItemStack t) {
58-
if (!t.getType().equals(Material.REDSTONE_TORCH)) {
59-
return false;
60-
}
61-
Adapt.verbose("Checking if item is bindable: " + t.getType().name());
62-
if (t.getItemMeta() == null || t.getItemMeta().getLore() == null) {
63-
Adapt.verbose("Item is not bindable: " + t.getType().name());
64-
return false;
65-
}
66-
if (t.getItemMeta().getLore().get(0).contains(Localizer.dLocalize("items", "boundredstonetorch", "name"))) {
67-
Adapt.verbose("Item is bindable: " + t.getType().name());
68-
return true;
69-
} else {
70-
Adapt.verbose("Item is not bindable: " + t.getType().name());
71-
return false;
58+
Adapt.verbose("Checking if item is a bindable Torch: " + t.getType().name());
59+
if (t.getType().equals(Material.REDSTONE_TORCH)) {
60+
if (t.getItemMeta() != null && t.getItemMeta().getLore() != null) {
61+
if (t.getItemMeta().getLore().get(0).contains(Localizer.dLocalize("items", "boundredstonetorch", "name"))) {
62+
Adapt.verbose("Torch is bindable: " + t.getType().name());
63+
return true;
64+
}
65+
}
7266
}
67+
return false;
7368
}
7469

7570
@Override

0 commit comments

Comments
 (0)