Skip to content

Commit

Permalink
Update lang to use party name
Browse files Browse the repository at this point in the history
  • Loading branch information
RemainingToast committed Oct 14, 2022
1 parent ef4e1d1 commit e9dc311
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,20 @@ protected boolean executeFirst(final CommandSender sender, final String label, f
return true;
}

final Player target = Bukkit.getPlayerExact(args[0]);
Player target = Bukkit.getPlayerExact(args[0]);
final com.alessiodp.parties.api.interfaces.Party targetParty = target == null ? parties.getApi().getParty(args[0]) : parties.getApi().getPartyOfPlayer(target.getUniqueId());

if (target == null && targetParty != null && targetParty.getLeader() != null) {
target = Bukkit.getPlayer(targetParty.getLeader());
}

if (target == null || !player.canSee(target)) {
lang.sendMessage(sender, "ERROR.player.not-found", "name", args[0]);
return true;
}

final com.alessiodp.parties.api.interfaces.Party targetParty = parties.getApi().getPartyOfPlayer(target.getUniqueId());
final Collection<Player> targetPlayers = targetParty == null ? Collections.singleton(target) : partyManager.getOnlinePlayers(targetParty);

// final Party targetParty = partyManager.get(target);
// final Collection<Player> targetPlayers = targetParty == null ? Collections.singleton(target) : targetParty.getOnlineMembers();

if (!ValidatorUtil.validate(validatorManager.getDuelTargetValidators(), new Pair<>(player, target), targetParty, targetPlayers)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import java.util.Collection;
import java.util.Collections;

import com.alessiodp.parties.api.interfaces.PartyPlayer;
import me.realized.duels.util.TextBuilder;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -64,19 +68,40 @@ protected void execute(final CommandSender sender, final String label, final Str
final String arena = settings.getArena() != null ? settings.getArena().getName() : lang.getMessage("GENERAL.random");

if (request.isPartyDuel()) {
final Collection<Player> senderPartyMembers = partyManager.getOnlinePlayers(request.getSenderParty());
final Collection<Player> targetPartyMembers = partyManager.getOnlinePlayers(request.getTargetParty());
final Party senderParty = request.getSenderParty();
final Party targettParty = request.getTargetParty();

final Collection<Player> senderPartyMembers = partyManager.getOnlinePlayers(senderParty);
final Collection<Player> targetPartyMembers = partyManager.getOnlinePlayers(targettParty);

lang.sendMessage(senderPartyMembers, "COMMAND.duel.party-request.accept.receiver-party",
"owner", player.getName(), "name", target.getName(), "kit", kit, "own_inventory", ownInventory, "arena", arena);
"name", senderParty.getName(),
"kit", kit,
"own_inventory", ownInventory,
"arena", arena);

lang.sendMessage(targetPartyMembers, "COMMAND.duel.party-request.accept.sender-party",
"owner", target.getName(), "name", player.getName(), "kit", kit, "own_inventory", ownInventory, "arena", arena);
"name", targettParty.getName(),
"kit", kit,
"own_inventory", ownInventory,
"arena", arena);
} else {
final double bet = settings.getBet();
final String itemBetting = settings.isItemBetting() ? lang.getMessage("GENERAL.enabled") : lang.getMessage("GENERAL.disabled");

lang.sendMessage(player, "COMMAND.duel.request.accept.receiver",
"name", target.getName(), "kit", kit, "arena", arena, "bet_amount", bet, "item_betting", itemBetting);
"name", target.getName(),
"kit", kit,
"arena", arena,
"bet_amount", bet,
"item_betting", itemBetting);

lang.sendMessage(target, "COMMAND.duel.request.accept.sender",
"name", player.getName(), "kit", kit, "arena", arena, "bet_amount", bet, "item_betting", itemBetting);
"name", player.getName(),
"kit", kit,
"arena", arena,
"bet_amount", bet,
"item_betting", itemBetting);
}

