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 #1315

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ allprojects {
implementation 'com.sk89q:squirrelid:0.1.0'
implementation "io.papermc:paperlib:1.0.7"
implementation 'org.bstats:bstats-bukkit:2.2.1'
implementation 'com.github.Anon8281:UniversalScheduler:0.1.3'

testImplementation 'org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT'
testImplementation 'com.sk89q.worldedit:worldedit-core:7.2.14'
Expand Down Expand Up @@ -140,10 +141,12 @@ allprojects {
include(dependency('io.papermc:paperlib'))
include(dependency('com.sk89q:squirrelid'))
include(dependency("org.bstats:"))
include(dependency("com.github.Anon8281:UniversalScheduler"))
}
relocate 'org.bstats', 'com.sk89q.craftbook.bukkit.bstats'
relocate 'com.sk89q.squirrelid', 'com.sk89q.craftbook.util.profile'
relocate 'io.papermc.lib', 'com.sk89q.craftbook.bukkit.paperlib'
relocate 'com.github.Anon8281.universalScheduler', 'com.sk89q.craftbook.universalScheduler'
exclude 'GradleStart**'
exclude '.cache'
exclude 'LICENSE*'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.item.ItemType;
import io.papermc.lib.PaperLib;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -68,7 +69,7 @@ public boolean hasPermission(String perm) {
@Override
public void teleport(Location location) {

player.teleport(CraftBookBukkitUtil.toLocation(location));
PaperLib.teleportAsync(player, CraftBookBukkitUtil.toLocation(location));
}

@Override
Expand Down
31 changes: 21 additions & 10 deletions src/main/java/com/sk89q/craftbook/bukkit/CraftBookPlugin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.sk89q.craftbook.bukkit;

import com.github.Anon8281.universalScheduler.UniversalScheduler;
import com.github.Anon8281.universalScheduler.scheduling.schedulers.TaskScheduler;
import com.google.common.collect.Sets;
import com.sk89q.bukkit.util.CommandsManagerRegistration;
import com.sk89q.craftbook.CraftBookMechanic;
Expand Down Expand Up @@ -215,6 +217,11 @@ public class CraftBookPlugin extends JavaPlugin {
*/
private NMSAdapter nmsAdapter;

/**
* Universal scheduler
*/
private static TaskScheduler scheduler;

public static final Map<String, Class<? extends CraftBookMechanic>> availableMechanics;

public boolean useLegacyCartSystem = false;
Expand Down Expand Up @@ -347,7 +354,7 @@ public CraftBookMechanic getMechanic(Class<? extends CraftBookMechanic> clazz) {

/**
* Retrieve the UUID Mappings system of CraftBook.
*
*
* @return The UUID Mappings System.
*/
public UUIDMappings getUUIDMappings() {
Expand Down Expand Up @@ -384,6 +391,7 @@ public void setNmsAdapter(NMSAdapter nmsAdapter) {
public void onEnable() {

ItemSyntax.plugin = this;
scheduler = UniversalScheduler.getScheduler(this);

nmsAdapter = new NMSAdapter();

Expand Down Expand Up @@ -497,8 +505,7 @@ public void playerJoin(PlayerJoinEvent event) {
}

if(!foundAMech) {
Bukkit.getScheduler().runTaskTimer(this,
() -> getLogger().warning(ChatColor.RED + "Warning! You have no mechanics enabled, the plugin will appear to do nothing until a feature is enabled!"), 20L, 20*60*5);
CraftBookPlugin.getScheduler().runTaskTimer(() -> getLogger().warning(ChatColor.RED + "Warning! You have no mechanics enabled, the plugin will appear to do nothing until a feature is enabled!"), 20L, 20*60*5);
}

PaperLib.suggestPaper(this);
Expand All @@ -524,7 +531,7 @@ public void setupCraftBook() {
languageManager = new LanguageManager();
languageManager.init();

getServer().getScheduler().runTask(this, CompatabilityUtil::init);
getScheduler().runTask(CompatabilityUtil::init);

mechanics = new ArrayList<>();

Expand Down Expand Up @@ -598,7 +605,7 @@ public void setupCraftBook() {

/**
* Enables the mechanic with the specified name.
*
*
* @param mechanic The name of the mechanic.
* @return If the mechanic could be found and enabled.
*/
Expand Down Expand Up @@ -649,7 +656,7 @@ public boolean enableMechanic(String mechanic) {

/**
* Disables the mechanic with the specified name.
*
*
* @param mechanic The name of the mechanic.
* @return If the mechanic could be found and disabled.
*/
Expand Down Expand Up @@ -685,7 +692,7 @@ public void registerGlobalEvents() {
getServer().getPluginManager().registerEvents(managerAdapter, inst());

if(config.easterEggs) {
Bukkit.getScheduler().runTaskLater(this, new Runnable() {
CraftBookPlugin.getScheduler().runTaskLater(new Runnable() {

@Override
public void run () {
Expand Down Expand Up @@ -852,7 +859,7 @@ private void setupSelfTriggered() {

// Set up the clock for self-triggered ICs.

getServer().getScheduler().runTaskTimer(this, mechanicClock, 0, config.stThinkRate);
getScheduler().runTaskTimer(mechanicClock, 0, config.stThinkRate);

getServer().getPluginManager().registerEvents(selfTriggerManager, this);
}
Expand Down Expand Up @@ -1075,7 +1082,7 @@ public void reloadConfiguration() throws Throwable {
for(CraftBookMechanic mech : mechanics)
mech.disable();
mechanics = null;
getServer().getScheduler().cancelTasks(inst());
getScheduler().cancelTasks(inst());
HandlerList.unregisterAll(inst());

if(config.debugLogToFile) {
Expand Down Expand Up @@ -1240,7 +1247,7 @@ public void setPersistentStorage(PersistentStorage storage) {

/**
* Parses more advanced portions of the Item Syntax.
*
*
* @param item The item to parse
* @return The parsed string. (Can be the same, and should be if nothing found)
*/
Expand All @@ -1259,4 +1266,8 @@ public final String parseItemSyntax(String item) {
public static String getWikiDomain() {
return "https://craftbook.enginehub.org/en/3.x";
}

public static TaskScheduler getScheduler() {
return scheduler;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void onPlayerInteract(final PlayerInteractEvent event) {
return;
} else {
signClickTimer.add(event.getPlayer().getName());
Bukkit.getScheduler().runTaskLater(CraftBookPlugin.inst(), () -> signClickTimer.remove(event.getPlayer().getName()), CraftBookPlugin.inst().getConfiguration().signClickTimeout);
CraftBookPlugin.getScheduler().runTaskLater(() -> signClickTimer.remove(event.getPlayer().getName()), CraftBookPlugin.inst().getConfiguration().signClickTimeout);
}
}
SignClickEvent ev = new SignClickEvent(event.getPlayer(), action, event.getItem(), block, event.getBlockFace());
Expand Down Expand Up @@ -345,7 +345,7 @@ private static void handleDirectWireInput(int x, int y, int z, Block sourceBlock
CraftBookPlugin.inst().getServer().getPluginManager().callEvent(event);

if(CraftBookPlugin.inst().useLegacyCartSystem) {
CraftBookPlugin.server().getScheduler().runTask(CraftBookPlugin.inst(), () -> {
CraftBookPlugin.getScheduler().runTask(() -> {
try {
CartMechanismBlocks cmb = CartMechanismBlocks.find(event.getBlock());
CartBlockRedstoneEvent ev = new CartBlockRedstoneEvent(event.getBlock(), event.getSource(), event.getOldCurrent(), event.getNewCurrent(), cmb, CartBlockMechanism.getCart(cmb.rail));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void onChunkLoad(final ChunkLoadEvent event) {
if (!EventUtil.passesFilter(event))
return;

CraftBookPlugin.server().getScheduler().runTaskLater(CraftBookPlugin.inst(), () -> registerSelfTrigger(event.getChunk()), 2);
CraftBookPlugin.getScheduler().runTaskLater(() -> registerSelfTrigger(event.getChunk()), 2);
}

@EventHandler(priority = EventPriority.HIGH)
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/sk89q/craftbook/mechanics/BetterLeads.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ else if (typeName == null)
if(event.getRightClicked() instanceof Creature && ((Creature) event.getRightClicked()).getTarget() != null && ((Creature) event.getRightClicked()).getTarget().equals(event.getPlayer()))
((Creature) event.getRightClicked()).setTarget(null); //Rescan for a new target.
event.setCancelled(true);
Bukkit.getScheduler().runTask(CraftBookPlugin.inst(), () -> {
CraftBookPlugin.getScheduler().runTask(CraftBookPlugin.inst(), () -> {
if(!((LivingEntity) event.getRightClicked()).setLeashHolder(event.getPlayer())) {
CraftBookPlugin.logDebugMessage("Failed to leash entity!", "betterleads.allowed-mobs");
}
Expand Down Expand Up @@ -136,7 +136,7 @@ public void onHitchBreakRandomly(final HangingBreakEvent event) {

if(amountConnected == 0) {
//Still needs to be used by further plugins in the event. We wouldn't want bukkit complaining now, would we?
Bukkit.getScheduler().runTask(CraftBookPlugin.inst(), event.getEntity()::remove);
CraftBookPlugin.getScheduler().runTask(CraftBookPlugin.inst(), event.getEntity()::remove);
}
}

Expand Down Expand Up @@ -170,7 +170,7 @@ public void onHitchBreak(final HangingBreakByEntityEvent event) {

if(!leadsHitchPersists && amountConnected == 0) {
//Still needs to be used by further plugins in the event. We wouldn't want bukkit complaining now, would we?
Bukkit.getScheduler().runTask(CraftBookPlugin.inst(), event.getEntity()::remove);
CraftBookPlugin.getScheduler().runTask(CraftBookPlugin.inst(), event.getEntity()::remove);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void onBlockUpdate(BlockPhysicsEvent event) {

private static void checkForPhysics(Block block) {
if(FallingLadders.isValid(block)) {
Bukkit.getScheduler().runTask(CraftBookPlugin.inst(), new FallingLadders(block));
CraftBookPlugin.getScheduler().runTask(CraftBookPlugin.inst(), new FallingLadders(block));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Tag;
Expand Down Expand Up @@ -304,7 +305,7 @@ public void superSticky(final Block trigger, final Piston piston, final ChangedS
for (int p = 0; p < amount; p++) {
final int fp = p;

Bukkit.getScheduler().runTaskLater(CraftBookPlugin.inst(), () -> {
CraftBookPlugin.getScheduler().runTaskLater(() -> {
for (int x = 1; x <= fblock + 2; x++) {
int i = x;
if (x == 1 && !InventoryUtil.doesBlockHaveInventory(trigger.getRelative(piston.getFacing(), i)) && fp == 0) {
Expand All @@ -316,7 +317,7 @@ public void superSticky(final Block trigger, final Piston piston, final ChangedS
}
for (Entity ent : trigger.getRelative(piston.getFacing(), i).getChunk().getEntities()) {
if (EntityUtil.isEntityInBlock(ent, trigger.getRelative(piston.getFacing(), i))) {
ent.teleport(ent.getLocation().subtract(piston.getFacing().getModX() * movemod, piston.getFacing().getModY() * movemod, piston.getFacing().getModZ() * movemod));
PaperLib.teleportAsync(ent, ent.getLocation().subtract(piston.getFacing().getModX() * movemod, piston.getFacing().getModY() * movemod, piston.getFacing().getModZ() * movemod));
}
}
copyData(trigger.getRelative(piston.getFacing(), i + 1), trigger.getRelative(piston.getFacing(), i));
Expand All @@ -343,7 +344,7 @@ public void superPush(final Block trigger, final Piston piston, ChangedSign sign
final int fblock = block;

for (int p = 0; p < amount; p++) {
Bukkit.getScheduler().runTaskLater(CraftBookPlugin.inst(), () -> {
CraftBookPlugin.getScheduler().runTaskLater(() -> {
for (int x = fblock + 2; x >= 1; x--) {
Block offset = trigger.getRelative(piston.getFacing(), x);
Block next = trigger.getRelative(piston.getFacing(), x + 1);
Expand All @@ -352,7 +353,7 @@ public void superPush(final Block trigger, final Piston piston, ChangedSign sign
if (next.getType() == Material.AIR) {
for (Entity ent : next.getChunk().getEntities()) {
if (EntityUtil.isEntityInBlock(ent, offset)) {
ent.teleport(ent.getLocation().add(piston.getFacing().getModX() * movemod, piston.getFacing().getModY() * movemod, piston.getFacing().getModZ() * movemod));
PaperLib.teleportAsync(ent, ent.getLocation().add(piston.getFacing().getModX() * movemod, piston.getFacing().getModY() * movemod, piston.getFacing().getModZ() * movemod));
}
}
if(copyData(offset, next))
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/sk89q/craftbook/mechanics/BetterPlants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sk89q.craftbook.mechanics;

import com.github.Anon8281.universalScheduler.scheduling.tasks.MyScheduledTask;
import com.sk89q.craftbook.AbstractCraftBookMechanic;
import com.sk89q.craftbook.bukkit.CraftBookPlugin;
import com.sk89q.craftbook.util.BlockUtil;
Expand All @@ -24,14 +25,14 @@

public class BetterPlants extends AbstractCraftBookMechanic {

private BukkitTask growthTask;
private MyScheduledTask growthTask;

@Override
public boolean enable() {
if(fernFarming) {
tickedWorlds.addAll(Bukkit.getWorlds());

growthTask = Bukkit.getScheduler().runTaskTimer(CraftBookPlugin.inst(), new GrowthTicker(), 2L, 2L);
growthTask = CraftBookPlugin.getScheduler().runTaskTimer( new GrowthTicker(), 2L, 2L);
}

return fernFarming; //Only enable if a mech is enabled
Expand All @@ -54,7 +55,7 @@ public void onBlockBreak(final BlockBreakEvent event) {
&& ((Bisected) event.getBlock().getBlockData()).getHalf() == Bisected.Half.TOP
&& event.getBlock().getRelative(0, -1, 0).getType() == Material.LARGE_FERN
&& ((Bisected) event.getBlock().getRelative(0, -1, 0).getBlockData()).getHalf() == Bisected.Half.BOTTOM) {
Bukkit.getScheduler().runTaskLater(CraftBookPlugin.inst(), () -> {
CraftBookPlugin.getScheduler().runTaskLater(() -> {
event.getBlock().getWorld().dropItemNaturally(BlockUtil.getBlockCentre(event.getBlock()), new ItemStack(Material.FERN));
event.getBlock().getRelative(0, -1, 0).setType(Material.FERN);
}, 2L);
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/sk89q/craftbook/mechanics/Chair.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.sk89q.worldedit.world.block.BlockCategories;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.item.ItemTypes;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.attribute.Attribute;
Expand Down Expand Up @@ -96,9 +97,9 @@ private void addChair(final Player player, Block block, final Location chairLoc)
// Attach the player to said arrow.
final Entity far = ar;
if(ar.isEmpty() && isNew) {
Bukkit.getScheduler().runTask(CraftBookPlugin.inst(), () -> {
CraftBookPlugin.getScheduler().runTask(CraftBookPlugin.inst(), () -> {
if (chairLoc != null)
player.teleport(chairLoc);
PaperLib.teleportAsync(player, chairLoc);
far.addPassenger(player);
});
} else if (ar.isEmpty()) {
Expand All @@ -125,8 +126,8 @@ private void removeChair(final Player player) {
ent.eject();
player.eject();
ent.remove();
Bukkit.getScheduler().runTaskLater(CraftBookPlugin.inst(), () -> {
player.teleport(chairData.playerExitPoint);
CraftBookPlugin.getScheduler().runTaskLater(() -> {
PaperLib.teleportAsync(player, chairData.playerExitPoint);
player.setSneaking(false);
}, 5L);
}
Expand Down Expand Up @@ -290,7 +291,7 @@ public void run() {
if (p == null || p.isDead() || !p.isValid()) {
ChairData data = chairs.remove(pl.getKey());
if (data != null && data.chairEntity != null) {
Bukkit.getScheduler().runTaskLater(CraftBookPlugin.inst(), () -> {
CraftBookPlugin.getScheduler().runTaskLater(() -> {
data.chairEntity.eject();
data.chairEntity.remove();
}, 5);
Expand Down Expand Up @@ -328,7 +329,7 @@ public boolean enable () {

chairs = new ConcurrentHashMap<>();

Bukkit.getScheduler().runTaskTimer(CraftBookPlugin.inst(), new ChairChecker(), 20L, 20L);
CraftBookPlugin.getScheduler().runTaskTimer(new ChairChecker(), 20L, 20L);

try {
Class.forName("com.comphenix.protocol.events.PacketListener");
Expand Down
Loading