88import com .ampznetwork .worldmod .api .model .TextResourceProvider ;
99import com .ampznetwork .worldmod .api .model .WandType ;
1010import com .ampznetwork .worldmod .api .model .config .WorldModConfigAdapter ;
11+ import com .ampznetwork .worldmod .api .model .log .LogEntry ;
1112import com .ampznetwork .worldmod .api .model .query .IQueryManager ;
13+ import com .ampznetwork .worldmod .api .model .region .Group ;
1214import com .ampznetwork .worldmod .api .model .region .Region ;
1315import com .ampznetwork .worldmod .api .model .sel .Area ;
1416import net .kyori .adventure .text .format .NamedTextColor ;
2729import java .util .Arrays ;
2830import java .util .Map ;
2931import java .util .Optional ;
32+ import java .util .Set ;
3033import java .util .UUID ;
3134import java .util .function .Predicate ;
3235import java .util .logging .Level ;
@@ -52,6 +55,13 @@ default Class<?> getModuleType() {
5255 return WorldMod .class ;
5356 }
5457
58+ @ Override
59+ default Set <Class <? extends DbObject >> getEntityTypes () {
60+ return Stream .concat (getLib ().getEntityTypes ().stream (),
61+ Stream .of (Region .class , Group .class , LogEntry .class , Area .class ))
62+ .collect (Collectors .toUnmodifiableSet ());
63+ }
64+
5565 @ Override
5666 default TextColor getThemeColor () {
5767 return NamedTextColor .LIGHT_PURPLE ;
@@ -69,13 +79,21 @@ default Stream<Object> expandContext(Object... context) {
6979 Map <String , IQueryManager > getQueryManagers ();
7080
7181 default Optional <WandType > findWandType (String itemResourceKey ) {
72- return wandItems ().entrySet ().stream ().filter (e -> LibMod .equalResourceKey (itemResourceKey , e .getValue ())).findAny ().map (Map .Entry ::getKey );
82+ return wandItems ().entrySet ()
83+ .stream ()
84+ .filter (e -> LibMod .equalResourceKey (itemResourceKey , e .getValue ()))
85+ .findAny ()
86+ .map (Map .Entry ::getKey );
7387 }
7488
7589 default boolean addRegion (Region region ) {
76- if (region .findOverlaps (this ).findAny ().isPresent ()) throw new Command .Error ("The selected area is overlapping with another claim" );
90+ if (region .findOverlaps (this ).findAny ().isPresent ())
91+ throw new Command .Error ("The selected area is overlapping with another claim" );
7792 try {
78- region .getAreas ().stream ().filter (a -> getEntityService ().getAccessor (Area .TYPE ).get (a .getId ()).isEmpty ()).forEach (getEntityService ()::save );
93+ region .getAreas ()
94+ .stream ()
95+ .filter (a -> getEntityService ().getAccessor (Area .TYPE ).get (a .getId ()).isEmpty ())
96+ .forEach (getEntityService ()::save );
7997 getEntityService ().save (region );
8098 return true ;
8199 } catch (Throwable t ) {
@@ -99,8 +117,15 @@ isMatch as (select Region_id as matchId, false
99117 ## todo add more matching methods
100118 as bool from inside)
101119 select r.* from worldmod_regions r, isMatch where bool and matchId = r.id and r.worldName = :worldName
102- """ , Map .of ("posX" , location .getX (), "posY" , location .getY (), "posZ" , location .getZ (), "worldName" , worldName )),
103- Stream .of (Region .global ("world" ))).sorted (Region .BY_PRIORITY );
120+ """ ,
121+ Map .of ("posX" ,
122+ location .getX (),
123+ "posY" ,
124+ location .getY (),
125+ "posZ" ,
126+ location .getZ (),
127+ "worldName" ,
128+ worldName )), Stream .of (Region .global ("world" ))).sorted (Region .BY_PRIORITY );
104129 }
105130
106131 default Stream <Region > findChunkloadedRegions () {
@@ -112,7 +137,10 @@ default Stream<Region> findChunkloadedRegions() {
112137 where rf.flag = 'manage.chunkload' or rgf.flag = 'manage.chunkload'
113138 """ )
114139 .sorted (Region .BY_PRIORITY )
115- .filter (rg -> !chunkloadWhileOnlineOnly () || rg .getMembers ().stream ().map (DbObject ::getId ).anyMatch (getPlayerAdapter ()::isOnline ));
140+ .filter (rg -> !chunkloadWhileOnlineOnly () || rg .getMembers ()
141+ .stream ()
142+ .map (DbObject ::getId )
143+ .anyMatch (getPlayerAdapter ()::isOnline ));
116144 }
117145
118146 TextResourceProvider text ();
@@ -131,13 +159,19 @@ default Map<String, Long> flagLog(@Nullable Player player, @Nullable String targ
131159 if (player != null ) query .setParameter ("playerId" , player .getId ().toString ());
132160 if (target != null ) query .setParameter ("target" , target );
133161 var map = Polyfill .<Stream <Tuple >>uncheckedCast (query .getResultStream ())
134- .collect (Collectors .toMap (it -> it .get ("action" , String .class ), it -> it .get ("count" , BigInteger .class ).longValue ()));
135- Flag .VALUES .values ().stream ().map (Flag ::getCanonicalName ).filter (Predicate .not (map ::containsKey )).forEach (key -> map .put (key , 0L ));
162+ .collect (Collectors .toMap (it -> it .get ("action" , String .class ),
163+ it -> it .get ("count" , BigInteger .class ).longValue ()));
164+ Flag .VALUES .values ()
165+ .stream ()
166+ .map (Flag ::getCanonicalName )
167+ .filter (Predicate .not (map ::containsKey ))
168+ .forEach (key -> map .put (key , 0L ));
136169 return map ;
137170 }
138171
139172 private static Stream <String > ownAndChildFlagNames (Flag flag ) {
140173 var name = flag .getName ();
141- return Stream .concat (Stream .of (name ), flag .getChildren ().stream ().flatMap (WorldMod ::ownAndChildFlagNames ).map (str -> name + '.' + str ));
174+ return Stream .concat (Stream .of (name ),
175+ flag .getChildren ().stream ().flatMap (WorldMod ::ownAndChildFlagNames ).map (str -> name + '.' + str ));
142176 }
143177}
0 commit comments