Skip to content
Closed
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
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@
<include>com.github.broken1arrow.Utility-Library:serialize-utility*</include>
<include>com.github.broken1arrow.Utility-Library:color-conversion*</include>
<include>com.github.broken1arrow.Utility-Library:log-and-validate*</include>
<include>space.arim.morepaperlib:morepaperlib*</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.broken.arrow</pattern>
<shadedPattern>${dependencys_path}</shadedPattern>
</relocation>
<relocation>
<pattern>space.arim.morepaperlib</pattern>
<shadedPattern>${dependencys_path}</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
Expand Down Expand Up @@ -85,6 +90,11 @@
<url>https://repo.codemc.io/repository/maven-public/</url>
<layout>default</layout>
</repository>
<!-- MorePaperLib-->
<repository>
<id>arim-mvn-lgpl3</id>
<url>https://mvn-repo.arim.space/lesser-gpl3/</url>
</repository>
</repositories>
<dependencies>
<dependency>
Expand Down Expand Up @@ -140,6 +150,13 @@
<version>2.10.1</version>
<scope>compile</scope>
</dependency>
<!-- MorePaperLib -->
<dependency>
<groupId>space.arim.morepaperlib</groupId>
<artifactId>morepaperlib</artifactId>
<version>0.4.3</version>
<scope>compile</scope>
</dependency>
<!--<dependency>-->
<!--<groupId>dev.lone</groupId>-->
<!--<artifactId>api-itemsadder</artifactId>-->
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/dutchjelly/bukkitadapter/Adapter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dutchjelly.bukkitadapter;


import com.dutchjelly.craftenhance.CraftEnhance;
import com.dutchjelly.craftenhance.crafthandling.recipes.FurnaceRecipe;
import com.dutchjelly.craftenhance.exceptions.ConfigError;
import com.dutchjelly.craftenhance.gui.util.SkullCreator;
Expand Down Expand Up @@ -324,12 +325,12 @@ public static void DiscoverRecipes(final Player player, final List<Recipe> recip
if (recipe instanceof ShapedRecipe) {
final ShapedRecipe shaped = (ShapedRecipe) recipe;;
if (shaped.getKey().getNamespace().contains("craftenhance")) {
player.discoverRecipe(shaped.getKey());
CraftEnhance.getMorePaperLib().scheduling().entitySpecificScheduler(player).run(() -> player.discoverRecipe(shaped.getKey()), null);
}
} else if (recipe instanceof ShapelessRecipe) {
final ShapelessRecipe shapeless = (ShapelessRecipe) recipe;
if (shapeless.getKey().getNamespace().contains("craftenhance")) {
player.discoverRecipe(shapeless.getKey());
CraftEnhance.getMorePaperLib().scheduling().entitySpecificScheduler(player).run(() -> player.discoverRecipe(shapeless.getKey()), null);
}
}
}
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/com/dutchjelly/craftenhance/CraftEnhance.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import space.arim.morepaperlib.MorePaperLib;

import java.io.File;
import java.util.Arrays;
Expand All @@ -62,7 +63,9 @@ public static CraftEnhance self() {
return plugin;
}

