Updated copy and display commands

This commit is contained in:
jayoevans 2019-10-30 11:51:38 +10:00
parent ad72ad026c
commit 456b115bf6
12 changed files with 170 additions and 186 deletions

View file

@ -30,8 +30,8 @@ public class AbilityManager extends Module {
private final MultiAbilityManager multiAbilityManager;
private final PassiveAbilityManager passiveAbilityManager;
private final Map<String, AbilityInfo> abilities = new HashMap<>();
private final Map<Class<? extends Ability>, AbilityInfo> abilityInfoMap = new HashMap<>();
private final Map<String, AbilityInfo> abilityInfoByName = new HashMap<>();
private final Map<Class<? extends Ability>, AbilityInfo> abilityInfoByClass = new HashMap<>();
private final Set<Ability> playerAbilitySet = new HashSet<>();
private final Map<UUID, Map<Class<? extends Ability>, LinkedList<Ability>>> playerAbilityMap = new HashMap<>();
@ -211,7 +211,8 @@ public class AbilityManager extends Module {
return;
}
this.abilities.put(abilityInfo.getName(), abilityInfo);
this.abilityInfoByName.put(abilityInfo.getName(), abilityInfo);
this.abilityInfoByClass.put(abilityClass, abilityInfo);
}
private AbilityConfig getAbilityConfig(Class<? extends Ability> abilityClass) throws AbilityException {
@ -301,23 +302,15 @@ public class AbilityManager extends Module {
}
public AbilityInfo getAbilityInfo(String abilityName) {
return this.abilities.get(abilityName);
return this.abilityInfoByName.get(abilityName);
}
public AbilityInfo getAbilityInfo(Class<? extends Ability> abilityClass) {
return this.abilityInfoMap.computeIfAbsent(abilityClass, k ->
{
try {
return ((Class<? extends AbilityInfo>) ((ParameterizedType) abilityClass.getGenericSuperclass()).getActualTypeArguments()[0]).newInstance();
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
return null;
}
});
return this.abilityInfoByClass.get(abilityClass);
}
public List<AbilityInfo> getAbilityInfo() {
return new ArrayList<>(this.abilities.values());
return new ArrayList<>(this.abilityInfoByName.values());
}
public <T extends Ability> LinkedList<T> getAbilities(Class<T> abilityClass) {
@ -335,7 +328,7 @@ public class AbilityManager extends Module {
}
public List<AbilityInfo> getAbilities(Element element) {
return this.abilities.values().stream()
return this.abilityInfoByName.values().stream()
.filter(ability ->
{
if (ability.getElement().equals(element)) {

View file

@ -1,6 +1,7 @@
package com.projectkorra.projectkorra.ability;
import com.projectkorra.projectkorra.ability.info.ComboAbilityInfo;
import com.projectkorra.projectkorra.element.Element;
import com.projectkorra.projectkorra.module.Module;
import com.projectkorra.projectkorra.module.ModuleManager;
import com.projectkorra.projectkorra.player.BendingPlayer;
@ -20,14 +21,17 @@ import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import java.util.*;
import java.util.stream.Collectors;
public class ComboAbilityManager extends Module {
private final BendingPlayerManager bendingPlayerManager;
private final AbilityManager abilityManager;
private final List<ComboAbilityInfo> abilities = new ArrayList<>();
private final List<ComboAbility> comboAbilities = new ArrayList<>();
private final Map<UUID, LinkedList<Combination>> recentlyUsed = new HashMap<>();
private final List<ComboAbility> abilities = new ArrayList<>();
private final long combinationMax = 8;
@ -43,7 +47,8 @@ public class ComboAbilityManager extends Module {
public void registerAbility(Class<? extends Ability> abilityClass, ComboAbilityInfo comboAbilityInfo) {
ComboAbility comboAbility = new ComboAbility(abilityClass, comboAbilityInfo.getName(), comboAbilityInfo.getCombination());
this.abilities.add(comboAbility);
this.abilities.add(comboAbilityInfo);
this.comboAbilities.add(comboAbility);
}
private void processComboAbility(Player player, ClickType clickType) {
@ -59,7 +64,7 @@ public class ComboAbilityManager extends Module {
recentlyUsed.removeLast();
}
ComboAbility comboAbility = getComboAbility(recentlyUsed);
ComboAbility comboAbility = getAbility(recentlyUsed);
if (comboAbility == null) {
return;
@ -72,8 +77,8 @@ public class ComboAbilityManager extends Module {
this.abilityManager.createAbility(player, comboAbility.abilityClass);
}
private ComboAbility getComboAbility(LinkedList<Combination> recentlyUsed) {
for (ComboAbility comboAbility : this.abilities) {
private ComboAbility getAbility(LinkedList<Combination> recentlyUsed) {
for (ComboAbility comboAbility : this.comboAbilities) {
int comboSize = comboAbility.combinations.size();
if (recentlyUsed.size() < comboSize) {
@ -88,6 +93,12 @@ public class ComboAbilityManager extends Module {
return null;
}
public List<ComboAbilityInfo> getAbilities(Element element) {
return this.abilities.stream()
.filter(comboAbilityInfo -> comboAbilityInfo.getElement().equals(element))
.collect(Collectors.toList());
}
@EventHandler
public void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();

View file

@ -84,19 +84,19 @@ public class PassiveAbilityManager extends Module {
return this.abilities.get(abilityClass);
}
public List<Class<? extends Ability>> getPassivesForElement(Element element) {
List<Class<? extends Ability>> abilities = new ArrayList<>();
public List<PassiveAbilityInfo> getPassives(Element element) {
List<PassiveAbilityInfo> abilities = new ArrayList<>();
this.abilities.forEach((abilityClass, passiveAbilityLoader) -> {
this.abilities.values().forEach(passiveAbilityInfo -> {
Element passiveElement = passiveAbilityLoader.getElement();
Element passiveElement = passiveAbilityInfo.getElement();
if (passiveElement instanceof SubElement) {
passiveElement = ((SubElement) passiveElement).getParent();
}
if (passiveElement.equals(element)) {
abilities.add(abilityClass);
abilities.add(passiveAbilityInfo);
}
});

View file

@ -90,7 +90,7 @@ public class AddCommand extends PKCommand<AddCommandConfig> {
BendingPlayer bendingPlayer = this.bendingPlayerManager.getBendingPlayer(target);
if (bendingPlayer.isBendingRemoved()) {
if (bendingPlayer.isBendingPermanentlyRemoved()) {
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + ConfigManager.getConfig(CommandPropertiesConfig.class).BendingPermanentlyRemoved_Other);
return;
}
@ -211,7 +211,7 @@ public class AddCommand extends PKCommand<AddCommandConfig> {
}
final List<String> l = new ArrayList<>();
if (args.size() == 0) {
for (Element element : this.elementManager.getElements()) {
for (Element element : this.elementManager.getAllElements()) {
l.add(element.getName());
}
} else {

View file

@ -3,6 +3,8 @@ package com.projectkorra.projectkorra.command;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ability.bind.AbilityBindManager;
import com.projectkorra.projectkorra.ability.info.AbilityInfo;
import com.projectkorra.projectkorra.ability.info.ComboAbilityInfo;
import com.projectkorra.projectkorra.ability.info.PassiveAbilityInfo;
import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.configuration.configs.commands.BindCommandConfig;
import com.projectkorra.projectkorra.element.Element;
@ -157,9 +159,7 @@ public class BindCommand extends PKCommand<BindCommandConfig> {
Set<String> abilitySet = new HashSet<>();
for (AbilityInfo abilityInfo : this.abilityManager.getAbilityInfo()) {
// if (!coreAbil.isHiddenAbility() && bPlayer.canBind(coreAbil) && !(coreAbil instanceof PassiveAbility || coreAbil instanceof ComboAbility) && !abilities.contains(coreAbil.getName())) {
if (bendingPlayer.canBind(abilityInfo)) {
if (!abilityInfo.isHidden() && bendingPlayer.canBind(abilityInfo) && !(abilityInfo instanceof PassiveAbilityInfo || abilityInfo instanceof ComboAbilityInfo && !abilitySet.contains(abilityInfo.getName()))) {
abilitySet.add(abilityInfo.getName());
}
}

View file

@ -199,9 +199,7 @@ public class ChooseCommand extends PKCommand<ChooseCommandConfig> {
final List<String> l = new ArrayList<String>();
if (args.size() == 0) {
for (Element element : this.elementManager.getElements()) {
if (!(element instanceof SubElement)) {
l.add(element.getName());
}
l.add(element.getName());
}
} else {
for (final Player p : Bukkit.getOnlinePlayers()) {

View file

@ -3,15 +3,15 @@ package com.projectkorra.projectkorra.command;
import java.util.ArrayList;
import java.util.List;
import com.projectkorra.projectkorra.ability.info.AbilityInfo;
import com.projectkorra.projectkorra.player.BendingPlayer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ProjectKorra;
import com.projectkorra.projectkorra.ability.CoreAbility;
import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.configuration.configs.commands.CopyCommandConfig;
import com.projectkorra.projectkorra.configuration.configs.properties.CommandPropertiesConfig;
@ -79,18 +79,10 @@ public class CopyCommand extends PKCommand<CopyCommandConfig> {
private boolean assignAbilities(final CommandSender sender, final Player player, final Player player2, final boolean self) {
BendingPlayer orig = BendingPlayer.getBendingPlayer(player);
BendingPlayer target = BendingPlayer.getBendingPlayer(player2);
BendingPlayer orig = this.bendingPlayerManager.getBendingPlayer(player);
BendingPlayer target = this.bendingPlayerManager.getBendingPlayer(player2);
if (orig == null) {
GeneralMethods.createBendingPlayer(player.getUniqueId(), player.getName());
orig = BendingPlayer.getBendingPlayer(player);
}
if (target == null) {
GeneralMethods.createBendingPlayer(player2.getUniqueId(), player2.getName());
target = BendingPlayer.getBendingPlayer(player2);
}
if (orig.isPermaRemoved()) {
if (orig.isBendingPermanentlyRemoved()) {
if (self) {
GeneralMethods.sendBrandingMessage(player, ChatColor.RED + ConfigManager.getConfig(CommandPropertiesConfig.class).BendingPermanentlyRemoved);
} else {
@ -99,17 +91,22 @@ public class CopyCommand extends PKCommand<CopyCommandConfig> {
return false;
}
final String[] abilities = orig.getAbilities().clone();
List<String> abilities = orig.getAbilities();
boolean boundAll = true;
for (int i = 0; i < 9; i++) {
final CoreAbility coreAbil = CoreAbility.getAbility(abilities[i]);
if (coreAbil != null && !target.canBind(coreAbil)) {
abilities[i] = null;
String abilityName = abilities.get(0);
AbilityInfo abilityInfo = this.abilityManager.getAbilityInfo(abilityName);
if (abilityInfo == null || !target.canBind(abilityInfo)) {
boundAll = false;
continue;
}
this.abilityBindManager.bindAbility(player2, abilityName, i);
}
target.setAbilities(abilities);
return boundAll;
}

View file

@ -7,20 +7,19 @@ import java.util.Objects;
import java.util.Set;
import java.util.stream.Stream;
import com.projectkorra.projectkorra.ability.info.AbilityInfo;
import com.projectkorra.projectkorra.ability.info.AddonAbilityInfo;
import com.projectkorra.projectkorra.ability.info.ComboAbilityInfo;
import com.projectkorra.projectkorra.ability.info.PassiveAbilityInfo;
import com.projectkorra.projectkorra.element.Element;
import com.projectkorra.projectkorra.element.SubElement;
import com.projectkorra.projectkorra.player.BendingPlayer;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.Element.SubElement;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ability.api.AddonAbility;
import com.projectkorra.projectkorra.ability.api.ComboAbility;
import com.projectkorra.projectkorra.ability.CoreAbility;
import com.projectkorra.projectkorra.ability.api.SubAbility;
import com.projectkorra.projectkorra.ability.util.ComboManager;
import com.projectkorra.projectkorra.ability.util.PassiveManager;
import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.configuration.configs.commands.DisplayCommandConfig;
import com.projectkorra.projectkorra.configuration.configs.properties.CommandPropertiesConfig;
@ -83,29 +82,24 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
} else if (elementName.equalsIgnoreCase("avp")) {
elementName = "avatarpassive";
}
final Element element = Element.fromString(elementName.replace("combos", "").replace("combo", "").replace("passives", "").replace("passive", ""));
final Element element = this.elementManager.getElement(elementName.replace("combos", "").replace("combo", "").replace("passives", "").replace("passive", ""));
// combos.
if (elementName.contains("combo")) {
if (element == null) {
sender.sendMessage(ChatColor.BOLD + "Combos");
for (final Element e : Element.getAllElements()) {
final ChatColor color = e != null ? e.getColor() : null;
final ArrayList<String> combos = ComboManager.getCombosForElement(e);
for (final Element e : this.elementManager.getElements()) {
final List<ComboAbilityInfo> abilities = this.comboAbilityManager.getAbilities(e);
for (final String comboAbil : combos) {
ChatColor comboColor = color;
if (!sender.hasPermission("bending.ability." + comboAbil)) {
for (final ComboAbilityInfo comboAbilityInfo : abilities) {
if (!sender.hasPermission("bending.ability." + comboAbilityInfo.getName())) {
continue;
}
final CoreAbility coreAbil = CoreAbility.getAbility(comboAbil);
if (coreAbil != null) {
comboColor = coreAbil.getElement().getColor();
}
String message = (comboColor + comboAbil);
String message = comboAbilityInfo.getElement().getColor() + comboAbilityInfo.getName();
if (coreAbil instanceof AddonAbility) {
if (comboAbilityInfo instanceof AddonAbilityInfo) {
message += ChatColor.WHITE + (ChatColor.BOLD + "*");
}
@ -115,29 +109,23 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
return;
} else {
final ChatColor color = element != null ? element.getColor() : null;
final ArrayList<String> combos = ComboManager.getCombosForElement(element);
final List<ComboAbilityInfo> abilities = this.comboAbilityManager.getAbilities(element);
if (combos.isEmpty()) {
if (abilities.isEmpty()) {
GeneralMethods.sendBrandingMessage(sender, color + this.noCombosAvailable.replace("{element}", element.getName()));
return;
}
sender.sendMessage(element.getColor() + (ChatColor.BOLD + element.getName()) + element.getType().getBending() + ChatColor.WHITE + (ChatColor.BOLD + " Combos"));
for (final String comboMove : combos) {
ChatColor comboColor = color;
if (!sender.hasPermission("bending.ability." + comboMove)) {
for (final ComboAbilityInfo comboAbilityInfo : abilities) {
if (!sender.hasPermission("bending.ability." + comboAbilityInfo.getName())) {
continue;
}
final CoreAbility coreAbil = CoreAbility.getAbility(comboMove);
if (coreAbil != null) {
comboColor = coreAbil.getElement().getColor();
}
String message = comboAbilityInfo.getElement().getColor() + comboAbilityInfo.getName();
String message = (comboColor + comboMove);
if (coreAbil instanceof AddonAbility) {
if (comboAbilityInfo instanceof AddonAbilityInfo) {
message += ChatColor.WHITE + (ChatColor.BOLD + "*");
}
@ -150,23 +138,17 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
if (element == null) {
sender.sendMessage(ChatColor.BOLD + "Passives");
for (final Element e : Element.getAllElements()) {
final ChatColor color = e != null ? e.getColor() : null;
final Set<String> passives = PassiveManager.getPassivesForElement(e);
for (final Element e : this.elementManager.getElements()) {
final List<PassiveAbilityInfo> passives = this.passiveAbilityManager.getPassives(e);
for (final String passiveAbil : passives) {
ChatColor passiveColor = color;
if (!sender.hasPermission("bending.ability." + passiveAbil)) {
for (final PassiveAbilityInfo passiveAbilityInfo : passives) {
if (!sender.hasPermission("bending.ability." + passiveAbilityInfo.getName())) {
continue;
}
final CoreAbility coreAbil = CoreAbility.getAbility(passiveAbil);
if (coreAbil != null) {
passiveColor = coreAbil.getElement().getColor();
}
String message = (passiveColor + passiveAbil);
String message = passiveAbilityInfo.getElement().getColor() + passiveAbilityInfo.getName();
if (coreAbil instanceof AddonAbility) {
if (passiveAbilityInfo instanceof AddonAbilityInfo) {
message += ChatColor.WHITE + (ChatColor.BOLD + "*");
}
@ -176,7 +158,7 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
return;
}
final ChatColor color = element != null ? element.getColor() : null;
final Set<String> passives = PassiveManager.getPassivesForElement(element);
final List<PassiveAbilityInfo> passives = this.passiveAbilityManager.getPassives(element);
if (passives.isEmpty()) {
GeneralMethods.sendBrandingMessage(sender, color + this.noPassivesAvailable.replace("{element}", element.getName()));
@ -185,17 +167,12 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
sender.sendMessage(element.getColor() + (ChatColor.BOLD + element.getName()) + element.getType().getBending() + ChatColor.WHITE + (ChatColor.BOLD + " Passives"));
for (final String passiveAbil : passives) {
ChatColor passiveColor = color;
if (!sender.hasPermission("bending.ability." + passiveAbil)) {
for (final PassiveAbilityInfo passiveAbilityInfo : passives) {
if (!sender.hasPermission("bending.ability." + passiveAbilityInfo.getName())) {
continue;
}
final CoreAbility coreAbil = CoreAbility.getAbility(passiveAbil);
if (coreAbil != null) {
passiveColor = coreAbil.getElement().getColor();
}
sender.sendMessage(passiveColor + passiveAbil);
sender.sendMessage(passiveAbilityInfo.getElement().getColor() + passiveAbilityInfo.getName());
}
return;
} else if (element != null) {
@ -209,14 +186,14 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
else {
final StringBuilder elements = new StringBuilder(ChatColor.RED + this.invalidArgument);
elements.append(ChatColor.WHITE + "\nElements: ");
for (final Element e : Element.getAllElements()) {
for (final Element e : this.elementManager.getElements()) {
if (!(e instanceof SubElement)) {
elements.append(e.getColor() + e.getName() + ChatColor.WHITE + " | ");
}
}
sender.sendMessage(elements.toString());
final StringBuilder subelements = new StringBuilder(ChatColor.WHITE + "SubElements: ");
for (final SubElement e : Element.getAllSubElements()) {
for (final SubElement e : this.elementManager.getSubElements()) {
subelements.append(ChatColor.WHITE + "\n- " + e.getColor() + e.getName());
}
sender.sendMessage(subelements.toString());
@ -228,7 +205,7 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.playersOnly);
return;
}
this.displayBinds(sender);
this.displayBinds((Player) sender);
}
}
@ -239,7 +216,7 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
* @param element The element to show the moves for
*/
private void displayElement(final CommandSender sender, final Element element) {
final List<CoreAbility> abilities = CoreAbility.getAbilitiesByElement(element);
final List<AbilityInfo> abilities = this.abilityManager.getAbilities(element);
if (abilities.isEmpty()) {
sender.sendMessage(ChatColor.YELLOW + this.noAbilitiesAvailable.replace("{element}", element.getColor() + element.getName() + ChatColor.YELLOW));
@ -249,29 +226,29 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
sender.sendMessage(element.getColor() + (ChatColor.BOLD + element.getName()) + element.getType().getBending());
final HashSet<String> abilitiesSent = new HashSet<String>(); // Some abilities have the same name. This prevents this from showing anything.
for (final CoreAbility ability : abilities) {
if (ability instanceof SubAbility || ability instanceof ComboAbility || ability.isHiddenAbility() || abilitiesSent.contains(ability.getName())) {
for (final AbilityInfo abilityInfo : abilities) {
if (abilityInfo instanceof SubAbility || abilityInfo instanceof ComboAbilityInfo || abilityInfo.isHidden() || abilitiesSent.contains(abilityInfo.getName())) {
continue;
}
if (!(sender instanceof Player) || GeneralMethods.canView((Player) sender, ability.getName())) {
String message = ability.getElement().getColor() + ability.getName();
if (ability instanceof AddonAbility) {
if (!(sender instanceof Player) || GeneralMethods.canView((Player) sender, abilityInfo.getName())) {
String message = abilityInfo.getElement().getColor() + abilityInfo.getName();
if (abilityInfo instanceof AddonAbilityInfo) {
message += ChatColor.WHITE + (ChatColor.BOLD + "*");
}
sender.sendMessage(message);
abilitiesSent.add(ability.getName());
abilitiesSent.add(abilityInfo.getName());
}
}
if (element.equals(Element.CHI)) {
if (element.equals(this.elementManager.getChi())) {
sender.sendMessage(ChatColor.YELLOW + "Combos: " + ChatColor.GOLD + "/bending display ChiCombos");
sender.sendMessage(ChatColor.YELLOW + "Passives: " + ChatColor.GOLD + "/bending display ChiPassives");
} else {
sender.sendMessage(element.getSubColor() + "Combos: " + element.getColor() + "/bending display " + element.getName() + "Combos");
sender.sendMessage(element.getSubColor() + "Passives: " + element.getColor() + "/bending display " + element.getName() + "Passives");
for (final SubElement sub : Element.getSubElements(element)) {
sender.sendMessage(element.getSecondaryColor() + "Combos: " + element.getColor() + "/bending display " + element.getName() + "Combos");
sender.sendMessage(element.getSecondaryColor() + "Passives: " + element.getColor() + "/bending display " + element.getName() + "Passives");
for (final SubElement sub : this.elementManager.getSubElements(element)) {
if (sender.hasPermission("bending." + element.getName().toLowerCase() + "." + sub.getName().toLowerCase())) {
sender.sendMessage(sub.getColor() + sub.getName() + " abilities: " + element.getColor() + "/bending display " + sub.getName());
}
@ -286,7 +263,7 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
* @param element The subelement to show the moves for
*/
private void displaySubElement(final CommandSender sender, final SubElement element) {
final List<CoreAbility> abilities = CoreAbility.getAbilitiesByElement(element);
final List<AbilityInfo> abilities = this.abilityManager.getAbilities(element);;
if (abilities.isEmpty() && element != null) {
sender.sendMessage(ChatColor.YELLOW + this.noAbilitiesAvailable.replace("{element}", element.getColor() + element.getName() + ChatColor.YELLOW));
@ -296,20 +273,20 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
sender.sendMessage(element.getColor() + (ChatColor.BOLD + element.getName()) + element.getType().getBending());
final HashSet<String> abilitiesSent = new HashSet<String>();
for (final CoreAbility ability : abilities) {
if (ability.isHiddenAbility() || abilitiesSent.contains(ability.getName())) {
for (final AbilityInfo abilityInfo : abilities) {
if (abilityInfo.isHidden() || abilitiesSent.contains(abilityInfo.getName())) {
continue;
} else if (!(sender instanceof Player) || GeneralMethods.canView((Player) sender, ability.getName())) {
String message = element.getColor() + ability.getName();
if (ability instanceof AddonAbility) {
} else if (!(sender instanceof Player) || GeneralMethods.canView((Player) sender, abilityInfo.getName())) {
String message = element.getColor() + abilityInfo.getName();
if (abilityInfo instanceof AddonAbilityInfo) {
message += ChatColor.WHITE + (ChatColor.BOLD + "*");
}
sender.sendMessage(message);
abilitiesSent.add(ability.getName());
abilitiesSent.add(abilityInfo.getName());
}
}
sender.sendMessage(element.getParentElement().getColor() + "Passives: " + element.getColor() + "/bending display " + element.getName() + "Passives");
sender.sendMessage(element.getParent().getColor() + "Passives: " + element.getColor() + "/bending display " + element.getName() + "Passives");
}
/**
@ -317,68 +294,45 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
*
* @param sender The CommandSender to output the bound abilities to
*/
private void displayBinds(final CommandSender sender) {
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(sender.getName());
if (bPlayer == null) {
GeneralMethods.createBendingPlayer(((Player) sender).getUniqueId(), sender.getName());
bPlayer = BendingPlayer.getBendingPlayer(sender.getName());
}
final String[] abilities = bPlayer.getAbilities();
private void displayBinds(final Player player) {
BendingPlayer bendingPlayer = this.bendingPlayerManager.getBendingPlayer(player);
List<String> abilities = bendingPlayer.getAbilities();
if (Stream.of(abilities).allMatch(Objects::isNull)) {
sender.sendMessage(ChatColor.RED + this.noBinds);
if (abilities.stream().allMatch(Objects::isNull)) {
player.sendMessage(ChatColor.RED + this.noBinds);
return;
}
sender.sendMessage(ChatColor.WHITE + (ChatColor.BOLD + "Abilities"));
player.sendMessage(ChatColor.WHITE + (ChatColor.BOLD + "Abilities"));
for (int i = 1; i <= 9; i++) {
final String ability = abilities[i - 1];
final CoreAbility coreAbil = CoreAbility.getAbility(ability);
if (coreAbil != null && !ability.equalsIgnoreCase("null")) {
String message = i + ". " + coreAbil.getElement().getColor() + ability;
for (int i = 0; i < 9; i++) {
final String abilityName = abilities.get(i);
final AbilityInfo abilityInfo = this.abilityManager.getAbilityInfo(abilityName);
if (coreAbil instanceof AddonAbility) {
message += ChatColor.WHITE + (ChatColor.BOLD + "*");
}
sender.sendMessage(message);
if (abilityInfo == null) {
continue;
}
String message = (i + 1) + ". " + abilityInfo.getElement().getColor() + abilityName;
if (abilityInfo instanceof AddonAbilityInfo) {
message += ChatColor.WHITE + (ChatColor.BOLD + "*");
}
player.sendMessage(message);
}
}
@Override
protected List<String> getTabCompletion(final CommandSender sender, final List<String> args) {
if (args.size() >= 1 || !sender.hasPermission("bending.command.display")) {
return new ArrayList<String>();
return new ArrayList<>();
}
final List<String> list = new ArrayList<String>();
list.add("Air");
list.add("Earth");
list.add("Fire");
list.add("Water");
list.add("Chi");
for (final Element e : Element.getAddonElements()) {
for (Element e : this.elementManager.getAllElements()) {
list.add(e.getName());
}
list.add("Bloodbending");
list.add("Combustion");
list.add("Flight");
list.add("Healing");
list.add("Ice");
list.add("Lava");
list.add("Lightning");
list.add("Metal");
list.add("Plantbending");
list.add("Sand");
list.add("Spiritual");
for (final SubElement se : Element.getAddonSubElements()) {
list.add(se.getName());
}
list.add("AirCombos");
list.add("EarthCombos");
list.add("FireCombos");

View file

@ -10,6 +10,9 @@ import java.util.List;
import java.util.Map;
import com.projectkorra.projectkorra.ability.AbilityManager;
import com.projectkorra.projectkorra.ability.ComboAbilityManager;
import com.projectkorra.projectkorra.ability.MultiAbilityManager;
import com.projectkorra.projectkorra.ability.PassiveAbilityManager;
import com.projectkorra.projectkorra.ability.bind.AbilityBindManager;
import com.projectkorra.projectkorra.element.ElementManager;
import com.projectkorra.projectkorra.module.ModuleManager;
@ -34,6 +37,9 @@ public abstract class PKCommand<C extends CommandConfig> implements SubCommand<C
protected final BendingPlayerManager bendingPlayerManager = ModuleManager.getModule(BendingPlayerManager.class);
protected final ElementManager elementManager = ModuleManager.getModule(ElementManager.class);
protected final AbilityManager abilityManager = ModuleManager.getModule(AbilityManager.class);
protected final ComboAbilityManager comboAbilityManager = ModuleManager.getModule(ComboAbilityManager.class);
protected final MultiAbilityManager multiAbilityManager = ModuleManager.getModule(MultiAbilityManager.class);
protected final PassiveAbilityManager passiveAbilityManager = ModuleManager.getModule(PassiveAbilityManager.class);
protected final AbilityBindManager abilityBindManager = ModuleManager.getModule(AbilityBindManager.class);
protected String noPermissionMessage, mustBePlayerMessage;

View file

@ -8,13 +8,15 @@ public class Element {
private final String elementName;
private final String displayName;
private final ChatColor color;
private final ChatColor secondaryColor;
private final ElementManager.ElementType type;
public Element(int elementId, String elementName, String displayName, ChatColor color, ElementManager.ElementType type) {
public Element(int elementId, String elementName, String displayName, ChatColor color, ChatColor secondaryColor, ElementManager.ElementType type) {
this.elementId = elementId;
this.elementName = elementName;
this.displayName = displayName;
this.color = color;
this.secondaryColor = secondaryColor;
this.type = type;
}
@ -34,6 +36,10 @@ public class Element {
return this.color;
}
public ChatColor getSecondaryColor() {
return this.secondaryColor;
}
public String getColoredName() {
return this.color + this.displayName;
}

View file

@ -1,6 +1,7 @@
package com.projectkorra.projectkorra.element;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
import com.projectkorra.projectkorra.module.DatabaseModule;
import com.projectkorra.projectkorra.module.ModuleManager;
import com.projectkorra.projectkorra.player.BendingPlayer;
@ -11,10 +12,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ -30,6 +28,7 @@ public class ElementManager extends DatabaseModule<ElementRepository> {
private final Map<Integer, Element> elements = new HashMap<>();
private final Map<String, Element> names = new HashMap<>();
private final Map<Element, List<SubElement>> subElements = new HashMap<>();
private final String nameRegex = "[a-zA-Z]+";
@ -49,33 +48,33 @@ public class ElementManager extends DatabaseModule<ElementRepository> {
getRepository().createTables();
// Waterbending
this.water = addElement(WATER, "Water", ChatColor.AQUA, ElementType.BENDING);
this.water = addElement(WATER, "Water", ChatColor.AQUA, ChatColor.DARK_AQUA, ElementType.BENDING);
this.blood = addSubElement(BLOOD, "Blood", ChatColor.DARK_AQUA, ElementType.BENDING, this.water);
this.healing = addSubElement(HEALING, "Healing", ChatColor.DARK_AQUA, ElementType.NO_SUFFIX, this.water);
this.ice = addSubElement(ICE, "Ice", ChatColor.DARK_AQUA, ElementType.BENDING, this.water);
this.plant = addSubElement(PLANT, "Plant", ChatColor.DARK_AQUA, ElementType.BENDING, this.water);
// Earthbending
this.earth = addElement(EARTH, "Earth", ChatColor.AQUA, ElementType.BENDING);
this.earth = addElement(EARTH, "Earth", ChatColor.GREEN, ChatColor.DARK_GREEN ,ElementType.BENDING);
this.lava = addSubElement(LAVA, "Lava", ChatColor.DARK_GREEN, ElementType.BENDING, this.earth);
this.metal = addSubElement(METAL, "Metal", ChatColor.DARK_GREEN, ElementType.BENDING, this.earth);
this.sand = addSubElement(SAND, "Sand", ChatColor.DARK_GREEN, ElementType.BENDING, this.earth);
// Firebending
this.fire = addElement(FIRE, "Fire", ChatColor.RED, ElementType.BENDING);
this.fire = addElement(FIRE, "Fire", ChatColor.RED, ChatColor.DARK_RED, ElementType.BENDING);
this.combustion = addSubElement(COMBUSTION, "Combustion", ChatColor.DARK_RED, ElementType.BENDING, this.fire);
this.lightning = addSubElement(LIGHTNING, "Lightning", ChatColor.DARK_RED, ElementType.BENDING, this.fire);
// Airbending
this.air = addElement(AIR, "Air", ChatColor.GRAY, ElementType.BENDING);
this.air = addElement(AIR, "Air", ChatColor.GRAY, ChatColor.DARK_GRAY, ElementType.BENDING);
this.flight = addSubElement(FLIGHT, "Flight", ChatColor.DARK_GRAY, ElementType.NO_SUFFIX, this.air);
this.spiritual = addSubElement(SPIRITUAL, "Spiritual", ChatColor.DARK_GRAY, ElementType.NO_SUFFIX, this.air);
// Chiblocking
this.chi = addElement(CHI, "Chi", ChatColor.GOLD, ElementType.BLOCKING);
this.chi = addElement(CHI, "Chi", ChatColor.GOLD, ChatColor.YELLOW, ElementType.BLOCKING);
// Avatar
this.avatar = addElement(AVATAR, "Avatar", ChatColor.DARK_PURPLE, null);
this.avatar = addElement(AVATAR, "Avatar", ChatColor.DARK_PURPLE, ChatColor.WHITE, null);
} catch (SQLException e) {
e.printStackTrace();
}
@ -171,10 +170,10 @@ public class ElementManager extends DatabaseModule<ElementRepository> {
return this.names.get(elementName);
}
private Element addElement(String elementName, String displayName, ChatColor color, ElementType type) {
private Element addElement(String elementName, String displayName, ChatColor color, ChatColor secondaryColor, ElementType type) {
int elementId = registerElement(elementName);
Element element = new Element(elementId, elementName, displayName, color, type);
Element element = new Element(elementId, elementName, displayName, color, secondaryColor, type);
this.elements.put(elementId, element);
this.names.put(elementName, element);
@ -189,6 +188,7 @@ public class ElementManager extends DatabaseModule<ElementRepository> {
this.elements.put(elementId, element);
this.names.put(elementName, element);
this.subElements.computeIfAbsent(parent, k -> new ArrayList<>()).add(element);
return element;
}
@ -275,6 +275,25 @@ public class ElementManager extends DatabaseModule<ElementRepository> {
}
public List<Element> getElements() {
return this.elements.values().stream()
.filter(Predicates.not(SubElement.class::isInstance))
.collect(Collectors.toList());
}
public List<SubElement> getSubElements() {
return this.elements.values().stream()
.filter(SubElement.class::isInstance)
.map(SubElement.class::cast)
.collect(Collectors.toList());
}
public List<SubElement> getSubElements(Element parent) {
List<SubElement> subElements = this.subElements.get(parent);
return subElements != null ? subElements : Collections.emptyList();
}
public List<Element> getAllElements() {
return new ArrayList<>(this.elements.values());
}

View file

@ -7,7 +7,7 @@ public class SubElement extends Element {
private final Element parent;
public SubElement(int elementId, String elementName, String displayName, ChatColor color, ElementManager.ElementType type, Element parent) {
super(elementId, elementName, displayName, color, type);
super(elementId, elementName, displayName, color, ChatColor.WHITE, type);
this.parent = parent;
}