Skip to content

Commit

Permalink
Merge pull request #380 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Release 1.16.0
  • Loading branch information
tastybento authored Mar 30, 2024
2 parents 27a9bcb + e18e7b9 commit 14b10b4
Show file tree
Hide file tree
Showing 13 changed files with 970 additions and 107 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.0</build.version>
<build.version>1.16.0</build.version>
<!-- SonarCloud -->
<sonar.projectKey>BentoBoxWorld_AOneBlock</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization>
Expand Down
69 changes: 34 additions & 35 deletions src/main/java/world/bentobox/aoneblock/AOneBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Objects;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldCreator;
Expand All @@ -24,6 +25,7 @@
import world.bentobox.aoneblock.listeners.ItemsAdderListener;
import world.bentobox.aoneblock.listeners.JoinLeaveListener;
import world.bentobox.aoneblock.listeners.NoBlockHandler;
import world.bentobox.aoneblock.listeners.StartSafetyListener;
import world.bentobox.aoneblock.oneblocks.OneBlockCustomBlockCreator;
import world.bentobox.aoneblock.oneblocks.OneBlocksManager;
import world.bentobox.aoneblock.oneblocks.customblock.ItemsAdderCustomBlock;
Expand All @@ -32,6 +34,9 @@
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.configuration.Config;
import world.bentobox.bentobox.api.configuration.WorldSettings;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.api.flags.Flag.Mode;
import world.bentobox.bentobox.api.flags.Flag.Type;
import world.bentobox.bentobox.database.objects.Island;

