Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Folia support #570

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
24 changes: 17 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,18 @@
<artifactSet>
<includes>
<include>org.bstats:*</include>
<include>com.github.Anon8281:*</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>com.dre.brewery.integration.bstats</shadedPattern>
</relocation>
<relocation>
<pattern>com.github.Anon8281.universalScheduler</pattern>
<shadedPattern>com.dre.brewery.integration.universalScheduler</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
Expand Down Expand Up @@ -127,11 +132,11 @@
<id>chestshop-repo</id>
<url>https://repo.minebench.de/</url>
</repository>
<repository>
<!-- BlockLocker -->
<id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
<repository>
<!-- BlockLocker -->
<id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
<repository>
<!-- MythicLib (MMOItems) -->
<id>phoenix</id>
Expand All @@ -142,7 +147,6 @@
<id>Lichtspiele</id>
<url>https://nexus.lichtspiele.org/repository/releases/</url>
</repository>

</repositories>

<dependencies>
Expand Down Expand Up @@ -296,7 +300,7 @@
<!-- https://www.spigotmc.org/resources/towny-advanced.72694/history -->
<groupId>com.github.TownyAdvanced</groupId>
<artifactId>Towny</artifactId>
<version>0.100.0.0</version>
<version>0.100.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -320,5 +324,11 @@
<version>16.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.Anon8281</groupId>
<artifactId>UniversalScheduler</artifactId>
<version>0.1.3</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
1 change: 1 addition & 0 deletions resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: 3.1.1
main: com.dre.brewery.P
softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention, Vault, ChestShop, Shopkeepers, Towny, BlockLocker, Slimefun]
authors: [Milan Albrecht, Frank Baumann, ProgrammerDan, Daniel Saukel]
folia-supported: true
api-version: 1.13
commands:
brewery:
Expand Down
9 changes: 5 additions & 4 deletions src/com/dre/brewery/BCauldron.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class BCauldron {
public static final byte EMPTY = 0, SOME = 1, FULL = 2;
public static final int PARTICLEPAUSE = 15;
public static Random particleRandom = new Random();
private static Set<UUID> plInteracted = new HashSet<>(); // Interact Event helper
public static Map<Block, BCauldron> bcauldrons = new HashMap<>(); // All active cauldrons. Mapped to their block for fast retrieve
public volatile static Map<Block, BCauldron> bcauldrons = new ConcurrentHashMap<>(); // All active cauldrons. Mapped to their block for fast retrieve
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason why you added volatile to this Map? It is already a ConcurrentHashMap, did you find a reason that this has to be added?

Copy link
Author

Choose a reason for hiding this comment

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

Just in case. I'm not sure about the need for this


private BIngredients ingredients = new BIngredients();
private final Block block;
Expand Down Expand Up @@ -372,7 +373,7 @@ public static void processCookEffects() {

for (BCauldron cauldron : bcauldrons.values()) {
if (particleRandom.nextFloat() < chance) {
cauldron.cookEffect();
P.getScheduler().runTask(cauldron.block.getLocation(), cauldron::cookEffect);
}
}
}
Expand Down Expand Up @@ -441,7 +442,7 @@ public static void clickCauldron(PlayerInteractEvent event) {
if (event.getHand() == EquipmentSlot.HAND) {
final UUID id = player.getUniqueId();
plInteracted.add(id);
P.p.getServer().getScheduler().runTask(P.p, () -> plInteracted.remove(id));
P.getScheduler().runTask(() -> plInteracted.remove(id));
} else if (event.getHand() == EquipmentSlot.OFF_HAND) {
if (!plInteracted.remove(player.getUniqueId())) {
item = player.getInventory().getItemInMainHand();
Expand Down Expand Up @@ -563,7 +564,7 @@ public static void save(ConfigurationSection config, ConfigurationSection oldDat
// bukkit bug not updating the inventory while executing event, have to
// schedule the give
public static void giveItem(final Player player, final ItemStack item) {
P.p.getServer().getScheduler().runTaskLater(P.p, () -> player.getInventory().addItem(item), 1L);
P.getScheduler().runTaskLater(() -> player.getInventory().addItem(item), 1L);
}

}
68 changes: 36 additions & 32 deletions src/com/dre/brewery/BDistiller.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.dre.brewery;

import com.dre.brewery.lore.BrewLore;
import com.github.Anon8281.universalScheduler.UniversalRunnable;
import com.github.Anon8281.universalScheduler.scheduling.tasks.MyScheduledTask;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
Expand All @@ -10,10 +12,10 @@
import org.bukkit.inventory.BrewerInventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
* Updated for 1.9 to replicate the "Brewing" process for distilling.
Expand All @@ -27,9 +29,9 @@
public class BDistiller {

private static final int DISTILLTIME = 400;
private static Map<Block, BDistiller> trackedDistillers = new HashMap<>();
private static Map<Block, BDistiller> trackedDistillers = new ConcurrentHashMap<>();

private int taskId;
private MyScheduledTask task;
private int runTime = -1;
private int brewTime = -1;
private Block standBlock;
Expand All @@ -41,11 +43,11 @@ public BDistiller(Block standBlock, int fuel) {
}

public void cancelDistill() {
Bukkit.getScheduler().cancelTask(taskId); // cancel prior
task.cancel();
}

public void start() {
taskId = new DistillRunnable().runTaskTimer(P.p, 2L, 1L).getTaskId();
task = new DistillRunnable().runTaskTimer(P.p, 2L, 1L);
}

public static void distillerClick(InventoryClickEvent event) {
Expand Down Expand Up @@ -167,43 +169,45 @@ public static void showAlc(BrewerInventory inv, Brew[] contents) {
}
}

public class DistillRunnable extends BukkitRunnable {
public class DistillRunnable extends UniversalRunnable {
private Brew[] contents = null;

@Override
public void run() {
BlockState now = standBlock.getState();
if (now instanceof BrewingStand) {
BrewingStand stand = (BrewingStand) now;
if (brewTime == -1) { // check at the beginning for distillables
if (!prepareForDistillables(stand)) {
return;
P.getScheduler().runTask(standBlock.getLocation(), () -> {
BlockState now = standBlock.getState();
if (now instanceof BrewingStand) {
BrewingStand stand = (BrewingStand) now;
if (brewTime == -1) { // check at the beginning for distillables
if (!prepareForDistillables(stand)) {
return;
}
}
}

brewTime--; // count down.
stand.setBrewingTime((int) ((float) brewTime / ((float) runTime / (float) DISTILLTIME)) + 1);

if (brewTime <= 1) { // Done!
contents = getDistillContents(stand.getInventory()); // Get the contents again at the end just in case
stand.setBrewingTime(0);
stand.update();
if (!runDistill(stand.getInventory(), contents)) {
this.cancel();
trackedDistillers.remove(standBlock);
P.p.debugLog("All done distilling");
brewTime--; // count down.
stand.setBrewingTime((int) ((float) brewTime / ((float) runTime / (float) DISTILLTIME)) + 1);

if (brewTime <= 1) { // Done!
contents = getDistillContents(stand.getInventory()); // Get the contents again at the end just in case
stand.setBrewingTime(0);
stand.update();
if (!runDistill(stand.getInventory(), contents)) {
this.cancel();
trackedDistillers.remove(standBlock);
P.p.debugLog("All done distilling");
} else {
brewTime = -1; // go again.
P.p.debugLog("Can distill more! Continuing.");
}
} else {
brewTime = -1; // go again.
P.p.debugLog("Can distill more! Continuing.");
stand.update();
}
} else {
stand.update();
this.cancel();
trackedDistillers.remove(standBlock);
P.p.debugLog("The block was replaced; not a brewing stand.");
}
} else {
this.cancel();
trackedDistillers.remove(standBlock);
P.p.debugLog("The block was replaced; not a brewing stand.");
}
});
}

private boolean prepareForDistillables(BrewingStand stand) {
Expand Down
19 changes: 10 additions & 9 deletions src/com/dre/brewery/BPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.dre.brewery.recipe.BEffect;
import com.dre.brewery.utility.BUtil;
import com.dre.brewery.utility.PermissionUtil;
import com.github.Anon8281.universalScheduler.scheduling.tasks.MyScheduledTask;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Location;
Expand All @@ -32,7 +33,7 @@
public class BPlayer {
private static Map<String, BPlayer> players = new HashMap<>();// Players uuid and BPlayer
private static Map<Player, Integer> pTasks = new HashMap<>();// Player and count
private static int taskId;
private static MyScheduledTask task;
private static Random pukeRand;

private final String uuid;
Expand Down Expand Up @@ -218,8 +219,8 @@ public void showDrunkeness(Player player) {
try {
// It this returns false, then the Action Bar is not supported. Do not repeat the message as it was sent into chat
if (sendDrunkenessMessage(player)) {
P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> sendDrunkenessMessage(player), 40);
P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> sendDrunkenessMessage(player), 80);
P.getScheduler().runTaskLater(() -> sendDrunkenessMessage(player), 40);
P.getScheduler().runTaskLater(() -> sendDrunkenessMessage(player), 80);
}
} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -303,7 +304,7 @@ public boolean sendDrunkenessMessage(Player player) {
b.append("§7]");
final String text = b.toString();
if (hangover && P.use1_11) {
P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> player.sendTitle("", text, 30, 100, 90), 160);
P.getScheduler().runTaskLater(() -> player.sendTitle("", text, 30, 100, 90), 160);
return false;
}
try {
Expand All @@ -321,7 +322,7 @@ public void drinkCap(Player player) {
drunkeness = 100;
syncToSQL(false);
if (BConfig.overdrinkKick && !player.hasPermission("brewery.bypass.overdrink")) {
P.p.getServer().getScheduler().scheduleSyncDelayedTask(P.p, () -> passOut(player), 1);
P.getScheduler().runTaskLater(() -> passOut(player), 1);
} else {
addPuke(player, 60 + (int) (Math.random() * 60.0));
P.p.msg(player, P.p.languageReader.get("Player_CantDrink"));
Expand Down Expand Up @@ -467,7 +468,7 @@ public void join(final Player player) {
return;
}
// delayed login event as the player is not fully accessible pre login
P.p.getServer().getScheduler().runTaskLater(P.p, () -> login(player), 1L);
P.getScheduler().runTaskLater(() -> login(player), 1L);
}

// he may be having a hangover
Expand Down Expand Up @@ -573,7 +574,7 @@ public static void addPuke(Player player, int count) {
BUtil.reapplyPotionEffect(player, PotionEffectType.HUNGER.createEffect(80, 4), true);

if (pTasks.isEmpty()) {
taskId = P.p.getServer().getScheduler().scheduleSyncRepeatingTask(P.p, BPlayer::pukeTask, 1L, 1L);
task = P.getScheduler().runTaskTimer(P.p, BPlayer::pukeTask, 1L, 1L);
}
pTasks.put(player, event.getCount());
}
Expand All @@ -594,7 +595,7 @@ public static void pukeTask() {
}
}
if (pTasks.isEmpty()) {
P.p.getServer().getScheduler().cancelTask(taskId);
task.cancel();
}
}

Expand Down Expand Up @@ -673,7 +674,7 @@ public void drunkEffects(Player player) {
return;
}
for (PotionEffect effect : l) {
effect.apply(player);
P.getScheduler().runTask(player, () -> effect.apply(player));
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/com/dre/brewery/BSealer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dre.brewery;

import com.github.Anon8281.universalScheduler.scheduling.tasks.MyScheduledTask;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Sound;
Expand Down Expand Up @@ -30,7 +31,7 @@ public class BSealer implements InventoryHolder {
private final Player player;
private short[] slotTime = new short[9];
private ItemStack[] contents = null;
private BukkitTask task;
private MyScheduledTask task;

public BSealer(Player player) {
this.player = player;
Expand All @@ -56,7 +57,7 @@ public BSealer(Player player) {
public void clickInv() {
contents = null;
if (task == null) {
task = P.p.getServer().getScheduler().runTaskTimer(P.p, this::itemChecking, 1, 1);
task = P.getScheduler().runTaskTimer(P.p, this::itemChecking, 1, 1);
}
}

Expand Down
Loading