Skip to content

Commit

Permalink
📌[main/TeamManager] Change every attribute into private
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepymalc committed Aug 16, 2021
1 parent 6460c2f commit 944f5d8
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 95 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/linyuanlin/minecraft/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public void onPlayerInteract(PlayerInteractEntityEvent event1) {
Entity entity = event1.getRightClicked();
if (entity instanceof Player && event1.getHand() == EquipmentSlot.HAND) {
p.sendMessage("他是 " + entity.getName());
p.sendMessage("該玩家擁有財產 " + allPlayers.get(entity.getUniqueId()).getBalance() + " 元");
p.sendMessage("該玩家擁有財產 " + allPlayers.get(entity.getUniqueId()).balance() + " 元");
TextComponent a = new TextComponent("[傳送組隊邀請]");
a.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("點擊發送組隊邀請給 " + entity.getName())));
a.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/team invite " + entity.getName()));
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/linyuanlin/minecraft/Manager/GuildManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}

private boolean getInvitationPaper(PlayerData senderPlayer) {
if (senderPlayer.getBalance() < 1000) {
senderPlayer.player.sendMessage(
"你的錢不夠購買公會創立卷! " + ChatColor.RED + "(" + senderPlayer.getBalance() + "/1000)");
if (senderPlayer.balance() < 1000) {
senderPlayer.player().sendMessage(
"你的錢不夠購買公會創立卷! " + ChatColor.RED + "(" + senderPlayer.balance() + "/1000)");
return false;
}
senderPlayer.modifyBalance(-1000, "Buy Guild Invitation Paper");
senderPlayer.player.sendMessage("你已成功購買公會創立卷! " + senderPlayer.getBalanceString());
senderPlayer.player.getInventory().addItem(new ItemStack(CustomItem.guildInvitationPaper));
senderPlayer.player().sendMessage("你已成功購買公會創立卷! " + senderPlayer.getBalanceString());
senderPlayer.player().getInventory().addItem(new ItemStack(CustomItem.guildInvitationPaper));
return true;
}

Expand All @@ -71,12 +71,12 @@ private boolean second(PlayerData senderPlayer, String[] args) {
}

private boolean help(PlayerData senderPlayer) {
senderPlayer.player.sendMessage(ChatColor.RED + "沒有這個指令");
senderPlayer.player.sendMessage(ChatColor.AQUA + "/guild 的使用方式:");
senderPlayer.player().sendMessage(ChatColor.RED + "沒有這個指令");
senderPlayer.player().sendMessage(ChatColor.AQUA + "/guild 的使用方式:");

senderPlayer.player.sendMessage("/guild getInvitationPaper" + ChatColor.GRAY + " - 獲得公會創立卷");
senderPlayer.player().sendMessage("/guild getInvitationPaper" + ChatColor.GRAY + " - 獲得公會創立卷");

senderPlayer.player.sendMessage(ChatColor.GRAY + "/guild help - 取得幫助");
senderPlayer.player().sendMessage(ChatColor.GRAY + "/guild help - 取得幫助");
return false;
}
}
110 changes: 56 additions & 54 deletions src/main/java/com/linyuanlin/minecraft/Manager/TeamManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,54 +82,54 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
*/
private boolean invite(PlayerData senderPlayer, String[] args) {
if (args.length != 2) {
senderPlayer.player.sendMessage(ChatColor.RED + "邀請指令錯誤");
senderPlayer.player().sendMessage(ChatColor.RED + "邀請指令錯誤");
this.help(senderPlayer);
return false;
}

Player p = Bukkit.getPlayer(args[1]);
if (p == null) {
senderPlayer.player.sendMessage(
senderPlayer.player().sendMessage(
"你邀請的玩家 " + ChatColor.GOLD + args[1] + ChatColor.WHITE + " 不存在或是不在線上!");
return false;
}

PlayerData receiverPlayer = app.allPlayers.get(p.getUniqueId());
if (receiverPlayer == null) {
senderPlayer.player.sendMessage("你邀請的玩家 " + ChatColor.GOLD + args[1] + ChatColor.WHITE
senderPlayer.player().sendMessage("你邀請的玩家 " + ChatColor.GOLD + args[1] + ChatColor.WHITE
+ " 不存在於allPlayers中,請聯繫開發人員");
return false;
}

Optional<Team> team = app.allPlayers.get(receiverPlayer.player.getUniqueId()).team;
Optional<Team> team = app.allPlayers.get(receiverPlayer.player().getUniqueId()).team();

if (receiverPlayer == senderPlayer) {
senderPlayer.player.sendMessage("不能邀請自己");
senderPlayer.player().sendMessage("不能邀請自己");
return false;
}

if (team.isPresent()) {
senderPlayer.player.sendMessage(
ChatColor.GOLD + receiverPlayer.player.getName() + ChatColor.WHITE + "已經有隊伍了!");
senderPlayer.player().sendMessage(ChatColor.GOLD + receiverPlayer.player().getName()
+ ChatColor.WHITE + "已經有隊伍了!");
return false;
}

if (senderPlayer.isInviteCooling(receiverPlayer)) {
senderPlayer.player.sendMessage("邀請" + ChatColor.GOLD + receiverPlayer.player.getName()
senderPlayer.player().sendMessage("邀請" + ChatColor.GOLD + receiverPlayer.player().getName()
+ ChatColor.WHITE + "冷卻中" + ChatColor.RED + "(1分鐘)");
return false;
}

TextComponent msg;
msg = new TextComponent(
"[確認 " + ChatColor.GOLD + senderPlayer.player.getName() + ChatColor.WHITE + " 的組隊邀請]");
msg = new TextComponent("[確認 " + ChatColor.GOLD + senderPlayer.player().getName() + ChatColor.WHITE
+ " 的組隊邀請]");
msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("點擊接受 " + ChatColor.GOLD
+ senderPlayer.player.getName() + ChatColor.WHITE + " 的組隊邀請")));
+ senderPlayer.player().getName() + ChatColor.WHITE + " 的組隊邀請")));
msg.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND,
"/team join " + senderPlayer.player.getName()));
receiverPlayer.player.spigot().sendMessage(msg);
"/team join " + senderPlayer.player().getName()));
receiverPlayer.player().spigot().sendMessage(msg);

