Skip to content

Commit 85620b6

Browse files
committed
feat: use folialib
1 parent 68fa239 commit 85620b6

File tree

10 files changed

+128
-118
lines changed

10 files changed

+128
-118
lines changed

examples/paper/src/main/java/me/devnatan/inventoryframework/runtime/SamplePlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import me.devnatan.inventoryframework.ViewFrame;
55
import me.devnatan.inventoryframework.runtime.commands.IFExampleCommandExecutor;
66
import me.devnatan.inventoryframework.runtime.listener.PigListener;
7+
import me.devnatan.inventoryframework.runtime.view.*;
78
import me.devnatan.inventoryframework.runtime.view.AnvilInputSample;
89
import me.devnatan.inventoryframework.runtime.view.AutoUpdate;
910
import me.devnatan.inventoryframework.runtime.view.Failing;
1011
import me.devnatan.inventoryframework.runtime.view.SimplePagination;
11-
import me.devnatan.inventoryframework.runtime.view.*;
1212
import org.bukkit.plugin.java.JavaPlugin;
1313

1414
public class SamplePlugin extends JavaPlugin {

inventory-framework-api/src/main/java/me/devnatan/inventoryframework/context/IFSlotClickContext.java

Lines changed: 95 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -13,99 +13,99 @@
1313
*/
1414
public interface IFSlotClickContext extends IFSlotContext, IFConfinedContext {
1515

16-
// TODO needs documentation
17-
@NotNull
18-
ViewContainer getClickedContainer();
19-
20-
Component getComponent();
21-
22-
int getClickedSlot();
23-
24-
/**
25-
* If the click was using the left mouse button.
26-
*
27-
* @return If the click was using the left mouse button.
28-
*/
29-
boolean isLeftClick();
30-
31-
/**
32-
* If the click was using the right mouse button.
33-
*
34-
* @return If the click was using the right mouse button.
35-
*/
36-
boolean isRightClick();
37-
38-
/**
39-
* If the click was using the middle mouse button, commonly known as the scroll button.
40-
*
41-
* @return If the click was using the middle mouse button.
42-
*/
43-
boolean isMiddleClick();
44-
45-
/**
46-
* If the click was accompanied by a click holding the keyboard shift button.
47-
*
48-
* @return If it was a click holding the keyboard shift button.
49-
*/
50-
boolean isShiftClick();
51-
52-
default boolean isShiftLeftClick() {
53-
return isLeftClick() && isShiftClick();
54-
}
55-
56-
default boolean isShiftRightClick() {
57-
return isRightClick() && isShiftClick();
58-
}
59-
60-
/**
61-
* If the click source came from a keyboard, e.g. the player's toolbar number.
62-
*
63-
* @return If the click source came from a keyboard.
64-
*/
65-
boolean isKeyboardClick();
66-
67-
/**
68-
* If the click did not occur within any containers.
69-
*
70-
* @return If the click did not occur within any containers.
71-
*/
72-
boolean isOutsideClick();
73-
74-
/**
75-
* The click identifier, available only in cases where the library does not cover all types of
76-
* clicks, so you can discover the type of click through its identifier.
77-
*
78-
* @return The click type identifier. Can be null if the click type is known or a platform doesn't implement an identifier.
79-
*/
80-
default String getClickIdentifier() {
81-
return null;
82-
}
83-
84-
/**
85-
* If the click was cancelled.
86-
*
87-
* @return If the click was cancelled.
88-
*/
89-
boolean isCancelled();
90-
91-
/**
92-
* Cancels the click.
93-
*
94-
* @param cancelled If the click should be cancelled.
95-
*/
96-
void setCancelled(boolean cancelled);
97-
98-
/**
99-
* <b><i> This is an internal inventory-framework API that should not be used from outside of
100-
* this library. No compatibility guarantees are provided. </i></b>
101-
*/
102-
@ApiStatus.Internal
103-
Object getPlatformEvent();
104-
105-
/**
106-
* <b><i> This is an internal inventory-framework API that should not be used from outside of
107-
* this library. No compatibility guarantees are provided. </i></b>
108-
*/
109-
@ApiStatus.Internal
110-
boolean isCombined();
16+
// TODO needs documentation
17+
@NotNull
18+
ViewContainer getClickedContainer();
19+
20+
Component getComponent();
21+
22+
int getClickedSlot();
23+
24+
/**
25+
* If the click was using the left mouse button.
26+
*
27+
* @return If the click was using the left mouse button.
28+
*/
29+
boolean isLeftClick();
30+
31+
/**
32+
* If the click was using the right mouse button.
33+
*
34+
* @return If the click was using the right mouse button.
35+
*/
36+
boolean isRightClick();
37+
38+
/**
39+
* If the click was using the middle mouse button, commonly known as the scroll button.
40+
*
41+
* @return If the click was using the middle mouse button.
42+
*/
43+
boolean isMiddleClick();
44+
45+
/**
46+
* If the click was accompanied by a click holding the keyboard shift button.
47+
*
48+
* @return If it was a click holding the keyboard shift button.
49+
*/
50+
boolean isShiftClick();
51+
52+
default boolean isShiftLeftClick() {
53+
return isLeftClick() && isShiftClick();
54+
}
55+
56+
default boolean isShiftRightClick() {
57+
return isRightClick() && isShiftClick();
58+
}
59+
60+
/**
61+
* If the click source came from a keyboard, e.g. the player's toolbar number.
62+
*
63+
* @return If the click source came from a keyboard.
64+
*/
65+
boolean isKeyboardClick();
66+
67+
/**
68+
* If the click did not occur within any containers.
69+
*
70+
* @return If the click did not occur within any containers.
71+
*/
72+
boolean isOutsideClick();
73+
74+
/**
75+
* The click identifier, available only in cases where the library does not cover all types of
76+
* clicks, so you can discover the type of click through its identifier.
77+
*
78+
* @return The click type identifier. Can be null if the click type is known or a platform doesn't implement an identifier.
79+
*/
80+
default String getClickIdentifier() {
81+
return null;
82+
}
83+
84+
/**
85+
* If the click was cancelled.
86+
*
87+
* @return If the click was cancelled.
88+
*/
89+
boolean isCancelled();
90+
91+
/**
92+
* Cancels the click.
93+
*
94+
* @param cancelled If the click should be cancelled.
95+
*/
96+
void setCancelled(boolean cancelled);
97+
98+
/**
99+
* <b><i> This is an internal inventory-framework API that should not be used from outside of
100+
* this library. No compatibility guarantees are provided. </i></b>
101+
*/
102+
@ApiStatus.Internal
103+
Object getPlatformEvent();
104+
105+
/**
106+
* <b><i> This is an internal inventory-framework API that should not be used from outside of
107+
* this library. No compatibility guarantees are provided. </i></b>
108+
*/
109+
@ApiStatus.Internal
110+
boolean isCombined();
111111
}

inventory-framework-platform-bukkit/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ dependencies {
1717
testRuntimeOnly(libs.spigot)
1818
testImplementation(projects.inventoryFrameworkApi)
1919
testImplementation(projects.inventoryFrameworkTest)
20+
implementation(libs.folialib)
2021
}
2122

2223
tasks.shadowJar {

inventory-framework-platform-bukkit/src/main/java/me/devnatan/inventoryframework/ViewFrame.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ public class ViewFrame extends IFViewFrame<ViewFrame, View> {
3838
private final Plugin owner;
3939
private final FeatureInstaller<ViewFrame> featureInstaller = new DefaultFeatureInstaller<>(this);
4040

41-
static {
42-
PlatformUtils.setFactory(new BukkitElementFactory());
43-
}
44-
4541
private ViewFrame(Plugin owner) {
4642
this.owner = owner;
4743
}
@@ -191,6 +187,7 @@ public final void openEndless(
191187
public final ViewFrame register() {
192188
if (isRegistered()) throw new IllegalStateException("This view frame is already registered");
193189

190+
PlatformUtils.setFactory(new BukkitElementFactory(getOwner()));
194191
tryEnableMetrics();
195192
checkRelocationIssues();
196193
setRegistered(true);

inventory-framework-platform-bukkit/src/main/java/me/devnatan/inventoryframework/internal/BukkitElementFactory.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static me.devnatan.inventoryframework.runtime.util.InventoryUtils.checkInventoryTypeSupport;
44

5+
import com.tcoded.folialib.FoliaLib;
56
import java.util.List;
67
import java.util.Map;
78
import java.util.UUID;
@@ -14,10 +15,12 @@
1415
import me.devnatan.inventoryframework.context.*;
1516
import me.devnatan.inventoryframework.logging.Logger;
1617
import me.devnatan.inventoryframework.logging.NoopLogger;
18+
import me.devnatan.inventoryframework.state.TimerState;
1719
import org.bukkit.entity.Player;
1820
import org.bukkit.event.inventory.InventoryClickEvent;
1921
import org.bukkit.inventory.Inventory;
2022
import org.bukkit.inventory.InventoryHolder;
23+
import org.bukkit.plugin.Plugin;
2124
import org.jetbrains.annotations.NotNull;
2225
import org.jetbrains.annotations.Nullable;
2326

@@ -26,6 +29,12 @@ public class BukkitElementFactory extends ElementFactory {
2629
private static final ViewType defaultType = ViewType.CHEST;
2730
private Boolean worksInCurrentPlatform = null;
2831

32+
private final FoliaLib foliaLib;
33+
34+
public BukkitElementFactory(Plugin plugin) {
35+
this.foliaLib = new FoliaLib(plugin);
36+
}
37+
2938
@Override
3039
public @NotNull RootView createUninitializedRoot() {
3140
return new View();
@@ -142,6 +151,12 @@ public Logger getLogger() {
142151

143152
@Override
144153
public Job scheduleJobInterval(@NotNull RootView root, long intervalInTicks, @NotNull Runnable execution) {
145-
return new BukkitTaskJobImpl(((View) root).getFramework().getOwner(), intervalInTicks, execution);
154+
return new BukkitTaskJobImpl(foliaLib.getScheduler(), intervalInTicks, execution);
155+
}
156+
157+
@Override
158+
public TimerState createTimerState(long stateId, long intervalInTicks) {
159+
160+
return null;
146161
}
147162
}

inventory-framework-platform-bukkit/src/main/java/me/devnatan/inventoryframework/internal/BukkitTaskJobImpl.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
package me.devnatan.inventoryframework.internal;
22

3-
import org.bukkit.plugin.Plugin;
4-
import org.bukkit.scheduler.BukkitTask;
3+
import com.tcoded.folialib.impl.PlatformScheduler;
4+
import com.tcoded.folialib.wrapper.task.WrappedTask;
55

66
class BukkitTaskJobImpl implements Job {
77

8-
private final Plugin plugin;
8+
private final PlatformScheduler scheduler;
99
private final long intervalInTicks;
1010
private final Runnable execution;
11-
private BukkitTask task;
11+
private WrappedTask task;
1212

13-
public BukkitTaskJobImpl(Plugin plugin, long intervalInTicks, Runnable execution) {
14-
this.plugin = plugin;
13+
public BukkitTaskJobImpl(PlatformScheduler scheduler, long intervalInTicks, Runnable execution) {
14+
this.scheduler = scheduler;
1515
this.intervalInTicks = intervalInTicks;
1616
this.execution = execution;
1717
}
1818

1919
@Override
2020
public boolean isStarted() {
21-
return task != null;
21+
return task != null && !task.isCancelled();
2222
}
2323

2424
@Override
2525
public void start() {
2626
if (isStarted()) return;
27-
task = plugin.getServer().getScheduler().runTaskTimer(plugin, this::loop, intervalInTicks, intervalInTicks);
27+
task = scheduler.runTimer(this::loop, intervalInTicks, intervalInTicks);
2828
}
2929

3030
@Override

inventory-framework-platform-minestom/src/main/kotlin/me/devnatan/inventoryframework/IFInventoryListener.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ internal class IFInventoryListener(
4545
event.isCancelled = context.config.getOptionValue(ViewConfig.CANCEL_ON_DROP)
4646
return
4747
}
48-
if (
49-
event.click is Click.LeftDrag ||
50-
event.click is Click.RightDrag
51-
) {
48+
if (event.click is Click.LeftDrag || event.click is Click.RightDrag) {
5249
val context: IFContext = viewer.activeContext
5350
if (!context.config.isOptionSet(ViewConfig.CANCEL_ON_DRAG)) return
5451

inventory-framework-platform-minestom/src/main/kotlin/me/devnatan/inventoryframework/context/SlotClickContext.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ class SlotClickContext
6464

6565
override fun isShiftClick(): Boolean {
6666
val clickType = clickOrigin.click
67-
return clickType is Click.LeftShift ||
68-
clickType is Click.RightShift
67+
return clickType is Click.LeftShift || clickType is Click.RightShift
6968
}
7069

7170
override fun isKeyboardClick(): Boolean = clickOrigin.click is Click.HotbarSwap

inventory-framework-platform-minestom/src/main/kotlin/me/devnatan/inventoryframework/internal/MinestomElementFactory.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,11 @@ class MinestomElementFactory : ElementFactory() {
9191
type,
9292
when (val title = config.title) {
9393
is net.kyori.adventure.text.Component -> title
94-
null -> net.kyori.adventure.text.Component.empty()
94+
null ->
95+
net.kyori.adventure.text.Component
96+
.empty()
9597
else -> text(title.toString())
96-
}
98+
},
9799
)
98100
return MinestomViewContainer(inventory, false, finalType, false)
99101
}

inventory-framework-platform-paper/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ repositories {
1414
dependencies {
1515
compileOnly(libs.paperSpigot)
1616
implementation(projects.inventoryFrameworkPlatformBukkit)
17-
implementation(libs.folialib)
1817
}
1918

2019
java {

0 commit comments

Comments
 (0)