优化缓存逻辑
This commit is contained in:
parent
ca9f5b0925
commit
1e79169926
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>cn.lunadeer</groupId>
|
<groupId>cn.lunadeer</groupId>
|
||||||
<artifactId>Dominion</artifactId>
|
<artifactId>Dominion</artifactId>
|
||||||
<version>1.24.4-beta</version>
|
<version>1.24.5-beta</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>Dominion</name>
|
<name>Dominion</name>
|
||||||
|
@ -11,7 +11,6 @@ import javax.annotation.Nullable;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
@ -121,19 +120,16 @@ public class Cache {
|
|||||||
}
|
}
|
||||||
if (dominion != null) {
|
if (dominion != null) {
|
||||||
if (!isInDominion(dominion, player)) {
|
if (!isInDominion(dominion, player)) {
|
||||||
// glow
|
if (dominion.isTopDom()) {
|
||||||
player.setGlowing(false);
|
|
||||||
if (dominion.getParentDomId() == -1) {
|
|
||||||
Dominion.notification.info(player, "您已离开领地:%s", dominion.getName());
|
Dominion.notification.info(player, "您已离开领地:%s", dominion.getName());
|
||||||
player.sendMessage(Component.text(dominion.getLeaveMessage()));
|
player.sendMessage(Component.text(dominion.getLeaveMessage()));
|
||||||
update_player_current_dominion(player, null);
|
|
||||||
dominion = null;
|
dominion = null;
|
||||||
} else {
|
} else {
|
||||||
Dominion.notification.info(player, "您已离开子领地:%s", dominion.getName());
|
Dominion.notification.info(player, "您已离开子领地:%s", dominion.getName());
|
||||||
player.sendMessage(Component.text(dominion.getLeaveMessage()));
|
player.sendMessage(Component.text(dominion.getLeaveMessage()));
|
||||||
dominion = id_dominions.get(dominion.getParentDomId());
|
dominion = id_dominions.get(dominion.getParentDomId());
|
||||||
update_player_current_dominion(player, dominion);
|
|
||||||
}
|
}
|
||||||
|
update_player_current_dominion(player, dominion);
|
||||||
} else {
|
} else {
|
||||||
// 如果在领地内则检查是否在子领地内
|
// 如果在领地内则检查是否在子领地内
|
||||||
List<Integer> children = dominion_children.get(dominion.getId());
|
List<Integer> children = dominion_children.get(dominion.getId());
|
||||||
@ -150,29 +146,20 @@ public class Cache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dominion == null) {
|
if (dominion == null) {
|
||||||
String world = player.getWorld().getName();
|
List<DominionDTO> in_dominions = getDominionsParentAndChildren(player.getLocation());
|
||||||
List<Integer> dominions_id = world_dominions.get(world);
|
if (in_dominions.size() != 0) {
|
||||||
if (dominions_id == null) return null;
|
dominion = in_dominions.get(0);
|
||||||
List<DominionDTO> in_dominions = new ArrayList<>();
|
Dominion.notification.info(player, "您正在进入领地:%s", dominion.getName());
|
||||||
for (Integer id : dominions_id) {
|
player.sendMessage(Component.text(dominion.getJoinMessage()));
|
||||||
DominionDTO d = id_dominions.get(id);
|
|
||||||
if (isInDominion(d, player)) {
|
|
||||||
in_dominions.add(d);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (in_dominions.size() == 0) return null;
|
|
||||||
in_dominions.sort(Comparator.comparingInt(DominionDTO::getId));
|
|
||||||
dominion = in_dominions.get(0);
|
|
||||||
Dominion.notification.info(player, "您正在进入领地:%s", dominion.getName());
|
|
||||||
player.sendMessage(Component.text(dominion.getJoinMessage()));
|
|
||||||
update_player_current_dominion(player, dominion);
|
update_player_current_dominion(player, dominion);
|
||||||
}
|
}
|
||||||
return dominion;
|
return dominion;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update_player_current_dominion(Player player, DominionDTO dominion) {
|
private void update_player_current_dominion(Player player, DominionDTO dominion) {
|
||||||
|
lightOrNot(player, dominion); // 发光检查
|
||||||
if (dominion == null) {
|
if (dominion == null) {
|
||||||
player.setGlowing(false);
|
|
||||||
player_current_dominion_id.put(player.getUniqueId(), null);
|
player_current_dominion_id.put(player.getUniqueId(), null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -183,32 +170,45 @@ public class Cache {
|
|||||||
dominion.getLocation1(),
|
dominion.getLocation1(),
|
||||||
dominion.getLocation2());
|
dominion.getLocation2());
|
||||||
}
|
}
|
||||||
// glow
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查玩家是否需要设置为发光
|
||||||
|
*
|
||||||
|
* @param player 玩家
|
||||||
|
* @param dominion 领地
|
||||||
|
*/
|
||||||
|
private void lightOrNot(Player player, DominionDTO dominion) {
|
||||||
|
if (dominion == null) {
|
||||||
|
player.setGlowing(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
PlayerPrivilegeDTO privilege = getPlayerPrivilege(player, dominion);
|
PlayerPrivilegeDTO privilege = getPlayerPrivilege(player, dominion);
|
||||||
if (privilege != null) {
|
if (privilege != null) {
|
||||||
if (privilege.getGlow()) {
|
player.setGlowing(privilege.getGlow());
|
||||||
player.setGlowing(true);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (dominion.getGlow()) {
|
player.setGlowing(dominion.getGlow());
|
||||||
player.setGlowing(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DominionDTO getDominion(Location loc) {
|
private List<DominionDTO> getDominionsParentAndChildren(Location loc) {
|
||||||
String world = loc.getWorld().getName();
|
String world = loc.getWorld().getName();
|
||||||
List<Integer> dominions_id = world_dominions.get(world);
|
List<Integer> dominions_id = world_dominions.get(world);
|
||||||
if (dominions_id == null) return null;
|
|
||||||
List<DominionDTO> in_dominions = new ArrayList<>();
|
List<DominionDTO> in_dominions = new ArrayList<>();
|
||||||
|
if (dominions_id == null) return in_dominions;
|
||||||
for (Integer id : dominions_id) {
|
for (Integer id : dominions_id) {
|
||||||
DominionDTO d = id_dominions.get(id);
|
DominionDTO d = id_dominions.get(id);
|
||||||
if (isInDominion(d, loc)) {
|
if (isInDominion(d, loc)) {
|
||||||
in_dominions.add(d);
|
in_dominions.add(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (in_dominions.size() == 0) return null;
|
|
||||||
in_dominions.sort(Comparator.comparingInt(DominionDTO::getId));
|
in_dominions.sort(Comparator.comparingInt(DominionDTO::getId));
|
||||||
|
return in_dominions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DominionDTO getDominion(Location loc) {
|
||||||
|
List<DominionDTO> in_dominions = getDominionsParentAndChildren(loc);
|
||||||
|
if (in_dominions.size() == 0) return null;
|
||||||
return in_dominions.get(in_dominions.size() - 1);
|
return in_dominions.get(in_dominions.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -530,6 +530,10 @@ public class DominionDTO {
|
|||||||
return parentDomId;
|
return parentDomId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isTopDom() {
|
||||||
|
return parentDomId == -1;
|
||||||
|
}
|
||||||
|
|
||||||
public DominionDTO setParentDomId(Integer parentDomId) {
|
public DominionDTO setParentDomId(Integer parentDomId) {
|
||||||
this.parentDomId = parentDomId;
|
this.parentDomId = parentDomId;
|
||||||
return update(this);
|
return update(this);
|
||||||
|
Reference in New Issue
Block a user