Skip to content

Commit

Permalink
Final fix for the Jarpath problem
Browse files Browse the repository at this point in the history
Fixed an error ocurring when a Minigun was shot without Custom Enchantments on it
Fixed Volley's arrows not inheriting all Custom Enchantments of the original arrow
  • Loading branch information
Taiterio authored and Taiterio committed May 27, 2015
1 parent 8f4ed84 commit bf0da5e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
20 changes: 17 additions & 3 deletions src/com/taiter/ce/CEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.taiter.ce.CBasic.Trigger;
import com.taiter.ce.CItems.CItem;
import com.taiter.ce.Enchantments.CEnchantment;
import com.taiter.ce.Enchantments.Bow.Volley;


/*
Expand Down Expand Up @@ -210,8 +211,7 @@ public static void handleBows(Player toCheck, EntityDamageByEntityEvent e) {
for(String ench : enchantments) {
String[] enchantment = ench.split(" : ");
CEnchantment ce = Tools.getEnchantmentByOriginalname(enchantment[0]);
if(Tools.random.nextDouble()*100 < ce.getOccurrenceChance())
ce.effect(e, toCheck.getItemInHand(), Integer.parseInt(enchantment[1]));
ce.effect(e, toCheck.getItemInHand(), Integer.parseInt(enchantment[1]));
}
e.getDamager().removeMetadata("ce.bow.enchantment", Main.plugin);
}
Expand All @@ -225,6 +225,8 @@ public static void handleEventMain(Player toCheck, ItemStack i, Event e, HashSet

Boolean checkLore = im.hasLore();
Boolean checkName = im.hasDisplayName();

int volleyLevel = -1; //Level to let Volley have its effect after all other bow enchantments

List<String> lore = im.getLore();
String name = im.getDisplayName();
Expand All @@ -246,13 +248,17 @@ public static void handleEventMain(Player toCheck, ItemStack i, Event e, HashSet
if(!ce.getHasCooldown(toCheck))
try {
long time = System.currentTimeMillis();
if(Tools.random.nextInt(100) < ce.getOccurrenceChance()) {
if(Tools.random.nextDouble()*100 <= ce.getOccurrenceChance()) {
//BOWS
if(e instanceof EntityShootBowEvent) {
String enchantments = ce.getOriginalName() + " : " + level;
if(((EntityShootBowEvent) e).getProjectile().hasMetadata("ce.bow.enchantment"))
enchantments += " ; " + ((EntityShootBowEvent) e).getProjectile().getMetadata("ce.bow.enchantment").get(0).asString();
((EntityShootBowEvent) e).getProjectile().setMetadata("ce.bow.enchantment", new FixedMetadataValue(Main.plugin, enchantments));
if(ce instanceof Volley) {
volleyLevel = level;
continue;
}
}
//BOWS

Expand Down Expand Up @@ -318,6 +324,14 @@ public static void handleEventMain(Player toCheck, ItemStack i, Event e, HashSet
}
}
}

if(volleyLevel >= 0) {
for(CBasic cb : list)
if(cb instanceof Volley)
((Volley) cb).effect(e, i, volleyLevel);
}


}
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/com/taiter/ce/CItems/Minigun.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,20 @@ public boolean effect(Event event, final Player player) {
e.setCancelled(true);
addLock(player);


String meta = null;
if(oldArrow.hasMetadata("ce.bow.enchantment"))
meta = oldArrow.getMetadata("ce.bow.enchantment").get(0).asString();


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();

final String metadata = meta;
new BukkitRunnable() {


int lArrows = ArrowCountPerVolley;
ItemStack last = player.getItemInHand();

Expand Down Expand Up @@ -100,7 +107,8 @@ public void run() {
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));
if(metadata != null)
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
24 changes: 18 additions & 6 deletions src/com/taiter/ce/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -490,12 +491,17 @@ private boolean setupEconomy() {

public static void makeLists(boolean finalize, boolean printSuccess) {
long time = System.currentTimeMillis();



//--------------Dynamic enchantment class loading-------------------------------
try {
String path = plugin.getDataFolder().getAbsolutePath() + ".jar";
String path = plugin.getDataFolder().getAbsolutePath();
String classSource = Bukkit.getPluginManager().getPlugin("CustomEnchantments").getClass().getProtectionDomain().getCodeSource().getLocation().getFile();
String seperator = "\\\\";
if(classSource.contains("/"))
seperator = "/";
String[] classSourceSplit = classSource.split(seperator);
path = path.substring(0, path.length() - 18) + classSourceSplit[classSourceSplit.length-1].replace("%20", " ");
JarFile jar = new JarFile(path);
Enumeration<JarEntry> entries = jar.entries();

Expand All @@ -518,10 +524,16 @@ public static void makeLists(boolean finalize, boolean printSuccess) {

jar.close();
} catch (Exception e) {
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[CE] Custom Enchantments could not be loaded,");
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[CE] please report this error on the Bukkit page of the plugin");
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[CE] by sending the following to Taiterio via PM:");
e.printStackTrace();
if(e instanceof FileNotFoundException) {
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[CE] Custom Enchantments could not be started,");
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[CE] please make sure that you the plugins jar");
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[CE] in your plugin folder is named 'CustomEnchantments'.");
} else {
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[CE] Custom Enchantments could not be loaded,");
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[CE] please report this error on the Bukkit page of the plugin");
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[CE] by sending the following to Taiterio via PM:");
e.printStackTrace();
}
plugin.getServer().getPluginManager().disablePlugin(plugin);
return;
}
Expand Down

0 comments on commit bf0da5e

Please sign in to comment.