Skip to content

Commit

Permalink
Version 2.2b
Browse files Browse the repository at this point in the history
	Fixed the checks for duplicate enchantments when buying a new enchantment
	Added a system that limits the maximum amount of iterations that the enchantment handling will do
	Bows can now hold multiple Custom Enchantments at once
	Fixed permission nodes
	Vanilla Enchantments can now be enchanted using /ce ench
	The command /ce change now supports alternative colorcodes
	Fixed Obsidian Shield
	Fixed the unregistering of the Listener

	New Enchantments (Thanks to hetjoshi):
		Revulsion
		Self Destruct
		Aerial
		Charge
  • Loading branch information
Taiterio authored and Taiterio committed Apr 12, 2015
1 parent 6bd3b0c commit 54edd81
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 39 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.2a
version: 2.2b

softdepend: [WorldGuard, WorldEdit, Vault]

Expand Down
10 changes: 9 additions & 1 deletion src/com/taiter/ce/CEListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
Expand Down Expand Up @@ -206,7 +207,7 @@ public void inventoryMenu(final InventoryClickEvent event) {
int number = 0;
for(String s : lore) {
CEnchantment c = Tools.getEnchantmentByDisplayname(s);
if(c != null && Tools.checkForEnchantment(s, c)) {
if(c != null && c.originalName == ce.originalName) {
p.sendMessage(ChatColor.RED + "[CE] This item already has this enchantment!");
return;
}
Expand Down Expand Up @@ -587,6 +588,13 @@ public void PlayerInteractEntityEvent(PlayerInteractEntityEvent e) {
CEventHandler.handleEvent(e.getPlayer(), e, interactE);

}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void PlayerDeathEvent(PlayerDeathEvent e) {

CEventHandler.handleEvent(e.getEntity(), e, death);

}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void PlayerMoveEvent(PlayerMoveEvent e) {
Expand Down
27 changes: 19 additions & 8 deletions src/com/taiter/ce/CEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,16 @@ public static void handleEnchanting(EnchantItemEvent e) {
lore = im.getLore();

int numberOfEnchantments = Tools.random.nextInt(4) + 1;
int maxTries = 10;
int appliedEnchantments = 0;

if(Main.maxEnchants < numberOfEnchantments)
numberOfEnchantments = Main.maxEnchants;

if(list.size() < numberOfEnchantments)
numberOfEnchantments = list.size();

while(numberOfEnchantments > 0) {
while(numberOfEnchantments > 0 && maxTries >= 0) {
for(CEnchantment ce : list) {
if(numberOfEnchantments <= 0)
break;
Expand All @@ -106,14 +108,17 @@ else if(Tools.random.nextInt(100) < ce.getEnchantProbability()) {
}

lore.add(ce.getDisplayName() + " " + Tools.intToLevel(Tools.random.nextInt(ce.getEnchantmentMaxLevel()-1)+1));
appliedEnchantments++;
numberOfEnchantments--;

}


}
maxTries--;
}

if(appliedEnchantments == 0)
return;

im.setLore(lore);
i.setItemMeta(im);

Expand Down Expand Up @@ -169,10 +174,12 @@ public static void handleBows(Player toCheck, EntityDamageByEntityEvent e) {
}

if(e.getDamager().hasMetadata("ce.bow.enchantment")) {

String[] enchantment = e.getDamager().getMetadata("ce.bow.enchantment").get(0).asString().split(" : ");
String[] enchantments = e.getDamager().getMetadata("ce.bow.enchantment").get(0).asString().split(" ; ");
for(String ench : enchantments) {
String[] enchantment = ench.split(" : ");

Tools.getEnchantmentByOriginalname(enchantment[0]).effect(e, toCheck.getItemInHand(), Integer.parseInt(enchantment[1]));
Tools.getEnchantmentByOriginalname(enchantment[0]).effect(e, toCheck.getItemInHand(), Integer.parseInt(enchantment[1]));
}
e.getDamager().removeMetadata("ce.bow.enchantment", Main.plugin);
}
}
Expand Down Expand Up @@ -205,8 +212,12 @@ private static void handleEventMain(Player toCheck, ItemStack i, Event e, HashSe
if(!ce.lockList.contains(toCheck))
if(!ce.getHasCooldown(toCheck))
try {
if(e instanceof EntityShootBowEvent)
((EntityShootBowEvent) e).getProjectile().setMetadata("ce.bow.enchantment", new FixedMetadataValue(Main.plugin, ce.getOriginalName() + " : " + level));
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));
}
long time = System.currentTimeMillis();
if(Tools.random.nextInt(100) < ce.getOccurrenceChance())
ce.effect(e, i, level);
Expand Down
51 changes: 38 additions & 13 deletions src/com/taiter/ce/CeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public String processCommand(CommandSender sender, String[] args) {
String Error = ChatColor.RED + "[CE] ";
String usageError = Error + "Correct Usage: /ce ";

String node = "ce.cmd.*";
String requiredPermission = "ce.cmd.";


Expand All @@ -64,7 +65,7 @@ public String processCommand(CommandSender sender, String[] args) {
if(name.startsWith("r")) {

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


Expand Down Expand Up @@ -152,7 +153,7 @@ public void run() {
if(args.length >= 4) {

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

Player target = null;
Expand Down Expand Up @@ -516,7 +517,7 @@ public void run() {

} else if(name.startsWith("m")) {
requiredPermission += "menu";
if(!sender.hasPermission(requiredPermission) && !sender.isOp())
if(!sender.hasPermission(node) && !sender.hasPermission(requiredPermission) && !sender.isOp())
return Error + "You do not have permission to use this command.";
Tools.openCEMenu(p);
return "";
Expand All @@ -531,7 +532,7 @@ public void run() {
if(args.length >= 2) {

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

String customName = args[1];
Expand Down Expand Up @@ -568,8 +569,23 @@ public void run() {
custom = ci;
}
if(custom == null) {
Enchantment ench = null;
try {
ench = Enchantment.getById(Integer.parseInt(customName));
} catch (Exception e) {
try {
ench = Enchantment.getByName(customName);
} catch(Exception ex) {}
}

if(ench != null) {
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;

}

if(!Tools.checkPermission(custom, p)) {
Expand Down Expand Up @@ -670,7 +686,7 @@ public void run() {
if(args.length >= 4) {

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

String toChange = args[1].toLowerCase();
Expand All @@ -690,6 +706,8 @@ public void run() {
}

toSet += args[args.length - 1];

toSet = ChatColor.translateAlternateColorCodes('&', toSet);

im.setDisplayName(toSet);
item.setItemMeta(im);
Expand All @@ -700,16 +718,23 @@ public void run() {
if(item.hasItemMeta() && im.hasDisplayName()) {

if(option.startsWith("c")) {

if(ChatColor.valueOf(args[3].toUpperCase()) != null) {

im.setDisplayName(ChatColor.valueOf(args[3].toUpperCase()) + "" + ChatColor.stripColor(im.getDisplayName()));
item.setItemMeta(im);
return Success + "You have successfully changed the item's Color!";


String test = args[3].toUpperCase();
try {
test = ChatColor.valueOf(test) + "";
} catch (IllegalArgumentException e) {
if(test.contains("&"))
test = ChatColor.translateAlternateColorCodes('&', test);
else
return Error + "The Color " + args[3] + " could not be found.";
}

im.setDisplayName(test + ChatColor.stripColor(im.getDisplayName()));
item.setItemMeta(im);
return Success + "You have successfully changed the item's Color!";

return Error + "The Color " + args[3] + " could not be found.";



} else if(option.startsWith("a")) {

Expand Down
2 changes: 1 addition & 1 deletion src/com/taiter/ce/Enchantments/Armor/ObsidianShield.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ObsidianShield extends CEnchantment {

public ObsidianShield(String originalName, Application app, int enchantProbability, int occurrenceChance) {
super(originalName, app, enchantProbability, occurrenceChance);
triggers.add(Trigger.DAMAGE_TAKEN);
triggers.add(Trigger.MOVE);
}

@Override
Expand Down
59 changes: 59 additions & 0 deletions src/com/taiter/ce/Enchantments/Armor/Revulsion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.taiter.ce.Enchantments.Armor;

/*
* 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.entity.LivingEntity;
import org.bukkit.event.Event;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import com.taiter.ce.Enchantments.CEnchantment;



public class Revulsion extends CEnchantment {

int duration;

public Revulsion(String originalName, Application app, int enchantProbability, int occurrenceChance) {
super(originalName, app, enchantProbability, occurrenceChance);
configEntries.add("Duration: 20");
triggers.add(Trigger.DAMAGE_TAKEN);
}

@Override
public void effect(Event e, ItemStack item, int level) {
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
LivingEntity target = (LivingEntity) event.getDamager();
target.addPotionEffect(
new PotionEffect(
PotionEffectType.CONFUSION,
duration * level, //This value is counted in ticks, 1/20 of a second
0));
}

@Override
public void initConfigEntries() {
duration = Integer.parseInt(getConfig().getString("Enchantments." + getOriginalName() + ".Duration"));
}
}
63 changes: 63 additions & 0 deletions src/com/taiter/ce/Enchantments/Armor/SelfDestruct.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.taiter.ce.Enchantments.Armor;

/*
* 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.entity.EntityType;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.Event;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector;

import com.taiter.ce.Main;
import com.taiter.ce.Tools;
import com.taiter.ce.Enchantments.CEnchantment;



public class SelfDestruct extends CEnchantment {

int delay;

public SelfDestruct(String originalName, Application app, int enchantProbability, int occurrenceChance) {
super(originalName, app, enchantProbability, occurrenceChance);
triggers.add(Trigger.DEATH);
this.configEntries.add("ExplosionDelay: 40");
}

@Override
public void effect(Event e, ItemStack item, int level) {
PlayerDeathEvent event = (PlayerDeathEvent) e;
for(int i = level; i >= 0; i--) {
TNTPrimed tnt = (TNTPrimed) event.getEntity().getWorld().spawnEntity(event.getEntity().getLocation(), EntityType.PRIMED_TNT);
tnt.setFuseTicks(delay);
tnt.setVelocity(new Vector(Tools.random.nextDouble()*1.5 - 1, Tools.random.nextDouble() * 1.5, Tools.random.nextDouble()*1.5 - 1));
if(!Main.createExplosions)
tnt.setMetadata("ce.explosive", new FixedMetadataValue(getPlugin(), null));
}
}

@Override
public void initConfigEntries() {
delay = Integer.parseInt(getConfig().getString("Enchantments." + getOriginalName() + ".ExplosionDelay"));
}
}
Loading

0 comments on commit 54edd81

Please sign in to comment.