Fixes to some WorldShop issues and behaviors.

This commit is contained in:
sigonasr2 2016-07-08 17:00:05 -05:00
parent 88c21c17c2
commit 7cecc25c05
6 changed files with 146 additions and 23 deletions

Binary file not shown.

View File

@ -1,6 +1,6 @@
name: TwosideKeeper name: TwosideKeeper
main: sig.plugin.TwosideKeeper.TwosideKeeper main: sig.plugin.TwosideKeeper.TwosideKeeper
version: 3.4.7d1 version: 3.4.7e
commands: commands:
money: money:
description: Tells the player the amount of money they are holding. description: Tells the player the amount of money they are holding.

View File

@ -0,0 +1,68 @@
package sig.plugin.TwosideKeeper.HelperStructures;
import java.text.DecimalFormat;
import org.bukkit.ChatColor;
public enum ArtifactAbility {
//Enum Structure:
// "Friendly Name", "Description", base value (per point) (-1 means it's a TEMPORARY ability.), decay value (per point), max level, level requirement (The min level required to get this perk)
//Temporary abilities: Work for 1 level and wear off afterward.
//Weapon Abilities
DAMAGE("Strike","Improves Base Damage by [VAL]",1.0,1.0,100),
ARMOR_PEN("Piercing","[VAL]% of your damage is ignored by resistances. ([PENDMG] damage)",1.0,1.0,100,1),
EXECUTION("Execute","Deals [VAL] extra damage for every 20% of target's missing health.",2.0,1.0,100,1),
LIFESTEAL("Lifesteal","Heals [VAL]% of the damage dealt to targets back to your health pool.",1.0,1.0,100,1),
//Armor abilities
DAMAGE_REDUCTION("Defense","Increases Base Damage reduction by [VAL]%",1.0,2.0,100,1),
HEALTH("Health","Increases Maximum Health by [VAL].",1.0,1.0,100,1),
HEALTH_REGEN("Regeneration","Regenerates an extra [VAL] health every 5 seconds.",0.5,1.0,100,1),
STATUS_EFFECT_RESISTANCE("Resistance","When a debuff is applied",0.5,1.0,100,1),
SURVIVOR("Survivor","Taking fatal damage will not kill you and instead consume this ability, removes all debuffs, and leaving you with 1 HP.",-1,0,1,10),
;
String name;
String desc;
double baseval;
double decayval;
int maxlv;
ArtifactAbility(String name, String desc, double baseval, double decayval, int maxlv) {
this.name=name;
this.desc=desc;
this.baseval=baseval;
this.decayval=decayval;
this.maxlv=maxlv;
}
public double calculateValue(int lv) {
double sum=0;
for(int i=0;i<lv;i++){
sum+=1/(1+this.decayval*i);
}
return sum*this.baseval;
}
public String displayDescription(int lv, double playerdmgval) { //Level to display information for.
String msg = this.desc;
DecimalFormat df = new DecimalFormat("0.00");
msg.replace("[VAL]", df.format(calculateValue(lv)));
msg.replace("[PENDMG]", df.format(calculateValue(lv)/100*playerdmgval)); //Based on multiplying [VAL] by the base damage value.
return msg;
}
public String displayDescriptionUpgrade(int fromlv, int tolv, double playerdmgval) { //Level to display information for.
String msg = this.desc;
DecimalFormat df = new DecimalFormat("0.00");
msg.replace("[VAL]", DisplayChangedValue(df.format(calculateValue(fromlv)),df.format(calculateValue(tolv))));
msg.replace("[PENDMG]", DisplayChangedValue(df.format(calculateValue(fromlv)/100*playerdmgval),df.format(calculateValue(tolv)/100*playerdmgval))); //Based on multiplying [VAL] by the base damage value.
return msg;
}
String DisplayChangedValue(String val1,String val2) {
return ChatColor.DARK_GRAY+""+ChatColor.STRIKETHROUGH+val1+ChatColor.RESET+ChatColor.GREEN+val2+ChatColor.DARK_GREEN+ChatColor.BOLD+"^"+ChatColor.RESET;
}
}

