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 15, 2022
1 parent ef4e1d1 commit 9c082a4
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 145 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 targetParty1 = request.getTargetParty();

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

lang.sendMessage(senderPartyMembers, "COMMAND.duel.party-request.accept.receiver-party",
"owner", player.getName(), "name", target.getName(), "kit", kit, "own_inventory", ownInventory, "arena", arena);
"name", targetParty1.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", targetParty1.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
Expand Up @@ -28,15 +28,14 @@ public PartyDuelCountdown(final DuelsPlugin plugin, final ArenaImpl arena, final
@Override
protected void sendMessage(final String rawMessage, final String message, final String title) {
final String kitName = match.getKit() != null ? match.getKit().getName() : lang.getMessage("GENERAL.none");
match.getPlayerToParty().entrySet().forEach(entry -> {
final Player player = entry.getKey();
match.getPlayerToParty().forEach((player, value) -> {
config.playSound(player, rawMessage);
player.sendMessage(message
.replace("%opponents%", info.get(arena.getOpponent(entry.getValue())))
.replace("%kit%", kitName)
.replace("%arena%", arena.getName())
.replace("%opponents%", info.get(arena.getOpponent(value)))
.replace("%kit%", kitName)
.replace("%arena%", arena.getName())
);

if (title != null) {
Titles.send(player, title, null, 0, 20, 50);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void update(final Player player) {
}

final String lore = lang.getMessage("GUI.settings.buttons.details.lore",
"opponent", target.getName(),
"opponent", settings.isPartyDuel() ? plugin.getPartyManager().get(target).getName() : target.getName(),
"kit", settings.getKit() != null ? settings.getKit().getName() : lang.getMessage("GENERAL.not-selected"),
"own_inventory", settings.isOwnInventory() ? lang.getMessage("GENERAL.enabled") : lang.getMessage("GENERAL.disabled"),
"arena", settings.getArena() != null ? settings.getArena().getName() : lang.getMessage("GENERAL.random"),
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 @@ -7,17 +7,20 @@
import java.util.UUID;
import java.util.stream.Collectors;

import com.alessiodp.parties.api.interfaces.PartyPlayer;
import me.realized.duels.DuelsPlugin;
import me.realized.duels.api.event.request.RequestSendEvent;
import me.realized.duels.config.Config;
import me.realized.duels.config.Lang;
import me.realized.duels.party.PartyManagerImpl;
import me.realized.duels.setting.Settings;
import me.realized.duels.util.Loadable;
import me.realized.duels.util.StringUtil;
import me.realized.duels.util.TextBuilder;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent.Action;
import org.bukkit.Bukkit;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -74,13 +77,25 @@ public void send(final Player sender, final Player target, final Settings settin
final String ownInventory = settings.isOwnInventory() ? lang.getMessage("GENERAL.enabled") : lang.getMessage("GENERAL.disabled");
final String arena = settings.getArena() != null ? settings.getArena().getName() : lang.getMessage("GENERAL.random");

if (request.isPartyDuel()) {
if (isParty) {
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());
"opponents", StringUtil.join(targetPartyMembers.stream().map(HumanEntity::getName).collect(Collectors.toList()), " &f,&r "),
"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());
"opponents", StringUtil.join(senderPartyMembers.stream().map(HumanEntity::getName).collect(Collectors.toList()), " &f,&r "),
"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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ public boolean validate(final Pair<Player, Player> pair, final Party party, fina
}

if (senderParty == null) {
lang.sendMessage(pair.getKey(), "ERROR.party.not-in-party.sender", "name", pair.getKey().getName());
lang.sendMessage(pair.getKey(), "ERROR.party-duel.not-in-party.sender", "name", pair.getKey().getName());
return false;
}

// If sender is in the same party as target
if (senderParty.equals(party)) {
lang.sendMessage(pair.getKey(), "ERROR.party.in-same-party", "name", pair.getValue().getName());
lang.sendMessage(pair.getKey(), "ERROR.party-duel.in-same-party", "name", pair.getValue().getName());
return false;
}

if (config.isPartySameSizeOnly() && senderParty.getMembers().size() != party.getMembers().size()) {
lang.sendMessage(pair.getKey(), "ERROR.party.is-not-same-size");
lang.sendMessage(pair.getKey(), "ERROR.party-duel.is-not-same-size");
return false;
}

if (players.size() != party.getMembers().size()) {
lang.sendMessage(pair.getKey(), "ERROR.party.is-not-online.target", "name", pair.getValue().getName());
if (players.size() != party.getOnlineMembers().size()) {
lang.sendMessage(pair.getKey(), "ERROR.party-duel.is-not-online.target", "name", party.getName());
return false;
}

Expand Down
Loading

0 comments on commit 9c082a4

Please sign in to comment.