Skip to content

Commit

Permalink
修复皮肤id重复导致的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lt-name committed Nov 18, 2023
1 parent 0bcf4c4 commit bbc64d3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 40 deletions.
5 changes: 4 additions & 1 deletion src/main/java/cn/lanink/gunwar/GunWar.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,10 @@ private Skin loadSkin(File img, File json) {
Skin skin = new Skin();
skin.setTrusted(true);
skin.setSkinData(skinData);
String skinId = "GunWar" + img.getName().split("\\.")[0];
String skinId = "GunWar:" +
img.getName().split("\\.")[0] + ":" +
json.getName().split("\\.")[0] + ":" +
flagSkinMap.size() + ":" + RANDOM.nextInt(1000);
skin.setSkinId(skinId);

Map<String, Object> skinJson = new Config(json, Config.JSON).getAll();
Expand Down
56 changes: 28 additions & 28 deletions src/main/java/cn/lanink/gunwar/room/conquest/ConquestModeRoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public class ConquestModeRoom extends BaseRespawnModeRoom {
@Getter
private final Vector3 conquestPointC;

public EntityLongFlag aFlag;
public EntityLongFlag bFlag;
public EntityLongFlag cFlag;
public EntityLongFlag flagA;
public EntityLongFlag flagB;
public EntityLongFlag flagC;

private final ConcurrentHashMap<Player, DummyBossBar> bossBarMap = new ConcurrentHashMap<>();
private int bossBarShowTime = 0;
Expand All @@ -53,9 +53,9 @@ public ConquestModeRoom(@NotNull Level level, @NotNull Config config) throws Roo
String aPosString = config.getString("ConquestPointA");
String bPosString = config.getString("ConquestPointB");
String cPosString = config.getString("ConquestPointC");
if ("".equals(aPosString.trim()) ||
"".equals(bPosString.trim()) ||
"".equals(cPosString.trim())) {
if (aPosString.trim().isEmpty() ||
bPosString.trim().isEmpty() ||
cPosString.trim().isEmpty()) {
throw new RoomLoadException("§c房间:" + level.getFolderName() + " 配置不完整,加载失败!");
}
this.conquestPointA = Tools.stringToVector3(aPosString);
Expand All @@ -70,17 +70,17 @@ protected void initData() {
this.redScore = this.getVictoryScore() / 2;
this.blueScore = this.getVictoryScore() / 2;

if (this.aFlag != null) {
this.aFlag.close();
this.aFlag = null;
if (this.flagA != null) {
this.flagA.close();
this.flagA = null;
}
if (this.bFlag != null) {
this.bFlag.close();
this.bFlag = null;
if (this.flagB != null) {
this.flagB.close();
this.flagB = null;
}
if (this.cFlag != null) {
this.cFlag.close();
this.cFlag = null;
if (this.flagC != null) {
this.flagC.close();
this.flagC = null;
}

if (this.bossBarMap != null && !this.bossBarMap.isEmpty()) {
Expand All @@ -97,10 +97,10 @@ public void timeTask() {
super.timeTask();

if (!this.isRoundEnd()) {
if (this.aFlag != null && this.bFlag != null && this.cFlag != null) { //初始化时可能为空
String text = "§aA: " + (this.aFlag.getTeam() == Team.NULL ? "§fX" : this.aFlag.getTeam().getShowName()) +
" §aB: " + (this.bFlag.getTeam() == Team.NULL ? "§fX" : this.bFlag.getTeam().getShowName()) +
" §aC: " + (this.cFlag.getTeam() == Team.NULL ? "§fX" : this.cFlag.getTeam().getShowName());
if (this.flagA != null && this.flagB != null && this.flagC != null) { //初始化时可能为空
String text = "§aA: " + (this.flagA.getTeam() == Team.NULL ? "§fX" : this.flagA.getTeam().getShowName()) +
" §aB: " + (this.flagB.getTeam() == Team.NULL ? "§fX" : this.flagB.getTeam().getShowName()) +
" §aC: " + (this.flagC.getTeam() == Team.NULL ? "§fX" : this.flagC.getTeam().getShowName());

for (Player player : this.getPlayerDataMap().keySet()) {
Tools.createBossBar(player, this.bossBarMap);
Expand All @@ -122,24 +122,24 @@ public void timeTask() {
if (this.gameTime%5 == 0) {
int redFlagCount = 0;
int blueFlagCount = 0;
if (this.aFlag.getKeepTime() > 5) {
if (this.aFlag.getTeam() == Team.RED) {
if (this.flagA.getKeepTime() > 5) {
if (this.flagA.getTeam() == Team.RED) {
redFlagCount++;
} else if (this.aFlag.getTeam() == Team.BLUE) {
} else if (this.flagA.getTeam() == Team.BLUE) {
blueFlagCount++;
}
}
if (this.bFlag.getKeepTime() > 5) {
if (this.bFlag.getTeam() == Team.RED) {
if (this.flagB.getKeepTime() > 5) {
if (this.flagB.getTeam() == Team.RED) {
redFlagCount++;
} else if (this.bFlag.getTeam() == Team.BLUE) {
} else if (this.flagB.getTeam() == Team.BLUE) {
blueFlagCount++;
}
}
if (this.cFlag.getKeepTime() > 5) {
if (this.cFlag.getTeam() == Team.RED) {
if (this.flagC.getKeepTime() > 5) {
if (this.flagC.getTeam() == Team.RED) {
redFlagCount++;
} else if (this.cFlag.getTeam() == Team.BLUE) {
} else if (this.flagC.getTeam() == Team.BLUE) {
blueFlagCount++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void onRun() {
try {
this.work(this.tick);
} catch (Exception e) {
GunWar.getInstance().getLogger().error("FlagRadiusShowTask Error!", e);
GunWar.getInstance().getLogger().error("AsyncFlagRadiusCheckTask Error!", e);
}

this.tick++;
Expand All @@ -49,7 +49,7 @@ public void onRun() {
try {
Thread.sleep(Math.max(50L - duration, 1));
} catch (Exception e) {
GunWar.getInstance().getLogger().error("FlagRadiusShowTask Error!", e);
GunWar.getInstance().getLogger().error("AsyncFlagRadiusCheckTask Error!", e);
}
}
}
Expand All @@ -67,15 +67,21 @@ private void work(int tick) {
cFlagPlayers.add(player);
}
}
this.checkCapturePoints(aFlagPlayers, this.room.aFlag);
this.checkCapturePoints(bFlagPlayers, this.room.bFlag);
this.checkCapturePoints(cFlagPlayers, this.room.cFlag);
this.checkCapturePoints(aFlagPlayers, this.room.flagA);
this.checkCapturePoints(bFlagPlayers, this.room.flagB);
this.checkCapturePoints(cFlagPlayers, this.room.flagC);

if (tick%20 == 1) {
this.showParticleEffect();
}
}

/**
* 检查旗帜占领进度
*
* @param players 在占领范围内的玩家列表
* @param flag 旗帜
*/
private void checkCapturePoints(ArrayList<Player> players, EntityLongFlag flag) {
ArrayList<Player> redCount = new ArrayList<>();
ArrayList<Player> blueCount = new ArrayList<>();
Expand All @@ -98,6 +104,9 @@ private void checkCapturePoints(ArrayList<Player> players, EntityLongFlag flag)
}
}

/**
* 显示占领范围粒子效果
*/
private void showParticleEffect() {
LinkedList<Vector3> list = Tools.getRoundEdgePoint(this.room.getConquestPointA(), this.room.getConquestPointRadius());
list.addAll(Tools.getRoundEdgePoint(this.room.getConquestPointB(), this.room.getConquestPointRadius()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ private void checkAndSpawnFlag(int i) {
Vector3 vector3 = null;
switch (i) {
case 1:
entityLongFlag = this.room.aFlag;
entityLongFlag = this.room.flagA;
vector3 = this.room.getConquestPointA();
break;
case 2:
entityLongFlag = this.room.bFlag;
entityLongFlag = this.room.flagB;
vector3 = this.room.getConquestPointB();
break;
case 3:
entityLongFlag = this.room.cFlag;
entityLongFlag = this.room.flagC;
vector3 = this.room.getConquestPointC();
break;
}
Expand All @@ -70,13 +70,13 @@ private void checkAndSpawnFlag(int i) {
entityLongFlag.spawnToAll();
switch (i) {
case 1:
this.room.aFlag = entityLongFlag;
this.room.flagA = entityLongFlag;
break;
case 2:
this.room.bFlag = entityLongFlag;
this.room.flagB = entityLongFlag;
break;
case 3:
this.room.cFlag = entityLongFlag;
this.room.flagC = entityLongFlag;
break;
}
}
Expand Down

0 comments on commit bbc64d3

Please sign in to comment.