Skip to content

Commit

Permalink
Fix logic
Browse files Browse the repository at this point in the history
  • Loading branch information
CitralFlo committed Jan 17, 2025
1 parent 43ea1b0 commit f054dbd
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

public class MsgToggle {

private final UUID uuid;
private final boolean toggle;
UUID uuid;
boolean toggle;

public MsgToggle() {

}

public MsgToggle(UUID uuid, boolean toggle) {
this.uuid = uuid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import java.util.concurrent.CompletableFuture;
import org.bukkit.entity.Player;

// To clarify:
// ON - true - means that the player has turned on msgToggle and has blocked getting private messages
// OFF - false - means that the player has turned off msgToggle and has allowed getting private messages
@Command(name = "msgtoggle")
@Permission("eternalcore.msgtoggle")
public class MsgToggleCommand {
Expand All @@ -31,15 +34,15 @@ public void execute(@Context Player context) {
CompletableFuture<Boolean> hasMsgToggledOff = this.msgToggleService.hasMsgToggledOff(context.getUniqueId());

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

@Execute(name = "on")
@Execute(name = "off")
@DescriptionDocs(description = "Enable private messages")
public void on(@Context Player context) {
this.msgToggleService.toggleMsg(context.getUniqueId(), true);
Expand All @@ -50,7 +53,7 @@ public void on(@Context Player context) {
.send();
}

@Execute(name = "off")
@Execute(name = "on")
@DescriptionDocs(description = "Disable private messages")
public void off(@Context Player context) {
this.msgToggleService.toggleMsg(context.getUniqueId(), false);
Expand All @@ -67,7 +70,7 @@ public void off(@Context Player context) {
public void other(@Context Player context, @Arg("player") Player player) {
CompletableFuture<Boolean> hasMsgToggledOff = this.msgToggleService.hasMsgToggledOff(player.getUniqueId());

hasMsgToggledOff.thenAccept(toggledOff -> this.other(context, player, toggledOff ? STATE.ON : STATE.OFF));
hasMsgToggledOff.thenAccept(toggledOff -> this.other(context, player, !toggledOff ? STATE.ON : STATE.OFF));
}

@Execute
Expand All @@ -82,7 +85,8 @@ public void other(@Context Player context, @Arg("player") Player player, @Arg("<
translation.privateChat().msgTogglePlayerOn() :
translation.privateChat().msgTogglePlayerOff()
)
.player(player.getUniqueId())
.player(context.getUniqueId())
.placeholder("{PLAYER}", player.getName())
.send();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public interface MsgToggleRepository {

CompletableFuture<Boolean> isToggledOff(UUID uuid);

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public CompletableFuture<Boolean> isToggledOff(UUID uuid) {
}

@Override
public void setToggledOff(UUID uuid, boolean toggledOff) {
this.save(MsgToggle.class, new MsgToggle(uuid, toggledOff));
public CompletableFuture<Void> setToggledOff(UUID uuid, boolean toggledOff) {
return this.save(MsgToggleWrapper.class, new MsgToggleWrapper(uuid, toggledOff))
.thenApply(status -> null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@
import com.j256.ormlite.table.DatabaseTable;
import java.util.UUID;

@DatabaseTable(tableName = "msgtoggle")
@DatabaseTable(tableName = "eternal_core_msg_toggles")
class MsgToggleWrapper {

@DatabaseField(columnName = "id", id = true)
private UUID id;
private UUID uniqueId;

@DatabaseField(columnName = "enabled")
private boolean enabled;

MsgToggleWrapper() {
}

MsgToggleWrapper(UUID id, boolean enabled) {
this.id = id;
this.uniqueId = id;
this.enabled = enabled;
}

static MsgToggleWrapper from(MsgToggleWrapper msgToggle) {
return new MsgToggleWrapper(msgToggle.id, msgToggle.enabled);
MsgToggleWrapper() {}

static MsgToggleWrapper from(MsgToggle msgToggle) {
return new MsgToggleWrapper(msgToggle.uuid, msgToggle.toggle);
}

boolean isEnabled() {
Expand All @@ -32,5 +31,4 @@ boolean isEnabled() {
void setEnabled(boolean enabled) {
this.enabled = enabled;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,10 @@ public static class ENPrivateSection implements PrivateChatSection {
public Notice socialSpyDisable = Notice.chat("<red>► <white>SocialSpy has been {STATE}<white>!");


public Notice msgToggledOff = Notice.chat("<red>► <dark_red> This player has disabled private messages!");
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 disabled!");
public Notice msgToggleSelfOn = Notice.chat("<green>► <white>Private messages have been enabled!");
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>!");

@Description("# {PLAYER} - Player")
public Notice msgTogglePlayerOff = Notice.chat("<green>► <white>Private messages have been disabled 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 wyłączone!");
public Notice msgToggleSelfOn = Notice.chat("<green>► <white>Wiadomości prywatne zostały włą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!");

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

@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 f054dbd

Please sign in to comment.