Skip to content

Commit 2b1da75

Browse files
committed
* Blocks in the "break-only-effected" list can now use the format <material>:<delay> for individual delays.
* Fixed an issue allowing blocks in the avoided material list to be damaged by explosives.
1 parent c95199d commit 2b1da75

5 files changed

Lines changed: 59 additions & 31 deletions

File tree

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>dev.zotware.plugins</groupId>
88
<artifactId>PhysicsToGo</artifactId>
9-
<version>2.0.8</version>
9+
<version>2.0.9</version>
1010

1111
<properties>
1212
<java.version>1.8</java.version>
@@ -87,7 +87,7 @@
8787
<dependency>
8888
<groupId>org.spigotmc</groupId>
8989
<artifactId>spigot-api</artifactId>
90-
<version>1.20-R0.1-SNAPSHOT</version>
90+
<version>1.20.1-R0.1-SNAPSHOT</version>
9191
<scope>provided</scope>
9292
</dependency>
9393
<dependency>

src/main/java/xzot1k/plugins/ptg/core/Listeners.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ && getPluginInstance().getAdvancedConfig().getBoolean("cancel-flow-radius")) {
9797
}
9898
}
9999

100+
@SuppressWarnings("deprecation")
100101
@EventHandler(priority = EventPriority.LOWEST)
101102
public void onForm(EntityChangeBlockEvent e) {
102103
if (getPluginInstance().doesNotPassHooksCheck(e.getBlock().getLocation())) return;
@@ -117,6 +118,7 @@ public void onForm(EntityChangeBlockEvent e) {
117118
}
118119
}
119120

121+
@SuppressWarnings("deprecation")
120122
@EventHandler(priority = EventPriority.LOWEST)
121123
public void onPlace(BlockPlaceEvent e) {
122124
if (e.isCancelled() || getPluginInstance().doesNotPassHooksCheck(e.getBlock().getLocation())) return;
@@ -130,7 +132,7 @@ public void onPlace(BlockPlaceEvent e) {
130132
if (checkState(blockState, ActionType.PLACE)) return;
131133

132134
if (!getPluginInstance().getManager().isWhitelistedPlaceMaterial(e.getBlock().getType())
133-
|| getPluginInstance().getManager().isAvoidedMaterial(e.getBlock().getType()))
135+
|| getPluginInstance().getManager().isAvoidedMaterial(e.getBlock().getType(), e.getBlock().getData()))
134136
return;
135137

136138
if (getPluginInstance().getCoreProtectHook() != null && getPluginInstance().getConfig().getBoolean("core-protect"))
@@ -142,6 +144,7 @@ public void onPlace(BlockPlaceEvent e) {
142144
}
143145
}
144146

