Skip to content

Commit

Permalink
#49 fix wrong contract/expand behave, optimize command tab complete p…
Browse files Browse the repository at this point in the history
…erformance
  • Loading branch information
ColdeZhang committed Jan 6, 2025
1 parent 67b12bb commit 3aae169
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var libraries = listOf<String>()
libraries = libraries + "cn.lunadeer:MinecraftPluginUtils:2.0.7"

group = "cn.lunadeer"
version = "3.2.7-beta"
version = "3.2.8-beta"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/cn/lunadeer/dominion/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,17 @@ public List<DominionDTO> getPlayerDominions(UUID player_uuid) {
return dominions;
}

public List<DominionDTO> getPlayerAdminDominions(UUID player_uuid) {
List<DominionDTO> dominions = new ArrayList<>();
for (DominionDTO dominion : id_dominions.values()) {
MemberDTO privilege = getMember(player_uuid, dominion);
if (privilege != null && privilege.getAdmin()) {
dominions.add(dominion);
}
}
return dominions;
}

public List<ResMigration.ResidenceNode> getResidenceData(UUID player_uuid) {
if (residence_data == null) {
residence_data = new HashMap<>();
Expand Down
13 changes: 3 additions & 10 deletions core/src/main/java/cn/lunadeer/dominion/commands/Helper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.lunadeer.dominion.commands;

import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.DominionInterface;
import cn.lunadeer.dominion.api.dtos.DominionDTO;
import cn.lunadeer.dominion.api.dtos.GroupDTO;
Expand Down Expand Up @@ -64,22 +65,14 @@ public static List<String> groupPlayers(String domName, String groupName) {
public static List<String> playerOwnDominionNames(CommandSender sender) {
Player player = playerOnly(sender);
if (player == null) return new ArrayList<>();
return DominionInterface.instance.getPlayerDominions(player.getUniqueId()).stream().map(DominionDTO::getName).toList();
return Cache.instance.getPlayerDominions(player.getUniqueId()).stream().map(DominionDTO::getName).toList();
}

public static List<String> playerAdminDominionNames(CommandSender sender) {
List<String> dominions_name = new ArrayList<>();
Player player = playerOnly(sender);
if (player == null) return dominions_name;
List<MemberDTO> dominions_admin = new ArrayList<>(cn.lunadeer.dominion.dtos.MemberDTO.selectAll(player.getUniqueId()));
for (MemberDTO member : dominions_admin) {
if (member.getAdmin()) {
DominionDTO dom = DominionInterface.instance.getDominion(member.getDomID());
if (dom == null) continue;
dominions_name.add(dom.getName());
}
}
return dominions_name;
return Cache.instance.getPlayerAdminDominions(player.getUniqueId()).stream().map(DominionDTO::getName).toList();
}

public static List<String> allDominions() {
Expand Down
23 changes: 20 additions & 3 deletions core/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,31 @@ public DominionDTO(UUID owner, String name, @NotNull World world,
this(null, owner, name, world.getUID(), x1, y1, z1, x2, y2, z2, -1);
}

/**
* Creates a new DominionDTO instance.
* <p>
* ONLY USED BY {@link cn.lunadeer.dominion.handler.DominionEventHandler}
*
* @param owner The UUID of the owner of the dominion.
* @param name The name of the dominion.
* @param world The world where the dominion is located.
* @param x1 The first x-coordinate of the dominion.
* @param y1 The first y-coordinate of the dominion.
* @param z1 The first z-coordinate of the dominion.
* @param x2 The second x-coordinate of the dominion.
* @param y2 The second y-coordinate of the dominion.
* @param z2 The second z-coordinate of the dominion.
* @param parent The parent dominion, if any.
* @return A new DominionDTO instance.
*/
public static @NotNull DominionDTO create(UUID owner, String name, @NotNull World world,
Integer x1, Integer y1, Integer z1, Integer x2, Integer y2, Integer z2, cn.lunadeer.dominion.api.dtos.DominionDTO parent) {
x1 = Math.min(x1, x2);
y1 = Math.min(y1, y2);
z1 = Math.min(z1, z2);
x2 = Math.max(x1, x2) + 1;
y2 = Math.max(y1, y2) + 1;
z2 = Math.max(z1, z2) + 1;
x2 = Math.max(x1, x2);
y2 = Math.max(y1, y2);
z2 = Math.max(z1, z2);
return new DominionDTO(null, owner, name, world.getUID(), x1, y1, z1, x2, y2, z2, parent == null ? -1 : parent.getId());
}

Expand Down

0 comments on commit 3aae169

Please sign in to comment.