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

Repush Folia Support #815

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 0 additions & 2 deletions paper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ val mcVersion: String = providers.gradleProperty("mcVersion").get()
dependencies {
paperweight.paperDevBundle(libs.versions.bundle)

implementation(libs.metrics)

implementation(libs.nbtapi)

compileOnly(libs.placeholder.api)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.badbones69.crazyenchantments.paper.listeners.ProtectionCrystalListener;
import com.badbones69.crazyenchantments.paper.listeners.ShopListener;
import com.badbones69.crazyenchantments.paper.listeners.server.WorldSwitchListener;
import org.bstats.bukkit.Metrics;
import com.badbones69.crazyenchantments.paper.utils.Metrics;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter;
Expand Down Expand Up @@ -132,6 +132,9 @@ public void onEnable() {

@Override
public void onDisable() {
getServer().getGlobalRegionScheduler().cancelTasks(this);
getServer().getAsyncScheduler().cancelTasks(this);

this.bossBarController.removeAllBossBars();

if (this.armorEnchantments != null) this.armorEnchantments.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public void fireWork(Location loc, ArrayList<Color> colors) {

this.plugin.getFireworkDamageListener().addFirework(firework);

this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, firework::detonate, 2);
this.plugin.getServer().getRegionScheduler().runDelayed(this.plugin, loc, task -> firework.detonate(), 2);
}

public Enchantment getEnchantment(String enchantmentName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

public class CrazyManager {

Expand Down Expand Up @@ -162,9 +163,9 @@ public void load() {
if (playerHealthPatch) player.getAttribute(genericAttribute).setBaseValue(baseValue);

// Loop through all players & back them up.
this.plugin.getServer().getScheduler().runTaskTimerAsynchronously(this.plugin, task ->
this.plugin.getServer().getAsyncScheduler().runAtFixedRate(this.plugin, task ->
getCEPlayers().forEach(name ->
backupCEPlayer(name.getPlayer())), 5 * 20 * 60, 5 * 20 * 60);
backupCEPlayer(name.getPlayer())), 5, 5, TimeUnit.MINUTES);
});

// Invalidate cached enchants.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ private boolean isFirstEmpty(InventoryClickEvent event, Player player, ItemStack
public void onInvClose(final InventoryCloseEvent event) {
if (!(event.getInventory().getHolder() instanceof TinkererMenu holder)) return;

this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, () -> {
Player player = holder.getPlayer();
Player player = holder.getPlayer();
player.getScheduler().execute(this.plugin, () -> {

Inventory inventory = holder.getInventory();

Expand All @@ -216,7 +216,7 @@ public void onInvClose(final InventoryCloseEvent event) {

holder.getInventory().clear();
}
}, 0);
}, null, 0);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.badbones69.crazyenchantments.paper.api.managers;

import com.badbones69.crazyenchantments.paper.CrazyEnchantments;
import com.badbones69.crazyenchantments.paper.api.FileManager.Files;
import com.badbones69.crazyenchantments.paper.api.objects.AllyMob;
import com.badbones69.crazyenchantments.paper.api.objects.AllyMob.AllyType;
Expand All @@ -8,6 +9,9 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -16,6 +20,8 @@

public class AllyManager {

@NotNull
private final CrazyEnchantments plugin = JavaPlugin.getPlugin(CrazyEnchantments.class);
private final List<AllyMob> allyMobs = new ArrayList<>();
private final Map<UUID, List<AllyMob>> allyOwners = new HashMap<>();
private final Map<AllyType, String> allyTypeNameCache = new HashMap<>();
Expand Down Expand Up @@ -63,23 +69,31 @@ public void removeAllyMob(AllyMob allyMob) {

public void forceRemoveAllies() {
if (!this.allyMobs.isEmpty()) {
this.allyMobs.forEach(ally -> ally.getAlly().remove());
for (AllyMob ally : this.allyMobs) {
LivingEntity allyLE = ally.getAlly();
allyLE.getScheduler().run(plugin, task -> allyLE.remove(), null);
}
this.allyMobs.clear();
this.allyOwners.clear();
}
}

public void forceRemoveAllies(Player owner) {
for (AllyMob ally : this.allyOwners.getOrDefault(owner.getUniqueId(), new ArrayList<>())) {
ally.getAlly().remove();
this.allyMobs.remove(ally);
LivingEntity allyLE = ally.getAlly();
allyLE.getScheduler().run(plugin, task -> {
allyLE.remove();
this.allyMobs.remove(ally);
}, null);
}

this.allyOwners.remove(owner.getUniqueId());
}

public void setEnemy(Player owner, Entity enemy) {
this.allyOwners.getOrDefault(owner.getUniqueId(), new ArrayList<>()).forEach(ally -> ally.attackEnemy((LivingEntity) enemy));
this.allyOwners.getOrDefault(owner.getUniqueId(), new ArrayList<>()).forEach(ally -> {
ally.getAlly().getScheduler().run(plugin, task -> ally.attackEnemy((LivingEntity) enemy), null);
});
}

public Map<AllyType, String> getAllyTypeNameCache() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.badbones69.crazyenchantments.paper.api.FileManager.Files;
import com.badbones69.crazyenchantments.paper.api.enums.CEnchantments;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
Expand All @@ -22,7 +22,7 @@ public class WingsManager {
private final List<String> limitlessFlightWorlds = new ArrayList<>();
private boolean ownersCanFly;
private boolean membersCanFly;
private BukkitTask wingsTask;
private ScheduledTask wingsTask;

public void load() {
this.isWingsEnabled = CEnchantments.WINGS.isActivated();
Expand Down Expand Up @@ -136,7 +136,7 @@ public boolean canMembersFly() {
return this.membersCanFly;
}

public void setWingsTask(BukkitTask task) {
public void setWingsTask(ScheduledTask task) {
endWingsTask();
this.wingsTask = task;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.badbones69.crazyenchantments.paper.CrazyEnchantments;
import com.badbones69.crazyenchantments.paper.api.enums.Messages;
import com.badbones69.crazyenchantments.paper.api.managers.AllyManager;
import com.badbones69.crazyenchantments.paper.scheduler.FoliaRunnable;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import org.bukkit.Location;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Bee;
Expand All @@ -15,8 +17,6 @@
import org.bukkit.entity.Wolf;
import org.bukkit.entity.Zombie;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;

Expand All @@ -34,7 +34,7 @@ public class AllyMob {

private LivingEntity ally;
private long spawnTime;
private BukkitTask runnable;
private ScheduledTask runnable;

public AllyMob(Player owner, AllyType type) {
this.type = type;
Expand Down Expand Up @@ -86,48 +86,50 @@ public void forceRemoveAlly() {
}

public void attackEnemy(LivingEntity enemy) {
switch (this.ally.getType()) {
case WOLF -> {
Wolf wolf = (Wolf) this.ally;
wolf.setTarget(enemy);
}
this.ally.getScheduler().run(this.plugin, task -> {
switch (this.ally.getType()) {
case WOLF -> {
Wolf wolf = (Wolf) this.ally;
wolf.setTarget(enemy);
}

case IRON_GOLEM -> {
IronGolem iron = (IronGolem) this.ally;
iron.setTarget(enemy);
}
case IRON_GOLEM -> {
IronGolem iron = (IronGolem) this.ally;
iron.setTarget(enemy);
}

case ZOMBIE -> {
Zombie zom = (Zombie) this.ally;
zom.setTarget(enemy);
}
case ZOMBIE -> {
Zombie zom = (Zombie) this.ally;
zom.setTarget(enemy);
}

case ENDERMITE -> {
Endermite mite = (Endermite) this.ally;
mite.setTarget(enemy);
}
case ENDERMITE -> {
Endermite mite = (Endermite) this.ally;
mite.setTarget(enemy);
}

case SILVERFISH -> {
Silverfish sfish = (Silverfish) this.ally;
sfish.setTarget(enemy);
}
case SILVERFISH -> {
Silverfish sfish = (Silverfish) this.ally;
sfish.setTarget(enemy);
}

case BEE -> {
Bee bee = (Bee) this.ally;
bee.setTarget(enemy);
case BEE -> {
Bee bee = (Bee) this.ally;
bee.setTarget(enemy);
}
}
}
}, null);
}

private void startSpawnTimer() {
if (this.ally != null) {
this.runnable = new BukkitRunnable() {
this.runnable = new FoliaRunnable(this.ally.getScheduler(), null) {
@Override
public void run() {
allyManager.removeAllyMob(instance);
ally.remove();
}
}.runTaskLater(this.plugin, this.spawnTime * 20);
}.runDelayed(this.plugin, this.spawnTime * 20);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import com.badbones69.crazyenchantments.paper.api.enums.CEnchantments;
import com.badbones69.crazyenchantments.paper.api.objects.gkitz.GKitz;
import com.badbones69.crazyenchantments.paper.api.objects.gkitz.GkitCoolDown;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

//todo() register gkit permissions
public class CEPlayer {
Expand All @@ -31,7 +31,7 @@ public class CEPlayer {
private Double rageMultiplier;
private boolean hasRage;
private int rageLevel;
private BukkitTask rageTask;
private ScheduledTask rageTask;
private final Set<CEnchantments> onCooldown = new HashSet<>();

/**
Expand Down Expand Up @@ -253,15 +253,15 @@ public void setRageLevel(int rageLevel) {
/**
* Get the cooldown task the player's rage has till they calm down.
*/
public BukkitTask getRageTask() {
public ScheduledTask getRageTask() {
return this.rageTask;
}

/**
* Set the new cooldown task for the player's rage.
* @param rageTask The new cooldown task for the player.
*/
public void setRageTask(BukkitTask rageTask) {
public void setRageTask(ScheduledTask rageTask) {
this.rageTask = rageTask;
}

Expand All @@ -277,7 +277,7 @@ public boolean onEnchantCooldown(CEnchantments enchant, int delay) {

this.onCooldown.add(enchant);
// Limit players to using each enchant only once per second.
this.plugin.getServer().getScheduler().runTaskLaterAsynchronously(this.plugin, () -> this.onCooldown.remove(enchant), delay);
this.plugin.getServer().getAsyncScheduler().runDelayed(this.plugin, (task) -> this.onCooldown.remove(enchant), delay * 50L, TimeUnit.MILLISECONDS);

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void spawnWebs(Entity hitEntity, EnchantedArrow enchantedArrow, Arrow arr

arrow.remove();

this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () -> {
this.plugin.getServer().getRegionScheduler().runDelayed(this.plugin, entityLocation, scheduledTask -> {
entityLocation.getBlock().setType(Material.AIR);
webBlocks.remove(entityLocation.getBlock());
}, 5 * 20);
Expand All @@ -127,18 +127,20 @@ public void spawnWebs(Entity hitEntity, EnchantedArrow enchantedArrow, Arrow arr
}

private void setWebBlocks(Entity hitEntity) {
for (Block block : getCube(hitEntity.getLocation())) {

block.setType(Material.COBWEB);
this.webBlocks.add(block);

this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () -> {
if (block.getType() == Material.COBWEB) {
block.setType(Material.AIR);
webBlocks.remove(block);
}
}, 5 * 20);
}
this.plugin.getServer().getRegionScheduler().execute(this.plugin, hitEntity.getLocation(), () -> {
for (Block block : getCube(hitEntity.getLocation())) {

block.setType(Material.COBWEB);
this.webBlocks.add(block);

this.plugin.getServer().getRegionScheduler().runDelayed(this.plugin, block.getLocation(), scheduledTask -> {
if (block.getType() == Material.COBWEB) {
block.setType(Material.AIR);
webBlocks.remove(block);
}
}, 5 * 20);
}
});
}

// Sticky Shot End!
Expand Down
Loading