Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
KingKits v3.3.4
Browse files Browse the repository at this point in the history
KingKits v3.3.4 update.
  • Loading branch information
FarisR99 committed Mar 14, 2015
1 parent 929a3fa commit a1a488a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 35 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.faris</groupId>
<artifactId>KingKits</artifactId>
<version>3.3.3</version>
<version>3.3.4</version>

<packaging>jar</packaging>

Expand Down
14 changes: 8 additions & 6 deletions src/main/java/com/faris/kingkits/KingKits.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ public void loadConfiguration() throws Exception {
this.getConfig().addDefault("Remove potion effects on leave", true);
this.getConfig().addDefault("Set compass target to nearest player", true);
this.getConfig().addDefault("Quick soup", true);
this.getConfig().addDefault("Quick soup heal", 2.5D);
this.getConfig().addDefault("Requires kit to use refill", true);
this.getConfig().addDefault("Command to run when changing kits", "");
this.getConfig().addDefault("Disable block placing and breaking", false);
Expand Down Expand Up @@ -363,11 +364,11 @@ public void loadConfiguration() throws Exception {
this.cmdValues.deleteUKits = this.getConfig().getBoolean("Enable delete user kits command");
this.cmdValues.renameUKits = this.getConfig().getBoolean("Enable rename user kits command");
this.cmdValues.refillKits = this.getConfig().getBoolean("Enable refill command");
this.configValues.strKitSign = ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Kit sign"));
this.configValues.strKitListSign = ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Kit list sign"));
this.configValues.strKitSignValid = ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Kit sign valid"));
this.configValues.strKitSignInvalid = ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Kit sign invalid"));
this.configValues.strKitListSignValid = ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("Kit list sign valid"));
this.configValues.strKitSign = Utils.replaceChatColour(this.getConfig().getString("Kit sign"));
this.configValues.strKitListSign = Utils.replaceChatColour(this.getConfig().getString("Kit list sign"));
this.configValues.strKitSignValid = Utils.replaceChatColour(this.getConfig().getString("Kit sign valid"));
this.configValues.strKitSignInvalid = Utils.replaceChatColour(this.getConfig().getString("Kit sign invalid"));
this.configValues.strKitListSignValid = Utils.replaceChatColour(this.getConfig().getString("Kit list sign valid"));
this.configValues.kitCooldown = this.getConfig().getBoolean("Kit cooldown enabled");
this.configValues.listKitsOnJoin = this.getConfig().getBoolean("List kits on join");
this.configValues.kitListMode = this.getConfig().getString("Kit list mode");
Expand All @@ -386,6 +387,7 @@ public void loadConfiguration() throws Exception {
this.configValues.removePotionEffectsOnLeave = this.getConfig().getBoolean("Remove potion effects on leave");
this.configValues.rightClickCompass = this.getConfig().getBoolean("Set compass target to nearest player");
this.configValues.quickSoup = this.getConfig().getBoolean("Quick soup");
this.configValues.quickSoupHeal = (float) (Math.ceil(this.getConfig().getDouble("Quick soup heal") * 2) / 2);
this.configValues.quickSoupKitOnly = this.getConfig().getBoolean("Requires kit to use refill");
this.configValues.banBlockBreakingAndPlacing = this.getConfig().getBoolean("Disable block placing and breaking");
this.configValues.disableDeathMessages = this.getConfig().getBoolean("Disable death messages");
Expand All @@ -402,7 +404,7 @@ public void loadConfiguration() throws Exception {
this.configValues.showKitPreview = this.getConfig().getBoolean("Show kit preview");
this.configValues.replaceItems = this.getConfig().getBoolean("Replace items when selecting a kit");

this.configValues.guiTitle = ChatColor.translateAlternateColorCodes('&', this.getConfig().getString("GUI.Title"));
this.configValues.guiTitle = Utils.replaceChatColour(this.getConfig().getString("GUI.Title"));
this.configValues.guiSize = this.getConfig().getInt("GUI.Size");
if (this.configValues.guiSize <= 0 || this.configValues.guiSize % 9 != 0 || this.configValues.guiSize > 54)
this.configValues.guiSize = 36;
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/com/faris/kingkits/Kit.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class Kit implements Iterable<ItemStack>, ConfigurationSerializable {
private List<ItemStack> kitArmour = new ArrayList<ItemStack>();
private List<PotionEffect> potionEffects = new ArrayList<PotionEffect>();
private Map<Long, List<String>> killstreakCommands = new HashMap<Long, List<String>>();
private List<String> kitDescription = new ArrayList<String>();

private boolean itemBreaking = true;

Expand Down Expand Up @@ -98,7 +99,8 @@ public Kit(String kitName, double kitCost, Map<Integer, ItemStack> kitItems, Lis

public Kit addItem(ItemStack itemStack) {
Validate.notNull(itemStack);
this.kitItems.put(this.getFreeSlot(), itemStack);
int freeSlot = this.getFreeSlot();
if (freeSlot >= 0 && freeSlot < 36) this.kitItems.put(freeSlot, itemStack);
return this;
}

Expand All @@ -122,6 +124,10 @@ public double getCost() {
return this.kitCost;
}

public List<String> getDescription() {
return this.kitDescription;
}

private int getFreeSlot() {
for (int i = 0; i < 36; i++) {
if (!this.kitItems.containsKey(new Integer(i))) return i;
Expand Down Expand Up @@ -179,6 +185,10 @@ public boolean hasCooldown() {
return KingKits.getInstance().configValues.kitCooldown && this.kitCooldown > 0;
}

public boolean hasDescription() {
return !this.kitDescription.isEmpty();
}

public boolean isUserKit() {
return this.userKit;
}
Expand Down Expand Up @@ -220,6 +230,11 @@ public Kit setCost(double cost) {
return this;
}

public Kit setDescription(List<String> description) {
if (description != null) this.kitDescription = description;
return this;
}

public Kit setGuiItem(ItemStack guiItem) {
this.guiItem = guiItem != null ? guiItem : new ItemStack(Material.AIR);
return this;
Expand Down Expand Up @@ -291,6 +306,7 @@ public Map<String, Object> serialize() {
serializedKit.put("Item breaking", this.itemBreaking);
serializedKit.put("Max health", this.maxHealth);
serializedKit.put("GUI Position", this.guiPosition);
serializedKit.put("Description", this.kitDescription);

/** GUI Item **/
if (this.guiItem != null) {
Expand Down Expand Up @@ -440,6 +456,8 @@ public static Kit deserialize(Map<String, Object> kitSection) throws NullPointer
kit.setMaxHealth(getObject(kitSection, "Max health", Integer.class));
if (kitSection.containsKey("GUI Position"))
kit.setGuiPosition(getObject(kitSection, "GUI Position", Integer.class));
if (kitSection.containsKey("Description"))
kit.setDescription(getObject(kitSection, "Description", List.class));
if (kitSection.containsKey("GUI Item")) {
Map<String, Object> guiItemMap = getValues(kitSection, "GUI Item");
ItemStack guiItem = null;
Expand Down Expand Up @@ -664,7 +682,7 @@ public static Kit deserialize(Map<String, Object> kitSection) throws NullPointer
public static <T> T getObject(Map<String, Object> map, String key, Class<T> unused) throws ClassCastException {
try {
T value = map.containsKey(key) ? (T) map.get(key) : null;
return value != null ? (unused == Long.class ? (T) ((Long) Long.parseLong(value.toString())) : (unused == Integer.class ? (T) ((Integer) Integer.parseInt(value.toString())) : (unused == Short.class ? (T) ((Short) Short.parseShort(value.toString())) : value))) : null;
return value != null ? (unused == Long.class ? (T) ((Long) Long.parseLong(value.toString())) : (unused == Integer.class ? (T) ((Integer) Integer.parseInt(value.toString())) : (unused == Short.class ? (T) ((Short) Short.parseShort(value.toString())) : (unused == Double.class ? (T) ((Double) Double.parseDouble(value.toString())) : value)))) : null;
} catch (ClassCastException ex) {
throw ex;
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/faris/kingkits/guis/GuiKitMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,24 @@ protected void fillInventory() {
if (currentStack.getItemMeta() != null) {
ItemMeta itemMeta = currentStack.getItemMeta();
Kit targetKit = PvPKits.getKitByName(this.guiKitStacks[i].getKitName(), this.getPlayerName());

ChatColor kitColour = this.getPlayer().hasPermission("kingkits.kits." + (targetKit != null ? targetKit.getRealName().toLowerCase() : Utils.stripColour(this.guiKitStacks[i].getKitName().toLowerCase()))) ? ChatColor.GREEN : ChatColor.DARK_RED;
itemMeta.setDisplayName(ChatColor.RESET + "" + kitColour + this.guiKitStacks[i].getKitName());

if (targetKit != null && targetKit.hasDescription()) {
List<String> kitDescription = new ArrayList<String>();
for (String descriptionLine : targetKit.getDescription()) {
descriptionLine = Utils.replaceChatColour(descriptionLine);
descriptionLine = descriptionLine.replace("<player>", this.getPlayerName());
descriptionLine = descriptionLine.replace("<name>", targetKit.getName());
descriptionLine = descriptionLine.replace("<cost>", String.valueOf(targetKit.getCost()));
descriptionLine = descriptionLine.replace("<cooldown>", String.valueOf(targetKit.getCooldown()));
descriptionLine = descriptionLine.replace("<maxhealth>", String.valueOf(targetKit.getMaxHealth()));
kitDescription.add(descriptionLine);
}
itemMeta.setLore(kitDescription);
}

currentStack.setItemMeta(itemMeta);
}
this.guiInventory.addItem(currentStack);
Expand Down
40 changes: 14 additions & 26 deletions src/main/java/com/faris/kingkits/listeners/event/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,40 +240,28 @@ public void onPlayerInteract(PlayerInteractEvent event) {
if (this.getPlugin().configValues.pvpWorlds.contains("All") || this.getPlugin().configValues.pvpWorlds.contains(event.getPlayer().getWorld().getName())) {
Player player = event.getPlayer();
int soupAmount = player.getInventory().getItemInHand().getAmount();
if (soupAmount == 1) {
if (soupAmount > 0) {
boolean valid = true;
if (player.getHealth() < player.getMaxHealth()) {
if (player.getHealth() + 5 > player.getMaxHealth())
if (player.getHealth() + (this.getPlugin().configValues.quickSoupHeal * 2) > player.getMaxHealth())
player.setHealth(player.getMaxHealth());
else player.setHealth(player.getHealth() + 5);
else player.setHealth(player.getHealth() + (this.getPlugin().configValues.quickSoupHeal * 2));
} else if (player.getFoodLevel() < 20) {
if (player.getFoodLevel() + 4 > 20) player.setFoodLevel(20);
else player.setFoodLevel(player.getFoodLevel() + 4);
if (player.getFoodLevel() + 6 > 20) player.setFoodLevel(20);
else player.setFoodLevel(player.getFoodLevel() + 6);
} else {
valid = false;
}
if (valid) {
player.getInventory().setItemInHand(new ItemStack(Material.BOWL, 1));
event.setCancelled(true);
}
} else if (soupAmount > 0) {
boolean valid = true;
if (player.getHealth() < player.getMaxHealth()) {
if (player.getHealth() + 5 > player.getMaxHealth())
player.setHealth(player.getMaxHealth());
else player.setHealth(player.getHealth() + 5);
} else if (player.getFoodLevel() < 20) {
if (player.getFoodLevel() + 4 > 20) player.setFoodLevel(20);
else player.setFoodLevel(player.getFoodLevel() + 4);
} else {
valid = false;
}
if (valid) {
int newAmount = soupAmount - 1;
ItemStack newItem = player.getInventory().getItemInHand();
newItem.setAmount(newAmount);
player.getInventory().setItemInHand(newItem);
player.getInventory().addItem(new ItemStack(Material.BOWL));
if (soupAmount == 1) {
player.getInventory().setItemInHand(new ItemStack(Material.BOWL, 1));
} else {
int newAmount = soupAmount - 1;
ItemStack newItem = player.getInventory().getItemInHand();
newItem.setAmount(newAmount);
player.getInventory().setItemInHand(newItem);
player.getInventory().addItem(new ItemStack(Material.BOWL, 1));
}
event.setCancelled(true);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/faris/kingkits/values/ConfigValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class ConfigValues {

public boolean quickSoup = true;
public boolean quickSoupKitOnly = true;
public double quickSoupHeal = 2.5;

public boolean banBlockBreakingAndPlacing = false;

Expand Down

0 comments on commit a1a488a

Please sign in to comment.