if (settings.isItemBetting()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.realized.duels.party;

import com.alessiodp.parties.api.interfaces.PartiesAPI;
import com.alessiodp.parties.api.interfaces.Party;
import me.realized.duels.DuelsPlugin;
import me.realized.duels.config.Lang;
import me.realized.duels.hook.hooks.PartiesHook;
Expand Down Expand Up @@ -38,7 +39,7 @@ public void handleUnload() {

}

public com.alessiodp.parties.api.interfaces.Party get(final Player player) {
public Party get(final Player player) {
return partiesAPI.getPartyOfPlayer(player.getUniqueId());
}

Expand All @@ -47,9 +48,10 @@ public Collection<Player> getOnlinePlayers(com.alessiodp.parties.api.interfaces.
}

public boolean canDamage(final Player damager, final Player damaged) {
final com.alessiodp.parties.api.interfaces.Party party = get(damager);
final Party party = get(damager);
final Party party1 = get(damaged);

if (party == null || !party.equals(get(damaged))) {
if (party == null || !party.equals(party1) || damager == damaged) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,19 @@ public void send(final Player sender, final Player target, final Settings settin
if (request.isPartyDuel()) {
final Collection<Player> senderPartyMembers = partyManager.getOnlinePlayers(request.getSenderParty());
final Collection<Player> targetPartyMembers = partyManager.getOnlinePlayers(request.getTargetParty());

lang.sendMessage(senderPartyMembers, "COMMAND.duel.party-request.send.sender-party",
"owner", sender.getName(), "name", target.getName(), "kit", kit, "own_inventory", ownInventory, "arena", arena, "party", request.getTargetParty().getName());
"name", request.getTargetParty().getName(),
"kit", kit,
"own_inventory", ownInventory,
"arena", arena);

lang.sendMessage(targetPartyMembers, "COMMAND.duel.party-request.send.receiver-party",
"name", sender.getName(), "kit", kit, "own_inventory", ownInventory, "arena", arena, "party", request.getSenderParty().getName());
"name", request.getSenderParty().getName(),
"kit", kit,
"own_inventory", ownInventory,
"arena", arena);

sendClickableMessage("COMMAND.duel.party-request.send.clickable-text.", sender, targetPartyMembers);
} else {
final int betAmount = settings.getBet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public static TextBuilder of(final String base,
public static TextBuilder of(final String base) {
return of(base, null, null, null, null);
}

public TextBuilder add(final String text) {
if (text == null) {
return this;
Expand Down Expand Up @@ -131,4 +130,15 @@ public void send(final Collection<Player> players) {
public void send(final Player... players) {
send(Arrays.asList(players));
}

@Override
public String toString() {
final BaseComponent[] message = list.toArray(new BaseComponent[0]);
final StringBuilder stringBuilder = new StringBuilder();
Arrays.stream(message).forEach(baseComponent -> stringBuilder
.append(baseComponent.toLegacyText())
.append("\n"));
final String s = stringBuilder.toString();
return s.endsWith("\n") ? s.substring(0, s.length() - 1) : s;
}
}
132 changes: 15 additions & 117 deletions duels-plugin/src/main/resources/lang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,40 +70,15 @@ ERROR:
in-blacklisted-world: '{PREFIX} &cYou or your party member is in a blacklisted world.'
is-tagged: '{PREFIX} &cYou or your party member is currently combat tagged.'
not-in-duelzone: '{PREFIX} &cYou or your party member is currently not in one of the following regions: %regions%'
already-has-request: '{PREFIX} &cYou already have a request sent to %name%''s party.'
no-request: '{PREFIX} &cYou do not have a request from %name%''s party.'
already-has-request: '{PREFIX} &cYou already have a request sent to %name%'
no-request: '{PREFIX} &cYou do not have a request from %name%'
already-in-match:
sender: '{PREFIX} &cYou cannot do this while your party in a duel.'
target: '{PREFIX} &c%name%''s party is already in a duel.'
target: '{PREFIX} &c%name% is already in a duel.'
already-spectating:
sender: '{PREFIX} &cYou cannot do this while you or your party member is in spectator mode.'
target: '{PREFIX} &cA member of %name%''s party is in spectator mode.'
target: '{PREFIX} &cA member of %name% party is in spectator mode.'
option-unavailable: '{PREFIX} &cItem/Money Betting is currently not available for party duels.'
party:
is-self: '{PREFIX} &cYou cannot create a party with yourself.'
is-not-owner: '{PREFIX} &cYou must be the owner of this party to do this.'
is-owner: '{PREFIX} &cYou cannot leave this party as you are the owner. You must either transfer the ownership of the party using ''/party transfer'' or disband the party using ''/party disband''.'
requests-disabled: '{PREFIX} &c%name% is currently not accepting party requests.'
already-has-invite: '{PREFIX} &cYou already have a invite sent to %name%.'
no-invite: '{PREFIX} &cYou do not have an invite from %name%.'
not-found: '{PREFIX} &cThat party no longer exists.'
already-in-party:
sender: '{PREFIX} &cYou cannot do this while in a party.'
target: '{PREFIX} &c%name% is already in a party.'
not-in-party:
sender: '{PREFIX} &cYou must be in a party to do this.'
target: '{PREFIX} &c%name% is not in a party.'
not-a-member: '{PREFIX} &c%name% is not a member of your party.'
in-same-party: '{PREFIX} &c%name% is in your party.'
kick-self: '{PREFIX} &cYou cannot kick yourself from the party.'
is-not-same-size: '{PREFIX} &cParty sizes must match to do this.'
is-not-online:
sender: '{PREFIX} &cAll members of your party must be online!'
target: '{PREFIX} &cAll members of %name%''s party must be online!'
max-size-reached:
sender: '{PREFIX} &cYour party has reached the maximum number of members!'
target: '{PREFIX} &c%name%''s Party has reached the maximum number of members!'
cannot-friendly-fire: '{PREFIX} &cFriendly fire is not allowed.'
setting:
disabled-option: '{PREFIX} &c%option% is currently disabled.'
arena-not-applicable: '{PREFIX} &cYou cannot use kit %kit% on arena %arena%.'
Expand Down Expand Up @@ -186,14 +161,14 @@ COMMAND:
send:
sender-party:
- '{LINE}'
- '&f%owner% &7has sent a duel request sent to &f%name%''s Party&7.'
- '&fSent a duel request sent to &f%name%&7.'
- '&6- &7Kit: &3%kit%'
- '&6- &7Own Inventory: &r%own_inventory%'
- '&6- &7Arena: &e%arena%'
- '{LINE}'
receiver-party:
- '{LINE}'
- '&7Duel request received from &f%name%''s Party&7.'
- '&7Duel request received from &f%name%&7.'
- '&6- &7Kit: &3%kit%'
- '&6- &7Own Inventory: &r%own_inventory%'
- '&6- &7Arena: &e%arena%'
Expand All @@ -211,22 +186,22 @@ COMMAND:
text: '{LINE}'
hover-text: ''
accept:
sender-party:
sender-party:
- '{LINE}'
- '{PREFIX} &f%name%''s Party &7has accepted &f%owner%&7''s duel request.'
- '{PREFIX} &f%name% &7has accepted the duel request.'
- '{LINE}'
receiver-party:
receiver-party:
- '{LINE}'
- '{PREFIX} &f%owner% &7has accepted the duel request from &f%name%''s Party&7.'
- '{PREFIX} &f%name% &7has accepted the duel request&7.'
- '{LINE}'
deny:
sender-party:
sender-party:
- '{LINE}'
- '{PREFIX} &f%name%''s Party &7has declined &f%owner%&7''s duel request.'
- '{PREFIX} &f%name% &7has declined the duel request.'
- '{LINE}'
receiver-party:
receiver-party:
- '{LINE}'
- '{PREFIX} &7&f%owner%&7''s has declined the duel request from &f%name%''s Party&7.'
- '{PREFIX} &f%name%&7 has declined the duel request&7.'
- '{LINE}'
stats:
displayed:
Expand Down Expand Up @@ -365,83 +340,6 @@ COMMAND:
- '{LINE}'
start-spectate: '{PREFIX} &7Now spectating &f%name%&7 vs &f%opponent%&7 in arena &e%arena%&7. Type &f/spectate &7to stop spectating.'
stop-spectate: '{PREFIX} &7You are no longer spectating &f%name%&7.'

party:
usage:
- '{LINE}'
- '&f/%command% toggle &e- &7Enable or disable receiving party invites.'
- '&f/%command% [player] &e- &7Sends a party invite to a player.'
- '&f/%command% list &e- &7Lists the current party''s members.'
- '&f/%command% accept [player] &e- &7Accepts a party invite.'
- '&f/%command% leave &e- &7Leaves the current party.'
- '&f/%command% kick [player] &e- &7Kicks a player from your party.'
- '&f/%command% friendlyfire &e- &7Enable or disable friendly fire for your party.'
- '&f/%command% transfer [player] &e- &7Transfers the ownership of your party to player.'
- '&f/%command% disband &e- &7Disbands the current party.'
- '{LINE}'
toggle:
enabled: '{PREFIX} &aYou are now receiving party requests.'
disabled: '{PREFIX} &cYou are no longer accepting party requests.'
list:
- '{LINE}'
- '&7Leader: &f%owner%'
- '&7Members (&r%members_count%&7): &r%members%'
- '&7Online (&r%online_count%&7): &r%online_members%'
- '{LINE}'
invite:
send:
receiver:
- '{LINE}'
- '{PREFIX} &7Party invite received from &f%name%&7. Type &f/party accept %name% &7to join the party.'
- '{LINE}'
members:
- '{LINE}'
- '{PREFIX} &f%owner% &7has invited &f%name% &7to the party!'
- '{LINE}'
accept:
receiver:
- '{LINE}'
- '{PREFIX} &7Accepted the party invite from &f%name%&7.'
- '{LINE}'
members:
- '{LINE}'
- '{PREFIX} &f%name% &7has joined the party!'
- '{LINE}'
leave:
sender:
- '{LINE}'
- '{PREFIX} &7You have left &f%name%''s Party&7.'
- '{LINE}'
members:
- '{LINE}'
- '{PREFIX} &f%name% &7has left the party!'
- '{LINE}'
kick:
receiver:
- '{LINE}'
- '{PREFIX} &f%owner% &7has kicked you from the party!'
- '{LINE}'
members:
- '{LINE}'
- '{PREFIX} &f%owner% &7has kicked &f%name% &7from the party!'
- '{LINE}'
friendly-fire:
enabled:
- '{LINE}'
- '{PREFIX} &cFriendly fire &7is now &aenabled&7!'
- '{LINE}'
disabled:
- '{LINE}'
- '{PREFIX} &cFriendly fire &7is now &cdisabled&7!'
- '{LINE}'
transfer:
- '{LINE}'
- '{PREFIX} &f%owner% &7has transferred the party to &f%name%&7.'
- '{LINE}'
disband:
- '{LINE}'
- '{PREFIX} &f%owner% &7has disbanded the party.'
- '{LINE}'

sub-command-usage: '{PREFIX} &f/%command% %usage% &e- &7%description%'

Expand Down Expand Up @@ -483,7 +381,7 @@ DUEL:
tie: '{PREFIX} &7Tie Game!'
plugin-disable: '{PREFIX} &cPlugin is disabling! Ending match automatically.'
opponent-defeat: '{PREFIX} &f%winner% &a(%winner_rating%) (+%change%) &7defeated &f%loser% &c(%loser_rating%) (-%change%) &7with kit &3%kit% &7on arena &e%arena%&7.'
party-opponent-defeat: '{PREFIX} &f%winners% &7defeated &f%losers% &7with kit &3%kit% &7on arena &e%arena%&7.'
party-opponent-defeat: '{PREFIX} &f%winner% &7defeated &f%loser% &7with kit &3%kit% &7on arena &e%arena%&7.'
inventories:
message: '&7Inventories (click on the name to view): '
name-color: '&b'
Expand Down

0 comments on commit e9dc311

Please sign in to comment.