Skip to content

Commit

Permalink
🐛[main/app] fix team bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepymalc committed Aug 8, 2021
1 parent 018395e commit d6e9cf7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
<version>2.4.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.0-jre</version>
</dependency>
</dependencies>

<build>
Expand Down
35 changes: 21 additions & 14 deletions src/main/java/com/linyuanlin/minecraft/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,32 @@ public boolean onCommand(CommandSender sender, Command cmd, String cmdlable, Str
case "invite": {
Player p = Bukkit.getPlayer(args[1]);
TextComponent a = new TextComponent("[確認組隊邀請]");
a.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("點擊接受 " + sender.getName() + " 的組隊邀請 ")));
a.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new Text("點擊接受 " + sender.getName() + " 的組隊邀請 ")));
a.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team join " + args[1]));
p.spigot().sendMessage(a);
break;
}
case "join": {
Player p = Bukkit.getPlayer(args[1]);
TextComponent msg = new TextComponent("");
if (allPlayers.get(p1.getUniqueId()).team.isEmpty()) {
if (allPlayers.get(p1.getUniqueId()).team.isPresent()) {
List<PlayerData> playerArray = new ArrayList<>();
playerArray.add(allPlayers.get(p1.getUniqueId()));
playerArray.add(allPlayers.get(p.getUniqueId()));
Team team = new Team(playerArray);
Optional<Team> team = Optional.of(new Team(playerArray));
allPlayers.get(p1.getUniqueId()).team = team;
allPlayers.get(p.getUniqueId()).team = team;
team.leader = allPlayers.get(p1.getUniqueId());
msg = new TextComponent(p.getName() + "已加入" + "(" + allPlayers.get(p1.getUniqueId()).team.size() + "/4");
} else if (!allPlayers.get(p1.getUniqueId()).team.isFull()) {
allPlayers.get(p1.getUniqueId()).team.playerList.add(allPlayers.get(Bukkit.getPlayer(args[0]).getUniqueId()));
allPlayers.get(Bukkit.getPlayer(p.getName()).getUniqueId()).team = allPlayers.get(p1.getUniqueId()).team;
msg = new TextComponent(p.getName() + "已加入" + "(" + allPlayers.get(p1.getUniqueId()).team.size() + "/4");
team.get().leader = allPlayers.get(p1.getUniqueId());
msg = new TextComponent(
p.getName() + "已加入" + "(" + allPlayers.get(p1.getUniqueId()).team.get().size() + "/4");
} else if (!allPlayers.get(p1.getUniqueId()).team.get().isFull()) {
allPlayers.get(p1.getUniqueId()).team.get().playerList
.add(allPlayers.get(Bukkit.getPlayer(args[0]).getUniqueId()));
allPlayers.get(Bukkit.getPlayer(p.getName()).getUniqueId()).team = allPlayers
.get(p1.getUniqueId()).team;
msg = new TextComponent(
p.getName() + "已加入" + "(" + allPlayers.get(p1.getUniqueId()).team.get().size() + "/4");
} else {
msg = new TextComponent("隊伍已滿");
}
Expand All @@ -165,16 +170,18 @@ public boolean onCommand(CommandSender sender, Command cmd, String cmdlable, Str
}
case "list": {
StringBuilder teamMemberNameString = new StringBuilder();
for (int i = 0; i < allPlayers.get(p1.getUniqueId()).team.size(); i++) {
teamMemberNameString.append(allPlayers.get(p1.getUniqueId()).team.playerList.get(i).player.getName()).append(" ");
for (int i = 0; i < allPlayers.get(p1.getUniqueId()).team.get().size(); i++) {
teamMemberNameString
.append(allPlayers.get(p1.getUniqueId()).team.get().playerList.get(i).player.getName())
.append(" ");
}
TextComponent msg = new TextComponent("隊伍成員:" + teamMemberNameString);
for (int i = 0; i < allPlayers.get(p1.getUniqueId()).team.size(); i++) {
allPlayers.get(p1.getUniqueId()).team.playerList.get(i).player.spigot().sendMessage(msg);
for (int i = 0; i < allPlayers.get(p1.getUniqueId()).team.get().size(); i++) {
allPlayers.get(p1.getUniqueId()).team.get().playerList.get(i).player.spigot().sendMessage(msg);
}

}
break;
break;
default:
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/linyuanlin/minecraft/models/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

import java.util.List;
import java.util.UUID;
import java.util.Optional;

public class PlayerData {

public Player player;

public int balance = 0;

public Team team;
public Optional<Team> team;

public PlayerData(UUID uuid) throws Exception {

Expand All @@ -34,5 +35,4 @@ public void saveData() {
player.sendMessage(ChatColor.GRAY + "你的資料已自動保存至資料庫");

}

}
13 changes: 7 additions & 6 deletions src/main/java/com/linyuanlin/minecraft/models/Team.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.linyuanlin.minecraft.models;

import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand All @@ -11,20 +12,20 @@ public class Team {
public List<PlayerData> playerList;
public PlayerData leader;

public Team(List<PlayerData> playerList){
public Team(List<PlayerData> playerList) {
this.playerList = playerList;
this.leader = playerList.get(0);
}

public boolean isEmpty(){
return this.playerList.size() == 0 ? true : false;
public boolean isEmpty() {
return this.playerList.size() == 0;
}

public boolean isFull(){
return this.playerList.size() == 4 ? true : false;
public boolean isFull() {
return this.playerList.size() == 4;
}

public int size(){
public int size() {
return this.playerList.size();
}
}

0 comments on commit d6e9cf7

Please sign in to comment.