Skip to content

Commit

Permalink
Version 2.3b
Browse files Browse the repository at this point in the history
	Feature Upgrades
		Changes to /ce ench
			Now has a third argument which defines a material that is required for the enchantment to be applied
			Now starts at level 1 if no level is specified
			Now increases the level of an enchantment by the specified level if the item already has the enchantment
		The arrows of the Volley enchantment and the Minigun now inherit most properties of the original arrow (With the exception of Power's damage increase)
	New Enchantments
		Healing (Thanks to rpgrowland and hetjoshi)
	Bugfixes
		Bow enchantments no longer work when hitting with the bow itself
		Fixed a bug that would cause the config to not write itself on new servers
  • Loading branch information
Taiterio authored and Taiterio committed May 26, 2015
1 parent 04f2ec0 commit 8f4ed84
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 24 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CustomEnchantments
main: com.taiter.ce.Main
version: 2.3a
version: 2.3b

softdepend: [WorldGuard, WorldEdit, Vault]

Expand Down
4 changes: 4 additions & 0 deletions src/com/taiter/ce/CEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import com.taiter.ce.CBasic.Trigger;
import com.taiter.ce.CItems.CItem;
import com.taiter.ce.Enchantments.CEnchantment;

Expand Down Expand Up @@ -254,6 +255,9 @@ public static void handleEventMain(Player toCheck, ItemStack i, Event e, HashSet
((EntityShootBowEvent) e).getProjectile().setMetadata("ce.bow.enchantment", new FixedMetadataValue(Main.plugin, enchantments));
}
//BOWS

if(e instanceof EntityDamageByEntityEvent && ((EntityDamageByEntityEvent) e).getDamager() instanceof Player && ce.triggers.contains(Trigger.SHOOT_BOW))
continue;

ce.effect(e, i, level);
}
Expand Down
10 changes: 10 additions & 0 deletions src/com/taiter/ce/CItems/Minigun.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ public Minigun(String originalName, ChatColor color, String lDescription, long l
@Override
public boolean effect(Event event, final Player player) {
final EntityShootBowEvent e = (EntityShootBowEvent) event;
Arrow oldArrow = (Arrow) e.getProjectile();
e.setCancelled(true);
addLock(player);

final int fireTicks = oldArrow.getFireTicks();
final int knockbackStrength = oldArrow.getKnockbackStrength();
final boolean critical = oldArrow.isCritical();
final String metadata = oldArrow.getMetadata("ce.bow.enchantment").get(0).asString();

new BukkitRunnable() {

Expand Down Expand Up @@ -91,6 +97,10 @@ public void run() {
arrow.setBounce(false);
arrow.setVelocity(player.getLocation().getDirection().multiply(5));
arrow.setShooter(player);
arrow.setFireTicks(fireTicks); // Set the new arrows on fire if the original one was
arrow.setKnockbackStrength(knockbackStrength);
arrow.setCritical(critical);
arrow.setMetadata("ce.bow.enchantment", new FixedMetadataValue(getPlugin(), metadata));
arrow.setMetadata("ce.minigunarrow", new FixedMetadataValue(main, null));
player.getWorld().playEffect(player.getLocation(),Effect.BOW_FIRE, 20);
lArrows--;
Expand Down
59 changes: 49 additions & 10 deletions src/com/taiter/ce/CeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -528,16 +528,35 @@ public void run() {


if(name.startsWith("i") || name.startsWith("e")) {
usageError += (name.startsWith("e") ? "enchant <Enchantment> <Level>" : "item <Item>");
usageError += (name.startsWith("e") ? "enchant [Required Material] <Enchantment> <Level>" : "item <Item>");
if(args.length >= 2) {

requiredPermission += "enchant";
if(!sender.hasPermission(node) && !sender.hasPermission(requiredPermission) && !sender.isOp())
return Error + "You do not have permission to use this command.";

String customName = args[1];
Material test = null;

int level = 0;
int start = 2;

if(Material.getMaterial(customName) != null)
test = Material.getMaterial(customName);
else
try {
int material = Integer.parseInt(customName);
if(Material.getMaterial(material) != null)
test = Material.getMaterial(material);
} catch(NumberFormatException ex) {}

if(test != null) {
if(p.getItemInHand().getType() != test)
return Error + "You do not have the right material to enchant this!";
start++;
customName = args[2];
}

int level = 1;

if(name.startsWith("e")) {
if(item.getType().equals(Material.AIR))
Expand All @@ -553,8 +572,8 @@ public void run() {
if(level > 10)
level = 0;

if(args.length > 2)
for(int i = 2; i < (level == 0 ? args.length : args.length-1); i++)
if(args.length > start)
for(int i = start; i < (level == 0 ? args.length : args.length-1); i++)
customName += " " + args[i];


Expand All @@ -578,10 +597,16 @@ public void run() {
} catch(Exception ex) {}
}

if(ench != null) {
item.addUnsafeEnchantment(ench, level);
return Success + "You have succesfully enchanted your item with " + ench.getName() + " level " + level + ".";
}
if(ench != null)
if(item.containsEnchantment(ench)) {
int newLevel = item.getEnchantmentLevel(ench) + level;
item.removeEnchantment(ench);
item.addUnsafeEnchantment(ench, newLevel);
return Success + "You have succesfully increased the item's level of " + ench.getName() + " by " + level + ".";
} else {
item.addUnsafeEnchantment(ench, level);
return Success + "You have succesfully enchanted your item with " + ench.getName() + " level " + level + ".";
}

Error += "The " + (name.startsWith("i") ? "item":"enchantment") +" '" + customName + "' does not exist.";
return Error;
Expand All @@ -601,7 +626,21 @@ public void run() {
lore = item.getItemMeta().getLore();
if(custom instanceof CEnchantment) {
if(Tools.checkForEnchantments(lore, (CEnchantment) custom))
return Error + "You already have this Enchantment!";
for(int i = 0; i < lore.size(); i++) {
if(Tools.checkForEnchantment(lore.get(i), (CEnchantment) custom)) {
int newLevel = Tools.getLevel(lore.get(i))+level;
int maxLevel = ((CEnchantment) custom).getEnchantmentMaxLevel();
if(Tools.getLevel(lore.get(i)) == ((CEnchantment) custom).getEnchantmentMaxLevel())
return Error + "You already have the maximum level of this enchantment!";
if(newLevel > maxLevel)
newLevel = maxLevel;
lore.set(i, custom.getDisplayName() + " " + Tools.intToLevel(newLevel));
im.setLore(lore);
item.setItemMeta(im);
p.setItemInHand(item);
return Success + "You have increased your item's level of " + custom.getDisplayName() + ChatColor.GREEN + (newLevel == maxLevel ? " to " + maxLevel : " by " + level ) + "!";
}
}
int number = Main.maxEnchants;
for(CEnchantment ce : Main.enchantments)
if(number > 0) {
Expand All @@ -618,7 +657,7 @@ public void run() {
im.setLore(lore);
item.setItemMeta(im);
p.setItemInHand(item);
Success += "You have enchanted your item with '" + custom.getDisplayName() + ChatColor.GREEN + "'" + (level != 0 ? " level " + level : "") + "!";
Success += "You have enchanted your item with '" + custom.getDisplayName() + ChatColor.GREEN + "' level " + level + "!";
} else if(custom instanceof CItem){
Material toSet = item.getType();
if(toSet == Material.AIR)
Expand Down
61 changes: 61 additions & 0 deletions src/com/taiter/ce/Enchantments/Bow/Healing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.taiter.ce.Enchantments.Bow;

/*
* This file is part of Custom Enchantments
* Copyright (C) Taiterio 2015
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/



import org.bukkit.Effect;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;

import com.taiter.ce.Enchantments.CEnchantment;



public class Healing extends CEnchantment {

public Healing(Application app) {
super(app);
triggers.add(Trigger.SHOOT_BOW);
triggers.add(Trigger.DAMAGE_GIVEN);
}

@Override
public void effect(Event e, ItemStack item, int level) {
if(e instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
LivingEntity target = (LivingEntity) event.getEntity();


double newHealth = target.getHealth()+event.getDamage() + level;

if(newHealth >= target.getMaxHealth())
newHealth = target.getMaxHealth();
target.setHealth(newHealth);
event.setDamage(0);
target.getWorld().playEffect(target.getLocation(), Effect.POTION_BREAK, 10);
}
}

@Override
public void initConfigEntries() {
}
}
16 changes: 11 additions & 5 deletions src/com/taiter/ce/Enchantments/Bow/Volley.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ private void volley(EntityShootBowEvent e, ItemStack item, int lvl) {
int amount = 1 + 2*lvl; // Keep amount of arrows uneven, 2 extra arrows in a volley per level.

Arrow oldArrow = (Arrow) e.getProjectile();
Vector velocity = oldArrow.getVelocity();
oldArrow.remove(); // Remove original arrow.

int fireTicks = oldArrow.getFireTicks();
int knockbackStrength = oldArrow.getKnockbackStrength();
boolean critical = oldArrow.isCritical();
String metadata = oldArrow.getMetadata("ce.bow.enchantment").get(0).asString();

double angleBetweenArrows = (CONE_DEGREES / (amount-1)) * Math.PI/180;
double pitch = (p.getLocation().getPitch() + 90) * Math.PI / 180;
Expand All @@ -73,11 +74,16 @@ private void volley(EntityShootBowEvent e, ItemStack item, int lvl) {

Arrow arrow = p.launchProjectile(Arrow.class);
arrow.setShooter(p);
// Need to make sure arrow has same speed as original arrow.
arrow.setVelocity(newDir.normalize().multiply(velocity.length()));
arrow.setVelocity(newDir.normalize().multiply(oldArrow.getVelocity().length())); // Need to make sure arrow has same speed as original arrow.
arrow.setFireTicks(fireTicks); // Set the new arrows on fire if the original one was
arrow.setKnockbackStrength(knockbackStrength);
arrow.setCritical(critical);

if(i > 0)
arrow.setMetadata("ce.Volley", new FixedMetadataValue(getPlugin(), null)); //Control metadata to prevent players from duplicating arrows
arrow.setMetadata("ce.bow.enchantment", new FixedMetadataValue(getPlugin(), metadata));
}
oldArrow.remove(); // Remove original arrow.
}

@Override
Expand Down
8 changes: 0 additions & 8 deletions src/com/taiter/ce/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ public final class Main extends JavaPlugin {

public static Boolean createExplosions;

public static Boolean repeatPotionEffects;
public static int repeatDelay;



//The inventories for the Enchantment Menu
public static Inventory CEMainMenu;
Expand Down Expand Up @@ -182,10 +178,6 @@ public void onEnable(){

createExplosions = Boolean.parseBoolean(Main.config.getString("Global.CreateExplosions"));

//The Config options for the potion effect repeating
repeatPotionEffects = Boolean.parseBoolean(Main.config.getString("Global.Enchantments.RepeatPotionEffects"));
repeatDelay = Integer.parseInt(Main.config.getString("Global.Enchantments.RepeatDelay"));

//Get the maximum amount of Enchantments on an Item
maxEnchants = Integer.parseInt(config.getString("Global.Enchantments.MaximumCustomEnchantments"));

Expand Down

0 comments on commit 8f4ed84

Please sign in to comment.