Skip to content

Commit

Permalink
πŸ“Œ[main/App] Team leaving functionality implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepymalc committed Aug 8, 2021
1 parent 0581052 commit 3dfc352
Showing 1 changed file with 37 additions and 6 deletions.
43 changes: 37 additions & 6 deletions src/main/java/com/linyuanlin/minecraft/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public void onJoin(PlayerJoinEvent e) throws Exception {
}
}


@EventHandler
public void onPlayerWorldChange(PlayerChangedWorldEvent e) {
Player p = e.getPlayer();
Expand Down Expand Up @@ -150,13 +149,13 @@ public boolean onCommand(CommandSender sender, Command cmd, String cmdlable, Str
Player p1 = (Player) sender;
if (cmdlable.equals("team")) {
switch (args[0]) {
case "invite": {//p1 invite p to p1's team
case "invite": {// p1 invite p to p1's team
Player p = Bukkit.getPlayer(args[1]);
TextComponent a = new TextComponent();
if (allPlayers.get(p.getUniqueId()).team.isPresent()){
if (allPlayers.get(p.getUniqueId()).team.isPresent()) {
a = new TextComponent(p.getName() + "ε·²ηΆ“ζœ‰ιšŠδΌδΊ†οΌ");
p1.spigot().sendMessage(a);
}else{
} else {
a = new TextComponent("[η’Ίθͺη΅„ιšŠι‚€θ«‹]");
a.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new Text("ι»žζ“ŠζŽ₯受 " + p1.getName() + " ηš„η΅„ιšŠι‚€θ«‹ ")));
Expand All @@ -165,7 +164,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String cmdlable, Str
}
return true;
}
case "join": {//p join p1's team
case "join": {// p join p1's team
Player p = Bukkit.getPlayer(args[1]);
TextComponent msg = new TextComponent("");
if (!allPlayers.get(p.getUniqueId()).team.isPresent()) {
Expand Down Expand Up @@ -205,10 +204,42 @@ public boolean onCommand(CommandSender sender, Command cmd, String cmdlable, Str
teamMemberNameString.append(pd.player.getName()).append(" ");
}

TextComponent msg = new TextComponent("ιšŠδΌζˆε“‘οΌš" + teamMemberNameString);
TextComponent msg = new TextComponent(
"ιšŠδΌζˆε“‘οΌš" + teamMemberNameString + " | ιšŠι•·:" + team.get().leader.player.getName());
p1.spigot().sendMessage(msg);
return true;
}
case "leave": {
Optional<Team> team = allPlayers.get(p1.getUniqueId()).team;
if (!team.isPresent()) {
p1.spigot().sendMessage(new TextComponent("δ½ ζ²’ζœ‰ιšŠδΌ"));
return false;
}

if (team.get().size() == 1) {
team = Optional.empty();
} else {
team.get().playerList.remove((Object) p1);
if (team.get().leader == p1) {
for (PlayerData pd : allPlayers.get(p1.getUniqueId()).team.get().playerList) {
if (team.get().leader != p1) {
team.get().leader = pd;
break;
}
}
for (PlayerData pd : allPlayers.get(p1.getUniqueId()).team.get().playerList) {
pd.player.spigot().sendMessage(new TextComponent(
"ιšŠι•· " + p1.getName() + " ι›’ι–‹δΊ†ιšŠδΌ, ζ–°ιšŠι•·η‚Ί" + team.get().leader.player.getName()));
}
} else {
for (PlayerData pd : allPlayers.get(p1.getUniqueId()).team.get().playerList) {
pd.player.spigot().sendMessage(new TextComponent("ιšŠε“‘ " + p1.getName() + " ι›’ι–‹δΊ†ιšŠδΌ"));
}
}
}
p1.spigot().sendMessage(new TextComponent("δ½ ι›’ι–‹δΊ†ιšŠδΌ"));
return true;
}
default:
break;
}
Expand Down

0 comments on commit 3dfc352

Please sign in to comment.