/**
Expand All @@ -51,8 +56,16 @@ public class AOneBlock extends GameModeAddon {
private final Config<Settings> configObject = new Config<>(this, Settings.class);
private BlockListener blockListener;
private OneBlocksManager oneBlockManager;
private PlaceholdersManager phManager;
private AOneBlockPlaceholders phManager;
private HoloListener holoListener;

// Flag
public final Flag START_SAFETY = new Flag.Builder("START_SAFETY", Material.BAMBOO_BLOCK)
.mode(Mode.BASIC)
.type(Type.WORLD_SETTING)
.listener(new StartSafetyListener(this))
.defaultSetting(false)
.build();

@Override
public void onLoad() {
Expand All @@ -73,10 +86,13 @@ public void onLoad() {
// Register commands
playerCommand = new PlayerCommand(this);
adminCommand = new AdminCommand(this);
// Register flag with BentoBox
// Register protection flag with BentoBox
getPlugin().getFlagsManager().registerFlag(this, START_SAFETY);
}
}

private boolean loadSettings() {
private boolean loadSettings() {
// Load settings again to get worlds
settings = configObject.loadConfigObject();
if (settings == null) {
Expand Down Expand Up @@ -105,7 +121,7 @@ public void onEnable() {
registerListener(new JoinLeaveListener(this));
registerListener(new InfoListener(this));
// Register placeholders
registerPlaceholders();
phManager = new AOneBlockPlaceholders(this, getPlugin().getPlaceholdersManager());

// Register request handlers
registerRequestHandler(new IslandStatsHandler(this));
Expand All @@ -130,37 +146,6 @@ public boolean loadData() {
return false;
}

private void registerPlaceholders() {
phManager = new PlaceholdersManager(this);
getPlugin().getPlaceholdersManager().registerPlaceholder(this, "visited_island_phase",
phManager::getPhaseByLocation);
getPlugin().getPlaceholdersManager().registerPlaceholder(this, "visited_island_count",
phManager::getCountByLocation);
getPlugin().getPlaceholdersManager().registerPlaceholder(this, "my_island_phase", phManager::getPhase);
getPlugin().getPlaceholdersManager().registerPlaceholder(this, "my_island_count", phManager::getCount);
getPlugin().getPlaceholdersManager().registerPlaceholder(this, "visited_island_next_phase",
phManager::getNextPhaseByLocation);
getPlugin().getPlaceholdersManager().registerPlaceholder(this, "my_island_next_phase", phManager::getNextPhase);
getPlugin().getPlaceholdersManager().registerPlaceholder(this, "my_island_blocks_for_phase",
phManager::getPhaseBlocks);
getPlugin().getPlaceholdersManager().registerPlaceholder(this, "my_island_blocks_to_next_phase",
phManager::getNextPhaseBlocks);
getPlugin().getPlaceholdersManager().registerPlaceholder(this, "visited_island_blocks_to_next_phase",
phManager::getNextPhaseBlocksByLocation);
getPlugin().getPlaceholdersManager().registerPlaceholder(this, "my_island_percent_done",
phManager::getPercentDone);
getPlugin().getPlaceholdersManager().registerPlaceholder(this, "visited_island_percent_done",
phManager::getPercentDoneByLocation);
getPlugin().getPlaceholdersManager().registerPlaceholder(this, "my_island_done_scale", phManager::getDoneScale);
getPlugin().getPlaceholdersManager().registerPlaceholder(this, "visited_island_done_scale",
phManager::getDoneScaleByLocation);
// Since 1.10
getPlugin().getPlaceholdersManager().registerPlaceholder(this, "visited_island_lifetime_count",
phManager::getLifetimeByLocation);
getPlugin().getPlaceholdersManager().registerPlaceholder(this, "my_island_lifetime_count",
phManager::getLifetime);
}

@Override
public void onDisable() {
// save cache
Expand Down Expand Up @@ -319,7 +304,7 @@ public BlockListener getBlockListener() {
*
* @return the phManager
*/
public PlaceholdersManager getPlaceholdersManager() {
public AOneBlockPlaceholders getPlaceholdersManager() {
return phManager;
}

Expand All @@ -336,4 +321,18 @@ public HoloListener getHoloListener() {
public boolean hasItemsAdder() {
return hasItemsAdder;
}

/**
* Set the addon's world. Used only for testing.
* @param world world
*/
public void setIslandWorld(World world) {
this.islandWorld = world;

}

public void setSettings(Settings settings) {
this.settings = settings;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;

public class PlaceholdersManager {
public class AOneBlockPlaceholders {

private static final TreeMap<Double, String> SCALE;
private static final String INFINITE = "aoneblock.placeholders.infinite";
Expand All @@ -26,8 +26,26 @@ public class PlaceholdersManager {

private final AOneBlock addon;

public PlaceholdersManager(AOneBlock addon) {
public AOneBlockPlaceholders(AOneBlock addon,
world.bentobox.bentobox.managers.PlaceholdersManager placeholdersManager) {
this.addon = addon;
placeholdersManager.registerPlaceholder(addon, "visited_island_phase", this::getPhaseByLocation);
placeholdersManager.registerPlaceholder(addon, "visited_island_count", this::getCountByLocation);
placeholdersManager.registerPlaceholder(addon, "my_island_phase", this::getPhase);
placeholdersManager.registerPlaceholder(addon, "my_island_count", this::getCount);
placeholdersManager.registerPlaceholder(addon, "visited_island_next_phase", this::getNextPhaseByLocation);
placeholdersManager.registerPlaceholder(addon, "my_island_next_phase", this::getNextPhase);
placeholdersManager.registerPlaceholder(addon, "my_island_blocks_for_phase", this::getPhaseBlocks);
placeholdersManager.registerPlaceholder(addon, "my_island_blocks_to_next_phase", this::getNextPhaseBlocks);
placeholdersManager.registerPlaceholder(addon, "visited_island_blocks_to_next_phase",
this::getNextPhaseBlocksByLocation);
placeholdersManager.registerPlaceholder(addon, "my_island_percent_done", this::getPercentDone);
placeholdersManager.registerPlaceholder(addon, "visited_island_percent_done", this::getPercentDoneByLocation);
placeholdersManager.registerPlaceholder(addon, "my_island_done_scale", this::getDoneScale);
placeholdersManager.registerPlaceholder(addon, "visited_island_done_scale", this::getDoneScaleByLocation);
// Since 1.10
placeholdersManager.registerPlaceholder(addon, "visited_island_lifetime_count", this::getLifetimeByLocation);
placeholdersManager.registerPlaceholder(addon, "my_island_lifetime_count", this::getLifetime);
}

/**
Expand Down
115 changes: 115 additions & 0 deletions src/main/java/world/bentobox/aoneblock/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Map;
import java.util.Set;

import org.bukkit.Color;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.block.Biome;
Expand Down Expand Up @@ -111,6 +112,28 @@ public class Settings implements WorldSettings {
@ConfigEntry(path = "world.hologram-duration")
private int hologramDuration = 10;

@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("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.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.65D;
@ConfigComment("Color of particles")
@ConfigEntry(path = "world.block-id.particle-color")
private Color particleColor = Color.GREEN;


@ConfigComment("Clear blocks when spawning mobs.")
@ConfigComment("Mobs break blocks when they spawn is to prevent players from building a box around the magic block,")
@ConfigComment("having the mob spawn, and then die by suffocation, i.e., it's a cheat prevention.")
Expand Down Expand Up @@ -2061,4 +2084,96 @@ public boolean isClearBlocks() {
public void setClearBlocks(boolean clearBlocks) {
this.clearBlocks = clearBlocks;
}

/**
* @return the startingSafetyDuration
*/
public int getStartingSafetyDuration() {
return startingSafetyDuration;
}

/**
* @param startingSafetyDuration the startingSafetyDuration to set
*/
public void setStartingSafetyDuration(int startingSafetyDuration) {
this.startingSafetyDuration = startingSafetyDuration;
}

/**
* @return the particleSize
*/
public Double getParticleSize() {
if (particleSize == null) {
particleSize = 0.8;
}
if (particleSize < 0.0) {
particleSize = 0.0;
}
return particleSize;
}


/**
* @param particleSize the particleSize to set
*/
public void setParticleSize(Double particleSize) {
this.particleSize = particleSize;
}

/**
* @return the particleColor
*/
public Color getParticleColor() {
if (particleColor == null) {
particleColor = Color.GREEN;
}
return particleColor;
}

/**
* @param particleColor the particleColor to set
*/
public void setParticleColor(Color particleColor) {
this.particleColor = particleColor;
}

/**
* @return the particleDensity
*/
public Double getParticleDensity() {
if (particleDensity == null) {
particleDensity = 0.5;
}
if (particleDensity < 0.1D) {
particleDensity = 0.1D;
}
if (particleDensity > 1D) {
particleDensity = 1D;
}
return particleDensity;
}

/**
* @param particleDensity the particleDensity to set
*/
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.util.Vector;

import world.bentobox.aoneblock.listeners.BlockProtect;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
Expand All @@ -20,6 +20,7 @@
*/
public class IslandRespawnBlockCommand extends CompositeCommand
{

/**
* Instantiates a new Island respawn block command.
*
Expand Down Expand Up @@ -83,32 +84,14 @@ else if (Material.BEDROCK.equals(island.getCenter().getBlock().getType()) ||
}
else
{
// Spawn 6 particles where block is located.
island.getWorld().spawnParticle(Particle.REDSTONE,
island.getCenter().add(new Vector(0.5, 1.0, 0.5)),
5, 0.1, 0, 0.1, 1,
new Particle.DustOptions(Color.fromBGR(0, 100, 0), 1));
island.getWorld().spawnParticle(Particle.REDSTONE,
island.getCenter().add(new Vector(1.0, 0.5, 0.5)),
5, 0.1, 0, 0.1, 1,
new Particle.DustOptions(Color.fromBGR(0, 100, 0), 1));
island.getWorld().spawnParticle(Particle.REDSTONE,
island.getCenter().add(new Vector(0.5, 0.5, 1.0)),
5, 0.1, 0, 0.1, 1,
new Particle.DustOptions(Color.fromBGR(0, 100, 0), 1));
island.getWorld().spawnParticle(Particle.REDSTONE,
island.getCenter().add(new Vector(0.5, 0.0, 0.5)),
5, 0.1, 0, 0.1, 1,
new Particle.DustOptions(Color.fromBGR(0, 100, 0), 1));
island.getWorld().spawnParticle(Particle.REDSTONE,
island.getCenter().add(new Vector(0.0, 0.5, 0.5)),
5, 0.1, 0, 0.1, 1,
new Particle.DustOptions(Color.fromBGR(0, 100, 0), 1));
island.getWorld().spawnParticle(Particle.REDSTONE,
island.getCenter().add(new Vector(0.5, 0.5, 0.0)),
5, 0.1, 0, 0.1, 1,
new Particle.DustOptions(Color.fromBGR(0, 100, 0), 1));

for (double x = 0.0; x <= 1.0; x += 0.5) {
for (double y = 0.0; y <= 1.0; y += 0.5) {
for (double z = 0.0; z < 1.0; z += 0.5) {
island.getWorld().spawnParticle(Particle.REDSTONE, island.getCenter().add(new Vector(x, y, z)),
5, 0.1, 0, 0.1, 1, new Particle.DustOptions(BlockProtect.GREEN, 1));
}
}
}
user.sendMessage("aoneblock.commands.respawn-block.block-exist");
}

Expand Down
Loading

0 comments on commit 14b10b4

Please sign in to comment.