View File

@ -6,27 +6,32 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import sig.plugin.TwosideKeeper.TwosideKeeper;
import sig.plugin.TwosideKeeper.WorldShopManager;
import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions; import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions;
public class ShopPurchase { public class ShopPurchase {
String player; String player;
String customer; String customer;
String itemname; int shopID;
double money; double money;
int amt; int amt;
boolean sell; boolean sell;
public ShopPurchase(String p, Player customer, ItemStack item, double money, int amt) { public ShopPurchase(String p, Player customer, int shopID, double money, int amt) {
ShopPurchase(p,customer,item,money,amt,true); //Assume this is a selling purchase by default. ShopPurchase(p,customer,shopID,money,amt,true); //Assume this is a selling purchase by default.
} }
public ShopPurchase(String p, Player customer, ItemStack item, double money, int amt, boolean sell) { public ShopPurchase(String p, Player customer, int shopID, double money, int amt, boolean sell) {
ShopPurchase(p,customer,item,money,amt,sell); //Assume this is a selling purchase by default. ShopPurchase(p,customer,shopID,money,amt,sell); //Assume this is a selling purchase by default.
} }
public void ShopPurchase(String p, Player customer, ItemStack item, double money, int amt, boolean sell) { public void ShopPurchase(String p, Player customer, int shopID, double money, int amt, boolean sell) {
player = p; this.player = p;
this.customer=customer.getName(); this.customer=customer.getName();
itemname = GenericFunctions.GetItemName(item); this.shopID = shopID;
this.money = money; this.money = money;
this.amt=amt; this.amt=amt;
this.sell=sell; this.sell=sell;
@ -39,12 +44,28 @@ public class ShopPurchase {
return customer; return customer;
} }
public String announcementString() { public TextComponent announcementString() {
DecimalFormat df = new DecimalFormat("0.00"); DecimalFormat df = new DecimalFormat("0.00");
if (sell) { if (sell) {
return "Player "+ChatColor.BLUE+customer+ChatColor.WHITE+" has purchased "+ChatColor.YELLOW+amt+ChatColor.WHITE+" of your "+ChatColor.YELLOW+itemname+". You have earned $"+df.format(money)+". "+ChatColor.GRAY+""+ChatColor.ITALIC+"(See /money)"; WorldShop ss = TwosideKeeper.TwosideShops.LoadWorldShopData(shopID);
TextComponent message1 = new TextComponent("Player "+ChatColor.BLUE+customer+ChatColor.WHITE+" has purchased "+ChatColor.YELLOW+amt+ChatColor.WHITE+" of your ");
TextComponent message2 = new TextComponent(ChatColor.GREEN+"["+GenericFunctions.GetItemName(ss.GetItem())+ChatColor.RESET+""+ChatColor.GREEN+"]");
message2.setHoverEvent(new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(GenericFunctions.GetItemName(ss.GetItem())+WorldShop.GetItemInfo(ss.GetItem())).create()));
TextComponent message3 = new TextComponent(". You have earned $"+df.format(money)+". "+ChatColor.GRAY+""+ChatColor.ITALIC+"(See /money)");
TextComponent finalmsg = message1;
finalmsg.addExtra(message2);
finalmsg.addExtra(message3);
return finalmsg;
} else { } else {
return "Player "+ChatColor.BLUE+customer+ChatColor.WHITE+" has sold "+ChatColor.YELLOW+amt+ChatColor.WHITE+" "+ChatColor.YELLOW+itemname+" to you. $"+df.format(money)+" has been deducted from your bank account. "+ChatColor.GRAY+""+ChatColor.ITALIC+"(Check your shop to collect your items.)"; WorldShop ss = TwosideKeeper.TwosideShops.LoadWorldShopData(shopID);
TextComponent message1 = new TextComponent("Player "+ChatColor.BLUE+customer+ChatColor.WHITE+" has sold "+ChatColor.YELLOW+amt+ChatColor.WHITE+" ");
TextComponent message2 = new TextComponent(ChatColor.GREEN+"["+GenericFunctions.GetItemName(ss.GetItem())+ChatColor.RESET+""+ChatColor.GREEN+"]");
message2.setHoverEvent(new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(GenericFunctions.GetItemName(ss.GetItem())+WorldShop.GetItemInfo(ss.GetItem())).create()));
TextComponent message3 = new TextComponent(" to you. $"+df.format(money)+" has been deducted from your bank account. "+ChatColor.GRAY+""+ChatColor.ITALIC+"(Check your shop to collect your items.)");
TextComponent finalmsg = message1;
finalmsg.addExtra(message2);
finalmsg.addExtra(message3);
return finalmsg;
} }
} }
} }

