3838import org .spongepowered .api .data .meta .ItemEnchantment ;
3939import org .spongepowered .api .entity .living .player .Player ;
4040import org .spongepowered .api .event .Listener ;
41- import org .spongepowered .api .event .game .state .GameInitializationEvent ;
4241import org .spongepowered .api .event .game .state .GamePostInitializationEvent ;
42+ import org .spongepowered .api .event .game .state .GameStartingServerEvent ;
4343import org .spongepowered .api .item .Enchantment ;
4444import org .spongepowered .api .item .inventory .ItemStack ;
4545import 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