Skip to content

Commit

Permalink
Add sprint glass break
Browse files Browse the repository at this point in the history
  • Loading branch information
max1mde committed Jan 29, 2024
1 parent 30c36b4 commit e086fe6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = 'com.maximde'
version = '2.8.4'
version = '2.8.5'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.maximde.fancyphysics.listeners.player;

import com.maximde.fancyphysics.FancyPhysics;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.block.Block;
Expand All @@ -24,28 +23,26 @@ public void onPlayerMove(PlayerMoveEvent event) {
}

private void doorBreakManager(PlayerMoveEvent event) {
if(!this.fancyPhysics.getPluginConfig().isSprintDoorBreak()) return;
if(!this.fancyPhysics.getPluginConfig().isSprintDoorBreak() && !this.fancyPhysics.getPluginConfig().isSprintGlassBreak()) return;
Player player = event.getPlayer();
if(!player.isSprinting()) return;
Block block = player.getTargetBlock(null, 1);

if (isDoor(block.getType()) || isDoor(block.getRelative(BlockFace.UP).getType())) {
Block doorBlock = isDoor(block.getType()) ? block : block.getRelative(BlockFace.UP);
if (isBreakable(block.getType()) || isBreakable(block.getRelative(BlockFace.UP).getType())) {
Block doorBlock = isBreakable(block.getType()) ? block : block.getRelative(BlockFace.UP);
Block aboveBlock = doorBlock.getRelative(BlockFace.UP);
doorBlock.getLocation().getWorld().spawnParticle(Particle.EXPLOSION_LARGE, doorBlock.getLocation(), 4);
this.fancyPhysics.getParticleGenerator().simulateSplashBloodParticles(doorBlock.getLocation(), doorBlock.getType());
doorBlock.breakNaturally();
}
}

private boolean isDoor(Material material) {
switch (material) {
case DARK_OAK_DOOR, BIRCH_DOOR, BAMBOO_DOOR, ACACIA_DOOR, CHERRY_DOOR, CRIMSON_DOOR, IRON_DOOR, JUNGLE_DOOR, MANGROVE_DOOR, OAK_DOOR, SPRUCE_DOOR, WARPED_DOOR -> {
return true;
}
default -> {
return false;
}
}
private boolean isBreakable(Material material) {
boolean isDoor = material.name().contains("DOOR");
boolean isGlass = material.name().contains("GLASS");

if(isGlass && this.fancyPhysics.getPluginConfig().isSprintGlassBreak()) return true;

return isDoor && this.fancyPhysics.getPluginConfig().isSprintDoorBreak();
}
}
3 changes: 3 additions & 0 deletions src/main/java/com/maximde/fancyphysics/utils/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Config {
private boolean realisticTrees;
private boolean dropSaplings;
private boolean sprintDoorBreak;
private boolean sprintGlassBreak;
private boolean visualCrafting;
private boolean naturalDropsOnExplode;
private boolean fallingBlockPhysics;
Expand Down Expand Up @@ -51,6 +52,7 @@ public Config() {
String[] settingsPhysicsDisabled = {
"TrapdoorPhysics",
"SprintDoorBreak",
"SprintGlassBreak",
"FlyUpParticles",
"TreeRegeneration",
"ExplosionRegeneration",
Expand Down Expand Up @@ -103,6 +105,7 @@ private void initValues() {
dropSaplings = cfg.getBoolean("Physics.DropSaplings");
performanceMode = cfg.getBoolean("Physics.PerformanceMode");
sprintDoorBreak = cfg.getBoolean("Physics.SprintDoorBreak");
sprintGlassBreak = cfg.getBoolean("Physics.SprintGlassBreak");
visualCrafting = cfg.getBoolean("Physics.VisualCrafting");
naturalDropsOnExplode = cfg.getBoolean("Physics.NaturalDropsOnExplode");
flyUpParticles = cfg.getBoolean("Physics.FlyUpParticles");
Expand Down

0 comments on commit e086fe6

Please sign in to comment.