-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add working bukkit platform including translations
- Loading branch information
Showing
30 changed files
with
1,311 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
apply plugin: 'kr.entree.spigradle' | ||
|
||
archivesBaseName = "${project.property("pluginName")}-bukkit" | ||
|
||
spigot { | ||
name = project.property("pluginName") | ||
authors = [project.property("author")] | ||
apiVersion = project.property("apiVersion") | ||
load = STARTUP | ||
depends = [] | ||
softDepends = ['PlaceholderAPI'] | ||
permissions { | ||
'template.player' { | ||
description 'Contains all basic player permissions.' | ||
defaults 'true' | ||
children = [ | ||
'template.player.one' : true, | ||
'template.player.two.example': true | ||
] | ||
} | ||
'template.admin' { | ||
description 'Contains all admin permissions.' | ||
defaults 'op' | ||
children = [ | ||
'template.admin.reload': true | ||
] | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation project(':platform') | ||
|
||
implementation spigot(mcVersion) | ||
|
||
implementation 'cloud.commandframework:cloud-paper:1.6.1' | ||
implementation "net.kyori:adventure-platform-bukkit:4.0.1" | ||
implementation "org.spongepowered:configurate-yaml:4.1.2" | ||
|
||
testImplementation 'com.github.seeseemelk:MockBukkit-v1.18:1.15.5' | ||
testImplementation(testFixtures(project(":core"))) | ||
} | ||
|
||
shadowJar { | ||
archiveClassifier.set("") | ||
dependencies { | ||
include(project(':api')) | ||
include(project(':core')) | ||
include(project(':platform')) | ||
include(dependency('cloud.commandframework::')) | ||
include(dependency('io.leangen.geantyref::')) | ||
include(dependency('org.spongepowered::')) | ||
include(dependency('net.kyori::')) | ||
} | ||
relocate 'cloud.commandframework', "${packageName}.lib.commands" | ||
relocate 'org.spongepowered.configurate', "${packageName}.lib.configurate" | ||
relocate 'io.leangen.geantyref', "${packageName}.lib.typetoken" | ||
relocate 'net.kyori', "${packageName}.lib.kyori" | ||
relocate 'org.bstats', "${packageName}.lib.bstats" | ||
} | ||
|
||
tasks.build.dependsOn(shadowJar) | ||
tasks.publish.dependsOn(shadowJar) |
61 changes: 61 additions & 0 deletions
61
platform/bukkit/src/main/java/net/silthus/template/bukkit/BukkitLoader.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,61 @@ | ||
/* | ||
* sChat, a Supercharged Minecraft Chat Plugin | ||
* Copyright (C) Silthus <https://www.github.com/silthus> | ||
* Copyright (C) sChat team and 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.silthus.template.bukkit; | ||
|
||
import java.io.File; | ||
import kr.entree.spigradle.annotations.PluginMain; | ||
import org.bukkit.plugin.PluginDescriptionFile; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.bukkit.plugin.java.JavaPluginLoader; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@PluginMain | ||
public final class BukkitLoader extends JavaPlugin { | ||
|
||
private final SChatBukkitBootstrap bootstrap; | ||
|
||
public BukkitLoader() { | ||
this.bootstrap = new SChatBukkitBootstrap(this); | ||
} | ||
|
||
// testing constructor | ||
public BukkitLoader(@NotNull JavaPluginLoader loader, | ||
@NotNull PluginDescriptionFile description, | ||
@NotNull File dataFolder, | ||
@NotNull File file) { | ||
super(loader, description, dataFolder, file); | ||
this.bootstrap = new SChatBukkitBootstrap(this); | ||
} | ||
|
||
@Override | ||
public void onLoad() { | ||
bootstrap.onLoad(); | ||
} | ||
|
||
@Override | ||
public void onEnable() { | ||
bootstrap.onEnable(); | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
bootstrap.onDisable(); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
platform/bukkit/src/main/java/net/silthus/template/bukkit/SChatBukkitBootstrap.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,67 @@ | ||
/* | ||
* sChat, a Supercharged Minecraft Chat Plugin | ||
* Copyright (C) Silthus <https://www.github.com/silthus> | ||
* Copyright (C) sChat team and 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.silthus.template.bukkit; | ||
|
||
import java.nio.file.Path; | ||
import lombok.Getter; | ||
import net.silthus.template.bukkit.adapter.BukkitSchedulerAdapter; | ||
import net.silthus.template.platform.plugin.bootstrap.Bootstrap; | ||
import net.silthus.template.platform.plugin.bootstrap.LoaderBootstrap; | ||
import net.silthus.template.platform.plugin.logging.JavaPluginLogger; | ||
import net.silthus.template.platform.plugin.logging.PluginLogger; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
@Getter | ||
public class SChatBukkitBootstrap implements Bootstrap, LoaderBootstrap { | ||
|
||
private final JavaPlugin loader; | ||
private final SChatBukkitPlugin plugin; | ||
|
||
private final PluginLogger pluginLogger; | ||
private final BukkitSchedulerAdapter scheduler; | ||
|
||
public SChatBukkitBootstrap(JavaPlugin loader) { | ||
this.loader = loader; | ||
|
||
this.pluginLogger = new JavaPluginLogger(loader.getLogger()); | ||
this.scheduler = new BukkitSchedulerAdapter(loader); | ||
this.plugin = new SChatBukkitPlugin(this); | ||
} | ||
|
||
@Override | ||
public void onLoad() { | ||
plugin.load(); | ||
} | ||
|
||
@Override | ||
public void onEnable() { | ||
plugin.enable(); | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
plugin.disable(); | ||
} | ||
|
||
@Override | ||
public Path getDataDirectory() { | ||
return getLoader().getDataFolder().toPath().toAbsolutePath(); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
platform/bukkit/src/main/java/net/silthus/template/bukkit/SChatBukkitPlugin.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,79 @@ | ||
/* | ||
* sChat, a Supercharged Minecraft Chat Plugin | ||
* Copyright (C) Silthus <https://www.github.com/silthus> | ||
* Copyright (C) sChat team and 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.silthus.template.bukkit; | ||
|
||
import cloud.commandframework.CommandManager; | ||
import cloud.commandframework.paper.PaperCommandManager; | ||
import lombok.Getter; | ||
import lombok.SneakyThrows; | ||
import net.kyori.adventure.platform.bukkit.BukkitAudiences; | ||
import net.silthus.template.bukkit.adapter.BukkitSchedulerAdapter; | ||
import net.silthus.template.bukkit.adapter.BukkitSenderFactory; | ||
import net.silthus.template.platform.config.adapter.ConfigurationAdapter; | ||
import net.silthus.template.platform.config.adapter.ConfigurationAdapters; | ||
import net.silthus.template.platform.plugin.AbstractTemplatePlugin; | ||
import net.silthus.template.platform.sender.Sender; | ||
import org.bukkit.Bukkit; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import static cloud.commandframework.execution.CommandExecutionCoordinator.simpleCoordinator; | ||
|
||
@Getter | ||
public final class SChatBukkitPlugin extends AbstractTemplatePlugin { | ||
|
||
private final SChatBukkitBootstrap bootstrap; | ||
private BukkitSenderFactory senderFactory; | ||
|
||
SChatBukkitPlugin(SChatBukkitBootstrap bootstrap) { | ||
this.bootstrap = bootstrap; | ||
} | ||
|
||
@Override | ||
protected ConfigurationAdapter provideConfigurationAdapter() { | ||
return ConfigurationAdapters.YAML.create(resolveConfig("config.yml").toFile()); | ||
} | ||
|
||
@Override | ||
protected void setupSenderFactory() { | ||
senderFactory = new BukkitSenderFactory(getAudiences(), new BukkitSchedulerAdapter(bootstrap.getLoader())); | ||
} | ||
|
||
@NotNull | ||
private BukkitAudiences getAudiences() { | ||
return BukkitAudiences.create(getBootstrap().getLoader()); | ||
} | ||
|
||
@Override | ||
@SneakyThrows | ||
protected CommandManager<Sender> provideCommandManager() { | ||
try { | ||
return new PaperCommandManager<>( | ||
getBootstrap().getLoader(), | ||
simpleCoordinator(), | ||
commandSender -> getSenderFactory().wrap(commandSender), | ||
sender -> getSenderFactory().unwrap(sender) | ||
); | ||
} catch (Exception e) { | ||
getLogger().severe("Failed to initialize the command manager."); | ||
Bukkit.getPluginManager().disablePlugin(getBootstrap().getLoader()); | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
platform/bukkit/src/main/java/net/silthus/template/bukkit/adapter/BukkitIdentityAdapter.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,58 @@ | ||
package net.silthus.template.bukkit.adapter; | ||
|
||
import java.util.function.Supplier; | ||
import lombok.NonNull; | ||
import net.kyori.adventure.text.Component; | ||
import net.kyori.adventure.text.TextComponent; | ||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; | ||
import net.silthus.template.identity.Identity; | ||
import org.bukkit.OfflinePlayer; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import static java.util.Objects.requireNonNullElse; | ||
import static net.kyori.adventure.text.Component.text; | ||
import static net.silthus.template.pointer.Pointer.weak; | ||
import static org.bukkit.Bukkit.getPlayer; | ||
|
||
public final class BukkitIdentityAdapter { | ||
|
||
private static final LegacyComponentSerializer LEGACY_SERIALIZER = LegacyComponentSerializer.legacySection(); | ||
|
||
private BukkitIdentityAdapter() { | ||
} | ||
|
||
public static @NotNull Identity identity(@NonNull OfflinePlayer player) { | ||
return Identity.identity( | ||
player.getUniqueId(), | ||
player.getName(), | ||
displayName(player) | ||
); | ||
} | ||
|
||
@NotNull | ||
private static Supplier<Component> displayName(@NonNull OfflinePlayer offlinePlayer) { | ||
if (offlinePlayer.isOnline()) | ||
if (offlinePlayer instanceof Player player) | ||
return getOnlinePlayerDisplayName(player); | ||
else | ||
return getOnlinePlayerDisplayName(getPlayer(offlinePlayer.getUniqueId())); | ||
else | ||
return getDisplayNameFromName(offlinePlayer); | ||
} | ||
|
||
@NotNull | ||
private static Supplier<Component> getOnlinePlayerDisplayName(Player player) { | ||
return weak(player, BukkitIdentityAdapter::deserializeDisplayName, text(player.getName())); | ||
} | ||
|
||
@NotNull | ||
private static Supplier<Component> getDisplayNameFromName(@NotNull OfflinePlayer offlinePlayer) { | ||
return () -> text(requireNonNullElse(offlinePlayer.getName(), "")); | ||
} | ||
|
||
@NotNull | ||
private static TextComponent deserializeDisplayName(Player p) { | ||
return LEGACY_SERIALIZER.deserialize(p.getDisplayName()); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...form/bukkit/src/main/java/net/silthus/template/bukkit/adapter/BukkitSchedulerAdapter.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,40 @@ | ||
/* | ||
* sChat, a Supercharged Minecraft Chat Plugin | ||
* Copyright (C) Silthus <https://www.github.com/silthus> | ||
* Copyright (C) sChat team and 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.silthus.template.bukkit.adapter; | ||
|
||
import java.util.concurrent.Executor; | ||
import net.silthus.template.platform.plugin.scheduler.AbstractJavaScheduler; | ||
import net.silthus.template.platform.plugin.scheduler.SchedulerAdapter; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
public final class BukkitSchedulerAdapter extends AbstractJavaScheduler implements SchedulerAdapter { | ||
|
||
private final Executor sync; | ||
|
||
public BukkitSchedulerAdapter(JavaPlugin loader) { | ||
this.sync = r -> loader.getServer().getScheduler().scheduleSyncDelayedTask(loader, r); | ||
} | ||
|
||
@Override | ||
public Executor sync() { | ||
return this.sync; | ||
} | ||
|
||
} |
Oops, something went wrong.