Skip to content

Commit

Permalink
Merge pull request #379 from BentoBoxWorld/particle_adjustment
Browse files Browse the repository at this point in the history
Particle adjustment
  • Loading branch information
tastybento authored Mar 29, 2024
2 parents 281d777 + 377474f commit e18e7b9
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 30 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>1.15.1</build.version>
<build.version>1.16.0</build.version>
<!-- SonarCloud -->
<sonar.projectKey>BentoBoxWorld_AOneBlock</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization>
Expand Down
32 changes: 27 additions & 5 deletions src/main/java/world/bentobox/aoneblock/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,23 @@ public class Settings implements WorldSettings {
@ConfigEntry(path = "world.hologram-duration")
private int hologramDuration = 10;

@ConfigComment("Duration in seonds that players cannot move when they start a new one block.")
@ConfigComment("Duration in seconds that players cannot move when they start a new one block.")
@ConfigComment("Used only if the Starting Safety world setting is active.")
@ConfigEntry(path = "world.starting-safety-duration")
private int startingSafetyDuration = 10;

@ConfigComment("Block identification appearance.")
@ConfigComment("Size of particles. Default is 0.7. Must be greater than 0.")
@ConfigComment("Click type that will make particles appear. Options are:")
@ConfigComment("LEFT (default), RIGHT, or NONE")
@ConfigEntry(path = "world.block-id.click-type")
private String clickType = "LEFT";

@ConfigComment("Size of particles. Default is 0.5. Must be greater than 0.")
@ConfigEntry(path = "world.block-id.particle-size")
private Double particleSize = 0.7;
@ConfigComment("Density of particles - Value from 0.1 to 1. Default is 0.5. Smaller values are more dense, higher are less.")
private Double particleSize = 0.5;
@ConfigComment("Density of particles - Value from 0.1 to 1. Default is 0.65. Smaller values are more dense, higher are less.")
@ConfigEntry(path = "world.block-id.particle-density")
private Double particleDensity = 0.5D;
private Double particleDensity = 0.65D;
@ConfigComment("Color of particles")
@ConfigEntry(path = "world.block-id.particle-color")
private Color particleColor = Color.GREEN;
Expand Down Expand Up @@ -2154,4 +2159,21 @@ public Double getParticleDensity() {
public void setParticleDensity(Double particleDensity) {
this.particleDensity = particleDensity;
}

/**
* @return the clickType
*/
public String getClickType() {
if (clickType == null || (!clickType.equalsIgnoreCase("LEFT") && !clickType.equalsIgnoreCase("RIGHT")
&& !clickType.equalsIgnoreCase("NONE"))) {
clickType = "LEFT";
}
return clickType;
}
/**
* @param clickType the clickType to set
*/
public void setClickType(String clickType) {
this.clickType = clickType;
}
}
22 changes: 16 additions & 6 deletions src/main/java/world/bentobox/aoneblock/listeners/BlockProtect.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.util.Vector;

import world.bentobox.aoneblock.AOneBlock;
Expand All @@ -45,13 +46,22 @@ public BlockProtect(AOneBlock addon) {
* @param e - event
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockDamage(BlockDamageEvent e) {
if (!addon.inWorld(e.getBlock().getWorld())) {
public void onBlockDamage(PlayerInteractEvent e) {
Action action = e.getAction();
String clickType = addon.getSettings().getClickType();

if (clickType.equalsIgnoreCase("NONE") || !addon.inWorld(e.getPlayer().getWorld())
|| e.getClickedBlock() == null) {
return;
}
Block block = e.getBlock();
Location l = block.getLocation();
addon.getIslands().getIslandAt(l).map(Island::getCenter).filter(l::equals).ifPresent(this::showSparkles);

if ((action == Action.LEFT_CLICK_BLOCK && clickType.equalsIgnoreCase("LEFT"))
|| (action == Action.RIGHT_CLICK_BLOCK && clickType.equalsIgnoreCase("RIGHT"))) {

Location l = e.getClickedBlock().getLocation();
addon.getIslands().getIslandAt(l).map(Island::getCenter).filter(center -> center.equals(l))
.ifPresent(this::showSparkles);
}
}

public void showSparkles(Location location) {
Expand Down
57 changes: 45 additions & 12 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ aoneblock:
set-count-command: setCount
# How long a player must wait until they can use the setCount command again. In minutes.
# This is the command that is run from the phases panel.
# Added since 1.13.0
# Added since 1.13.0.
set-count-cooldown: 5
# The command label that allows to check if magic block is present and respawns it if not.
# By default it is 'respawnBlock check'.
Expand All @@ -58,11 +58,29 @@ world:
# Duration in seconds that phase holograms will exist after being displayed, if used.
# If set to 0, then holograms will persist until cleared some other way.
hologram-duration: 10
# Duration in seconds that players cannot move when they start a new one block.
# Used only if the Starting Safety world setting is active.
starting-safety-duration: 10
block-id:
# Block identification appearance.
# Click type that will make particles appear. Options are:
# LEFT (default), RIGHT, or NONE
click-type: RIGHT
# Size of particles. Default is 0.7. Must be greater than 0.
particle-size: 0.5
# Density of particles - Value from 0.1 to 1. Default is 0.5. Smaller values are more dense, higher are less.
particle-density: 0.65
# Color of particles
particle-color:
==: Color
ALPHA: 255
RED: 0
BLUE: 0
GREEN: 128
# Clear blocks when spawning mobs.
# Mobs break blocks when they spawn is to prevent players from building a box around the magic block,
# having the mob spawn, and then die by suffocation, i.e., it's a cheat prevention.
clear-blocks: true

mobs-clear-blocks: true
spawn-limits:
# Spawn limits. These override the limits set in bukkit.yml
# If set to a negative number, the server defaults will be used
Expand Down Expand Up @@ -174,34 +192,37 @@ world:
# Mob white list - these mobs will NOT be removed when logging in or doing /island
remove-mobs-whitelist:
- ENDERMAN
- WITHER
- ZOMBIE_VILLAGER
- WITHER
# World flags. These are boolean settings for various flags for this world
flags:
CREEPER_DAMAGE: true
OBSIDIAN_SCOOPING: true
PISTON_PUSH: false
ISLAND_RESPAWN: true
CREEPER_GRIEFING: false
VISITOR_KEEP_INVENTORY: false
PETS_STAY_AT_HOME: true
NATURAL_SPAWNING_OUTSIDE_RANGE: true
LIQUIDS_FLOWING_OUT: false
REMOVE_MOBS: true
ENDER_CHEST: false
TREES_GROWING_OUTSIDE_RANGE: false
WITHER_DAMAGE: false
PISTON_PUSH: false
COARSE_DIRT_TILLING: true
ENDERMAN_GRIEFING: true
CLEAN_SUPER_FLAT: false
CHEST_DAMAGE: false
PREVENT_TELEPORT_WHEN_FALLING: false
NATURAL_SPAWNING_OUTSIDE_RANGE: true
START_SAFETY: false
ENTER_EXIT_MESSAGES: true
ALLOW_MOVE_BOX: true
ENDERMAN_DEATH_DROP: true
LIQUIDS_FLOWING_OUT: false
OFFLINE_REDSTONE: true
REMOVE_END_EXIT_ISLAND: true
OFFLINE_GROWTH: true
REMOVE_MOBS: true
ENDER_CHEST: false
ITEM_FRAME_DAMAGE: false
TREES_GROWING_OUTSIDE_RANGE: false
SPAWNER_SPAWN_EGGS: true
WITHER_DAMAGE: false
# These are the default protection settings for new islands.
# The value is the minimum island rank required allowed to do the action
# Ranks are the following:
Expand All @@ -213,6 +234,7 @@ world:
# OWNER = 1000
default-island-flags:
HURT_ANIMALS: 500
LOOM: 500
DRAGON_EGG: 500
REDSTONE: 500
BUCKET: 500
Expand All @@ -228,6 +250,8 @@ world:
END_PORTAL: 500
BREEDING: 500
HURT_VILLAGERS: 500
BOOKSHELF: 500
HARVEST: 500
FROST_WALKER: 500
TURTLE_EGGS: 500
COLLECT_LAVA: 500
Expand All @@ -240,6 +264,7 @@ world:
NAME_TAG: 500
ARMOR_STAND: 500
CHANGE_SETTINGS: 1000
SIGN_EDITING: 500
TRADING: 0
EGGS: 500
ITEM_DROP: 0
Expand All @@ -250,15 +275,19 @@ world:
SCULK_SENSOR: 500
LECTERN: 500
SHULKER_BOX: 500
GRINDSTONE: 500
ITEM_PICKUP: 0
CROP_TRAMPLE: 500
DROPPER: 500
BREWING: 500
MOVE_BOX: 1000
TNT_PRIMING: 500
PARKOUR_CREATIVE: 500
COLLECT_WATER: 500
AXOLOTL_SCOOPING: 500
BUTTON: 500
COMPOSTER: 500
STONECUTTING: 500
FIRE_EXTINGUISH: 500
COMMAND_RANKS: 500
BEACON: 500
Expand All @@ -270,6 +299,7 @@ world:
HIVE: 500
ITEM_FRAME: 500
PLACE_BLOCKS: 500
CROP_PLANTING: 500
CRAFTING: 0
SHEARING: 500
ENCHANTING: 0
Expand All @@ -281,6 +311,7 @@ world:
DISPENSER: 500
SCULK_SHRIEKER: 500
GATE: 0
SMITHING: 500
EXPERIENCE_PICKUP: 500
HOPPER: 500
LEASH: 500
Expand All @@ -292,13 +323,16 @@ world:
POTION_THROWING: 500
BARREL: 500
COLLECT_POWDERED_SNOW: 500
CARTOGRAPHY: 500
# These are the default settings for new islands
default-island-settings:
PVP_END: false
PVP_NETHER: false
LEAF_DECAY: true
ENDERMAN_TELEPORT: true
ANIMAL_NATURAL_SPAWN: true
MONSTER_NATURAL_SPAWN: true
SHULKER_TELEPORT: true
FIRE_SPREAD: true
FIRE_BURNING: true
PVP_OVERWORLD: false
Expand Down Expand Up @@ -548,4 +582,3 @@ protection:
do-not-edit-these-settings:
# These settings should not be edited
reset-epoch: 0

Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -74,6 +75,8 @@ public class BlockProtectTest {
*/
@Before
public void setUp() throws Exception {

when(p.getWorld()).thenReturn(world);
// In World
when(addon.inWorld(world)).thenReturn(true);

Expand Down Expand Up @@ -118,11 +121,12 @@ public void testBlockProtect() {
@Test
public void testOnBlockDamage() {
ItemStack item = new ItemStack(Material.DIAMOND_PICKAXE);
BlockDamageEvent blockDamageEvent = new BlockDamageEvent(p, block, item, false);
PlayerInteractEvent blockDamageEvent = new PlayerInteractEvent(p, Action.LEFT_CLICK_BLOCK, item, block,
BlockFace.UP);
bp.onBlockDamage(blockDamageEvent);
verify(addon).inWorld(world);
verify(im).getIslandAt(location);
verify(world, times(80)).spawnParticle(eq(Particle.REDSTONE), eq(null), eq(5),
verify(world, times(48)).spawnParticle(eq(Particle.REDSTONE), eq(null), eq(5),
eq(0.1D), eq(0D), eq(0.1D), eq(1D), any(Particle.DustOptions.class));
}

Expand All @@ -131,9 +135,10 @@ public void testOnBlockDamage() {
*/
@Test
public void testOnBlockDamageWrongWorld() {
when(block.getWorld()).thenReturn(mock(World.class));
when(p.getWorld()).thenReturn(mock(World.class));
ItemStack item = new ItemStack(Material.DIAMOND_PICKAXE);
BlockDamageEvent blockDamageEvent = new BlockDamageEvent(p, block, item, false);
PlayerInteractEvent blockDamageEvent = new PlayerInteractEvent(p, Action.LEFT_CLICK_BLOCK, item, block,
BlockFace.UP);
bp.onBlockDamage(blockDamageEvent);
verify(im, never()).getIslandAt(location);
verify(world, never()).spawnParticle(any(Particle.class), any(Location.class),anyInt(),
Expand All @@ -147,7 +152,8 @@ public void testOnBlockDamageWrongWorld() {
public void testOnBlockDamageNotCenterMagicBlock() {
when(block.getLocation()).thenReturn(mock(Location.class));
ItemStack item = new ItemStack(Material.DIAMOND_PICKAXE);
BlockDamageEvent blockDamageEvent = new BlockDamageEvent(p, block, item, false);
PlayerInteractEvent blockDamageEvent = new PlayerInteractEvent(p, Action.LEFT_CLICK_BLOCK, item, block,
BlockFace.UP);
bp.onBlockDamage(blockDamageEvent);
verify(addon).inWorld(world);
verify(im).getIslandAt(any(Location.class));
Expand Down

0 comments on commit e18e7b9

Please sign in to comment.