mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 14:38:48 +00:00
Add context error messages
This commit is contained in:
1 parent
e03b43119b
commit
1685fa6ba9
9 files changed
+57
-40
No files matched your search
@@ -28,6 +28,7 @@ public final class CarbonTranslations {
|
||||
}
|
||||
|
||||
private ExceptionMessages exceptionMessages = new ExceptionMessages();
|
||||
private ContextMessages contextMessages = new ContextMessages();
|
||||
|
||||
@Setting private String reloaded = "<yellow>Chat config has been reloaded!";
|
||||
@Setting private String otherPlayerOffline = "<red>That player is offline!";
|
||||
@@ -69,6 +70,10 @@ public final class CarbonTranslations {
|
||||
return this.exceptionMessages;
|
||||
}
|
||||
|
||||
public ContextMessages contextMessages() {
|
||||
return this.contextMessages;
|
||||
}
|
||||
|
||||
public String reloaded() {
|
||||
return this.reloaded;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.draycia.carbon.api.config;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Setting;
|
||||
|
||||
@ConfigSerializable
|
||||
public final class ContextMessages {
|
||||
|
||||
@Setting private @NonNull String vaultBalanceNotEnough = "<red>You do not have enough balance, required: <balance><red>.";
|
||||
@Setting private @NonNull String vaultCostNotEnough = "<red>You do not have enough balance, cost: <balance><red>.";
|
||||
@Setting private @NonNull String mcmmoPartyNotInParty = "<red>You are not in a party!";
|
||||
@Setting private @NonNull String townyTownNotInTown = "<red>You are not in a town!";
|
||||
|
||||
public String vaultBalanceNotEnough() {
|
||||
return this.vaultBalanceNotEnough;
|
||||
}
|
||||
|
||||
public String vaultCostNotEnough() {
|
||||
return this.vaultCostNotEnough;
|
||||
}
|
||||
|
||||
public String mcmmoPartyNotInParty() {
|
||||
return this.mcmmoPartyNotInParty;
|
||||
}
|
||||
|
||||
public String townyTownNotInTown() {
|
||||
return this.townyTownNotInTown;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
package net.draycia.carbon.api.users;
|
||||
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.identity.Identified;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public interface CarbonUser extends Audience, Identified {
|
||||
|
||||
@@ -12,14 +10,4 @@ public interface CarbonUser extends Audience, Identified {
|
||||
|
||||
@NonNull String name();
|
||||
|
||||
@Nullable ChatChannel selectedChannel();
|
||||
|
||||
default void selectedChannel(@NonNull final ChatChannel channel) {
|
||||
this.selectedChannel(channel, false);
|
||||
}
|
||||
|
||||
void selectedChannel(@NonNull ChatChannel channel, boolean fromRemote);
|
||||
|
||||
void clearSelectedChannel();
|
||||
|
||||
}
|
||||
@@ -107,4 +107,14 @@ public interface PlayerUser extends CarbonUser {
|
||||
|
||||
void sendMessage(@NonNull final PlayerUser sender, @NonNull String message);
|
||||
|
||||
@Nullable ChatChannel selectedChannel();
|
||||
|
||||
default void selectedChannel(@NonNull final ChatChannel channel) {
|
||||
this.selectedChannel(channel, false);
|
||||
}
|
||||
|
||||
void selectedChannel(@NonNull ChatChannel channel, boolean fromRemote);
|
||||
|
||||
void clearSelectedChannel();
|
||||
|
||||
}
|
||||
+2
-2
@@ -50,7 +50,7 @@ public class EconomyContext {
|
||||
event.cancelled(true);
|
||||
|
||||
event.user().sendMessage(Identity.nil(), this.carbonChat.messageProcessor()
|
||||
.processMessage(event.channel().cannotUseMessage()));
|
||||
.processMessage(this.carbonChat.translations().contextMessages().vaultBalanceNotEnough()));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -84,7 +84,7 @@ public class EconomyContext {
|
||||
event.cancelled(true);
|
||||
|
||||
event.user().sendMessage(Identity.nil(), this.carbonChat.messageProcessor()
|
||||
.processMessage(event.channel().cannotUseMessage()));
|
||||
.processMessage(this.carbonChat.translations().contextMessages().vaultCostNotEnough()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
+5
-3
@@ -48,18 +48,20 @@ public final class TownyContext implements Listener {
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean()) {
|
||||
if (!this.isInTown(event.user())) {
|
||||
//event.failureMessage(carbonChat.getConfig().getString("contexts.Towny.cancellation-message"));
|
||||
event.failureMessage(this.carbonChat.translations().contextMessages().townyTownNotInTown());
|
||||
event.cancelled(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
CarbonEvents.register(MessageContextEvent.class, PostOrders.NORMAL, false, event -> {
|
||||
// TODO: event.setFailureMessage
|
||||
final Context context = event.channel().context(KEY);
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean()) {
|
||||
if (!this.isInTown(event.user())) {
|
||||
event.user().sendMessage(this.carbonChat.messageProcessor().processMessage(
|
||||
this.carbonChat.translations().contextMessages().townyTownNotInTown()));
|
||||
|
||||
event.cancelled(!this.isInTown(event.user()));
|
||||
}
|
||||
}
|
||||
@@ -69,7 +71,7 @@ public final class TownyContext implements Listener {
|
||||
@EventHandler
|
||||
public void onResidentRemove(final TownRemoveResidentEvent event) {
|
||||
final String name = event.getResident().getName();
|
||||
final CarbonUser user = this.carbonChat.userService().wrap(Bukkit.getPlayer(name).getUniqueId());
|
||||
final PlayerUser user = this.carbonChat.userService().wrap(Bukkit.getPlayer(name).getUniqueId());
|
||||
final ChatChannel channel = user.selectedChannel();
|
||||
|
||||
if (!(channel instanceof TextChannel)) {
|
||||
|
||||
+4
-2
@@ -32,7 +32,6 @@ public final class mcMMOContext implements Listener {
|
||||
final Context context = event.channel().context(KEY);
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean()) {
|
||||
// TODO: failureMessage
|
||||
event.cancelled(!this.isInSameParty(event.sender(), event.recipient()));
|
||||
}
|
||||
});
|
||||
@@ -47,7 +46,7 @@ public final class mcMMOContext implements Listener {
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean()) {
|
||||
if (!this.isInParty(event.user())) {
|
||||
//event.failureMessage(carbonChat.carbonSettings().getString("contexts.mcMMO.cancellation-message"));
|
||||
event.failureMessage(this.carbonChat.translations().contextMessages().mcmmoPartyNotInParty());
|
||||
event.cancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -57,6 +56,9 @@ public final class mcMMOContext implements Listener {
|
||||
final Context context = event.channel().context(KEY);
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean()) {
|
||||
event.user().sendMessage(this.carbonChat.messageProcessor().processMessage(
|
||||
this.carbonChat.translations().contextMessages().mcmmoPartyNotInParty()));
|
||||
|
||||
event.cancelled(!this.isInParty(event.user()));
|
||||
}
|
||||
});
|
||||
|
||||
-3
@@ -30,9 +30,6 @@ public class BukkitChatListener implements Listener {
|
||||
// Chat messages
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerchat(@NonNull final AsyncPlayerChatEvent event) {
|
||||
// TODO: Move most of this to Common handling
|
||||
// TODO: ChatMessageEvent that's called at the start of this
|
||||
// TODO: Obtain a component (for console usage) from that event, or another
|
||||
final PlayerUser user = this.carbonChat.userService().wrap(event.getPlayer().getUniqueId());
|
||||
ChatChannel channel = user.selectedChannel();
|
||||
|
||||
|
||||
-18
@@ -1,6 +1,5 @@
|
||||
package net.draycia.carbon.bukkit.users;
|
||||
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ConsoleUser;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
@@ -10,7 +9,6 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class BukkitConsoleUser implements ConsoleUser, ForwardingAudience.Single {
|
||||
|
||||
@@ -42,20 +40,4 @@ public class BukkitConsoleUser implements ConsoleUser, ForwardingAudience.Single
|
||||
return "Console";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ChatChannel selectedChannel() {
|
||||
// TODO: stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectedChannel(@NonNull final ChatChannel channel, final boolean fromRemote) {
|
||||
// TODO: stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearSelectedChannel() {
|
||||
// TODO: stub
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user