private Metrics metrics;
private Metrics metrics;
@Getter
private static MorePaperLib morePaperLib;
@Getter
private FileManager fm;
@Getter
Expand All @@ -89,6 +92,7 @@ public static CraftEnhance self() {
@Override
public void onEnable() {
plugin = this;
morePaperLib = new MorePaperLib(this);
//The file manager needs serialization, so firstly register the classes.
registerSerialization();
versionChecker = VersionChecker.init(this);
Expand All @@ -99,7 +103,7 @@ public void onEnable() {
Debug.init(this);

if (isReloding)
Bukkit.getScheduler().runTaskAsynchronously(this, () -> loadPluginData(isReloding));
CraftEnhance.getMorePaperLib().scheduling().asyncScheduler().run(() -> loadPluginData(isReloding));
else {
this.loadPluginData(false);
loadRecipes();
Expand All @@ -117,7 +121,7 @@ public void onEnable() {
for (int i = 0; i < 4; i++)
Messenger.Message("WARN: The installed version isn't tested to work with this version of the server.");
}
Bukkit.getScheduler().runTaskAsynchronously(this, versionChecker::runUpdateCheck);
CraftEnhance.getMorePaperLib().scheduling().asyncScheduler().run(versionChecker::runUpdateCheck);

if (metrics == null) {
final int metricsId = 9023;
Expand All @@ -129,9 +133,9 @@ public void onEnable() {

public void reload() {
isReloding = true;
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
CraftEnhance.getMorePaperLib().scheduling().asyncScheduler().run(() -> {
this.onDisable();
Bukkit.getScheduler().runTask(this, () -> {
CraftEnhance.getMorePaperLib().scheduling().globalRegionalScheduler().run(() -> {
RecipeLoader.clearInstance();
reloadConfig();
this.onEnable();
Expand Down Expand Up @@ -241,7 +245,7 @@ private void loadPluginData(final Boolean isReloding) {
menuSettingsCache = new MenuSettingsCache(this);

if (isReloding)
Bukkit.getScheduler().runTask(this, this::loadRecipes);
CraftEnhance.getMorePaperLib().scheduling().globalRegionalScheduler().run(this::loadRecipes);
}

private void loadRecipes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void handleCrafting(final PrepareItemCraftEvent craftEvent) {
Debug.Send(Type.Crafting, "Recipe matches, injecting " + wbRecipe.getResult().toString());
if (makeItemsadderCompatible && containsModeldata(inv)) {
Debug.Send(Type.Crafting, "This recipe contains Modeldata and will be crafted if the recipe is not cancelled.");
Bukkit.getScheduler().runTask(self(), () -> {
CraftEnhance.getMorePaperLib().scheduling().globalRegionalScheduler().run(() -> {
if (wbRecipe.matches(inv.getMatrix())) {
final BeforeCraftOutputEvent beforeCraftOutputEvent = new BeforeCraftOutputEvent(eRecipe, wbRecipe, wbRecipe.getResult().clone());
if (beforeCraftOutputEvent.isCancelled()) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/dutchjelly/craftenhance/gui/GuiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public boolean chatWaiting(final AsyncPlayerChatEvent e){
final UUID id = e.getPlayer().getUniqueId();
if (!chatWaitingCopy.containsKey(id)) return false;

Bukkit.getScheduler().runTask(getMain(), () -> {
CraftEnhance.getMorePaperLib().scheduling().globalRegionalScheduler().run(() -> {
final IChatInputHandler callback = chatWaitingCopy.get(id).getSecond();
if (callback.handle(e.getMessage())) return;
final MenuHolder gui = chatWaitingCopy.get(id).getFirst();
Expand All @@ -109,14 +109,14 @@ public boolean chatWaitingOld(final AsyncPlayerChatEvent e){
final UUID id = e.getPlayer().getUniqueId();
if (!chatWaiting.containsKey(id)) return false;

Bukkit.getScheduler().runTask(getMain(), () -> {
CraftEnhance.getMorePaperLib().scheduling().entitySpecificScheduler(e.getPlayer()).run(() -> {
final IChatInputHandler callback = chatWaiting.get(id).getSecond();
if (callback.handle(e.getMessage())) return;
final GUIElement gui = chatWaiting.get(id).getFirst();
if (gui != null)
openGUI(e.getPlayer(), gui);
chatWaiting.remove(id);
});
}, null);
return true;
}
public void openGUI(final Player p, final GUIElement gui) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void handleEventRest(InventoryClickEvent e) {
}

Debug.Send("player clicked inside recipe content");
Bukkit.getScheduler().runTask(CraftEnhance.self(), () -> {
CraftEnhance.getMorePaperLib().scheduling().globalRegionalScheduler().run(() -> {
//Call event in next tick (after the click has finished)
Bukkit.getServer().getPluginManager().callEvent(new CustomPrepareCraftEvent(this));
});
Expand Down Expand Up @@ -208,9 +208,8 @@ public void handleDragging(InventoryDragEvent e){

if(e.getRawSlots().size() == validDrags.size()){
if(updatedMatrix)
Bukkit.getScheduler().runTask(CraftEnhance.self(), () ->
Bukkit.getServer().getPluginManager().callEvent(new CustomPrepareCraftEvent(this))
);
CraftEnhance.getMorePaperLib().scheduling().globalRegionalScheduler().run(() ->
Bukkit.getServer().getPluginManager().callEvent(new CustomPrepareCraftEvent(this)));
return;
}

Expand Down Expand Up @@ -242,10 +241,10 @@ public void handleDragging(InventoryDragEvent e){
Debug.Send("player dropped " + dropped + " item");
ItemStack newCursor = e.getOldCursor().clone();
if(dropped == newCursor.getAmount())
Bukkit.getScheduler().runTask(CraftEnhance.self(), () -> e.getView().setCursor(null));
CraftEnhance.getMorePaperLib().scheduling().entitySpecificScheduler(e.getWhoClicked()).run(() -> e.getView().setCursor(null), null);
else {
newCursor.setAmount(newCursor.getAmount() - dropped);
Bukkit.getScheduler().runTask(CraftEnhance.self(), () -> e.getView().setCursor(newCursor));
CraftEnhance.getMorePaperLib().scheduling().entitySpecificScheduler(e.getWhoClicked()).run(() -> e.getView().setCursor(newCursor), null);
}

if(updatedMatrix){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dutchjelly.craftenhance.gui.guis;

import com.dutchjelly.bukkitadapter.Adapter;
import com.dutchjelly.craftenhance.CraftEnhance;
import com.dutchjelly.craftenhance.files.CategoryData;
import com.dutchjelly.craftenhance.files.MenuSettingsCache;
import com.dutchjelly.craftenhance.gui.guis.editors.RecipesViewerCategorysSettings;
Expand All @@ -20,6 +21,7 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
Expand Down Expand Up @@ -94,7 +96,7 @@ public boolean run(final MenuButtonData value, final Inventory menu, final Playe
final CategoryData newCategoryData = self().getCategoryDataCache().of(this.category, new ItemStack(itemStack), categoryData.getDisplayName());
newCategoryData.setEnhancedRecipes(categoryData.getEnhancedRecipes());
self().getCategoryDataCache().put(this.category, newCategoryData);
Bukkit.getScheduler().runTaskLaterAsynchronously( self(),()-> self().getCategoryDataCache().save(),1L);
CraftEnhance.getMorePaperLib().scheduling().asyncScheduler().runDelayed(() -> self().getCategoryDataCache().save(), Duration.ofMillis(50L));
new RecipesViewerCategorysSettings(this.category).menuOpen(player);
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dutchjelly.craftenhance.gui.guis.editors;

import com.dutchjelly.bukkitadapter.Adapter;
import com.dutchjelly.craftenhance.CraftEnhance;
import com.dutchjelly.craftenhance.crafthandling.recipes.EnhancedRecipe;
import com.dutchjelly.craftenhance.files.CategoryData;
import com.dutchjelly.craftenhance.files.MenuSettingsCache;
Expand All @@ -20,6 +21,7 @@
import org.bukkit.inventory.ItemStack;

import javax.annotation.Nonnull;
import java.time.Duration;
import java.util.List;
import java.util.Map.Entry;

Expand Down Expand Up @@ -89,7 +91,7 @@ public boolean run(final MenuButtonData value, final Inventory menu, final Playe
self().getCategoryDataCache().put(defaultCategory, oldCategory);
}
self().getCategoryDataCache().remove((this.category));
Bukkit.getScheduler().runTaskLaterAsynchronously(self(), () -> self().getCategoryDataCache().save(), 1);
CraftEnhance.getMorePaperLib().scheduling().asyncScheduler().runDelayed(() -> self().getCategoryDataCache().save(), Duration.ofMillis(50));
new RecipesViewerCategorys("").menuOpen(player);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dutchjelly.craftenhance.gui.guis.settings;

import com.dutchjelly.bukkitadapter.Adapter;
import com.dutchjelly.craftenhance.CraftEnhance;
import com.dutchjelly.craftenhance.crafthandling.recipes.EnhancedRecipe;
import com.dutchjelly.craftenhance.crafthandling.recipes.FurnaceRecipe;
import com.dutchjelly.craftenhance.crafthandling.recipes.WBRecipe;
Expand Down Expand Up @@ -128,7 +129,7 @@ public boolean run(final MenuButtonData value, final Inventory menu, final Playe
if (player.isConversing()) return true;
new HandleChatInput(this, message -> {
if (!this.handleSetWorld(message, click)) {
this.runTask(() -> this.menuOpen(player));
this.runTask(() -> this.menuOpen(player), player);
return false;
}
return true;
Expand Down Expand Up @@ -159,7 +160,7 @@ public boolean run(final MenuButtonData value, final Inventory menu, final Playe
if (player.isConversing()) return true;
new HandleChatInput(this, msg -> {
if (!handlePermissionSetCB(msg)) {
this.runTask(() -> this.menuOpen(player));
this.runTask(() -> this.menuOpen(player), player);
return false;
}
return true;
Expand All @@ -173,7 +174,7 @@ public boolean run(final MenuButtonData value, final Inventory menu, final Playe
if (player.isConversing()) return true;
new HandleChatInput(this, msg -> {
if (!GuiUtil.changeOrCreateCategory(msg, player, this.recipe)) {
this.runTask(() -> this.menuOpen(player));
this.runTask(() -> this.menuOpen(player), player);
return false;
}
return true;
Expand Down Expand Up @@ -358,8 +359,8 @@ public Map<String, String> setPlaceholders() {
return placeholders;
}

protected void runTask(final Runnable runnable) {
Bukkit.getScheduler().runTaskLater(self(), runnable, 1);
protected void runTask(final Runnable runnable, Player player) {
CraftEnhance.getMorePaperLib().scheduling().entitySpecificScheduler(player).runDelayed(runnable, null, 1);
}

protected boolean onPlayerClick(final RecipeT recipe, final String buttonAction, final Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected boolean onPlayerClick(final BlastRecipe blastRecipe, final String butt
new HandleChatInput(this, msg -> {
int parsed;
if (msg.equals("cancel") || msg.equals("quit") || msg.equals("exit")) {
this.runTask(() -> this.menuOpen(player));
this.runTask(() -> this.menuOpen(player), player);
return false;
}
try {
Expand All @@ -39,7 +39,7 @@ protected boolean onPlayerClick(final BlastRecipe blastRecipe, final String butt
if (blastRecipe != null) {
blastRecipe.setExp(parsed);
}
this.runTask(() -> this.menuOpen(player));
this.runTask(() -> this.menuOpen(player), player);
return false;
}).setMessages("Please input an exp amount.Type q, exit, cancel to turn it off.").start(getViewer());
return true;
Expand All @@ -49,7 +49,7 @@ protected boolean onPlayerClick(final BlastRecipe blastRecipe, final String butt
new HandleChatInput(this, (msg) -> {
short parsed;
if (msg.equals("cancel") || msg.equals("quit") || msg.equals("exit") || msg.equals("q")) {
this.runTask(() -> this.menuOpen(player));
this.runTask(() -> this.menuOpen(player), player);
return false;
}
try {
Expand All @@ -63,7 +63,7 @@ protected boolean onPlayerClick(final BlastRecipe blastRecipe, final String butt
if (blastRecipe != null) {
blastRecipe.setDuration(parsed);
}
this.runTask(() -> this.menuOpen(player));
this.runTask(() -> this.menuOpen(player), player);
return false;
}).setMessages("Please input a cook duration.Type q, exit, cancel to turn it off.").start(player);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected boolean onPlayerClick(final FurnaceRecipe furnaceRecipe, final String
new HandleChatInput(this, msg -> {
int parsed;
if (msg.equals("cancel") || msg.equals("quit") || msg.equals("exit")) {
this.runTask(() -> this.menuOpen(player));
this.runTask(() -> this.menuOpen(player), player);
return false;
}
try {
Expand All @@ -39,7 +39,7 @@ protected boolean onPlayerClick(final FurnaceRecipe furnaceRecipe, final String
if (furnaceRecipe != null) {
furnaceRecipe.setExp(parsed);
}
this.runTask(() -> this.menuOpen(player));
this.runTask(() -> this.menuOpen(player), player);
return false;
}).setMessages("Please input an exp amount.Type q, exit, cancel to turn it off.").start(getViewer());
return true;
Expand All @@ -49,7 +49,7 @@ protected boolean onPlayerClick(final FurnaceRecipe furnaceRecipe, final String
new HandleChatInput(this, (msg) -> {
short parsed;
if (msg.equals("cancel") || msg.equals("quit") || msg.equals("exit") || msg.equals("q")) {
this.runTask(() -> this.menuOpen(player));
this.runTask(() -> this.menuOpen(player), player);
return false;
}
try {
Expand All @@ -63,7 +63,7 @@ protected boolean onPlayerClick(final FurnaceRecipe furnaceRecipe, final String
if (furnaceRecipe != null) {
furnaceRecipe.setDuration(parsed);
}
this.runTask(() -> this.menuOpen(player));
this.runTask(() -> this.menuOpen(player), player);
return false;
}).setMessages("Please input a cook duration.Type q, exit, cancel to turn it off.").start(player);
return true;
Expand Down
Loading