Skip to content

Commit

Permalink
v1.8.0 整理一些代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Sobadfish committed Sep 5, 2022
1 parent 1e9cfe7 commit 9f8ea17
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 58 deletions.
14 changes: 12 additions & 2 deletions src/main/java/org/sobadfish/bedwar/manager/RandomJoinManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,24 @@ public static RandomJoinManager newInstance(){

public void nextJoin(PlayerInfo info){
//TODO 匹配下一局 程序分配
// info.getGameRoom().quitPlayerInfo(info,true);
join(info,null);
GameRoom gameRoom = info.getGameRoom();
if(gameRoom != null){
gameRoom.quitPlayerInfo(info,false);
}
join(info,null,true);
}

public void join(PlayerInfo info, String name){
join(info, name,false);
}

public void join(PlayerInfo info, String name,boolean isNext){
if(info.getGameRoom() != null && info.getGameRoom().getType() != GameRoom.GameType.END){
return;
}
IPlayerInfo iPlayerInfo = new IPlayerInfo();
iPlayerInfo.playerInfo = info;
iPlayerInfo.isNext = isNext;
if(playerInfos.contains(iPlayerInfo)){
info.sendForceMessage("&c取消匹配");
playerInfos.remove(iPlayerInfo);
Expand All @@ -64,6 +72,8 @@ public static class IPlayerInfo{

public boolean cancel;

public boolean isNext;

public PlayerInfo getPlayerInfo() {
if(playerInfo != null && playerInfo.getPlayer() instanceof Player && !playerInfo.getPlayer().closed){
return playerInfo;
Expand Down
46 changes: 20 additions & 26 deletions src/main/java/org/sobadfish/bedwar/player/PlayerInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public EntityHuman getPlayer() {
}

public void setLeave(boolean leave) {

isLeave = leave;
if(leave){
playerType = PlayerType.LEAVE;
Expand Down Expand Up @@ -484,7 +483,7 @@ public String toString(){
teamName = "&7[&r"+teamInfo.getTeamConfig().getNameColor()+teamInfo.getTeamConfig().getName()+"&7]&r";
playerName = teamInfo.getTeamConfig().getNameColor()+" &7"+player.getName();
}else if(isWatch()){
teamName = "&7[旁观]";
teamName = "&7[旁观] ";
}

return "&7["+data.getLevelString()+"&7]&r "+teamName+playerName;
Expand Down Expand Up @@ -595,9 +594,10 @@ private ArrayList<String> getLore(boolean isWait){
* 定时任务
* */
public void onUpdate(){
if(gameRoom != null && gameRoom.getType() == GameRoom.GameType.END){
if(gameRoom == null || gameRoom.getType() == GameRoom.GameType.END){
return;
}

updateTime++;
if(isWatch()){
if(player instanceof Player){
Expand Down Expand Up @@ -639,9 +639,13 @@ public void onUpdate(){
}else{
if(spawnTime == 0 && !isSendkey){
isSendkey = true;
sendTitle("&c你死了",gameRoom.reSpawnTime);
if(gameRoom != null) {
sendTitle("&c你死了", gameRoom.reSpawnTime);
}
}
if(gameRoom != null) {
sendSubTitle((gameRoom.reSpawnTime - spawnTime) + " 秒后复活");
}
sendSubTitle((gameRoom.reSpawnTime - spawnTime)+" 秒后复活");
spawnTime++;
}

Expand Down Expand Up @@ -854,20 +858,7 @@ public boolean isDeath(){
}

private void leave(){
if(player instanceof Player){
if(((Player) player).isOnline()){
player.setNameTag(player.getName());
player.getInventory().clearAll();
((Player) player).sendExperience(0);
if(inventory != null && eInventory != null){
player.getInventory().setContents(inventory.getContents());
player.getEnderChestInventory().setContents(eInventory.getContents());
}
if(getPlayer() instanceof Player) {
((Player) getPlayer()).setGamemode(0);
}
}
}
clear();
if(getTeamInfo() != null){
getTeamInfo().quit(this);
}
Expand Down Expand Up @@ -922,16 +913,19 @@ public void spawn() {

public void clear(){
if(player instanceof Player){
if(((Player) player).isOnline()) {
((Player) player).setExperience(0,0);
((Player) player).getUIInventory().clearAll();
player.getEnderChestInventory().clearAll();
if(((Player) player).isOnline()){
player.setNameTag(player.getName());
player.getInventory().clearAll();
((Player) player).getFoodData().reset();
player.removeAllEffects();
((Player) player).sendExperience(0);
if(inventory != null && eInventory != null){
player.getInventory().setContents(inventory.getContents());
player.getEnderChestInventory().setContents(eInventory.getContents());
}
if(getPlayer() instanceof Player) {
((Player) getPlayer()).setGamemode(0);
}
}
}

}

public void putEffect(ArrayList<TeamEffectInfo> effects){
Expand Down
40 changes: 14 additions & 26 deletions src/main/java/org/sobadfish/bedwar/room/GameRoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -498,16 +498,6 @@ public JoinType joinPlayerInfo(PlayerInfo info,boolean sendMessage){
}else {
if(info.getGameRoom().getType() != GameType.END && info.getGameRoom() == this){
return JoinType.NO_JOIN;
// if(info.getGameRoom().getType() != GameType.WAIT){
// info.getGameRoom().quitPlayerInfo(info,false);
// return JoinType.CAN_WATCH;
// }
// if(info.getTeamInfo() != null){
// info.death(null);
// }else{
// info.getGameRoom().quitPlayerInfo(info,false);
// return JoinType.CAN_WATCH;
// }
}else{
info.getGameRoom().quitPlayerInfo(info,true);
return JoinType.CAN_WATCH;
Expand Down Expand Up @@ -581,6 +571,8 @@ public LinkedList<PlayerInfo> getNoTeamPlayers(){
return noTeam;
}



/**
* 玩家离开游戏
* */
Expand All @@ -589,7 +581,6 @@ public boolean quitPlayerInfo(PlayerInfo info,boolean teleport){

if (info.getPlayer() instanceof Player) {
if (playerInfos.contains(info)) {
info.setLeave(true);
PlayerQuitRoomEvent event = new PlayerQuitRoomEvent(info, this, BedWarMain.getBedWarMain());
Server.getInstance().getPluginManager().callEvent(event);
if (teleport) {
Expand All @@ -598,13 +589,10 @@ public boolean quitPlayerInfo(PlayerInfo info,boolean teleport){
info.cancel();
info.getPlayer().removeAllEffects();
((Player) info.getPlayer()).setExperience(0, 0);
if (((Player) info.getPlayer()).isOnline()) {
BedWarMain.getRoomManager().playerJoin.remove(info.getPlayer().getName());
}
BedWarMain.getRoomManager().playerJoin.remove(info.getPlayer().getName());
} else {
if (((Player) info.getPlayer()).isOnline()) {
BedWarMain.getRoomManager().playerJoin.remove(info.getPlayer().getName());
}
BedWarMain.getRoomManager().playerJoin.remove(info.getPlayer().getName());

}
} else {
info.getPlayer().close();
Expand Down Expand Up @@ -830,19 +818,19 @@ public void onDisable(){
for(PlayerInfo playerInfo: getInRoomPlayers()){
RandomJoinManager.joinManager.nextJoin(playerInfo);
}
}else {
//TODO 房间被关闭 释放一些资源
for (PlayerInfo info : playerInfos) {
info.clear();
if (info.getPlayer() instanceof Player) {
quitPlayerInfo(info, true);
}
//没必要破坏床
}
//TODO 房间被关闭 释放一些资源
for (PlayerInfo info : playerInfos) {
info.clear();
if (info.getPlayer() instanceof Player) {
quitPlayerInfo(info, true);
}
//没必要破坏床
// if (info.getTeamInfo() != null) {
// info.getTeamInfo().breakBed();
// }
}
}

//浮空字释放
for(FloatTextInfo floatTextInfo: floatTextInfos){
floatTextInfo.bedWarFloatText.toClose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
import cn.nukkit.Player;
import cn.nukkit.Server;
import org.sobadfish.bedwar.BedWarMain;
import org.sobadfish.bedwar.manager.*;
import org.sobadfish.bedwar.manager.PlayerHasChoseRoomManager;
import org.sobadfish.bedwar.manager.RandomJoinManager;
import org.sobadfish.bedwar.manager.ThreadManager;
import org.sobadfish.bedwar.player.PlayerInfo;
import org.sobadfish.bedwar.room.GameRoom;
import org.sobadfish.bedwar.room.WorldRoom;
import org.sobadfish.bedwar.room.config.GameRoomConfig;
import org.sobadfish.bedwar.tools.Utils;
import org.sobadfish.bedwar.world.config.WorldInfoConfig;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

/**
Expand Down Expand Up @@ -56,7 +56,6 @@ public void run() {
if(info.getPlayerInfo().getPlayer() instanceof Player) {
info.getPlayerInfo().clear();
info.getPlayerInfo().getPlayer().teleport(Server.getInstance().getDefaultLevel().getSafeSpawn());

}
}
RandomJoinManager.newInstance().playerInfos.remove(info);
Expand Down

0 comments on commit 9f8ea17

Please sign in to comment.