mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
feature: basic towny integration (#334)
Co-authored-by: Jason Penilla <[email protected]>
This commit is contained in:
1 parent
a902fc56cd
commit
b5431e542e
24 files changed
+755
-48
No files matched your search
@@ -26,6 +26,7 @@ dependencies {
|
||||
compileOnly(libs.miniplaceholders)
|
||||
compileOnly(libs.essentialsXDiscord)
|
||||
compileOnly(libs.discordsrv)
|
||||
compileOnly(libs.towny)
|
||||
|
||||
runtimeDownload(libs.guice) {
|
||||
exclude("com.google.guava")
|
||||
@@ -43,6 +44,8 @@ tasks {
|
||||
downloadPlugins {
|
||||
url("https://download.luckperms.net/1515/bukkit/loader/LuckPerms-Bukkit-5.4.102.jar")
|
||||
github("MiniPlaceholders", "MiniPlaceholders", libs.versions.miniplaceholders.get(), "MiniPlaceholders-Paper-${libs.versions.miniplaceholders.get()}.jar")
|
||||
github("MiniPlaceholders", "PlaceholderAPI-Expansion", "1.2.0", "PlaceholderAPI-Expansion-1.2.0.jar")
|
||||
hangar("PlaceholderAPI", "2.11.5")
|
||||
}
|
||||
}
|
||||
register<RunServer>("runServer2") {
|
||||
@@ -70,6 +73,7 @@ paper {
|
||||
dependency("EssentialsDiscord", PaperPluginDescription.Load.BEFORE, false)
|
||||
dependency("DiscordSRV", PaperPluginDescription.Load.BEFORE, false)
|
||||
dependency("MiniPlaceholders", PaperPluginDescription.Load.BEFORE, false)
|
||||
dependency("Towny", PaperPluginDescription.Load.BEFORE, false)
|
||||
}
|
||||
|
||||
bukkit {
|
||||
|
||||
@@ -22,7 +22,6 @@ package net.draycia.carbon.paper;
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.brigadier.CloudBrigadierManager;
|
||||
import cloud.commandframework.paper.PaperCommandManager;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.multibindings.Multibinder;
|
||||
@@ -31,10 +30,12 @@ import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonServer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.CarbonCommonModule;
|
||||
import net.draycia.carbon.common.CarbonPlatformModule;
|
||||
import net.draycia.carbon.common.DataDirectory;
|
||||
import net.draycia.carbon.common.PlatformScheduler;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.ExecutionCoordinatorHolder;
|
||||
import net.draycia.carbon.common.integration.Integration;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageRenderer;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.draycia.carbon.common.users.PlatformUserManager;
|
||||
@@ -42,6 +43,7 @@ import net.draycia.carbon.common.users.ProfileResolver;
|
||||
import net.draycia.carbon.common.util.CloudUtils;
|
||||
import net.draycia.carbon.paper.command.PaperCommander;
|
||||
import net.draycia.carbon.paper.command.PaperPlayerCommander;
|
||||
import net.draycia.carbon.paper.integration.towny.TownyIntegration;
|
||||
import net.draycia.carbon.paper.listeners.PaperChatListener;
|
||||
import net.draycia.carbon.paper.listeners.PaperPlayerJoinListener;
|
||||
import net.draycia.carbon.paper.messages.PaperMessageRenderer;
|
||||
@@ -58,7 +60,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class CarbonChatPaperModule extends AbstractModule {
|
||||
public final class CarbonChatPaperModule extends CarbonPlatformModule {
|
||||
|
||||
private final Logger logger = LogManager.getLogger("CarbonChat");
|
||||
private final CarbonPaperBootstrap bootstrap;
|
||||
@@ -105,7 +107,7 @@ public final class CarbonChatPaperModule extends AbstractModule {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure() {
|
||||
protected void configurePlatform() {
|
||||
this.install(new CarbonCommonModule());
|
||||
|
||||
this.bind(CarbonChat.class).to(CarbonChatPaper.class);
|
||||
@@ -122,6 +124,12 @@ public final class CarbonChatPaperModule extends AbstractModule {
|
||||
this.configureListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureIntegrations(final Multibinder<Integration> integrations, final Multibinder<Integration.ConfigMeta> configs) {
|
||||
integrations.addBinding().to(TownyIntegration.class);
|
||||
configs.addBinding().toInstance(TownyIntegration.configMeta());
|
||||
}
|
||||
|
||||
private void configureListeners() {
|
||||
final Multibinder<Listener> listeners = Multibinder.newSetBinder(this.binder(), Listener.class);
|
||||
listeners.addBinding().to(PaperChatListener.class);
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.integration.towny;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.channels.messages.ConfigChannelMessageSource;
|
||||
import net.draycia.carbon.common.config.ConfigHeader;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
@ConfigSerializable
|
||||
@ConfigHeader(ResidentListChannel.TOWNY_CHANNEL_HEADER)
|
||||
public class AllianceChannel extends NationChannel {
|
||||
|
||||
public static final String FILE_NAME = "alliancechat.conf";
|
||||
|
||||
public AllianceChannel() {
|
||||
this.key = Key.key("carbon", "alliancechat");
|
||||
this.commandAliases = List.of();
|
||||
|
||||
this.messageSource = new ConfigChannelMessageSource();
|
||||
this.messageSource.defaults = Map.of(
|
||||
"default_format", "(alliance) <display_name>: <message>",
|
||||
"console", "[alliance] <username> - <uuid>: <message>"
|
||||
);
|
||||
this.messageSource.locales = Map.of(
|
||||
Locale.US, Map.of("default_format", "(alliance) <display_name>: <message>")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Player> onlinePlayers(final Nation residentList) {
|
||||
return TOWNY_API.getOnlinePlayersAlliance(residentList);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cannotUseChannel(final CarbonPlayer player) {
|
||||
this.messages.cannotUseAllianceChannel(player);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.integration.towny;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Nation;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.channels.messages.ConfigChannelMessageSource;
|
||||
import net.draycia.carbon.common.config.ConfigHeader;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
@ConfigSerializable
|
||||
@ConfigHeader(ResidentListChannel.TOWNY_CHANNEL_HEADER)
|
||||
public class NationChannel extends ResidentListChannel<Nation> {
|
||||
|
||||
public static final String FILE_NAME = "nationchat.conf";
|
||||
|
||||
public NationChannel() {
|
||||
this.key = Key.key("carbon", "nationchat");
|
||||
this.commandAliases = List.of("nc");
|
||||
|
||||
this.messageSource = new ConfigChannelMessageSource();
|
||||
this.messageSource.defaults = Map.of(
|
||||
"default_format", "(nation: %townyadvanced_nation_unformatted%) <display_name>: <message>",
|
||||
"console", "[nation: %townyadvanced_nation_unformatted%] <username> - <uuid>: <message>"
|
||||
);
|
||||
this.messageSource.locales = Map.of(
|
||||
Locale.US, Map.of("default_format", "(nation: %townyadvanced_nation_unformatted%) <display_name>: <message>")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable Nation residentList(final CarbonPlayer player) {
|
||||
final @Nullable Resident resident = TOWNY_API.getResident(player.uuid());
|
||||
if (resident == null) {
|
||||
return null;
|
||||
}
|
||||
return TOWNY_API.getResidentNationOrNull(resident);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cannotUseChannel(final CarbonPlayer player) {
|
||||
this.messages.cannotUseNationChannel(player);
|
||||
}
|
||||
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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.integration.towny;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.object.ResidentList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.channels.ConfigChatChannel;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
abstract class ResidentListChannel<T extends ResidentList> extends ConfigChatChannel {
|
||||
|
||||
protected static final String TOWNY_CHANNEL_HEADER = """
|
||||
See the Towny Wiki at https://github.com/TownyAdvanced/Towny/wiki/Placeholders
|
||||
for placeholders Towny provides to PlaceholderAPI.
|
||||
""";
|
||||
protected final static TownyAPI TOWNY_API = TownyAPI.getInstance();
|
||||
|
||||
protected transient @MonotonicNonNull @Inject CarbonMessages messages;
|
||||
protected transient @MonotonicNonNull @Inject UserManager<?> users;
|
||||
|
||||
protected abstract @Nullable T residentList(CarbonPlayer player);
|
||||
|
||||
@Override
|
||||
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
|
||||
return this.residentList(player) != null
|
||||
? ChannelPermissionResult.allowed()
|
||||
: ChannelPermissionResult.denied(Component.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
|
||||
return this.residentList(player) != null
|
||||
? ChannelPermissionResult.allowed()
|
||||
: ChannelPermissionResult.denied(Component.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Audience> recipients(final CarbonPlayer sender) {
|
||||
final @Nullable T residentList = this.residentList(sender);
|
||||
|
||||
if (residentList == null) {
|
||||
if (sender.online()) {
|
||||
this.cannotUseChannel(sender);
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final List<Audience> recipients = new ArrayList<>();
|
||||
for (final Player player : this.onlinePlayers(residentList)) {
|
||||
final @Nullable CarbonPlayer carbon = this.users.user(player.getUniqueId()).getNow(null);
|
||||
if (carbon != null) {
|
||||
recipients.add(carbon);
|
||||
}
|
||||
}
|
||||
|
||||
recipients.add(this.server.console());
|
||||
|
||||
return recipients;
|
||||
}
|
||||
|
||||
protected List<Player> onlinePlayers(final T residentList) {
|
||||
return TOWNY_API.getOnlinePlayers(residentList);
|
||||
}
|
||||
|
||||
protected abstract void cannotUseChannel(CarbonPlayer player);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.integration.towny;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.channels.messages.ConfigChannelMessageSource;
|
||||
import net.draycia.carbon.common.config.ConfigHeader;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
@ConfigSerializable
|
||||
@ConfigHeader(ResidentListChannel.TOWNY_CHANNEL_HEADER)
|
||||
public class TownChannel extends ResidentListChannel<Town> {
|
||||
|
||||
public static final String FILE_NAME = "townchat.conf";
|
||||
|
||||
public TownChannel() {
|
||||
this.key = Key.key("carbon", "townchat");
|
||||
this.commandAliases = List.of("tc");
|
||||
|
||||
this.messageSource = new ConfigChannelMessageSource();
|
||||
this.messageSource.defaults = Map.of(
|
||||
"default_format", "(town: %townyadvanced_town_unformatted%) <display_name>: <message>",
|
||||
"console", "[town: %townyadvanced_town_unformatted%] <username> - <uuid>: <message>"
|
||||
);
|
||||
this.messageSource.locales = Map.of(
|
||||
Locale.US, Map.of("default_format", "(town: %townyadvanced_town_unformatted%) <display_name>: <message>")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable Town residentList(final CarbonPlayer player) {
|
||||
final @Nullable Resident resident = TOWNY_API.getResident(player.uuid());
|
||||
if (resident == null) {
|
||||
return null;
|
||||
}
|
||||
return TOWNY_API.getResidentTownOrNull(resident);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cannotUseChannel(final CarbonPlayer player) {
|
||||
this.messages.cannotUseTownChannel(player);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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.integration.towny;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
|
||||
import net.draycia.carbon.common.config.ConfigManager;
|
||||
import net.draycia.carbon.common.integration.Integration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class TownyIntegration implements Integration {
|
||||
|
||||
private final CarbonChannelRegistry channelRegistry;
|
||||
private final Config config;
|
||||
|
||||
@Inject
|
||||
public TownyIntegration(
|
||||
final CarbonChannelRegistry channelRegistry,
|
||||
final ConfigManager configManager
|
||||
) {
|
||||
this.channelRegistry = channelRegistry;
|
||||
this.config = this.config(configManager, configMeta());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean eligible() {
|
||||
return this.config.enabled && Bukkit.getPluginManager().isPluginEnabled("Towny");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register() {
|
||||
if (this.config.townChannel) {
|
||||
this.channelRegistry.registerSpecialConfigChannel(TownChannel.FILE_NAME, TownChannel.class);
|
||||
}
|
||||
|
||||
if (this.config.nationChannel) {
|
||||
this.channelRegistry.registerSpecialConfigChannel(NationChannel.FILE_NAME, NationChannel.class);
|
||||
}
|
||||
|
||||
if (this.config.allianceChannel) {
|
||||
this.channelRegistry.registerSpecialConfigChannel(AllianceChannel.FILE_NAME, AllianceChannel.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static ConfigMeta configMeta() {
|
||||
return Integration.configMeta("towny", TownyIntegration.Config.class);
|
||||
}
|
||||
|
||||
@ConfigSerializable
|
||||
public static final class Config {
|
||||
boolean enabled = true;
|
||||
boolean townChannel = true;
|
||||
boolean nationChannel = true;
|
||||
boolean allianceChannel = false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user