Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -46,6 +50,13 @@
<version>1.21.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- Folia API (via papermc) -->
<dependency>
<groupId>dev.folia</groupId>
<artifactId>folia-api</artifactId>
<version>1.21.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- XSeries -->
<!-- https://github.com/CryptoMorin/XSeries/ -->
<dependency>
Expand Down Expand Up @@ -93,12 +104,6 @@
<artifactId>bukkit-server-version</artifactId>
<version>0.0.2</version>
</dependency>
<!-- LeafCommunity Tasks (via jitpack.io) -->
<dependency>
<groupId>community.leaf.tasks</groupId>
<artifactId>tasks-bukkit</artifactId>
<version>0.0.2</version>
</dependency>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep this dependency.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no why on using that dependency since it isn't used anymore, and it CAN'T be used since it uses only bukkit scheduler

<!-- bStats (via maven-central) -->
<dependency>
<groupId>org.bstats</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2022-2024, RezzedUp and Contributors <https://github.com/LeafCommunity/ConcreteMixer>
* Copyright © 2022-2025, RezzedUp and Contributors <https://github.com/LeafCommunity/ConcreteMixer>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -13,8 +13,9 @@
import community.leaf.eventful.bukkit.annotations.CancelledEvents;
import community.leaf.eventful.bukkit.annotations.EventListener;
import community.leaf.survival.concretemixer.metrics.TransformationsPerHour;
import community.leaf.survival.concretemixer.util.folia.FoliaRunnable;
import community.leaf.survival.concretemixer.util.folia.SchedulerUtils;
import community.leaf.survival.concretemixer.util.internal.ConcreteDebug;
import community.leaf.tasks.TaskContext;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
Expand All @@ -37,7 +38,7 @@
import java.util.UUID;

