@@ -201,15 +201,15 @@ private void initReturnTypeManager(ReturnTypeManager returnTypeManager) {
201201
202202 private void initMethodParseManager (MethodParseManager parser ) {
203203 parser .registerParser ((t , annos ) -> t .equals (UISession .class ), (annotations , t , e ) -> session );
204- parser .registerParser ((t , annos ) -> {
204+ parser .registerParser ((t , annos ) -> Arrays .stream (annos ).anyMatch (a -> a .annotationType () == FromPattern .class ), (annotations , t , e ) -> {
205+ FromPattern pattern = (FromPattern ) Arrays .stream (annotations ).filter (a -> a .annotationType () == FromPattern .class ).findAny ().orElseThrow (() -> new IllegalStateException ("cannot find @FromPattern in List<ItemStack> parameters" ));
205206 if (t instanceof ParameterizedType ) {
206207 var parat = (ParameterizedType ) t ;
207- return parat .getActualTypeArguments ()[0 ] == ItemStack .class && parat .getRawType () == List .class ;
208+ if (parat .getActualTypeArguments ()[0 ] == ItemStack .class && parat .getRawType () == List .class ){
209+ return this .currentView .getEldgContext ().getItems (pattern .value ());
210+ }
208211 }
209- return false ;
210- }, (annotations , t , e ) -> {
211- FromPattern pattern = (FromPattern ) Arrays .stream (annotations ).filter (a -> a .annotationType () == FromPattern .class ).findAny ().orElseThrow (() -> new IllegalStateException ("cannot find @FromPattern in List<ItemStack> parameters" ));
212- return this .currentView .getEldgContext ().getItems (pattern .value ());
212+ throw new IllegalStateException ("@FromPattern 必須使用 List<ItemStack> 作為其類型" );
213213 });
214214 //parser.registerParser((t, annos) -> t.equals(UIRequest.class), (annotations, t, e) -> eldgContext);
215215 parser .registerParser ((t , annos ) -> t .equals (Player .class ), (annotations , t , e ) -> owner );
@@ -241,6 +241,28 @@ private void initMethodParseManager(MethodParseManager parser) {
241241 LOGGER .debug ("using " + toConvert + " to create instance of " + model );
242242 return PersistDataUtils .mapToObject (toConvert , model );
243243 });
244+ parser .registerParser ((t , annos ) -> Arrays .stream (annos ).anyMatch (a -> a .annotationType () == MapAttribute .class ),
245+ (annotations , type , event ) -> {
246+ MapAttribute attribute = (MapAttribute ) Arrays .stream (annotations ).filter (a -> a .annotationType () == MapAttribute .class ).findAny ().orElseThrow (() -> new IllegalStateException ("cannot find MapAttribute annotation" ));
247+ var context = this .currentView .getEldgContext ();
248+ boolean isMap = false ;
249+ if (type instanceof ParameterizedType ){
250+ var parat = (ParameterizedType )type ;
251+ isMap = parat .getRawType () == Map .class && parat .getActualTypeArguments ()[0 ] == String .class && parat .getActualTypeArguments ()[1 ] == Object .class ;
252+ }
253+
254+ if (!isMap ) throw new IllegalStateException ("@MapAttribute 必須使用 Map<String, Object> 作為其類型" );
255+ Map <String , Object > fieldMap = context .getItems (attribute .value ())
256+ .stream ()
257+ .filter (item -> context .getAttribute (item , AttributeController .FIELD_TAG ) != null )
258+ .collect (Collectors
259+ .toMap (
260+ item -> context .getAttribute (item , AttributeController .FIELD_TAG ),
261+ item -> Optional .ofNullable (context .getAttribute (item , AttributeController .VALUE_TAG )).orElseThrow (() -> new IllegalStateException ("The value tag of " + item .toString () + " is null." ))
262+ )
263+ );
264+ return PersistDataUtils .toNestedMap (fieldMap );
265+ });
244266 }
245267
246268 private ItemStack getItemByEvent (InventoryEvent e ) {
0 commit comments