Skip to content

Commit

Permalink
Fix logic, rename messages
Browse files Browse the repository at this point in the history
  • Loading branch information
CitralFlo committed Jan 22, 2025
1 parent f054dbd commit 2437624
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public interface MsgToggleService {

CompletableFuture<Boolean> hasMsgToggledOff(UUID uuid);
CompletableFuture<Boolean> hasMsgToggled(UUID uuid);

void toggleMsg(UUID uuid, boolean toggle);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,43 @@ public MsgToggleCommand(MsgToggleService msgToggleService, NoticeService noticeS
this.noticeService = noticeService;
}

public enum STATE {
ON,
OFF
}

@Execute
@DescriptionDocs(description = "Toggle private messages")
@DescriptionDocs(description = "Toggle receiving private messages on and off")
public void execute(@Context Player context) {

CompletableFuture<Boolean> hasMsgToggledOff = this.msgToggleService.hasMsgToggledOff(context.getUniqueId());
CompletableFuture<Boolean> hasMsgToggledOff = this.msgToggleService.hasMsgToggled(context.getUniqueId());

hasMsgToggledOff.thenAccept(toggledOff -> {
if (!toggledOff) {
this.on(context);
this.toggleOff(context);
} else {
this.off(context);
this.toggleOn(context);
}
});
}

@Execute(name = "off")
@DescriptionDocs(description = "Enable private messages")
public void on(@Context Player context) {
@Execute(name = "on")
@DescriptionDocs(description = "Block incoming private messages")
public void toggleOn(@Context Player context) {
this.msgToggleService.toggleMsg(context.getUniqueId(), true);

this.noticeService.create()
.notice(translation -> translation.privateChat().msgToggleSelfOn())
.notice(translation -> translation.privateChat().msgToggledSelf())
.player(context.getUniqueId())
.send();
}

@Execute(name = "on")
@DescriptionDocs(description = "Disable private messages")
public void off(@Context Player context) {
@Execute(name = "off")
@DescriptionDocs(description = "Unblock incoming private messages")
public void toggleOff(@Context Player context) {
this.msgToggleService.toggleMsg(context.getUniqueId(), false);

this.noticeService.create()
.notice(translation -> translation.privateChat().msgToggleSelfOff())
.notice(translation -> translation.privateChat().msgUntoggleSelf())
.player(context.getUniqueId())
.send();
}
Expand All @@ -68,7 +72,7 @@ public void off(@Context Player context) {
@Permission("eternalcore.msgtoggle.other")
@DescriptionDocs(description = "Toggle private messages for other player", arguments = "<player>")
public void other(@Context Player context, @Arg("player") Player player) {
CompletableFuture<Boolean> hasMsgToggledOff = this.msgToggleService.hasMsgToggledOff(player.getUniqueId());
CompletableFuture<Boolean> hasMsgToggledOff = this.msgToggleService.hasMsgToggled(player.getUniqueId());

hasMsgToggledOff.thenAccept(toggledOff -> this.other(context, player, !toggledOff ? STATE.ON : STATE.OFF));
}
Expand All @@ -82,17 +86,13 @@ public void other(@Context Player context, @Arg("player") Player player, @Arg("<
this.noticeService.create()
.notice(
translation -> toggle == STATE.ON ?
translation.privateChat().msgTogglePlayerOn() :
translation.privateChat().msgTogglePlayerOff()
translation.privateChat().msgUntogglePlayer() :
translation.privateChat().msgToggledPlayer()
)
.player(context.getUniqueId())
.placeholder("{PLAYER}", player.getName())
.send();

}

public enum STATE {
ON,
OFF
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public interface MsgToggleRepository {

CompletableFuture<Boolean> isToggledOff(UUID uuid);
CompletableFuture<Boolean> isToggled(UUID uuid);

CompletableFuture<Void> setToggledOff(UUID uuid, boolean toggledOff);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private MsgToggleRepositoryOrmLite(DatabaseManager databaseManager, Scheduler sc
}

@Override
public CompletableFuture<Boolean> isToggledOff(UUID uuid) {
public CompletableFuture<Boolean> isToggled(UUID uuid) {
return this.selectSafe(MsgToggleWrapper.class, uuid)
.thenApply(
optional -> optional.map(MsgToggleWrapper::isEnabled).orElse(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public MsgToggleServiceImpl(MsgToggleRepository msgToggleRepository) {


@Override
public CompletableFuture<Boolean> hasMsgToggledOff(UUID uuid) {
return this.msgToggleRepository.isToggledOff(uuid);
public CompletableFuture<Boolean> hasMsgToggled(UUID uuid) {
return this.msgToggleRepository.isToggled(uuid);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ void privateMessage(User sender, User target, String message) {

UUID uniqueId = target.getUniqueId();

this.msgToggleService.hasMsgToggledOff(uniqueId).thenAccept(hasToggledOff -> {
if (hasToggledOff) {
this.msgToggleService.hasMsgToggled(uniqueId).thenAccept(hasMsgToggled -> {
if (hasMsgToggled) {
this.noticeService.player(sender.getUniqueId(), translation -> translation.privateChat().msgToggledOff());

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ interface PrivateChatSection {
Notice socialSpyDisable();

Notice msgToggledOff();
Notice msgToggleSelfOff();
Notice msgToggleSelfOn();
Notice msgTogglePlayerOff();
Notice msgTogglePlayerOn();
Notice msgToggledSelf();
Notice msgUntoggleSelf();
Notice msgToggledPlayer();
Notice msgUntogglePlayer();

Notice ignorePlayer();
Notice ignoreAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,12 @@ public static class ENPrivateSection implements PrivateChatSection {

public Notice msgToggledOff = Notice.chat("<red>► <dark_red>This player has disabled private messages!");

public Notice msgToggleSelfOff = Notice.chat("<green>► <white>Private messages have been <red>disabled<white>!");
public Notice msgToggleSelfOn = Notice.chat("<green>► <white>Private messages have been <green>enabled<white>!");
public Notice msgToggledSelf = Notice.chat("<green>► <white>Private messages have been <red>disabled<white>!");
public Notice msgUntoggleSelf = Notice.chat("<green>► <white>Private messages have been <green>enabled<white>!");

@Description("# {PLAYER} - Player")
public Notice msgTogglePlayerOff = Notice.chat("<green>► <white>Private messages have been disabled for <green>{PLAYER}<white>!");
public Notice msgTogglePlayerOn = Notice.chat("<green>► <white>Private messages have been enabled for <green>{PLAYER}<white>!");
public Notice msgToggledPlayer = Notice.chat("<green>► <white>Private messages have been disabled for <green>{PLAYER}<white>!");
public Notice msgUntogglePlayer = Notice.chat("<green>► <white>Private messages have been enabled for <green>{PLAYER}<white>!");



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,12 @@ public static class PLPrivateChatSection implements PrivateChatSection {

public Notice msgToggledOff = Notice.chat("<red>► <dark_red>Wiadomości prywatne zostały wyłączone!");

public Notice msgToggleSelfOff = Notice.chat("<green>► <white>Wiadomości prywatne zostały <red>wyłączone!");
public Notice msgToggleSelfOn = Notice.chat("<green>► <white>Wiadomości prywatne zostały <green>włączone!");
public Notice msgToggledSelf = Notice.chat("<green>► <white>Wiadomości prywatne zostały <red>wyłączone!");
public Notice msgUntoggleSelf = Notice.chat("<green>► <white>Wiadomości prywatne zostały <green>włączone!");

@Description({" ", "# {PLAYER} - Gracz któremu wyłączono wiadomości prywatne"})
public Notice msgTogglePlayerOff = Notice.chat("<green>► <white>Wiadomości prywatne zostały <red>wyłączone <white>dla gracza <green>{PLAYER}<white>!");
public Notice msgTogglePlayerOn = Notice.chat("<green>► <white>Wiadomości prywatne zostały <green>włączone <white>dla gracza <green>{PLAYER}<white>!");
public Notice msgToggledPlayer = Notice.chat("<green>► <white>Wiadomości prywatne zostały <red>wyłączone <white>dla gracza <green>{PLAYER}<white>!");
public Notice msgUntogglePlayer = Notice.chat("<green>► <white>Wiadomości prywatne zostały <green>włączone <white>dla gracza <green>{PLAYER}<white>!");

@Description({" ", "# {PLAYER} - Gracz który jest zignorowany"})
public Notice ignorePlayer = Notice.chat("<green>► <white>Zignorowano gracza <red>{PLAYER}<white>!");
Expand Down

0 comments on commit 2437624

Please sign in to comment.