Skip to content

Commit

Permalink
Change folia to implement PaperCore vs BukkitCore.
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Jul 21, 2024
1 parent 1b1edc4 commit 63786bb
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 30 deletions.
10 changes: 8 additions & 2 deletions Folia/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@
</dependency>
<dependency>
<groupId>net.tnemc</groupId>
<artifactId>BukkitCore</artifactId>
<artifactId>Paper</artifactId>
<version>0.1.3.0-SNAPSHOT-11</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>net.tnemc</groupId>
<artifactId>TNML-Bukkit</artifactId>
<artifactId>TNML-Paper</artifactId>
</exclusion>
</exclusions>
</dependency>
Expand All @@ -222,6 +222,12 @@
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.tnemc</groupId>
<artifactId>Paper</artifactId>
<version>0.1.3.0-SNAPSHOT-11</version>
<scope>compile</scope>
</dependency>
</dependencies>

<parent>
Expand Down
10 changes: 5 additions & 5 deletions Folia/src/net/tnemc/folia/TNE.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import net.tnemc.bukkit.BukkitPlugin;
import net.tnemc.folia.impl.FoliaServerProvider;
import net.tnemc.paper.PaperPlugin;
import org.bukkit.plugin.java.JavaPlugin;

/**
Expand All @@ -30,20 +30,20 @@
*/
public class TNE extends JavaPlugin {

private final BukkitPlugin bukkit = new BukkitPlugin();
private final PaperPlugin paper = new PaperPlugin();

@Override
public void onLoad() {
this.bukkit.load(this, new FoliaServerProvider());
this.paper.load(this, new FoliaServerProvider());
}

@Override
public void onEnable() {
this.bukkit.enable(this);
this.paper.enable(this);
}

@Override
public void onDisable() {
this.bukkit.disable(this);
this.paper.disable(this);
}
}
8 changes: 4 additions & 4 deletions Folia/src/net/tnemc/folia/impl/FoliaPlayerProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
*/

