Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Baterka committed Nov 29, 2023
2 parents 1c46903 + 072fd0b commit f92df5f
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 85 deletions.
4 changes: 4 additions & 0 deletions src/main/java/world/bentobox/aoneblock/AOneBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import world.bentobox.aoneblock.listeners.ItemsAdderListener;
import world.bentobox.aoneblock.listeners.JoinLeaveListener;
import world.bentobox.aoneblock.listeners.NoBlockHandler;
import world.bentobox.aoneblock.oneblocks.OneBlockCustomBlockCreator;
import world.bentobox.aoneblock.oneblocks.OneBlocksManager;
import world.bentobox.aoneblock.oneblocks.customblock.ItemsAdderCustomBlock;
import world.bentobox.aoneblock.requests.IslandStatsHandler;
import world.bentobox.aoneblock.requests.LocationStatsHandler;
import world.bentobox.bentobox.api.addons.GameModeAddon;
Expand Down Expand Up @@ -57,6 +59,8 @@ public void onLoad() {
// Check if ItemsAdder exists, if yes register listener
if (Bukkit.getPluginManager().getPlugin("ItemsAdder") != null) {
registerListener(new ItemsAdderListener(this));
OneBlockCustomBlockCreator.register(ItemsAdderCustomBlock::fromId);
OneBlockCustomBlockCreator.register("itemsadder", ItemsAdderCustomBlock::fromMap);
hasItemsAdder = true;
}
// Save the default config from config.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

import dev.lone.itemsadder.api.CustomBlock;
import world.bentobox.aoneblock.AOneBlock;
import world.bentobox.aoneblock.dataobjects.OneBlockIslands;
import world.bentobox.aoneblock.events.MagicBlockEntityEvent;
Expand Down Expand Up @@ -443,13 +442,6 @@ private void breakBlock(@Nullable Player player, Block block, @NonNull OneBlockO
private void spawnBlock(@NonNull OneBlockObject nextBlock, @NonNull Block block) {
if (nextBlock.isCustomBlock()) {
nextBlock.getCustomBlock().execute(addon, block);
} else if (nextBlock.isItemsAdderBlock()) {
// Get Custom Block from ItemsAdder and place it
CustomBlock cBlock = CustomBlock.getInstance(nextBlock.getItemsAdderBlock());
if (cBlock != null) {
block.getLocation().getBlock().setType(Material.AIR);
cBlock.place(block.getLocation());
}
} else {
@NonNull
Material type = nextBlock.getMaterial();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public enum Rarity {
private Map<Integer, ItemStack> chest;
private Rarity rarity;
private OneBlockCustomBlock customBlock;
private String itemsAdderBlock;
private int prob;

/**
Expand Down Expand Up @@ -78,18 +77,6 @@ public OneBlockObject(OneBlockCustomBlock customBlock, int prob) {
this.prob = prob;
}

/**
* An ItemsAdder block
*
* @param namedSpaceID - ItemsAdder block
* @param prob - relative probability
*/

public OneBlockObject(String namedSpaceID, int prob) {
this.itemsAdderBlock = namedSpaceID;
this.prob = prob;
}

/**
* A chest
*
Expand All @@ -113,7 +100,6 @@ public OneBlockObject(OneBlockObject ob) {
this.rarity = ob.getRarity();
this.prob = ob.getProb();
this.customBlock = ob.getCustomBlock();
this.itemsAdderBlock = ob.getItemsAdderBlock();
}

/**
Expand Down Expand Up @@ -147,11 +133,6 @@ public OneBlockCustomBlock getCustomBlock() {
return customBlock;
}

/**
* @return the itemsAdderBlock
*/
public String getItemsAdderBlock() { return itemsAdderBlock; }


/**
* @return the isMaterial
Expand All @@ -176,13 +157,6 @@ public boolean isCustomBlock() {
return customBlock != null;
}

/**
* @return the isItemsAdderBlock
*/
public boolean isItemsAdderBlock() {
return itemsAdderBlock != null;
}

/**
* @return the rarity
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,6 @@ public void addCustomBlock(OneBlockCustomBlock customBlock, int prob) {
probMap.put(total, new OneBlockObject(customBlock, prob));
}

/**
* Adds a ItemsAdder's custom block and associated probability
* @param namedSpaceID - name space and ID
* @param prob - probability
*/
public void addItemsAdderCustomBlock(String namedSpaceID, int prob) {
total += prob;
blockTotal += prob;
probMap.put(total, new OneBlockObject(namedSpaceID, prob));
}

/**
* Adds an entity type and associated probability
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import com.google.common.base.Enums;
import com.google.common.io.Files;

import dev.lone.itemsadder.api.CustomBlock;
import dev.lone.itemsadder.api.ItemsAdder;
import world.bentobox.aoneblock.AOneBlock;
import world.bentobox.aoneblock.dataobjects.OneBlockIslands;
import world.bentobox.aoneblock.oneblocks.OneBlockObject.Rarity;
Expand Down Expand Up @@ -489,22 +487,7 @@ void addBlocks(OneBlockPhase obPhase, ConfigurationSection phase) {
if (phase.isConfigurationSection(BLOCKS)) {
ConfigurationSection blocks = phase.getConfigurationSection(BLOCKS);
for (String material : blocks.getKeys(false)) {
if (Material.getMaterial(material) != null) {
addMaterial(obPhase, material, Objects.toString(blocks.get(material)));
} else {
if (addon.hasItemsAdder()) {
CustomBlock block = CustomBlock.getInstance(material);
if (block != null) {
addItemsAdderBlock(obPhase, material, Objects.toString(blocks.get(material)));
} else if (ItemsAdder.getAllItems() != null) {
if (ItemsAdder.getAllItems().size() != 0) {
addon.logError("Bad block material in " + obPhase.getPhaseName() + ": " + material);
}
}
} else {
addon.logError("Bad block material in " + obPhase.getPhaseName() + ": " + material);
}
}
addMaterial(obPhase, material, Objects.toString(blocks.get(material)));
}
} else if (phase.isList(BLOCKS)) {
List<Map<?, ?>> blocks = phase.getMapList(BLOCKS);
Expand Down Expand Up @@ -559,22 +542,6 @@ private boolean addMaterial(OneBlockPhase obPhase, String material, String proba
return true;
}

private void addItemsAdderBlock(OneBlockPhase obPhase, String block, String probability) {
int prob;
try {
prob = Integer.parseInt(probability);
if (prob < 1) {
addon.logWarning("Bad item weight for " + obPhase.getPhaseName() + ": " + block
+ ". Must be positive number above 1.");
} else {
obPhase.addItemsAdderCustomBlock(block, prob);
}
} catch (Exception e) {
addon.logError("Bad item weight for " + obPhase.getPhaseName() + ": " + block + ". Must be a number.");
}

}

/**
* Return the current phase for the block count
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package world.bentobox.aoneblock.oneblocks.customblock;

import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import org.bukkit.Bukkit;
import org.bukkit.block.Block;

import world.bentobox.aoneblock.AOneBlock;
import world.bentobox.aoneblock.oneblocks.OneBlockCustomBlock;
import world.bentobox.bentobox.BentoBox;

import java.util.Map;
import java.util.Objects;
import java.util.Optional;

/**
* A custom block that is defined by a block data value.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package world.bentobox.aoneblock.oneblocks.customblock;

import dev.lone.itemsadder.api.CustomBlock;
import org.bukkit.Material;
import org.bukkit.block.Block;
import world.bentobox.aoneblock.AOneBlock;
import world.bentobox.aoneblock.oneblocks.OneBlockCustomBlock;
import world.bentobox.bentobox.BentoBox;

import java.util.Map;
import java.util.Objects;
import java.util.Optional;

public class ItemsAdderCustomBlock implements OneBlockCustomBlock {
private final CustomBlock customBlock;

public ItemsAdderCustomBlock(CustomBlock customBlock) {
this.customBlock = customBlock;
}

public static Optional<ItemsAdderCustomBlock> fromId(String id) {
return Optional.ofNullable(CustomBlock.getInstance(id)).map(ItemsAdderCustomBlock::new);
}

public static Optional<ItemsAdderCustomBlock> fromMap(Map<?, ?> map) {
return Optional
.ofNullable(Objects.toString(map.get("id"), null))
.flatMap(ItemsAdderCustomBlock::fromId);
}

@Override
public void execute(AOneBlock addon, Block block) {
try {
block.setType(Material.AIR);
customBlock.place(block.getLocation());
} catch (Exception e) {
BentoBox.getInstance().logError("Could not place custom block " + customBlock.getId() + " for block " + block.getType());
block.setType(Material.STONE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static Optional<MobCustomBlock> fromMap(Map<?, ?> map) {
EntityType entityType = maybeEntity(entityTypeValue);
Material underlyingBlock = Material.getMaterial(underlyingBlockValue);

if(underlyingBlock == null){
if (underlyingBlock == null) {
BentoBox.getInstance().logWarning("Underlying block " + underlyingBlockValue + " does not exist and will be replaced with STONE.");
}

Expand Down

0 comments on commit f92df5f

Please sign in to comment.