diff --git a/TwosideKeeper.jar b/TwosideKeeper.jar index 9f95d83..7018ff5 100644 Binary files a/TwosideKeeper.jar and b/TwosideKeeper.jar differ diff --git a/src/plugin.yml b/src/plugin.yml index c668f05..79c706d 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: TwosideKeeper main: sig.plugin.TwosideKeeper.TwosideKeeper -version: 3.11.1d +version: 3.11.1f loadbefore: [aPlugin] commands: money: diff --git a/src/sig/plugin/TwosideKeeper/CustomDamage.java b/src/sig/plugin/TwosideKeeper/CustomDamage.java index 8dd5630..150cb9d 100644 --- a/src/sig/plugin/TwosideKeeper/CustomDamage.java +++ b/src/sig/plugin/TwosideKeeper/CustomDamage.java @@ -1072,7 +1072,7 @@ public class CustomDamage { private static void addSweepupBonus(Player p, double damage, String reason) { if (reason!=null && reason.equalsIgnoreCase("sweep up")) { if (ItemSet.HasSetBonusBasedOnSetBonusCount(p, ItemSet.PRIDE, 5)) { - TwosideKeeper.log("In here. Damage: "+damage, 0); + //TwosideKeeper.log("In here. Damage: "+damage, 0); GenericFunctions.HealEntity(p, damage/2); } } @@ -2282,8 +2282,8 @@ public class CustomDamage { //!damager.getWorld().getPVP() Player attacker = (Player)damager; Player defender = (Player)target; - if (!attacker.getWorld().getPVP() || !defender.isOnline() || - PVP.isFriendly(attacker,defender) || !PVP.isPvPing(defender)) { + if (attacker.getWorld().getPVP() && (!defender.isOnline() || + PVP.isFriendly(attacker,defender) || !PVP.isPvPing(defender))) { if (PVP.isWaitingForPlayers(defender)) { PVP session = PVP.getMatch(defender); session.joinMatch(attacker); @@ -2418,7 +2418,7 @@ public class CustomDamage { public static boolean CanResistDotsWithExperienceSet(Entity damager, LivingEntity target, String reason) { return target instanceof Player && ItemSet.HasSetBonusBasedOnSetBonusCount((Player)target, ItemSet.ALUSTINE, 3) && - ((reason!=null && (reason.equalsIgnoreCase("poison") || reason.equalsIgnoreCase("wither") || reason.equalsIgnoreCase("fire_tick") || reason.equalsIgnoreCase("lava") || reason.equalsIgnoreCase("fire")))) && + ((reason!=null && (reason.equalsIgnoreCase("shrapnel") ||reason.equalsIgnoreCase("bleeding") ||reason.equalsIgnoreCase("infection") ||reason.equalsIgnoreCase("burn") || reason.equalsIgnoreCase("poison") || reason.equalsIgnoreCase("wither") || reason.equalsIgnoreCase("fire_tick") || reason.equalsIgnoreCase("lava") || reason.equalsIgnoreCase("fire")))) && aPlugin.API.getTotalExperience((Player)target)>=ItemSet.TotalBaseAmountBasedOnSetBonusCount((Player)target, ItemSet.ALUSTINE, 3, 3); } @@ -3642,7 +3642,7 @@ public class CustomDamage { Player p = (Player)damager; if (target instanceof Player && PVP.isEnemy(p, (Player)target)) { - armorpenmult = 0.25; + armorpenmult = 0.2; } PlayerStructure pd = PlayerStructure.GetPlayerStructure(p); if (GenericFunctions.isArtifactEquip(weapon) && diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java index 06fa4ae..ec58867 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/Common/GenericFunctions.java @@ -3241,7 +3241,7 @@ public class GenericFunctions { public static boolean hasPermissionToBreakSign(Sign s, Player p) { if (WorldShop.isWorldShopSign(s)) { WorldShop shop = TwosideKeeper.TwosideShops.LoadWorldShopData(s); - if (shop.GetOwner().equalsIgnoreCase(p.getName()) || p.isOp()) { + if (shop.GetOwner().equals(p.getUniqueId()) || p.isOp()) { return true; } else { return false; @@ -4061,7 +4061,7 @@ public class GenericFunctions { } if (allowed) { LivingEntity m = (LivingEntity)e; - TwosideKeeper.log("Allowed to hit entity "+GenericFunctions.GetEntityDisplayName(m)+" Damager: "+GenericFunctions.GetEntityDisplayName(damager), 0); + //TwosideKeeper.log("Allowed to hit entity "+GenericFunctions.GetEntityDisplayName(m)+" Damager: "+GenericFunctions.GetEntityDisplayName(damager), 0); affectedents.add(m); if (enoughTicksHavePassed(m,(Player)damager)) { basedmg=origdmg; diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/ItemSet.java b/src/sig/plugin/TwosideKeeper/HelperStructures/ItemSet.java index 529c132..6110180 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/ItemSet.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/ItemSet.java @@ -711,7 +711,7 @@ public enum ItemSet { lore.add(ChatColor.DARK_AQUA+" 2 - "+ChatColor.WHITE+" Gain immunity to Explosions."); lore.add(ChatColor.DARK_AQUA+" "+ChatColor.WHITE+" Consumes "+ChatColor.YELLOW+ItemSet.GetBaseAmount(set, tier, 2)+" XP"+ChatColor.WHITE+" per absorbed hit."); lore.add(ChatColor.DARK_AQUA+" "+ChatColor.GRAY+ChatColor.ITALIC+"Must have at least "+ChatColor.YELLOW+ChatColor.ITALIC+ItemSet.GetBaseAmount(set, tier, 2)+" XP"+ChatColor.GRAY+ChatColor.ITALIC+" to trigger."); - lore.add(ChatColor.DARK_AQUA+" 3 - "+ChatColor.WHITE+" Resists all fire, poison, and wither damage."); + lore.add(ChatColor.DARK_AQUA+" 3 - "+ChatColor.WHITE+" Resists all fire, poison, bleeding, infection and wither damage."); lore.add(ChatColor.DARK_AQUA+" "+ChatColor.WHITE+" Consumes "+ChatColor.YELLOW+ItemSet.GetBaseAmount(set, tier, 3)+" XP"+ChatColor.WHITE+" per absorbed hit."); lore.add(ChatColor.DARK_AQUA+" "+ChatColor.GRAY+ChatColor.ITALIC+"Must have at least "+ChatColor.YELLOW+ChatColor.ITALIC+ItemSet.GetBaseAmount(set, tier, 3)+" XP"+ChatColor.GRAY+ChatColor.ITALIC+" to trigger."); lore.add(ChatColor.DARK_AQUA+" 5 - "+ChatColor.WHITE+" Backstabs spill "+ChatColor.YELLOW+ItemSet.GetBaseAmount(set, tier, 4)+" XP"+ChatColor.WHITE+" out from the target hit."); diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/ShopPurchase.java b/src/sig/plugin/TwosideKeeper/HelperStructures/ShopPurchase.java index f1df5fa..a82c22c 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/ShopPurchase.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/ShopPurchase.java @@ -1,7 +1,9 @@ package sig.plugin.TwosideKeeper.HelperStructures; import java.text.DecimalFormat; +import java.util.UUID; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.inventory.ItemStack; @@ -11,14 +13,14 @@ import net.md_5.bungee.api.chat.TextComponent; import sig.plugin.TwosideKeeper.HelperStructures.Common.GenericFunctions; public class ShopPurchase { - String player; - String customer; + UUID player; + UUID customer; ItemStack item; double money; int amt; boolean sell; - public ShopPurchase(String p, String customer, ItemStack item, double money, int amt) { + public ShopPurchase(UUID p, UUID customer, ItemStack item, double money, int amt) { this.player = p; this.customer=customer; this.item=item; @@ -27,7 +29,7 @@ public class ShopPurchase { this.sell=true; } - public ShopPurchase(String p, String customer, ItemStack item, double money, int amt, boolean sell) { + public ShopPurchase(UUID p, UUID customer, ItemStack item, double money, int amt, boolean sell) { this.player = p; this.customer=customer; this.item=item; @@ -36,11 +38,11 @@ public class ShopPurchase { this.sell=sell; } - public String getSeller() { - return player; + public UUID getSeller() { + return Bukkit.getOfflinePlayer(player).getUniqueId(); } - public String getCustomer() { - return customer; + public UUID getCustomer() { + return Bukkit.getOfflinePlayer(customer).getUniqueId(); } public ItemStack getItem() { return item; @@ -58,7 +60,7 @@ public class ShopPurchase { public TextComponent announcementString() { DecimalFormat df = new DecimalFormat("0.00"); if (sell) { - TextComponent message1 = new TextComponent("Player "+ChatColor.BLUE+customer+ChatColor.WHITE+" has purchased "+ChatColor.YELLOW+amt+ChatColor.WHITE+" of your "); + TextComponent message1 = new TextComponent("Player "+ChatColor.BLUE+WorldShop.getFriendlyOwnerName(customer)+ChatColor.WHITE+" has purchased "+ChatColor.YELLOW+amt+ChatColor.WHITE+" of your "); TextComponent message2 = new TextComponent(ChatColor.GREEN+"["+GenericFunctions.GetItemName(this.item)+ChatColor.RESET+""+ChatColor.GREEN+"]"); message2.setHoverEvent(new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(GenericFunctions.GetItemName(this.item)+WorldShop.GetItemInfo(this.item)).create())); TextComponent message3 = new TextComponent(". You have earned $"+df.format(money)+". "+ChatColor.GRAY+""+ChatColor.ITALIC+"(See /money)"); @@ -67,7 +69,7 @@ public class ShopPurchase { finalmsg.addExtra(message3); return finalmsg; } else { - TextComponent message1 = new TextComponent("Player "+ChatColor.BLUE+customer+ChatColor.WHITE+" has sold "+ChatColor.YELLOW+amt+ChatColor.WHITE+" "); + TextComponent message1 = new TextComponent("Player "+ChatColor.BLUE+WorldShop.getFriendlyOwnerName(customer)+ChatColor.WHITE+" has sold "+ChatColor.YELLOW+amt+ChatColor.WHITE+" "); TextComponent message2 = new TextComponent(ChatColor.GREEN+"["+GenericFunctions.GetItemName(this.item)+ChatColor.RESET+""+ChatColor.GREEN+"]"); message2.setHoverEvent(new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(GenericFunctions.GetItemName(this.item)+WorldShop.GetItemInfo(this.item)).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.)"); diff --git a/src/sig/plugin/TwosideKeeper/HelperStructures/WorldShop.java b/src/sig/plugin/TwosideKeeper/HelperStructures/WorldShop.java index a1550f2..fe1899c 100644 --- a/src/sig/plugin/TwosideKeeper/HelperStructures/WorldShop.java +++ b/src/sig/plugin/TwosideKeeper/HelperStructures/WorldShop.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Map; import java.util.Random; import java.util.Set; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -24,6 +25,7 @@ import org.bukkit.DyeColor; import org.bukkit.FireworkEffect; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.OfflinePlayer; import org.bukkit.block.Banner; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -63,7 +65,7 @@ import sig.plugin.TwosideKeeper.HelperStructures.Utils.ItemUtils; public class WorldShop { ItemStack item; - String owner; + UUID owner; double price; int amt; int storedamt = 0; @@ -72,8 +74,9 @@ public class WorldShop { public static final double DEFAULTPRICE = 99.99; public static HashMap pricelist = new HashMap(); public static String price_file = TwosideKeeper.plugin.getDataFolder()+"/ShopPrices.data"; + public static final UUID ADMIN_UUID = UUID.nameUUIDFromBytes(new byte[]{(byte)0}); - public WorldShop (ItemStack i, int amt, int storedamt, double p, String player, int shopID, Location shopLoc) { + public WorldShop (ItemStack i, int amt, int storedamt, double p, UUID player, int shopID, Location shopLoc) { this.item=i; this.price=p; this.owner=player; @@ -109,6 +112,15 @@ public class WorldShop { public void UpdateLoc(Location loc) { this.loc=loc; } + + public static String getFriendlyOwnerName(UUID id) { + OfflinePlayer op = Bukkit.getOfflinePlayer(id); + if (op!=null) { + return op.getName(); + } else { + return "admin"; + } + } public Location getLoc() { return loc; @@ -121,7 +133,7 @@ public class WorldShop { return item; } public double GetUnitPrice() { - if (owner.equalsIgnoreCase("admin")) { + if (owner.equals(ADMIN_UUID)) { return GetWorldShopPrice(item); } else { return price; @@ -241,13 +253,13 @@ public class WorldShop { return id; } public int GetAmount() { - if (owner.equalsIgnoreCase("admin")) { + if (owner.equals(ADMIN_UUID)) { return 10000; } else { return amt; } } - public String GetOwner() { + public UUID GetOwner() { return owner; } @@ -1101,7 +1113,7 @@ public class WorldShop { public static boolean hasPermissionToBreakWorldShopSign(Sign s, Player p) { if (WorldShop.isWorldShopSign(s)) { WorldShop shop = TwosideKeeper.TwosideShops.LoadWorldShopData(s); - if (shop.GetOwner().equalsIgnoreCase(p.getName()) || p.isOp()) { + if (shop.GetOwner().equals(p.getUniqueId()) || p.isOp()) { return true; } else { return false; @@ -1240,7 +1252,7 @@ public class WorldShop { wallsign.setData(sign.getData()); Sign s = (Sign)wallsign.getState(); s.setLine(0,"shop"); - WorldShop shop = TwosideKeeper.TwosideShops.CreateWorldShop(s, item, 10000, DEFAULTPRICE, "admin"); + WorldShop shop = TwosideKeeper.TwosideShops.CreateWorldShop(s, item, 10000, DEFAULTPRICE, ADMIN_UUID); /*s.setLine(0, ChatColor.BLUE+"-- SHOP --"); s.setLine(1, GenericFunctions.UserFriendlyMaterialName(item)); s.setLine(2, "$"+df.format(GetWorldShopPrice(item))+ChatColor.DARK_BLUE+" [x10000]"); diff --git a/src/sig/plugin/TwosideKeeper/Monster/GenericBoss.java b/src/sig/plugin/TwosideKeeper/Monster/GenericBoss.java index 71ef086..d01b1ed 100644 --- a/src/sig/plugin/TwosideKeeper/Monster/GenericBoss.java +++ b/src/sig/plugin/TwosideKeeper/Monster/GenericBoss.java @@ -293,8 +293,8 @@ public class GenericBoss extends CustomMonster{ it.setPickupDelay(0);*/ } } - Bukkit.getServer().broadcastMessage(ChatColor.GREEN+participants_list.toString()+ChatColor.WHITE+" "+(participants_list.length()==1?"has single-handedly taken down the ":"have successfully slain ")+GenericFunctions.getDisplayName(m)+ChatColor.WHITE+"!"); - aPlugin.API.discordSendRaw(ChatColor.GREEN+participants_list.toString()+ChatColor.WHITE+" "+(participants_list.length()==1?"has single-handedly taken down the ":"have successfully slain ")+"**"+GenericFunctions.getDisplayName(m)+ChatColor.WHITE+"**!"); + Bukkit.getServer().broadcastMessage(ChatColor.GREEN+participants_list.toString()+ChatColor.WHITE+" "+(participants.size()==1?"has single-handedly taken down the ":"have successfully slain ")+GenericFunctions.getDisplayName(m)+ChatColor.WHITE+"!"); + aPlugin.API.discordSendRaw(ChatColor.GREEN+participants_list.toString()+ChatColor.WHITE+" "+(participants.size()==1?"has single-handedly taken down the ":"have successfully slain ")+"**"+GenericFunctions.getDisplayName(m)+ChatColor.WHITE+"**!"); Bukkit.getScheduler().scheduleSyncDelayedTask(TwosideKeeper.plugin, new Runnable() { public void run() { diff --git a/src/sig/plugin/TwosideKeeper/Monster/Knight.java b/src/sig/plugin/TwosideKeeper/Monster/Knight.java index 8d69790..fbe0870 100644 --- a/src/sig/plugin/TwosideKeeper/Monster/Knight.java +++ b/src/sig/plugin/TwosideKeeper/Monster/Knight.java @@ -941,7 +941,8 @@ public class Knight extends GenericBoss{ !m.getWorld().getName().contains("Instance") && Math.random()<=0.015 && TwosideKeeper.elitemonsters.size()==0 && - GenericBoss.bossCount()==0) || force) { + //GenericBoss.bossCount()==0 && + GenericFunctions.AllNaturalBlocks(m.getLocation().getBlock(),16,8,16)) || force) { Skeleton s = (Skeleton)m; s.setSkeletonType(SkeletonType.WITHER); Spider ss = DarkSpider.InitializeDarkSpider(m); diff --git a/src/sig/plugin/TwosideKeeper/Monster/SniperSkeleton.java b/src/sig/plugin/TwosideKeeper/Monster/SniperSkeleton.java index cb220fc..ad50027 100644 --- a/src/sig/plugin/TwosideKeeper/Monster/SniperSkeleton.java +++ b/src/sig/plugin/TwosideKeeper/Monster/SniperSkeleton.java @@ -675,7 +675,8 @@ public class SniperSkeleton extends GenericBoss{ !m.getWorld().getName().contains("Instance") && Math.random()<=0.015 && TwosideKeeper.elitemonsters.size()==0 && - GenericBoss.bossCount()==0) || force) { + //GenericBoss.bossCount()==0 && + GenericFunctions.AllNaturalBlocks(m.getLocation().getBlock(),16,8,16)) || force) { Skeleton s = (Skeleton)m; s.setSkeletonType(SkeletonType.NORMAL); //Determine distance from Twoside for Difficulty. diff --git a/src/sig/plugin/TwosideKeeper/PVP.java b/src/sig/plugin/TwosideKeeper/PVP.java index 4754a80..f823507 100644 --- a/src/sig/plugin/TwosideKeeper/PVP.java +++ b/src/sig/plugin/TwosideKeeper/PVP.java @@ -24,6 +24,10 @@ public class PVP { PVPOption battlefield; CHOICEENGINE state; long timer; + private long lastSelected=0; + int scorelimit; + long timelimit; + boolean scorematch = false; //If true, uses score limit. If false uses timer. //NEUTRAL team //Team1 @@ -145,10 +149,17 @@ public class PVP { p.sendMessage(ChatColor.YELLOW+style.getTitle()+ChatColor.GREEN+" has been voted as the style for this PVP match!"); } } - state = CHOICEENGINE.WAITFORSTAGECHOICES; + if (players.size()>2 && style.name().contains("ROUNDS")) { + state = CHOICEENGINE.WAITFORTEAMCHOICES; + lastSelected=TwosideKeeper.getServerTickTime(); + resetPlayerChoices(); + DisplayTeamChoices(); + } else { + state = CHOICEENGINE.WAITFORSTAGECHOICES; + resetPlayerChoices(); + DisplayStageChoices(); + } timer=TwosideKeeper.getServerTickTime(); - resetPlayerChoices(); - DisplayStageChoices(); } else { for (String s : players.keySet()) { Player pl = Bukkit.getPlayer(s); @@ -160,6 +171,26 @@ public class PVP { } } }break; + case WAITFORTEAMCHOICES:{ + if (lastSelected+100<=TwosideKeeper.getServerTickTime()) { + if (allPlayersHaveChosenATeam() || lastSelected+4000<=TwosideKeeper.getServerTickTime()) { + randomlyPickTeams(); + if (teamsAreInvalid()) { + for (String s : players.keySet()) { + Player p = Bukkit.getPlayer(s); + if (p!=null) { + p.sendMessage("Not enough players in both teams to begin a PvP Match! The match has been cancelled."); + } + } + return false; + } + SendTeamList(); + resetPlayerChoices(); + DisplayStageChoices(); + state = CHOICEENGINE.WAITFORSTAGECHOICES; + } + } + }break; case WAITFORSTAGECHOICES:{ if (timer+400<=TwosideKeeper.getServerTickTime() || allPlayersPicked()) { if (players.size()>=2) { @@ -215,6 +246,38 @@ public class PVP { return true; } + private boolean teamsAreInvalid() { + if (getPlayersInTeam(1).size()==0 || + getPlayersInTeam(2).size()==0) { + return true; + } else { + return false; + } + } + + private void randomlyPickTeams() { + for (String s : players.keySet()) { + PVPPlayer pp = players.get(s); + if (pp.team==0) { + if (getPlayersInTeam(1).size() team1 = getPlayersInTeam(1); + List team2 = getPlayersInTeam(2); + StringBuilder sb = new StringBuilder(); + sb.append(ChatColor.BLUE+"\n"+ChatColor.UNDERLINE+" Team 1 \n"+ChatColor.RESET+ChatColor.AQUA); + if (team1.size()>0) { + AppendTeam(team1, sb); + } else { + sb.append(ChatColor.ITALIC+"No One"+ChatColor.RESET); + } + sb.append("\n\n"+ChatColor.RED+""+ChatColor.UNDERLINE+" Team 2 \n"+ChatColor.RESET+ChatColor.GOLD); + if (team2.size()>0) { + AppendTeam(team2, sb); + } else { + sb.append(ChatColor.ITALIC+"No One"+ChatColor.RESET); + } + sb.append("\n"); + for (String s : players.keySet()) { + Player p = Bukkit.getPlayer(s); + if (p!=null) { + p.sendMessage(sb.toString()); + } + } + } + + private void AppendTeam(List team1, StringBuilder sb) { + for (int i=0;i getPlayersInTeam(int i) { + List teams = new ArrayList(); + for (String s : players.keySet()) { + PVPPlayer pp = players.get(s); + if (pp.team==i) { + teams.add(s); + } + } + return teams; + } + private boolean ValidateChoice(PVPOption option) { List options1 = ImmutableList.of(PVPOption.ROUNDS3,PVPOption.ROUNDS5,PVPOption.ROUNDS7, PVPOption.ROUNDS15,PVPOption.MIN3,PVPOption.MIN5,PVPOption.MIN10); List options2 = ImmutableList.of(PVPOption.OPENWORLD,PVPOption.SMALLBATTLEFIELD,PVPOption.AQUATICFORT, PVPOption.NETHERFORTRESS,PVPOption.THEEND); + List options3 = ImmutableList.of(PVPOption.TEAM1,PVPOption.TEAM2); switch (state) { case WAITFORROUNDCHOICES:{ return options1.contains(option); @@ -312,6 +461,9 @@ public class PVP { case WAITFORSTAGECHOICES:{ return options2.contains(option); } + case WAITFORTEAMCHOICES:{ + return options3.contains(option); + } } return true; } @@ -437,18 +589,21 @@ class PVPPlayer { Location startingLoc; Location lastLoc; PVPOption choice; + int team; PVPPlayer() { score=0; startingLoc=null; choice=PVPOption.NONE; lastLoc=null; + team=0; } } enum CHOICEENGINE { WAITFORPLAYERS, //Waits 10 seconds for any additional players to join in. WAITFORROUNDCHOICES, //Asks all participants to submit a round choice. (10 seconds Max) + WAITFORTEAMCHOICES, //Asks all participants to submit a team choice. WAITFORSTAGECHOICES, //Asks all participants to submit a stage choice. (10 seconds Max) PREPAREFORBATTLE, //Gives players 10 seconds before transferring them. FIGHTING, //The actual fighting @@ -457,29 +612,39 @@ enum CHOICEENGINE { enum PVPOption { NONE(0,"No Choice","Hey look! It's my favorite streamer! The one and only >>Legendary<<, yes LEGENDARY Captain_Marrow aka Storm! We break ultimate plates, alchemize Artifacts, miss skillshots, break Master Swords, collect food because we cannot dodge the Ganon, deny our combat-buddies from keeping their legendary equipment, and jump off boats right before they leave ( cy@ VoHiYo )! Come join the fun! Kappa"), - ROUNDS3(1,ChatColor.WHITE+"Best of 3","The player that wins 2 of 3 total rounds wins the duel."), - ROUNDS5(2,ChatColor.GRAY+"Best of 5","The player that wins 3 of 5 total rounds wins the duel."), - ROUNDS7(3,ChatColor.WHITE+"Best of 7","The player that wins 4 of 7 total rounds wins the duel."), - ROUNDS15(4,ChatColor.GRAY+"Best of 15","The player that wins 8 of 15 total rounds wins the duel."), - MIN3(5,ChatColor.WHITE+"3 Min Deathmatch","The player that gets the highest score within 3 minutes wins the duel. "+ChatColor.GREEN+"+1 Point per Kill"+ChatColor.RESET+", "+ChatColor.RED+"-1 Point per Death"), - MIN5(6,ChatColor.GRAY+"5 Min Deathmatch","The player that gets the highest score within 5 minutes wins the duel. "+ChatColor.GREEN+"+1 Point per Kill"+ChatColor.RESET+", "+ChatColor.RED+"-1 Point per Death"), - MIN10(7,ChatColor.WHITE+"10 Min Deathmatch","The player that gets the highest score within 10 minutes wins the duel. "+ChatColor.GREEN+"+1 Point per Kill"+ChatColor.RESET+", "+ChatColor.RED+"-1 Point per Death"), + ROUNDS3(1,ChatColor.WHITE+"Best of 3","The team that wins 2 of 3 total rounds wins the duel."), + ROUNDS5(2,ChatColor.GRAY+"Best of 5","The team that wins 3 of 5 total rounds wins the duel."), + ROUNDS7(3,ChatColor.WHITE+"Best of 7","The team that wins 4 of 7 total rounds wins the duel."), + ROUNDS15(4,ChatColor.GRAY+"Best of 15","The team that wins 8 of 15 total rounds wins the duel."), + MIN3(5,ChatColor.WHITE+"3 Min Deathmatch","The player that gets the highest score within 3 minutes wins the duel. "+ChatColor.GREEN+"+1 Point per Kill"+ChatColor.RESET+", "+ChatColor.RED+"-1 Point per Death",20*60*3), + MIN5(6,ChatColor.GRAY+"5 Min Deathmatch","The player that gets the highest score within 5 minutes wins the duel. "+ChatColor.GREEN+"+1 Point per Kill"+ChatColor.RESET+", "+ChatColor.RED+"-1 Point per Death",20*60*5), + MIN10(7,ChatColor.WHITE+"10 Min Deathmatch","The player that gets the highest score within 10 minutes wins the duel. "+ChatColor.GREEN+"+1 Point per Kill"+ChatColor.RESET+", "+ChatColor.RED+"-1 Point per Death",20*60*10), OPENWORLD(1,ChatColor.WHITE+"Open World","Fight in the current location you are located at."+ChatColor.RED+"\n NOTE: "+ChatColor.WHITE+"You may not wander more than 32 blocks away from your starting battle location."), SMALLBATTLEFIELD(2,ChatColor.GRAY+"Small Battlefield","Fight in a small, instanced battlefield"), AQUATICFORT(3,ChatColor.WHITE+"Aquatic Fort","Fight in a small, decorated fort with a moat surrounding the area."), NETHERFORTRESS(4,ChatColor.GRAY+"Nether Fortress","Fight in a medium-sized fortress sitting upon the fiery flames of hell."), - THEEND(5,ChatColor.WHITE+"The End","This is where all battles come to a spectacular end. A medium platform suspended high into the void. Falling off is inevitable."); + THEEND(5,ChatColor.WHITE+"The End","This is where all battles come to a spectacular end. A medium platform suspended high into the void. Falling off is inevitable."), + TEAM1(1,ChatColor.GRAY+"Team 1",""), + TEAM2(2,ChatColor.WHITE+"Team 2",""); int selection_numb; String short_desc; String hover_desc; + long time; PVPOption(int numb, String desc, String hover) { this.selection_numb=numb; this.short_desc=desc; this.hover_desc=hover; + this.time=0; + } + + PVPOption(int numb, String desc, String hover, long time) { + this.selection_numb=numb; + this.short_desc=desc; + this.hover_desc=hover; + this.time=time; } - int getSelectionNumber() { return selection_numb; } diff --git a/src/sig/plugin/TwosideKeeper/RecordKeeping.java b/src/sig/plugin/TwosideKeeper/RecordKeeping.java index 093fab4..1a86e27 100644 --- a/src/sig/plugin/TwosideKeeper/RecordKeeping.java +++ b/src/sig/plugin/TwosideKeeper/RecordKeeping.java @@ -9,12 +9,14 @@ import java.io.IOException; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import sig.plugin.TwosideKeeper.HelperStructures.PlayerMode; +import sig.plugin.TwosideKeeper.HelperStructures.WorldShop; public class RecordKeeping { String name; @@ -50,7 +52,7 @@ public class RecordKeeping { } public void saveRecordsToConfig() { - File file = new File(TwosideKeeper.plugin.getDataFolder()+"/records/"+ChatColor.stripColor(name)+".data"); + File file = new File(TwosideKeeper.plugin.getDataFolder()+"/records/"+ChatColor.stripColor(name)+".data2"); if (!file.exists()) { try { file.createNewFile(); @@ -74,8 +76,32 @@ public class RecordKeeping { public void loadRecordsFromConfig() { File file = new File(TwosideKeeper.plugin.getDataFolder()+"/records/"+ChatColor.stripColor(name)+".data"); + File file2 = new File(TwosideKeeper.plugin.getDataFolder()+"/records/"+ChatColor.stripColor(name)+".data2"); + if (file2.exists()) { + try( + FileReader fw = new FileReader(file); + BufferedReader bw = new BufferedReader(fw);) + { + String readline = bw.readLine(); + int lines = 0; + do { + if (readline!=null) { + lines++; + String[] split = readline.split(","); + UUID name = UUID.fromString(split[0]); + double score = Double.parseDouble(split[1]); + PlayerMode mode = PlayerMode.valueOf(split[2]); + recordlist.add(new Record(name,score,mode)); + readline = bw.readLine(); + }} while (readline!=null); + } catch (IOException e) { + e.printStackTrace(); + } + } else if (file.exists()) { + //Using the old system. Convert temporarily. + TwosideKeeper.log("WARNING! Using the old file system for Records "+name+". Converting...", 1); try( FileReader fw = new FileReader(file); BufferedReader bw = new BufferedReader(fw);) @@ -86,7 +112,7 @@ public class RecordKeeping { if (readline!=null) { lines++; String[] split = readline.split(","); - String name = split[0]; + UUID name = Bukkit.getOfflinePlayer(split[0]).getUniqueId(); double score = Double.parseDouble(split[1]); PlayerMode mode = PlayerMode.valueOf(split[2]); recordlist.add(new Record(name,score,mode)); @@ -95,6 +121,7 @@ public class RecordKeeping { } catch (IOException e) { e.printStackTrace(); } + file.delete(); } sortRecords(); @@ -103,9 +130,9 @@ public class RecordKeeping { } } - public void addRecord(String name, double score, PlayerMode mostusedmode) { + public void addRecord(UUID name, double score, PlayerMode mostusedmode) { for (Record r : recordlist) { - if (r.getName().equalsIgnoreCase(name)) { + if (r.getName().equals(name)) { if ((reverse && r.getScore()>score) || (!reverse && r.getScore()1) { Record recordbeat = recordlist.get(1);//Get the record we beat. //DecimalFormat df = new DecimalFormat("0.00"); - Bukkit.broadcastMessage(newRecordAdded.getMode().getColor()+"("+newRecordAdded.getMode().getAbbreviation()+")"+ChatColor.RESET+ChatColor.GREEN+newRecordAdded.getName()+ChatColor.RESET+" has beat "+recordbeat.getMode().getColor()+"("+recordbeat.getMode().getAbbreviation()+")"+ChatColor.RESET+ChatColor.GREEN+recordbeat.getName()+ChatColor.RESET+" in "+ChatColor.AQUA+ChatColor.BOLD+name+ChatColor.RESET+" with a score of "+ChatColor.YELLOW+ChatColor.BOLD+df.format(newRecordAdded.getScore())+"!!"); - aPlugin.API.discordSendRaw("*("+newRecordAdded.getMode().getAbbreviation()+")*"+newRecordAdded.getName()+" has beat *("+recordbeat.getMode().getAbbreviation()+")*"+recordbeat.getName()+" in **"+name+"** with a score of "+ChatColor.YELLOW+ChatColor.BOLD+df.format(newRecordAdded.getScore())+"!!"); + Bukkit.broadcastMessage(newRecordAdded.getMode().getColor()+"("+newRecordAdded.getMode().getAbbreviation()+")"+ChatColor.RESET+ChatColor.GREEN+WorldShop.getFriendlyOwnerName(newRecordAdded.getName())+ChatColor.RESET+" has beat "+recordbeat.getMode().getColor()+"("+recordbeat.getMode().getAbbreviation()+")"+ChatColor.RESET+ChatColor.GREEN+WorldShop.getFriendlyOwnerName(recordbeat.getName())+ChatColor.RESET+" in "+ChatColor.AQUA+ChatColor.BOLD+name+ChatColor.RESET+" with a score of "+ChatColor.YELLOW+ChatColor.BOLD+df.format(newRecordAdded.getScore())+"!!"); + aPlugin.API.discordSendRaw("*("+newRecordAdded.getMode().getAbbreviation()+")*"+WorldShop.getFriendlyOwnerName(newRecordAdded.getName())+" has beat *("+recordbeat.getMode().getAbbreviation()+")*"+WorldShop.getFriendlyOwnerName(recordbeat.getName())+" in **"+name+"** with a score of "+ChatColor.YELLOW+ChatColor.BOLD+df.format(newRecordAdded.getScore())+"!!"); leader = currentRecord; } else { - Bukkit.broadcastMessage(newRecordAdded.getMode().getColor()+"("+newRecordAdded.getMode().getAbbreviation()+")"+ChatColor.RESET+ChatColor.GREEN+newRecordAdded.getName()+ChatColor.RESET+" has completed "+ChatColor.AQUA+ChatColor.BOLD+name+ChatColor.RESET+" with a score of "+ChatColor.YELLOW+ChatColor.BOLD+df.format(newRecordAdded.getScore())); - aPlugin.API.discordSendRaw(newRecordAdded.getMode().getColor()+"*("+newRecordAdded.getMode().getAbbreviation()+")*"+newRecordAdded.getName()+" has completed **"+name+"** with a score of "+ChatColor.YELLOW+ChatColor.BOLD+df.format(newRecordAdded.getScore())); + Bukkit.broadcastMessage(newRecordAdded.getMode().getColor()+"("+newRecordAdded.getMode().getAbbreviation()+")"+ChatColor.RESET+ChatColor.GREEN+WorldShop.getFriendlyOwnerName(newRecordAdded.getName())+ChatColor.RESET+" has completed "+ChatColor.AQUA+ChatColor.BOLD+name+ChatColor.RESET+" with a new personal best score of "+ChatColor.YELLOW+ChatColor.BOLD+df.format(newRecordAdded.getScore())); + aPlugin.API.discordSendRaw(newRecordAdded.getMode().getColor()+"*("+newRecordAdded.getMode().getAbbreviation()+")*"+WorldShop.getFriendlyOwnerName(newRecordAdded.getName())+" has completed **"+name+"** with a new personal best score of "+ChatColor.YELLOW+ChatColor.BOLD+df.format(newRecordAdded.getScore())); } } @@ -164,7 +193,7 @@ public class RecordKeeping { if (recordlist.size()>0) { p.sendMessage(ChatColor.AQUA+"Records for "+ChatColor.BOLD+name); for (int i=0;i0) { //LEGACY CODE. //It did, we are going to release those items. @@ -8993,7 +9004,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { return; } else { //They are not the owner! Do not allow this shop to be broken. - p.sendMessage("This shop belongs to "+ChatColor.LIGHT_PURPLE+owner+ChatColor.WHITE+"! You cannot break others' shops!"); + p.sendMessage("This shop belongs to "+ChatColor.LIGHT_PURPLE+WorldShop.getFriendlyOwnerName(owner)+ChatColor.WHITE+"! You cannot break others' shops!"); ev.setCancelled(true); return; } @@ -9004,8 +9015,8 @@ public class TwosideKeeper extends JavaPlugin implements Listener { //This is a shop. Let's find out who the owner is. int shopID = TwosideShops.GetShopID(s); WorldShop shop = TwosideShops.LoadWorldShopData(shopID); - String owner = shop.GetOwner(); - if (owner.equalsIgnoreCase(p.getName()) || p.isOp()) { + UUID owner = shop.GetOwner(); + if (owner.equals(p.getUniqueId()) || p.isOp()) { //We are going to see if this shop had items in it. /*if (shop.GetStoredAmount()>0) { //LEGACY CODE. //It did, we are going to release those items. @@ -9055,7 +9066,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { return; } else { //They are not the owner! Do not allow this shop to be broken. - p.sendMessage("This shop belongs to "+ChatColor.LIGHT_PURPLE+owner+ChatColor.WHITE+"! You cannot break others' shops!"); + p.sendMessage("This shop belongs to "+ChatColor.LIGHT_PURPLE+WorldShop.getFriendlyOwnerName(owner)+ChatColor.WHITE+"! You cannot break others' shops!"); ev.setCancelled(true); return; } @@ -10848,24 +10859,38 @@ public class TwosideKeeper extends JavaPlugin implements Listener { DecimalFormat df = new DecimalFormat("0.00"); return Double.parseDouble(df.format(d)); } + @Deprecated public static double getPlayerMoney(String p) { //See if the data file exists, open it. if (Bukkit.getPlayer(p)!=null) { DecimalFormat df = new DecimalFormat("0.00"); return Double.parseDouble(df.format(getPlayerMoney(Bukkit.getPlayer(p)))); + } else { + if (Bukkit.getOfflinePlayer(p)!=null) { + return getPlayerMoney(Bukkit.getOfflinePlayer(p).getUniqueId()); + } else { + log("[WARNING] Could not find Player "+p+"'s offline profile!!",1); + DebugUtils.showStackTrace(); + return -1; + } + } + } + + public static double getPlayerMoney(UUID id) { + if (Bukkit.getPlayer(id)!=null) { + return getPlayerMoney(Bukkit.getPlayer(id)); } else { File config; - config = new File(TwosideKeeper.filesave,"users/"+Bukkit.getOfflinePlayer(p).getUniqueId()+".data"); + config = new File(TwosideKeeper.filesave,"users/"+id+".data"); FileConfiguration workable = YamlConfiguration.loadConfiguration(config); if (!config.exists()) { //Something bad happened if we got here. - log("[WARNING] Could not find the correct player data file for "+p+" to get money data from.",1); + log("[WARNING] Could not find the correct player data file for "+id+" to get money data from.",1); return -1; } return workable.getDouble("money"); } } - public static double getPlayerBankMoney(Player p) { //Tells a player how much money they have. PlayerStructure pd = (PlayerStructure)playerdata.get(p.getUniqueId()); @@ -10874,44 +10899,59 @@ public class TwosideKeeper extends JavaPlugin implements Listener { DecimalFormat df = new DecimalFormat("0.00"); return Double.parseDouble(df.format(d)); } - - public static double getPlayerBankMoney(String p) { - if (Bukkit.getPlayer(p)!=null) { - DecimalFormat df = new DecimalFormat("0.00"); - return Double.parseDouble(df.format(getPlayerBankMoney(Bukkit.getPlayer(p)))); + public static double getPlayerBankMoney(UUID id) { + if (Bukkit.getPlayer(id)!=null) { + return getPlayerBankMoney(Bukkit.getPlayer(id)); } else { - //See if the data file exists, open it. File config; - config = new File(TwosideKeeper.filesave,"users/"+Bukkit.getOfflinePlayer(p).getUniqueId()+".data"); + config = new File(TwosideKeeper.filesave,"users/"+id+".data"); FileConfiguration workable = YamlConfiguration.loadConfiguration(config); if (!config.exists()) { //Something bad happened if we got here. - log("[WARNING] Could not find the correct player data file for "+p+" to get money data from.",1); + log("[WARNING] Could not find the correct player data file for "+id+" to get money data from.",1); return -1; } return workable.getDouble("bank_money"); } } + @Deprecated + public static double getPlayerBankMoney(String p) { + if (Bukkit.getPlayer(p)!=null) { + DecimalFormat df = new DecimalFormat("0.00"); + return Double.parseDouble(df.format(getPlayerBankMoney(Bukkit.getPlayer(p)))); + } else { + //See if the data file exists, open it. + if (Bukkit.getOfflinePlayer(p)!=null) { + return getPlayerBankMoney(Bukkit.getOfflinePlayer(p).getUniqueId()); + } else { + log("[WARNING] Could not find Player "+p+"'s offline profile!!",1); + DebugUtils.showStackTrace(); + return -1; + } + } + } public static void givePlayerMoney(Player p, double amt) { PlayerStructure pd = (PlayerStructure)playerdata.get(p.getUniqueId()); //Found it. Read money and quit. pd.money+=amt; } - public static void givePlayerMoney(String p, double amt) { - if (Bukkit.getPlayer(p)!=null) { - givePlayerMoney(Bukkit.getPlayer(p),amt); + public static void givePlayerMoney(UUID id, double amt) { + /*PlayerStructure pd = (PlayerStructure)playerdata.get(p.getUniqueId()); + //Found it. Read money and quit. + pd.money+=amt;*/ + if (Bukkit.getPlayer(id)!=null) { + givePlayerMoney(Bukkit.getPlayer(id),amt); } else { - //See if the data file exists, open it. File config; - config = new File(TwosideKeeper.filesave,"users/"+Bukkit.getOfflinePlayer(p).getUniqueId()+".data"); + config = new File(TwosideKeeper.filesave,"users/"+id+".data"); FileConfiguration workable = YamlConfiguration.loadConfiguration(config); if (!config.exists()) { //Something bad happened if we got here. - log("[WARNING] Could not find the correct player data file for "+p+" to get money data from.",1); + log("[WARNING] Could not find the correct player data file for "+id+" to get money data from.",1); } else { double money = workable.getDouble("money"); @@ -10922,24 +10962,51 @@ public class TwosideKeeper extends JavaPlugin implements Listener { try { workable.save(config); } catch (IOException e) { - log("[WARNING] Could not find the correct player data file for "+p+" to get money data from.",1); + log("[WARNING] Could not find the correct player data file for "+id+" to get money data from.",1); e.printStackTrace(); } } } } + @Deprecated + public static void givePlayerMoney(String p, double amt) { + if (Bukkit.getPlayer(p)!=null) { + givePlayerMoney(Bukkit.getPlayer(p),amt); + } else { + //See if the data file exists, open it. + if (Bukkit.getOfflinePlayer(p)!=null) { + givePlayerMoney(Bukkit.getOfflinePlayer(p).getUniqueId(),amt); + } else { + log("[WARNING] Could not find Player "+p+"'s offline profile!!",1); + DebugUtils.showStackTrace(); + } + } + } public static void givePlayerBankMoney(Player p, double amt) { PlayerStructure pd = (PlayerStructure)playerdata.get(p.getUniqueId()); //Found it. Read money and quit. pd.bank_money+=amt; } + @Deprecated public static void givePlayerBankMoney(String p, double amt) { if (Bukkit.getPlayer(p)!=null) { givePlayerBankMoney(Bukkit.getPlayer(p),amt); } else { //See if the data file exists, open it. + if (Bukkit.getOfflinePlayer(p)!=null) { + givePlayerBankMoney(Bukkit.getOfflinePlayer(p).getUniqueId(),amt); + } else { + log("[WARNING] Could not find Player "+p+"'s offline profile!!",1); + DebugUtils.showStackTrace(); + } + } + } + public static void givePlayerBankMoney(UUID id, double amt) { + if (Bukkit.getPlayer(id)!=null) { + givePlayerBankMoney(Bukkit.getPlayer(id),amt); + } else { File config; - config = new File(TwosideKeeper.filesave,"users/"+Bukkit.getOfflinePlayer(p).getUniqueId()+".data"); + config = new File(TwosideKeeper.filesave,"users/"+id+".data"); FileConfiguration workable = YamlConfiguration.loadConfiguration(config); double money = workable.getDouble("bank_money"); @@ -10951,7 +11018,7 @@ public class TwosideKeeper extends JavaPlugin implements Listener { try { workable.save(config); } catch (IOException e) { - log("[WARNING] Could not find the correct player data file for "+p+" to get bank money data from.",1); + log("[WARNING] Could not find the correct player data file for "+id+" to get bank money data from.",1); e.printStackTrace(); } } diff --git a/src/sig/plugin/TwosideKeeper/TwosideKeeperAPI.java b/src/sig/plugin/TwosideKeeper/TwosideKeeperAPI.java index 850ed4e..7273338 100644 --- a/src/sig/plugin/TwosideKeeper/TwosideKeeperAPI.java +++ b/src/sig/plugin/TwosideKeeper/TwosideKeeperAPI.java @@ -3,6 +3,7 @@ package sig.plugin.TwosideKeeper; import java.util.Collection; import java.util.HashMap; import java.util.List; +import java.util.UUID; import org.bukkit.Location; import org.bukkit.Material; @@ -39,12 +40,26 @@ public final class TwosideKeeperAPI { public static void givePlayerMoney(Player p, double amt) { TwosideKeeper.givePlayerMoney(p, amt); } + public static void givePlayerMoney(UUID id, double amt) { + TwosideKeeper.givePlayerMoney(id, amt); + } + /** + * Use UUID version instead. + */ + @Deprecated public static void givePlayerMoney(String p, double amt) { TwosideKeeper.givePlayerMoney(p, amt); } + public static double getPlayerMoney(UUID id) { + return TwosideKeeper.getPlayerMoney(id); + } public static double getPlayerMoney(Player p) { return TwosideKeeper.getPlayerMoney(p); } + /** + * Use UUID version instead. + */ + @Deprecated public static double getPlayerMoney(String p) { return TwosideKeeper.getPlayerMoney(p); } @@ -53,12 +68,26 @@ public final class TwosideKeeperAPI { public static void givePlayerBankMoney(Player p, double amt) { TwosideKeeper.givePlayerBankMoney(p, amt); } + public static void givePlayerBankMoney(UUID id, double amt) { + TwosideKeeper.givePlayerBankMoney(id, amt); + } + /** + * Use UUID version instead. + */ + @Deprecated public static void givePlayerBankMoney(String p, double amt) { TwosideKeeper.givePlayerBankMoney(p, amt); } public static double getPlayerBankMoney(Player p) { return TwosideKeeper.getPlayerBankMoney(p); } + public static double getPlayerBankMoney(UUID id) { + return TwosideKeeper.getPlayerBankMoney(id); + } + /** + * Use UUID version instead. + */ + @Deprecated public static double getPlayerBankMoney(String p) { return TwosideKeeper.getPlayerBankMoney(p); } diff --git a/src/sig/plugin/TwosideKeeper/WorldShopManager.java b/src/sig/plugin/TwosideKeeper/WorldShopManager.java index c347082..7e8d45c 100644 --- a/src/sig/plugin/TwosideKeeper/WorldShopManager.java +++ b/src/sig/plugin/TwosideKeeper/WorldShopManager.java @@ -5,11 +5,13 @@ import java.io.IOException; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.OfflinePlayer; import org.bukkit.block.Chest; import org.bukkit.block.Sign; import org.bukkit.configuration.file.FileConfiguration; @@ -37,12 +39,12 @@ public class WorldShopManager { * @param price The unit price of the item. * @param owner Owner of the shop. */ - public WorldShop CreateWorldShop(Sign s, ItemStack item, int amt, double price, String owner) { + public WorldShop CreateWorldShop(Sign s, ItemStack item, int amt, double price, UUID owner) { //Convert the sign. return CreateWorldShop(s,item,amt,price,owner,false); } - public WorldShop CreateWorldShop(Sign s, ItemStack item, int amt, double price, String owner, boolean purchaseshop) { + public WorldShop CreateWorldShop(Sign s, ItemStack item, int amt, double price, UUID owner, boolean purchaseshop) { //Convert the sign. String[] lines = s.getLines(); WorldShop newshop = new WorldShop(item, amt, 0, price, owner, TwosideKeeper.WORLD_SHOP_ID, s.getLocation()); @@ -130,12 +132,30 @@ public class WorldShopManager { File config; config = new File(TwosideKeeper.filesave,"worldshop.data"); FileConfiguration workable = YamlConfiguration.loadConfiguration(config); - + + if (!workable.contains("uuid"+id)) { + //Update world shop to latest version. + TwosideKeeper.log("Old World Shop detected for ID "+id+". Attempting to convert...", 2); + OfflinePlayer op = Bukkit.getOfflinePlayer(workable.getString("owner"+id)); + TwosideKeeper.log("Offline Player: "+op.getName()+","+op.getUniqueId(), 0); + if (op!=null && !op.getName().equalsIgnoreCase("admin")) { + workable.set("uuid"+id, op.getUniqueId().toString()); + TwosideKeeper.log(" Converted to UUID standard. Owner is now "+op.getUniqueId()+".", 2); + } else { + TwosideKeeper.log(" WARNING ! Failed to convert this World Shop! Could not find player "+workable.getString("owner"+id)+". Converting to admin shop...", 1); + workable.set("uuid"+id, WorldShop.ADMIN_UUID.toString()); + } + try { + workable.save(config); + } catch (IOException e) { + e.printStackTrace(); + } + } if (workable.contains("locationdata"+id)) { String[] splitloc = workable.getString("locationdata"+id).split(","); - return new WorldShop(workable.getItemStack("item"+id),workable.getInt("amt"+id),workable.getInt("storedamt"+id),workable.getDouble("item_price"+id),workable.getString("owner"+id),id,new Location(Bukkit.getWorld(splitloc[0]),Integer.parseInt(splitloc[1]),Integer.parseInt(splitloc[2]),Integer.parseInt(splitloc[3]))); + return new WorldShop(workable.getItemStack("item"+id),workable.getInt("amt"+id),workable.getInt("storedamt"+id),workable.getDouble("item_price"+id),UUID.fromString(workable.getString("uuid"+id)),id,new Location(Bukkit.getWorld(splitloc[0]),Integer.parseInt(splitloc[1]),Integer.parseInt(splitloc[2]),Integer.parseInt(splitloc[3]))); } else { - return new WorldShop(workable.getItemStack("item"+id),workable.getInt("amt"+id),workable.getInt("storedamt"+id),workable.getDouble("item_price"+id),workable.getString("owner"+id),id,TwosideKeeper.TWOSIDE_LOCATION); + return new WorldShop(workable.getItemStack("item"+id),workable.getInt("amt"+id),workable.getInt("storedamt"+id),workable.getDouble("item_price"+id),UUID.fromString(workable.getString("uuid"+id)),id,TwosideKeeper.TWOSIDE_LOCATION); } } @@ -149,7 +169,7 @@ public class WorldShopManager { workable.set("item"+id,shop.GetItem()); workable.set("item_price"+id,shop.GetUnitPrice()); workable.set("amt"+id,shop.GetAmount()); - workable.set("owner"+id,shop.GetOwner()); + workable.set("uuid"+id,shop.GetOwner().toString()); workable.set("storedamt"+id,shop.GetStoredAmount()); workable.set("locationdata"+id,shop.GetLocString()); @@ -220,15 +240,15 @@ public class WorldShopManager { sessions.remove(ss); } - public void AddNewPurchase(String owner, String purchaser, ItemStack item, double price, int amt) { + public void AddNewPurchase(UUID owner, UUID purchaser, ItemStack item, double price, int amt) { purchases.add(new ShopPurchase(owner, purchaser, item, price, amt)); } - public void AddNewPurchase(String owner, String purchaser, ItemStack item, double price, int amt, boolean sell) { + public void AddNewPurchase(UUID owner, UUID purchaser, ItemStack item, double price, int amt, boolean sell) { purchases.add(new ShopPurchase(owner, purchaser, item, price, amt, sell)); } public boolean PlayerHasPurchases(Player p) { for (int i=0;i