Skip to content

Commit

Permalink
Merge pull request #16 from SlimefunGuguProject/bs-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ybw0014 authored Jun 6, 2023
2 parents 3f4d642 + 658629d commit 462f4c9
Show file tree
Hide file tree
Showing 21 changed files with 138 additions and 106 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.Slimefun</groupId>
<groupId>com.github.StarWishsama</groupId>
<artifactId>Slimefun4</artifactId>
<version>b1aae439f3</version>
<version>2023.06</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -141,7 +141,7 @@
<dependency>
<groupId>net.guizhanss</groupId>
<artifactId>GuizhanLibPlugin</artifactId>
<version>1.1.0</version>
<version>1.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package dev.sefiraat.netheopoiesis.api.interfaces;

import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData;
import dev.sefiraat.netheopoiesis.api.items.NetherCrux;
import dev.sefiraat.netheopoiesis.api.items.NetherSeed;
import dev.sefiraat.netheopoiesis.api.plant.GrowthStages;
import dev.sefiraat.netheopoiesis.utils.Skulls;
import dev.sefiraat.netheopoiesis.utils.Theme;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import org.bukkit.Location;
import org.bukkit.inventory.ItemStack;

Expand All @@ -26,10 +26,10 @@ public interface NetherPlant extends PurifyingObject {
*
* @param location The location of the plant being ticked
* @param seed The {@link SlimefunItem} being ticked
* @param data The {@link Config} from BlockStorage for the location
* @param data The {@link SlimefunBlockData} from BlockStorage for the location
*/
@ParametersAreNonnullByDefault
default void onTickAlways(Location location, NetherSeed seed, Config data) {
default void onTickAlways(Location location, NetherSeed seed, SlimefunBlockData data) {

}

Expand All @@ -38,10 +38,10 @@ default void onTickAlways(Location location, NetherSeed seed, Config data) {
*
* @param location The location of the plant being ticked
* @param seed The {@link SlimefunItem} being ticked
* @param data The {@link Config} from BlockStorage for the location
* @param data The {@link SlimefunBlockData} from BlockStorage for the location
*/
@ParametersAreNonnullByDefault
default void onTickFullyGrown(Location location, NetherSeed seed, Config data) {
default void onTickFullyGrown(Location location, NetherSeed seed, SlimefunBlockData data) {

}

Expand All @@ -50,10 +50,10 @@ default void onTickFullyGrown(Location location, NetherSeed seed, Config data) {
*
* @param location The location of the plant being ticked
* @param seed The {@link SlimefunItem} being ticked
* @param data The {@link Config} from BlockStorage for the location
* @param data The {@link SlimefunBlockData} from BlockStorage for the location
*/
@ParametersAreNonnullByDefault
default void onGrowthStep(Location location, NetherSeed seed, Config data) {
default void onGrowthStep(Location location, NetherSeed seed, SlimefunBlockData data) {

}

Expand All @@ -62,10 +62,10 @@ default void onGrowthStep(Location location, NetherSeed seed, Config data) {
*
* @param location The location of the plant being ticked
* @param seed The {@link SlimefunItem} being ticked
* @param data The {@link Config} from BlockStorage for the location
* @param data The {@link SlimefunBlockData} from BlockStorage for the location
*/
@ParametersAreNonnullByDefault
default void onFullyMatures(Location location, NetherSeed seed, Config data) {
default void onFullyMatures(Location location, NetherSeed seed, SlimefunBlockData data) {

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.sefiraat.netheopoiesis.api.interfaces;

import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData;
import dev.sefiraat.netheopoiesis.api.items.CruxSpreadingSeed;
import dev.sefiraat.netheopoiesis.api.items.NetherSeed;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import org.bukkit.Location;
import org.bukkit.block.Block;

Expand All @@ -16,10 +16,10 @@
public interface SpreadingPlant {

@ParametersAreNonnullByDefault
void spread(Location sourceLocation, NetherSeed seed, Config data);
void spread(Location sourceLocation, NetherSeed seed, SlimefunBlockData data);

@ParametersAreNonnullByDefault
default void afterSpread(Location sourceLocation, NetherSeed seed, Config data, Block spreadTo) {
default void afterSpread(Location sourceLocation, NetherSeed seed, SlimefunBlockData data, Block spreadTo) {

}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package dev.sefiraat.netheopoiesis.api.items;

import com.google.common.base.Preconditions;
import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData;
import com.xzavier0722.mc.plugin.slimefun4.storage.util.StorageCacheUtils;
import dev.sefiraat.netheopoiesis.Purification;
import dev.sefiraat.netheopoiesis.api.interfaces.CustomPlacementBlock;
import dev.sefiraat.netheopoiesis.api.interfaces.PurificationDrain;
import dev.sefiraat.netheopoiesis.listeners.CustomPlacementListener;
import dev.sefiraat.netheopoiesis.utils.Keys;
Expand All @@ -13,9 +14,9 @@
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
Expand All @@ -40,7 +41,7 @@
* It will also post its location to the Registry and draw additional power from other SiphoningBlocks
* below it so long as it's a tier higher.
*/
public class BeaconSiphoningBlock extends SlimefunItem implements PurificationDrain, CustomPlacementBlock {
public class BeaconSiphoningBlock extends SlimefunItem implements PurificationDrain {

@Nonnull
private static final Map<BlockPosition, Integer> POWER_MAP = new HashMap<>();
Expand Down Expand Up @@ -79,7 +80,7 @@ public boolean isSynchronized() {
}

@Override
public void tick(Block block, SlimefunItem item, Config data) {
public void tick(Block block, SlimefunItem item, SlimefunBlockData data) {
onTick(block, item, data);
}

Expand All @@ -88,6 +89,13 @@ public void uniqueTick() {
onUniqueTick();
}
},
new BlockPlaceHandler(false) {
@Override
@ParametersAreNonnullByDefault
public void onPlayerPlace(BlockPlaceEvent e) {
whenPlaced(e);
}
},
new BlockBreakHandler(false, false) {
@Override
public void onPlayerBreak(BlockBreakEvent e, ItemStack item, List<ItemStack> drops) {
Expand All @@ -99,7 +107,7 @@ public void onPlayerBreak(BlockBreakEvent e, ItemStack item, List<ItemStack> dro

@ParametersAreNonnullByDefault
@OverridingMethodsMustInvokeSuper
protected boolean onTick(Block block, SlimefunItem item, Config data) {
protected boolean onTick(Block block, SlimefunItem item, SlimefunBlockData data) {

// We do not want to operate every single tick
if (currentTick != TICKS_PER_OPERATION) {
Expand All @@ -122,7 +130,7 @@ protected boolean onTick(Block block, SlimefunItem item, Config data) {
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
final Block blockBelow = block.getRelative(x, -1, z);
final SlimefunItem slimefunItem = BlockStorage.check(blockBelow);
final SlimefunItem slimefunItem = StorageCacheUtils.getSfItem(blockBelow.getLocation());
if (slimefunItem instanceof BeaconSiphoningBlock siphon
&& siphon.tier == this.tier + 1
) {
Expand Down Expand Up @@ -158,12 +166,13 @@ public void whenPlaced(@Nonnull BlockPlaceEvent event) {

if (WorldUtils.inNether(block.getWorld())) {
final UUID uuid = event.getPlayer().getUniqueId();
BlockStorage.addBlockInfo(location, Keys.BLOCK_OWNER, uuid.toString());
StorageCacheUtils.setData(location, Keys.BLOCK_OWNER, uuid.toString());
ownerCache.put(location, uuid);
return;
}
// Wasn't placable, so cancel the event
event.setCancelled(true);
Slimefun.getDatabaseManager().getBlockDataController().removeBlock(location);
}

@Override
Expand All @@ -178,7 +187,7 @@ public void init() {

@Override
public void newInstance(@Nonnull BlockMenu menu, @Nonnull Block block) {
final String ownerUuidString = BlockStorage.getLocationInfo(block.getLocation(), Keys.BLOCK_OWNER);
final String ownerUuidString = StorageCacheUtils.getData(block.getLocation(), Keys.BLOCK_OWNER);
if (ownerUuidString != null) {
final UUID ownerUuid = UUID.fromString(ownerUuidString);
addOwner(block.getLocation(), ownerUuid);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.sefiraat.netheopoiesis.api.items;

import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData;
import dev.sefiraat.netheopoiesis.Netheopoiesis;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
Expand Down Expand Up @@ -28,13 +29,13 @@ public BiomeSpreadingSeed(@Nonnull SlimefunItemStack item) {

@Override
@ParametersAreNonnullByDefault
public void onTickFullyGrown(Location location, NetherSeed seed, Config data) {
public void onTickFullyGrown(Location location, NetherSeed seed, SlimefunBlockData data) {
spread(location, seed, data);
}

@Override
@ParametersAreNonnullByDefault
public void afterSpread(Location sourceLocation, NetherSeed seed, Config data, Block spreadTo) {
public void afterSpread(Location sourceLocation, NetherSeed seed, SlimefunBlockData data, Block spreadTo) {
if (this.biome != null) {
for (int i = spreadTo.getY() - 2; i < spreadTo.getY() + 5; i++) {
spreadTo.getWorld().setBiome(spreadTo.getX(), i, spreadTo.getZ(), this.biome);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.sefiraat.netheopoiesis.api.items;

import com.google.common.base.Preconditions;
import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData;
import com.xzavier0722.mc.plugin.slimefun4.storage.util.StorageCacheUtils;
import dev.sefiraat.netheopoiesis.Netheopoiesis;
import dev.sefiraat.netheopoiesis.Purification;
import dev.sefiraat.netheopoiesis.api.events.CruxSpreadEvent;
Expand All @@ -9,9 +11,8 @@
import dev.sefiraat.netheopoiesis.utils.ProtectionUtils;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.libraries.dough.protection.Interaction;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
Expand All @@ -37,13 +38,13 @@ public CruxSpreadingSeed(@Nonnull SlimefunItemStack item) {

@Override
@ParametersAreNonnullByDefault
public void onTickFullyGrown(Location location, NetherSeed seed, Config data) {
public void onTickFullyGrown(Location location, NetherSeed seed, SlimefunBlockData data) {
spread(location, seed, data);
}

@Override
@ParametersAreNonnullByDefault
public void spread(Location sourceLocation, NetherSeed seed, Config data) {
public void spread(Location sourceLocation, NetherSeed seed, SlimefunBlockData data) {
double randomChance = ThreadLocalRandom.current().nextDouble();

if (randomChance <= (this.spreadChance * Netheopoiesis.CRUX_SPREAD_MULTIPLIER)) {
Expand All @@ -57,7 +58,7 @@ public void spread(Location sourceLocation, NetherSeed seed, Config data) {
// For loop to make sure the purification can creep up and down.

final Block block = sourceLocation.clone().add(randomX, randomY, randomZ).getBlock();
final SlimefunItem possibleCrux = BlockStorage.check(block);
final SlimefunItem possibleCrux = StorageCacheUtils.getSfItem(block.getLocation());
if (possibleCrux instanceof NetherCrux currentCrux
&& getPlacements().contains(currentCrux.getId())
&& ProtectionUtils.hasPermission(getOwner(sourceLocation), block, Interaction.BREAK_BLOCK)
Expand All @@ -76,7 +77,7 @@ && getPlacements().contains(currentCrux.getId())
// Event cancelled - lets not spread
return;
}
BlockStorage.clearBlockInfo(block);
Slimefun.getDatabaseManager().getBlockDataController().removeBlock(block.getLocation());
Purification.removeValue(block);
// Schedule a task to ensure the new block storage happens only AFTER deletion
UpdateCruxTask task = new UpdateCruxTask(block, convertTo);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package dev.sefiraat.netheopoiesis.api.items;

import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData;
import com.xzavier0722.mc.plugin.slimefun4.storage.util.StorageCacheUtils;
import dev.sefiraat.netheopoiesis.Netheopoiesis;
import io.github.bakedlibs.dough.collections.RandomizedSet;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -33,21 +34,21 @@ public DroppingSeed(@Nonnull SlimefunItemStack item) {

@Override
@ParametersAreNonnullByDefault
public void onTickFullyGrown(Location location, NetherSeed seed, Config data) {
public void onTickFullyGrown(Location location, NetherSeed seed, SlimefunBlockData data) {
double randomChance = ThreadLocalRandom.current().nextDouble();
if (randomChance <= chance) {
location.getWorld().dropItem(location, this.stacksToDrop.getRandom());
updateGrowthStage(location, 1);
final String currentChance = BlockStorage.getLocationInfo(location, WITHER_KEY);
final String currentChance = StorageCacheUtils.getData(location, WITHER_KEY);
if (currentChance == null) {
BlockStorage.addBlockInfo(location, WITHER_KEY, String.valueOf(WITHER_CHANCE));
StorageCacheUtils.setData(location, WITHER_KEY, String.valueOf(WITHER_CHANCE));
} else {
final int currentChanceInt = Integer.parseInt(currentChance);
if (ThreadLocalRandom.current().nextInt(101) < currentChanceInt) {
location.getBlock().setType(Material.AIR);
BlockStorage.clearBlockInfo(location);
Slimefun.getDatabaseManager().getBlockDataController().removeBlock(location);
} else {
BlockStorage.addBlockInfo(location, WITHER_KEY, String.valueOf(currentChanceInt + WITHER_CHANCE));
StorageCacheUtils.setData(location, WITHER_KEY, String.valueOf(currentChanceInt + WITHER_CHANCE));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.sefiraat.netheopoiesis.api.items;

import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData;
import dev.sefiraat.netheopoiesis.Netheopoiesis;
import dev.sefiraat.netheopoiesis.utils.WorldUtils;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
Expand Down Expand Up @@ -35,7 +36,7 @@ public EntitySpawningSeed(@Nonnull SlimefunItemStack item) {

@Override
@ParametersAreNonnullByDefault
public void onTickFullyGrown(Location location, NetherSeed seed, Config data) {
public void onTickFullyGrown(Location location, NetherSeed seed, SlimefunBlockData data) {
double randomChance = ThreadLocalRandom.current().nextDouble();
if (randomChance <= 0.05) {
final Block block = WorldUtils.randomLocation(location, 4).getBlock();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.sefiraat.netheopoiesis.api.items;

import com.google.common.base.Preconditions;
import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData;
import dev.sefiraat.netheopoiesis.Netheopoiesis;
import dev.sefiraat.netheopoiesis.implementation.GenericTickingMethods;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
Expand Down Expand Up @@ -29,7 +30,7 @@ public GenericTickingSeed(@Nonnull SlimefunItemStack item) {

@Override
@ParametersAreNonnullByDefault
public void onTickFullyGrown(Location location, NetherSeed seed, Config data) {
public void onTickFullyGrown(Location location, NetherSeed seed, SlimefunBlockData data) {
final GenericTickingMethods.TickParameters tickParameters = new GenericTickingMethods.TickParameters(
location,
seed,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.sefiraat.netheopoiesis.api.items;

import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData;
import dev.sefiraat.netheopoiesis.api.RecipeTypes;
import dev.sefiraat.netheopoiesis.api.interfaces.PurifyingObject;
import dev.sefiraat.netheopoiesis.implementation.Stacks;
Expand All @@ -8,9 +9,8 @@
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler;
import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.block.BlockBreakEvent;
Expand Down Expand Up @@ -53,7 +53,7 @@ public void onPlayerBreak(BlockBreakEvent event, ItemStack item, List<ItemStack>
if (slimefunItem == null || !slimefunItem.getId().equals(Stacks.CRUX_GATHERER.getItemId())) {
event.setCancelled(true);
block.setType(Material.AIR);
BlockStorage.clearBlockInfo(block);
Slimefun.getDatabaseManager().getBlockDataController().removeBlock(block.getLocation());
}
removePurificationRegistry(block);
}
Expand All @@ -65,7 +65,7 @@ public boolean isSynchronized() {
}

@Override
public void tick(Block block, SlimefunItem item, Config data) {
public void tick(Block block, SlimefunItem item, SlimefunBlockData data) {
if (NetherCrux.this.tick >= TICKS_REQUIRED) {
registerPurificationValue(block);
}
Expand Down
Loading

0 comments on commit 462f4c9

Please sign in to comment.