gpt4 book ai didi

java - ConcurrentModificationException 小游戏

转载 作者:行者123 更新时间:2023-11-29 07:07:50 26 4
gpt4 key购买 nike

<分区>

您好。

我正在运行一个服务器并添加了一个小游戏。

每当游戏即将开始时..它首先调用 onStart()。现在我在这一行得到了 ConcurrentModificationException:

for(Player p : waiting) {

方法如下:

    public void onStart() {
trawler.players.clear();
for(Player p : waiting) {
if(!boat.playerInArea(p)) {
waiting.remove(p);
}
}

for(Player p : waiting) {
trawler.players.add(p);
}

trawler.start();
waiting.clear();
}

如果您需要这些类(class),请看这里:

TrawlerWaitingRoom.java:

package server.model.minigames.trawler;

import server.model.players.Location;
import server.model.players.Player;

public class TrawlerWaitingRoom extends WaitingRoom {
private Trawler trawler;
//private Location boat = new Location(2668,2674,3165,3185);
private Location boat = new Location(2808, 2811,3415,3425);


public TrawlerWaitingRoom(Trawler trawler) {
super(1, 2);
this.trawler = trawler;
}

@Override
public boolean startGame() {
if(trawler.inProgress()) {
return false;
}
return true;
}

@Override
public void onStart() {
trawler.players.clear();
for(Player p : waiting) {
if(!boat.playerInArea(p)) {
waiting.remove(p);
}
}

for(Player p : waiting) {
trawler.players.add(p);
}

trawler.start();
waiting.clear();
}

@Override
public void onLeave(Player p) {
p.asClient().getPA().movePlayer(2804, 3421, 0);
//p.asClient().getPA().movePlayer(2676, 3170, 0);
}

@Override
public void onJoin(Player p) {
p.asClient().getPA().movePlayer(2808, 3421, 1);
//p.asClient().getPA().movePlayer(2672, 3170, 1);
if(!isActive()) {
p.asClient().sendMessage(trawler.getGameTime() == 0 ? "The trawler will be returning in less than a minute!" : "The trawler will return in "+trawler.getGameTime() + (trawler.getGameTime() == 1 ? " minute" : " minutes")+"!");
} else {
p.asClient().sendMessage(getTimeRemaining() == 0 ? "The trawler will be leaving in less than a minute!" : "The trawler will leave in "+ getTimeRemaining() + (getTimeRemaining() == 1 ? " minute" : " minutes")+"!");
}
}

@Override
public Location getLocation() {
return boat;
}

@Override
public void onTimeChange() {
for(Player p : waiting) {
if(!isActive()) {
p.asClient().sendMessage(trawler.getGameTime() == 0 ? "The trawler will be returning in less than a minute!" : "The trawler will return in "+trawler.getGameTime() + (trawler.getGameTime() == 1 ? " minute" : " minutes")+"!");
} else {
p.asClient().sendMessage(getTimeRemaining() == 0 ? "The trawler will be leaving in less than a minute!" : "The trawler will leave in "+ getTimeRemaining() + (getTimeRemaining() == 1 ? " minute" : " minutes")+"!");
}
}
}

@Override
public boolean canStart() {
if(trawler.inProgress()) {
return false;
}
if(waiting.size() < minimumPlayers) {
return false;
}
return true;
}

GroupMinigame.java:

package server.model.minigames.trawler;

import server.model.minigames.trawler.WaitingRoom;

public abstract class GroupMinigame {

public abstract WaitingRoom getWaitingRoom();

public abstract String getWaitingRoomMessage();
}

WaitingRoom.java: http://pastebin.com/KkC8ReWV

拖网渔船.java: http://pastebin.com/XW5XrsjR

提前致谢!

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com