Skip to content

Commit

Permalink
Added /vote
Browse files Browse the repository at this point in the history
  • Loading branch information
muriplz committed Jan 19, 2024
1 parent d7f23d4 commit 530788c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ This votifier.json is:
"host": "0.0.0.0",
"port": "8192",
"debug": false,
"command-after-voting": "/give %player% diamond 1"
"command-after-voting": "/give %player% diamond 1",
"voting-link": "https://minecraft.net/?vote=true"
}
```

Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/kryeit/votifier/command/Vote.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.kryeit.votifier.command;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.Style;
import net.minecraft.text.Text;

import java.util.function.Supplier;

import static com.kryeit.votifier.config.ConfigReader.LINK;

public class Vote {
public static int execute(CommandContext<ServerCommandSource> context) {
ServerCommandSource source = context.getSource();
ServerPlayerEntity player = source.getPlayer();

if (player == null) {
Supplier<Text> message = () -> Text.of("Can't execute from console");
source.sendFeedback(message, false);
return 0;
}

String link = LINK;
player.sendMessage(Text.literal("Voting site -> " + link)
.setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, link))));
return Command.SINGLE_SUCCESS;
}

public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(CommandManager.literal("vote")
.executes(Vote::execute)
);
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/kryeit/votifier/config/ConfigReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ConfigReader {
public static int PORT;
public static boolean DEBUG;
public static String COMMAND;
public static String LINK;

private ConfigReader() {

Expand All @@ -27,6 +28,7 @@ public static void readFile(Path path) throws IOException {
PORT = Integer.parseInt(configObject.getString("port"));
DEBUG = configObject.getBoolean("debug");
COMMAND = configObject.getString("command-after-voting");
LINK = configObject.getString("voting-link");
}

public static String readOrCopyFile(Path path, String exampleFile) throws IOException {
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/votifier.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"host": "0.0.0.0",
"port": "8192",
"debug": false,
"command-after-voting": "/give %player% diamond 1"
"command-after-voting": "/give %player% diamond 1",
"voting-link": "https://minecraft.net/?vote=true"
}

0 comments on commit 530788c

Please sign in to comment.