Skip to content

Commit

Permalink
Version 2.2
Browse files Browse the repository at this point in the history
 Framework-update
  Improved the usage of the event lists
  Expanded Triggers
 Feature updates
  2 New Items
    Firecrackers
	Firework-Batteries
  Enchantments can now be sold through signs
  Explosions can now be blocked globally by setting "Global.CreateExplosions" to false in the config
  • Loading branch information
Taiterio authored and Taiterio committed Feb 19, 2015
1 parent 5359b77 commit e26aa1f
Show file tree
Hide file tree
Showing 64 changed files with 744 additions and 287 deletions.
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Global:
CreateExplosions: true
Updates:
ShowPercentageOnUpdate: true
CheckOnStartup: true
Expand Down
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.1g
version: 2.2

softdepend: [WorldGuard, WorldEdit, Vault]

Expand Down
13 changes: 9 additions & 4 deletions src/com/taiter/ce/CBasic.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ static public enum Trigger {
INTERACT_RIGHT,
MOVE,
DAMAGE_GIVEN,
DAMAGE_RECEIVED,
DAMAGE_TAKEN,
DAMAGE_NATURE, //Falldamage, damage by cactus, etc.
BLOCK_PLACED,
BLOCK_BROKEN,
SHOOT_BOW,
THROW,
PROJECTILE_THROWN,
PROJECTILE_HIT,
EQUIP_ITEM,
DEATH
}

