支持缓存玩家添加的点(最多20个)

This commit is contained in:
张宇衡 2023-06-03 12:16:33 +08:00
parent f9394edefd
commit ee78a96e14
3 changed files with 11 additions and 4 deletions

View File

@ -6,7 +6,7 @@
<groupId>site.deercloud</groupId> <groupId>site.deercloud</groupId>
<artifactId>LiteWorldEdit</artifactId> <artifactId>LiteWorldEdit</artifactId>
<version>1.1-SNAPSHOT</version> <version>1.3-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>LiteWorldEdit</name> <name>LiteWorldEdit</name>

View File

@ -38,7 +38,10 @@ public class Commands implements TabExecutor {
return true; return true;
} }
Point point = new Point(x, y, z, player); Point point = new Point(x, y, z, player);
LiteWorldEdit.instance.getCache().addPoint(player, index, point); if (!LiteWorldEdit.instance.getCache().addPoint(player, index, point)) {
sender.sendMessage("点的数量不允许超过20请使用已有点序号覆盖已有点。");
return true;
}
sender.sendMessage("" + index + " 已设置为 " + x + ", " + y + ", " + z + ""); sender.sendMessage("" + index + " 已设置为 " + x + ", " + y + ", " + z + "");
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
sender.sendMessage("参数错误。"); sender.sendMessage("参数错误。");

View File

@ -23,11 +23,15 @@ public class Cache {
_bars = new HashMap<String, BossBar>(); _bars = new HashMap<String, BossBar>();
} }
public void addPoint(Player player, Integer index, Point point) { public boolean addPoint(Player player, Integer index, Point point) {
if (!_points.containsKey(player.getUniqueId().toString())) { if (!_points.containsKey(player.getUniqueId().toString())) {
_points.put(player.getUniqueId().toString(), new HashMap<Integer, Point>()); _points.put(player.getUniqueId().toString(), new HashMap<Integer, Point>());
} }
if (_points.get(player.getUniqueId().toString()).size() >= 20) {
return false;
}
_points.get(player.getUniqueId().toString()).put(index, point); _points.get(player.getUniqueId().toString()).put(index, point);
return true;
} }
public void addJob(Player player, Job job) { public void addJob(Player player, Job job) {
@ -63,7 +67,7 @@ public class Cache {
} }
public void deletePlayerCache(Player player) { public void deletePlayerCache(Player player) {
_points.remove(player.getUniqueId().toString()); // _points.remove(player.getUniqueId().toString());
_jobs.remove(player.getUniqueId().toString()); _jobs.remove(player.getUniqueId().toString());
_bars.remove(player.getUniqueId().toString()); _bars.remove(player.getUniqueId().toString());
} }