Skip to content

Commit

Permalink
Added msg translation with HexColor, in config.yml and classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloB07 committed Sep 28, 2024
1 parent 6251d54 commit 287ae13
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.UUID;

import com.posthog.java.shaded.org.jetbrains.annotations.NotNull;
import org.bukkit.Color;
import org.worldcoin.bukkit.plugin.worldid.WorldId;
import org.worldcoin.bukkit.plugin.worldid.tasks.CheckVerified;

Expand All @@ -14,45 +16,52 @@
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.worldcoin.bukkit.plugin.worldid.utils.ColorUtils;

public class VerifyCommand implements CommandExecutor {

private WorldId plugin = WorldId.getPlugin(WorldId.class);
private final WorldId plugin = WorldId.getPlugin(WorldId.class);

private FileConfiguration config = plugin.getConfig();
private String orbGroupName = config.getString("orb-group-name");
private String deviceGroupName = config.getString("device-group-name");
private String baseUrl = config.getString("web-url");
private String serverUUID = config.getString("server-uuid");
private final FileConfiguration config = plugin.getConfig();

private final String verifyAlreadyVerified = config.getString("messages.verify-already-verified");
private final String verifyClickHere = config.getString("messages.verify-click-here");
private final String verifyNow = config.getString("messages.verify-now");

private final String orbGroupName = config.getString("orb-group-name");
private final String deviceGroupName = config.getString("device-group-name");
private final String baseUrl = config.getString("web-url");
private final String serverUUID = config.getString("server-uuid");

@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] strings) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {

if (sender instanceof Player) {
Player player = (Player) sender;
if (sender instanceof Player player) {

if (player.hasPermission("group." + orbGroupName) | player.hasPermission("group." + deviceGroupName)) {
player.sendMessage("You've already been verified with World ID!");
if (player.hasPermission("group." + orbGroupName) || player.hasPermission("group." + deviceGroupName)) {
player.sendMessage(ColorUtils.colorize(verifyAlreadyVerified));
return true;
}
UUID reqUUID = UUID.randomUUID();
String url = baseUrl + "/verify?reqUUID=" + reqUUID + "&serverUUID=" + serverUUID;

player.sendMessage("Click here to verify with World ID:");
player.sendMessage("");
player.sendMessage(ColorUtils.colorize(verifyClickHere));
player.sendMessage("----------------------------------------");

// player.spigot().sendMessage( new TextComponent(" "));

TextComponent button = new TextComponent("Verify!");
button.setColor(ChatColor.WHITE);
TextComponent button = new TextComponent(ColorUtils.colorize(verifyNow));
// button.setColor(ChatColor.WHITE);
button.setBold(true);
button.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url));

player.spigot().sendMessage( button );
player.sendMessage("");
player.sendMessage("----------------------------------------");

new CheckVerified(player, reqUUID, 20).runTaskTimerAsynchronously(plugin, 100, 200);
return true;
} else {
sender.sendMessage("You must be a player!");
sender.sendMessage(ColorUtils.colorize("You must be a player to use this!"));
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.worldcoin.bukkit.plugin.worldid.utils.ColorUtils;

public class JoinListener implements Listener {

private WorldId plugin = WorldId.getPlugin(WorldId.class);
private final WorldId plugin = WorldId.getPlugin(WorldId.class);

private FileConfiguration config = plugin.getConfig();
private String orbGroupName = config.getString("orb-group-name");
private String deviceGroupName = config.getString("device-group-name");
private final FileConfiguration config = plugin.getConfig();
private final String orbGroupName = config.getString("orb-group-name");
private final String deviceGroupName = config.getString("device-group-name");
private final String welcomeMsg = config.getString("listener-messages.welcome-msg");
private final String verifyWelcomeMsg = config.getString("listener-messages.verify-welcome-msg");
private final String verifyToMsg = config.getString("listener-messages.verify-to-msg");
private final String verifyMsg = config.getString("listener-messages.verify-msg");

public JoinListener(WorldId plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
Expand All @@ -23,12 +28,12 @@ public JoinListener(WorldId plugin) {
@EventHandler
public void join(PlayerJoinEvent event) {
Player player = event.getPlayer();
player.sendMessage("Welcome to the server!");
player.sendMessage(ColorUtils.colorize(welcomeMsg));
if (player.hasPermission("group."+orbGroupName) || player.hasPermission("group."+deviceGroupName)) {
player.sendMessage("You've been verified with World ID!");
player.sendMessage(ColorUtils.colorize(verifyWelcomeMsg));
} else {
player.sendMessage("You haven't been verified with World ID!");
player.sendMessage("You can get permissions by typing the `/verify` command to verify with World ID.");
player.sendMessage(ColorUtils.colorize(verifyToMsg));
player.sendMessage(ColorUtils.colorize(verifyMsg));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,34 @@
import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.node.types.InheritanceNode;
import net.luckperms.api.model.user.User;
import org.worldcoin.bukkit.plugin.worldid.utils.ColorUtils;

public class CheckVerified extends BukkitRunnable {

private WorldId plugin = WorldId.getPlugin(WorldId.class);
private final WorldId plugin = WorldId.getPlugin(WorldId.class);

private final Player player;
private final String webUrl;
private int counter;

private FileConfiguration config = plugin.getConfig();
private String orbGroupName = config.getString("orb-group-name");
private String deviceGroupName = config.getString("device-group-name");
private String baseUrl = config.getString("web-url");
private final FileConfiguration config = plugin.getConfig();

private final String verifySuccess = config.getString("messages.verify-success");
private final String verifyFailed = config.getString("messages.verify-failure");
private final String verifyError = config.getString("messages.verify-error");

private final String verifyLevel = config.getString("messages.verify-level");
private final String verifyInvalid = config.getString("messages.verify-invalid");

private final String orbGroupName = config.getString("orb-group-name");
private final String deviceGroupName = config.getString("device-group-name");

PostHog posthog = new PostHog.Builder(WorldId.POSTHOG_API_KEY).host(WorldId.POSTHOG_HOST).build();

public CheckVerified(Player player, UUID uuid, int counter) {
this.player = player;
this.webUrl = baseUrl+"/api/isVerified?id="+uuid;
String baseUrl = config.getString("web-url");
this.webUrl = baseUrl +"/api/isVerified?id="+uuid;
if (counter <= 0) {
throw new IllegalArgumentException("counter must be greater than 0");
} else {
Expand Down Expand Up @@ -64,20 +73,19 @@ public Boolean handleResponse(final ClassicHttpResponse response) throws IOExcep
case "device":
groupName = deviceGroupName;
if (groupName == null) {
player.sendMessage("This Verification Level is not accepted.");
player.sendMessage(ColorUtils.colorize(verifyLevel));
CheckVerified.this.cancel();
return false;
}
break;
default:
groupName = null;
player.sendMessage("Invalid Verification Level.");
CheckVerified.this.cancel();
player.sendMessage(ColorUtils.colorize(verifyInvalid));
return false;
}

if (player.hasPermission("group." + groupName)) {
throw new IllegalStateException("player is already verified");
throw new IllegalStateException("Player is already verified.");
}

final LuckPerms api = LuckPermsProvider.get();
Expand All @@ -86,7 +94,7 @@ public Boolean handleResponse(final ClassicHttpResponse response) throws IOExcep
user.data().add(node);
user.setPrimaryGroup(groupName);
api.getUserManager().saveUser(user);
player.sendMessage("You've successfully verified with World ID!");
player.sendMessage(ColorUtils.colorize(verifySuccess));
posthog.capture(player.getUniqueId().toString(), "minecraft integration verification", new HashMap<String, Object>() {
{
put("verification_level", verification_level);
Expand All @@ -101,13 +109,13 @@ public Boolean handleResponse(final ClassicHttpResponse response) throws IOExcep
}
});
} catch (Exception e) {
player.sendMessage("Error while verifying with World ID: ", e.toString());
player.sendMessage(ColorUtils.colorize(verifyError + e.getMessage()));
this.cancel();
} finally {
counter--;
}
} else {
player.sendMessage("Timed out waiting for verification. Please try again.");
player.sendMessage(ColorUtils.colorize(verifyFailed));
this.cancel();
}
}
Expand Down
21 changes: 20 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,23 @@ server-uuid: ""
orb-group-name: "orb-humans"
# If you want to require Orb verification, leave device-group-name blank.
device-group-name: "device-humans"
web-url: "https://minecraft.worldcoin.org"
web-url: "https://minecraft.worldcoin.org"

# Messages with Hex colors. use with this format: <#FF6600> </#FF6600> or <&a> </&a>
# example using Hex Colors foo: <#FF6600>foo</#FF6600>
# example using Hex Color bar: <&a>bar</&a>
messages:
verify-success: "&aYou've successfully verified with World ID!"
verify-error: "&cError while verifying with World ID. Please try again."
verify-failure: "&cYou have failed verification with World ID. Please try again."
verify-already-verified: "&ePlayer is already verified with World ID."
verify-level: "&4This Verification Level is not accepted."
verify-invalid: "&4Invalid Verification Level."
verify-click-here: "&f&lClick here to verify with World ID: &r"
verify-now: "<#05F511>&lVerify me NOW!</#05F511>"

listener-messages:
welcome-msg: "&aWelcome to the server now using WorldID!"
verify-welcome-msg: "&aYou've been verified with World ID!"
verify-to-msg: "&eYou haven't been verified with World ID!"
verify-msg: "&bYou can get permissions by typing the `/verify` command to verify with World ID!"
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: WorldId
authors: [Penryn]
website: worldcoin.org
version: 0.1.0
version: 0.1.1
api-version: 1.20
main: org.worldcoin.bukkit.plugin.worldid.WorldId
prefix: "World ID"
Expand Down

0 comments on commit 287ae13

Please sign in to comment.