-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
186 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 37 additions & 1 deletion
38
common/src/main/java/net/draycia/carbon/common/PlatformScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,45 @@ | ||
/* | ||
* CarbonChat | ||
* | ||
* Copyright (c) 2023 Josua Parks (Vicarious) | ||
* Contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package net.draycia.carbon.common; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
import net.draycia.carbon.api.users.CarbonPlayer; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.checkerframework.framework.qual.DefaultQualifier; | ||
|
||
@DefaultQualifier(NonNull.class) | ||
public interface PlatformScheduler { | ||
|
||
void scheduleForPlayer(final CarbonPlayer carbonPlayer, final Runnable runnable); | ||
void scheduleForPlayer(CarbonPlayer carbonPlayer, Runnable runnable); | ||
|
||
@Singleton | ||
final class RunImmediately implements PlatformScheduler { | ||
@Inject | ||
private RunImmediately() { | ||
} | ||
|
||
@Override | ||
public void scheduleForPlayer(final CarbonPlayer carbonPlayer, final Runnable runnable) { | ||
runnable.run(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
fabric/src/main/java/net/draycia/carbon/fabric/FabricScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* CarbonChat | ||
* | ||
* Copyright (c) 2023 Josua Parks (Vicarious) | ||
* Contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package net.draycia.carbon.fabric; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
import net.draycia.carbon.api.users.CarbonPlayer; | ||
import net.draycia.carbon.common.PlatformScheduler; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.checkerframework.framework.qual.DefaultQualifier; | ||
|
||
@DefaultQualifier(NonNull.class) | ||
@Singleton | ||
public final class FabricScheduler implements PlatformScheduler { | ||
|
||
private final MinecraftServerHolder serverHolder; | ||
|
||
@Inject | ||
private FabricScheduler(final MinecraftServerHolder serverHolder) { | ||
this.serverHolder = serverHolder; | ||
} | ||
|
||
@Override | ||
public void scheduleForPlayer(final CarbonPlayer carbonPlayer, final Runnable runnable) { | ||
this.serverHolder.requireServer().execute(runnable); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 0 additions & 57 deletions
57
paper/src/main/java/net/draycia/carbon/paper/ContextualPlatformScheduler.java
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
paper/src/main/java/net/draycia/carbon/paper/PaperScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* CarbonChat | ||
* | ||
* Copyright (c) 2023 Josua Parks (Vicarious) | ||
* Contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package net.draycia.carbon.paper; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
import net.draycia.carbon.api.users.CarbonPlayer; | ||
import net.draycia.carbon.common.PlatformScheduler; | ||
import org.bukkit.Server; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import org.checkerframework.framework.qual.DefaultQualifier; | ||
|
||
@Singleton | ||
@DefaultQualifier(NonNull.class) | ||
public final class PaperScheduler implements PlatformScheduler { | ||
|
||
private static final boolean FOLIA; | ||
|
||
static { | ||
boolean folia; | ||
try { | ||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer"); | ||
folia = true; | ||
} catch (final ClassNotFoundException exception) { | ||
folia = false; | ||
} | ||
FOLIA = folia; | ||
} | ||
|
||
private final JavaPlugin plugin; | ||
private final Server server; | ||
|
||
@Inject | ||
private PaperScheduler(final JavaPlugin plugin, final Server server) { | ||
this.plugin = plugin; | ||
this.server = server; | ||
} | ||
|
||
public void scheduleForPlayer(final CarbonPlayer carbonPlayer, final Runnable runnable) { | ||
if (!FOLIA) { | ||
if (this.server.isPrimaryThread()) { | ||
runnable.run(); | ||
} else { | ||
this.server.getScheduler().runTask(this.plugin, runnable); | ||
} | ||
} else { | ||
final @Nullable Player player = this.server.getPlayer(carbonPlayer.uuid()); | ||
|
||
if (player == null) { | ||
runnable.run(); | ||
return; | ||
} | ||
|
||
if (this.server.isOwnedByCurrentRegion(player)) { | ||
runnable.run(); | ||
} else { | ||
player.getScheduler().run(this.plugin, $ -> runnable.run(), null); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.