senderPlayer.player.sendMessage("已發送邀請給 " + ChatColor.GOLD + receiverPlayer.player.getName());
senderPlayer.player().sendMessage("已發送邀請給 " + ChatColor.GOLD + receiverPlayer.player().getName());
senderPlayer.recordInvite(receiverPlayer);

return true;
Expand Down Expand Up @@ -158,36 +158,36 @@ private boolean invite(PlayerData senderPlayer, String[] args) {
*/
private boolean join(PlayerData senderPlayer, String[] args) throws Exception {
if (args.length != 2) {
senderPlayer.player.sendMessage("組隊指令錯誤");
senderPlayer.player().sendMessage("組隊指令錯誤");
this.help(senderPlayer);
return false;
}

Player p = Bukkit.getPlayer(args[1]);
if (p == null) {
senderPlayer.player.sendMessage(
senderPlayer.player().sendMessage(
"你要加入的隊伍的邀請人 " + ChatColor.GOLD + args[1] + ChatColor.WHITE + " 不存在或是不在線上!");
return false;
}
PlayerData receiverPlayer = app.allPlayers.get(p.getUniqueId());
if (receiverPlayer == null) {
senderPlayer.player.sendMessage("你要加入的隊伍的邀請人" + ChatColor.GOLD + args[1] + ChatColor.WHITE
senderPlayer.player().sendMessage("你要加入的隊伍的邀請人" + ChatColor.GOLD + args[1] + ChatColor.WHITE
+ "不存在於allPlayers中, 請聯繫開發人員");
return false;
}

if (senderPlayer.team.isPresent()) {
senderPlayer.player.sendMessage("你已有隊伍");
if (senderPlayer.team().isPresent()) {
senderPlayer.player().sendMessage("你已有隊伍");
return false;
}

if (!senderPlayer.isInvitedBy(receiverPlayer)) {
senderPlayer.player.sendMessage("你並沒有被邀請至 " + ChatColor.GOLD + receiverPlayer.player.getName()
+ ChatColor.WHITE + " 的隊伍");
senderPlayer.player().sendMessage("你並沒有被邀請至 " + ChatColor.GOLD
+ receiverPlayer.player().getName() + ChatColor.WHITE + " 的隊伍");
return false;
}

Optional<Team> team = receiverPlayer.team;
Optional<Team> team = receiverPlayer.team();

TextComponent msg;
if (!team.isPresent()) {
Expand All @@ -199,11 +199,11 @@ private boolean join(PlayerData senderPlayer, String[] args) throws Exception {
e.printStackTrace();
}

receiverPlayer.team = Optional.of(newTeam);
senderPlayer.team = Optional.of(newTeam);
receiverPlayer.replaceTeam(Optional.of(newTeam));
senderPlayer.replaceTeam(Optional.of(newTeam));

msg = new TextComponent(ChatColor.GOLD + senderPlayer.player.getName() + ChatColor.WHITE + "已加入"
+ senderPlayer.teamCapacityStatus());
msg = new TextComponent(ChatColor.GOLD + senderPlayer.player().getName() + ChatColor.WHITE
+ "已加入" + senderPlayer.teamCapacityStatus());

receiverPlayer.destroyInvitedRecord();
} else if (!team.get().isFull()) {
Expand All @@ -213,17 +213,17 @@ private boolean join(PlayerData senderPlayer, String[] args) throws Exception {
e.printStackTrace();
}

senderPlayer.team = team;
senderPlayer.replaceTeam(team);

msg = new TextComponent(ChatColor.GOLD + senderPlayer.player.getName() + ChatColor.WHITE + "已加入"
+ senderPlayer.teamCapacityStatus());
msg = new TextComponent(ChatColor.GOLD + senderPlayer.player().getName() + ChatColor.WHITE
+ "已加入" + senderPlayer.teamCapacityStatus());
} else {
senderPlayer.player.sendMessage("隊伍已滿");
senderPlayer.player().sendMessage("隊伍已滿");

return false;
}

receiverPlayer.team.ifPresent(t -> t.sendMessageToAll(msg));
receiverPlayer.team().ifPresent(t -> t.sendMessageToAll(msg));

senderPlayer.destroyInvitedRecord();

Expand All @@ -243,17 +243,17 @@ private boolean join(PlayerData senderPlayer, String[] args) throws Exception {
*
*/
private boolean list(PlayerData senderPlayer) {
Optional<Team> team = senderPlayer.team;
Optional<Team> team = senderPlayer.team();
if (!team.isPresent()) {
senderPlayer.player.sendMessage("你不在任何隊伍裡");
senderPlayer.player().sendMessage("你不在任何隊伍裡");

return false;
}

senderPlayer.player.spigot()
senderPlayer.player().spigot()
.sendMessage(new TextComponent("隊伍成員:" + team.get().allTeamMemberString()
+ ChatColor.GRAY + " | " + ChatColor.WHITE + "隊長:" + ChatColor.GOLD
+ team.get().leader().player.getName()));
+ team.get().leader().player().getName()));

return true;
}
Expand All @@ -274,19 +274,19 @@ private boolean list(PlayerData senderPlayer) {
*
*/
private boolean leave(PlayerData senderPlayer) {
Optional<Team> team = senderPlayer.team;
Optional<Team> team = senderPlayer.team();
if (!team.isPresent()) {
senderPlayer.player.spigot().sendMessage(new TextComponent("你沒有隊伍"));
senderPlayer.player().spigot().sendMessage(new TextComponent("你沒有隊伍"));
return false;
}

if (team.get().size() == 2) {
team.get().sendMessageToAll(new TextComponent(ChatColor.GOLD + senderPlayer.player.getName()
team.get().sendMessageToAll(new TextComponent(ChatColor.GOLD + senderPlayer.player().getName()
+ ChatColor.WHITE + " 離開了隊伍, 隊伍人數不足,自動解散"));
try {
team.get().delete(senderPlayer);
team.get().delete(team.get().leader());
team.get().leader().team = Optional.empty();
team.get().leader().replaceTeam(Optional.empty());
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -297,26 +297,28 @@ private boolean leave(PlayerData senderPlayer) {
} catch (Exception e) {
e.printStackTrace();
}
senderPlayer.team.ifPresent(t -> t.sendMessageToAll(new TextComponent("隊長 "
+ ChatColor.GOLD + senderPlayer.player.getName() + ChatColor.WHITE
+ " 離開了隊伍, 新隊長為" + ChatColor.GOLD + team.get().leader().player.getName()
+ senderPlayer.teamCapacityStatus())));
senderPlayer.team()
.ifPresent(t -> t.sendMessageToAll(new TextComponent("隊長 "
+ ChatColor.GOLD + senderPlayer.player().getName()
+ ChatColor.WHITE + " 離開了隊伍, 新隊長為" + ChatColor.GOLD
+ team.get().leader().player().getName()
+ senderPlayer.teamCapacityStatus())));
} else {
try {
team.get().delete(senderPlayer);
} catch (Exception e) {
e.printStackTrace();
}
senderPlayer.team.ifPresent(t -> t.sendMessageToAll(new TextComponent(
"隊員 " + ChatColor.GOLD + senderPlayer.player.getName() + ChatColor.WHITE
+ " 離開了隊伍" + senderPlayer.teamCapacityStatus())));
senderPlayer.team().ifPresent(t -> t.sendMessageToAll(new TextComponent("隊員 "
+ ChatColor.GOLD + senderPlayer.player().getName() + ChatColor.WHITE
+ " 離開了隊伍" + senderPlayer.teamCapacityStatus())));
}
} else {
return false;
}

senderPlayer.team = Optional.empty();
senderPlayer.player.spigot().sendMessage(new TextComponent("你離開了隊伍"));
senderPlayer.replaceTeam(Optional.empty());
senderPlayer.player().spigot().sendMessage(new TextComponent("你離開了隊伍"));

return true;
}
Expand All @@ -334,14 +336,14 @@ private boolean leave(PlayerData senderPlayer) {
*
*/
private boolean help(PlayerData senderPlayer) {
senderPlayer.player.sendMessage(ChatColor.RED + "沒有這個指令");
senderPlayer.player.sendMessage(ChatColor.AQUA + "/team 的使用方式:");
senderPlayer.player().sendMessage(ChatColor.RED + "沒有這個指令");
senderPlayer.player().sendMessage(ChatColor.AQUA + "/team 的使用方式:");

senderPlayer.player.sendMessage("/team invite <對象>" + ChatColor.GRAY + " - 邀請其他玩家加入隊伍");
senderPlayer.player.sendMessage("/team join <對象>" + ChatColor.GRAY + " - 加入其他玩家的隊伍");
senderPlayer.player.sendMessage("/team list" + ChatColor.GRAY + " - 顯示隊伍狀態");
senderPlayer.player().sendMessage("/team invite <對象>" + ChatColor.GRAY + " - 邀請其他玩家加入隊伍");
senderPlayer.player().sendMessage("/team join <對象>" + ChatColor.GRAY + " - 加入其他玩家的隊伍");
senderPlayer.player().sendMessage("/team list" + ChatColor.GRAY + " - 顯示隊伍狀態");

senderPlayer.player.sendMessage(ChatColor.GRAY + "/team help - 取得幫助");
senderPlayer.player().sendMessage(ChatColor.GRAY + "/team help - 取得幫助");
return false;
}
}
45 changes: 23 additions & 22 deletions src/main/java/com/linyuanlin/minecraft/Manager/TradeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
}

private boolean me(PlayerData senderPlayer) {
senderPlayer.player.sendMessage(
ChatColor.GRAY + "當前可用餘額:" + ChatColor.WHITE + senderPlayer.getBalance() + " 元");
senderPlayer.player().sendMessage(
ChatColor.GRAY + "當前可用餘額:" + ChatColor.WHITE + senderPlayer.balance() + " 元");
return true;
}

private boolean pay(PlayerData senderPlayer, String[] args) {
if (args.length != 3) {
senderPlayer.player.sendMessage(ChatColor.RED + "轉帳指令錯誤");
senderPlayer.player().sendMessage(ChatColor.RED + "轉帳指令錯誤");
this.help(senderPlayer);
return false;
}
Expand All @@ -65,52 +65,53 @@ private boolean pay(PlayerData senderPlayer, String[] args) {

int amount = Integer.parseInt(amountStr);
if (amount <= 0) {
senderPlayer.player.sendMessage(ChatColor.RED + "請輸入正確的轉帳金額!(轉帳金額不能為負數)");
senderPlayer.player().sendMessage(ChatColor.RED + "請輸入正確的轉帳金額!(轉帳金額不能為負數)");
return false;
}

if (senderPlayer.getBalance() < amount) {
senderPlayer.player.sendMessage(ChatColor.GOLD + "你沒那麼多錢拉,窮逼。");
if (senderPlayer.balance() < amount) {
senderPlayer.player().sendMessage(ChatColor.GOLD + "你沒那麼多錢拉,窮逼。");
return false;
}

Player p = Bukkit.getPlayer(receiverName);
if (p == null) {
senderPlayer.player.sendMessage(
senderPlayer.player().sendMessage(
"玩家 " + ChatColor.GOLD + receiverName + ChatColor.WHITE + " 不存在或是不在線上");
return false;
}

PlayerData receiverPlayer = app.allPlayers.get(p.getUniqueId());
if (receiverPlayer == null) {
senderPlayer.player.sendMessage(
senderPlayer.player().sendMessage(
"玩家 " + ChatColor.GOLD + receiverName + ChatColor.WHITE + " 不存在或是不在線上");
return false;
}

receiverPlayer.modifyBalance(amount, "Receive transfer from " + senderPlayer.player.getName() + " ("
+ senderPlayer.player.getUniqueId() + ")");
receiverPlayer.player.sendMessage(ChatColor.GREEN + "收到來自玩家 " + ChatColor.WHITE
+ senderPlayer.player.getName() + ChatColor.GREEN + " 的轉帳 " + ChatColor.WHITE
receiverPlayer.modifyBalance(amount, "Receive transfer from " + senderPlayer.player().getName() + " ("
+ senderPlayer.player().getUniqueId() + ")");
receiverPlayer.player().sendMessage(ChatColor.GREEN + "收到來自玩家 " + ChatColor.WHITE
+ senderPlayer.player().getName() + ChatColor.GREEN + " 的轉帳 " + ChatColor.WHITE
+ amountStr + ChatColor.GREEN + " 元 " + receiverPlayer.getBalanceString());

senderPlayer.modifyBalance(-amount, "Transfer to " + receiverPlayer.player.getName() + " ("
+ receiverPlayer.player.getUniqueId() + ")");
senderPlayer.player.sendMessage(ChatColor.GREEN + "成功轉帳 " + ChatColor.WHITE + amountStr
+ ChatColor.GREEN + " 元給玩家 " + ChatColor.WHITE + receiverPlayer.player.getName()
+ ChatColor.GREEN + " 了~ " + senderPlayer.getBalanceString());
senderPlayer.modifyBalance(-amount, "Transfer to " + receiverPlayer.player().getName() + " ("
+ receiverPlayer.player().getUniqueId() + ")");
senderPlayer.player()
.sendMessage(ChatColor.GREEN + "成功轉帳 " + ChatColor.WHITE + amountStr + ChatColor.GREEN
+ " 元給玩家 " + ChatColor.WHITE + receiverPlayer.player().getName()
+ ChatColor.GREEN + " 了~ " + senderPlayer.getBalanceString());

return true;
}

private boolean help(PlayerData senderPlayer) {
senderPlayer.player.sendMessage(ChatColor.RED + "沒有這個指令");
senderPlayer.player.sendMessage(ChatColor.AQUA + "/trade 的使用方式:");
senderPlayer.player().sendMessage(ChatColor.RED + "沒有這個指令");
senderPlayer.player().sendMessage(ChatColor.AQUA + "/trade 的使用方式:");

senderPlayer.player.sendMessage("/trade pay <對象> <金額>" + ChatColor.GRAY + " - 向其他玩家轉帳");
senderPlayer.player.sendMessage("/trade me" + ChatColor.GRAY + " - 查看自己的經濟狀況");
senderPlayer.player().sendMessage("/trade pay <對象> <金額>" + ChatColor.GRAY + " - 向其他玩家轉帳");
senderPlayer.player().sendMessage("/trade me" + ChatColor.GRAY + " - 查看自己的經濟狀況");

senderPlayer.player.sendMessage(ChatColor.GRAY + "/trade help - 取得幫助");
senderPlayer.player().sendMessage(ChatColor.GRAY + "/trade help - 取得幫助");
return false;
}

Expand Down
Loading

0 comments on commit 944f5d8

Please sign in to comment.