Skip to content

Commit

Permalink
Merge pull request #60 from Global-Tags/feat/emailConnection
Browse files Browse the repository at this point in the history
feat: Implement email connection
  • Loading branch information
RappyTV authored Sep 28, 2024
2 parents 908935a + ee33732 commit 344283e
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 44 deletions.
2 changes: 1 addition & 1 deletion api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import net.labymod.labygradle.common.extension.LabyModAnnotationProcessorExtensi
dependencies {
labyProcessor()
labyApi("api")
addonMavenDependency("com.rappytv.globaltags:GlobalTagsJava:1.1.2")
addonMavenDependency("com.rappytv.globaltags:GlobalTagsJava:1.1.3")
}

labyModAnnotationProcessor {
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import net.labymod.labygradle.common.extension.LabyModAnnotationProcessorExtensi
dependencies {
labyProcessor()
api(project(":api"))
addonMavenDependency("com.rappytv.globaltags:GlobalTagsJava:1.1.2")
addonMavenDependency("com.rappytv.globaltags:GlobalTagsJava:1.1.3")
}

labyModAnnotationProcessor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import com.rappytv.globaltags.command.subcommands.ClearCacheCommand;
import com.rappytv.globaltags.command.subcommands.LinkDiscordSubcommand;
import com.rappytv.globaltags.command.subcommands.RenewCacheCommand;
import com.rappytv.globaltags.command.subcommands.UnlinkDiscordSubcommand;
import com.rappytv.globaltags.command.subcommands.UnlinkSubcommand;
import com.rappytv.globaltags.command.subcommands.VerifyCommand;
import net.labymod.api.client.chat.command.Command;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.TextComponent;
Expand All @@ -27,7 +28,8 @@ public GlobalTagCommand(GlobalTagAddon addon) {
withSubCommand(new ClearCacheCommand(api));
withSubCommand(new LinkDiscordSubcommand(api));
withSubCommand(new RenewCacheCommand(api));
withSubCommand(new UnlinkDiscordSubcommand(api));
withSubCommand(new UnlinkSubcommand(api));
withSubCommand(new VerifyCommand(api));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import net.labymod.api.Laby;
import net.labymod.api.client.chat.command.SubCommand;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.event.ClickEvent;
import net.labymod.api.client.component.event.HoverEvent;
import net.labymod.api.client.component.format.NamedTextColor;
import net.labymod.api.client.component.format.TextDecoration;

public class LinkDiscordSubcommand extends SubCommand {

Expand All @@ -17,22 +20,82 @@ public LinkDiscordSubcommand(GlobalTagAPI api) {
}

@Override
public boolean execute(String s, String[] strings) {
api.getApiHandler().linkDiscord((info) -> {
if(info.successful()) {
String code = info.data();
Laby.references().chatExecutor().copyToClipboard(code);
displayMessage(GlobalTagAddon.prefix.copy().append(Component.translatable(
"globaltags.commands.link.discord.copied",
NamedTextColor.GREEN
)));
} else displayMessage(
GlobalTagAddon.prefix.copy().append(Component.text(
info.data(),
NamedTextColor.RED
))
);
});
public boolean execute(String prefix, String[] arguments) {
switch (arguments.length > 0 ? arguments[0].toLowerCase() : "none") {
case "discord":
api.getApiHandler().linkDiscord((info) -> {
if (info.successful()) {
String code = info.data();
Laby.references().chatExecutor().copyToClipboard(code);
displayMessage(GlobalTagAddon.prefix.copy().append(Component.translatable(
"globaltags.commands.link.discord.copied",
NamedTextColor.GREEN
)));
} else {
displayMessage(
GlobalTagAddon.prefix.copy().append(Component.text(
info.data(),
NamedTextColor.RED
))
);
}
});
break;
case "email":
if (arguments.length < 2) {
displayMessage(
Component.empty()
.append(GlobalTagAddon.prefix)
.append(Component.translatable(
"globaltags.commands.usage",
NamedTextColor.RED,
Component.text("/gt link email <address>")
))
);
return true;
}

api.getApiHandler().linkEmail(arguments[1], (info) -> {
if (info.successful()) {
displayMessage(
Component.empty()
.append(GlobalTagAddon.prefix)
.append(Component.text(info.data(), NamedTextColor.GREEN))
.append(Component.newline())
.append(GlobalTagAddon.prefix)
.append(
Component.translatable(
"globaltags.commands.link.email.verify",
NamedTextColor.AQUA
)
.decorate(TextDecoration.UNDERLINED)
.clickEvent(ClickEvent.suggestCommand("/gt verify email "))
.hoverEvent(HoverEvent.showText(
Component.translatable(
"globaltags.commands.link.email.hover")
))
)
);
} else {
displayMessage(
Component.empty()
.append(GlobalTagAddon.prefix)
.append(Component.text(info.data(), NamedTextColor.RED))
);
}
});
break;
default:
displayMessage(
Component.empty()
.append(GlobalTagAddon.prefix)
.append(Component.translatable(
"globaltags.commands.usage",
NamedTextColor.RED,
Component.text("/gt link <discord/email>")
))
);
}
return true;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.rappytv.globaltags.command.subcommands;

import com.rappytv.globaltags.api.GlobalTagAPI;
import com.rappytv.globaltags.GlobalTagAddon;
import com.rappytv.globaltags.api.Util;
import net.labymod.api.client.chat.command.SubCommand;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.format.NamedTextColor;

public class UnlinkSubcommand extends SubCommand {

private final GlobalTagAPI api;

public UnlinkSubcommand(GlobalTagAPI api) {
super("unlink");
this.api = api;
}

@Override
public boolean execute(String prefix, String[] arguments) {
switch (arguments.length > 0 ? arguments[0].toLowerCase() : "none") {
case "discord":
api.getApiHandler().unlinkDiscord((response) -> displayMessage(
GlobalTagAddon.prefix.copy().append(Util.getResponseComponent(response)))
);
break;
case "email":
api.getApiHandler().unlinkEmail((response) -> displayMessage(
GlobalTagAddon.prefix.copy().append(Util.getResponseComponent(response)))
);
break;
default:
displayMessage(
Component.empty()
.append(GlobalTagAddon.prefix)
.append(Component.translatable(
"globaltags.commands.usage",
NamedTextColor.RED,
Component.text("/gt unlink <discord/email>")
))
);
}
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.rappytv.globaltags.command.subcommands;

import com.rappytv.globaltags.GlobalTagAddon;
import com.rappytv.globaltags.api.GlobalTagAPI;
import com.rappytv.globaltags.api.Util;
import net.labymod.api.client.chat.command.SubCommand;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.format.NamedTextColor;

public class VerifyCommand extends SubCommand {

private final GlobalTagAPI api;

public VerifyCommand(GlobalTagAPI api) {
super("verify");
this.api = api;
}

@Override
public boolean execute(String prefix, String[] arguments) {
switch (arguments.length > 0 ? arguments[0].toLowerCase() : "none") {
case "email":
if(arguments.length < 2) {
displayMessage(
Component.empty()
.append(GlobalTagAddon.prefix)
.append(Component.translatable(
"globaltags.commands.usage",
NamedTextColor.RED,
Component.text("/gt verify email <code>")
))
);
return true;
}

api.getApiHandler().verifyEmail(arguments[1], (response) -> displayMessage(
GlobalTagAddon.prefix.copy().append(Util.getResponseComponent(response))
));
break;
default:
displayMessage(
Component.empty()
.append(GlobalTagAddon.prefix)
.append(Component.translatable(
"globaltags.commands.usage",
NamedTextColor.RED,
Component.text("/gt verify email <code>")
))
);
}
return true;
}
}
5 changes: 5 additions & 0 deletions core/src/main/resources/assets/globaltags/i18n/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"error": "Es ist ein Fehler aufgetreten"
},
"commands": {
"usage": "Benutzung: %s",
"base": {
"version": "Addon Version: %s",
"api": {
Expand All @@ -148,6 +149,10 @@
"link": {
"discord": {
"copied": "Der Code wurde in deine Zwischenablage kopiert!"
},
"email": {
"verify": "Email verifizieren",
"hover": "Klicke, um den Verifizierungscode einzugeben"
}
}
},
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/resources/assets/globaltags/i18n/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"error": "An error ocurred"
},
"commands": {
"usage": "Usage: %s",
"base": {
"version": "Addon Version: %s",
"api": {
Expand All @@ -148,6 +149,10 @@
"link": {
"discord": {
"copied": "The code was copied to your clipboard!"
},
"email": {
"verify": "Verify email",
"hover": "Click to enter verification code"
}
}
},
Expand Down

0 comments on commit 344283e

Please sign in to comment.