Various changes

- Changed BindChangeEvent call spot
- Changed subelements to be stored in database
- Changed choose command to accept subelements as an argument
- Changed add command to accept subelements as an argument
- Changed all canBend<SubElement> methods
- Added PlayerChangeSubElementEvent
- Added saveSubElements() method to GeneralMethods
- Cleaned up imports in various classes
- Removed print out in damagehandler
This commit is contained in:
Benford 2016-03-13 15:16:01 -04:00
parent 928eeeae1b
commit 105dc8b005
15 changed files with 337 additions and 86 deletions

Binary file not shown.

Binary file not shown.

BIN
lib/Residence4.0.0.4.jar Normal file

Binary file not shown.

View file

@ -49,6 +49,7 @@ public class BendingPlayer {
private String name; private String name;
private ChiAbility stance; private ChiAbility stance;
private ArrayList<Element> elements; private ArrayList<Element> elements;
private ArrayList<SubElement> subelements;
private HashMap<Integer, String> abilities; private HashMap<Integer, String> abilities;
private ConcurrentHashMap<String, Long> cooldowns; private ConcurrentHashMap<String, Long> cooldowns;
private ConcurrentHashMap<Element, Boolean> toggledElements; private ConcurrentHashMap<Element, Boolean> toggledElements;
@ -62,11 +63,12 @@ public class BendingPlayer {
* @param abilities The known abilities * @param abilities The known abilities
* @param permaRemoved The permanent removed status * @param permaRemoved The permanent removed status
*/ */
public BendingPlayer(UUID uuid, String playerName, ArrayList<Element> elements, HashMap<Integer, String> abilities, public BendingPlayer(UUID uuid, String playerName, ArrayList<Element> elements, ArrayList<SubElement> subelements, HashMap<Integer, String> abilities,
boolean permaRemoved) { boolean permaRemoved) {
this.uuid = uuid; this.uuid = uuid;
this.name = playerName; this.name = playerName;
this.elements = elements; this.elements = elements;
this.subelements = subelements;
this.setAbilities(abilities); this.setAbilities(abilities);
this.permaRemoved = permaRemoved; this.permaRemoved = permaRemoved;
this.player = Bukkit.getPlayer(uuid); this.player = Bukkit.getPlayer(uuid);
@ -110,11 +112,20 @@ public class BendingPlayer {
/** /**
* Adds an element to the {@link BendingPlayer}'s known list. * Adds an element to the {@link BendingPlayer}'s known list.
* *
* @param e The element to add * @param element The element to add.
*/ */
public void addElement(Element element) { public void addElement(Element element) {
this.elements.add(element); this.elements.add(element);
} }
/**
* Adds a subelement to the {@link BendingPlayer}'s known list.
*
* @param subelement The subelement to add.
*/
public void addSubElement(SubElement subelement) {
this.subelements.add(subelement);
}
/** /**
* Sets chiBlocked to true. * Sets chiBlocked to true.
@ -251,7 +262,7 @@ public class BendingPlayer {
* @return true If player has permission node "bending.earth.bloodbending" * @return true If player has permission node "bending.earth.bloodbending"
*/ */
public boolean canBloodbend() { public boolean canBloodbend() {
return player.hasPermission("bending.water.bloodbending"); return subelements.contains(SubElement.BLOOD);
} }
public boolean canBloodbendAtAnytime() { public boolean canBloodbendAtAnytime() {
@ -259,12 +270,11 @@ public class BendingPlayer {
} }
public boolean canCombustionbend() { public boolean canCombustionbend() {
return player.hasPermission("bending.fire.combustionbending"); return subelements.contains(SubElement.COMBUSTION);
} }
public boolean canIcebend() { public boolean canIcebend() {
return player.hasPermission("bending.water.icebending"); return subelements.contains(SubElement.ICE);
} }
/** /**
@ -274,11 +284,11 @@ public class BendingPlayer {
* @return true If player has permission node "bending.earth.lavabending" * @return true If player has permission node "bending.earth.lavabending"
*/ */
public boolean canLavabend() { public boolean canLavabend() {
return player.hasPermission("bending.earth.lavabending"); return subelements.contains(SubElement.LAVA);
} }
public boolean canLightningbend() { public boolean canLightningbend() {
return player.hasPermission("bending.fire.lightningbending"); return subelements.contains(SubElement.LIGHTNING);
} }
/** /**
@ -288,11 +298,7 @@ public class BendingPlayer {
* @return true If player has permission node "bending.earth.metalbending" * @return true If player has permission node "bending.earth.metalbending"
*/ */
public boolean canMetalbend() { public boolean canMetalbend() {
return player.hasPermission("bending.earth.metalbending"); return subelements.contains(SubElement.METAL);
}
public boolean canPackedIcebend() {
return getConfig().getBoolean("Properties.Water.CanBendPackedIce");
} }
/** /**
@ -302,7 +308,7 @@ public class BendingPlayer {
* @return true If player has permission node "bending.ability.plantbending" * @return true If player has permission node "bending.ability.plantbending"
*/ */
public boolean canPlantbend() { public boolean canPlantbend() {
return player.hasPermission("bending.water.plantbending"); return subelements.contains(SubElement.PLANT);
} }
/** /**
@ -312,7 +318,7 @@ public class BendingPlayer {
* @return true If player has permission node "bending.earth.sandbending" * @return true If player has permission node "bending.earth.sandbending"
*/ */
public boolean canSandbend() { public boolean canSandbend() {
return player.hasPermission("bending.earth.sandbending"); return subelements.contains(SubElement.SAND);
} }
/** /**
@ -321,7 +327,7 @@ public class BendingPlayer {
* @return true If player has permission node "bending.air.flight" * @return true If player has permission node "bending.air.flight"
*/ */
public boolean canUseFlight() { public boolean canUseFlight() {
return player.hasPermission("bending.air.flight"); return subelements.contains(SubElement.FLIGHT);
} }
/** /**
@ -331,7 +337,7 @@ public class BendingPlayer {
* @return true If player has permission node "bending.air.spiritualprojection" * @return true If player has permission node "bending.air.spiritualprojection"
*/ */
public boolean canUseSpiritualProjection() { public boolean canUseSpiritualProjection() {
return player.hasPermission("bending.air.spiritualprojection"); return subelements.contains(SubElement.SPIRITUAL);
} }
/** /**
@ -339,7 +345,7 @@ public class BendingPlayer {
* @return true If player has permission node "bending.water.healing" * @return true If player has permission node "bending.water.healing"
*/ */
public boolean canWaterHeal() { public boolean canWaterHeal() {
return player.hasPermission("bending.water.healing"); return subelements.contains(SubElement.HEALING);
} }
/** /**
@ -348,7 +354,7 @@ public class BendingPlayer {
* @return true If the player has permission to bend that subelement. * @return true If the player has permission to bend that subelement.
*/ */
public boolean canUseSubElement(SubElement sub) { public boolean canUseSubElement(SubElement sub) {
return player.hasPermission("bending." + sub.getParentElement().getName().toLowerCase() + "." + sub.getName().toLowerCase()); return subelements.contains(sub);
} }
/** /**
@ -472,6 +478,14 @@ public class BendingPlayer {
} }
return false; return false;
} }
public boolean hasSubElement(SubElement sub) {
if (sub == null) {
return false;
} else {
return this.subelements.contains(sub);
}
}
public boolean isAvatarState() { public boolean isAvatarState() {
return CoreAbility.hasAbility(player, AvatarState.class); return CoreAbility.hasAbility(player, AvatarState.class);

View file

@ -1,7 +1,5 @@
package com.projectkorra.projectkorra; package com.projectkorra.projectkorra;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
import me.ryanhamshire.GriefPrevention.Claim; import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.GriefPrevention; import me.ryanhamshire.GriefPrevention.GriefPrevention;
import net.sacredlabyrinth.Phaed.PreciousStones.FieldFlag; import net.sacredlabyrinth.Phaed.PreciousStones.FieldFlag;
@ -29,6 +27,7 @@ import com.palmergames.bukkit.towny.object.WorldCoord;
import com.palmergames.bukkit.towny.utils.PlayerCacheUtil; import com.palmergames.bukkit.towny.utils.PlayerCacheUtil;
import com.palmergames.bukkit.towny.war.flagwar.TownyWar; import com.palmergames.bukkit.towny.war.flagwar.TownyWar;
import com.palmergames.bukkit.towny.war.flagwar.TownyWarConfig; import com.palmergames.bukkit.towny.war.flagwar.TownyWarConfig;
import com.projectkorra.projectkorra.Element.SubElement;
import com.projectkorra.projectkorra.ability.Ability; import com.projectkorra.projectkorra.ability.Ability;
import com.projectkorra.projectkorra.ability.AddonAbility; import com.projectkorra.projectkorra.ability.AddonAbility;
import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.ability.CoreAbility;
@ -45,14 +44,11 @@ import com.projectkorra.projectkorra.airbending.AirShield;
import com.projectkorra.projectkorra.airbending.AirSpout; import com.projectkorra.projectkorra.airbending.AirSpout;
import com.projectkorra.projectkorra.airbending.AirSuction; import com.projectkorra.projectkorra.airbending.AirSuction;
import com.projectkorra.projectkorra.airbending.AirSwipe; import com.projectkorra.projectkorra.airbending.AirSwipe;
import com.projectkorra.projectkorra.command.Commands;
import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.earthbending.EarthBlast; import com.projectkorra.projectkorra.earthbending.EarthBlast;
import com.projectkorra.projectkorra.earthbending.EarthPassive; import com.projectkorra.projectkorra.earthbending.EarthPassive;
import com.projectkorra.projectkorra.event.AbilityDamageEntityEvent;
import com.projectkorra.projectkorra.event.BendingReloadEvent; import com.projectkorra.projectkorra.event.BendingReloadEvent;
import com.projectkorra.projectkorra.event.BindChangeEvent; import com.projectkorra.projectkorra.event.BindChangeEvent;
import com.projectkorra.projectkorra.event.EntityBendingDeathEvent;
import com.projectkorra.projectkorra.firebending.Combustion; import com.projectkorra.projectkorra.firebending.Combustion;
import com.projectkorra.projectkorra.firebending.FireBlast; import com.projectkorra.projectkorra.firebending.FireBlast;
import com.projectkorra.projectkorra.firebending.FireCombo; import com.projectkorra.projectkorra.firebending.FireCombo;
@ -60,7 +56,6 @@ import com.projectkorra.projectkorra.firebending.FireShield;
import com.projectkorra.projectkorra.object.Preset; import com.projectkorra.projectkorra.object.Preset;
import com.projectkorra.projectkorra.storage.DBConnection; import com.projectkorra.projectkorra.storage.DBConnection;
import com.projectkorra.projectkorra.util.BlockCacheElement; import com.projectkorra.projectkorra.util.BlockCacheElement;
import com.projectkorra.projectkorra.util.DamageHandler;
import com.projectkorra.projectkorra.util.Flight; import com.projectkorra.projectkorra.util.Flight;
import com.projectkorra.projectkorra.util.ParticleEffect; import com.projectkorra.projectkorra.util.ParticleEffect;
import com.projectkorra.projectkorra.util.TempBlock; import com.projectkorra.projectkorra.util.TempBlock;
@ -86,8 +81,6 @@ import org.bukkit.entity.FallingSand;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
@ -170,10 +163,7 @@ public class GeneralMethods {
*/ */
public static void bindAbility(Player player, String ability) { public static void bindAbility(Player player, String ability) {
int slot = player.getInventory().getHeldItemSlot() + 1; int slot = player.getInventory().getHeldItemSlot() + 1;
BindChangeEvent event = new BindChangeEvent(player, ability, slot, true); bindAbility(player, ability, slot);
Bukkit.getServer().getPluginManager().callEvent(event);
if(!event.isCancelled())
bindAbility(player, ability, slot);
} }
/** /**
@ -190,22 +180,18 @@ public class GeneralMethods {
return; return;
} }
BindChangeEvent event = new BindChangeEvent(player, ability, slot, true); BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player.getName());
Bukkit.getServer().getPluginManager().callEvent(event); CoreAbility coreAbil = CoreAbility.getAbility(ability);
if(!event.isCancelled()) {
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player.getName()); if (bPlayer == null) {
CoreAbility coreAbil = CoreAbility.getAbility(ability); return;
if (bPlayer == null) {
return;
}
bPlayer.getAbilities().put(slot, ability);
if (coreAbil != null) {
player.sendMessage(coreAbil.getElement().getColor() + ConfigManager.languageConfig.get().getString("Commands.Bind.SuccessfullyBound").replace("{ability}", ability).replace("{slot}", String.valueOf(slot)));
}
saveAbility(bPlayer, slot, ability);
} }
bPlayer.getAbilities().put(slot, ability);
if (coreAbil != null) {
player.sendMessage(coreAbil.getElement().getColor() + ConfigManager.languageConfig.get().getString("Commands.Bind.SuccessfullyBound").replace("{ability}", ability).replace("{slot}", String.valueOf(slot)));
}
saveAbility(bPlayer, slot, ability);
} }
/** /**
@ -290,7 +276,7 @@ public class GeneralMethods {
ResultSet rs2 = DBConnection.sql.readQuery("SELECT * FROM pk_players WHERE uuid = '" + uuid.toString() + "'"); ResultSet rs2 = DBConnection.sql.readQuery("SELECT * FROM pk_players WHERE uuid = '" + uuid.toString() + "'");
try { try {
if (!rs2.next()) { // Data doesn't exist, we want a completely new player. if (!rs2.next()) { // Data doesn't exist, we want a completely new player.
new BendingPlayer(uuid, player, new ArrayList<Element>(), new HashMap<Integer, String>(), false); new BendingPlayer(uuid, player, new ArrayList<Element>(), new ArrayList<SubElement>(), new HashMap<Integer, String>(), false);
DBConnection.sql.modifyQuery("INSERT INTO pk_players (uuid, player) VALUES ('" + uuid.toString() + "', '" + player + "')"); DBConnection.sql.modifyQuery("INSERT INTO pk_players (uuid, player) VALUES ('" + uuid.toString() + "', '" + player + "')");
ProjectKorra.log.info("Created new BendingPlayer for " + player); ProjectKorra.log.info("Created new BendingPlayer for " + player);
} else { } else {
@ -301,7 +287,7 @@ public class GeneralMethods {
// They have changed names. // They have changed names.
ProjectKorra.log.info("Updating Player Name for " + player); ProjectKorra.log.info("Updating Player Name for " + player);
} }
String subelement = rs2.getString("subelement");
String element = rs2.getString("element"); String element = rs2.getString("element");
String permaremoved = rs2.getString("permaremoved"); String permaremoved = rs2.getString("permaremoved");
boolean p = false; boolean p = false;
@ -334,6 +320,53 @@ public class GeneralMethods {
} }
} }
} }
final ArrayList<SubElement> subelements = new ArrayList<SubElement>();
if (subelement != null) {
boolean hasAddon = subelement.contains(";");
String[] split = subelement.split(";");
if (split[0] != null) {
if (split[0].contains("m")) {
subelements.add(Element.METAL);
}
if (split[0].contains("v")) {
subelements.add(Element.LAVA);
}
if (split[0].contains("s")) {
subelements.add(Element.SAND);
}
if (split[0].contains("c")) {
subelements.add(Element.COMBUSTION);
}
if (split[0].contains("l")) {
subelements.add(Element.LIGHTNING);
}
if (split[0].contains("t")) {
subelements.add(Element.SPIRITUAL);
}
if (split[0].contains("f")) {
subelements.add(Element.FLIGHT);
}
if (split[0].contains("i")) {
subelements.add(Element.ICE);
}
if (split[0].contains("h")) {
subelements.add(Element.HEALING);
}
if (split[0].contains("b")) {
subelements.add(Element.BLOOD);
}
if (split[0].contains("p")) {
subelements.add(Element.PLANT);
}
if (hasAddon) {
for (String addon : split[split.length - 1].split(",")) {
if (Element.getElement(addon) != null && Element.getElement(addon) instanceof SubElement) {
subelements.add((SubElement)Element.getElement(addon));
}
}
}
}
}
final HashMap<Integer, String> abilities = new HashMap<Integer, String>(); final HashMap<Integer, String> abilities = new HashMap<Integer, String>();
for (int i = 1; i <= 9; i++) { for (int i = 1; i <= 9; i++) {
@ -350,7 +383,7 @@ public class GeneralMethods {
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
new BendingPlayer(uuid, player, elements, abilities, boolean_p); new BendingPlayer(uuid, player, elements, subelements, abilities, boolean_p);
} }
}.runTask(ProjectKorra.plugin); }.runTask(ProjectKorra.plugin);
} }
@ -1447,7 +1480,12 @@ public class GeneralMethods {
return; return;
} }
String uuid = bPlayer.getUUIDString(); String uuid = bPlayer.getUUIDString();
BindChangeEvent event = new BindChangeEvent(Bukkit.getPlayer(UUID.fromString(uuid)), ability, slot, false);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
//Temp code to block modifications of binds, Should be replaced when bind event is added. //Temp code to block modifications of binds, Should be replaced when bind event is added.
if (MultiAbilityManager.playerAbilities.containsKey(Bukkit.getPlayer(bPlayer.getUUID()))) { if (MultiAbilityManager.playerAbilities.containsKey(Bukkit.getPlayer(bPlayer.getUUID()))) {
return; return;
@ -1492,6 +1530,61 @@ public class GeneralMethods {
DBConnection.sql.modifyQuery("UPDATE pk_players SET element = '" + elements + "' WHERE uuid = '" + uuid + "'"); DBConnection.sql.modifyQuery("UPDATE pk_players SET element = '" + elements + "' WHERE uuid = '" + uuid + "'");
} }
public static void saveSubElements(BendingPlayer bPlayer) {
if (bPlayer == null) {
return;
}
String uuid = bPlayer.getUUIDString();
StringBuilder subs = new StringBuilder();
if (bPlayer.hasSubElement(Element.METAL)) {
subs.append("m");
}
if (bPlayer.hasSubElement(Element.LAVA)) {
subs.append("v");
}
if (bPlayer.hasSubElement(Element.SAND)) {
subs.append("s");
}
if (bPlayer.hasSubElement(Element.COMBUSTION)) {
subs.append("c");
}
if (bPlayer.hasSubElement(Element.LIGHTNING)) {
subs.append("l");
}
if (bPlayer.hasSubElement(Element.SPIRITUAL)) {
subs.append("t");
}
if (bPlayer.hasSubElement(Element.FLIGHT)) {
subs.append("f");
}
if (bPlayer.hasSubElement(Element.ICE)) {
subs.append("i");
}
if (bPlayer.hasSubElement(Element.HEALING)) {
subs.append("h");
}
if (bPlayer.hasSubElement(Element.BLOOD)) {
subs.append("b");
}
if (bPlayer.hasSubElement(Element.PLANT)) {
subs.append("p");
}
boolean hasAddon = false;
for (Element element : bPlayer.getElements()) {
if (!(element instanceof SubElement)) continue;
if (Arrays.asList(Element.getAddonElements()).contains(element)) {
if (!hasAddon) {
hasAddon = true;
subs.append(";");
}
subs.append(element.getName() + ",");
}
}
DBConnection.sql.modifyQuery("UPDATE pk_players SET subelement = '" + subs + "' WHERE uuid = '" + uuid + "'");
}
public static void savePermaRemoved(BendingPlayer bPlayer) { public static void savePermaRemoved(BendingPlayer bPlayer) {
if (bPlayer == null) { if (bPlayer == null) {

View file

@ -38,8 +38,8 @@ public class MultiAbilityManager {
/** /**
* Sets up a player's binds for a MultiAbility. * Sets up a player's binds for a MultiAbility.
* *
* @param player * @param player Player having the multiability bound
* @param multiAbility * @param multiAbility MultiAbility being bound
*/ */
public static void bindMultiAbility(Player player, String multiAbility) { public static void bindMultiAbility(Player player, String multiAbility) {
BindChangeEvent event = new BindChangeEvent(player, multiAbility, true); BindChangeEvent event = new BindChangeEvent(player, multiAbility, true);

View file

@ -2,10 +2,12 @@ package com.projectkorra.projectkorra.command;
import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.Element.SubElement;
import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.event.PlayerChangeElementEvent; import com.projectkorra.projectkorra.event.PlayerChangeElementEvent;
import com.projectkorra.projectkorra.event.PlayerChangeElementEvent.Result; import com.projectkorra.projectkorra.event.PlayerChangeElementEvent.Result;
import com.projectkorra.projectkorra.event.PlayerChangeSubElementEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -26,6 +28,8 @@ public class AddCommand extends PKCommand {
private String added; private String added;
private String alreadyHasElementOther; private String alreadyHasElementOther;
private String alreadyHasElement; private String alreadyHasElement;
private String alreadyHasSubElementOther;
private String alreadyHasSubElement;
public AddCommand() { public AddCommand() {
super("add", "/bending add <Element> [Player]", ConfigManager.languageConfig.get().getString("Commands.Add.Description"), new String[] { "add", "a" }); super("add", "/bending add <Element> [Player]", ConfigManager.languageConfig.get().getString("Commands.Add.Description"), new String[] { "add", "a" });
@ -36,6 +40,8 @@ public class AddCommand extends PKCommand {
this.added = ConfigManager.languageConfig.get().getString("Commands.Add.SuccessfullyAdded"); this.added = ConfigManager.languageConfig.get().getString("Commands.Add.SuccessfullyAdded");
this.alreadyHasElementOther = ConfigManager.languageConfig.get().getString("Commands.Add.Other.AlreadyHasElement"); this.alreadyHasElementOther = ConfigManager.languageConfig.get().getString("Commands.Add.Other.AlreadyHasElement");
this.alreadyHasElement = ConfigManager.languageConfig.get().getString("Commands.Add.AlreadyHasElement"); this.alreadyHasElement = ConfigManager.languageConfig.get().getString("Commands.Add.AlreadyHasElement");
this.alreadyHasSubElementOther = ConfigManager.languageConfig.get().getString("Commands.Add.Other.AlreadyHasSubElement");
this.alreadyHasSubElement = ConfigManager.languageConfig.get().getString("Commands.Add.AlreadyHasSubElement");
} }
public void execute(CommandSender sender, List<String> args) { public void execute(CommandSender sender, List<String> args) {
@ -96,6 +102,27 @@ public class AddCommand extends PKCommand {
GeneralMethods.saveElements(bPlayer); GeneralMethods.saveElements(bPlayer);
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(sender, target, element, Result.ADD)); Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(sender, target, element, Result.ADD));
return; return;
} else if (Arrays.asList(Element.getAllSubElements()).contains(element)) {
SubElement sub = (SubElement) element;
if (bPlayer.hasSubElement(sub)) {
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
sender.sendMessage(ChatColor.RED + alreadyHasSubElementOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + ChatColor.RED));
} else {
sender.sendMessage(ChatColor.RED + alreadyHasSubElement);
}
return;
}
bPlayer.addSubElement(sub);
ChatColor color = element.getColor();
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
sender.sendMessage(color + addedOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", sub.getName() + sub.getType().getBender()));
} else {
target.sendMessage(color + added.replace("{element}", sub.getName() + sub.getType().getBender()));
}
GeneralMethods.saveSubElements(bPlayer);
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeSubElementEvent(sender, target, sub, com.projectkorra.projectkorra.event.PlayerChangeSubElementEvent.Result.ADD));
return;
} else { } else {
sender.sendMessage(ChatColor.RED + invalidElement); sender.sendMessage(ChatColor.RED + invalidElement);
} }

View file

@ -2,11 +2,13 @@ package com.projectkorra.projectkorra.command;
import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.Element.SubElement;
import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ProjectKorra;
import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.event.PlayerChangeElementEvent; import com.projectkorra.projectkorra.event.PlayerChangeElementEvent;
import com.projectkorra.projectkorra.event.PlayerChangeElementEvent.Result; import com.projectkorra.projectkorra.event.PlayerChangeElementEvent.Result;
import com.projectkorra.projectkorra.event.PlayerChangeSubElementEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -27,7 +29,7 @@ public class ChooseCommand extends PKCommand {
private String chosenOther; private String chosenOther;
public ChooseCommand() { public ChooseCommand() {
super("choose", "/bending choose <Element> [Player]", ConfigManager.languageConfig.get().getString("Commands.Choose.Description"), new String[] { "choose", "ch" }); super("choose", "/bending choose <Element/SubElement> [Player]", ConfigManager.languageConfig.get().getString("Commands.Choose.Description"), new String[] { "choose", "ch" });
this.playerNotFound = ConfigManager.languageConfig.get().getString("Commands.Choose.PlayerNotFound"); this.playerNotFound = ConfigManager.languageConfig.get().getString("Commands.Choose.PlayerNotFound");
this.invalidElement = ConfigManager.languageConfig.get().getString("Commands.Choose.InvalidElement"); this.invalidElement = ConfigManager.languageConfig.get().getString("Commands.Choose.InvalidElement");
@ -66,6 +68,12 @@ public class ChooseCommand extends PKCommand {
} }
add(sender, (Player) sender, target); add(sender, (Player) sender, target);
return; return;
} else if (Arrays.asList(Element.getAllSubElements()).contains(target)) {
SubElement sub = (SubElement) target;
if (!hasPermission(sender, sub.getName())) {
return;
}
add(sender, (Player) sender, sub);
} else { } else {
sender.sendMessage(ChatColor.RED + invalidElement); sender.sendMessage(ChatColor.RED + invalidElement);
return; return;
@ -104,20 +112,33 @@ public class ChooseCommand extends PKCommand {
if (bPlayer == null) { if (bPlayer == null) {
return; return;
} }
if (element instanceof SubElement) {
bPlayer.setElement(element); SubElement sub = (SubElement) element;
ChatColor color = element != null ? element.getColor() : null; bPlayer.addSubElement(sub);
if (!(sender instanceof Player) || !((Player) sender).equals(target)) { ChatColor color = sub != null ? sub.getColor() : ChatColor.WHITE;
sender.sendMessage(color + chosenOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", element.getName() + element.getType().getBender())); if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
sender.sendMessage(color + chosenOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", sub.getName() + sub.getType().getBender()));
} else {
target.sendMessage(color + chosen.replace("{element}", sub.getName() + sub.getType().getBender()));
}
GeneralMethods.saveSubElements(bPlayer);
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeSubElementEvent(sender, target, sub, com.projectkorra.projectkorra.event.PlayerChangeSubElementEvent.Result.CHOOSE));
} else { } else {
target.sendMessage(color + chosen.replace("{element}", element.getName() + element.getType().getBender())); bPlayer.setElement(element);
ChatColor color = element != null ? element.getColor() : ChatColor.WHITE;
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
sender.sendMessage(color + chosenOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", element.getName() + element.getType().getBender()));
} else {
target.sendMessage(color + chosen.replace("{element}", element.getName() + element.getType().getBender()));
}
GeneralMethods.saveElements(bPlayer);
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(sender, target, element, Result.CHOOSE));
} }
GeneralMethods.removeUnusableAbilities(target.getName()); GeneralMethods.removeUnusableAbilities(target.getName());
GeneralMethods.saveElements(bPlayer);
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(sender, target, element, Result.CHOOSE));
} }
public static boolean isVowel(char c) { public static boolean isVowel(char c) {

View file

@ -2,6 +2,7 @@ package com.projectkorra.projectkorra.command;
import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.Element.SubElement;
import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ProjectKorra;
import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.configuration.ConfigManager;
@ -68,17 +69,26 @@ public class ImportCommand extends PKCommand {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
UUID uuid = ProjectKorra.plugin.getServer().getOfflinePlayer(playername).getUniqueId(); UUID uuid = ProjectKorra.plugin.getServer().getOfflinePlayer(playername).getUniqueId();
ArrayList<Element> elements = new ArrayList<Element>(); ArrayList<Element> elements = new ArrayList<Element>();
ArrayList<SubElement> subs = new ArrayList<SubElement>();
List<Integer> bendingTypes = bendingPlayers.getIntegerList(string + ".BendingTypes"); List<Integer> bendingTypes = bendingPlayers.getIntegerList(string + ".BendingTypes");
boolean permaremoved = bendingPlayers.getBoolean(string + ".Permaremoved"); boolean permaremoved = bendingPlayers.getBoolean(string + ".Permaremoved");
Element[] mainElements = Element.getMainElements(); Element[] mainElements = Element.getMainElements();
Element[] allElements = Element.getAllElements();
for (int i : bendingTypes) { for (int i : bendingTypes) {
if (i < mainElements.length) { if (i < mainElements.length) {
elements.add(mainElements[i]); elements.add(mainElements[i]);
} }
} }
for (Element e : allElements) {
if (e instanceof SubElement) {
SubElement s = (SubElement) e;
subs.add(s);
}
}
BendingPlayer bPlayer = new BendingPlayer(uuid, playername, elements, new HashMap<Integer, String>(), permaremoved); BendingPlayer bPlayer = new BendingPlayer(uuid, playername, elements, subs, new HashMap<Integer, String>(), permaremoved);
bPlayers.add(bPlayer); bPlayers.add(bPlayer);
} }

View file

@ -200,8 +200,10 @@ public class ConfigManager {
config.addDefault("Commands.Add.PlayerNotFound", "That player could not be found."); config.addDefault("Commands.Add.PlayerNotFound", "That player could not be found.");
config.addDefault("Commands.Add.InvalidElement", "You must specify a valid element."); config.addDefault("Commands.Add.InvalidElement", "You must specify a valid element.");
config.addDefault("Commands.Add.AlreadyHasElement", "You already have that element!"); config.addDefault("Commands.Add.AlreadyHasElement", "You already have that element!");
config.addDefault("Commands.Add.AlreadyHasSubElement", "You already have that subelement!");
config.addDefault("Commands.Add.Other.SuccessfullyAdded", "{target} is now also a {element}."); config.addDefault("Commands.Add.Other.SuccessfullyAdded", "{target} is now also a {element}.");
config.addDefault("Commands.Add.Other.AlreadyHasElement", "{target} already has that element!"); config.addDefault("Commands.Add.Other.AlreadyHasElement", "{target} already has that element!");
config.addDefault("Commands.Add.Other.AlreadyHasSubElement", "{target} already has that subelement!");
config.addDefault("DeathMessages.Enabled", true); config.addDefault("DeathMessages.Enabled", true);
config.addDefault("DeathMessages.Default", "{victim} was slain by {attacker}'s {ability}"); config.addDefault("DeathMessages.Default", "{victim} was slain by {attacker}'s {ability}");
@ -1100,6 +1102,7 @@ public class ConfigManager {
config.addDefault("Storage.MySQL.pass", ""); config.addDefault("Storage.MySQL.pass", "");
config.addDefault("Storage.MySQL.db", "minecraft"); config.addDefault("Storage.MySQL.db", "minecraft");
config.addDefault("Storage.MySQL.user", "root"); config.addDefault("Storage.MySQL.user", "root");
config.addDefault("Storage.MySQL.SubElementAdded", false);
config.addDefault("debug", false); config.addDefault("debug", false);

View file

@ -12,9 +12,7 @@ public class ConfigType {
public static final ConfigType DEFAULT = new ConfigType("Default"); public static final ConfigType DEFAULT = new ConfigType("Default");
public static final ConfigType PRESETS = new ConfigType("Presets"); public static final ConfigType PRESETS = new ConfigType("Presets");
public static final ConfigType LANGUAGE = new ConfigType("Language"); public static final ConfigType LANGUAGE = new ConfigType("Language");
public static final ConfigType[] CORE_TYPES = {DEFAULT, PRESETS, LANGUAGE}; public static final ConfigType[] CORE_TYPES = {DEFAULT, PRESETS, LANGUAGE};
private static List<ConfigType> addonTypes = new ArrayList<ConfigType>();
private String string; private String string;

View file

@ -0,0 +1,78 @@
package com.projectkorra.projectkorra.event;
import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.Element.SubElement;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class PlayerChangeSubElementEvent extends Event{
private static final HandlerList handlers = new HandlerList();
private CommandSender sender;
private Player target;
private SubElement sub;
private Result result;
/**
*
* @param sender the {@link CommandSender} who changed the player's bending
* @param target the {@link Player} who's bending was changed
* @param sub the {@link SubElement} that was changed to
* @param result whether the element was chosen, added, removed, or permaremoved
*/
public PlayerChangeSubElementEvent(CommandSender sender, Player target, SubElement sub, Result result) {
this.sender = sender;
this.target = target;
this.sub = sub;
this.result = result;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
/**
*
* @return the {@link CommandSender} who changed the player's bending
*/
public CommandSender getSender() {
return sender;
}
/**
*
* @return the {@link Player player} who's bending was changed
*/
public Player getTarget() {
return target;
}
/**
*
* @return the {@link Element element} that was affected
*/
public SubElement getSubElement() {
return sub;
}
/**
*
* @return whether the element was chosen, added, removed, or permaremoved
*/
public Result getResult() {
return result;
}
public static enum Result {
CHOOSE, REMOVE, ADD, PERMAREMOVE;
private Result() {
}
}
}

View file

@ -1,15 +1,13 @@
package com.projectkorra.projectkorra.firebending; package com.projectkorra.projectkorra.firebending;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.ability.CoreAbility;
import com.projectkorra.projectkorra.event.EntityBendingDeathEvent;
import com.projectkorra.projectkorra.util.DamageHandler; import com.projectkorra.projectkorra.util.DamageHandler;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public class FireDamageTimer { public class FireDamageTimer {

View file

@ -2,6 +2,7 @@ package com.projectkorra.projectkorra.storage;
import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ProjectKorra;
import com.projectkorra.projectkorra.configuration.ConfigManager;
public class DBConnection { public class DBConnection {
@ -13,6 +14,7 @@ public class DBConnection {
public static String user; public static String user;
public static String pass; public static String pass;
public static boolean isOpen = false; public static boolean isOpen = false;
private static boolean subelement = ConfigManager.defaultConfig.get().getBoolean("Storage.MySQL.SubElementAdded");
public static void init() { public static void init() {
if (ProjectKorra.plugin.getConfig().getString("Storage.engine").equalsIgnoreCase("mysql")) { if (ProjectKorra.plugin.getConfig().getString("Storage.engine").equalsIgnoreCase("mysql")) {
@ -28,15 +30,20 @@ public class DBConnection {
if (!sql.tableExists("pk_players")) { if (!sql.tableExists("pk_players")) {
ProjectKorra.log.info("Creating pk_players table"); ProjectKorra.log.info("Creating pk_players table");
String query = "CREATE TABLE `pk_players` (" + "`uuid` varchar(36) NOT NULL," + "`player` varchar(16) NOT NULL," + "`element` varchar(5)," + "`permaremoved` varchar(5)," + "`slot1` varchar(255)," + "`slot2` varchar(255)," + "`slot3` varchar(255)," + "`slot4` varchar(255)," + "`slot5` varchar(255)," + "`slot6` varchar(255)," + "`slot7` varchar(255)," + "`slot8` varchar(255)," + "`slot9` varchar(255)," + " PRIMARY KEY (uuid));"; String query = "CREATE TABLE `pk_players` (" + "`uuid` varchar(36) NOT NULL," + "`player` varchar(16) NOT NULL," + "`element` varchar(255)," + "`subelement` varchar(255)" + "`permaremoved` varchar(5)," + "`slot1` varchar(255)," + "`slot2` varchar(255)," + "`slot3` varchar(255)," + "`slot4` varchar(255)," + "`slot5` varchar(255)," + "`slot6` varchar(255)," + "`slot7` varchar(255)," + "`slot8` varchar(255)," + "`slot9` varchar(255)," + " PRIMARY KEY (uuid));";
sql.modifyQuery(query); sql.modifyQuery(query);
} else {
if (!subelement) {
sql.modifyQuery("ALTER TABLE `pk_players` ADD subelement varchar(255);");
ConfigManager.defaultConfig.get().set("Storage.MySQL.SubElementAdded", true);
}
} }
if (!sql.tableExists("pk_presets")) { if (!sql.tableExists("pk_presets")) {
ProjectKorra.log.info("Creating pk_presets table"); ProjectKorra.log.info("Creating pk_presets table");
String query = "CREATE TABLE `pk_presets` (" + "`uuid` varchar(36) NOT NULL," + "`name` varchar(255) NOT NULL," + "`slot1` varchar(255)," + "`slot2` varchar(255)," + "`slot3` varchar(255)," + "`slot4` varchar(255)," + "`slot5` varchar(255)," + "`slot6` varchar(255)," + "`slot7` varchar(255)," + "`slot8` varchar(255)," + "`slot9` varchar(255)," + " PRIMARY KEY (uuid, name));"; String query = "CREATE TABLE `pk_presets` (" + "`uuid` varchar(36) NOT NULL," + "`name` varchar(255) NOT NULL," + "`slot1` varchar(255)," + "`slot2` varchar(255)," + "`slot3` varchar(255)," + "`slot4` varchar(255)," + "`slot5` varchar(255)," + "`slot6` varchar(255)," + "`slot7` varchar(255)," + "`slot8` varchar(255)," + "`slot9` varchar(255)," + " PRIMARY KEY (uuid, name));";
sql.modifyQuery(query); sql.modifyQuery(query);
} }
} else { } else {
sql = new SQLite(ProjectKorra.log, "Establishing SQLite Connection.", "projectkorra.db", ProjectKorra.plugin.getDataFolder().getAbsolutePath()); sql = new SQLite(ProjectKorra.log, "Establishing SQLite Connection.", "projectkorra.db", ProjectKorra.plugin.getDataFolder().getAbsolutePath());
if (((SQLite) sql).open() == null) { if (((SQLite) sql).open() == null) {
@ -48,8 +55,13 @@ public class DBConnection {
isOpen = true; isOpen = true;
if (!sql.tableExists("pk_players")) { if (!sql.tableExists("pk_players")) {
ProjectKorra.log.info("Creating pk_players table."); ProjectKorra.log.info("Creating pk_players table.");
String query = "CREATE TABLE `pk_players` (" + "`uuid` TEXT(36) PRIMARY KEY," + "`player` TEXT(16)," + "`element` TEXT(255)," + "`permaremoved` TEXT(5)," + "`slot1` TEXT(255)," + "`slot2` TEXT(255)," + "`slot3` TEXT(255)," + "`slot4` TEXT(255)," + "`slot5` TEXT(255)," + "`slot6` TEXT(255)," + "`slot7` TEXT(255)," + "`slot8` TEXT(255)," + "`slot9` TEXT(255));"; String query = "CREATE TABLE `pk_players` (" + "`uuid` TEXT(36) PRIMARY KEY," + "`player` TEXT(16)," + "`element` TEXT(255)," + "`subelement` TEXT(255)" + "`permaremoved` TEXT(5)," + "`slot1` TEXT(255)," + "`slot2` TEXT(255)," + "`slot3` TEXT(255)," + "`slot4` TEXT(255)," + "`slot5` TEXT(255)," + "`slot6` TEXT(255)," + "`slot7` TEXT(255)," + "`slot8` TEXT(255)," + "`slot9` TEXT(255));";
sql.modifyQuery(query); sql.modifyQuery(query);
} else {
if (!subelement) {
sql.modifyQuery("ALTER TABLE `pk_players` ADD subelement TEXT(255);");
ConfigManager.defaultConfig.get().set("Storage.MySQL.SubElementAdded", true);
}
} }
if (!sql.tableExists("pk_presets")) { if (!sql.tableExists("pk_presets")) {

View file

@ -1,5 +1,13 @@
package com.projectkorra.projectkorra.util; package com.projectkorra.projectkorra.util;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
import com.projectkorra.projectkorra.ability.Ability;
import com.projectkorra.projectkorra.command.Commands;
import com.projectkorra.projectkorra.event.AbilityDamageEntityEvent;
import com.projectkorra.projectkorra.event.EntityBendingDeathEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@ -7,16 +15,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.ability.Ability;
import com.projectkorra.projectkorra.ability.CoreAbility;
import com.projectkorra.projectkorra.command.Commands;
import com.projectkorra.projectkorra.event.AbilityDamageEntityEvent;
import com.projectkorra.projectkorra.event.EntityBendingDeathEvent;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
public class DamageHandler { public class DamageHandler {
/** /**
@ -53,7 +51,6 @@ public class DamageHandler {
((LivingEntity) entity).damage(damage, source); ((LivingEntity) entity).damage(damage, source);
System.out.println("calling regular damage");
entity.setLastDamageCause(new EntityDamageByEntityEvent(player, entity, DamageCause.CUSTOM, damage)); entity.setLastDamageCause(new EntityDamageByEntityEvent(player, entity, DamageCause.CUSTOM, damage));
if (Bukkit.getPluginManager().isPluginEnabled("NoCheatPlus")) { if (Bukkit.getPluginManager().isPluginEnabled("NoCheatPlus")) {