147+
@SuppressWarnings("deprecation")
145148
@EventHandler(priority = EventPriority.LOWEST)
146149
public void onBreak(BlockBreakEvent e) {
147150
if (e.isCancelled() || getPluginInstance().doesNotPassHooksCheck(e.getBlock().getLocation())) return;
@@ -163,7 +166,8 @@ public void onBreak(BlockBreakEvent e) {
163166
}
164167

165168
final BlockState blockState = e.getBlock().getState();
166-
final boolean drops = getPluginInstance().getConfig().getBoolean("tree-drops"), treeRegeneration = getPluginInstance().getConfig().getBoolean("tree-regeneration");
169+
final boolean drops = getPluginInstance().getConfig().getBoolean("tree-drops"),
170+
treeRegeneration = getPluginInstance().getConfig().getBoolean("tree-regeneration");
167171
if (checkState(blockState, ActionType.TREE_BREAK)) return;
168172

169173
e.setCancelled(true);
@@ -179,8 +183,8 @@ public void onBreak(BlockBreakEvent e) {
179183
final BlockState blockState = e.getBlock().getState();
180184
if (checkState(blockState, ActionType.BREAK)) return;
181185

182-
if (!getPluginInstance().getManager().isWhitelistedBreakMaterial(blockState.getType()) || getPluginInstance().getManager().isAvoidedMaterial(blockState.getType()))
183-
return;
186+
final Pair<Boolean, Integer> wbmPair = getPluginInstance().getManager().isWhitelistedBreakMaterial(blockState.getType());
187+
if (!wbmPair.getKey() || getPluginInstance().getManager().isAvoidedMaterial(blockState.getType(), blockState.getRawData())) return;
184188

185189
if (getPluginInstance().getCoreProtectHook() != null && getPluginInstance().getConfig().getBoolean("core-protect"))
186190
getPluginInstance().getCoreProtectHook().logLocation(blockState.getLocation());
@@ -199,11 +203,12 @@ public void onBreak(BlockBreakEvent e) {
199203
signRestore = getPluginInstance().getConfig().getBoolean("sign-restoration");
200204
handleSpecialStateRetore(e.getBlock(), blockState, containerRestore, signRestore);
201205

202-
getPluginInstance().getServer().getScheduler().runTaskLater(getPluginInstance(), new BlockRegenerationTask(getPluginInstance(), e.getBlock(), blockState, false),
203-
getPluginInstance().getConfig().getInt("break-regeneration-delay"));
206+
getPluginInstance().getServer().getScheduler().runTaskLater(getPluginInstance(),
207+
new BlockRegenerationTask(getPluginInstance(), e.getBlock(), blockState, false), wbmPair.getValue());
204208
}
205209
}
206210

211+
@SuppressWarnings("deprecation")
207212
@EventHandler(priority = EventPriority.LOWEST)
208213
public void onExplode(EntityExplodeEvent e) {
209214
if (e.isCancelled()) return;
@@ -217,6 +222,8 @@ public void onExplode(EntityExplodeEvent e) {
217222
return;
218223
}
219224

225+
e.blockList().removeIf(block -> getPluginInstance().getManager().isAvoidedMaterial(block.getType(), block.getData()));
226+
220227
final List<Block> blockList = new ArrayList<>(e.blockList());
221228
int delay = getPluginInstance().getConfig().getInt("explosive-regeneration-delay"),
222229
speed = getPluginInstance().getConfig().getInt("explosive-regeneration-speed");
@@ -234,12 +241,8 @@ public void onExplode(EntityExplodeEvent e) {
234241
if (block == null || getPluginInstance().doesNotPassHooksCheck(block.getLocation())) continue;
235242

236243
final BlockState blockState = block.getState();
237-
if (checkState(blockState, ActionType.EXPLOSIVE)) continue;
238-
239-
if (getPluginInstance().getManager().isAvoidedMaterial(block.getType())) {
240-
e.blockList().remove(i);
241-
continue;
242-
}
244+
if (checkState(blockState, ActionType.EXPLOSIVE)
245+
|| getPluginInstance().getManager().isAvoidedMaterial(block.getType(), block.getData())) continue;
243246

244247
getPluginInstance().getManager().playNaturalBlockBreakEffect(block); // play special effect
245248

@@ -274,7 +277,8 @@ public void onExplode(EntityExplodeEvent e) {
274277
handleSpecialStateRetore(block, blockState, containerRestore, signRestore);
275278

276279
getPluginInstance().getManager().getSavedBlockStates().add(blockState);
277-
getPluginInstance().getServer().getScheduler().runTaskLater(getPluginInstance(), new BlockRegenerationTask(getPluginInstance(), block, blockState, false), delay);
280+
getPluginInstance().getServer().getScheduler().runTaskLater(getPluginInstance(),
281+
new BlockRegenerationTask(getPluginInstance(), block, blockState, false), delay);
278282
delay += speed;
279283
}
280284
}

src/main/java/xzot1k/plugins/ptg/core/Manager.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import xzot1k.plugins.ptg.PhysicsToGo;
1818
import xzot1k.plugins.ptg.core.enums.TreeType;
1919
import xzot1k.plugins.ptg.core.objects.LocationClone;
20+
import xzot1k.plugins.ptg.core.objects.Pair;
2021
import xzot1k.plugins.ptg.core.objects.SaplingData;
2122

2223
import java.util.*;
@@ -136,16 +137,23 @@ public boolean isNotTreeBlock(Block block) {
136137
/**
137138
* Checks to see if the material is a configured material that should be avoided.
138139
*
139-
* @param material The material to check.
140+
* @param material The material to check.
141+
* @param durability The durability of the material (For older versions of MineCraft).
140142
* @return If it is a material to avoid.
141143
*/
142-
public boolean isAvoidedMaterial(Material material) {
144+
public boolean isAvoidedMaterial(Material material, int durability) {
143145
List<String> materialNames = getPluginInstance().getConfig().getStringList("avoided-materials");
144146
if (materialNames.isEmpty()) return false;
145147

146148
for (int i = -1; ++i < materialNames.size(); ) {
147-
String materialName = materialNames.get(i);
148-
if (materialName != null && material.name().contains(materialName.toUpperCase().replace(" ", "_").replace("-", "_")))
149+
final String materialName = materialNames.get(i);
150+
if (materialName == null || materialName.isEmpty()) continue;
151+
152+
if (materialName.contains(":")) {
153+
String[] args = materialName.split(":");
154+
if (material.name().contains(args[0].toUpperCase().replace(" ", "_").replace("-", "_"))
155+
&& args[1].equals(String.valueOf(durability))) return true;
156+
} else if (material.name().contains(materialName.toUpperCase().replace(" ", "_").replace("-", "_")))
149157
return true;
150158
}
151159
return false;
@@ -173,18 +181,25 @@ public boolean isWhitelistedPlaceMaterial(Material material) {
173181
* Checks to see if the material is whitelisted to be only effected (Block Breaking).
174182
*
175183
* @param material The material to check.
176-
* @return If it is a whitelisted material.
184+
* @return If it is a whitelisted material (Returns NULL if invalid).
177185
*/
178-
public boolean isWhitelistedBreakMaterial(Material material) {
186+
public Pair<Boolean, Integer> isWhitelistedBreakMaterial(Material material) {
179187
List<String> effectedMaterials = getPluginInstance().getConfig().getStringList("break-only-effected");
180-
if (effectedMaterials.isEmpty()) return true;
188+
if (effectedMaterials.isEmpty()) return null;
181189

182190
for (int i = -1; ++i < effectedMaterials.size(); ) {
183191
String materialName = effectedMaterials.get(i);
184-
if (material != null && material.name().contains(materialName.toUpperCase().replace(" ", "_").replace("-", "_")))
185-
return true;
192+
if (materialName == null || materialName.isEmpty()) continue;
193+
194+
if (materialName.contains(":")) {
195+
String[] args = materialName.split(":");
196+
if (material.name().contains(args[0].toUpperCase().replace(" ", "_").replace("-", "_")))
197+
return new Pair<>(true, Integer.parseInt(args[1]));
198+
} else if (material.name().contains(materialName.toUpperCase().replace(" ", "_").replace("-", "_")))
199+
return new Pair<>(true, getPluginInstance().getConfig().getInt("break-regeneration-delay"));
186200
}
187-
return false;
201+
202+
return null;
188203
}
189204

190205
/**

src/main/java/xzot1k/plugins/ptg/core/tasks/TreePhysicsTask.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,13 @@ private void workAdjacents(Block centerBlock, int counter) {
103103

104104
if (adjacentBlock.getType().name().contains("LOG")) {
105105
TreePhysicsTask treePhysicsTask = new TreePhysicsTask(getPluginInstance(), getPlayer(), adjacentBlock.getState(), canDrop(), canRegenerate());
106-
treePhysicsTask.setTaskId(getPluginInstance().getServer().getScheduler().runTaskTimer(getPluginInstance(), treePhysicsTask, 0, getPluginInstance().getConfig().getInt("tree-regeneration-speed")).getTaskId());
106+
treePhysicsTask.setTaskId(getPluginInstance().getServer().getScheduler().runTaskTimer(getPluginInstance(), treePhysicsTask, 0,
107+
getPluginInstance().getConfig().getInt("tree-regeneration-speed")).getTaskId());
107108
return;
108109
}
109110

110-
takeActionOnBlock(adjacentBlock, getTreeRegenDelay() + (adjacentBlock.getType().name().contains("LOG") ? 0 : getPluginInstance().getManager().getRandomInRange(20, 30)));
111+
takeActionOnBlock(adjacentBlock, getTreeRegenDelay() + (adjacentBlock.getType().name().contains("LOG") ? 0 : getPluginInstance().getManager().getRandomInRange(20,
112+
30)));
111113
workAdjacents(adjacentBlock, counter + 1); // nested adjacent checks.
112114
}
113115
}
@@ -124,7 +126,8 @@ private BlockFace[] shuffleBlockFaceList() {
124126
}
125127

126128
private void takeActionOnBlock(Block block, int delay) {
127-
getPluginInstance().getCoreProtectHook().logLocation(block.getLocation()); // log to core protect.
129+
if (getPluginInstance().getCoreProtectHook() != null && getPluginInstance().getConfig().getBoolean("core-protect"))
130+
getPluginInstance().getCoreProtectHook().logLocation(block.getLocation()); // log to core protect.
128131
final BlockState blockState = block.getState();
129132
if (canRegenerate()) getPluginInstance().getManager().getSavedBlockStates().add(blockState);
130133

src/main/resources/config.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ explosive-tnt-ignite: true
4848
# This tells the plugin what the fuse of harmed tnt blocks should be (IN TICKS, 20 ticks = 1 second). This option requires the "explosive-tnt-ignite" feature to be enabled.
4949
explosive-tnt-fuse: 10
5050
# This is a list that will prevent explosive block regeneration entirely if the explosion was caused by an entity in this list.
51+
# Entities: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html
5152
blocked-entity-regeneration: [ ]
5253
# This is a list that will block explosive damage and effects toward all entity types found in the list.
54+
# Entities: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html
5355
explosive-blocked-entities:
5456
- "ARMOR_STAND"
5557
- "PAINTING"
@@ -61,6 +63,7 @@ place-removal: false
6163
# This determines how long (IN TICKS, 20 ticks = 1 second) it will take for the block to be removed and reverted to the original material.
6264
place-removal-delay: 20
6365
# This list will act as a whitelist when the "place-removal" option is enabled and will ONLY remove the materials found in the list.
66+
# Materials: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html
6467
# (NOTE: This list will be avoided if it is empty.)
6568
place-only-effected:
6669
- "TORCH"
@@ -71,14 +74,16 @@ break-regeneration: false
7174
break-drops: true
7275
# This determines how long (IN TICKS, 20 ticks = 1 second) it will take for the block to be regenerated to its original state.
7376
break-regeneration-delay: 20
74-
# This list will act as a whitelist when the "break-regeneration" option is enabled. All materials in the list will regenerate after a delay to their original material.
75-
# (NOTE: This list will be avoided if it is empty.)
77+
# This list is a whitelist and requires the "break-regeneration" option enabled. All materials in the list will regenerate after a delay to their original material.
78+
# Materials: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html
79+
# (NOTE: This list will be avoided if it is empty. You may use the format: <material>:<delay> to set individual delays for specific materials)
7680
break-only-effected:
77-
- "ORE"
81+
- "ORE:120"
7882

7983
# This will convert the "blocked-material-regeneration" into a whitelist from a blacklist.
8084
invert-bmr: false
8185
# This is a list that will prevent block regeneration entirely if its material is in the list.
86+
# Materials: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html
8287
blocked-material-regeneration:
8388
- "FIRE"
8489
- "TNT"
@@ -89,6 +94,7 @@ invert-wb: false
8994
world-blacklist:
9095
- "blocked_world"
9196
# This list should contain all materials that should be avoided like the black plague. Essentially these materials are safe from the plugins actions at all costs.
97+
# Materials: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html
9298
avoided-materials:
9399
- "BEDROCK"
94100
- "OBSIDIAN"

0 commit comments

Comments
 (0)