Skip to content

Commit

Permalink
correct and improve
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Nov 12, 2023
1 parent 7be5105 commit f22027a
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class PumpkinPVPConfig {
protected PumpkinPVPConfig() throws Exception {
this.config = loadConfig(new File(PumpkinPVPReloaded.getInstance().getDataFolder(), "config.yml"));
getList("pumpkin-explosion.pumpkin-types", List.of(
Material.PUMPKIN.name(), Material.CARVED_PUMPKIN.name()
Material.PUMPKIN.name(), Material.CARVED_PUMPKIN.name(), Material.JACK_O_LANTERN.name()
)).forEach(configuredMaterial -> {
try {
Material material = Material.valueOf(configuredMaterial);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ protected DeathSoundEffects() {
Sound.ENTITY_RAVAGER_DEATH.name(),
Sound.ENTITY_SKELETON_HORSE_DEATH.name(),
Sound.ENTITY_WARDEN_DEATH.name(),
Sound.ENTITY_WITCH_CELEBRATE.name(),
Sound.ENTITY_WITHER_DEATH.name()
Sound.ENTITY_WITCH_CELEBRATE.name()
), """
Use multiple entries to randomly cycle through a list of sounds or just one.
Requires correct enums from https://jd.papermc.io/paper/1.20/org/bukkit/Sound.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerInteractEvent;

import java.util.HashSet;
Expand Down Expand Up @@ -84,42 +83,4 @@ private void onBlockLeftClick(PlayerInteractEvent event) {
).callEvent();
});
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onBlockBreak(BlockBreakEvent event) {
final Block broken = event.getBlock();
if (!pumpkins.contains(broken.getType())) return;

PrePumpkinExplodeEvent prePumpkinExplodeEvent = new PrePumpkinExplodeEvent(
broken,
event.getPlayer(),
broken.getLocation().toCenterLocation(),
TriggerAction.LEFT_CLICK
);

if (!prePumpkinExplodeEvent.callEvent()) {
if (prePumpkinExplodeEvent.cancelPreceding()) event.setCancelled(true);
return;
}

final Location explodeLoc = prePumpkinExplodeEvent.getExplodeLocation();

regionScheduler.run(plugin, explodeLoc, kaboom -> {
prePumpkinExplodeEvent.getPumpkin().setType(Material.AIR);

final float power = prePumpkinExplodeEvent.getExplodePower();
final boolean fire = prePumpkinExplodeEvent.shouldSetFire();
final boolean breakBlocks = prePumpkinExplodeEvent.shouldBreakBlocks();

new PostPumpkinExplodeEvent(
prePumpkinExplodeEvent.getExploder(),
explodeLoc,
power,
fire,
breakBlocks,
explodeLoc.getWorld().createExplosion(explodeLoc, power, fire, breakBlocks),
prePumpkinExplodeEvent.getTriggerAction()
).callEvent();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ protected FireworkEffects() {
FireworkEffect.Type effectType = FireworkEffect.Type.valueOf(effect);
parsedColors.forEach(primary_color -> {
Color secondary_color = primary_color;
int tries = 0; // Avoid infinite loop on bad config
int tries = 0;
while (secondary_color.equals(primary_color)) { // Avoid rolling the same color
if (tries > 100) break;
if (tries > 100) break; // Avoid infinite loop on bad config
secondary_color = parsedColors.get(new Random().nextInt(0, parsedColors.size()));
tries++;
}
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ version: '${project.version}'
main: me.xginko.pumpkinpvpreloaded.PumpkinPVPReloaded
api-version: '1.19'
prefix: PumpkinPVP
load: STARTUP
authors: [xGinko]
description: ${project.description}
website: ${project.url}
Expand Down

0 comments on commit f22027a

Please sign in to comment.