Skip to content

Commit

Permalink
Version 1.0.0 BETA
Browse files Browse the repository at this point in the history
This is another release for version 1.0.0 BETA

NOTE: Settlements now only works for version 1.21+

- Fixed some bugs
- Fixed Initial migration
- Fixed particles
- Changed maps to repository
- Updated services
- Updated POM
  • Loading branch information
HuskyDreaming committed Sep 15, 2024
1 parent beafd15 commit 687eb89
Show file tree
Hide file tree
Showing 19 changed files with 223 additions and 193 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>21</source>
<target>21</target>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
Expand All @@ -36,6 +36,10 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
Expand All @@ -53,13 +57,13 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.4-R0.1-SNAPSHOT</version>
<version>1.21.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.10</version>
<version>7.0.11</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
14 changes: 9 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>21</source>
<target>21</target>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
Expand All @@ -51,6 +51,10 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
Expand All @@ -66,11 +70,10 @@
</repositories>

<dependencies>
<!--This adds the Spigot API artifact to the build -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.20.4-R0.1-SNAPSHOT</version>
<version>1.21.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -91,7 +94,7 @@
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.10</version>
<version>7.0.11</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -100,6 +103,7 @@
<version>2.11.6</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.github.TownyAdvanced</groupId>
<artifactId>towny</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void onCommand(Player player, String[] strings) {
String string = strings[1];
OfflinePlayer offlinePlayer = Util.getOfflinePlayer(string);
if (offlinePlayer == null) {
player.sendMessage(Message.PLAYER_NULL.prefix(string));
player.sendMessage(Message.PLAYER_NEVER_PLAYED.prefix(string));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void migrate(Connection connection, String table) {
"CREATE TABLE " + table + "_claim (" +
"id INTEGER PRIMARY KEY /*!40101 AUTO_INCREMENT */," +
"settlement_id INTEGER NOT NULL," +
"world_uid INTEGER NOT NULL," +
"world_uid TEXT NOT NULL," +
"x INTEGER NOT NULL," +
"z INTEGER NOT NULL)");
} catch (SQLException e) {
Expand Down Expand Up @@ -75,7 +75,7 @@ public void migrate(Connection connection, String table) {
"id INTEGER PRIMARY KEY /*!40101 AUTO_INCREMENT */," +
"name TEXT NOT NULL," +
"settlement_id INTEGER NOT NULL," +
"world_uid INTEGER NOT NULL," +
"world_uid TEXT NOT NULL," +
"x DOUBLE NOT NULL," +
"y DOUBLE NOT NULL," +
"z DOUBLE NOT NULL," +
Expand Down Expand Up @@ -103,10 +103,10 @@ public void migrate(Connection connection, String table) {
"CREATE TABLE " + table + "_member (" +
"id INTEGER PRIMARY KEY /*!40101 AUTO_INCREMENT */," +
"player_uuid TEXT NOT NULL," +
"settlement_id INTEGER NOT NULL DEFAULT NULL," +
"role_id INTEGER NOT NULL DEFAULT NULL," +
"last_online TEXT NOT NULL DEFAULT NULL," +
"auto_claim TINYINT NOT NULL DEFAULT NULL)");
"settlement_id INTEGER NOT NULL," +
"role_id INTEGER NOT NULL," +
"last_online TEXT NOT NULL," +
"auto_claim TINYINT NOT NULL)");
} catch (SQLException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
package com.huskydreaming.settlements.inventories.actions;

import com.huskydreaming.huskycore.HuskyPlugin;
import com.huskydreaming.settlements.database.entities.Container;
import com.huskydreaming.settlements.database.entities.Role;
import com.huskydreaming.settlements.database.entities.Settlement;
import com.huskydreaming.settlements.inventories.base.InventoryAction;
import com.huskydreaming.settlements.inventories.base.InventoryActionType;
import com.huskydreaming.settlements.services.interfaces.*;
import com.huskydreaming.settlements.enumeration.locale.Message;
import org.bukkit.entity.Player;

import java.util.Set;

public class DisbandInventoryAction implements InventoryAction {

private final BorderService borderService;
private final FlagService flagService;
private final MemberService memberService;
private final ClaimService claimService;
private final ContainerService containerService;
private final FlagService flagService;
private final HomeService homeService;
private final MemberService memberService;
private final PermissionService permissionService;
private final RoleService roleService;
private final SettlementService settlementService;
private final TrustService trustService;
private final long settlementId;

public DisbandInventoryAction(HuskyPlugin plugin, Settlement settlement) {
borderService = plugin.provide(BorderService.class);
flagService = plugin.provide(FlagService.class);
settlementService = plugin.provide(SettlementService.class);
containerService = plugin.provide(ContainerService.class);
claimService = plugin.provide(ClaimService.class);
flagService = plugin.provide(FlagService.class);
homeService = plugin.provide(HomeService.class);
memberService = plugin.provide(MemberService.class);
permissionService = plugin.provide(PermissionService.class);
roleService = plugin.provide(RoleService.class);
settlementService = plugin.provide(SettlementService.class);
trustService = plugin.provide(TrustService.class);
this.settlementId = settlement.getId();
}
Expand All @@ -42,10 +50,15 @@ public void onAccept(Player player) {
Settlement settlement = settlementService.getSettlement(settlementId);
if(settlement == null) return;

Set<Role> roles = roleService.getRoles(settlement);
Container container = containerService.getContainer(settlement);
containerService.deleteContainer(container);

claimService.clean(settlement);
containerService.clean(settlement);
memberService.clean(settlement);
flagService.clean(settlement);
homeService.clean(settlement);
memberService.clean(settlement);
permissionService.clean(roles);
roleService.clean(settlement);
trustService.clean(settlement);
settlementService.disbandSettlement(settlement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void run() {
Particle.DustOptions dustOptions = new Particle.DustOptions(borderData.color(), 1.0f);

for (Location location : borderData.locations()) {
player.spawnParticle(Particle.REDSTONE, location, 1, dustOptions);
player.spawnParticle(Particle.DUST, location, 1, dustOptions);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.huskydreaming.settlements.services.implementations;

import com.huskydreaming.huskycore.HuskyPlugin;
import com.huskydreaming.huskycore.implementations.RepositoryImpl;
import com.huskydreaming.huskycore.interfaces.Repository;
import com.huskydreaming.huskycore.utilities.Util;
import com.huskydreaming.settlements.SettlementPlugin;
import com.huskydreaming.settlements.database.SqlType;
Expand All @@ -13,28 +15,27 @@
import org.bukkit.block.BlockFace;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class ClaimServiceImpl implements ClaimService {

private final ClaimDao claimDao;
private final Map<Long, Claim> claims;
private final Repository<Claim> claimRepository;

public ClaimServiceImpl(SettlementPlugin plugin) {
this.claimDao = new ClaimDao(plugin);
this.claims = new ConcurrentHashMap<>();
this.claimRepository = new RepositoryImpl<>();
}

@Override
public void deserialize(HuskyPlugin plugin) {
claimDao.bulkImport(SqlType.CLAIM, claims::putAll);
claimDao.bulkImport(SqlType.CLAIM, claimRepository::bulkAdd);
}

@Override
public void serialize(HuskyPlugin plugin) {
claimDao.bulkUpdate(SqlType.CLAIM, claims.values());
claimDao.bulkUpdate(SqlType.CLAIM, claimRepository.values());
}

@Override
Expand All @@ -49,7 +50,7 @@ public Claim createClaim(Chunk chunk) {

@Override
public void addClaim(Claim claim) {
claims.put(claim.getId(), claim);
claimRepository.add(claim);
}

@Override
Expand All @@ -62,7 +63,7 @@ public void addClaim(Settlement settlement, Chunk chunk, Runnable runnable) {

claimDao.insert(claim).queue(i -> {
claim.setId(i);
claims.put(i, claim);
claimRepository.add(claim);
runnable.run();
});
}
Expand All @@ -71,25 +72,25 @@ public void addClaim(Settlement settlement, Chunk chunk, Runnable runnable) {
@Override
public void removeClaim(Claim claim, Runnable runnable) {
claimDao.delete(claim).queue(i -> {
claims.remove(claim.getId());
claimRepository.remove(claim);
runnable.run();
});
}

@Override
public void clean(Settlement settlement) {
Set<Long> claimIds = claims.entrySet().stream()
Set<Long> claimIds = claimRepository.entries().stream()
.filter(e -> e.getValue().getSettlementId() == settlement.getId())
.map(Map.Entry::getKey)
.collect(Collectors.toSet());

claimDao.bulkDelete(SqlType.CLAIM, claimIds);
claims.keySet().removeAll(claimIds);
claimRepository.keys().removeAll(claimIds);
}

@Override
public boolean isClaim(Chunk chunk) {
return claims.values().stream().anyMatch(c ->
return claimRepository.values().stream().anyMatch(c ->
c.getWorldUID() == chunk.getWorld().getUID() &&
c.getX() == chunk.getX() &&
c.getZ() == chunk.getZ());
Expand All @@ -103,7 +104,7 @@ public Claim getClaim(Settlement settlement, Chunk chunk) {
c.getX() == chunk.getX() &&
c.getZ() == chunk.getZ());

return claims.values().stream().filter(claimPredicate).findFirst().orElse(null);
return claimRepository.values().stream().filter(claimPredicate).findFirst().orElse(null);
}

@Override
Expand All @@ -113,31 +114,31 @@ public Claim getClaim(Chunk chunk) {
c.getX() == chunk.getX() &&
c.getZ() == chunk.getZ());

return claims.values().stream().filter(claimPredicate).findFirst().orElse(null);
return claimRepository.values().stream().filter(claimPredicate).findFirst().orElse(null);
}

@Override
public Set<Claim> getClaims(long settlementId) {
return claims.values().stream()
return claimRepository.values().stream()
.filter(c -> c.getSettlementId() == settlementId)
.collect(Collectors.toSet());
}

@Override
public Set<Claim> getClaims(Settlement settlement) {
return claims.values().stream()
return claimRepository.values().stream()
.filter(c -> c.getSettlementId() == settlement.getId())
.collect(Collectors.toSet());
}

@Override
public int getCount() {
return claims.size();
return claimRepository.size();
}

@Override
public LinkedHashMap<Long, Long> getTop(int limit) {
return claims.values().stream()
return claimRepository.values().stream()
.collect(Collectors.groupingBy(Claim::getSettlementId, Collectors.counting()))
.entrySet().stream()
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
Expand Down
Loading

0 comments on commit 687eb89

Please sign in to comment.