public class CauldronPowderDropListener implements Listener {
private final Map<UUID, TaskContext<BukkitTask>> transformationTasksByItemUuid = new HashMap<>();
private final Map<UUID, FoliaRunnable> transformationTasksByItemUuid = new HashMap<>();

private final ConcreteMixerPlugin plugin;
private final TransformationsPerHour counter;
Expand Down Expand Up @@ -117,22 +118,17 @@ public void onCauldronLevelChange(CauldronLevelChangeEvent event) {
}

private boolean cancelExistingTransformation(Item item) {
@NullOr TaskContext<BukkitTask> task =
@NullOr FoliaRunnable runnable =
transformationTasksByItemUuid.remove(item.getUniqueId());

if (task != null) {
task.cancel();
if (runnable != null) {
runnable.cancel();
return true;
}

return false;
}

private void cancel(Item item, TaskContext<BukkitTask> task) {
transformationTasksByItemUuid.remove(item.getUniqueId());
task.cancel();
}

private @NullOr Entity entity(@NullOr UUID uuid) {
return (uuid == null) ? null : plugin.getServer().getEntity(uuid);
}
Expand All @@ -144,113 +140,120 @@ class IterationCounter {
}

IterationCounter iterations = new IterationCounter();

transformationTasksByItemUuid.put(
item.getUniqueId(),
plugin.sync().delay(2).ticks().every(2).ticks().run(task ->
SchedulerUtils.runTaskTimer(item.getLocation(), new FoliaRunnable()
{
Block cauldron = item.getLocation().getBlock();
Material material = item.getItemStack().getType();

// Outside the cauldron, dropping in ... (or not)
if (cauldron.getType() != Material.WATER_CAULDRON) {
iterations.outside++;

// Took too long to drop in, might not even be a cauldron nearby for all we know
if (iterations.outside > 20) {
cancel(item, task);
}

return;
private void cancel(Item item) {
transformationTasksByItemUuid.remove(item.getUniqueId());
cancel();
}

// Inside the cauldron
iterations.inside++;
boolean lowerWaterLevel = plugin.config().getOrDefault(Config.LOWER_WATER_LEVEL);

// Check if player is allowed to use this specific cauldron
// (only if water level gets lowered, since that could be considered griefing)
if (lowerWaterLevel && entity(item.getThrower()) instanceof Player player) {
if (!plugin.permissions().canAccessCauldron(player, cauldron)) {
cancel(item, task);

@Override
public void run() {
Block cauldron = item.getLocation().getBlock();
Material material = item.getItemStack().getType();

// Outside the cauldron, dropping in ... (or not)
if (cauldron.getType() != Material.WATER_CAULDRON) {
iterations.outside++;

// Took too long to drop in, might not even be a cauldron nearby for all we know
if (iterations.outside > 20) {
cancel(item);
}

return;
}
}

// TODO: more sophisticated merging
// Attempt to merge item stacks
if (experimentalItemMerging && item.getItemStack().getAmount() == 1) {
for (Entity nearby : item.getNearbyEntities(0.5, 0.5, 0.5)) {
if (!(nearby instanceof Item cooking)) {
continue;
}
if (!transformationTasksByItemUuid.containsKey(cooking.getUniqueId())) {
continue;
}
if (!Objects.equals(item.getThrower(), cooking.getThrower())) {
continue;
}

ItemStack cooked = cooking.getItemStack();
if (cooked.getAmount() >= 64 || cooked.getType() != material) {
continue;

// Inside the cauldron
iterations.inside++;
boolean lowerWaterLevel = plugin.config().getOrDefault(Config.LOWER_WATER_LEVEL);

// Check if player is allowed to use this specific cauldron
// (only if water level gets lowered, since that could be considered griefing)
if (lowerWaterLevel && entity(item.getThrower()) instanceof Player player) {
if (!plugin.permissions().canAccessCauldron(player, cauldron)) {
cancel(item);
return;
}
if (plugin.events().call(new ItemMergeEvent(item, cooking)).isCancelled()) {
continue; // merge cancelled, try another neighbor
}

// TODO: more sophisticated merging
// Attempt to merge item stacks
if (experimentalItemMerging && item.getItemStack().getAmount() == 1) {
for (Entity nearby : item.getNearbyEntities(0.5, 0.5, 0.5)) {
if (!(nearby instanceof Item cooking)) {
continue;
}
if (!transformationTasksByItemUuid.containsKey(cooking.getUniqueId())) {
continue;
}
if (!Objects.equals(item.getThrower(), cooking.getThrower())) {
continue;
}

ItemStack cooked = cooking.getItemStack();
if (cooked.getAmount() >= 64 || cooked.getType() != material) {
continue;
}
if (plugin.events().call(new ItemMergeEvent(item, cooking)).isCancelled()) {
continue; // merge cancelled, try another neighbor
}

cooked.setAmount(cooked.getAmount() + 1);
item.remove();

cancel(item);
return;
}

cooked.setAmount(cooked.getAmount() + 1);
item.remove();

cancel(item, task);
}

if (iterations.inside == 1) {
item.setPickupDelay(40);
plugin.effects().cauldronSplashSound(item.getLocation());
}

if (iterations.inside < 15) {
plugin.effects().cauldronSplashParticles(cauldron);
return;
}

// Done with this task... it's finally time to transform the powder!
cancel(item);

@NullOr Concrete concrete = Concrete.ofPowder(material).orElse(null);
if (concrete == null) {
return;
}

ItemStack stack = item.getItemStack();
stack.setType(concrete.concrete());
item.setItemStack(stack);

item.setVelocity(new Vector(0, 0.3, 0));
item.setPickupDelay(10);

plugin.effects().concreteTransform(cauldron);
counter.transformed(stack.getAmount());

if (!lowerWaterLevel) {
return;
}
if (!(cauldron.getBlockData() instanceof Levelled levelled)) {
return;
}

int level = levelled.getLevel() - 1;

if (level <= 0) {
cauldron.setType(Material.CAULDRON);
} else {
levelled.setLevel(level);
cauldron.setBlockData(levelled);
}
}

if (iterations.inside == 1) {
item.setPickupDelay(40);
plugin.effects().cauldronSplashSound(item.getLocation());
}

if (iterations.inside < 15) {
plugin.effects().cauldronSplashParticles(cauldron);
return;
}

// Done with this task... it's finally time to transform the powder!
cancel(item, task);

@NullOr Concrete concrete = Concrete.ofPowder(material).orElse(null);
if (concrete == null) {
return;
}

ItemStack stack = item.getItemStack();
stack.setType(concrete.concrete());
item.setItemStack(stack);

item.setVelocity(new Vector(0, 0.3, 0));
item.setPickupDelay(10);

plugin.effects().concreteTransform(cauldron);
counter.transformed(stack.getAmount());

if (!lowerWaterLevel) {
return;
}
if (!(cauldron.getBlockData() instanceof Levelled levelled)) {
return;
}

int level = levelled.getLevel() - 1;

if (level <= 0) {
cauldron.setType(Material.CAULDRON);
} else {
levelled.setLevel(level);
cauldron.setBlockData(levelled);
}
})
}, 2, 2)
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2022-2024, RezzedUp and Contributors <https://github.com/LeafCommunity/ConcreteMixer>
* Copyright © 2022-2025, RezzedUp and Contributors <https://github.com/LeafCommunity/ConcreteMixer>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2022-2024, RezzedUp and Contributors <https://github.com/LeafCommunity/ConcreteMixer>
* Copyright © 2022-2025, RezzedUp and Contributors <https://github.com/LeafCommunity/ConcreteMixer>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2022-2024, RezzedUp and Contributors <https://github.com/LeafCommunity/ConcreteMixer>
* Copyright © 2022-2025, RezzedUp and Contributors <https://github.com/LeafCommunity/ConcreteMixer>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -11,7 +11,7 @@
import community.leaf.eventful.bukkit.BukkitEventSource;
import community.leaf.survival.concretemixer.hooks.HookHandler;
import community.leaf.survival.concretemixer.metrics.TransformationsPerHour;
import community.leaf.tasks.bukkit.BukkitTaskSource;
import community.leaf.survival.concretemixer.util.folia.SchedulerUtils;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SingleLineChart;
import org.bukkit.command.PluginCommand;
Expand All @@ -21,14 +21,27 @@

import java.nio.file.Path;

public class ConcreteMixerPlugin extends JavaPlugin implements BukkitEventSource, BukkitTaskSource {
public class ConcreteMixerPlugin extends JavaPlugin implements BukkitEventSource {
public static boolean usingFolia = false;

private @NullOr Version version;
private @NullOr Path directory;
private @NullOr Config config;
private @NullOr EffectHandler effects;
private @NullOr HookHandler hooks;
private @NullOr PermissionHandler permissions;
private @NullOr UpdateChecker updates;

@Override
public void onLoad() {
try {
Class.forName("io.papermc.paper.threadedregions.scheduler.RegionScheduler");
usingFolia = true;
} catch (ClassNotFoundException e) {
usingFolia = false;
}
SchedulerUtils.plugin = this;
}

@Override
public void onEnable() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2022-2024, RezzedUp and Contributors <https://github.com/LeafCommunity/ConcreteMixer>
* Copyright © 2022-2025, RezzedUp and Contributors <https://github.com/LeafCommunity/ConcreteMixer>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2022-2024, RezzedUp and Contributors <https://github.com/LeafCommunity/ConcreteMixer>
* Copyright © 2022-2025, RezzedUp and Contributors <https://github.com/LeafCommunity/ConcreteMixer>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2022-2024, RezzedUp and Contributors <https://github.com/LeafCommunity/ConcreteMixer>
* Copyright © 2022-2025, RezzedUp and Contributors <https://github.com/LeafCommunity/ConcreteMixer>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down
Loading