import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.tnemc.bukkit.BukkitCore;
import net.tnemc.core.TNECore;
import net.tnemc.menu.folia.FoliaPlayer;
import net.tnemc.paper.PaperCore;
import net.tnemc.plugincore.core.compatibility.Location;
import net.tnemc.plugincore.core.compatibility.PlayerProvider;
import net.tnemc.plugincore.core.io.message.MessageData;
Expand All @@ -43,7 +43,7 @@ public class FoliaPlayerProvider extends FoliaPlayer implements PlayerProvider {
private final OfflinePlayer player;

public FoliaPlayerProvider(OfflinePlayer player) {
super(player, BukkitCore.instance().getPlugin());
super(player, PaperCore.instance().getPlugin());
this.player = player;
}

Expand Down Expand Up @@ -168,7 +168,7 @@ public void setExpLevel(int level) {

@Override
public FoliaInventoryProvider inventory() {
return new FoliaInventoryProvider(identifier(), BukkitCore.instance().getPlugin());
return new FoliaInventoryProvider(identifier(), PaperCore.instance().getPlugin());
}

/**
Expand Down Expand Up @@ -204,7 +204,7 @@ public void message(final MessageData messageData) {
return;
}

try(BukkitAudiences provider = BukkitAudiences.create(BukkitCore.instance().getPlugin())) {
try(BukkitAudiences provider = BukkitAudiences.create(PaperCore.instance().getPlugin())) {
MessageHandler.translate(messageData, player.getUniqueId(), provider.sender(player.getPlayer()));
}
}
Expand Down
19 changes: 9 additions & 10 deletions Folia/src/net/tnemc/folia/impl/FoliaServerProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@
*/

import com.destroystokyo.paper.profile.PlayerProfile;
import net.tnemc.bukkit.BukkitCore;
import net.tnemc.folia.impl.scheduler.FoliaScheduler;
import net.tnemc.item.AbstractItemStack;
import net.tnemc.item.bukkit.BukkitCalculationsProvider;
import net.tnemc.item.bukkit.BukkitItemStack;
import net.tnemc.item.paper.PaperCalculationsProvider;
import net.tnemc.paper.PaperCore;
import net.tnemc.plugincore.PluginCore;
import net.tnemc.plugincore.bukkit.BukkitPluginCore;
import net.tnemc.plugincore.bukkit.hook.PAPIParser;
import net.tnemc.plugincore.bukkit.impl.BukkitPlayerProvider;
import net.tnemc.plugincore.bukkit.impl.BukkitProxyProvider;
import net.tnemc.plugincore.core.compatibility.CmdSource;
import net.tnemc.plugincore.core.compatibility.PlayerProvider;
import net.tnemc.plugincore.core.compatibility.ProxyProvider;
import net.tnemc.plugincore.core.compatibility.ServerConnector;
import net.tnemc.plugincore.core.compatibility.helper.CraftingRecipe;
import net.tnemc.plugincore.core.compatibility.scheduler.SchedulerProvider;
import net.tnemc.plugincore.paper.impl.PaperProxyProvider;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand All @@ -61,8 +60,8 @@
*/
public class FoliaServerProvider implements ServerConnector {

private final BukkitCalculationsProvider calc = new BukkitCalculationsProvider();
private final BukkitProxyProvider proxy = new BukkitProxyProvider();
private final PaperCalculationsProvider calc = new PaperCalculationsProvider();
private final PaperProxyProvider proxy = new PaperProxyProvider();

private final FoliaScheduler scheduler;

Expand Down Expand Up @@ -266,7 +265,7 @@ public AbstractItemStack<?> stackBuilder() {

@Override
public void saveResource(String path, boolean replace) {
BukkitCore.instance().getPlugin().saveResource(path, replace);
PaperCore.instance().getPlugin().saveResource(path, replace);
}

@Override
Expand Down Expand Up @@ -296,7 +295,7 @@ public void registerCrafting(@NotNull final String key, @NotNull CraftingRecipe
ShapedRecipe shaped;

try {
shaped = new ShapedRecipe(new NamespacedKey(BukkitPluginCore.instance().getPlugin(), key), (ItemStack)recipe.getResult().locale());
shaped = new ShapedRecipe(new NamespacedKey(PaperCore.instance().getPlugin(), key), (ItemStack)recipe.getResult().locale());
} catch(Exception ignore) {
shaped = new ShapedRecipe((ItemStack)recipe.getResult().locale());
}
Expand All @@ -311,7 +310,7 @@ public void registerCrafting(@NotNull final String key, @NotNull CraftingRecipe
ShapelessRecipe shapeless;

try {
shapeless = new ShapelessRecipe(new NamespacedKey(BukkitPluginCore.instance().getPlugin(), key), (ItemStack)recipe.getResult().locale());
shapeless = new ShapelessRecipe(new NamespacedKey(PaperCore.instance().getPlugin(), key), (ItemStack)recipe.getResult().locale());
} catch(Exception ignore) {
shapeless = new ShapelessRecipe((ItemStack)recipe.getResult().locale());
}
Expand All @@ -324,7 +323,7 @@ public void registerCrafting(@NotNull final String key, @NotNull CraftingRecipe
}

@Override
public BukkitCalculationsProvider calculations() {
public PaperCalculationsProvider calculations() {
return calc;
}

Expand Down
6 changes: 3 additions & 3 deletions Folia/src/net/tnemc/folia/impl/scheduler/FoliaScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import net.tnemc.bukkit.BukkitCore;
import net.tnemc.paper.PaperCore;
import net.tnemc.plugincore.core.compatibility.scheduler.Chore;
import net.tnemc.plugincore.core.compatibility.scheduler.ChoreExecution;
import net.tnemc.plugincore.core.compatibility.scheduler.ChoreTime;
Expand All @@ -44,7 +44,7 @@ public class FoliaScheduler extends SchedulerProvider<FoliaChore> {
@Override
public void createDelayedTask(Runnable task, ChoreTime delay, ChoreExecution environment) {
//we divide the delay by 20 because Folia uses seconds, and the delay is sent in ticks.
Bukkit.getAsyncScheduler().runDelayed(BukkitCore.instance().getPlugin(), (scheduledTask) -> task.run(), delay.asSeconds(), TimeUnit.SECONDS);
Bukkit.getAsyncScheduler().runDelayed(PaperCore.instance().getPlugin(), (scheduledTask) -> task.run(), delay.asSeconds(), TimeUnit.SECONDS);
}

/**
Expand All @@ -60,7 +60,7 @@ public void createDelayedTask(Runnable task, ChoreTime delay, ChoreExecution env
@Override
public FoliaChore createRepeatingTask(Runnable task, ChoreTime delay, ChoreTime period, ChoreExecution environment) {
return new FoliaChore(Bukkit.getAsyncScheduler()
.runAtFixedRate(BukkitCore.instance().getPlugin(), (scheduledTask)->task.run(),
.runAtFixedRate(PaperCore.instance().getPlugin(), (scheduledTask)->task.run(),
delay.asSeconds(), period.asSeconds(), TimeUnit.SECONDS),
environment);
}
Expand Down
1 change: 0 additions & 1 deletion PaperCore/src/net/tnemc/paper/PaperCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import net.tnemc.bukkit.BukkitConfig;
import net.tnemc.bukkit.BukkitCore;
import net.tnemc.bukkit.BukkitItemCalculations;
import net.tnemc.bukkit.depend.faction.FactionHandler;
import net.tnemc.bukkit.depend.towny.TownyHandler;
Expand Down
1 change: 0 additions & 1 deletion PaperCore/src/net/tnemc/paper/PaperDebugCalculations.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import net.tnemc.item.data.ItemStorageData;
import net.tnemc.item.paper.PaperCalculationsProvider;
import net.tnemc.item.paper.PaperItemStack;
import net.tnemc.item.providers.CalculationsProvider;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
Expand Down
9 changes: 7 additions & 2 deletions PaperCore/src/net/tnemc/paper/PaperPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.tnemc.paper.hook.misc.PAPIHook;
import net.tnemc.paper.listener.PlayerInteractListener;
import net.tnemc.plugincore.PluginCore;
import net.tnemc.plugincore.core.compatibility.ServerConnector;
import net.tnemc.plugincore.paper.PaperPluginCore;
import net.tnemc.plugincore.paper.impl.PaperServerProvider;
import org.bstats.bukkit.Metrics;
Expand All @@ -52,15 +53,19 @@ public class PaperPlugin {
private PaperCore core;
private boolean papiHooked = false;

public void load(final JavaPlugin plugin) {
load(plugin, new PaperServerProvider(new PaperCalculationsProvider()));
}

/**
* Called when the plugin is loaded by the Bukkit plugin manager.
* This method should be used to initialize any necessary resources or data.
*/
public void load(final JavaPlugin plugin) {
public void load(final JavaPlugin plugin, ServerConnector provider) {

//Initialize our TNE Core Class
this.core = new PaperCore(plugin);
this.pluginCore = new PaperPluginCore(plugin, core, new PaperServerProvider(new PaperCalculationsProvider()), new BaseTranslationProvider(), new TNECallbackProvider());
this.pluginCore = new PaperPluginCore(plugin, core, provider, new BaseTranslationProvider(), new TNECallbackProvider());

//Vault
PluginCore.log().inform("Checking for VaultUnlocked");
Expand Down
1 change: 0 additions & 1 deletion PaperCore/src/net/tnemc/paper/hook/economy/VaultHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@


import net.milkbowl.vault.economy.Economy;
import net.tnemc.bukkit.BukkitCore;
import net.tnemc.core.hook.Hook;
import net.tnemc.paper.PaperCore;
import net.tnemc.plugincore.PluginCore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

import net.milkbowl.vault2.economy.Economy;
import net.tnemc.bukkit.BukkitCore;
import net.tnemc.core.hook.Hook;
import net.tnemc.paper.PaperCore;
import net.tnemc.plugincore.PluginCore;
Expand Down

0 comments on commit 63786bb

Please sign in to comment.