Expand All @@ -69,10 +72,12 @@ static public enum Trigger {
public String getDisplayName() { return this.displayName; }

public String getOriginalName() { return this.originalName; }

public HashSet<Trigger> getTriggers() { return this.triggers; }

public FileConfiguration getConfig() { return Main.config; }
public FileConfiguration getConfig() { return Main.config; }

public String getType() { return this.typeString; }
public String getType() { return this.typeString; }

public abstract double getCost();

Expand Down
194 changes: 169 additions & 25 deletions src/com/taiter/ce/CEListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@


import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

import net.milkbowl.vault.economy.EconomyResponse;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
Expand All @@ -42,11 +44,14 @@
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCreativeEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
Expand All @@ -59,22 +64,30 @@
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;

import com.taiter.ce.CItems.CItem;
import com.taiter.ce.Enchantments.CEnchantment;
import com.taiter.ce.Enchantments.CEnchantment.Application;


public class CEListener implements Listener {


List<CEnchantment> moveEnchantments = new ArrayList<CEnchantment>();
List<CEnchantment> clickEnchantments = new ArrayList<CEnchantment>();
List<CEnchantment> interactEnchantments = new ArrayList<CEnchantment>();
List<CEnchantment> damageTakenEnchantments = new ArrayList<CEnchantment>();
List<CEnchantment> damageGivenEnchantments = new ArrayList<CEnchantment>();
List<CEnchantment> bowEnchantments = new ArrayList<CEnchantment>();
List<CEnchantment> deathEnchantments = new ArrayList<CEnchantment>();
List<CEnchantment> blockPlaceEnchantments = new ArrayList<CEnchantment>();
List<CEnchantment> blockBreakEnchantments = new ArrayList<CEnchantment>();
HashSet<CBasic> move = new HashSet<CBasic>();
HashSet<CBasic> interact = new HashSet<CBasic>();
HashSet<CBasic> interactE = new HashSet<CBasic>();
HashSet<CBasic> interactR = new HashSet<CBasic>();
HashSet<CBasic> interactL = new HashSet<CBasic>();
HashSet<CBasic> damageTaken = new HashSet<CBasic>();
HashSet<CBasic> damageGiven = new HashSet<CBasic>();
HashSet<CBasic> damageNature = new HashSet<CBasic>();
HashSet<CBasic> shootBow = new HashSet<CBasic>();
HashSet<CBasic> projectileThrow = new HashSet<CBasic>();
HashSet<CBasic> projectileHit = new HashSet<CBasic>();
HashSet<CBasic> death = new HashSet<CBasic>();
HashSet<CBasic> blockPlaced = new HashSet<CBasic>();
HashSet<CBasic> blockBroken = new HashSet<CBasic>();
HashSet<CBasic> equipItem = new HashSet<CBasic>();



/*
Expand Down Expand Up @@ -260,8 +273,8 @@ public void inventoryMenu(final InventoryClickEvent event) {
if(ecr.transactionSuccess())
successString = (ChatColor.GREEN + "[CE] Purchased " + type + ChatColor.GREEN + " for " + cost + " " + ((cost == 1) ? Main.econ.currencyNameSingular() : Main.econ.currencyNamePlural()));
else {
p.sendMessage(ChatColor.RED + "[CE] An economy error has occured:");
p.sendMessage(ChatColor.RED + ecr.errorMessage);
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[CE] An economy error has occured:");
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + ecr.errorMessage);
p.closeInventory();
return;
}
Expand Down Expand Up @@ -343,9 +356,9 @@ public void EntityDamageByEntityEvent(EntityDamageByEntityEvent e) {


if(damaged instanceof Player)
CEventHandler.handleEvent((Player) damaged, e, damageTakenEnchantments);
CEventHandler.handleEvent((Player) damaged, e, damageTaken);
if(damager instanceof Player)
CEventHandler.handleEvent((Player) damager, e, damageGivenEnchantments);
CEventHandler.handleEvent((Player) damager, e, damageGiven);
else if(damager instanceof Arrow)
if(damager.hasMetadata("ce.bow.item") || damager.hasMetadata("ce.bow.enchantment"))
CEventHandler.handleBows((Player) ((Projectile) damager).getShooter(), e);
Expand All @@ -362,7 +375,7 @@ public void EntityDamageEvent(EntityDamageEvent e) {

if(damaged instanceof Player) {

CEventHandler.handleEvent((Player) damaged, e, damageTakenEnchantments);
CEventHandler.handleEvent((Player) damaged, e, damageNature);

if(damaged.hasMetadata("ce.springs")) {
e.setCancelled(true);
Expand All @@ -376,19 +389,39 @@ public void EntityDamageEvent(EntityDamageEvent e) {

}


@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void EntityExplodeEvent(EntityExplodeEvent e) {

if(e.getEntity() != null && e.getEntity().hasMetadata("ce.explosive")) {
e.getEntity().remove();
e.setCancelled(true);
}

}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void EntityShootBowEvent(EntityShootBowEvent e) {

Entity shooter = e.getEntity();

if(shooter instanceof Player)
CEventHandler.handleEvent((Player) shooter, e, bowEnchantments);

CEventHandler.handleEvent((Player) shooter, e, shootBow);
}


@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void ProjectileHitEvent(ProjectileHitEvent e) {

ProjectileSource shooter = e.getEntity().getShooter();

if(shooter instanceof Player) {
if(e.getEntity().hasMetadata("ce.projectile.item")) {
CItem ci = Tools.getItemByOriginalname(e.getEntity().getMetadata("ce.projectile.item").get(0).asString());
if(ci != null)
ci.effect(e, (Player) shooter);
}
}
}


//PLAYER: org.bukkit.event.player

Expand All @@ -399,21 +432,132 @@ public void EntityShootBowEvent(EntityShootBowEvent e) {
//
// }

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void ProjectileLaunchEvent(ProjectileLaunchEvent e) {

ProjectileSource shooter = e.getEntity().getShooter();

if(shooter instanceof Player)
CEventHandler.handleEvent((Player) shooter, e, projectileThrow);

}

@EventHandler(priority = EventPriority.HIGHEST)
public void SignChangeEvent(SignChangeEvent e) {
if(e.getLine(0).equals("[CustomEnchant]") && !e.getPlayer().isOp())
e.setCancelled(true);
}

@EventHandler(priority = EventPriority.HIGHEST)
public void PlayerInteractEvent(PlayerInteractEvent e) {

CEventHandler.handleEvent(e.getPlayer(), e, clickEnchantments);
CEventHandler.handleEvent(e.getPlayer(), e, interact);

if(e.getAction().toString().startsWith("LEFT"))
CEventHandler.handleEvent(e.getPlayer(), e, interactL);
else if(e.getAction().toString().startsWith("RIGHT"))
CEventHandler.handleEvent(e.getPlayer(), e, interactR);

if(e.getClickedBlock() != null && e.getClickedBlock() instanceof Sign)
if(((Sign) e.getClickedBlock()).getLine(0).equals("[CustomEnchant]"))
Tools.openCEMenu(e.getPlayer());
if(((Sign) e.getClickedBlock()).getLine(0).equals("[CustomEnchant]")) {
Player p = e.getPlayer();
if(!Main.hasEconomy) {
p.performCommand("/ce menu");
} else if(p.getItemInHand().getType() != Material.AIR){
Sign sign = ((Sign) e.getClickedBlock());
CEnchantment ce = Tools.getEnchantmentByDisplayname(sign.getLine(1));
if(ce == null)
Tools.getEnchantmentByOriginalname(sign.getLine(1));
if(ce == null)
for(CEnchantment ceT : Main.enchantments)
if(Tools.checkForEnchantment(sign.getLine(1), ceT))
ce = ceT;
if(ce == null)
return;

ItemStack inHand = p.getItemInHand();
if(!Tools.isApplicable(inHand, ce)) {
p.sendMessage(ChatColor.RED + "[CE] This enchantment can not be applied to this item.");
return;
}

int cost = 0;
try {
cost = Integer.parseInt(sign.getLine(3).replaceAll("\\D+",""));
} catch(NumberFormatException ex) {
return;
}

if(inHand.hasItemMeta() && inHand.getItemMeta().hasLore()) {
List<String> lore = inHand.getItemMeta().getLore();
for(int i = 0; i < lore.size(); i++)
if(Tools.checkForEnchantment(lore.get(i), ce)) {
int newLevel = Tools.getLevel(lore.get(i))+1;
if(newLevel <= ce.getEnchantmentMaxLevel()) {
if(Main.econ.getBalance(p.getName()) >= cost) {
EconomyResponse ecr = Main.econ.withdrawPlayer(p.getName(), cost);
if(ecr.transactionSuccess())
p.sendMessage(ChatColor.GREEN + "[CE] Upgraded enchantment " + ce.getDisplayName() + ChatColor.RESET + "" + ChatColor.GREEN + " for " + cost + " " + ((cost == 1) ? Main.econ.currencyNameSingular() : Main.econ.currencyNamePlural()));
else {
p.sendMessage(ChatColor.RED + "[CE] An economy error has occured:");
p.sendMessage(ChatColor.RED + ecr.errorMessage);
p.closeInventory();
return;
}
} else {
p.sendMessage(ChatColor.RED + "[CE] You do not have enough money to buy this!");
p.closeInventory();
return;
}
lore.set(i, ce.getDisplayName() + " " + Tools.intToLevel(newLevel));
ItemMeta im = inHand.getItemMeta();
im.setLore(lore);
inHand.setItemMeta(im);
return;
} else {
p.sendMessage(ChatColor.RED + "[CE] You already have the maximum level of this enchantment!");
return;
}
}
}

List<String> lore = new ArrayList<String>();
ItemMeta im = inHand.getItemMeta();

if(inHand.getItemMeta().hasLore())
lore = im.getLore();

if(Main.econ.getBalance(p.getName()) >= cost) {
EconomyResponse ecr = Main.econ.withdrawPlayer(p.getName(), cost);
if(ecr.transactionSuccess())
p.sendMessage(ChatColor.GREEN + "[CE] Bought enchantment " + ce.getDisplayName() + ChatColor.RESET + "" + ChatColor.GREEN + " for " + cost + " " + ((cost == 1) ? Main.econ.currencyNameSingular() : Main.econ.currencyNamePlural()));
else {
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "[CE] An economy error has occured:");
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + ecr.errorMessage);
p.closeInventory();
return;
}
} else {
p.sendMessage(ChatColor.RED + "[CE] You do not have enough money to buy this!");
p.closeInventory();
return;
}

lore.add(ce.getDisplayName() + " I");
im.setLore(lore);
inHand.setItemMeta(im);
return;


}
}

}

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

CEventHandler.handleEvent(e.getPlayer(), e, interactEnchantments);
CEventHandler.handleEvent(e.getPlayer(), e, interactE);

}

Expand All @@ -429,7 +573,7 @@ public void PlayerMoveEvent(PlayerMoveEvent e) {

if(from.getBlockX() != to.getBlockX() || from.getBlockY() != to.getBlockY() || from.getBlockZ() != to.getBlockZ() ) {

CEventHandler.handleEvent(e.getPlayer(), e, moveEnchantments);
CEventHandler.handleEvent(e.getPlayer(), e, move);
CEventHandler.handleMines(e.getPlayer(), e);

}
Expand All @@ -444,7 +588,7 @@ public void PlayerMoveEvent(PlayerMoveEvent e) {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void BlockPlaceEvent(BlockPlaceEvent e) {

CEventHandler.handleEvent(e.getPlayer(), e, blockPlaceEnchantments);
CEventHandler.handleEvent(e.getPlayer(), e, blockPlaced);

}

Expand All @@ -455,7 +599,7 @@ public void BlockBreakEvent(BlockBreakEvent e) {
if(e.getBlock().hasMetadata("ce.Ice"))
e.setCancelled(true);

CEventHandler.handleEvent(e.getPlayer(), e, blockBreakEnchantments);
CEventHandler.handleEvent(e.getPlayer(), e, blockBroken);
if(e.getBlock().hasMetadata("ce.mine")) {
Block b = e.getBlock();
b.removeMetadata("ce.mine", Main.plugin);
Expand Down
Loading

0 comments on commit e26aa1f

Please sign in to comment.