Skip to content

Commit faaf3d3

Browse files
committed
So anything you could do to help would be ... very... helpful
1 parent 008226a commit faaf3d3

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/main/java/org/kitteh/tim/Tim.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
import org.spongepowered.api.data.meta.ItemEnchantment;
3939
import org.spongepowered.api.entity.living.player.Player;
4040
import org.spongepowered.api.event.Listener;
41-
import org.spongepowered.api.event.game.state.GameInitializationEvent;
4241
import org.spongepowered.api.event.game.state.GamePostInitializationEvent;
42+
import org.spongepowered.api.event.game.state.GameStartingServerEvent;
4343
import org.spongepowered.api.item.Enchantment;
4444
import org.spongepowered.api.item.inventory.ItemStack;
4545
import org.spongepowered.api.plugin.Plugin;
@@ -89,7 +89,19 @@ public class Tim {
8989
private Logger logger;
9090

9191
@Listener
92-
public void onGameInit(GameInitializationEvent event) {
92+
public void onGameStarting(GamePostInitializationEvent event) {
93+
Function<ImmutableMap.Builder<String, Enchantment>, ImmutableMap<String, Enchantment>> finisher = ImmutableMap.Builder::build; // Compiler doesn't seem to like putting this in the collector.
94+
this.enchantments = Collections.unmodifiableMap(
95+
this.game.getRegistry().getAllOf(Enchantment.class).stream()
96+
.collect(Collector.of(
97+
ImmutableMap.Builder::new,
98+
(builder, enchantment) -> builder.put(enchantment.getName(), enchantment),
99+
(left, right) -> left.putAll(right.build()),
100+
finisher)));
101+
}
102+
103+
@Listener
104+
public void onGameServerStarting(GameStartingServerEvent event) {
93105
CommandSpec enchantAllCommandSpec = CommandSpec.builder()
94106
.arguments(GenericArguments.optional(GenericArguments.string(Text.of(COMMAND_ARG_LEVEL))))
95107
.executor(this::commandEnchantAll).build();
@@ -102,18 +114,6 @@ public void onGameInit(GameInitializationEvent event) {
102114
this.logger.info("There are some who call me... Tim?");
103115
}
104116

105-
@Listener
106-
public void onGameStarting(GamePostInitializationEvent event) {
107-
Function<ImmutableMap.Builder<String, Enchantment>, ImmutableMap<String, Enchantment>> finisher = ImmutableMap.Builder::build; // Compiler doesn't seem to like putting this in the collector.
108-
this.enchantments = Collections.unmodifiableMap(
109-
this.game.getRegistry().getAllOf(Enchantment.class).stream()
110-
.collect(Collector.of(
111-
ImmutableMap.Builder::new,
112-
(builder, enchantment) -> builder.put(enchantment.getName(), enchantment),
113-
(left, right) -> left.putAll(right.build()),
114-
finisher)));
115-
}
116-
117117
private CommandResult commandEnchant(CommandSource commandSource, CommandContext commandContext) throws CommandException {
118118
Enchantment enchantment = commandContext.<Enchantment>getOne(COMMAND_ARG_ENCHANTMENT).get();
119119
int level = this.getEnchantmentLevel(commandContext);

0 commit comments

Comments
 (0)