Added points command
This commit is contained in:
parent
feca8ec77c
commit
6f8debde93
|
|
@ -1,6 +1,7 @@
|
|||
package com.alttd.fishingevent.commands;
|
||||
|
||||
import com.alttd.fishingevent.FishingEvent;
|
||||
import com.alttd.fishingevent.commands.fish_subcommands.Points;
|
||||
import com.alttd.fishingevent.config.Messages;
|
||||
import com.alttd.fishingevent.util.Logger;
|
||||
import org.bukkit.command.*;
|
||||
|
|
@ -27,6 +28,7 @@ public class FishCommand implements CommandExecutor, TabExecutor {
|
|||
command.setTabCompleter(this);
|
||||
|
||||
subCommands = Arrays.asList(
|
||||
new Points()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
package com.alttd.fishingevent.commands.fish_subcommands;
|
||||
|
||||
import com.alttd.fishingevent.commands.SubCommand;
|
||||
import com.alttd.fishingevent.config.Messages;
|
||||
import com.alttd.fishingevent.points.PointsManagement;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Points extends SubCommand {
|
||||
|
|
@ -14,18 +19,40 @@ public class Points extends SubCommand {
|
|||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||
Component playerName;
|
||||
int points;
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
if (args.length != 2) {
|
||||
if (args.length == 3) {
|
||||
if (commandSender.hasPermission(getPermission() + ".others")) {
|
||||
commandSender.sendMiniMessage(Messages.GENERIC.NO_PERMISSION, null);
|
||||
return true;
|
||||
}
|
||||
Optional<Player> playerFromArg = getPlayerFromArg(args[2]);
|
||||
if (playerFromArg.isEmpty()) {
|
||||
commandSender.sendMiniMessage(Messages.GENERIC.INVALID_PLAYER, Placeholder.parsed("player", args[2]));
|
||||
return true;
|
||||
}
|
||||
Player argPlayer = playerFromArg.get();
|
||||
playerName = argPlayer.displayName();
|
||||
points = PointsManagement.getInstance().getPoints(argPlayer.getUniqueId());
|
||||
} else if (args.length == 2) {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (args.length == 1) {
|
||||
playerName = player.displayName();
|
||||
points = PointsManagement.getInstance().getPoints(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
playerName = player.displayName();
|
||||
points = PointsManagement.getInstance().getPoints(player.getUniqueId());
|
||||
} else
|
||||
return false;
|
||||
|
||||
return false;
|
||||
|
||||
commandSender.sendMiniMessage(Messages.FISHING_COMMAND.POINTS, TagResolver.resolver(
|
||||
Placeholder.component("player", playerName),
|
||||
Placeholder.parsed("points", String.valueOf(points))));
|
||||
return true;
|
||||
}
|
||||
|
||||
private Optional<Player> getPlayerFromArg(String arg) {
|
||||
Player player = Bukkit.getPlayer(arg);
|
||||
if (player == null)
|
||||
return Optional.empty();
|
||||
return Optional.of(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -37,11 +37,13 @@ public class Messages extends AbstractConfig {
|
|||
|
||||
public static String NO_PERMISSION = "<red>You don't have permission for this command</red>";
|
||||
public static String PLAYER_ONLY = "<red>This command can only be executed as a player</red>";
|
||||
public static String INVALID_PLAYER = "<red><player> is not a valid player</red>";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
NO_PERMISSION = config.getString(prefix, "no-permission", NO_PERMISSION);
|
||||
PLAYER_ONLY = config.getString(prefix, "player-only", PLAYER_ONLY);
|
||||
INVALID_PLAYER = config.getString(prefix, "invalid-player", INVALID_PLAYER);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -52,6 +54,7 @@ public class Messages extends AbstractConfig {
|
|||
public static String PRIZES_GUI_NAME = "<green>Prizes GUI</green>";
|
||||
public static String SELL_GUI_NAME = "<green>Sell GUI</green>";;
|
||||
public static String NOT_INITIALIZED = "<red>There was an error initializing this GUI, please contact staff</red>";
|
||||
public static String EARNED_POINTS = "<green>You earned <gold><earned_points></gold> points from this sale, you are now at <gold><total_points></gold> points!";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
|
|
@ -60,14 +63,17 @@ public class Messages extends AbstractConfig {
|
|||
PRIZES_GUI_NAME = config.getString(prefix, "prizes-gui-name", PRIZES_GUI_NAME);
|
||||
SELL_GUI_NAME = config.getString(prefix, "sell-gui-name", SELL_GUI_NAME);
|
||||
NOT_INITIALIZED = config.getString(prefix, "not-initialized", NOT_INITIALIZED);
|
||||
EARNED_POINTS = config.getString(prefix, "earned-points", EARNED_POINTS);
|
||||
}
|
||||
}
|
||||
|
||||
public static class FISHING_COMMAND {
|
||||
private static final String prefix = "fishing-command.";
|
||||
public static String POINTS = "<green><player> has <gold><points></gold> points.";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
POINTS = config.getString(prefix, "points", POINTS);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ public class PointsManagement {
|
|||
}
|
||||
|
||||
public synchronized int getPoints(UUID uuid) {
|
||||
return pointsMap.getInt(uuid);
|
||||
return pointsMap.getOrDefault(uuid, 0);
|
||||
}
|
||||
|
||||
public synchronized void clear() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user