Skip to content

Commit c3e42e5

Browse files
committed
Add data providers for owned regions
1 parent f50b67d commit c3e42e5

5 files changed

Lines changed: 100 additions & 0 deletions

File tree

realty-backend-api/src/main/java/io/github/md5sha256/realty/api/RealtyBackend.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,12 @@ record ExpiredLeasehold(
539539

540540
int countRegionsByAuthority(@NotNull UUID playerId);
541541

542+
@NotNull List<String> listRegionNamesByTitleHolder(@NotNull UUID playerId);
543+
544+
@NotNull List<String> listRegionNamesByTenant(@NotNull UUID playerId);
545+
546+
@NotNull List<String> listRegionNamesByLandlord(@NotNull UUID playerId);
547+
542548
int countRegionsByTitleHolder(@NotNull UUID playerId);
543549

544550
int countRegionsByLandlord(@NotNull UUID playerId);

realty-backend/src/main/java/io/github/md5sha256/realty/database/RealtyBackendImpl.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,27 @@ public int countRegionsByAuthority(@NotNull UUID playerId) {
15431543
}
15441544
}
15451545

1546+
@Override
1547+
public @NotNull List<String> listRegionNamesByTitleHolder(@NotNull UUID playerId) {
1548+
try (SqlSessionWrapper wrapper = database.openSession()) {
1549+
return wrapper.realtyRegionMapper().selectRegionNamesByTitleHolder(playerId);
1550+
}
1551+
}
1552+
1553+
@Override
1554+
public @NotNull List<String> listRegionNamesByTenant(@NotNull UUID playerId) {
1555+
try (SqlSessionWrapper wrapper = database.openSession()) {
1556+
return wrapper.realtyRegionMapper().selectRegionNamesByTenant(playerId);
1557+
}
1558+
}
1559+
1560+
@Override
1561+
public @NotNull List<String> listRegionNamesByLandlord(@NotNull UUID playerId) {
1562+
try (SqlSessionWrapper wrapper = database.openSession()) {
1563+
return wrapper.realtyRegionMapper().selectRegionNamesByLandlord(playerId);
1564+
}
1565+
}
1566+
15461567
@Override
15471568
public int countRegionsByTitleHolder(@NotNull UUID playerId) {
15481569
try (SqlSessionWrapper wrapper = database.openSession()) {

realty-backend/src/main/java/io/github/md5sha256/realty/database/mapper/RealtyRegionMapper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ public interface RealtyRegionMapper {
3939

4040
int countRegionsByTenant(@NotNull UUID playerId);
4141

42+
@NotNull List<String> selectRegionNamesByTitleHolder(@NotNull UUID playerId);
43+
44+
@NotNull List<String> selectRegionNamesByTenant(@NotNull UUID playerId);
45+
46+
@NotNull List<String> selectRegionNamesByLandlord(@NotNull UUID playerId);
47+
4248
int countRegionsByLandlord(@NotNull UUID playerId);
4349

4450
int countAll();

realty-backend/src/main/java/io/github/md5sha256/realty/database/maria/mapper/MariaRealtyRegionMapper.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,36 @@ SELECT COUNT(*)
169169
""")
170170
int countRegionsByTenant(@Param("playerId") @NotNull UUID playerId);
171171

172+
@Override
173+
@Select("""
174+
SELECT rr.worldGuardRegionId
175+
FROM RealtyRegion rr
176+
INNER JOIN Contract c ON c.realtyRegionId = rr.realtyRegionId AND c.contractType = 'freehold'
177+
INNER JOIN FreeholdContract fc ON fc.freeholdContractId = c.contractId
178+
WHERE fc.titleHolderId = #{playerId}
179+
""")
180+
@NotNull List<String> selectRegionNamesByTitleHolder(@Param("playerId") @NotNull UUID playerId);
181+
182+
@Override
183+
@Select("""
184+
SELECT rr.worldGuardRegionId
185+
FROM RealtyRegion rr
186+
INNER JOIN Contract c ON c.realtyRegionId = rr.realtyRegionId AND c.contractType = 'leasehold'
187+
INNER JOIN LeaseholdContract lc ON lc.leaseholdContractId = c.contractId
188+
WHERE lc.tenantId = #{playerId}
189+
""")
190+
@NotNull List<String> selectRegionNamesByTenant(@Param("playerId") @NotNull UUID playerId);
191+
192+
@Override
193+
@Select("""
194+
SELECT rr.worldGuardRegionId
195+
FROM RealtyRegion rr
196+
INNER JOIN Contract c ON c.realtyRegionId = rr.realtyRegionId AND c.contractType = 'leasehold'
197+
INNER JOIN LeaseholdContract lc ON lc.leaseholdContractId = c.contractId
198+
WHERE lc.landlordId = #{playerId}
199+
""")
200+
@NotNull List<String> selectRegionNamesByLandlord(@Param("playerId") @NotNull UUID playerId);
201+
172202
@Override
173203
@Select("""
174204
SELECT COUNT(*)

realty-paper-plan-extension/src/main/java/io/github/md5sha256/realty/plan/RealtyDataExtension.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.djrapitops.plan.extension.annotation.NumberProvider;
77
import com.djrapitops.plan.extension.annotation.PercentageProvider;
88
import com.djrapitops.plan.extension.annotation.PluginInfo;
9+
import com.djrapitops.plan.extension.annotation.StringProvider;
910
import com.djrapitops.plan.extension.FormatType;
1011
import com.djrapitops.plan.extension.icon.Color;
1112
import com.djrapitops.plan.extension.icon.Family;
@@ -208,4 +209,40 @@ public double playerLeaseholdOccupancyRate(UUID playerUUID) {
208209
}
209210
return (double) realtyApi.countOccupiedLeaseholdsByLandlord(playerUUID) / total;
210211
}
212+
213+
@StringProvider(
214+
text = "Freehold Regions",
215+
description = "Regions where this player is the title holder of a freehold",
216+
priority = 3,
217+
iconName = "house-user",
218+
iconFamily = Family.SOLID,
219+
iconColor = Color.BLUE
220+
)
221+
public String playerFreeholdRegions(UUID playerUUID) {
222+
return String.join(", ", realtyApi.listRegionNamesByTitleHolder(playerUUID));
223+
}
224+
225+
@StringProvider(
226+
text = "Leasehold Tenancies",
227+
description = "Regions where this player is a tenant of a leasehold",
228+
priority = 2,
229+
iconName = "file-signature",
230+
iconFamily = Family.SOLID,
231+
iconColor = Color.GREEN
232+
)
233+
public String playerTenantRegions(UUID playerUUID) {
234+
return String.join(", ", realtyApi.listRegionNamesByTenant(playerUUID));
235+
}
236+
237+
@StringProvider(
238+
text = "Landlord Regions",
239+
description = "Regions where this player is the landlord of a leasehold",
240+
priority = 1,
241+
iconName = "building",
242+
iconFamily = Family.SOLID,
243+
iconColor = Color.AMBER
244+
)
245+
public String playerLandlordRegions(UUID playerUUID) {
246+
return String.join(", ", realtyApi.listRegionNamesByLandlord(playerUUID));
247+
}
211248
}

0 commit comments

Comments
 (0)