Add Faction, Alliance, and Truce chats from FactionsUUID (#349)

Co-authored-by: Jason Penilla <[email protected]>
This commit is contained in:
Josua ParksandJason Penilla authored and GitHub committed 2023-11-14 18:04:22 -07:00
1 parent ae4e9eb866
commit cf28f2d31b
15 files changed
+521 -4

No files matched your search

@@ -549,4 +549,13 @@ public interface CarbonMessages {
@Message("integrations.mcmmo.cannot_use_party_channel")
Component cannotUseMcmmoPartyChannel(Audience audience);
@Message("integrations.fuuid.cannot_use_faction_channel")
Component cannotUseFactionChannel(Audience audience);
@Message("integrations.fuuid.cannot_use_alliance_channel")
Component cannotUseFactionAllianceChannel(Audience audience);
@Message("integrations.fuuid.cannot_use_truce_channel")
Component cannotUseTruceChannel(Audience audience);
}
@@ -153,3 +153,6 @@ integrations.towny.cannot_use_alliance_channel=<red>You must join an alliance to
integrations.towny.cannot_use_nation_channel=<red>You must join a nation to use this channel.
integrations.towny.cannot_use_town_channel=<red>You must join a town to use this channel.
integrations.mcmmo.cannot_use_party_channel=<red>You must join an mcMMO party to use this channel.
integrations.fuuid.cannot_use_faction_channel=<red>You must join a faction to use this channel.
integrations.fuuid.cannot_use_alliance_channel=<red>You must join an alliance to use this channel.
integrations.fuuid.cannot_use_truce_channel=<red>You must have a truce with another faction to use this channel.
+2
View File
@@ -51,6 +51,7 @@ nats = "2.16.14"
h2 = "2.2.224"
towny = "0.100.0.2"
mcmmo = "2.1.225"
fuuid = "1.6.9.5-U0.6.33"
# synced with version used by lowest supported mc (currently 1.19.4 on paper)
gson = "2.10"
@@ -139,3 +140,4 @@ placeholderapi = { group = "me.clip", name = "placeholderapi", version.ref = "pl
miniplaceholders = { group = "io.github.miniplaceholders", name = "miniplaceholders-api", version.ref = "miniplaceholders" }
towny = { group = "com.palmergames.bukkit.towny", name = "towny", version.ref = "towny" }
mcmmo = { group = "com.gmail.nossr50.mcMMO", name = "mcMMO", version.ref = "mcmmo" }
factionsUuid = { group = "com.massivecraft", name = "Factions", version.ref = "fuuid" }
+3
View File
@@ -35,6 +35,7 @@ dependencies {
compileOnly(libs.mcmmo) {
isTransitive = false
}
compileOnly(libs.factionsUuid)
runtimeDownload(libs.guice) {
exclude("com.google.guava")
@@ -43,6 +44,7 @@ dependencies {
configurablePlugins.dependency(libs.towny)
configurablePlugins.dependency(libs.mcmmo)
configurablePlugins.dependency(libs.factionsUuid)
tasks {
shadowJar {
@@ -86,6 +88,7 @@ paper {
// Integrations
dependency("Towny", PaperPluginDescription.Load.BEFORE, false)
dependency("mcMMO", PaperPluginDescription.Load.BEFORE, false)
dependency("Factions", PaperPluginDescription.Load.BEFORE, false)
}
bukkit {
@@ -43,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.fuuid.FactionsIntegration;
import net.draycia.carbon.paper.integration.mcmmo.McmmoIntegration;
import net.draycia.carbon.paper.integration.towny.TownyIntegration;
import net.draycia.carbon.paper.listeners.PaperChatListener;
@@ -132,6 +133,9 @@ public final class CarbonChatPaperModule extends CarbonPlatformModule {
integrations.addBinding().to(McmmoIntegration.class);
configs.addBinding().toInstance(McmmoIntegration.configMeta());
integrations.addBinding().to(FactionsIntegration.class);
configs.addBinding().toInstance(FactionsIntegration.configMeta());
}
private void configureListeners() {
@@ -0,0 +1,51 @@
/*
* 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.fuuid;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.perms.Relation;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.common.channels.ConfigChatChannel;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
import org.jspecify.annotations.NonNull;
@DefaultQualifier(NonNull.class)
abstract class AbstractFactionsChannel extends ConfigChatChannel {
protected final @Nullable Faction faction(final CarbonPlayer player) {
final FPlayer fPlayer = FPlayers.getInstance().getById(player.uuid().toString());
if (fPlayer == null || !fPlayer.hasFaction()) {
return null;
}
return fPlayer.getFaction();
}
protected final boolean hasRelations(final CarbonPlayer player, final Relation relation) {
final @Nullable Faction faction = this.faction(player);
return faction != null && faction.getRelationCount(relation) > 0;
}
}
@@ -0,0 +1,126 @@
/*
* 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.fuuid;
import com.google.inject.Inject;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.perms.Relation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import net.draycia.carbon.api.channels.ChannelPermissionResult;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.UserManager;
import net.draycia.carbon.common.channels.messages.ConfigChannelMessageSource;
import net.draycia.carbon.common.messages.CarbonMessages;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.key.Key;
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;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import static net.draycia.carbon.api.channels.ChannelPermissionResult.channelPermissionResult;
@DefaultQualifier(NonNull.class)
@ConfigSerializable
public class AllianceChannel extends AbstractFactionsChannel {
public static final String FILE_NAME = "factionsuuid-alliancechat.conf";
private transient @MonotonicNonNull @Inject CarbonMessages messages;
private transient @MonotonicNonNull @Inject UserManager<?> users;
public AllianceChannel() {
this.key = Key.key("carbon", "alliancechat");
this.commandAliases = List.of("ac");
this.messageSource = new ConfigChannelMessageSource();
this.messageSource.defaults = Map.of(
"default_format", "(alliance: %factionsuuid_faction_name%) <display_name>: <message>",
"console", "[alliance: %factionsuuid_faction_name%] <username>: <message>"
);
}
@Override
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
return channelPermissionResult(
this.hasRelations(player, Relation.ALLY),
() -> this.messages.cannotUseFactionAllianceChannel(player)
);
}
@Override
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
return channelPermissionResult(
this.hasRelations(player, Relation.ALLY),
() -> this.messages.cannotUseFactionAllianceChannel(player)
);
}
@Override
public List<Audience> recipients(final CarbonPlayer sender) {
if (!this.hasRelations(sender, Relation.ALLY)) {
if (sender.online()) {
sender.sendMessage(this.messages.cannotUseFactionAllianceChannel(sender));
}
return Collections.emptyList();
}
final List<Audience> recipients = new ArrayList<>();
for (final Player player : this.alliedPlayersTo(sender)) {
final @Nullable CarbonPlayer carbon = this.users.user(player.getUniqueId()).getNow(null);
if (carbon != null) {
recipients.add(carbon);
}
}
recipients.add(this.server.console());
return recipients;
}
private List<Player> alliedPlayersTo(final CarbonPlayer player) {
final @Nullable Faction faction = this.faction(player);
if (faction == null) {
return List.of();
}
final List<Player> alliedPlayers = new ArrayList<>();
for (final FPlayer onlinePlayer : FPlayers.getInstance().getOnlinePlayers()) {
final Relation relation = faction.getRelationTo(onlinePlayer);
if (relation.isAtLeast(Relation.ALLY)) {
alliedPlayers.add(onlinePlayer.getPlayer());
}
}
return alliedPlayers;
}
}
@@ -0,0 +1,105 @@
/*
* 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.fuuid;
import com.google.inject.Inject;
import com.massivecraft.factions.Faction;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import net.draycia.carbon.api.channels.ChannelPermissionResult;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.UserManager;
import net.draycia.carbon.common.channels.messages.ConfigChannelMessageSource;
import net.draycia.carbon.common.messages.CarbonMessages;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.key.Key;
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;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import static net.draycia.carbon.api.channels.ChannelPermissionResult.channelPermissionResult;
@DefaultQualifier(NonNull.class)
@ConfigSerializable
public class FactionChannel extends AbstractFactionsChannel {
public static final String FILE_NAME = "factionsuuid-factionchat.conf";
private transient @MonotonicNonNull @Inject CarbonMessages messages;
private transient @MonotonicNonNull @Inject UserManager<?> users;
public FactionChannel() {
this.key = Key.key("carbon", "factionchat");
this.commandAliases = List.of("fc");
this.messageSource = new ConfigChannelMessageSource();
this.messageSource.defaults = Map.of(
"default_format", "(faction: %factionsuuid_faction_name%) <display_name>: <message>",
"console", "[faction: %factionsuuid_faction_name%] <username>: <message>"
);
}
@Override
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
return channelPermissionResult(
this.faction(player) != null,
() -> this.messages.cannotUseFactionChannel(player)
);
}
@Override
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
return channelPermissionResult(
this.faction(player) != null,
() -> this.messages.cannotUseFactionChannel(player)
);
}
@Override
public List<Audience> recipients(final CarbonPlayer sender) {
final @Nullable Faction faction = this.faction(sender);
if (faction == null) {
if (sender.online()) {
sender.sendMessage(this.messages.cannotUseFactionChannel(sender));
}
return Collections.emptyList();
}
final List<Audience> recipients = new ArrayList<>();
for (final Player player : faction.getOnlinePlayers()) {
final @Nullable CarbonPlayer carbon = this.users.user(player.getUniqueId()).getNow(null);
if (carbon != null) {
recipients.add(carbon);
}
}
recipients.add(this.server.console());
return recipients;
}
}
@@ -0,0 +1,79 @@
/*
* 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.fuuid;
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 FactionsIntegration implements Integration {
private final CarbonChannelRegistry channelRegistry;
private final Config config;
@Inject
public FactionsIntegration(
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("Factions");
}
@Override
public void register() {
if (this.config.factionChannel) {
this.channelRegistry.registerSpecialConfigChannel(FactionChannel.FILE_NAME, FactionChannel.class);
}
if (this.config.allianceChannel) {
this.channelRegistry.registerSpecialConfigChannel(AllianceChannel.FILE_NAME, AllianceChannel.class);
}
if (this.config.truceChannel) {
this.channelRegistry.registerSpecialConfigChannel(TruceChannel.FILE_NAME, TruceChannel.class);
}
}
public static ConfigMeta configMeta() {
return Integration.configMeta("factionsuuid", FactionsIntegration.Config.class);
}
@ConfigSerializable
public static final class Config {
boolean enabled = true;
boolean factionChannel = true;
boolean allianceChannel = true;
boolean truceChannel = true;
}
}
@@ -0,0 +1,126 @@
/*
* 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.fuuid;
import com.google.inject.Inject;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.perms.Relation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import net.draycia.carbon.api.channels.ChannelPermissionResult;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.UserManager;
import net.draycia.carbon.common.channels.messages.ConfigChannelMessageSource;
import net.draycia.carbon.common.messages.CarbonMessages;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.key.Key;
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;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import static net.draycia.carbon.api.channels.ChannelPermissionResult.channelPermissionResult;
@DefaultQualifier(NonNull.class)
@ConfigSerializable
public class TruceChannel extends AbstractFactionsChannel {
public static final String FILE_NAME = "factionsuuid-trucechat.conf";
private transient @MonotonicNonNull @Inject CarbonMessages messages;
private transient @MonotonicNonNull @Inject UserManager<?> users;
public TruceChannel() {
this.key = Key.key("carbon", "trucechat");
this.commandAliases = List.of("tc");
this.messageSource = new ConfigChannelMessageSource();
this.messageSource.defaults = Map.of(
"default_format", "(truce: %factionsuuid_faction_name%) <display_name>: <message>",
"console", "[truce: %factionsuuid_faction_name%] <username>: <message>"
);
}
@Override
public ChannelPermissionResult speechPermitted(final CarbonPlayer player) {
return channelPermissionResult(
this.hasRelations(player, Relation.TRUCE),
() -> this.messages.cannotUseTruceChannel(player)
);
}
@Override
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
return channelPermissionResult(
this.hasRelations(player, Relation.TRUCE),
() -> this.messages.cannotUseTruceChannel(player)
);
}
@Override
public List<Audience> recipients(final CarbonPlayer sender) {
if (!this.hasRelations(sender, Relation.TRUCE)) {
if (sender.online()) {
sender.sendMessage(this.messages.cannotUseTruceChannel(sender));
}
return Collections.emptyList();
}
final List<Audience> recipients = new ArrayList<>();
for (final Player player : this.hasTruceWith(sender)) {
final @Nullable CarbonPlayer carbon = this.users.user(player.getUniqueId()).getNow(null);
if (carbon != null) {
recipients.add(carbon);
}
}
recipients.add(this.server.console());
return recipients;
}
private List<Player> hasTruceWith(final CarbonPlayer player) {
final @Nullable Faction faction = this.faction(player);
if (faction == null) {
return List.of();
}
final List<Player> alliedPlayers = new ArrayList<>();
for (final FPlayer onlinePlayer : FPlayers.getInstance().getOnlinePlayers()) {
final Relation relation = faction.getRelationTo(onlinePlayer);
if (relation.isAtLeast(Relation.TRUCE)) {
alliedPlayers.add(onlinePlayer.getPlayer());
}
}
return alliedPlayers;
}
}
@@ -37,7 +37,7 @@ import org.spongepowered.configurate.objectmapping.ConfigSerializable;
@ConfigHeader(ResidentListChannel.TOWNY_CHANNEL_HEADER)
public class AllianceChannel extends NationChannel {
public static final String FILE_NAME = "alliancechat.conf";
public static final String FILE_NAME = "towny-alliancechat.conf";
public AllianceChannel() {
this.key = Key.key("carbon", "alliancechat");
@@ -38,7 +38,7 @@ import org.spongepowered.configurate.objectmapping.ConfigSerializable;
@ConfigHeader(ResidentListChannel.TOWNY_CHANNEL_HEADER)
public class NationChannel extends ResidentListChannel<Nation> {
public static final String FILE_NAME = "nationchat.conf";
public static final String FILE_NAME = "towny-nationchat.conf";
public NationChannel() {
this.key = Key.key("carbon", "nationchat");
@@ -38,7 +38,7 @@ import org.spongepowered.configurate.objectmapping.ConfigSerializable;
@ConfigHeader(ResidentListChannel.TOWNY_CHANNEL_HEADER)
public class TownChannel extends ResidentListChannel<Town> {
public static final String FILE_NAME = "townchat.conf";
public static final String FILE_NAME = "towny-townchat.conf";
public TownChannel() {
this.key = Key.key("carbon", "townchat");
+5
View File
@@ -20,6 +20,11 @@
"matchPackageNames": ["net.fabricmc.fabric-api:fabric-api", "net.fabricmc.fabric-api:fabric-api-deprecated"],
"versioning": "regex:^(?<major>\\d+)(\\.(?<minor>\\d+))?(\\.(?<patch>\\d+))?(?:\\+(?<compatibility>.*))?$"
},
{
"description": "Correct FactionsUUID version handling",
"matchPackageNames": ["com.massivecraft:Factions"],
"versioning": "regex:^1\\.6\\.9\\.5\\-U(?<major>\\d+)(\\.(?<minor>\\d+))?(\\.(?<patch>\\d+))?$"
},
{
"matchManagers": ["github-actions", "gradle-wrapper"],
"groupName": "gradle and github actions"
+5 -1
View File
@@ -53,6 +53,10 @@ dependencyResolutionManagement {
maven("https://repo.glaremasters.me/repository/towny/") {
content { includeGroup("com.palmergames.bukkit.towny") }
}
// FactionsUUID
maven("https://ci.ender.zone/plugin/repository/everything/") {
content { includeGroup("com.massivecraft") }
}
}
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
}
@@ -78,7 +82,7 @@ plugins {
rootProject.name = "CarbonChat"
sequenceOf(
listOf(
"api",
"common",
"paper",