View File

@ -1343,7 +1343,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
TwosideShops.SaveWorldShopData(shop); TwosideShops.SaveWorldShopData(shop);
TwosideShops.RemoveSession(ev.getPlayer()); TwosideShops.RemoveSession(ev.getPlayer());
givePlayerMoney(ev.getPlayer(), -amt*shop.GetUnitPrice()); givePlayerMoney(ev.getPlayer(), -amt*shop.GetUnitPrice());
TwosideShops.AddNewPurchase(shop.GetOwner(), ev.getPlayer(), shop.GetItem(), amt*shop.GetUnitPrice(), amt); TwosideShops.AddNewPurchase(shop.GetOwner(), ev.getPlayer(), shop.getID(), amt*shop.GetUnitPrice(), amt);
if (Bukkit.getPlayer(shop.GetOwner())!=null) { if (Bukkit.getPlayer(shop.GetOwner())!=null) {
givePlayerMoney(Bukkit.getPlayer(shop.GetOwner()), amt*shop.GetUnitPrice()); givePlayerMoney(Bukkit.getPlayer(shop.GetOwner()), amt*shop.GetUnitPrice());
} else { } else {
@ -1401,7 +1401,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
TwosideShops.RemoveSession(ev.getPlayer()); TwosideShops.RemoveSession(ev.getPlayer());
givePlayerMoney(ev.getPlayer(), amt*shop.GetUnitPrice()); givePlayerMoney(ev.getPlayer(), amt*shop.GetUnitPrice());
givePlayerBankMoney(shop.GetOwner(), -amt*shop.GetUnitPrice()); givePlayerBankMoney(shop.GetOwner(), -amt*shop.GetUnitPrice());
TwosideShops.AddNewPurchase(shop.GetOwner(), ev.getPlayer(), shop.GetItem(), amt*shop.GetUnitPrice(), amt, false); TwosideShops.AddNewPurchase(shop.GetOwner(), ev.getPlayer(), shop.getID(), amt*shop.GetUnitPrice(), amt, false);
} else { } else {
ev.getPlayer().sendMessage(ChatColor.LIGHT_PURPLE+shop.GetOwner()+ChatColor.WHITE+" only has enough money in their bank to buy "+ChatColor.GREEN+(int)(getPlayerBankMoney(shop.GetOwner())/shop.GetUnitPrice())+ChatColor.WHITE+" of "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+"! Please try again."); ev.getPlayer().sendMessage(ChatColor.LIGHT_PURPLE+shop.GetOwner()+ChatColor.WHITE+" only has enough money in their bank to buy "+ChatColor.GREEN+(int)(getPlayerBankMoney(shop.GetOwner())/shop.GetUnitPrice())+ChatColor.WHITE+" of "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+"! Please try again.");
} }
@ -1885,12 +1885,12 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
TwosideShops.AddSession(SessionState.BUY_UPDATE, player, s); TwosideShops.AddSession(SessionState.BUY_UPDATE, player, s);
} else { } else {
if (shop.GetAmount()>0) { if (shop.GetAmount()>0) {
//player.sendMessage("How many "+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+" would you like to sell? "+ChatColor.GREEN+"(MAX: "+(shop.GetUnitPrice()*GenericFunctions.CountItems(player, shop.GetItem())<=getPlayerBankMoney(shop.GetOwner())?((GenericFunctions.CountItems(player, shop.GetItem())<=shop.GetAmount())?(GenericFunctions.CountItems(player, shop.GetItem())):shop.GetAmount()):(int)(getPlayerBankMoney(shop.GetOwner())/shop.GetUnitPrice()))+")"); //player.sendMessage(+ChatColor.GREEN+shop.GetItemName()+ChatColor.WHITE+);
TextComponent message1 = new TextComponent("Creating a shop to buy "); TextComponent message1 = new TextComponent("How many ");
TextComponent message2 = new TextComponent(ChatColor.GREEN+"["+shop.GetItemName()+ChatColor.RESET+""+ChatColor.GREEN+"]"); TextComponent message2 = new TextComponent(ChatColor.GREEN+"["+shop.GetItemName()+ChatColor.RESET+""+ChatColor.GREEN+"]");
message2.setHoverEvent(new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(shop.GetItemName()+WorldShop.GetItemInfo(shop.GetItem())).create())); message2.setHoverEvent(new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(shop.GetItemName()+WorldShop.GetItemInfo(shop.GetItem())).create()));
TextComponent message3 = new TextComponent("."); TextComponent message3 = new TextComponent(" would you like to sell? "+ChatColor.GREEN+"(MAX: "+(shop.GetUnitPrice()*GenericFunctions.CountItems(player, shop.GetItem())<=getPlayerBankMoney(shop.GetOwner())?((GenericFunctions.CountItems(player, shop.GetItem())<=shop.GetAmount())?(GenericFunctions.CountItems(player, shop.GetItem())):shop.GetAmount()):(int)(getPlayerBankMoney(shop.GetOwner())/shop.GetUnitPrice()))+")");
TextComponent finalmsg = message1; TextComponent finalmsg = message1;
finalmsg.addExtra(message2); finalmsg.addExtra(message2);
finalmsg.addExtra(message3); finalmsg.addExtra(message3);
@ -1898,7 +1898,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
//Initiate buying session. //Initiate buying session.
TwosideShops.AddSession(SessionState.SELL, player, s); TwosideShops.AddSession(SessionState.SELL, player, s);
log("Added a shop session for "+player.getName()+".",4); log("Added a shop session for "+player.getName()+".",4);
shop.sendItemInfo(player); //shop.sendItemInfo(player);
} else { } else {
player.sendMessage(ChatColor.GOLD+"Sorry! "+ChatColor.WHITE+"This shop is not buying anymore items! "+ChatColor.LIGHT_PURPLE+shop.GetOwner()+ChatColor.WHITE+" needs to edit the shop!"); player.sendMessage(ChatColor.GOLD+"Sorry! "+ChatColor.WHITE+"This shop is not buying anymore items! "+ChatColor.LIGHT_PURPLE+shop.GetOwner()+ChatColor.WHITE+" needs to edit the shop!");
} }
@ -1997,6 +1997,27 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
TwosideSpleefGames.PassEvent(ev); TwosideSpleefGames.PassEvent(ev);
if (ev.getBlockPlaced().getType()==Material.CHEST ||
ev.getBlockPlaced().getType()==Material.TRAPPED_CHEST) {
//Check for a chest or trapped chest around each side of the block.
for (int x=-1;x<2;x++) {
for (int z=-1;z<2;z++) {
if ((x!=0)^(z!=0) && ev.getBlockPlaced().getLocation().add(x,0,z).getBlock().getType()==ev.getBlockPlaced().getType()) {
//This is the same type of block. Make sure there's no shop sign attached to it.
if (WorldShop.hasShopSignAttached(ev.getBlockPlaced().getLocation().add(x,0,z).getBlock())) {
Sign s = WorldShop.grabShopSign(ev.getBlockPlaced().getLocation().add(x,0,z));
WorldShop shop = TwosideShops.LoadWorldShopData(s);
if (!shop.GetOwner().equalsIgnoreCase(ev.getPlayer().getName())) {
//This is not allowed! We can't expand shops that are not ours.
ev.getPlayer().sendMessage("There's a shop owned by "+ChatColor.LIGHT_PURPLE+shop.GetOwner()+ChatColor.WHITE+" right next to your chest! You cannot expand others' shops!");
ev.setCancelled(true);
}
}
}
}
}
}
if (ev.getItemInHand().hasItemMeta() && if (ev.getItemInHand().hasItemMeta() &&
ev.getItemInHand().getItemMeta().hasLore() && ev.getItemInHand().getItemMeta().hasLore() &&
ev.getItemInHand().getItemMeta().getLore().size()==4 && ev.getItemInHand().getItemMeta().getLore().size()==4 &&
@ -3210,6 +3231,12 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
//of a new custom damage calculation. //of a new custom damage calculation.
DealDamageToMob(p.getInventory().getItemInMainHand(),p,m); DealDamageToMob(p.getInventory().getItemInMainHand(),p,m);
if (m instanceof Monster) { if (m instanceof Monster) {
if (m.getType()==EntityType.SPIDER &&
p.getEquipment().getItemInMainHand().containsEnchantment(Enchantment.DAMAGE_ARTHROPODS)) {
//Apply just slowness 1 to the spider. Not this slowness IV ridiculousness.
m.removePotionEffect(PotionEffectType.SLOW);
m.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,300,0));
}
if (m.getType()==EntityType.ZOMBIE && if (m.getType()==EntityType.ZOMBIE &&
MonsterController.isZombieLeader(m) && MonsterController.isZombieLeader(m) &&
!m.hasPotionEffect(PotionEffectType.GLOWING) /*Make sure it's not being aggro'd already.*/) { !m.hasPotionEffect(PotionEffectType.GLOWING) /*Make sure it's not being aggro'd already.*/) {
@ -3767,6 +3794,13 @@ public class TwosideKeeper extends JavaPlugin implements Listener {
//This is a world shop. DO NOT allow this to happen. //This is a world shop. DO NOT allow this to happen.
ev.setCancelled(true); ev.setCancelled(true);
} }
Inventory destination = ev.getDestination();
l = destination.getLocation();
//See if this block is a world shop.
if (WorldShop.grabShopSign(l)!=null) {
//This is a world shop. DO NOT allow this to happen.
ev.setCancelled(true);
}
} }
@EventHandler(priority=EventPriority.LOW) @EventHandler(priority=EventPriority.LOW)

View File

@ -216,11 +216,11 @@ public class WorldShopManager {
sessions.remove(ss); sessions.remove(ss);
} }
public void AddNewPurchase(String owner, Player purchaser, ItemStack item, double price, int amt) { public void AddNewPurchase(String owner, Player purchaser, int shopID, double price, int amt) {
purchases.add(new ShopPurchase(owner, purchaser, item, price, amt)); purchases.add(new ShopPurchase(owner, purchaser, shopID, price, amt));
} }
public void AddNewPurchase(String owner, Player purchaser, ItemStack item, double price, int amt, boolean sell) { public void AddNewPurchase(String owner, Player purchaser, int shopID, double price, int amt, boolean sell) {
purchases.add(new ShopPurchase(owner, purchaser, item, price, amt, sell)); purchases.add(new ShopPurchase(owner, purchaser, shopID, price, amt, sell));
} }
public boolean PlayerHasPurchases(Player p) { public boolean PlayerHasPurchases(Player p) {
for (int i=0;i<purchases.size();i++) { for (int i=0;i<purchases.size();i++) {
@ -233,7 +233,7 @@ public class WorldShopManager {
public void PlayerSendPurchases(Player p) { public void PlayerSendPurchases(Player p) {
for (int i=0;i<purchases.size();i++) { for (int i=0;i<purchases.size();i++) {
if (p.getName().equalsIgnoreCase(purchases.get(i).getPlayer())) { if (p.getName().equalsIgnoreCase(purchases.get(i).getPlayer())) {
p.sendMessage(purchases.get(i).announcementString()); p.spigot().sendMessage(purchases.get(i).announcementString());
purchases.remove(i); purchases.remove(i);
i--; i--;
} }