Skip to content

Commit

Permalink
Fixes #292
Browse files Browse the repository at this point in the history
  • Loading branch information
Pante committed Jun 22, 2021
1 parent 5a5c23e commit 96e7aff
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This update adds argument type matching and overhauls code generation for the command framework. The Scribe project has also been removed.
Underneath the hood, we have streamlined the project's infrastructure and documentation. Documentation is now applied on the master branch
and the staging branch has been removed. The minimum Java version has also been bumped to Java 16
and the staging branch has been removed. The minimum Java version has also been bumped to Java 16.

### Annotations

Expand Down Expand Up @@ -59,7 +59,9 @@ Typist.
- Change `KnowledgeBookBuilder.of(Material)` to `KnowledgeBookBuilder.of()` - only knowledge books contain a `KnowledgeBookMeta`
- Change `SkullBuilder` to `HeadBuilder`
- Change `TropicalFishBucketBuilder.of(Material)` to `TropicalFishBucketBuilder.of()` - only tropical fish buckets contain a `TropicalFishBucketMeta`
- Change the length at which a displayed command is trimmed when an error occurs from 10 to 20
- Fix incorrect capitalization of names in `com.karuslabs.commons.item.Head`
- Fix commands not being sent to players after server reload - see #292
- Remove `com.karuslabs.commons.command.aot.*`
- Remove methods prefixed with `as` in `com.karuslabs.commons.item.ItemBuilder` - replaced with equivalent methods without prefixes
- Remove `LeatherArmourBuilder.of(Material)` - replaced with equivalent methods for specific leather armour items
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import org.bukkit.event.server.ServerLoadEvent;
import org.bukkit.plugin.Plugin;

import static org.bukkit.event.server.ServerLoadEvent.LoadType.STARTUP;

/**
* A {@code CommandDispatcher} that facilities the registration of commands between
* a Spigot plugin and the server.
Expand Down Expand Up @@ -134,15 +136,23 @@ public void update() {
}

/**
* Synchronizes this dispatcher with the server when the server is started or
* reloaded.
* Synchronizes this dispatcher with the server when the server is reloaded or
* restarted. The changes to the server are then sent to all clients if the
* server was reloaded.
*
* @param event the event that denotes the starting and reloading of the server
*/
@EventHandler
protected void update(ServerLoadEvent event) {
dispatcher = server.getCommands().getDispatcher();
walker.prune(dispatcher.getRoot(), getRoot().getChildren());
if (event.getType() == STARTUP) {
// We don't have to manually send the changes since the startup event
// is fired before connections to the server are allowed.
walker.prune(dispatcher.getRoot(), getRoot().getChildren());

} else {
update();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ static void report(CommandSender sender, CommandSyntaxException exception) {
style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, input))
);

if (index > 10) {
if (index > 20) {
text.append("...");
}

text.append(input.substring(Math.max(0, index - 10), index));
text.append(input.substring(Math.max(0, index - 20), index));

if (index < input.length()) {
var error = new TextComponent(input.substring(index)).withStyle(new ChatFormatting[]{ChatFormatting.RED, ChatFormatting.UNDERLINE});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@
import org.bukkit.craftbukkit.v1_17_R1.command.CraftCommandMap;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_17_R1.scheduler.CraftScheduler;
import org.bukkit.event.server.ServerLoadEvent;
import org.bukkit.event.server.ServerLoadEvent.LoadType;
import org.junit.jupiter.api.*;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -118,15 +122,21 @@ void update() {
}


@Test
void update_server_reload() {
@ParameterizedTest
@CsvSource({"STARTUP, 0", "RELOAD, 1"})
void update_server_event(LoadType type, int times) {
var player = mock(CraftPlayer.class);
when(craftserver.getOnlinePlayers()).thenReturn(List.of(player));

dispatcher.getRoot().addChild(Literal.of("a").build());
dispatcher.dispatcher = null;

dispatcher.update(null);
dispatcher.update(new ServerLoadEvent(type));

assertNotNull(dispatcher.dispatcher.getRoot().getChild("a"));
assertSame(internal, dispatcher.dispatcher);

verify(player, times(times)).updateCommands();
}

}

0 comments on commit 96e7aff

Please sign in to comment.