-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: start adding event system, small lang fixes
- Loading branch information
1 parent
8a43dce
commit 2b289da
Showing
21 changed files
with
253 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/dev/emortal/velocity/party/commands/event/EventCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package dev.emortal.velocity.party.commands.event; | ||
|
||
import com.mojang.brigadier.arguments.StringArgumentType; | ||
import com.mojang.brigadier.context.CommandContext; | ||
import com.velocitypowered.api.command.CommandSource; | ||
import dev.emortal.api.service.party.PartyService; | ||
import dev.emortal.velocity.command.EmortalCommand; | ||
import dev.emortal.velocity.lang.ChatMessages; | ||
import dev.emortal.velocity.party.commands.event.subs.CreateSub; | ||
import dev.emortal.velocity.party.commands.event.subs.ListSub; | ||
|
||
public class EventCommand extends EmortalCommand { | ||
|
||
public EventCommand(PartyService partyService) { | ||
super("event"); | ||
|
||
super.setCondition(source -> source.hasPermission("command.event")); | ||
|
||
// List | ||
ListSub listSub = new ListSub(partyService); | ||
super.setDefaultExecutor(listSub); | ||
super.addSyntax(listSub, literal("list")); | ||
|
||
// Create | ||
super.addSyntax(this::createUsage, literal("create")); | ||
super.addSyntax(this::createUsage, literal("create"), literal("help")); | ||
super.addSyntax(new CreateSub(partyService), literal("create"), argument("id", StringArgumentType.word()), | ||
argument("showTime", StringArgumentType.word()), argument("startTime", StringArgumentType.word())); | ||
} | ||
|
||
private void createUsage(CommandContext<CommandSource> context) { | ||
ChatMessages.EVENT_CREATE_USAGE.send(context.getSource()); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
src/main/java/dev/emortal/velocity/party/commands/event/subs/CreateSub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package dev.emortal.velocity.party.commands.event.subs; | ||
|
||
import com.velocitypowered.api.command.CommandSource; | ||
import com.velocitypowered.api.proxy.Player; | ||
import dev.emortal.api.model.common.PlayerSkin; | ||
import dev.emortal.api.model.party.EventData; | ||
import dev.emortal.api.service.party.PartyService; | ||
import dev.emortal.velocity.command.ArgumentProvider; | ||
import dev.emortal.velocity.command.EmortalCommandExecutor; | ||
import dev.emortal.velocity.lang.ChatMessages; | ||
import dev.emortal.velocity.utils.SkinUtils; | ||
import io.grpc.Status; | ||
import io.grpc.StatusRuntimeException; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
|
||
public class CreateSub implements EmortalCommandExecutor { | ||
private static final @NotNull Logger LOGGER = LoggerFactory.getLogger(CreateSub.class); | ||
|
||
private final @NotNull PartyService partyService; | ||
|
||
public CreateSub(@NotNull PartyService partyService) { | ||
this.partyService = partyService; | ||
} | ||
|
||
@Override | ||
public void execute(@NotNull CommandSource source, @NotNull ArgumentProvider arguments) { | ||
if (!(source instanceof Player player)) return; | ||
|
||
String id = arguments.getArgument("id", String.class); | ||
if (id.length() < 3 || id.length() > 32) { | ||
ChatMessages.ERROR_EVENT_INVALID_ID.send(source); | ||
return; | ||
} | ||
|
||
PlayerSkin skin = SkinUtils.getProtoSkin(player); | ||
if (skin == null) { | ||
ChatMessages.ERROR_NO_SKIN.send(player); | ||
return; | ||
} | ||
|
||
String showTimeStr = arguments.getArgument("showTime", String.class); | ||
Instant showTime; | ||
try { | ||
showTime = this.parseStrTime(showTimeStr); | ||
} catch (DateTimeParseException unused) { | ||
ChatMessages.ERROR_INVALID_TIME_FORMAT_ARG.send(player, "showTime"); | ||
return; | ||
} | ||
|
||
String startTimeStr = arguments.getArgument("startTime", String.class); | ||
Instant startTime; | ||
try { | ||
startTime = this.parseStrTime(startTimeStr); | ||
} catch (DateTimeParseException unused) { | ||
ChatMessages.ERROR_INVALID_TIME_FORMAT_ARG.send(player, "startTime"); | ||
return; | ||
} | ||
|
||
Instant timeNow = Instant.now().minusSeconds(60); | ||
if (timeNow.isAfter(startTime)) { | ||
ChatMessages.ERROR_TIME_IN_PAST_ARG.send(player, "startTime"); | ||
return; | ||
} | ||
|
||
EventData createdEvent; | ||
try { | ||
createdEvent = this.partyService.createEvent(id, player.getUniqueId(), player.getUsername(), skin, showTime, startTime); | ||
} catch (StatusRuntimeException ex) { | ||
if (ex.getStatus().getCode() == Status.Code.ALREADY_EXISTS) { | ||
ChatMessages.ERROR_EVENT_ALREADY_EXISTS.send(player, id); | ||
return; | ||
} | ||
|
||
ChatMessages.GENERIC_ERROR.send(player); | ||
LOGGER.error("Failed to create event", ex); | ||
return; | ||
} | ||
|
||
ChatMessages.EVENT_CREATED.send(player, createdEvent); | ||
} | ||
|
||
private Instant parseStrTime(@Nullable String input) { | ||
if (input == null) return null; | ||
if (input.equals("now")) return Instant.now(); | ||
|
||
return LocalDateTime.parse(input, DateTimeFormatter.ISO_LOCAL_DATE_TIME) | ||
.atZone(ZoneId.of("Europe/London")) | ||
.toInstant(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/dev/emortal/velocity/party/commands/event/subs/ListSub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package dev.emortal.velocity.party.commands.event.subs; | ||
|
||
import com.velocitypowered.api.command.CommandSource; | ||
import dev.emortal.api.service.party.PartyService; | ||
import dev.emortal.velocity.command.ArgumentProvider; | ||
import dev.emortal.velocity.command.EmortalCommandExecutor; | ||
import dev.emortal.velocity.lang.ChatMessages; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ListSub implements EmortalCommandExecutor { | ||
private final @NotNull PartyService partyService; | ||
|
||
public ListSub(@NotNull PartyService partyService) { | ||
this.partyService = partyService; | ||
} | ||
|
||
@Override | ||
public void execute(@NotNull CommandSource source, @NotNull ArgumentProvider arguments) { | ||
ChatMessages.EVENT_DATA_LIST.send(source, this.partyService.listEvents()); | ||
} | ||
} |
24 changes: 12 additions & 12 deletions
24
...velocity/party/commands/PartyCommand.java → ...ty/party/commands/party/PartyCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...arty/commands/subs/PartyBroadcastSub.java → ...ommands/party/subs/PartyBroadcastSub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ty/party/commands/subs/PartyCloseSub.java → ...ty/commands/party/subs/PartyCloseSub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../party/commands/subs/PartyDisbandSub.java → .../commands/party/subs/PartyDisbandSub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...y/party/commands/subs/PartyInviteSub.java → ...y/commands/party/subs/PartyInviteSub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ity/party/commands/subs/PartyKickSub.java → ...rty/commands/party/subs/PartyKickSub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...y/party/commands/subs/PartyLeaderSub.java → ...y/commands/party/subs/PartyLeaderSub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.