diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/banner/CountryFlag.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/banner/CountryFlag.java index af4dfec31..d4e48144f 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/banner/CountryFlag.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/banner/CountryFlag.java @@ -8,51 +8,51 @@ import org.bukkit.inventory.ItemStack; public enum CountryFlag { - Brazil(DyeColor.GREEN, new Pattern(DyeColor.YELLOW, PatternType.RHOMBUS_MIDDLE), new Pattern(DyeColor.BLUE, PatternType.CIRCLE_MIDDLE)), - Usa(DyeColor.RED, new Pattern(DyeColor.WHITE, PatternType.STRIPE_SMALL), new Pattern(DyeColor.BLUE, PatternType.SQUARE_TOP_RIGHT)), - Canada(DyeColor.WHITE, new Pattern(DyeColor.RED, PatternType.STRIPE_TOP), new Pattern(DyeColor.RED, PatternType.STRIPE_BOTTOM), + BRAZIL(DyeColor.GREEN, new Pattern(DyeColor.YELLOW, PatternType.RHOMBUS_MIDDLE), new Pattern(DyeColor.BLUE, PatternType.CIRCLE_MIDDLE)), + USA(DyeColor.RED, new Pattern(DyeColor.WHITE, PatternType.STRIPE_SMALL), new Pattern(DyeColor.BLUE, PatternType.SQUARE_TOP_RIGHT)), + CANADA(DyeColor.WHITE, new Pattern(DyeColor.RED, PatternType.STRIPE_TOP), new Pattern(DyeColor.RED, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.RED, PatternType.CIRCLE_MIDDLE)), - Uk(DyeColor.BLUE, new Pattern(DyeColor.WHITE, PatternType.STRIPE_DOWNLEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_DOWNRIGHT), + UK(DyeColor.BLUE, new Pattern(DyeColor.WHITE, PatternType.STRIPE_DOWNLEFT), new Pattern(DyeColor.WHITE, PatternType.STRIPE_DOWNRIGHT), new Pattern(DyeColor.RED, PatternType.STRAIGHT_CROSS), new Pattern(DyeColor.RED, PatternType.CROSS)), - Ireland(DyeColor.WHITE, new Pattern(DyeColor.LIME, PatternType.STRIPE_TOP), new Pattern(DyeColor.ORANGE, PatternType.STRIPE_BOTTOM)), - Spain(DyeColor.YELLOW, new Pattern(DyeColor.RED, PatternType.STRIPE_LEFT), new Pattern(DyeColor.RED, PatternType.STRIPE_RIGHT)), - Japan(DyeColor.WHITE, new Pattern(DyeColor.RED, PatternType.CIRCLE_MIDDLE)), - South_Sudan(DyeColor.WHITE, new Pattern(DyeColor.RED, PatternType.STRIPE_LEFT), new Pattern(DyeColor.BLACK, PatternType.STRIPE_RIGHT), + IRELAND(DyeColor.WHITE, new Pattern(DyeColor.LIME, PatternType.STRIPE_TOP), new Pattern(DyeColor.ORANGE, PatternType.STRIPE_BOTTOM)), + SPAIN(DyeColor.YELLOW, new Pattern(DyeColor.RED, PatternType.STRIPE_LEFT), new Pattern(DyeColor.RED, PatternType.STRIPE_RIGHT)), + JAPAN(DyeColor.WHITE, new Pattern(DyeColor.RED, PatternType.CIRCLE_MIDDLE)), + SOUTH_SUDAN(DyeColor.WHITE, new Pattern(DyeColor.RED, PatternType.STRIPE_LEFT), new Pattern(DyeColor.BLACK, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.GREEN, PatternType.TRIANGLE_BOTTOM)), - Jamaica(DyeColor.GREEN, new Pattern(DyeColor.BLACK, PatternType.TRIANGLE_TOP), new Pattern(DyeColor.BLACK, PatternType.TRIANGLES_BOTTOM), + JAMAICA(DyeColor.GREEN, new Pattern(DyeColor.BLACK, PatternType.TRIANGLE_TOP), new Pattern(DyeColor.BLACK, PatternType.TRIANGLES_BOTTOM), new Pattern(DyeColor.YELLOW, PatternType.CROSS)), - Italy(DyeColor.WHITE, new Pattern(DyeColor.RED, PatternType.STRIPE_TOP), new Pattern(DyeColor.GREEN, PatternType.STRIPE_BOTTOM)), - Senegal(DyeColor.YELLOW, new Pattern(DyeColor.RED, PatternType.STRIPE_TOP), new Pattern(DyeColor.GREEN, PatternType.STRIPE_BOTTOM), + ITALY(DyeColor.WHITE, new Pattern(DyeColor.RED, PatternType.STRIPE_TOP), new Pattern(DyeColor.GREEN, PatternType.STRIPE_BOTTOM)), + SENEGAL(DyeColor.YELLOW, new Pattern(DyeColor.RED, PatternType.STRIPE_TOP), new Pattern(DyeColor.GREEN, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.GREEN, PatternType.CIRCLE_MIDDLE)), - France(DyeColor.WHITE, new Pattern(DyeColor.RED, PatternType.STRIPE_TOP), new Pattern(DyeColor.BLUE, PatternType.STRIPE_BOTTOM)), - India(DyeColor.WHITE, new Pattern(DyeColor.ORANGE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.GREEN, PatternType.STRIPE_RIGHT), + FRANCE(DyeColor.WHITE, new Pattern(DyeColor.RED, PatternType.STRIPE_TOP), new Pattern(DyeColor.BLUE, PatternType.STRIPE_BOTTOM)), + INDIA(DyeColor.WHITE, new Pattern(DyeColor.ORANGE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.GREEN, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.BLUE, PatternType.CIRCLE_MIDDLE)), - Belgium(DyeColor.YELLOW, new Pattern(DyeColor.BLACK, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.RED, PatternType.STRIPE_TOP)), - England(DyeColor.WHITE, new Pattern(DyeColor.RED, PatternType.STRAIGHT_CROSS)), - Austria(DyeColor.RED, new Pattern(DyeColor.WHITE, PatternType.STRIPE_CENTER)), - Armenia(DyeColor.RED, new Pattern(DyeColor.BLUE, PatternType.STRIPE_CENTER), new Pattern(DyeColor.ORANGE, PatternType.STRIPE_RIGHT)), - Argentina(DyeColor.LIGHT_BLUE, new Pattern(DyeColor.WHITE, PatternType.STRIPE_CENTER), new Pattern(DyeColor.YELLOW, PatternType.CIRCLE_MIDDLE)), - Greece(DyeColor.LIGHT_BLUE, new Pattern(DyeColor.WHITE, PatternType.STRIPE_SMALL), new Pattern(DyeColor.LIGHT_BLUE, PatternType.SQUARE_BOTTOM_LEFT)), - Czech_Republic(DyeColor.WHITE, new Pattern(DyeColor.RED, PatternType.HALF_VERTICAL_MIRROR), new Pattern(DyeColor.BLUE, PatternType.TRIANGLE_BOTTOM)), - Romania(DyeColor.YELLOW, new Pattern(DyeColor.BLUE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.RED, PatternType.STRIPE_TOP)), - Honduras(DyeColor.WHITE, new Pattern(DyeColor.BLUE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.BLUE, PatternType.STRIPE_RIGHT)), - Algeria(DyeColor.WHITE, new Pattern(DyeColor.LIME, PatternType.HALF_HORIZONTAL_MIRROR), new Pattern(DyeColor.RED, PatternType.CIRCLE_MIDDLE)), - Portugal(DyeColor.RED, new Pattern(DyeColor.GREEN, PatternType.STRIPE_TOP), new Pattern(DyeColor.YELLOW, PatternType.CIRCLE_MIDDLE)), - Bahrain(DyeColor.RED, new Pattern(DyeColor.WHITE, PatternType.TRIANGLES_BOTTOM)), - Germany(DyeColor.RED, new Pattern(DyeColor.BLACK, PatternType.STRIPE_LEFT), new Pattern(DyeColor.YELLOW, PatternType.STRIPE_RIGHT)), - Gabon(DyeColor.YELLOW, new Pattern(DyeColor.BLUE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.LIME, PatternType.STRIPE_LEFT)), - Scotland(DyeColor.BLUE, new Pattern(DyeColor.WHITE, PatternType.CROSS)), - Peru(DyeColor.WHITE, new Pattern(DyeColor.RED, PatternType.STRIPE_TOP), new Pattern(DyeColor.RED, PatternType.STRIPE_BOTTOM)), - Tanzania(DyeColor.LIME, new Pattern(DyeColor.LIGHT_BLUE, PatternType.DIAGONAL_RIGHT), new Pattern(DyeColor.BLACK, PatternType.STRIPE_DOWNLEFT)), - Morocco(DyeColor.RED, new Pattern(DyeColor.GREEN, PatternType.CIRCLE_MIDDLE)), - Solomon_Islands(DyeColor.GREEN, new Pattern(DyeColor.BLUE, PatternType.DIAGONAL_LEFT_MIRROR), new Pattern(DyeColor.YELLOW, PatternType.STRIPE_DOWNRIGHT)), - Switzerland(DyeColor.RED, new Pattern(DyeColor.WHITE, PatternType.STRAIGHT_CROSS), new Pattern(DyeColor.RED, PatternType.STRIPE_BOTTOM), + BELGIUM(DyeColor.YELLOW, new Pattern(DyeColor.BLACK, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.RED, PatternType.STRIPE_TOP)), + ENGLAND(DyeColor.WHITE, new Pattern(DyeColor.RED, PatternType.STRAIGHT_CROSS)), + AUSTRIA(DyeColor.RED, new Pattern(DyeColor.WHITE, PatternType.STRIPE_CENTER)), + ARMENIA(DyeColor.RED, new Pattern(DyeColor.BLUE, PatternType.STRIPE_CENTER), new Pattern(DyeColor.ORANGE, PatternType.STRIPE_RIGHT)), + ARGENTINA(DyeColor.LIGHT_BLUE, new Pattern(DyeColor.WHITE, PatternType.STRIPE_CENTER), new Pattern(DyeColor.YELLOW, PatternType.CIRCLE_MIDDLE)), + GREECE(DyeColor.LIGHT_BLUE, new Pattern(DyeColor.WHITE, PatternType.STRIPE_SMALL), new Pattern(DyeColor.LIGHT_BLUE, PatternType.SQUARE_BOTTOM_LEFT)), + CZECH_REPUBLIC(DyeColor.WHITE, new Pattern(DyeColor.RED, PatternType.HALF_VERTICAL_MIRROR), new Pattern(DyeColor.BLUE, PatternType.TRIANGLE_BOTTOM)), + ROMANIA(DyeColor.YELLOW, new Pattern(DyeColor.BLUE, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.RED, PatternType.STRIPE_TOP)), + HONDURAS(DyeColor.WHITE, new Pattern(DyeColor.BLUE, PatternType.STRIPE_LEFT), new Pattern(DyeColor.BLUE, PatternType.STRIPE_RIGHT)), + ALGERIA(DyeColor.WHITE, new Pattern(DyeColor.LIME, PatternType.HALF_HORIZONTAL_MIRROR), new Pattern(DyeColor.RED, PatternType.CIRCLE_MIDDLE)), + PORTUGAL(DyeColor.RED, new Pattern(DyeColor.GREEN, PatternType.STRIPE_TOP), new Pattern(DyeColor.YELLOW, PatternType.CIRCLE_MIDDLE)), + BAHRAIN(DyeColor.RED, new Pattern(DyeColor.WHITE, PatternType.TRIANGLES_BOTTOM)), + GERMANY(DyeColor.RED, new Pattern(DyeColor.BLACK, PatternType.STRIPE_LEFT), new Pattern(DyeColor.YELLOW, PatternType.STRIPE_RIGHT)), + GABON(DyeColor.YELLOW, new Pattern(DyeColor.BLUE, PatternType.STRIPE_RIGHT), new Pattern(DyeColor.LIME, PatternType.STRIPE_LEFT)), + SCOTLAND(DyeColor.BLUE, new Pattern(DyeColor.WHITE, PatternType.CROSS)), + PERU(DyeColor.WHITE, new Pattern(DyeColor.RED, PatternType.STRIPE_TOP), new Pattern(DyeColor.RED, PatternType.STRIPE_BOTTOM)), + TANZANIA(DyeColor.LIME, new Pattern(DyeColor.LIGHT_BLUE, PatternType.DIAGONAL_RIGHT), new Pattern(DyeColor.BLACK, PatternType.STRIPE_DOWNLEFT)), + MOROCCO(DyeColor.RED, new Pattern(DyeColor.GREEN, PatternType.CIRCLE_MIDDLE)), + SOLOMON_ISLANDS(DyeColor.GREEN, new Pattern(DyeColor.BLUE, PatternType.DIAGONAL_LEFT_MIRROR), new Pattern(DyeColor.YELLOW, PatternType.STRIPE_DOWNRIGHT)), + SWITZERLAND(DyeColor.RED, new Pattern(DyeColor.WHITE, PatternType.STRAIGHT_CROSS), new Pattern(DyeColor.RED, PatternType.STRIPE_BOTTOM), new Pattern(DyeColor.RED, PatternType.STRIPE_TOP)), - Finland(DyeColor.BLUE, new Pattern(DyeColor.WHITE, PatternType.SQUARE_BOTTOM_LEFT), new Pattern(DyeColor.WHITE, PatternType.SQUARE_BOTTOM_RIGHT), + FINLAND(DyeColor.BLUE, new Pattern(DyeColor.WHITE, PatternType.SQUARE_BOTTOM_LEFT), new Pattern(DyeColor.WHITE, PatternType.SQUARE_BOTTOM_RIGHT), new Pattern(DyeColor.WHITE, PatternType.HALF_HORIZONTAL), new Pattern(DyeColor.BLUE, PatternType.STRIPE_CENTER)), - South_Africa(DyeColor.WHITE, new Pattern(DyeColor.BLUE, PatternType.HALF_VERTICAL_MIRROR), new Pattern(DyeColor.RED, PatternType.HALF_VERTICAL), + SOUTH_AFRICA(DyeColor.WHITE, new Pattern(DyeColor.BLUE, PatternType.HALF_VERTICAL_MIRROR), new Pattern(DyeColor.RED, PatternType.HALF_VERTICAL), new Pattern(DyeColor.GREEN, PatternType.STRIPE_CENTER), new Pattern(DyeColor.BLACK, PatternType.TRIANGLE_BOTTOM)), - Poland(DyeColor.RED, new Pattern(DyeColor.WHITE, PatternType.HALF_VERTICAL_MIRROR)); + POLAND(DyeColor.RED, new Pattern(DyeColor.WHITE, PatternType.HALF_VERTICAL_MIRROR)); private DyeColor _baseColor; private Pattern[] _patterns; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/MiniClientPlugin.java b/Plugins/Mineplex.Core/src/mineplex/core/MiniClientPlugin.java index 391e86a54..d90d08fe5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/MiniClientPlugin.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/MiniClientPlugin.java @@ -35,7 +35,7 @@ public abstract class MiniClientPlugin extends MiniPlug synchronized (_clientDataLock) { if (!_clientData.containsKey(name)) - _clientData.put(name, AddPlayer(name)); + _clientData.put(name, addPlayer(name)); return _clientData.get(name); } @@ -66,5 +66,5 @@ public abstract class MiniClientPlugin extends MiniPlug } } - protected abstract DataType AddPlayer(String player); + protected abstract DataType addPlayer(String player); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManager.java b/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManager.java index 045d6f42f..804ba1931 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/benefit/BenefitManager.java @@ -67,7 +67,7 @@ public class BenefitManager extends MiniDbClientPlugin } @Override - protected BenefitData AddPlayer(String player) + protected BenefitData addPlayer(String player) { return new BenefitData(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java index 0fd3396b7..45736c3d6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java @@ -989,7 +989,7 @@ public class BonusManager extends MiniClientPlugin implements I } @Override - protected BonusClientData AddPlayer(String player) + protected BonusClientData addPlayer(String player) { return new BonusClientData(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/YoutubeButton.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/YoutubeButton.java index 475871234..dd741b450 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/YoutubeButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/YoutubeButton.java @@ -71,7 +71,7 @@ public class YoutubeButton implements GuiItem message = "Click here to visit our YouTube page!"; } - new JsonMessage(C.cAquaB + message).click(ClickEvent.OPEN_URL, "https://www.youtube.com/mineplexgamesofficial").sendToPlayer(_player); + new JsonMessage(C.cAquaB + message).click(ClickEvent.OPEN_URL, "http://youtube.com/mineplexgamesofficial?sub_confirmation=1").sendToPlayer(_player); } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterManager.java b/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterManager.java index a8b79473f..4254f6594 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/boosters/BoosterManager.java @@ -6,6 +6,7 @@ import mineplex.core.account.CoreClientManager; import mineplex.core.boosters.command.BoosterCommand; import mineplex.core.boosters.event.BoosterActivateEvent; import mineplex.core.boosters.event.BoosterExpireEvent; +import mineplex.core.boosters.event.BoosterItemGiveEvent; import mineplex.core.boosters.event.BoosterUpdateEvent; import mineplex.core.boosters.gui.BoosterShop; import mineplex.core.boosters.redis.BoosterUpdateRepository; @@ -14,6 +15,7 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.Callback; import mineplex.core.common.util.UtilGear; import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilServer; import mineplex.core.donation.DonationManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.itemstack.ItemStackFactory; @@ -361,6 +363,11 @@ public class BoosterManager extends MiniPlugin { if (_giveInterfaceItem && !UtilGear.isMat(player.getInventory().getItem(INTERFACE_SLOT), Material.EMERALD)) { + BoosterItemGiveEvent event = new BoosterItemGiveEvent(player); + UtilServer.CallEvent(event); + if (event.isCancelled()) + return; + player.getInventory().setItem(INTERFACE_SLOT, INTERFACE_ITEM); UtilInv.Update(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/boosters/event/BoosterItemGiveEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/boosters/event/BoosterItemGiveEvent.java new file mode 100644 index 000000000..90636623b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/boosters/event/BoosterItemGiveEvent.java @@ -0,0 +1,48 @@ +package mineplex.core.boosters.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * Called when a player is about to receive a booster gem. If cancelled the player will not receive said gem + */ +public class BoosterItemGiveEvent extends Event implements Cancellable +{ + private Player _player; + private boolean _cancelled; + + public BoosterItemGiveEvent(Player player) + { + this._player = player; + } + + public Player getPlayer() + { + return this._player; + } + + public boolean isCancelled() + { + return this._cancelled; + } + + public void setCancelled(boolean cancelled) + { + this._cancelled = cancelled; + } + + private static final HandlerList _handlers = new HandlerList(); + + private static HandlerList getHandlerList() + { + return _handlers; + } + + @Override + public HandlerList getHandlers() + { + return getHandlerList(); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/boosters/tips/BoosterTipManager.java b/Plugins/Mineplex.Core/src/mineplex/core/boosters/tips/BoosterTipManager.java index 1b5603ccd..be7f28ca9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/boosters/tips/BoosterTipManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/boosters/tips/BoosterTipManager.java @@ -110,7 +110,7 @@ public class BoosterTipManager extends MiniDbClientPlugin } @Override - protected PlayerTipData AddPlayer(String player) + protected PlayerTipData addPlayer(String player) { return new PlayerTipData(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java index 802b81b5d..11e4cf821 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/brawl/fountain/FountainManager.java @@ -51,7 +51,7 @@ public class FountainManager extends MiniPlugin World world = Bukkit.getWorlds().get(0);//-43.5, 66, -38.5 - int goal = !new File("eu.dat").exists() ? 300000000 : 5000000; + int goal = !new File("eu.dat").exists() ? 200000000 : 20000000; _gemFountain = new Fountain(new Location(world, -32.5, 72, -23.5), new Location(world, -43.5, 67, -38.5), C.cGreen + "Gem Fountain", "GemFountain_01", goal, this, clientManager, donationManager, _hologramManager, _statsManager); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/CosmeticManager.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/CosmeticManager.java index 0f0686a42..8da12b5d9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/CosmeticManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/CosmeticManager.java @@ -180,7 +180,7 @@ public class CosmeticManager extends MiniPlugin { _gadgetManager.disableAll(); _mountManager.DisableAll(); - _petManager.DisableAll(); + _petManager.disableAll(); } public void setHideParticles(boolean b) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/PetSorter.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/PetSorter.java index 8d339374e..64de96efc 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/PetSorter.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/PetSorter.java @@ -8,7 +8,7 @@ public class PetSorter implements Comparator { public int compare(Pet a, Pet b) { - if (a.GetPetType().getTypeId() < b.GetPetType().getTypeId()) + if (a.getPetType().getTypeId() < b.getPetType().getTypeId()) return -1; return 1; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/activate/ActivatePetButton.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/activate/ActivatePetButton.java index 2f1dffd96..61539e368 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/activate/ActivatePetButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/activate/ActivatePetButton.java @@ -23,7 +23,7 @@ public class ActivatePetButton implements IButton public void onClick(Player player, ClickType clickType) { _page.playAcceptSound(player); - _page.getPlugin().getPetManager().AddPetOwner(player, _pet.GetPetType(), player.getLocation()); + _page.getPlugin().getPetManager().addPetOwner(player, _pet.getPetType(), player.getLocation()); _page.getShop().openPageForPlayer(player, new Menu(_page.getPlugin(), _page.getShop(), _page.getClientManager(), _page.getDonationManager(), player)); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/deactivate/DeactivatePetButton.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/deactivate/DeactivatePetButton.java index 2b3fb0c61..1fc5c2af1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/deactivate/DeactivatePetButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/deactivate/DeactivatePetButton.java @@ -21,7 +21,7 @@ public class DeactivatePetButton implements IButton public void onClick(Player player, ClickType clickType) { _page.playAcceptSound(player); - _petManager.RemovePet(player, true); + _petManager.removePet(player, true); _page.refresh(); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/open/OpenPets.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/open/OpenPets.java index 711679214..a8ac5e906 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/open/OpenPets.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/open/OpenPets.java @@ -24,7 +24,7 @@ public class OpenPets implements IButton else { _menu.playAcceptSound(player); - _menu.getPlugin().getPetManager().RemovePet(player, true); + _menu.getPlugin().getPetManager().removePet(player, true); _menu.refresh(); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/GadgetPage.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/GadgetPage.java index 154188ad8..b56d4cf8e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/GadgetPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/GadgetPage.java @@ -4,7 +4,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.banner.CountryFlag; +import mineplex.core.gadget.event.GadgetChangeEvent; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -291,7 +293,7 @@ public class GadgetPage extends ShopPageBase { if (gadget.getCost(CurrencyType.TREASURE_SHARD) == -8) { - gadgetItemStack = CountryFlag.Usa.getBanner(); + gadgetItemStack = CountryFlag.USA.getBanner(); BannerMeta bannerMeta = (BannerMeta) gadgetItemStack.getItemMeta(); bannerMeta.setDisplayName(C.cGreen + C.Bold + gadget.getName()); bannerMeta.setLore(meta.getLore()); @@ -314,7 +316,7 @@ public class GadgetPage extends ShopPageBase { if (gadget.getCost(CurrencyType.TREASURE_SHARD) == -8) { - gadgetItemStack = CountryFlag.Usa.getBanner(); + gadgetItemStack = CountryFlag.USA.getBanner(); BannerMeta bannerMeta = (BannerMeta) gadgetItemStack.getItemMeta(); bannerMeta.setDisplayName(C.cGreen + C.Bold + gadget.getName()); bannerMeta.setLore(meta.getLore()); @@ -393,6 +395,9 @@ public class GadgetPage extends ShopPageBase playAcceptSound(player); gadget.enable(player); + GadgetChangeEvent gadgetChangeEvent = new GadgetChangeEvent(player, gadget, + GadgetChangeEvent.GadgetState.ENABLED); + UtilServer.getPluginManager().callEvent(gadgetChangeEvent); refresh(); } @@ -409,6 +414,9 @@ public class GadgetPage extends ShopPageBase { playAcceptSound(player); gadget.disable(player); + GadgetChangeEvent gadgetChangeEvent = new GadgetChangeEvent(player, gadget, + GadgetChangeEvent.GadgetState.DISABLED); + UtilServer.getPluginManager().callEvent(gadgetChangeEvent); refresh(); } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/Menu.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/Menu.java index a12a14307..51ed4dd84 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/Menu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/Menu.java @@ -100,7 +100,7 @@ public class Menu extends ShopPageBase Mount mountActive = getPlugin().getMountManager().getActive(getPlayer()); for (Mount mount : getPlugin().getMountManager().getMounts()) { - if (getDonationManager().Get(getPlayer()).OwnsUnknownPackage(mount.getName()) || mount.hasMount(getPlayer())) + if (getDonationManager().Get(getPlayer().getName()).OwnsUnknownPackage(mount.getName())) { mountOwned++; } @@ -110,17 +110,17 @@ public class Menu extends ShopPageBase int petOwned = 0; int petMax = 0; - for (Pet pet : getPlugin().getPetManager().GetFactory().GetPets()) + for (Pet pet : getPlugin().getPetManager().getFactory().GetPets()) { - NautHashMap pets = getPlugin().getPetManager().Get(getPlayer()).GetPets(); - if (pets != null && pets.containsKey(pet.GetPetType())) + NautHashMap pets = getPlugin().getPetManager().Get(getPlayer()).getPets(); + if (pets != null && pets.containsKey(pet.getPetType())) { petOwned++; } petMax++; } - Creature petActive = getPlugin().getPetManager().GetPet(getPlayer()); + Creature petActive = getPlugin().getPetManager().getPet(getPlayer()); GadgetType type = GadgetType.PARTICLE; String[] lore = getLore(ownedCount.get(type), maxCount.get(type), "Show everyone how cool you are with swirly particles that follow you when you walk!", "Visible Everywhere", enabled.get(type)); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/PetPage.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/PetPage.java index 3b278c855..8ecd60944 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/PetPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/PetPage.java @@ -49,7 +49,7 @@ public class PetPage extends ShopPageBase { int slot = 19; - List pets = new ArrayList(getPlugin().getPetManager().GetFactory().GetPets()); + List pets = new ArrayList(getPlugin().getPetManager().getFactory().GetPets()); Collections.sort(pets, new PetSorter()); @@ -61,7 +61,7 @@ public class PetPage extends ShopPageBase itemLore.add(C.cGray + "Your very own " + pet.getName() + "!"); //Chest Unlocks - if (!getPlugin().getPetManager().Get(getPlayer()).GetPets().containsKey(pet.GetPetType())) + if (!getPlugin().getPetManager().Get(getPlayer()).getPets().containsKey(pet.getPetType())) { if (pet.getCost(CurrencyType.TREASURE_SHARD) == -1) { @@ -113,21 +113,21 @@ public class PetPage extends ShopPageBase } //Owned - if (getPlugin().getPetManager().Get(getPlayer()).GetPets().containsKey(pet.GetPetType())) + if (getPlugin().getPetManager().Get(getPlayer()).getPets().containsKey(pet.getPetType())) { - String petName = getPlugin().getPetManager().Get(getPlayer()).GetPets().get(pet.GetPetType()); + String petName = getPlugin().getPetManager().Get(getPlayer()).getPets().get(pet.getPetType()); if (petName == null) { petName = pet.getName(); } - if (getPlugin().getPetManager().hasActivePet(getPlayer().getName()) && getPlugin().getPetManager().getActivePet(getPlayer().getName()).getType() == pet.GetPetType()) + if (getPlugin().getPetManager().hasActivePet(getPlayer().getName()) && getPlugin().getPetManager().getActivePet(getPlayer().getName()).getType() == pet.getPetType()) { itemLore.add(C.cBlack); itemLore.add(C.cGreen + "Click to Disable"); - addButton(slot, new ShopItem(Material.MONSTER_EGG, (byte) pet.GetPetType().getTypeId(), - pet.GetPetName() + " (" + C.cWhite + petName + C.cGreen + ")", + addButton(slot, new ShopItem(Material.MONSTER_EGG, (byte) pet.getPetType().getTypeId(), + pet.getPetName() + " (" + C.cWhite + petName + C.cGreen + ")", itemLore.toArray(new String[itemLore.size()]), 1, false, false), new DeactivatePetButton(this, getPlugin().getPetManager())); addGlow(slot); @@ -137,8 +137,8 @@ public class PetPage extends ShopPageBase itemLore.add(C.cBlack); itemLore.add(C.cGreen + "Click to Enable"); - addButton(slot, new ShopItem(Material.MONSTER_EGG, (byte) pet.GetPetType().getTypeId(), - pet.GetPetName() + " (" + C.cWhite + petName + C.cGreen + ")", + addButton(slot, new ShopItem(Material.MONSTER_EGG, (byte) pet.getPetType().getTypeId(), + pet.getPetName() + " (" + C.cWhite + petName + C.cGreen + ")", itemLore.toArray(new String[itemLore.size()]), 1, false, false), new ActivatePetButton(pet, this)); } } @@ -156,18 +156,18 @@ public class PetPage extends ShopPageBase itemLore.add(C.cBlack); itemLore.add(C.cGreen + "Click to Purchase"); - addButton(slot, new ShopItem(Material.INK_SACK, (byte) 8, pet.GetPetName(), itemLore.toArray(new String[itemLore.size()]), 1, true, false), new PetButton(pet, this)); + addButton(slot, new ShopItem(Material.INK_SACK, (byte) 8, pet.getPetName(), itemLore.toArray(new String[itemLore.size()]), 1, true, false), new PetButton(pet, this)); } else if (pet.getCost(CurrencyType.TREASURE_SHARD) > 0) { itemLore.add(C.cBlack); itemLore.add(C.cRed + "Not enough Treasure Shards."); - setItem(slot, new ShopItem(Material.INK_SACK, (byte)8, pet.GetPetName(), itemLore.toArray(new String[itemLore.size()]), 1, true, false)); + setItem(slot, new ShopItem(Material.INK_SACK, (byte)8, pet.getPetName(), itemLore.toArray(new String[itemLore.size()]), 1, true, false)); } else { - setItem(slot, new ShopItem(Material.INK_SACK, (byte)8, pet.GetPetName(), itemLore.toArray(new String[itemLore.size()]), 1, true, false)); + setItem(slot, new ShopItem(Material.INK_SACK, (byte)8, pet.getPetName(), itemLore.toArray(new String[itemLore.size()]), 1, true, false)); } } @@ -178,7 +178,7 @@ public class PetPage extends ShopPageBase } slot = 49; - for (PetExtra petExtra : getPlugin().getPetManager().GetFactory().GetPetExtras()) + for (PetExtra petExtra : getPlugin().getPetManager().getFactory().GetPetExtras()) { List itemLore = new ArrayList(); @@ -233,7 +233,7 @@ public class PetPage extends ShopPageBase public void deactivatePet(Player player) { playAcceptSound(player); - getPlugin().getPetManager().RemovePet(player, true); + getPlugin().getPetManager().removePet(player, true); refresh(); } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/PetTagPage.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/PetTagPage.java index 4bc7ac740..27997f3a8 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/PetTagPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/PetTagPage.java @@ -108,8 +108,8 @@ public class PetTagPage extends ShopPageBase token.AccountId = PlayerCache.getInstance().getPlayer(getPlayer().getUniqueId()).getAccountId(); token.Name = getPlayer().getName(); - token.PetType = _pet.GetPetType().toString(); - token.PetId = _pet.GetPetType().ordinal(); + token.PetType = _pet.getPetType().toString(); + token.PetId = _pet.getPetType().ordinal(); token.PetName = _tagName; PetToken petToken = new PetToken(); @@ -117,16 +117,16 @@ public class PetTagPage extends ShopPageBase if (_petPurchase) { - getPlugin().getPetManager().GetRepository().AddPet(token); - getPlugin().getPetManager().addPetOwnerToQueue(getPlayer().getName(), _pet.GetPetType()); + getPlugin().getPetManager().getRepository().AddPet(token); + getPlugin().getPetManager().addPetOwnerToQueue(getPlayer().getName(), _pet.getPetType()); } else { - getPlugin().getPetManager().GetRepository().UpdatePet(token); + getPlugin().getPetManager().getRepository().UpdatePet(token); getPlugin().getPetManager().addRenamePetToQueue(getPlayer().getName(), token.PetName); } - getPlugin().getPetManager().Get(getPlayer()).GetPets().put(_pet.GetPetType(), token.PetName); + getPlugin().getPetManager().Get(getPlayer()).getPets().put(_pet.getPetType(), token.PetName); getShop().openPageForPlayer(getPlayer(), new Menu(getPlugin(), getShop(), getClientManager(), getDonationManager(), getPlayer())); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/customdata/CustomDataManager.java b/Plugins/Mineplex.Core/src/mineplex/core/customdata/CustomDataManager.java index 26652d24a..45893a07d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/customdata/CustomDataManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/customdata/CustomDataManager.java @@ -43,7 +43,7 @@ public class CustomDataManager extends MiniDbClientPlugin } @Override - protected PlayerCustomData AddPlayer(String player) + protected PlayerCustomData addPlayer(String player) { return new PlayerCustomData(_repository); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTask.java b/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTask.java index da5c6c7c0..d407ec093 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTask.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTask.java @@ -58,7 +58,7 @@ public class DelayedTask extends MiniClientPlugin } @Override - protected DelayedTaskClient AddPlayer(String player) + protected DelayedTaskClient addPlayer(String player) { return new DelayedTaskClient(Bukkit.getPlayer(player)); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java index b5708c16e..fd0862c9d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java @@ -518,7 +518,7 @@ public class DonationManager extends MiniDbClientPlugin } @Override - protected Donor AddPlayer(String player) + protected Donor addPlayer(String player) { return new Donor(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloManager.java b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloManager.java index 4ba9e6932..cbfec07b9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/elo/EloManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/elo/EloManager.java @@ -114,7 +114,7 @@ public class EloManager extends MiniDbClientPlugin } @Override - protected EloClientData AddPlayer(String player) + protected EloClientData addPlayer(String player) { return new EloClientData(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/energy/Energy.java b/Plugins/Mineplex.Core/src/mineplex/core/energy/Energy.java index 313bde55d..51849c397 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/energy/Energy.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/energy/Energy.java @@ -137,7 +137,7 @@ public class Energy extends MiniClientPlugin } @Override - protected ClientEnergy AddPlayer(String player) + protected ClientEnergy addPlayer(String player) { return new ClientEnergy(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookManager.java b/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookManager.java index 054ac2c79..4f1e56d17 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookManager.java @@ -106,7 +106,7 @@ public class FacebookManager extends MiniDbClientPlugin } @Override - protected FacebookClient AddPlayer(String player) + protected FacebookClient addPlayer(String player) { return new FacebookClient(false); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java b/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java index 4e64f95b1..355aa3407 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/friend/FriendManager.java @@ -70,7 +70,7 @@ public class FriendManager extends MiniDbClientPlugin } @Override - protected FriendData AddPlayer(String player) + protected FriendData addPlayer(String player) { return new FriendData(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java index f8c68e0ec..f4f95e586 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java @@ -4,6 +4,7 @@ import java.util.*; import java.util.function.Predicate; import mineplex.core.gadget.commands.LockCosmeticsCommand; +import mineplex.core.gadget.event.GadgetChangeEvent; import mineplex.core.gadget.event.GadgetEnableEvent; import mineplex.core.gadget.gadgets.arrowtrail.freedom.ArrowTrailFreedom; import mineplex.core.gadget.gadgets.death.freedom.DeathFreedom; @@ -660,10 +661,14 @@ public class GadgetManager extends MiniPlugin } } - public void disableAll(Player player, boolean callEvent) + public void disableAll(Player player, boolean winRooms) { for (GadgetType gadgetType : _gadgets.keySet()) { + if (gadgetType == GadgetType.WIN_EFFECT && winRooms) + { + continue; + } for (Gadget gadget : _gadgets.get(gadgetType)) { gadget.disable(player); @@ -776,7 +781,9 @@ public class GadgetManager extends MiniPlugin @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - saveGadgets(event.getPlayer()); + //saveGadgets(event.getPlayer()); + event.getPlayer().setWalkSpeed(0.2f); + event.getPlayer().setFlySpeed(0.1f); disableAll(event.getPlayer(), false); _lastMove.remove(event.getPlayer()); _playerActiveGadgetMap.remove(event.getPlayer()); @@ -914,89 +921,57 @@ public class GadgetManager extends MiniPlugin event.setCancelled(true); } - private void saveGadgets(Player player) + @EventHandler + private void saveGadget(GadgetChangeEvent event) { - if (player.getGameMode() == GameMode.SPECTATOR) - return; - Map cache = new HashMap<>(); - for (Gadget gadget : getAllGadgets()) + Gadget gadget = event.getGadget(); + if (gadget != null) { + String value = "disabled", key = ""; GadgetType gadgetType = gadget.getGadgetType(); - if (gadget.ownsGadget(player)) - { - switch (gadgetType) - { - case MUSIC_DISC: - case ITEM: - case MORPH: - case BALLOON: - break; - case COSTUME: - OutfitGadget outfitGadget = (OutfitGadget) gadget; - String key = "activeCostume" + outfitGadget.getSlot().getDatabaseKey(); - if (cache.containsKey(key)) - continue; - if (outfitGadget.isActive(player)) - cache.put(key, outfitGadget.getName()); - break; - case GAME_MODIFIER: - GameModifierGadget gameModifierGadget = (GameModifierGadget) gadget; - if (gameModifierGadget.canAllowMultiple()) - { - if (cache.containsKey(gadget.getName())) - continue; - cache.put(gadget.getName(), (gadget.isActive(player)) ? "enabled" : "disabled"); - } else - { - String dataKey = "activeModifier" + gameModifierGadget.getGameType().getName().replace(" ", ""); - if (cache.containsKey(dataKey)) - continue; - if (gadget.isActive(player)) - cache.put(dataKey, gadget.getName()); - } - break; - default: - if (cache.containsKey(gadgetType.getDatabaseKey())) - continue; - if (gadget.isActive(player)) - cache.put(gadgetType.getDatabaseKey(), gadget.getName()); - break; - } - } - } - cache = updateDefaultGadgets(cache); - _userGadgetPersistence.save(player, cache); - } - - private Map updateDefaultGadgets(Map cache) - { - for (GadgetType gadgetType : GadgetType.values()) - { - if (gadgetType == GadgetType.MUSIC_DISC || gadgetType == GadgetType.ITEM - || gadgetType == GadgetType.MORPH || gadgetType == GadgetType.BALLOON - || gadgetType == GadgetType.GAME_MODIFIER) - continue; - if (!cache.containsKey(gadgetType.getDatabaseKey())) + switch (gadgetType) { - String key = gadgetType.getDatabaseKey(); - if (gadgetType.equals(GadgetType.COSTUME)) - { - for (ArmorSlot armorSlot : ArmorSlot.values()) + case MUSIC_DISC: + case ITEM: + case MORPH: + case BALLOON: + return; + case COSTUME: + OutfitGadget outfitGadget = (OutfitGadget) gadget; + key = "activeCostume" + outfitGadget.getSlot().getDatabaseKey(); + if (event.getGadgetState() == GadgetChangeEvent.GadgetState.ENABLED) { - key = "activeCostume" + armorSlot.getDatabaseKey(); - if (!cache.containsKey(key)) + value = outfitGadget.getName(); + } + break; + case GAME_MODIFIER: + GameModifierGadget gameModifierGadget = (GameModifierGadget) gadget; + if (gameModifierGadget.canAllowMultiple()) + { + key = gameModifierGadget.getName(); + if (event.getGadgetState() == GadgetChangeEvent.GadgetState.ENABLED) { - cache.put(key, "disabled"); + value = "enabled"; } } - } - else - { - cache.put(key, "disabled"); - } + else + { + key = "activeModifier" + gameModifierGadget.getGameType().getName().replace(" ", ""); + if (event.getGadgetState() == GadgetChangeEvent.GadgetState.ENABLED) + { + value = gameModifierGadget.getName(); + } + } + break; + default: + key = gadgetType.getDatabaseKey(); + if (event.getGadgetState() == GadgetChangeEvent.GadgetState.ENABLED) + { + value = gadget.getName(); + } } + _userGadgetPersistence.save(event.getPlayer(), key, value); } - return cache; } public boolean isKitModifierActive(KitModifier kitModifier, Player player) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/commands/LockCosmeticsCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/commands/LockCosmeticsCommand.java index 7137b9def..1fc07c933 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/commands/LockCosmeticsCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/commands/LockCosmeticsCommand.java @@ -2,12 +2,17 @@ package mineplex.core.gadget.commands; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; +import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilText; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.GadgetType; +import mineplex.core.inventory.ClientItem; +import mineplex.core.inventory.data.Item; import mineplex.core.mount.Mount; +import mineplex.core.pet.Pet; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -28,7 +33,7 @@ public class LockCosmeticsCommand extends CommandBase // Removes all cosmetic types if (args.length == 0) { - addCosmetics(null, caller); + lockCosmetics(null, caller); } // Removes specific type else @@ -36,8 +41,16 @@ public class LockCosmeticsCommand extends CommandBase String type = args[0]; if (type.equalsIgnoreCase("all")) { - addCosmetics(null, caller); + lockCosmetics(null, caller); } + else if (type.equalsIgnoreCase("pet")) + { + lockPets(caller); + } + else if (type.equalsIgnoreCase("mount")) + { + lockMounts(caller); + } else { GadgetType gadgetType = GadgetType.valueOf(type); @@ -47,27 +60,74 @@ public class LockCosmeticsCommand extends CommandBase } else { - addCosmetics(gadgetType, caller); + lockCosmetics(gadgetType, caller); } } } } - private void addCosmetics(GadgetType gadgetType, Player caller) + private void lockCosmetics(GadgetType gadgetType, Player caller) { if (gadgetType == null) { for (GadgetType type : GadgetType.values()) { - addCosmetics(type, caller); + lockCosmetics(type, caller); } + lockMounts(caller); + lockPets(caller); return; } + int removed = 0; for (Gadget gadget : _plugin.getGadgets(gadgetType)) { - _plugin.getDonationManager().Get(caller.getName()).RemoveUnknownSalesPackagesOwned(gadget.getName()); + if (gadget.getGadgetType() == GadgetType.ITEM) + continue; + if (gadget.ownsGadget(caller)) + { + Item clientItem = _plugin.getInventoryManager().getItem(gadget.getName()); + if (clientItem == null) + continue; + _plugin.getInventoryManager().Get(caller.getName()).removeItem(new ClientItem(clientItem, 1)); + removed++; + } } - UtilPlayer.message(caller, F.main("Cosmetics", "Removed all the " + gadgetType.name() + " cosmetics!")); + UtilPlayer.message(caller, F.main("Cosmetics", "Removed all the " + gadgetType.name().toLowerCase() + .replace("_", " ") + "! (Removed " + C.cRed + removed + C.cGray + " " + + UtilText.plural("item", removed) + ")")); } + + private void lockMounts(Player caller) + { + int removed = 0; + for (Mount mount : _plugin.getMountManager().getMounts()) + { + if (mount.hasMount(caller)) + { + Item clientItem = _plugin.getInventoryManager().getItem(mount.getName()); + if (clientItem == null) + continue; + _plugin.getInventoryManager().Get(caller.getName()).removeItem(new ClientItem(clientItem, 1)); + removed++; + } + } + UtilPlayer.message(caller, F.main("Cosmetics", "Removed " + C.cRed + removed + C.cGray + " " + + UtilText.plural("mount", removed) + "!")); + } + + private void lockPets(Player caller) + { + int removed = 0; + for (Pet pet : _plugin.getPetManager().getFactory().GetPets()) + { + if (_plugin.getPetManager().Get(caller).getPets().containsKey(pet.getPetType())) + { + _plugin.getPetManager().Get(caller).getPets().remove(pet.getPetType()); + removed++; + } + } + UtilPlayer.message(caller, F.main("Cosmetics", "Removed " + C.cRed + removed + C.cGray + " " + + UtilText.plural("pet", removed) + "!")); + } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/commands/UnlockCosmeticsCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/commands/UnlockCosmeticsCommand.java index f55fb3394..36a279711 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/commands/UnlockCosmeticsCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/commands/UnlockCosmeticsCommand.java @@ -2,15 +2,15 @@ package mineplex.core.gadget.commands; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; +import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilText; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.GadgetType; import mineplex.core.mount.Mount; -import mineplex.core.mount.MountManager; import mineplex.core.pet.Pet; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; public class UnlockCosmeticsCommand extends CommandBase @@ -40,6 +40,14 @@ public class UnlockCosmeticsCommand extends CommandBase { addCosmetics(null, caller); } + else if (type.equalsIgnoreCase("pet")) + { + addPets(caller); + } + else if (type.equalsIgnoreCase("mount")) + { + addMounts(caller); + } else { GadgetType gadgetType = GadgetType.valueOf(type); @@ -64,12 +72,54 @@ public class UnlockCosmeticsCommand extends CommandBase { addCosmetics(type, caller); } + addMounts(caller); + addPets(caller); return; } + int added = 0; + int amount = 1; for (Gadget gadget : _plugin.getGadgets(gadgetType)) { - _plugin.getDonationManager().Get(caller.getName()).AddUnknownSalesPackagesOwned(gadget.getName()); + if (gadgetType == GadgetType.ITEM) + amount = 20; + if (!gadget.ownsGadget(caller)) + { + _plugin.getInventoryManager().addItemToInventory(caller, gadget.getName(), amount); + added++; + } } - UtilPlayer.message(caller, F.main("Cosmetics", "Added all the " + gadgetType.name() + " cosmetics!")); + UtilPlayer.message(caller, F.main("Cosmetics", "Added all the " + gadgetType.name().toLowerCase() + .replace("_", " ") + "! (Added " + C.cRed + added + C.cGray + " " + + UtilText.plural("item", added) + ")")); } + + private void addMounts(Player caller) + { + int added = 0; + for (Mount mount : _plugin.getMountManager().getMounts()) + { + if (!mount.hasMount(caller)) + { + _plugin.getInventoryManager().addItemToInventory(caller, mount.getName(), 1); + added++; + } + } + UtilPlayer.message(caller, F.main("Cosmetics", "Added " + C.cRed + added + C.cGray + " " + + UtilText.plural("mount", added) + "!")); + } + + private void addPets(Player caller) + { + int added = 0; + for (Pet pet : _plugin.getPetManager().getFactory().GetPets()) + { + if (!_plugin.getPetManager().Get(caller).getPets().containsKey(pet.getPetType())) + { + _plugin.getPetManager().Get(caller).getPets().put(pet.getPetType(), pet.getName()); + added++; + } + } + UtilPlayer.message(caller, F.main("Cosmetics", "Added " + C.cRed + added + C.cGray + " " + + UtilText.plural("pet", added) + "!")); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/event/GadgetChangeEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/event/GadgetChangeEvent.java new file mode 100644 index 000000000..d983cabe6 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/event/GadgetChangeEvent.java @@ -0,0 +1,60 @@ +package mineplex.core.gadget.event; + +import mineplex.core.gadget.types.Gadget; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * Called when a player enables or disables a gadget manually, + * allowing it to be saved when the player changes a gadget, instead of + * when they quit or join a server + */ +public class GadgetChangeEvent extends Event +{ + + public enum GadgetState + { + ENABLED, + DISABLED + } + + private static final HandlerList handlers = new HandlerList(); + + private final Player _player; + private final Gadget _gadget; + private final GadgetState _gadgetState; + + public GadgetChangeEvent(Player player, Gadget gadget, GadgetState gadgetState) + { + _player = player; + _gadget = gadget; + _gadgetState = gadgetState; + } + + public Player getPlayer() + { + return _player; + } + + public Gadget getGadget() + { + return _gadget; + } + + public GadgetState getGadgetState() + { + return _gadgetState; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/event/GadgetSelectLocationEvent.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/event/GadgetSelectLocationEvent.java new file mode 100644 index 000000000..fefbff7eb --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/event/GadgetSelectLocationEvent.java @@ -0,0 +1,84 @@ +package mineplex.core.gadget.event; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import mineplex.core.gadget.types.Gadget; + +/** + * This event is called when a gadget selects a location for a specific effect to be shown. + */ +public class GadgetSelectLocationEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + + private Player _player; + private Gadget _gadget; + private Location _location; + private boolean _showMessage = true; + private boolean _cancelled = false; + + public GadgetSelectLocationEvent(Player player, Gadget gadget, Location location) + { + _player = player; + _gadget = gadget; + _location = location; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + + public Gadget getGadget() + { + return _gadget; + } + + public Player getPlayer() + { + return _player; + } + + public Location getLocation() + { + return _location; + } + + public void setCancelled(boolean cancel) + { + _cancelled = cancel; + } + + public boolean isCancelled() + { + return _cancelled; + } + + /** + * Whether or not a cancellation message should be displayed. + * + * @param showMessage True for the message to be shown and false for the message to be hidden/ignored. + */ + public void setShowMessage(boolean showMessage) + { + _showMessage = showMessage; + } + + /** + * Returns whether or not a cancellation message can be shown. + * + * @return True if the message can be shown and false if the message should be hidden/ignored. + */ + public boolean canShowMessage() + { + return _showMessage; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemCoal.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemCoal.java index 377c596f0..f031776d3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemCoal.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/item/ItemCoal.java @@ -117,7 +117,7 @@ public class ItemCoal extends ItemGadget } //Coal Apparition - if (!Manager.getPetManager().Get(player).GetPets().containsKey(EntityType.PIG_ZOMBIE)) + if (!Manager.getPetManager().Get(player).getPets().containsKey(EntityType.PIG_ZOMBIE)) { goal = _pet; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphTitan.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphTitan.java index 558335c68..9881ffa93 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphTitan.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/morph/MorphTitan.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; @@ -17,6 +18,7 @@ import org.bukkit.util.Vector; import mineplex.core.common.Rank; import mineplex.core.common.util.C; +import mineplex.core.common.util.F; import mineplex.core.common.util.LineFormat; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAlg; @@ -32,6 +34,7 @@ import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.disguise.disguises.DisguiseBase; import mineplex.core.disguise.disguises.DisguiseGuardian; import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.event.GadgetSelectLocationEvent; import mineplex.core.gadget.types.MorphGadget; import mineplex.core.recharge.Recharge; import mineplex.core.recharge.RechargedEvent; @@ -105,6 +108,19 @@ public class MorphTitan extends MorphGadget Location loc = player.getTargetBlock(ignore, 64).getLocation().add(0.5, 0.5, 0.5); + GadgetSelectLocationEvent gadgetSelectLocationEvent = new GadgetSelectLocationEvent(player, this, loc); + Bukkit.getServer().getPluginManager().callEvent(gadgetSelectLocationEvent); + + if (gadgetSelectLocationEvent.isCancelled()) + { + if (gadgetSelectLocationEvent.canShowMessage()) + { + UtilPlayer.message(player, F.main("Gadget", "You cannot use the laser on this area!")); + } + + return; + } + ArmorStand stand = loc.getWorld().spawn(loc, ArmorStand.class); stand.setVisible(false); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/WinEffectLavaTrap.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/WinEffectLavaTrap.java index 93262ead7..0f05294b6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/WinEffectLavaTrap.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/wineffect/WinEffectLavaTrap.java @@ -146,7 +146,7 @@ public class WinEffectLavaTrap extends WinEffectGadget Location loc = getBaseLocation().add(UtilAlg.getRight(dir).multiply(5)).add(0, 2, 0).subtract(dir); loc.setDirection(getBaseLocation().subtract(loc).toVector()); - teleport(loc); + super.teleport(loc); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/WinEffectGadget.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/WinEffectGadget.java index b70b8ca49..76b052693 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/WinEffectGadget.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/WinEffectGadget.java @@ -2,11 +2,11 @@ package mineplex.core.gadget.types; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; import mineplex.core.common.util.*; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; import org.bukkit.*; import org.bukkit.Color; import org.bukkit.block.BlockFace; @@ -14,7 +14,10 @@ import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.vehicle.VehicleExitEvent; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; @@ -26,6 +29,7 @@ import mineplex.core.disguise.disguises.DisguisePlayer; import mineplex.core.gadget.GadgetManager; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; +import org.spigotmc.event.entity.EntityDismountEvent; /** * A wrapper for different win effects @@ -51,8 +55,8 @@ public abstract class WinEffectGadget extends Gadget protected List _nonTeam; /** All players on the team that didn't win + spectators which were not in the game at all. */ protected List _other; - /** All locked players */ - protected List _locked; + /** All the players that were teleported to the winroom */ + protected List _allPlayers; /** * @param manager The normal GadgetManager @@ -90,55 +94,10 @@ public abstract class WinEffectGadget extends Gadget this._finish = _start + 1000*12; play(); } - - /** - * Lock the player. Disabling any jump or walk movement - * @param p The player to lock in place - */ - public void lockPlayer(Player p) - { - _locked.add(p); - p.setWalkSpeed(0); - p.setFlySpeed(0); - } - - /** - * Unlock the player, allowing the player to walk and jump as normal again. - * @param p The player to unlock - */ - public void unlockPlayer(Player p) - { - if (_locked.contains(p)) - _locked.remove(p); - p.setWalkSpeed(0.2f); - p.setFlySpeed(0.1f); - } - - @EventHandler - public void onMove(PlayerMoveEvent event) - { - for(PotionEffect p : event.getPlayer().getActivePotionEffects()) - { - if(p.getType().equals(PotionEffectType.JUMP)) - { - if(p.getAmplifier() == 250) - { - if(event.getTo().clone().subtract(event.getFrom()).lengthSquared() > 0) - { - Location loc = event.getPlayer().getLocation().getBlock().getLocation().add(0.5, 0, 0.5); - loc.setDirection(event.getTo().getDirection()); - event.setTo(loc); - } - return; - } - } - } - } - + public void runFinish() { finish(); - UtilServer.getPlayersCollection().forEach(p -> {unlockPlayer(p); UtilPlayer.showForAll(p); }); _player = null; _baseLocation = null; _team.clear(); @@ -147,8 +106,8 @@ public abstract class WinEffectGadget extends Gadget _nonTeam = null; _other.clear(); _other = null; - _locked.clear(); - _locked = null; + _allPlayers.clear(); + _allPlayers = null; // Loads gadgets back when players are teleported to the arcade hub, after the win effect for (Player player : UtilServer.getPlayers()) { @@ -221,7 +180,8 @@ public abstract class WinEffectGadget extends Gadget _other.remove(player); _other.removeAll(team); - _locked = new ArrayList<>(); + _allPlayers = new ArrayList<>(); + _allPlayers.addAll(UtilServer.getPlayersCollection()); this._start = System.currentTimeMillis(); this._baseLocation = loc.clone(); @@ -245,32 +205,64 @@ public abstract class WinEffectGadget extends Gadget */ public void teleport(Location loc) { - loc.getBlock().setType(Material.AIR); - loc.getBlock().getRelative(BlockFace.UP).setType(Material.AIR); - loc.getBlock().getRelative(BlockFace.DOWN).setType(Material.BARRIER); - loc.getBlock().getRelative(BlockFace.EAST).getRelative(BlockFace.UP).setType(Material.BARRIER); - loc.getBlock().getRelative(BlockFace.WEST).getRelative(BlockFace.UP).setType(Material.BARRIER); - loc.getBlock().getRelative(BlockFace.NORTH).getRelative(BlockFace.UP).setType(Material.BARRIER); - loc.getBlock().getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP).setType(Material.BARRIER); - loc.clone().add(0, 2, 0).getBlock().setType(Material.BARRIER); + createBarriers(loc); BukkitRunnable bRunnable = new BukkitRunnable() { @Override public void run() { for(Player p : UtilServer.getPlayers()) { - lockPlayer(p); UtilPlayer.hideFromAll(p); + p.teleport(loc); p.setGameMode(GameMode.ADVENTURE); + p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 10 * 20, 1, false, false)); p.getInventory().clear(); - p.teleport(loc.clone().add(.5, 0, .5)); p.setAllowFlight(false); - Manager.disableAll(p, false); + p.setHealth(p.getMaxHealth()); + p.setFoodLevel(20); + Manager.disableAll(p, true); } } }; bRunnable.runTaskLater(UtilServer.getPlugin(), 10l); } - + + /** + * Updates players inventory + * @param event + */ + @EventHandler + public void onUpdate(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + return; + + if (!isRunning()) + return; + + for (Player player : _allPlayers) + { + player.getInventory().clear(); + } + } + + @EventHandler + public void onFoodLevelChange(FoodLevelChangeEvent event) + { + if (isRunning()) + { + event.setCancelled(true); + } + } + + @EventHandler + public void onPlayerDamage(EntityDamageEvent event) + { + if (isRunning()) + { + event.setCancelled(true); + } + } + /** * Build the win room, by default this will paste the scheamtic. Do any major setup here. This is called before the players are * teleported. @@ -357,4 +349,69 @@ public abstract class WinEffectGadget extends Gadget } } + private void createBarriers(Location baseLocation) + { + // FLOOR + Location floorBase = baseLocation.clone().subtract(0, 1, 0); + setBarrierBlock(floorBase); + setBarrierBlock(floorBase.clone().add(1, 0, 0)); + setBarrierBlock(floorBase.clone().add(0, 0, 1)); + setBarrierBlock(floorBase.clone().subtract(1, 0, 0)); + setBarrierBlock(floorBase.clone().subtract(0, 0, 1)); + setBarrierBlock(floorBase.clone().add(1, 0, 1)); + setBarrierBlock(floorBase.clone().add(1, 0, -1)); + setBarrierBlock(floorBase.clone().add(-1, 0, 1)); + setBarrierBlock(floorBase.clone().subtract(1, 0, 1)); + + // WALLS + floorBase.add(0, 2, 0); + setBarrierBlock(floorBase.clone().add(2, 0, 0)); + setBarrierBlock(floorBase.clone().add(2, 0, 1)); + setBarrierBlock(floorBase.clone().add(2, 0, -1)); + + setBarrierBlock(floorBase.clone().subtract(2, 0, 0)); + setBarrierBlock(floorBase.clone().subtract(2, 0, 1)); + setBarrierBlock(floorBase.clone().subtract(2, 0, -1)); + + setBarrierBlock(floorBase.clone().add(0, 0, 2)); + setBarrierBlock(floorBase.clone().add(1, 0, 2)); + setBarrierBlock(floorBase.clone().add(-1, 0, 2)); + + setBarrierBlock(floorBase.clone().subtract(0, 0, 2)); + setBarrierBlock(floorBase.clone().subtract(1, 0, 2)); + setBarrierBlock(floorBase.clone().subtract(-1, 0, 2)); + + // CEILING + floorBase.add(0, 2, 0); + setBarrierBlock(floorBase); + setBarrierBlock(floorBase.clone().add(1, 0, 0)); + setBarrierBlock(floorBase.clone().add(0, 0, 1)); + setBarrierBlock(floorBase.clone().subtract(1, 0, 0)); + setBarrierBlock(floorBase.clone().subtract(0, 0, 1)); + setBarrierBlock(floorBase.clone().add(1, 0, 1)); + setBarrierBlock(floorBase.clone().add(1, 0, -1)); + setBarrierBlock(floorBase.clone().add(-1, 0, 1)); + setBarrierBlock(floorBase.clone().subtract(1, 0, 1)); + + // CHANGES MIDDLE TO AIR + floorBase.subtract(1, 3, 1); + for (int x = 0; x < 3; x++) + { + for (int y = 0; y < 3; y++) + { + for (int z = 0; z < 3; z++) + { + floorBase.clone().add(x, y, z).getBlock().setType(Material.AIR); + } + } + } + + } + + private void setBarrierBlock(Location blockLocation) + { + if (blockLocation.getBlock().getType() == Material.AIR) + blockLocation.getBlock().setType(Material.BARRIER); + } + } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayManager.java b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayManager.java index bfcfa4981..9d86ffa9c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayManager.java @@ -173,7 +173,7 @@ public class GiveawayManager extends MiniDbClientPlugin } @Override - protected PlayerGiveawayData AddPlayer(String player) + protected PlayerGiveawayData addPlayer(String player) { return new PlayerGiveawayData(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/ignore/IgnoreManager.java b/Plugins/Mineplex.Core/src/mineplex/core/ignore/IgnoreManager.java index a4735a7a4..15c0fca39 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/ignore/IgnoreManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/ignore/IgnoreManager.java @@ -80,7 +80,7 @@ public class IgnoreManager extends MiniDbClientPlugin } @Override - protected IgnoreData AddPlayer(String player) + protected IgnoreData addPlayer(String player) { return new IgnoreData(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java b/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java index 92a1cb641..2594b4188 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java @@ -191,7 +191,7 @@ public class IncognitoManager extends MiniDbClientPlugin UtilPlayer.message(player, " "); } - protected IncognitoClient AddPlayer(String player) + protected IncognitoClient addPlayer(String player) { return new IncognitoClient(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java b/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java index 72a33d939..43a1d22e8 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/inventory/InventoryManager.java @@ -342,7 +342,7 @@ public class InventoryManager extends MiniDbClientPlugin } @Override - protected ClientInventory AddPlayer(String player) + protected ClientInventory addPlayer(String player) { return new ClientInventory(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java b/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java index 6d437d2d1..3faaee528 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java @@ -87,7 +87,7 @@ public class MessageManager extends MiniClientPlugin } @Override - protected ClientMessage AddPlayer(String player) + protected ClientMessage addPlayer(String player) { Set(player, new ClientMessage()); return Get(player); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/movement/Movement.java b/Plugins/Mineplex.Core/src/mineplex/core/movement/Movement.java index 9f801a28c..40d547a39 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/movement/Movement.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/movement/Movement.java @@ -40,7 +40,7 @@ public class Movement extends MiniClientPlugin } @Override - protected ClientMovement AddPlayer(String player) + protected ClientMovement addPlayer(String player) { return new ClientMovement(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketHandler.java index 3018daa85..d8076b1cf 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketHandler.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/packethandler/PacketHandler.java @@ -1,12 +1,8 @@ package mineplex.core.packethandler; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map.Entry; - +import com.mineplex.spigot.PacketProcessor; +import mineplex.core.MiniPlugin; import net.minecraft.server.v1_8_R3.Packet; - import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -15,16 +11,22 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; -import com.mineplex.spigot.PacketProcessor; - -import mineplex.core.MiniPlugin; -import mineplex.core.common.util.NautHashMap; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.TreeMap; public class PacketHandler extends MiniPlugin { - private NautHashMap _playerVerifierMap = new NautHashMap(); - private HashMap> _forceMainThread = new HashMap>(); - private HashMap> _packetHandlers = new HashMap>(); + private Map _playerVerifierMap = new HashMap<>(); + + private Map, Set> _forceMainThread = new HashMap<>(); + private Map, Map>> _packetHandlers = new HashMap<>(); public PacketHandler(JavaPlugin plugin) { @@ -40,18 +42,6 @@ public class PacketHandler extends MiniPlugin .get(event.getPlayer())); } - public boolean handlePacket(Player player, Packet packet) - { - if (!_playerVerifierMap.containsKey(player)) - { - return true; - } - - PacketVerifier verifier = _playerVerifierMap.get(player); - - return handlePacket(new PacketInfo(player, packet, verifier)); - } - public boolean handlePacket(PacketInfo packetInfo) { if (!_packetHandlers.containsKey(packetInfo.getPacket().getClass())) @@ -60,15 +50,18 @@ public class PacketHandler extends MiniPlugin return true; } - for (IPacketHandler handler : _packetHandlers.get(packetInfo.getPacket().getClass())) + for (Entry> entry : _packetHandlers.get(packetInfo.getPacket().getClass()).entrySet()) { - try + for (IPacketHandler handler : entry.getValue()) { - handler.handle(packetInfo); - } - catch (Exception ex) - { - ex.printStackTrace(); + try + { + handler.handle(packetInfo); + } + catch (Exception ex) + { + ex.printStackTrace(); + } } } @@ -90,72 +83,106 @@ public class PacketHandler extends MiniPlugin @SafeVarargs public final void addPacketHandler(IPacketHandler packetHandler, Class... packetsToListen) { - if (packetsToListen.length == 0) - { - throw new IllegalArgumentException("When registering a new packet listener, add the packets its going to listen to"); - } - - addPacketHandler(packetHandler, false, packetsToListen); + addPacketHandler(packetHandler, ListenerPriority.NORMAL, false, packetsToListen); } - /** - * This should only be used for incoming packets - */ - public void addPacketHandler(IPacketHandler packetHandler, boolean forceMainThread, - Class... packetsToListen) + @SafeVarargs + public final void addPacketHandler(IPacketHandler packetHandler, boolean forceMainThread, Class... packetsToListen) { if (packetsToListen.length == 0) { throw new IllegalArgumentException("When registering a new packet listener, add the packets its going to listen to"); } - for (Class c : packetsToListen) + addPacketHandler(packetHandler, ListenerPriority.NORMAL, forceMainThread, packetsToListen); + } + + @SafeVarargs + public final void addPacketHandler(IPacketHandler packetHandler, ListenerPriority priority, Class... packetsToListen) + { + if (packetsToListen.length == 0) + { + throw new IllegalArgumentException("When registering a new packet listener, add the packets its going to listen to"); + } + + addPacketHandler(packetHandler, priority, false, packetsToListen); + } + + /** + * This should only be used for incoming packets + */ + @SafeVarargs + public final void addPacketHandler(IPacketHandler packetHandler, ListenerPriority priority, boolean forceMainThread, + Class... packetsToListen) + { + if (packetsToListen.length == 0) + { + throw new IllegalArgumentException("When registering a new packet listener, add the packets its going to listen to"); + } + + for (Class c : packetsToListen) { if (forceMainThread) { - if (!_forceMainThread.containsKey(c)) - { - _forceMainThread.put(c, new ArrayList()); - } - - _forceMainThread.get(c).add(packetHandler); + _forceMainThread + .computeIfAbsent(c, key -> new HashSet<>()) + .add(packetHandler); } - if (!_packetHandlers.containsKey(c)) - { - _packetHandlers.put(c, new ArrayList()); - } + _packetHandlers + .computeIfAbsent(c, key -> new TreeMap<>()) + .computeIfAbsent(priority, key -> new ArrayList<>()) + .add(packetHandler); - _packetHandlers.get(c).add(packetHandler); PacketProcessor.addPacket(c, forceMainThread || _forceMainThread.containsKey(c)); } } public void removePacketHandler(IPacketHandler packetHandler) { - Iterator>> itel = _packetHandlers.entrySet().iterator(); + Iterator, Map>>> itel = _packetHandlers.entrySet().iterator(); while (itel.hasNext()) { - Entry> entry = itel.next(); + Entry, Map>> entry = itel.next(); - if (entry.getValue().remove(packetHandler)) + Set removedFrom = new HashSet<>(); + + for (Entry> ent : entry.getValue().entrySet()) { - if (_forceMainThread.containsKey(entry.getKey()) && _forceMainThread.get(entry.getKey()).remove(packetHandler)) + if (ent.getValue().remove(packetHandler)) { - if (_forceMainThread.get(entry.getKey()).isEmpty()) - { - _forceMainThread.remove(entry.getKey()); - PacketProcessor.addPacket(entry.getKey(), false); - } + removedFrom.add(ent.getKey()); } + } - if (entry.getValue().isEmpty()) + for (ListenerPriority priority : removedFrom) + { + if (entry.getValue().get(priority).isEmpty()) { - PacketProcessor.removePacket(entry.getKey()); - itel.remove(); + entry.getValue().remove(priority); } } + + if (_forceMainThread.containsKey(entry.getKey()) && _forceMainThread.get(entry.getKey()).remove(packetHandler)) + { + if (_forceMainThread.get(entry.getKey()).isEmpty()) + { + _forceMainThread.remove(entry.getKey()); + PacketProcessor.addPacket(entry.getKey(), false); + } + } + + if (entry.getValue().isEmpty()) + { + PacketProcessor.removePacket(entry.getKey()); + itel.remove(); + } } } + + public enum ListenerPriority + { + HIGH, NORMAL, LOW + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/pet/Pet.java b/Plugins/Mineplex.Core/src/mineplex/core/pet/Pet.java index 251b2827c..0ae459e78 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/pet/Pet.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/pet/Pet.java @@ -24,17 +24,17 @@ public class Pet extends SalesPackageBase KnownPackage = false; } - public EntityType GetPetType() + public EntityType getPetType() { return _petType; } - public void Update(PetSalesToken petToken) + public void update(PetSalesToken petToken) { _name = petToken.Name; } - public String GetPetName() + public String getPetName() { return _name; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/pet/PetClient.java b/Plugins/Mineplex.Core/src/mineplex/core/pet/PetClient.java index 5aa25843a..e24136065 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/pet/PetClient.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/pet/PetClient.java @@ -11,7 +11,7 @@ public class PetClient private NautHashMap _pets; private int _petNameTagCount; - public void Load(ClientPetToken token) + public void load(ClientPetToken token) { _pets = new NautHashMap(); @@ -26,7 +26,7 @@ public class PetClient _petNameTagCount = Math.max(0, token.PetNameTagCount); } - public NautHashMap GetPets() + public NautHashMap getPets() { return _pets; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/pet/PetManager.java b/Plugins/Mineplex.Core/src/mineplex/core/pet/PetManager.java index 4e609930f..d5f48d43b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/pet/PetManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/pet/PetManager.java @@ -128,7 +128,7 @@ public class PetManager extends MiniClientPlugin if (player != null && player.isOnline()) { - AddPetOwner(player, _petOwnerQueue.get(playerName), player.getLocation()); + addPetOwner(player, _petOwnerQueue.get(playerName), player.getLocation()); } } @@ -160,24 +160,24 @@ public class PetManager extends MiniClientPlugin if (rank.has(Rank.LEGEND)) { - if (!Get(p).GetPets().containsKey(EntityType.WITHER)) - Get(p).GetPets().put(EntityType.WITHER, "Widder"); + if (!Get(p).getPets().containsKey(EntityType.WITHER)) + Get(p).getPets().put(EntityType.WITHER, "Widder"); } if (rank.has(Rank.TITAN)) { - if (!Get(p).GetPets().containsKey(EntityType.SKELETON)) - Get(p).GetPets().put(EntityType.SKELETON, "Guardian"); + if (!Get(p).getPets().containsKey(EntityType.SKELETON)) + Get(p).getPets().put(EntityType.SKELETON, "Guardian"); } } - public void AddPetOwner(Player player, EntityType entityType, Location location) + public void addPetOwner(Player player, EntityType entityType, Location location) { if (_activePetOwners.containsKey(player.getName())) { if (_activePetOwners.get(player.getName()).getType() != entityType) { - RemovePet(player, true); + removePet(player, true); } else return; @@ -214,10 +214,10 @@ public class PetManager extends MiniClientPlugin } //Named Pet - if (Get(player).GetPets().get(entityType) != null && Get(player).GetPets().get(entityType).length() > 0) + if (Get(player).getPets().get(entityType) != null && Get(player).getPets().get(entityType).length() > 0) { //pet.setCustomNameVisible(true); - pet.setCustomName(Get(player).GetPets().get(entityType)); + pet.setCustomName(Get(player).getPets().get(entityType)); } if (pet instanceof Zombie) @@ -245,9 +245,9 @@ public class PetManager extends MiniClientPlugin DisguiseGuardian disguise = new DisguiseGuardian(pet); - if (Get(player).GetPets().get(entityType) != null && Get(player).GetPets().get(entityType).length() > 0) + if (Get(player).getPets().get(entityType) != null && Get(player).getPets().get(entityType).length() > 0) { - disguise.setName(Get(player).GetPets().get(entityType)); + disguise.setName(Get(player).getPets().get(entityType)); } _disguiseManager.disguise(disguise); @@ -265,12 +265,12 @@ public class PetManager extends MiniClientPlugin UtilEnt.Vegetate(pet); } - public Creature GetPet(Player player) + public Creature getPet(Player player) { return _activePetOwners.get(player.getName()); } - public void RemovePet(final Player player, boolean removeOwner) + public void removePet(final Player player, boolean removeOwner) { if (_activePetOwners.containsKey(player.getName())) { @@ -303,7 +303,7 @@ public class PetManager extends MiniClientPlugin @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - RemovePet(event.getPlayer(), true); + removePet(event.getPlayer(), true); } @EventHandler @@ -336,7 +336,7 @@ public class PetManager extends MiniClientPlugin if (player != null && player.isOnline()) { - RemovePet(player, true); + removePet(player, true); } } } @@ -438,25 +438,25 @@ public class PetManager extends MiniClientPlugin } @EventHandler - public void OnClientWebResponse(ClientWebResponseEvent event) + public void onClientWebResponse(ClientWebResponseEvent event) { ClientPetTokenWrapper token = new Gson().fromJson(event.GetResponse(), ClientPetTokenWrapper.class); - Get(token.Name).Load(token.DonorToken); + Get(token.Name).load(token.DonorToken); } @Override - protected PetClient AddPlayer(String player) + protected PetClient addPlayer(String player) { return new PetClient(); } - public PetFactory GetFactory() + public PetFactory getFactory() { return _petFactory; } - public PetRepository GetRepository() + public PetRepository getRepository() { return _repository; } @@ -471,15 +471,15 @@ public class PetManager extends MiniClientPlugin return _activePetOwners.get(name); } - public void DisableAll() + public void disableAll() { for (Player player : UtilServer.getPlayers()) - RemovePet(player, true); + removePet(player, true); } - public void DisableAll(Player player) + public void disableAll(Player player) { - RemovePet(player, true); + removePet(player, true); } public Collection getPets() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/poll/PollManager.java b/Plugins/Mineplex.Core/src/mineplex/core/poll/PollManager.java index a2d5298b0..64abfc3cf 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/poll/PollManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/poll/PollManager.java @@ -51,7 +51,7 @@ public class PollManager extends MiniDbClientPlugin } @Override - protected PlayerPollData AddPlayer(String player) + protected PlayerPollData addPlayer(String player) { return new PlayerPollData(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java index 5622bdef6..07592704a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java @@ -59,7 +59,7 @@ public class PreferencesManager extends MiniDbClientPlugin } @Override - protected UserPreferences AddPlayer(String player) + protected UserPreferences addPlayer(String player) { return new UserPreferences(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/progression/KitProgressionManager.java b/Plugins/Mineplex.Core/src/mineplex/core/progression/KitProgressionManager.java index 35511ac6a..4c3a962ea 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/progression/KitProgressionManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/progression/KitProgressionManager.java @@ -33,7 +33,7 @@ public class KitProgressionManager extends MiniClientPlugin @Override - protected PlayerKit AddPlayer(String player) + protected PlayerKit addPlayer(String player) { return null; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java index 7ff0962ab..508a59d2c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java @@ -864,7 +864,7 @@ public class RewardManager { if (!displayName.contains("Uncle Sam")) { - display = CountryFlag.Usa.getBanner(); + display = CountryFlag.USA.getBanner(); } } UnknownPackageReward reward = @@ -929,7 +929,7 @@ public class RewardManager public PetReward addPetReward(Type type, EntityType entityType, RewardRarity rarity, int weight, int shards) { - Pet pet = _petManager.GetFactory().getPet(entityType); + Pet pet = _petManager.getFactory().getPet(entityType); PetReward reward = new PetReward(_petManager, _inventoryManager, _donationManager, pet.getName() + " Pet", pet.getName(), entityType, rarity, weight, shards); addReward(type, reward); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/PetReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/PetReward.java index d3dba4662..9589502eb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/PetReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/PetReward.java @@ -50,8 +50,8 @@ public class PetReward extends UnknownPackageReward PetToken petToken = new PetToken(); petToken.PetType = token.PetType; - _petManager.GetRepository().AddPet(token); - _petManager.Get(player).GetPets().put(_petEntity, token.PetName); + _petManager.getRepository().AddPet(token); + _petManager.Get(player).getPets().put(_petEntity, token.PetName); _inventoryManager.addItemToInventory(player, _petEntity.toString(), 1); @@ -67,6 +67,6 @@ public class PetReward extends UnknownPackageReward return false; } - return !_petManager.Get(player).GetPets().containsKey(_petEntity); + return !_petManager.Get(player).getPets().containsKey(_petEntity); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java index 8c2bc5e06..52d19ec1e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java @@ -307,7 +307,7 @@ public class StatsManager extends MiniDbClientPlugin } @Override - protected PlayerStats AddPlayer(String player) + protected PlayerStats addPlayer(String player) { return new PlayerStats(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/task/TaskManager.java b/Plugins/Mineplex.Core/src/mineplex/core/task/TaskManager.java index 0427cb53e..ef09c15cb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/task/TaskManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/task/TaskManager.java @@ -49,7 +49,7 @@ public class TaskManager extends MiniDbClientPlugin } @Override - protected TaskClient AddPlayer(String playerName) + protected TaskClient addPlayer(String playerName) { return new TaskClient(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/tournament/TournamentManager.java b/Plugins/Mineplex.Core/src/mineplex/core/tournament/TournamentManager.java index d5bdf1a0b..4166c6a36 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/tournament/TournamentManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/tournament/TournamentManager.java @@ -80,7 +80,7 @@ public class TournamentManager extends MiniDbClientPlugin } @Override - protected ClientTournamentData AddPlayer(String player) + protected ClientTournamentData addPlayer(String player) { return new ClientTournamentData(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/BuyChestButton.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/BuyChestButton.java index 21bc6b37e..f62bd83cc 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/BuyChestButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/BuyChestButton.java @@ -40,6 +40,19 @@ public class BuyChestButton implements IButton @Override public void onClick(final Player player, ClickType clickType) { + if (_chestType == TreasureType.FREEDOM) + { + if (!_page.getPlugin().hasItemsToGivePlayer(_chestType.getRewardPool(), player)) + { + player.sendMessage(F.main("Treasure", "You seem to have all treasures for this chest unlocked already!")); + return; + } + else + { + player.sendMessage(F.main("Treasure", "This chest is no longer available for purchases!")); + return; + } + } if (!_page.getPlugin().hasItemsToGivePlayer(TreasureType.ILLUMINATED.getRewardPool(), player) && _chestType == TreasureType.ILLUMINATED) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasurePage.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasurePage.java index 3b91b09f4..c05c9a774 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasurePage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasurePage.java @@ -13,6 +13,7 @@ import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.GadgetType; import mineplex.core.mount.Mount; import org.bukkit.ChatColor; +import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -166,13 +167,11 @@ public class TreasurePage extends ShopPageBase freedomLore.add(C.cGray + "carved this chest himself from the wood"); freedomLore.add(C.cGray + "of the apple tree he cut down..."); freedomLore.add(" "); - if (freedomCount > 0) + if (freedomCount > 0 && !hasAllFreedomItems(getPlayer())) freedomLore.add(ChatColor.RESET + C.cGreen + "Click to Open!"); else { - freedomLore.add(ChatColor.RESET + "Click to craft for " + C.cAqua + "35000 Treasure Shards"); - freedomLore.add(" "); - freedomLore.add(ChatColor.RESET + "or Purchase at: " + C.cYellow + "www.mineplex.com/shop"); + freedomLore.add(C.cRed + "This item is no longer available!"); } freedomLore.add(" "); freedomLore.add(ChatColor.RESET + C.cGreen + getFreedomUnlockedAmount(getPlayer()) + "/7 Unlocked"); @@ -188,8 +187,13 @@ public class TreasurePage extends ShopPageBase addItem(40, shards); addChest(11, christmas, TreasureType.CHRISTMAS, christmasCount); - if (!hasAllFreedomItems(getPlayer())) + if (!hasAllFreedomItems(getPlayer()) && freedomCount >= 1) addChest(13, freedom, TreasureType.FREEDOM, freedomCount); + else + { + freedom = new ShopItem(Material.INK_SACK, DyeColor.SILVER.getData(), C.cRed + C.Bold + "Freedom " + C.cBlue + C.Bold + "Treasure", freedomLore.toArray(new String[0]), 0, true, false); + addChest(13, freedom, TreasureType.FREEDOM, freedomCount); + } addChest(15, illuminated, TreasureType.ILLUMINATED, illuminatedCount); addChest(20, basic, TreasureType.OLD, basicCount); addChest(22, heroic, TreasureType.ANCIENT, heroicCount); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/youtube/YoutubeManager.java b/Plugins/Mineplex.Core/src/mineplex/core/youtube/YoutubeManager.java index 45963b9b8..5683c4b20 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/youtube/YoutubeManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/youtube/YoutubeManager.java @@ -2,7 +2,10 @@ package mineplex.core.youtube; import mineplex.core.MiniDbClientPlugin; import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; import mineplex.core.donation.DonationManager; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; @@ -14,6 +17,7 @@ import java.time.ZonedDateTime; public class YoutubeManager extends MiniDbClientPlugin { + private static final int REWARD_MESSAGE_DELAY_SECONDS = 30; private final YoutubeRepository _repository; private final DonationManager _donationManager; @@ -48,7 +52,11 @@ public class YoutubeManager extends MiniDbClientPlugin } YoutubeClient client = Get(player); client.setClickDate(ZonedDateTime.now(ZoneOffset.UTC).toLocalDate()); - _repository.attemptYoutube(player, client, () -> _donationManager.RewardCoinsLater("YouTube", player, 250)); + _repository.attemptYoutube(player, client, () -> + { + _donationManager.RewardCoinsLater("YouTube", player, 250); + Bukkit.getScheduler().runTaskLater(getClientManager().getPlugin(), () -> UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem("250 Treasure Shards") + " for watching the YouTube video")), REWARD_MESSAGE_DELAY_SECONDS * 20L); + }); } @Override @@ -68,7 +76,7 @@ public class YoutubeManager extends MiniDbClientPlugin } @Override - protected YoutubeClient AddPlayer(String player) + protected YoutubeClient addPlayer(String player) { return new YoutubeClient(null); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index e4c0c7719..08157bd5d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -1000,7 +1000,7 @@ public class ClansManager extends MiniClientPluginimplements IRelati } @Override - protected ClientClan AddPlayer(String player) + protected ClientClan addPlayer(String player) { return new ClientClan(); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/murder/MurderManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/murder/MurderManager.java index 8f10f9f0b..49143cff6 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/murder/MurderManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/murder/MurderManager.java @@ -204,7 +204,7 @@ public class MurderManager extends MiniClientPlugin } @Override - protected ClientMurder AddPlayer(String player) + protected ClientMurder addPlayer(String player) { return new ClientMurder(); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/Playtime.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/Playtime.java index 52c3dfeba..c64fd698a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/Playtime.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/Playtime.java @@ -45,7 +45,7 @@ public class Playtime extends MiniClientPlugin @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - Set(event.getPlayer(), AddPlayer(event.getPlayer().getName())); + Set(event.getPlayer(), addPlayer(event.getPlayer().getName())); } @EventHandler @@ -73,7 +73,7 @@ public class Playtime extends MiniClientPlugin } @Override - protected PlayingClient AddPlayer(String player) + protected PlayingClient addPlayer(String player) { return new PlayingClient(Bukkit.getPlayer(player), TaskManager.Instance); } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index f53d023f4..37a50cbb3 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -135,6 +135,7 @@ public class HubManager extends MiniClientPlugin private IncognitoManager _incognito; private ValentinesManager _valentinesManager; private BonusManager _bonusManager; + private JumpManager _jumpManager; // private HalloweenSpookinessManager _halloweenManager; // private TrickOrTreatManager _trickOrTreatManager; @@ -181,7 +182,7 @@ public class HubManager extends MiniClientPlugin _parkour = new ParkourManager(this, donationManager, taskManager); new WorldManager(this); - new JumpManager(this); + _jumpManager = new JumpManager(this); //new TournamentInviter(this); @@ -786,7 +787,7 @@ public class HubManager extends MiniClientPlugin } @Override - protected HubClient AddPlayer(String player) + protected HubClient addPlayer(String player) { return new HubClient(player); } @@ -1072,4 +1073,9 @@ public class HubManager extends MiniClientPlugin { return _incognito; } + + public JumpManager getJumpManager() + { + return _jumpManager; + } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailManager.java index a5fd6ebb4..a31b07381 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/mail/MailManager.java @@ -27,7 +27,7 @@ public class MailManager extends MiniClientPlugin implements Not } @Override - protected PlayerMailData AddPlayer(String player) + protected PlayerMailData addPlayer(String player) { return new PlayerMailData(); } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/JumpManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/JumpManager.java index e0367bdba..afa61a5a1 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/JumpManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/JumpManager.java @@ -1,11 +1,13 @@ package mineplex.hub.modules; -import org.bukkit.Bukkit; +import java.util.HashSet; + import org.bukkit.Effect; import org.bukkit.GameMode; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerToggleFlightEvent; import org.bukkit.util.Vector; @@ -28,6 +30,7 @@ import mineplex.hub.HubManager; public class JumpManager extends MiniPlugin { public HubManager Manager; + private HashSet _preparedDoubleJump = new HashSet<>(); public JumpManager(HubManager manager) { @@ -66,8 +69,9 @@ public class JumpManager extends MiniPlugin vec.setY(Math.abs(vec.getY())); //Velocity + _preparedDoubleJump.add(player.getName()); UtilAction.velocity(player, vec, 1.4, false, 0, 0.2, 1, true); - + //Sound player.playEffect(player.getLocation(), Effect.BLAZE_SHOOT, 0); @@ -105,8 +109,20 @@ public class JumpManager extends MiniPlugin { player.setAllowFlight(true); player.setFlying(false); + _preparedDoubleJump.remove(player.getName()); } } } } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) + { + _preparedDoubleJump.remove(event.getPlayer().getName()); + } + + public boolean hasDoubleJumped(Player player) + { + return _preparedDoubleJump.contains(player.getName()); + } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/KothManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/KothManager.java index 6c0ad0d5b..0787e225b 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/KothManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/KothManager.java @@ -197,7 +197,7 @@ public class KothManager extends MiniPlugin Manager.GetGadget().disableAll(player, outfit); Manager.GetMount().DisableAll(player); - Manager.getPetManager().DisableAll(player); + Manager.getPetManager().disableAll(player); } else { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/SoccerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/SoccerManager.java index 04fb771b8..fed5f2501 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/SoccerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/SoccerManager.java @@ -3,9 +3,9 @@ package mineplex.hub.modules; import java.util.ArrayList; import java.util.HashSet; +import org.bukkit.Color; import org.bukkit.EntityEffect; import org.bukkit.FireworkEffect.Type; -import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.entity.Bat; @@ -20,9 +20,10 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerVelocityEvent; import org.bukkit.util.Vector; -import mineplex.core.MiniPlugin; +import mineplex.core.MiniPlugin; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAction; @@ -37,8 +38,10 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; +import mineplex.core.event.StackerEvent; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.event.GadgetEnableEvent; +import mineplex.core.gadget.event.GadgetSelectLocationEvent; import mineplex.core.gadget.gadgets.outfit.OutfitTeam; import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.GadgetType; @@ -50,8 +53,8 @@ import mineplex.hub.HubManager; public class SoccerManager extends MiniPlugin { - public HubManager Manager; - + private HubManager _hubManager; + private HashSet _active = new HashSet(); private ArrayList _teamArmor = new ArrayList(); @@ -71,10 +74,10 @@ public class SoccerManager extends MiniPlugin private Location _cornerBlueGoalA; private Location _cornerBlueGoalB; - int _blueGoals = 0; - int _redGoals = 0; + private int _blueGoals = 0; + private int _redGoals = 0; - int _insideGoalTicks = 0; + private int _insideGoalTicks = 0; private Slime _ball; private Vector _ballVel; @@ -89,29 +92,29 @@ public class SoccerManager extends MiniPlugin protected Location _lastLoc; protected ArrayList _velHistory = new ArrayList(); - public SoccerManager(HubManager manager, GadgetManager gadgets) + public SoccerManager(HubManager hubManager, GadgetManager gadgetManager) { - super("Football Manager", manager.getPlugin()); + super("Football Manager", hubManager.getPlugin()); - Manager = manager; + _hubManager = hubManager; + + _cornerFieldPlayerA = new Location(hubManager.GetSpawn().getWorld(), 28.5,70,-27.5); + _cornerFieldPlayerB = new Location(hubManager.GetSpawn().getWorld(), 50.5,100,-65.5); - _cornerFieldPlayerA = new Location(Manager.GetSpawn().getWorld(), 28.5,70,-27.5); - _cornerFieldPlayerB = new Location(Manager.GetSpawn().getWorld(), 50.5,100,-65.5); + _cornerGoalPlayerA = new Location(hubManager.GetSpawn().getWorld(), 35.5,70,-24.5); + _cornerGoalPlayerB = new Location(hubManager.GetSpawn().getWorld(), 43.5,100,-68.5); - _cornerGoalPlayerA = new Location(Manager.GetSpawn().getWorld(), 35.5,70,-24.5); - _cornerGoalPlayerB = new Location(Manager.GetSpawn().getWorld(), 43.5,100,-68.5); + _cornerFieldA = new Location(hubManager.GetSpawn().getWorld(), 29.75,70,-28.75); + _cornerFieldB = new Location(hubManager.GetSpawn().getWorld(), 49.25,100,-64.25); - _cornerFieldA = new Location(Manager.GetSpawn().getWorld(), 29.75,70,-28.75); - _cornerFieldB = new Location(Manager.GetSpawn().getWorld(), 49.25,100,-64.25); + _cornerRedGoalA = new Location(hubManager.GetSpawn().getWorld(), 36.75,70,-64.25); + _cornerRedGoalB = new Location(hubManager.GetSpawn().getWorld(), 42.25,73.5,-67.25); - _cornerRedGoalA = new Location(Manager.GetSpawn().getWorld(), 36.75,70,-64.25); - _cornerRedGoalB = new Location(Manager.GetSpawn().getWorld(), 42.25,73.5,-67.25); - - _cornerBlueGoalA = new Location(Manager.GetSpawn().getWorld(), 36.75,70,-25.75); - _cornerBlueGoalB = new Location(Manager.GetSpawn().getWorld(), 42.25,73.5,-28.75); + _cornerBlueGoalA = new Location(hubManager.GetSpawn().getWorld(), 36.75,70,-25.75); + _cornerBlueGoalB = new Location(hubManager.GetSpawn().getWorld(), 42.25,73.5,-28.75); //Store Gadgets - for (Gadget gadget : gadgets.getGadgets(GadgetType.COSTUME)) + for (Gadget gadget : gadgetManager.getGadgets(GadgetType.COSTUME)) { if (gadget instanceof OutfitTeam) { @@ -352,7 +355,7 @@ public class SoccerManager extends MiniPlugin return UtilAlg.inBoundingBox(entity.getLocation(), _cornerFieldPlayerA, _cornerFieldPlayerB) || UtilAlg.inBoundingBox(entity.getLocation(), _cornerGoalPlayerA, _cornerGoalPlayerB); } - + @EventHandler public void clean(UpdateEvent event) { @@ -470,9 +473,9 @@ public class SoccerManager extends MiniPlugin outfit.add("Team Pants"); outfit.add("Team Boots"); - Manager.GetGadget().disableAll(player, outfit); - Manager.GetMount().DisableAll(player); - Manager.getPetManager().DisableAll(player); + _hubManager.GetGadget().disableAll(player, outfit); + _hubManager.GetMount().DisableAll(player); + _hubManager.getPetManager().disableAll(player); } else { @@ -481,11 +484,11 @@ public class SoccerManager extends MiniPlugin } } - public boolean isSoccerMode(Player player) + public boolean isSoccerMode(Entity entity) { - return _active.contains(player); + return _active.contains(entity); } - + @EventHandler public void disableGadgets(GadgetEnableEvent event) { @@ -510,6 +513,35 @@ public class SoccerManager extends MiniPlugin event.setCancelled(true); } + @EventHandler + public void disableStacker(StackerEvent event) + { + if (isSoccerMode(event.getEntity())) + { + event.setCancelled(true); + } + } + + @EventHandler + public void disableGuardianLazer(GadgetSelectLocationEvent event) + { + if (UtilAlg.inBoundingBox(event.getLocation(), _cornerFieldA, _cornerFieldB)) + { + event.setCancelled(true); + } + } + + @EventHandler + public void disableVelocity(PlayerVelocityEvent event) + { + // Disable velocity but allow double jumping. + + if (isSoccerMode(event.getPlayer()) && !_hubManager.getJumpManager().hasDoubleJumped(event.getPlayer())) + { + event.setCancelled(true); + } + } + @EventHandler public void playerQuit(PlayerQuitEvent event) { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java index da26f23fd..a92a99b2e 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -948,7 +948,7 @@ public class ServerManager extends MiniDbClientPlugin implement } @Override - protected SimpleClanToken AddPlayer(String player) + protected SimpleClanToken addPlayer(String player) { return new SimpleClanToken(); } diff --git a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Class/ClassManager.java b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Class/ClassManager.java index da87fc2da..4bc36c039 100644 --- a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Class/ClassManager.java +++ b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Class/ClassManager.java @@ -322,7 +322,7 @@ public class ClassManager extends MiniClientPlugin implements IClas } @Override - protected ClientClass AddPlayer(String player) + protected ClientClass addPlayer(String player) { return new ClientClass(this, _skillFactory, _itemFactory, _clientManager.Get(player), _donationManager.Get(player), null); } diff --git a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/CustomDamageEvent.java b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/CustomDamageEvent.java index 8f2788e66..ec3781d43 100644 --- a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/CustomDamageEvent.java +++ b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/CustomDamageEvent.java @@ -44,6 +44,7 @@ public class CustomDamageEvent extends Event implements Cancellable private boolean _damageeBrute = false; private boolean _damageToLevel = true; private boolean _arrowShow = true; + private boolean _projectileDamageSelf = false; public CustomDamageEvent(LivingEntity damagee, LivingEntity damager, Projectile projectile, Location knockbackOrigin, DamageCause cause, double damage, boolean knockback, boolean ignoreRate, boolean ignoreArmor, String initialSource, @@ -169,6 +170,27 @@ public class CustomDamageEvent extends Event implements Cancellable return _projectile; } + public boolean getProjectileDamageSelf() + { + return _projectileDamageSelf; + } + + public void setProjectileDamageSelf(boolean projectileDamageSelf) + { + _projectileDamageSelf = projectileDamageSelf; + if(!projectileDamageSelf) + { + _cancellers.remove("Self Projectile Damage"); + } + else + { + if(!_cancellers.contains("Self Projectile Damage")) + { + _cancellers.add("Self Projectile Damage"); + } + } + } + public void setShowArrows(boolean show) { _arrowShow = show; diff --git a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java index f19f26b67..304394625 100644 --- a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java +++ b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java @@ -8,24 +8,6 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import mineplex.core.MiniPlugin; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilAction; -import mineplex.core.common.util.UtilAlg; -import mineplex.core.common.util.UtilEnt; -import mineplex.core.common.util.UtilEvent; -import mineplex.core.common.util.UtilGear; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; -import mineplex.core.disguise.DisguiseManager; -import mineplex.core.npc.NpcManager; -import mineplex.minecraft.game.core.combat.CombatManager; -import mineplex.minecraft.game.core.condition.ConditionManager; -import mineplex.minecraft.game.core.damage.compatibility.NpcProtectListener; -import net.minecraft.server.v1_8_R3.DamageSource; -import net.minecraft.server.v1_8_R3.EntityHuman; -import net.minecraft.server.v1_8_R3.EntityLiving; - import org.bukkit.EntityEffect; import org.bukkit.GameMode; import org.bukkit.Location; @@ -48,6 +30,24 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; +import mineplex.core.MiniPlugin; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilGear; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.disguise.DisguiseManager; +import mineplex.core.npc.NpcManager; +import mineplex.minecraft.game.core.combat.CombatManager; +import mineplex.minecraft.game.core.condition.ConditionManager; +import mineplex.minecraft.game.core.damage.compatibility.NpcProtectListener; +import net.minecraft.server.v1_8_R3.DamageSource; +import net.minecraft.server.v1_8_R3.EntityHuman; +import net.minecraft.server.v1_8_R3.EntityLiving; + public class DamageManager extends MiniPlugin { private CombatManager _combatManager; @@ -231,24 +231,42 @@ public class DamageManager extends MiniPlugin @EventHandler public void onEntityCombust(EntityCombustByEntityEvent event) { + if (!_enabled) + return; + if (!(event.getCombuster() instanceof Player || event.getCombuster() instanceof Arrow)) return; event.setCancelled(true); } - @EventHandler(priority = EventPriority.HIGHEST) - public void removeDemArrowsCrazyMan(EntityDamageEvent event) + /** + * Removes arrows after hit, especially in cases where arrows may bounce, like if the damage was cancelled. + */ + @EventHandler(priority = EventPriority.MONITOR) + public void removeArrows(EntityDamageEvent event) { - if (event.isCancelled()) - { - Projectile projectile = GetProjectile(event); + Projectile projectile = GetProjectile(event); - if (projectile instanceof Arrow) - { - projectile.teleport(new Location(projectile.getWorld(), 0, 0, 0)); - projectile.remove(); - } + if (projectile instanceof Arrow) + { + projectile.teleport(new Location(projectile.getWorld(), 0, 0, 0)); + projectile.remove(); + } + } + + /** + * Removes arrows after hit, especially in cases where arrows may bounce, like if the damage was cancelled. + */ + @EventHandler(priority = EventPriority.MONITOR) + public void removeArrows(CustomDamageEvent event) + { + Projectile projectile = event.GetProjectile(); + + if (projectile instanceof Arrow) + { + projectile.teleport(new Location(projectile.getWorld(), 0, 0, 0)); + projectile.remove(); } } /* @@ -315,6 +333,12 @@ public class DamageManager extends MiniPlugin event.SetCancelled("0 Health"); return; } + + if (event.GetProjectile() != null && event.GetDamageeEntity().equals(event.GetProjectile().getShooter()) && !event.getProjectileDamageSelf()) + { + event.SetCancelled("Self Projectile Damage"); + return; + } if (event.GetDamageePlayer() != null) { @@ -375,6 +399,10 @@ public class DamageManager extends MiniPlugin Player damagee = event.GetDamageePlayer(); if (damagee != null) { + if (event.GetDamage() <= 0) + { + return; + } if (getTotalEnchantReduction(damagee.getInventory().getArmorContents(), event.GetCause()) > 0) { event.AddMult("Ench Prot", damagee.getName(), getTotalEnchantReduction(damagee.getInventory().getArmorContents(), event.GetCause()), false); @@ -432,6 +460,8 @@ public class DamageManager extends MiniPlugin Player player = event.GetDamagerPlayer(true); if (player != null) { + if (player.equals(event.GetDamageeEntity()) && !event.getProjectileDamageSelf()) return; + player.playSound(player.getLocation(), Sound.ORB_PICKUP, 0.5f, 0.5f); } } @@ -456,6 +486,11 @@ public class DamageManager extends MiniPlugin if (event.GetDamageeEntity().getHealth() <= 0) return; + if (event.GetProjectile() != null && + event.GetDamageeEntity().equals(event.GetProjectile().getShooter()) && + !event.getProjectileDamageSelf()) + return; + //Player Conditions if (event.GetDamageePlayer() != null) { @@ -510,14 +545,21 @@ public class DamageManager extends MiniPlugin origin = event.GetDamagerEntity(true).getLocation(); if (event.getKnockbackOrigin() != null) origin = event.getKnockbackOrigin(); - else if (event.GetProjectile() != null) - origin = event.GetProjectile().getLocation(); //Vec Vector trajectory = UtilAlg.getTrajectory2d(origin, event.GetDamageeEntity().getLocation()); trajectory.multiply(0.6 * knockback); trajectory.setY(Math.abs(trajectory.getY())); - + + //Special handling for projectiles + if(event.GetProjectile() != null && event.getKnockbackOrigin() == null) + { + trajectory = event.GetProjectile().getVelocity(); + trajectory.setY(0); + trajectory.multiply(0.6 * knockback / trajectory.length()); + trajectory.setY(0.5); + } + //Apply double vel = 0.2 + trajectory.length() * 0.8; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 02245e363..75aea7dfa 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -172,6 +172,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation private KitProgressionManager _kitProgressionManager; private ProgressingKitManager _progressionKitManager; private BoosterManager _boosterManager; + private GameSpectatorManager _spectatorManager; private IncognitoManager _incognitoManager; @@ -290,7 +291,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation YoutubeManager youtubeManager = new YoutubeManager(plugin, clientManager, donationManager); _bonusManager = new BonusManager(plugin, clientManager, serverStatusManager, donationManager, pollManager , npcManager, hologramManager, statsManager, _inventoryManager, petManager, facebookManager, youtubeManager, _cosmeticManager.getGadgetManager(), boosterManager); new GameLootManager(this, petManager, _bonusManager.getRewardManager()); - new GameSpectatorManager(this); + _spectatorManager = new GameSpectatorManager(this); _gameWorldManager = new GameWorldManager(this); new MiscManager(this); _hologramManager = hologramManager; @@ -1705,4 +1706,9 @@ public class ArcadeManager extends MiniPlugin implements IRelation { return _kitProgressionManager; } + + public GameSpectatorManager getGameSpectatorManager() + { + return _spectatorManager; + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index 94f0fa25e..d81e0597e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -24,6 +24,7 @@ import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.events.PlayerGameRespawnEvent; import nautilus.game.arcade.events.PlayerStateChangeEvent; import nautilus.game.arcade.game.GameTeam.PlayerState; +import nautilus.game.arcade.game.modules.Module; import nautilus.game.arcade.kit.*; import nautilus.game.arcade.managers.GameLobbyManager; import nautilus.game.arcade.managers.chat.ChatStatData; @@ -314,8 +315,6 @@ public abstract class Game implements Listener public boolean AllowEntitySpectate = true; - public boolean PlayerTeamSelection = false; - public boolean TeamMode = false; public boolean TeamPerSpawn = false; @@ -335,6 +334,8 @@ public abstract class Game implements Listener private NautHashMap _teamReqs = new NautHashMap(); public WinEffectManager WinEffectManager = new WinEffectManager(); + private Map, Module> _modules = new HashMap<>(); + public Game(ArcadeManager manager, GameType gameType, Kit[] kits, String[] gameDesc) { Manager = manager; @@ -421,6 +422,20 @@ public abstract class Game implements Listener System.out.println("Loading " + GetName() + "..."); } + public void registerModule(Module module) + { + if (!_modules.containsKey(module.getClass())) + { + module.initialize(this); + _modules.put(module.getClass(), module); + UtilServer.RegisterEvents(module); + } + else + { + throw new IllegalStateException("Module " + module.getClass() + " is already registered"); + } + } + public void setKits(Kit[] kits) { _kits = kits; @@ -1912,157 +1927,6 @@ public abstract class Game implements Listener } } - @EventHandler(priority = EventPriority.HIGH) - public void teamSelectInteract(PlayerInteractEntityEvent event) - { - if (!PlayerTeamSelection) - return; - - if (GetState() != GameState.Recruit) - return; - - if (event.getRightClicked() == null) - return; - - if (!(event.getRightClicked() instanceof Player)) - return; - - Player player = event.getPlayer(); - - //Observer - if (Manager.IsObserver(player)) - { - UtilPlayer.message(player, F.main("Game", "Spectators cannot partake in games.")); - return; - } - - selectTeamMate(player, (Player) event.getRightClicked()); - } - - @EventHandler - public void teamSelectCommand(PlayerCommandPreprocessEvent event) - { - if (!PlayerTeamSelection) - return; - - if (GetState() != GameState.Recruit) - return; - - if (!event.getMessage().toLowerCase().startsWith("/team ")) - return; - - event.setCancelled(true); - - Player target = UtilPlayer.searchOnline(event.getPlayer(), event.getMessage().split(" ")[1], - true); - if (target == null) - return; - - //Observer - if (Manager.IsObserver(event.getPlayer())) - { - UtilPlayer.message(event.getPlayer(), - F.main("Game", "Spectators cannot partake in games.")); - return; - } - - if (event.getPlayer().equals(target)) - return; - - selectTeamMate(event.getPlayer(), target); - } - - public void selectTeamMate(Player player, Player ally) - { - //Accept Invite - if (_teamReqs.containsKey(ally) && _teamReqs.get(ally).equals(player)) - { - //Remove Prefs - _teamReqs.remove(player); - _teamReqs.remove(ally); - - //Inform - UtilPlayer.message(player, - F.main("Game", "You accepted " + ally.getName() + "'s Team Request!")); - UtilPlayer.message(ally, - F.main("Game", player.getName() + " accepted your Team Request!")); - - //Leave Old Teams - if (GetTeam(player) != null) - GetTeam(player).DisbandTeam(); - - if (GetTeam(ally) != null) - GetTeam(ally).DisbandTeam(); - - //Get Team - GameTeam team = getEmptyTeam(); - if (team == null) - return; - - //Join Team - SetPlayerTeam(player, team, true); - SetPlayerTeam(ally, team, true); - } - //Send Invite - else - { - //Already on Team with Target - if (GetTeam(player) != null) - if (GetTeam(player).HasPlayer(ally)) - return; - - //Inform Player - UtilPlayer.message(player, - F.main("Game", "You sent a Team Request to " + ally.getName() + "!")); - - //Inform Target - if (Recharge.Instance.use(player, "Team Req " + ally.getName(), 2000, false, false)) - { - UtilPlayer.message(ally, - F.main("Game", player.getName() + " sent you a Team Request!")); - UtilPlayer.message(ally, F.main("Game", - "Type " + F.elem("/team " + player.getName()) + " to accept!")); - } - - //Add Pref - _teamReqs.put(player, ally); - } - } - - @EventHandler - public void teamQuit(PlayerQuitEvent event) - { - if (!PlayerTeamSelection) - return; - - if (GetState() != GameState.Recruit) - return; - - Player player = event.getPlayer(); - - if (GetTeam(player) != null) - GetTeam(player).DisbandTeam(); - - Iterator teamIter = _teamReqs.keySet().iterator(); - while (teamIter.hasNext()) - { - Player sender = teamIter.next(); - if (sender.equals(player) || _teamReqs.get(sender).equals(player)) - teamIter.remove(); - } - } - - public GameTeam getEmptyTeam() - { - for (GameTeam team : GetTeamList()) - { - if (team.GetPlayers(false).isEmpty()) - return team; - } - - return null; - } - @EventHandler public void CustomTeamGeneration(GameStateChangeEvent event) { @@ -2286,4 +2150,17 @@ public abstract class Game implements Listener { } + public void cleanupModules() + { + for (Module module : this._modules.values()) + { + module.cleanup(); + HandlerList.unregisterAll(module); + } + } + + public T getModule(Class clazz) + { + return clazz.cast(_modules.get(clazz)); + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameTeam.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameTeam.java index 36bd685e2..701dfe0cf 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameTeam.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/GameTeam.java @@ -24,6 +24,7 @@ import org.bukkit.Location; import org.bukkit.entity.Creature; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.scoreboard.Team; public class GameTeam { @@ -192,7 +193,11 @@ public class GameTeam { for(Player other : UtilServer.getPlayers()) { - other.getScoreboard().getTeam(Host.Manager.GetClients().Get(player).GetRank().Name + _name.toUpperCase()).removePlayer(player); + Team team = other.getScoreboard().getTeam(Host.Manager.GetClients().Get(player).GetRank().Name + _name.toUpperCase()); + if (team != null) + { + team.removePlayer(player); + } other.getScoreboard().getTeam(Host.Manager.GetClients().Get(player).GetRank().Name).addPlayer(player); } UtilPlayer.message(player, F.main("Team", _color + C.Bold + getDisplayName() + " Team was disbanded.")); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/modes/TeamBuild.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/modes/TeamBuild.java index e2abb1537..0fb700e65 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/modes/TeamBuild.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/modes/TeamBuild.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; +import nautilus.game.arcade.game.modules.TeamModule; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Sound; @@ -40,7 +41,9 @@ public class TeamBuild extends Build super(manager, GameType.Brawl); TeamMode = true; - PlayerTeamSelection = true; + + registerModule(new TeamModule()); + TeamPerSpawn = true; FillTeamsInOrderToCount = 2; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/MineStrike.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/MineStrike.java index 817196908..33e1bd360 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/MineStrike.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/MineStrike.java @@ -2138,7 +2138,13 @@ public class MineStrike extends TeamGame team.SpawnTeleport(false); //Revive Dead Players - for (Player player : GetPlayers(false)) + for (Player player : GetPlayers(false)) + { + if (Manager.isVanished(player)) + { + continue; + } + if (!IsAlive(player)) { SetPlayerState(player, PlayerState.IN); @@ -2156,6 +2162,7 @@ public class MineStrike extends TeamGame if (GetKit(player) != null) GetKit(player).ApplyKit(player); } + } //Remove Scope for (Player player : GetPlayers(false)) @@ -2319,6 +2326,11 @@ public class MineStrike extends TeamGame if (GetState() == GameState.Recruit || GetState() == GameState.Loading) return; + if (Manager.isVanished(event.getPlayer())) + { + return; + } + //Target Team GameTeam targetTeam = null; if (GetTeamList().get(0).GetPlayers(false).size() < GetTeamList().get(1).GetPlayers(false).size()) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/HighExplosive.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/HighExplosive.java index 02c7b7300..c46e246d7 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/HighExplosive.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/grenades/HighExplosive.java @@ -52,7 +52,13 @@ public class HighExplosive extends Grenade continue; // Damage Event - game.Manager.GetDamage().NewDamageEvent(player, _thrower, null, ent.getLocation(), + Player damager = null; + if (game.IsAlive(_thrower)) + { + damager = _thrower; + } + + game.Manager.GetDamage().NewDamageEvent(player, damager, null, ent.getLocation(), DamageCause.CUSTOM, 1 + (players.get(player) * 18), true, true, false, _thrower.getName(), getName()); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/TeamSkywars.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/TeamSkywars.java index ba2949dd2..2b470ce33 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/TeamSkywars.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/TeamSkywars.java @@ -19,6 +19,7 @@ import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.Game.GameState; +import nautilus.game.arcade.game.modules.TeamModule; import nautilus.game.arcade.stats.DeathBomberStatTracker; import nautilus.game.arcade.stats.SkywarsKillZombieStatTracker; import nautilus.game.arcade.stats.SkywarsTNTStatTracker; @@ -78,10 +79,11 @@ public class TeamSkywars extends Skywars DamageTeamSelf = false; DontAllowOverfill = true; - - PlayerTeamSelection = true; + TeamMode = true; TeamPerSpawn = true; + + registerModule(new TeamModule()); } @Override diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/TeamSuperSmash.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/TeamSuperSmash.java index 3757bf8ee..3fb05c19c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/TeamSuperSmash.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/TeamSuperSmash.java @@ -15,6 +15,7 @@ import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.modules.TeamModule; import nautilus.game.arcade.managers.chat.ChatStatData; import nautilus.game.arcade.stats.FreeKitWinStatTracker; import nautilus.game.arcade.stats.KillFastStatTracker; @@ -55,7 +56,8 @@ public class TeamSuperSmash extends SuperSmash DontAllowOverfill = true; TeamMode = true; - PlayerTeamSelection = true; + + registerModule(new TeamModule()); registerStatTrackers( new WinWithoutDyingStatTracker(this, "MLGPro"), diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/speedbuilders/SpeedBuilders.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/speedbuilders/SpeedBuilders.java index da4406b2c..0c02a2c71 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/speedbuilders/SpeedBuilders.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/speedbuilders/SpeedBuilders.java @@ -55,7 +55,6 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; import org.bukkit.entity.ArmorStand; @@ -1541,6 +1540,13 @@ public class SpeedBuilders extends SoloGame UtilPlayer.message(event.getPlayer(), F.main("Build", "Cannot build outside your area!")); } + else + { + if (liquid.getType() == Material.STATIONARY_WATER || liquid.getType() == Material.WATER) + { + event.setCancelled(true); + } + } } @EventHandler @@ -1694,6 +1700,39 @@ public class SpeedBuilders extends SoloGame UtilAction.velocity(event.getPlayer(), new Vector(0, 1, 0)); } + + @EventHandler + public void fixDoorToggling(PlayerInteractEvent event) + { + if (!IsLive()) + return; + + if (_state != SpeedBuildersState.BUILDING) + return; + + if (!_buildRecreations.containsKey(event.getPlayer())) + return; + + if (_perfectBuild.containsKey(event.getPlayer())) + { + event.setCancelled(true); + return; + } + + if (event.getPlayer().getItemInHand() == null) + { + event.setCancelled(true); + return; + } + + Block block = event.getClickedBlock().getRelative(event.getBlockFace()); + + if (!_buildRecreations.get(event.getPlayer()).inBuildArea(block)) + { + event.setCancelled(true); + UtilPlayer.message(event.getPlayer(), F.main("Build", "Cannot build outside your area!")); + } + } @Override public void EndCheck() diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/speedbuilders/data/RecreationData.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/speedbuilders/data/RecreationData.java index 268434338..2bf2488c0 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/speedbuilders/data/RecreationData.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/speedbuilders/data/RecreationData.java @@ -324,6 +324,12 @@ public class RecreationData score++; } + //Fix for glowing redstone ore + if ((expectedState.getType() == Material.REDSTONE_ORE && currentBlock.getType() == Material.GLOWING_REDSTONE_ORE) || (expectedState.getType() == Material.GLOWING_REDSTONE_ORE && currentBlock.getType() == Material.REDSTONE_ORE)) + { + score++; + } + //Fix for corner stair shape if (currentBlock.getState().getData() instanceof Stairs && expectedState.getData() instanceof Stairs) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/TeamSurvivalGames.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/TeamSurvivalGames.java index 286426457..99d49393b 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/TeamSurvivalGames.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/TeamSurvivalGames.java @@ -17,6 +17,7 @@ import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.modules.TeamModule; import nautilus.game.arcade.managers.chat.ChatStatData; import nautilus.game.arcade.stats.FirstSupplyDropOpenStatTracker; import nautilus.game.arcade.stats.KillsWithinTimeLimitStatTracker; @@ -59,7 +60,8 @@ public class TeamSurvivalGames extends SurvivalGames DontAllowOverfill = true; TeamMode = true; - PlayerTeamSelection = true; + + registerModule(new TeamModule()); registerStatTrackers(new WinWithoutWearingArmorStatTracker(this), new KillsWithinTimeLimitStatTracker(this, 3, 60, "Bloodlust"), diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHC.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHC.java index a6d564eea..e4af92f98 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHC.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/UHC.java @@ -1,30 +1,15 @@ package nautilus.game.arcade.game.games.uhc; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - import com.mineplex.spigot.ChunkPreLoadEvent; import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.checks.access.IViolationInfo; import fr.neatmonster.nocheatplus.hooks.NCPHook; import fr.neatmonster.nocheatplus.hooks.NCPHookManager; -import mineplex.core.common.Pair; +import mineplex.core.account.CoreClient; +import mineplex.core.boosters.event.BoosterItemGiveEvent; +import mineplex.core.common.Rank; import mineplex.core.common.util.C; import mineplex.core.common.util.F; -import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; @@ -43,8 +28,6 @@ import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.combat.CombatLog; import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; -import mineplex.minecraft.game.core.damage.CustomDamageEvent; -import mineplex.serverdata.Utility; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GamePrepareCountdownCommence; @@ -53,16 +36,13 @@ import nautilus.game.arcade.events.PlayerPrepareTeleportEvent; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.TeamGame; +import nautilus.game.arcade.game.games.uhc.helpers.ChunkLoadingThread; +import nautilus.game.arcade.game.games.uhc.helpers.WorldGenThread; +import nautilus.game.arcade.game.modules.TeamModule; import nautilus.game.arcade.kit.Kit; - -import net.minecraft.server.v1_8_R3.BiomeCache; -import net.minecraft.server.v1_8_R3.ChunkProviderServer; -import net.minecraft.server.v1_8_R3.ChunkRegionLoader; -import net.minecraft.server.v1_8_R3.FileIOThread; -import net.minecraft.server.v1_8_R3.IChunkProvider; +import net.minecraft.server.v1_8_R3.Chunk; +import net.minecraft.server.v1_8_R3.MathHelper; import net.minecraft.server.v1_8_R3.MinecraftServer; -import net.minecraft.server.v1_8_R3.NBTTagCompound; -import net.minecraft.server.v1_8_R3.WorldChunkManager; import net.minecraft.server.v1_8_R3.WorldServer; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -70,41 +50,39 @@ import org.bukkit.Difficulty; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; -import org.bukkit.World; -import org.bukkit.WorldBorder; import org.bukkit.World.Environment; +import org.bukkit.WorldBorder; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.craftbukkit.v1_8_R3.CraftChunk; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_8_R3.util.LongHash; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.ExperienceOrb; import org.bukkit.entity.Ghast; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Monster; import org.bukkit.entity.Player; -import org.bukkit.entity.Villager; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; -import org.bukkit.event.entity.EntitySpawnEvent; +import org.bukkit.event.entity.EntityTargetLivingEntityEvent; import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.PrepareItemCraftEvent; -import org.bukkit.event.player.AsyncPlayerPreLoginEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerItemConsumeEvent; import org.bukkit.event.player.PlayerKickEvent; -import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -120,42 +98,48 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; -import org.spigotmc.AsyncCatcher; +import org.spigotmc.ActivationRange; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; public class UHC extends TeamGame implements NCPHook { // The view distance of UHC. The amount of time and ram needed grows polynomially - private static final int VIEW_DISTANCE = 5; + public static final int VIEW_DISTANCE = 5; // The number of threads to use for reading chunks from disk - private static final int THREADS_FOR_CHUNK_LOADING = 4; + public static final int THREADS_FOR_CHUNK_LOADING = 4; - private NautHashMap _teamReqs = new NautHashMap(); + // The number of minutes after which PVP should be enabled + public static final int SAFE_TIME_IN_MINUTES = 11; - private NautHashMap _deathTime = new NautHashMap(); - // private NautHashMap _combatTime = new NautHashMap(); + // The thread responsible for generating the world + private final WorldGenThread _worldGenThread = new WorldGenThread(this); - private volatile boolean _mapLoaded = false; - private volatile double _mapLoadPercent = 0; - private volatile int _chunksPerTick = 1; - private volatile boolean stopGen = false; + // The thread responsible for loading and decorating the world + private final ChunkLoadingThread _chunkLoadingThread = new ChunkLoadingThread(this); - private int _chunkTotal; - private int _chunkX = 0; - private int _chunkZ = 0; - private int _chunksLoaded = 0; + // The number of minutes passed in this game + private int _minutesSinceStart = 0; - private int _gameMinutes = 0; - private int _safeTime = 11; - private long _lastMinute = System.currentTimeMillis(); + // The Objective representing the tab list health display + private Objective _healthObjective; - private Objective _scoreObj; + // The number of players which have been teleported + private int _teleportedPlayers = -1; + // The total number of players to teleport + private int _totalPlayers = 0; + // Whether players are teleporting currently + private volatile boolean _isTeleporting = false; - private long _createTime; - private long _serverTime; - - - private boolean xrayDebug = false; + private boolean xrayDebug; // Border private int _secondsSinceStart; @@ -164,14 +148,6 @@ public class UHC extends TeamGame implements NCPHook private double _previousBorder = 1000; private long _borderStartedMoving; - - private volatile boolean _isDecorating = false; - private volatile boolean _allowSpawning = true; - private int _teleportedPlayers = -1; - private int _totalPlayers = 0; - private AtomicInteger actual = new AtomicInteger(); - private AtomicInteger expected = new AtomicInteger(23000); // Most likely it'll be around 23000 - public UHC(ArcadeManager manager) { this(manager, GameType.UHC); @@ -252,6 +228,8 @@ public class UHC extends TeamGame implements NCPHook WorldTimeSet = -1; + this.WorldLeavesDecay = true; + CraftRecipes(); // Disable Custom Mob Drops (and EXP Disable) @@ -263,13 +241,12 @@ public class UHC extends TeamGame implements NCPHook // Damage Settings Manager.GetDamage().SetEnabled(false); - _scoreObj = Scoreboard.GetScoreboard().registerNewObjective("Health", "health"); - _scoreObj.setDisplaySlot(DisplaySlot.PLAYER_LIST); - - _createTime = System.currentTimeMillis(); - _serverTime = Utility.currentTimeMillis(); + _healthObjective = Scoreboard.GetScoreboard().registerNewObjective("Health", "health"); + _healthObjective.setDisplaySlot(DisplaySlot.PLAYER_LIST); NCPHookManager.addHook(CheckType.ALL, this); + + registerModule(new TeamModule()); } @Override @@ -277,10 +254,6 @@ public class UHC extends TeamGame implements NCPHook { WorldData.World.setDifficulty(Difficulty.HARD); - _chunkX = (int) -(_currentBorder / 16); - _chunkZ = (int) -(_currentBorder / 16); - _chunkTotal = (int) ((_currentBorder * 2 / 16) * (_currentBorder * 2 / 16)); - WorldData.MinX = -1000; WorldData.MinZ = -1000; WorldData.MaxX = 1000; @@ -499,323 +472,18 @@ public class UHC extends TeamGame implements NCPHook worldServer.spigotConfig.viewDistance = VIEW_DISTANCE; worldServer.getPlayerChunkMap().a(VIEW_DISTANCE); - if (Runtime.getRuntime().maxMemory() / 1024 / 1024 < 2048) + if (Runtime.getRuntime().maxMemory() / 1024 / 1024 < 1536) { Announce(C.cGreen + C.Bold + "Skipping spawn pregeneration", false); + // Allow game to start + _chunkLoadingThread.flagDone(); return; } // Ensures the server does not tick us worldServer.getMinecraftServer().worlds.remove(worldServer); - _allowSpawning = false; - - new Thread(() -> - { - try - { - TimingManager.start("UHC Chunk Loading"); - - ChunkProviderServer chunkProviderServer = worldServer.chunkProviderServer; - - Field chunkLoaderField = chunkProviderServer.getClass().getDeclaredField("chunkLoader"); - chunkLoaderField.setAccessible(true); - - ChunkRegionLoader loader = (ChunkRegionLoader) chunkLoaderField.get(chunkProviderServer); - - Map loaded = new ConcurrentHashMap<>(); - Map compounds = new ConcurrentHashMap<>(); - - // Step 1: Read all the required chunks from the disk - // We're going to read all the required chunks from disk async - { - Set> coordPairs = new HashSet<>(); - - // Special case for 0, 0 - { - int x = spawn.getBlockX() >> 4; - int z = spawn.getBlockZ() >> 4; - - for (int dx = -VIEW_DISTANCE; dx <= VIEW_DISTANCE; dx++) - { - for (int dz = -VIEW_DISTANCE; dz <= VIEW_DISTANCE; dz++) - { - coordPairs.add(Pair.create(x + dx, z + dz)); - } - } - } - - // All the team spawns - { - for (int i = 0; i < GetTeamList().size(); i++) - { - GameTeam team = GetTeamList().get(i); - for (Location l : team.GetSpawns()) - { - int x = l.getChunk().getX(); - int z = l.getChunk().getZ(); - - for (int dx = -VIEW_DISTANCE; dx <= VIEW_DISTANCE; dx++) - { - for (int dz = -VIEW_DISTANCE; dz <= VIEW_DISTANCE; dz++) - { - coordPairs.add(Pair.create(x + dx, z + dz)); - } - } - } - } - } - - // Sigh... I don't want this to be here but it needs to be set somewhere... - // Multiply by 3 because there are 3 stages - expected.set(coordPairs.size() * 3); - - // Load them now - ExecutorService chunkLoaders = Executors.newFixedThreadPool(THREADS_FOR_CHUNK_LOADING); - - for (Pair coords : coordPairs) - { - chunkLoaders.submit(() -> - { - try - { - Object[] data = loader.loadChunk(worldServer, coords.getLeft(), coords.getRight()); - if (data != null) - { - NBTTagCompound compound = (NBTTagCompound) data[1]; - net.minecraft.server.v1_8_R3.Chunk chunk = (net.minecraft.server.v1_8_R3.Chunk) data[0]; - loaded.put(LongHash.toLong(coords.getLeft(), coords.getRight()), chunk); - compounds.put(LongHash.toLong(coords.getLeft(), coords.getRight()), compound); - } - else - { - System.out.println("Failed to load chunk " + coords.getLeft() + "," + coords.getRight()); - } - } - catch (Throwable t) - { - t.printStackTrace(); - } - finally - { - actual.getAndIncrement(); - } - }); - } - - chunkLoaders.shutdown(); - - // We've got plenty of time to wait - System.out.println("Finished submitting tasks to executor, waiting..."); - chunkLoaders.awaitTermination(1, TimeUnit.DAYS); - - System.out.println("Loaded: " + loaded.size() + " and coords: " + coordPairs.size()); - } - - // Step 2: Recreate structures, update neighbors, load entities - // This step should be super quick so there's no point in scheduling it elsewhere - // Code is plain copypasted from ChunkIOProvider - { - for (net.minecraft.server.v1_8_R3.Chunk chunk : loaded.values()) - { - NBTTagCompound compound = compounds.get(LongHash.toLong(chunk.locX, chunk.locZ)); - loader.loadEntities(chunk, compound.getCompound("Level"), worldServer); - chunk.setLastSaved(chunkProviderServer.world.getTime()); - if (chunkProviderServer.chunkProvider != null) - { - chunkProviderServer.chunkProvider.recreateStructures(chunk, chunk.locX, chunk.locZ); - } - for (int x = -2; x < 3; ++x) - { - for (int z = -2; z < 3; ++z) - { - if (x != 0 || z != 0) - { - net.minecraft.server.v1_8_R3.Chunk neighbor = loaded.get(LongHash.toLong(chunk.locX + x, chunk.locZ + z)); - if (neighbor != null) - { - neighbor.setNeighborLoaded(-x, -z); - chunk.setNeighborLoaded(x, z); - } - } - } - } - actual.getAndIncrement(); - } - } - - AtomicBoolean lockCompleted = new AtomicBoolean(false); - Object lock = new Object(); - - // Hop back onto the main thread - Manager.runSync(() -> - { - // We want to add all the chunks to the chunkmap so that the server is not out of sync - for (Map.Entry ent : loaded.entrySet()) - { - ent.getValue().addEntities(); - chunkProviderServer.chunks.put(ent.getKey(), ent.getValue()); - } - lockCompleted.set(true); - synchronized (lock) - { - lock.notifyAll(); - } - }); - - if (!lockCompleted.get()) - { - synchronized (lock) - { - lock.wait(); - } - } - if (!lockCompleted.get()) - { - throw new IllegalStateException("Lock was not completed"); - } - - - // Step 3: Decorate the chunks. This step must be performed async as otherwise the server lags way too hard - // Notes: Do not allow the server to tick the world. If this is allowed EntityTracker will raise CME - // NextTickList will also raise errors - // And worst case the server will crash - { - // Live life on the edge - AsyncCatcher.enabled = false; - _isDecorating = true; - int x = 0; - for (net.minecraft.server.v1_8_R3.Chunk chunk : loaded.values()) - { - loadNearby(chunkProviderServer, chunkProviderServer, chunk.locX, chunk.locZ, worldServer, chunk); - x++; - if (x % 100 == 0) - { - System.out.println(x); - } - actual.getAndIncrement(); - } - TimingManager.stop("UHC Chunk Loading"); - _isDecorating = false; - AsyncCatcher.enabled = true; - - System.out.println("Expected: " + expected.get() + ", actual: " + actual.get()); - - Manager.runSync(() -> - { - World world = worldServer.getWorld(); - for (Entity entity : world.getLivingEntities()) - { - if (!(entity instanceof Player) && !(entity instanceof Villager)) - { - entity.remove(); - } - } - // You may tick again - worldServer.getMinecraftServer().worlds.add(worldServer); - - // Well, if they're not equal, not much we can do. We've hit the end - actual.set(expected.get()); - }); - } - } - catch (Throwable t) - { - t.printStackTrace(); - } - }, "Chunk Loader").start(); - } - - // Plain copypasted from Chunk, but modified so that it doesn't load surrounding chunks if they're nonexistant - // This decorates the chunks. Do not remove! - public void loadNearby(ChunkProviderServer ichunkprovider, ChunkProviderServer ichunkprovider1, int i, int j, net.minecraft.server.v1_8_R3.World world, net.minecraft.server.v1_8_R3.Chunk chunk1) - { - boolean flag = ichunkprovider.isChunkLoaded(i, j - 1); - boolean flag1 = ichunkprovider.isChunkLoaded(i + 1, j); - boolean flag2 = ichunkprovider.isChunkLoaded(i, j + 1); - boolean flag3 = ichunkprovider.isChunkLoaded(i - 1, j); - boolean flag4 = ichunkprovider.isChunkLoaded(i - 1, j - 1); - boolean flag5 = ichunkprovider.isChunkLoaded(i + 1, j + 1); - boolean flag6 = ichunkprovider.isChunkLoaded(i - 1, j + 1); - boolean flag7 = ichunkprovider.isChunkLoaded(i + 1, j - 1); - if (flag1 && flag2 && flag5) - { - if (!chunk1.isDone()) - { - ichunkprovider.getChunkAt(ichunkprovider1, i, j); - } - else - { - ichunkprovider.a(ichunkprovider1, chunk1, i, j); - } - } - - net.minecraft.server.v1_8_R3.Chunk chunk; - if (flag3 && flag2 && flag6) - { - chunk = ichunkprovider.getChunkIfLoaded(i - 1, j); - if (chunk != null) - { - if (!chunk.isDone()) - { - ichunkprovider.getChunkAt(ichunkprovider1, i - 1, j); - } - else - { - ichunkprovider.a(ichunkprovider1, chunk, i - 1, j); - } - } - } - - if (flag && flag1 && flag7) - { - chunk = ichunkprovider.getChunkIfLoaded(i, j - 1); - if (chunk != null) - { - if (!chunk.isDone()) - { - ichunkprovider.getChunkAt(ichunkprovider1, i, j - 1); - } - else - { - ichunkprovider.a(ichunkprovider1, chunk, i, j - 1); - } - } - } - - if (flag4 && flag && flag3) - { - chunk = ichunkprovider.getChunkIfLoaded(i - 1, j - 1); - if (chunk != null) - { - if (!chunk.isDone()) - { - ichunkprovider.getChunkAt(ichunkprovider1, i - 1, j - 1); - } - else - { - ichunkprovider.a(ichunkprovider1, chunk, i - 1, j - 1); - } - } - } - } - - @EventHandler - public void on(EntitySpawnEvent event) - { - // Don't allow entity spawns while decorating, period - if (_isDecorating || !_allowSpawning) - { - if (event.getLocation().getWorld().getUID() == WorldData.World.getUID()) - { - event.setCancelled(true); - } - } - } - - private boolean areSpawnsGenerated() - { - return actual.get() == expected.get(); + _chunkLoadingThread.start(); } @EventHandler @@ -831,20 +499,16 @@ public class UHC extends TeamGame implements NCPHook if (!IsLive()) return; - if (event.getType() != UpdateType.FAST) + if (event.getType() != UpdateType.MIN_01) return; - if (!UtilTime.elapsed(_lastMinute, 60000)) - return; + _minutesSinceStart++; - _gameMinutes++; - _lastMinute = System.currentTimeMillis(); - - if (_gameMinutes < _safeTime) + if (_minutesSinceStart < SAFE_TIME_IN_MINUTES) { - UtilTextMiddle.display(null, "PvP enabled in " + (_safeTime - _gameMinutes) + " minutes.", 5, 80, 5); + UtilTextMiddle.display(null, "PvP enabled in " + (SAFE_TIME_IN_MINUTES - _minutesSinceStart) + " minutes.", 5, 80, 5); } - else if (_gameMinutes == _safeTime) + else if (_minutesSinceStart == SAFE_TIME_IN_MINUTES) { UtilTextMiddle.display(null, "PvP has been enabled!", 5, 80, 5); @@ -909,7 +573,14 @@ public class UHC extends TeamGame implements NCPHook { if (event.GetState() == GameState.Dead) { - stopGen = true; + _worldGenThread.flagStop(); + _chunkLoadingThread.flagStop(); + if (!_chunkLoadingThread.isDone()) + { + MinecraftServer.getServer().worlds.add(((CraftWorld) WorldData.World).getHandle()); + } + HandlerList.unregisterAll(_chunkLoadingThread); + NCPHookManager.removeHook(this); return; } @@ -918,180 +589,22 @@ public class UHC extends TeamGame implements NCPHook return; } - new Thread(() -> - { - try - { - Field fileIOThreadB = FileIOThread.class.getDeclaredField("b"); - fileIOThreadB.setAccessible(true); - - // This list is the list of chunks to be saved on the File IO Thread - List list = (List) fileIOThreadB.get(FileIOThread.a()); - - net.minecraft.server.v1_8_R3.WorldServer worldServer = ((CraftWorld) WorldData.World).getHandle(); - - WorldChunkManager manager = worldServer.getWorldChunkManager(); - - Field biomeCacheField = manager.getClass().getDeclaredField("d"); - biomeCacheField.setAccessible(true); - - // A thread safe BiomeCache - // The implementation is literally a copy/paste from the original BiomeCache, but with some synchronization - // Reason being while the server is ticking the world (for some reason, if you want to dig through the entire Arcade codebase go for it) - // it stores stuff in the BiomeCache, and chunk gen needs that BiomeCache info too - // Causing desynchronization in the cache - biomeCacheField.set(manager, new BiomeCache(manager) - { - private final Object _lock = new Object(); - - private long _lastCleanTime; // b -> _lastCleanTime - private Map _blockByCoord = new HashMap<>(); // LongHashMap -> HashMap, c -> _blockByCoord - private List _blocks = new ArrayList<>(); // d -> _blocks - - @Override - public BiomeCache.BiomeCacheBlock a(int x, int z) - { - x >>= 4; - z >>= 4; - long var3 = hash(x, z); - BiomeCache.BiomeCacheBlock var5 = this._blockByCoord.get(var3); - if (var5 == null) - { - var5 = new BiomeCache.BiomeCacheBlock(x, z); - synchronized (_lock) - { - this._blockByCoord.put(var3, var5); - this._blocks.add(var5); - } - } - - var5.e = MinecraftServer.az(); - return var5; - } - - @Override - public void a() - { - long currentTime = MinecraftServer.az(); - long deltaTime = currentTime - this._lastCleanTime; - if (deltaTime > 7500L || deltaTime < 0L) - { - this._lastCleanTime = currentTime; - - synchronized (_lock) - { - for (int i = 0; i < this._blocks.size(); ++i) - { - BiomeCache.BiomeCacheBlock biomeCacheBlock = (BiomeCache.BiomeCacheBlock) this._blocks.get(i); - long var7 = currentTime - biomeCacheBlock.e; - if (var7 > 30000L || var7 < 0L) - { - this._blocks.remove(i--); - this._blockByCoord.remove(hash(biomeCacheBlock.c, biomeCacheBlock.d)); - } - } - } - } - } - - private long hash(int x, int z) - { - return (long) x & 4294967295L | ((long) z & 4294967295L) << 32; - } - }); - - ChunkProviderServer cps = worldServer.chunkProviderServer; - IChunkProvider icp = cps.chunkProvider; - System.out.println("Using chunk provider " + icp.getClass()); - - TimingManager.start("Map Generation"); - - long start = System.currentTimeMillis(); - long last = start; - - while (!stopGen) - { - long now = System.currentTimeMillis(); - if ((now - last) >= 10 * 1000) - { - Announce(C.cGreen + C.Bold + "Generating Map: " + C.cWhite + getMapLoadETA() + " Remaining...", false); - last = now; - } - - long hash = LongHash.toLong(_chunkX, _chunkZ); - - // This is just a shortcut to how the Minecraft server would have generated a chunk if it doesn't exist. - // This should always create a chunk because we're not loading any chunks beforehand... - // /me looks at new maintainer - net.minecraft.server.v1_8_R3.Chunk chunk = icp.getOrCreateChunk(_chunkX, _chunkZ); - - // Run the copypasted code for chunk saving. - cps.saveChunk(chunk); - cps.saveChunkNOP(chunk); - cps.unloadQueue.remove(_chunkX, _chunkZ); - cps.chunks.remove(hash); - - if (_chunkX < _currentBorder / 16) - { - _chunkX++; - } - else if (_chunkZ < _currentBorder / 16) - { - _chunkX = (int) -(_currentBorder / 16); - _chunkZ++; - } - else - { - _mapLoaded = true; - System.out.println("Map Loading Finished! Took " + TimeUnit.MILLISECONDS.toSeconds(now - start) + " seconds"); - break; - } - - _chunksLoaded++; - - // Clamp it so we don't get 101% - _mapLoadPercent = UtilMath.clamp((double) _chunksLoaded / (double) _chunkTotal, 0.0, 1.0); - _chunksPerTick = (int) (_chunksLoaded / ((now - start) / 50.0)); - } - - TimingManager.stop("Map Generation"); - - if (stopGen) - { - return; - } - - TimingManager.start("Map Saving"); - - // Wait for all the chunks to save (but do we need this?) - while (!list.isEmpty()) - { - Thread.sleep(100); - } - - TimingManager.stop("Map Saving"); - - getArcadeManager().runSync(this::generateSpawns); - } - catch (Throwable t) - { - // todo proper exception handling - // maybe force shutdown? - t.printStackTrace(); - } - }, "WorldGen Thread").start(); + _worldGenThread.start(); } - @EventHandler + @EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = false) public void on(ChunkUnloadEvent event) { if (IsLive()) - return; - event.setCancelled(true); + { + event.setCancelled(false); + } + else + { + event.setCancelled(true); + } } - private volatile boolean _isTeleporting = false; - @EventHandler public void on(ChunkPreLoadEvent event) { @@ -1119,6 +632,9 @@ public class UHC extends TeamGame implements NCPHook if (event.GetState() != GameState.Prepare) return; + + Manager.GetChat().Silence(1000 * 120, false); + _isTeleporting = true; List players = game.GetPlayers(true); @@ -1128,6 +644,7 @@ public class UHC extends TeamGame implements NCPHook for (Player player : players) { player.teleport(zero); + player.hidePlayer(player); // Heal player.setHealth(player.getMaxHealth()); @@ -1136,7 +653,7 @@ public class UHC extends TeamGame implements NCPHook player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 30 * 20, 128), true); } - Announce(C.cGreen + C.Bold + "Please wait while you are teleported to your spawn", false); + Announce(C.cGreen + C.Bold + "Please wait, you will be teleported soon", false); _totalPlayers = players.size(); @@ -1148,6 +665,7 @@ public class UHC extends TeamGame implements NCPHook _teleportedPlayers++; if (_teleportedPlayers >= players.size()) { + Announce(C.cGreen + C.Bold + "The game will start in 5 seconds", false); Manager.runSyncLater(() -> { try @@ -1169,6 +687,8 @@ public class UHC extends TeamGame implements NCPHook player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 30 * 20, 128), true); player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 30 * 20, 128), true); } + + teleportedLocations.clear(); } finally { @@ -1188,14 +708,20 @@ public class UHC extends TeamGame implements NCPHook player.removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE); player.removePotionEffect(PotionEffectType.REGENERATION); } - }, 10 * 20L); - // Yes, right now they're both set to 10 seconds, but this may change in the future - Manager.runSyncLater(() -> - { - _allowSpawning = true; + + WorldData.World.setAutoSave(true); + + int x = 0; + for (org.bukkit.Chunk chunk : WorldData.World.getLoadedChunks()) + { + if (WorldData.World.unloadChunkRequest(chunk.getX(), chunk.getZ())) + { + System.out.println("Requesting unload of chunk #" + (++x) + " " + chunk.getX() + " " + chunk.getZ()); + } + } }, 10 * 20L); } - }, 3 * 20L); + }, 5 * 20L); Bukkit.getServer().getScheduler().cancelTask(id.get()); return; } @@ -1211,7 +737,7 @@ public class UHC extends TeamGame implements NCPHook teleportedLocations.put(player.getUniqueId(), team.SpawnTeleport(player)); // Update scoreboard - _scoreObj.getScore(player).setScore((int) player.getMaxHealth()); + _healthObjective.getScore(player).setScore((int) player.getMaxHealth()); game.addPlayerInTime(player); @@ -1234,7 +760,7 @@ public class UHC extends TeamGame implements NCPHook PlayerPrepareTeleportEvent playerStateEvent = new PlayerPrepareTeleportEvent(game, player); UtilServer.getServer().getPluginManager().callEvent(playerStateEvent); } - }, 4 * 20L, 4L).getTaskId()); + }, 5 * 20L, 5L).getTaskId()); //Spectators Move for (Player player : UtilServer.getPlayers()) @@ -1246,6 +772,55 @@ public class UHC extends TeamGame implements NCPHook } } + @Override + public Location GetSpectatorLocation() + { + if (SpectatorSpawn != null) + { + return SpectatorSpawn; + } + + SpectatorSpawn = WorldData.World.getSpawnLocation(); + + // Move Up - Out Of Blocks + while (!UtilBlock.airFoliage(SpectatorSpawn.getBlock()) + || !UtilBlock.airFoliage(SpectatorSpawn.getBlock().getRelative(BlockFace.UP))) + { + SpectatorSpawn.add(0, 1, 0); + } + + int Up = 0; + + // Move Up - Through Air + for (int i = 0; i < 15; i++) + { + if (UtilBlock.airFoliage(SpectatorSpawn.getBlock().getRelative(BlockFace.UP))) + { + SpectatorSpawn.add(0, 1, 0); + Up++; + } + else + { + break; + } + } + + // Move Down - Out Of Blocks + while (Up > 0 && !UtilBlock.airFoliage(SpectatorSpawn.getBlock()) + || !UtilBlock.airFoliage(SpectatorSpawn.getBlock().getRelative(BlockFace.UP))) + { + SpectatorSpawn.subtract(0, 1, 0); + Up--; + } + + SpectatorSpawn = SpectatorSpawn.getBlock().getLocation().add(0.5, 0.1, 0.5); + + while (SpectatorSpawn.getBlock().getTypeId() != 0 || SpectatorSpawn.getBlock().getRelative(BlockFace.UP).getTypeId() != 0) + SpectatorSpawn.add(0, 1, 0); + + return SpectatorSpawn; + } + @EventHandler public void WorldBoundaryYLimit(BlockPlaceEvent event) { @@ -1291,7 +866,7 @@ public class UHC extends TeamGame implements NCPHook if (block.getRelative(BlockFace.DOWN).isLiquid()) continue; - if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR) + if (!block.getRelative(BlockFace.DOWN).getType().isSolid()) continue; // Suffocated @@ -1373,9 +948,6 @@ public class UHC extends TeamGame implements NCPHook long timeAlive = System.currentTimeMillis() - GetStateTime(); AddGems(player, timeAlive / 60000d, "Survived " + UtilTime.MakeStr(timeAlive), false, false); } - - // Time - _deathTime.put(player.getName(), System.currentTimeMillis()); } @EventHandler(priority = EventPriority.HIGH) @@ -1414,21 +986,21 @@ public class UHC extends TeamGame implements NCPHook } @EventHandler - public void PlayerDeathTimeKick(UpdateEvent event) + public void on(EntityTargetLivingEntityEvent event) { - if (event.getType() != UpdateType.SEC) - return; - - for (Player player : UtilServer.getPlayers()) + if (event.getEntity() instanceof ExperienceOrb) { - if (!_deathTime.containsKey(player.getName())) - continue; + if (event.getTarget() instanceof Player) + { + Player player = (Player) event.getTarget(); - if (!UtilTime.elapsed(_deathTime.get(player.getName()), 20000)) - continue; + Game game = Manager.GetGame(); - _deathTime.remove(player.getName()); - // XXX Need this ? Manager.GetPortal().SendPlayerToServer(player, "Lobby"); + if (game == null || !game.IsAlive(player) || game.GetState() != GameState.Live) + { + event.setCancelled(true); + } + } } } @@ -1644,6 +1216,21 @@ public class UHC extends TeamGame implements NCPHook event.setCancelled(true); } + @EventHandler + public void on(InventoryClickEvent event) + { + Player clicker = (Player) event.getWhoClicked(); + if (!IsAlive(clicker)) + event.setCancelled(true); + } + + @EventHandler + public void on(BoosterItemGiveEvent event) + { + if (IsAlive(event.getPlayer())) + event.setCancelled(true); + } + @EventHandler(priority = EventPriority.LOWEST) public void clearCreeperExplode(EntityExplodeEvent event) { @@ -1713,8 +1300,8 @@ public class UHC extends TeamGame implements NCPHook long ingameTime = getPlayerIngameTime(player); if (ingameTime == 0) ingameTime = GetStateTime(); - - int gems = Math.round((System.currentTimeMillis() - ingameTime)/1000); + + int gems = Math.round((System.currentTimeMillis() - ingameTime) / 1000); AddGems(player, gems, "Winning Team", false, false); } } @@ -1803,19 +1390,7 @@ public class UHC extends TeamGame implements NCPHook public int GetHealth(Player player) { - int health = (int) player.getHealth(); - - if (player.getHealth() % 1d != 0) - { - health += 1; - } - - return health; - } - - public long getServerTime() - { - return _serverTime + (System.currentTimeMillis() - _createTime); + return (int) Math.ceil(player.getHealth()); } @Override @@ -1946,15 +1521,221 @@ public class UHC extends TeamGame implements NCPHook return ChatColor.YELLOW + "In Progress"; } - // Not Loaded (but still joinable) - if (!_mapLoaded) + if (!_worldGenThread.isMapLoaded()) { - return ChatColor.GREEN + "Generating Map (" + C.cWhite + getMapLoadETA() + C.cGreen + ")"; + return ChatColor.GREEN + "Generating Map (" + C.cWhite + _worldGenThread.getProgress() + C.cGreen + ")"; + } + + if (!_chunkLoadingThread.isDone()) + { + return ChatColor.GREEN + "Generating Spawns (" + C.cWhite + _chunkLoadingThread.getProgress() + C.cGreen + ")"; } return ChatColor.GREEN + "Recruiting"; } + public boolean isMapLoaded() + { + return _worldGenThread.isMapLoaded() && _chunkLoadingThread.isDone(); + } + + public String getObjectiveName(boolean _colorTick) + { + if (!_worldGenThread.isMapLoaded()) + { + return _worldGenThread.getProgress() + " " + (_colorTick ? ChatColor.GREEN : ChatColor.YELLOW) + "§l" + "Generating Map"; + } + else + { + return _chunkLoadingThread.getProgress() + " " + (_colorTick ? ChatColor.GREEN : ChatColor.YELLOW) + "§l" + "Generating Spawns"; + } + } + + @Override + public String getHookName() + { + return "UHC Hook"; + } + + @Override + public String getHookVersion() + { + return "0.0.1"; + } + + @Override + public boolean onCheckFailure(CheckType checkType, Player player, IViolationInfo iViolationInfo) + { + if (GetState() == GameState.Prepare) + { + return false; + } + return true; + } + + @EventHandler + public void on(PlayerCommandPreprocessEvent event) + { + if (event.getMessage().equals("/uhcentities")) + { + CoreClient client = getArcadeManager().GetClients().Get(event.getPlayer()); + if (client.GetRank().has(Rank.DEVELOPER)) + { + for (Entity entity : event.getPlayer().getNearbyEntities(5.0, 5.0, 5.0)) + { + net.minecraft.server.v1_8_R3.Entity nms = ((CraftEntity) entity).getHandle(); + String debug = "Entity: " + entity.getType() + " id:" + nms.getId() + " inac:" + ActivationRange.checkIfActive(nms); + debug += " at:" + nms.activatedTick + " dac:" + nms.defaultActivationState; + + int x = MathHelper.floor(nms.locX); + int z = MathHelper.floor(nms.locZ); + + net.minecraft.server.v1_8_R3.Chunk chunk = nms.world.getChunkIfLoaded(x >> 4, z >> 4); + debug += " c:" + chunk + " il:" + (chunk != null ? chunk.areNeighborsLoaded(1) : "null"); + event.getPlayer().sendMessage(debug); + } + event.setCancelled(true); + } + } + else if (event.getMessage().equals("/uhcchunk")) + { + CoreClient client = getArcadeManager().GetClients().Get(event.getPlayer()); + if (client.GetRank().has(Rank.DEVELOPER)) + { + net.minecraft.server.v1_8_R3.Chunk chunk = ((CraftChunk) event.getPlayer().getLocation().getChunk()).getHandle(); + try + { + Field neighbors = chunk.getClass().getDeclaredField("neighbors"); + neighbors.setAccessible(true); + int n = neighbors.getInt(chunk); + + for (int x = -1; x < 2; x++) + { + for (int z = -1; z < 2; z++) + { + if (x == 0 && z == 0) + { + continue; + } + + int mask = 0x1 << (x * 5 + z + 12); + + boolean should = chunk.world.getChunkIfLoaded(chunk.locX + x, chunk.locZ + z) != null; + boolean is = (n & mask) == mask; + if (is && should) + { + event.getPlayer().sendMessage(ChatColor.GREEN + "Chunk " + (chunk.locX + x) + "," + (chunk.locZ + z) + " (" + x + "," + z + ") is a neighbor"); + } + else if (is && !should) + { + event.getPlayer().sendMessage(ChatColor.RED + "Chunk " + (chunk.locX + x) + "," + (chunk.locZ + z) + " (" + x + "," + z + ") is a neighbor but should not be"); + } + else if (!is && should) + { + event.getPlayer().sendMessage(ChatColor.RED + "Chunk " + (chunk.locX + x) + "," + (chunk.locZ + z) + " (" + x + "," + z + ") is not a neighbor but should be"); + } + else if (!is && !should) + { + event.getPlayer().sendMessage(ChatColor.GREEN + "Chunk " + (chunk.locX + x) + "," + (chunk.locZ + z) + " (" + x + "," + z + ") is not a neighbor"); + } + } + } + } + catch (Throwable t) + { + t.printStackTrace(); + } + event.setCancelled(true); + } + } + else if (event.getMessage().equals("/uhcgc")) + { + CoreClient client = getArcadeManager().GetClients().Get(event.getPlayer()); + if (client.GetRank().has(Rank.DEVELOPER)) + { + System.gc(); + event.getPlayer().sendMessage("Cleaned up"); + event.setCancelled(true); + } + } + else if (event.getMessage().equals("/uhcallchunks")) + { + CoreClient client = getArcadeManager().GetClients().Get(event.getPlayer()); + if (client.GetRank().has(Rank.DEVELOPER)) + { + for (Chunk chunk : ((CraftWorld) event.getPlayer().getWorld()).getHandle().chunkProviderServer.chunks.values()) + { + try + { + Field neighbors = chunk.getClass().getDeclaredField("neighbors"); + neighbors.setAccessible(true); + int n = neighbors.getInt(chunk); + + for (int x = -1; x < 2; x++) + { + for (int z = -1; z < 2; z++) + { + if (x == 0 && z == 0) + { + continue; + } + + int mask = 0x1 << (x * 5 + z + 12); + + boolean should = chunk.world.getChunkIfLoaded(chunk.locX + x, chunk.locZ + z) != null; + boolean is = (n & mask) == mask; + if (is && !should) + { + event.getPlayer().sendMessage(ChatColor.RED + "Chunk " + (chunk.locX + x) + "," + (chunk.locZ + z) + " (" + x + "," + z + ") relative to " + (chunk.locX) + "," + chunk.locZ + " is a neighbor but should not be"); + } + else if (!is && should) + { + event.getPlayer().sendMessage(ChatColor.RED + "Chunk " + (chunk.locX + x) + "," + (chunk.locZ + z) + " (" + x + "," + z + ") relative to " + (chunk.locX) + "," + chunk.locZ + " is not a neighbor but should be"); + } + } + } + } + catch (Throwable t) + { + t.printStackTrace(); + } + } + + event.getPlayer().sendMessage("Done"); + event.setCancelled(true); + } + } + else if (event.getMessage().equals("/uhcworlds")) + { + CoreClient client = getArcadeManager().GetClients().Get(event.getPlayer()); + if (client.GetRank().has(Rank.DEVELOPER)) + { + MinecraftServer minecraftServer = MinecraftServer.getServer(); + + int nms = minecraftServer.worlds.size(); + int bukkit = Bukkit.getWorlds().size(); + + if (nms != bukkit) + { + event.getPlayer().sendMessage(ChatColor.RED + "Bukkit and NMS world counts don't match: " + nms + " vs " + bukkit); + } + + for (org.bukkit.World world : Bukkit.getWorlds()) + { + WorldServer worldServer = ((CraftWorld) world).getHandle(); + event.getPlayer().sendMessage("Bukkit world: " + worldServer.getWorldData().getName() + " loaded chunks: " + worldServer.chunkProviderServer.chunks.size() + " saving: " + worldServer.savingDisabled + " unload queue: " + worldServer.chunkProviderServer.unloadQueue.size()); + } + + for (WorldServer worldServer : minecraftServer.worlds) + { + event.getPlayer().sendMessage("NMS world: " + worldServer.getWorldData().getName() + " loaded chunks: " + worldServer.chunkProviderServer.chunks.size() + " saving: " + worldServer.savingDisabled + " unload queue: " + worldServer.chunkProviderServer.unloadQueue.size()); + } + + event.setCancelled(true); + } + } + } + @EventHandler(priority = EventPriority.MONITOR) public void xrayBlockBreak(BlockBreakEvent event) { @@ -2132,197 +1913,4 @@ public class UHC extends TeamGame implements NCPHook { } - - public boolean isMapLoaded() - { - return _mapLoaded && areSpawnsGenerated(); - } - - public String getMapLoadPercent() - { - return (int) (_mapLoadPercent * 100) + "%"; - } - - public String getSpawnGenPercent() - { - return UtilMath.clamp((int) ((actual.get() * 1.0 / expected.get()) * 100), 0, 100) + "%"; - } - - public String getObjectiveName(boolean _colorTick) - { - if (!getMapLoadPercent().equals("100%")) - { - return getMapLoadPercent() + " " + (_colorTick ? ChatColor.GREEN : ChatColor.YELLOW) + "§l" + "Generating Map"; - } - else - { - return getSpawnGenPercent() + " " + (_colorTick ? ChatColor.GREEN : ChatColor.YELLOW) + "§l" + "Generating Spawns"; - } - } - - public String getMapLoadETA() - { - int chunksToGo = _chunkTotal - _chunksLoaded; - - return UtilTime.MakeStr((long) ((double) chunksToGo / (double) (_chunksPerTick * 20) * 1000d), 1); - } - - @EventHandler(priority = EventPriority.HIGH) - public void teamSelectInteract(PlayerInteractEntityEvent event) - { - if (GetState() != GameState.Recruit) - return; - - if (event.getRightClicked() == null) - return; - - if (!(event.getRightClicked() instanceof Player)) - return; - - Player player = event.getPlayer(); - - //Observer - if (Manager.IsObserver(player)) - { - UtilPlayer.message(player, F.main("Game", "Spectators cannot partake in games.")); - return; - } - - selectTeamMate(player, (Player) event.getRightClicked()); - } - - @EventHandler - public void teamSelectCommand(PlayerCommandPreprocessEvent event) - { - if (GetState() != GameState.Recruit) - return; - - if (!event.getMessage().toLowerCase().startsWith("/team ")) - return; - - event.setCancelled(true); - - Player target = UtilPlayer.searchOnline(event.getPlayer(), event.getMessage().split(" ")[1], true); - if (target == null) - return; - - //Observer - if (Manager.IsObserver(event.getPlayer())) - { - UtilPlayer.message(event.getPlayer(), F.main("Game", "Spectators cannot partake in games.")); - return; - } - - if (event.getPlayer().equals(target)) - return; - - selectTeamMate(event.getPlayer(), target); - } - - public void selectTeamMate(Player player, Player ally) - { - //Accept Invite - if (_teamReqs.containsKey(ally) && _teamReqs.get(ally).equals(player)) - { - //Remove Prefs - _teamReqs.remove(player); - _teamReqs.remove(ally); - - //Inform - UtilPlayer.message(player, F.main("Game", "You accepted " + ally.getName() + "'s Team Request!")); - UtilPlayer.message(ally, F.main("Game", player.getName() + " accepted your Team Request!")); - - //Leave Old Teams - if (GetTeam(player) != null) - GetTeam(player).DisbandTeam(); - - if (GetTeam(ally) != null) - GetTeam(ally).DisbandTeam(); - - //Get Team - GameTeam team = getEmptyTeam(); - if (team == null) - return; - - team.setDisplayName(player.getName() + " & " + ally.getName()); - - //Join Team - SetPlayerTeam(player, team, true); - SetPlayerTeam(ally, team, true); - } - //Send Invite - else - { - //Already on Team with Target - if (GetTeam(player) != null) - if (GetTeam(player).HasPlayer(ally)) - return; - - //Inform Player - UtilPlayer.message(player, F.main("Game", "You sent a Team Request to " + ally.getName() + "!")); - - //Inform Target - if (Recharge.Instance.use(player, "Team Req " + ally.getName(), 2000, false, false)) - { - UtilPlayer.message(ally, F.main("Game", player.getName() + " sent you a Team Request!")); - UtilPlayer.message(ally, F.main("Game", "Type " + F.elem("/team " + player.getName()) + " to accept!")); - } - - //Add Pref - _teamReqs.put(player, ally); - } - } - - @EventHandler - public void teamQuit(PlayerQuitEvent event) - { - if (GetState() != GameState.Recruit) - return; - - Player player = event.getPlayer(); - - if (GetTeam(player) != null) - GetTeam(player).DisbandTeam(); - - Iterator teamIter = _teamReqs.keySet().iterator(); - while (teamIter.hasNext()) - { - Player sender = teamIter.next(); - if (sender.equals(player) || _teamReqs.get(sender).equals(player)) - teamIter.remove(); - } - } - - public GameTeam getEmptyTeam() - { - for (GameTeam team : GetTeamList()) - { - if (team.GetPlayers(false).isEmpty()) - return team; - } - - return null; - } - - @Override - public String getHookName() - { - return "UHC Hook"; - } - - @Override - public String getHookVersion() - { - return "0.0.1"; - } - - @Override - public boolean onCheckFailure(CheckType checkType, Player player, IViolationInfo iViolationInfo) - { - if (GetState() == GameState.Prepare) - { - return false; - } - return true; - } } \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/helpers/ChunkLoadingThread.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/helpers/ChunkLoadingThread.java new file mode 100644 index 000000000..7521c0360 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/helpers/ChunkLoadingThread.java @@ -0,0 +1,385 @@ +package nautilus.game.arcade.game.games.uhc.helpers; + +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilServer; +import mineplex.core.timing.TimingManager; +import nautilus.game.arcade.game.Game; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.games.uhc.UHC; +import net.minecraft.server.v1_8_R3.Chunk; +import net.minecraft.server.v1_8_R3.ChunkProviderServer; +import net.minecraft.server.v1_8_R3.ChunkRegionLoader; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.WorldServer; +import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; +import org.bukkit.craftbukkit.v1_8_R3.util.LongHash; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntitySpawnEvent; +import org.bukkit.event.world.ChunkLoadEvent; +import org.spigotmc.AsyncCatcher; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +import static nautilus.game.arcade.game.games.uhc.UHC.VIEW_DISTANCE; + +public class ChunkLoadingThread extends Thread implements Listener +{ + private Game _game; + + private volatile boolean _isDecorating = false; + private AtomicInteger _actual = new AtomicInteger(); + private AtomicInteger _expected = new AtomicInteger(23000); // Most likely it'll be around 23000 + + private Set _entities = new HashSet<>(); + + public ChunkLoadingThread(Game game) + { + super("Chunk Loader"); + this._game = game; + UtilServer.RegisterEvents(this); + } + + public void run() + { + WorldServer worldServer = ((CraftWorld) _game.WorldData.World).getHandle(); + Location spawn = _game.WorldData.World.getSpawnLocation(); + + Map loaded = new ConcurrentHashMap<>(); + Map compounds = new ConcurrentHashMap<>(); + + try + { + TimingManager.start("UHC Chunk Loading"); + + ChunkProviderServer chunkProviderServer = worldServer.chunkProviderServer; + + Field chunkLoaderField = chunkProviderServer.getClass().getDeclaredField("chunkLoader"); + chunkLoaderField.setAccessible(true); + + ChunkRegionLoader loader = (ChunkRegionLoader) chunkLoaderField.get(chunkProviderServer); + + // Step 1: Read all the required chunks from the disk + // We're going to read all the required chunks from disk async + { + Set coordPairs = new HashSet<>(); + + // Special case for 0, 0 + { + int x = spawn.getBlockX() >> 4; + int z = spawn.getBlockZ() >> 4; + + for (int dx = -VIEW_DISTANCE; dx <= VIEW_DISTANCE; dx++) + { + for (int dz = -VIEW_DISTANCE; dz <= VIEW_DISTANCE; dz++) + { + coordPairs.add(LongHash.toLong(x + dx, z + dz)); + } + } + } + + // All the team spawns + { + for (int i = 0; i < _game.GetTeamList().size(); i++) + { + GameTeam team = _game.GetTeamList().get(i); + for (Location l : team.GetSpawns()) + { + int x = l.getChunk().getX(); + int z = l.getChunk().getZ(); + + for (int dx = -VIEW_DISTANCE; dx <= VIEW_DISTANCE; dx++) + { + for (int dz = -VIEW_DISTANCE; dz <= VIEW_DISTANCE; dz++) + { + coordPairs.add(LongHash.toLong(x + dx, z + dz)); + } + } + } + } + } + + AtomicBoolean lockCompleted = new AtomicBoolean(false); + Object lock = new Object(); + + // Hop back onto the main thread + _game.getArcadeManager().runSync(() -> + { + for (Chunk chunk : new ArrayList<>(chunkProviderServer.chunks.values())) + { + chunk.bukkitChunk.unload(true, false); + } + lockCompleted.set(true); + synchronized(lock) + { + lock.notifyAll(); + } + }); + if (!lockCompleted.get()) + { + synchronized (lock) + { + lock.wait(); + } + } + if (!lockCompleted.get()) + { + throw new IllegalStateException("Lock was not completed"); + } + + + // Sigh... I don't want this to be here but it needs to be set somewhere... + // Multiply by 3 because there are 3 stages + _expected.set(coordPairs.size() * 3); + + // Load them now + ExecutorService chunkLoaders = Executors.newFixedThreadPool(UHC.THREADS_FOR_CHUNK_LOADING); + + for (long coord : coordPairs) + { + chunkLoaders.submit(() -> + { + int x = LongHash.msw(coord); + int z = LongHash.lsw(coord); + try + { + Object[] data = loader.loadChunk(worldServer, x, z); + if (data != null) + { + NBTTagCompound compound = (NBTTagCompound) data[1]; + net.minecraft.server.v1_8_R3.Chunk chunk = (net.minecraft.server.v1_8_R3.Chunk) data[0]; + loaded.put(coord, chunk); + compounds.put(coord, compound); + } + else + { + System.out.println("Failed to load chunk " + x + "," + z); + } + } + catch (Throwable t) + { + t.printStackTrace(); + } + finally + { + _actual.getAndIncrement(); + } + }); + } + + chunkLoaders.shutdown(); + + // We've got plenty of time to wait + System.out.println("Finished submitting tasks to executor, waiting..."); + chunkLoaders.awaitTermination(1, TimeUnit.DAYS); + + System.out.println("Loaded: " + loaded.size() + " and coords: " + coordPairs.size()); + coordPairs.clear(); + } + + // Step 2: Recreate structures, update neighbors, load entities + // This step should be super quick so there's no point in scheduling it elsewhere + // Code is plain copypasted from ChunkIOProvider + { + for (net.minecraft.server.v1_8_R3.Chunk chunk : loaded.values()) + { + NBTTagCompound compound = compounds.get(LongHash.toLong(chunk.locX, chunk.locZ)); + loader.loadEntities(chunk, compound.getCompound("Level"), worldServer); + chunk.setLastSaved(chunkProviderServer.world.getTime()); + if (chunkProviderServer.chunkProvider != null) + { + chunkProviderServer.chunkProvider.recreateStructures(chunk, chunk.locX, chunk.locZ); + } + + for (int x = -2; x < 3; ++x) + { + for (int z = -2; z < 3; ++z) + { + if (x != 0 || z != 0) + { + net.minecraft.server.v1_8_R3.Chunk neighbor = loaded.get(LongHash.toLong(chunk.locX + x, chunk.locZ + z)); + if (neighbor != null) + { + neighbor.setNeighborLoaded(-x, -z); + chunk.setNeighborLoaded(x, z); + } + } + } + } + _actual.getAndIncrement(); + } + } + + AtomicBoolean lockCompleted = new AtomicBoolean(false); + Object lock = new Object(); + + // Hop back onto the main thread + _game.getArcadeManager().runSync(() -> + { + // We want to add all the chunks to the chunkmap so that the server is not out of sync + for (Map.Entry ent : loaded.entrySet()) + { + ent.getValue().addEntities(); + chunkProviderServer.chunks.put(ent.getKey(), ent.getValue()); + ChunkLoadEvent event = new ChunkLoadEvent(ent.getValue().bukkitChunk, true); + UtilServer.CallEvent(event); + } + lockCompleted.set(true); + synchronized (lock) + { + lock.notifyAll(); + } + }); + + if (!lockCompleted.get()) + { + synchronized (lock) + { + lock.wait(); + } + } + if (!lockCompleted.get()) + { + throw new IllegalStateException("Lock was not completed"); + } + + + // Step 3: Decorate the chunks. This step must be performed async as otherwise the server lags way too hard + // Notes: Do not allow the server to tick the world. If this is allowed EntityTracker will raise CME + // NextTickList will also raise errors + // And worst case the server will crash + { + // Live life on the edge + AsyncCatcher.enabled = false; + _isDecorating = true; + int ct = 0; + for (net.minecraft.server.v1_8_R3.Chunk chunk : loaded.values()) + { + chunk.loadNearby(chunkProviderServer, chunkProviderServer, chunk.locX, chunk.locZ); + ct++; + if (ct % 100 == 0) + { + System.out.println(ct); + } + _actual.getAndIncrement(); + } + + TimingManager.stop("UHC Chunk Loading"); + _isDecorating = false; + AsyncCatcher.enabled = true; + + System.out.println("Expected: " + _expected.get() + ", actual: " + _actual.get()); + + _game.getArcadeManager().runSync(() -> + { + + for (Chunk chunk : chunkProviderServer.chunks.values()) + { + // Clear + for (int x = -2; x < 3; x++) { + for (int z = -2; z < 3; z++) { + if (x == 0 && z == 0) { + continue; + } + chunk.setNeighborUnloaded(x, z); + } + } + } + + for (Chunk chunk : chunkProviderServer.chunks.values()) + { + // Refresh + for (int x = -2; x < 3; x++) { + for (int z = -2; z < 3; z++) { + if (x == 0 && z == 0) { + continue; + } + + Chunk neighbor = chunkProviderServer.getChunkIfLoaded(chunk.locX + x, chunk.locZ + z); + if (neighbor != null) { + neighbor.setNeighborLoaded(-x, -z); + chunk.setNeighborLoaded(x, z); + } + } + } + } + + for (net.minecraft.server.v1_8_R3.Entity entity : _entities) + { + entity.dead = false; + worldServer.addEntity(entity, CreatureSpawnEvent.SpawnReason.CHUNK_GEN); + } + + _entities.clear(); + + // You may tick again + worldServer.getMinecraftServer().worlds.add(worldServer); + + // Well, if they're not equal, not much we can do. We've hit the end + _actual.set(_expected.get()); + }); + } + + loaded.clear(); + compounds.clear(); + + UtilServer.Unregister(this); + } + catch (Throwable t) + { + t.printStackTrace(); + } + } + + @EventHandler + public void on(EntitySpawnEvent event) + { + // Don't allow entity spawns while decorating, period + if (_isDecorating) + { + if (event.getLocation().getWorld().getUID() == _game.WorldData.World.getUID()) + { + _entities.add(((CraftEntity) event.getEntity()).getHandle()); + event.setCancelled(true); + } + } + } + + public void flagDone() + { + _actual.set(_expected.get()); + } + + public boolean isDone() + { + return _actual.get() == _expected.get(); + } + + public int getPercentageComplete() + { + return UtilMath.clamp((int) ((_actual.get() * 1.0 / _expected.get()) * 100), 0, 100); + } + + public String getProgress() + { + return getPercentageComplete() + "%"; + } + + public void flagStop() + { + this.interrupt(); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/helpers/WorldGenThread.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/helpers/WorldGenThread.java new file mode 100644 index 000000000..39012869c --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/uhc/helpers/WorldGenThread.java @@ -0,0 +1,239 @@ +package nautilus.game.arcade.game.games.uhc.helpers; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilTime; +import mineplex.core.timing.TimingManager; +import nautilus.game.arcade.game.Game; +import nautilus.game.arcade.game.games.uhc.UHC; +import net.minecraft.server.v1_8_R3.BiomeCache; +import net.minecraft.server.v1_8_R3.ChunkProviderServer; +import net.minecraft.server.v1_8_R3.FileIOThread; +import net.minecraft.server.v1_8_R3.IChunkProvider; +import net.minecraft.server.v1_8_R3.MinecraftServer; +import net.minecraft.server.v1_8_R3.WorldChunkManager; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.craftbukkit.v1_8_R3.util.LongHash; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +public class WorldGenThread extends Thread +{ + private UHC _game; + + private volatile boolean _mapLoaded = false; + private volatile int _chunksPerTick = 1; + private volatile boolean _stopGen = false; + + private int _chunkTotal; + private int _chunkX = 0; + private int _chunkZ = 0; + private int _chunksLoaded = 0; + + private int _currentBorder = 1000; + + + public WorldGenThread(UHC game) + { + super("WorldGen Thread"); + this._game = game; + + + _chunkX = (int) -(_currentBorder / 16); + _chunkZ = (int) -(_currentBorder / 16); + _chunkTotal = (int) ((_currentBorder * 2 / 16) * (_currentBorder * 2 / 16)); + } + + public void run() + { + try + { + Field fileIOThreadB = FileIOThread.class.getDeclaredField("b"); + fileIOThreadB.setAccessible(true); + + // This list is the list of chunks to be saved on the File IO Thread + List list = (List) fileIOThreadB.get(FileIOThread.a()); + + net.minecraft.server.v1_8_R3.WorldServer worldServer = ((CraftWorld) _game.WorldData.World).getHandle(); + + WorldChunkManager manager = worldServer.getWorldChunkManager(); + + Field biomeCacheField = manager.getClass().getDeclaredField("d"); + biomeCacheField.setAccessible(true); + + // A thread safe BiomeCache + // The implementation is literally a copy/paste from the original BiomeCache, but with some synchronization + // Reason being while the server is ticking the world (for some reason, if you want to dig through the entire Arcade codebase go for it) + // it stores stuff in the BiomeCache, and chunk gen needs that BiomeCache info too + // Causing desynchronization in the cache + biomeCacheField.set(manager, new BiomeCache(manager) + { + private final Object _lock = new Object(); + + private long _lastCleanTime; // b -> _lastCleanTime + private Map _blockByCoord = new HashMap<>(); // LongHashMap -> HashMap, c -> _blockByCoord + private List _blocks = new ArrayList<>(); // d -> _blocks + + @Override + public BiomeCache.BiomeCacheBlock a(int x, int z) + { + x >>= 4; + z >>= 4; + long var3 = hash(x, z); + BiomeCache.BiomeCacheBlock var5 = this._blockByCoord.get(var3); + if (var5 == null) + { + var5 = new BiomeCache.BiomeCacheBlock(x, z); + synchronized (_lock) + { + this._blockByCoord.put(var3, var5); + this._blocks.add(var5); + } + } + + var5.e = MinecraftServer.az(); + return var5; + } + + @Override + public void a() + { + long currentTime = MinecraftServer.az(); + long deltaTime = currentTime - this._lastCleanTime; + if (deltaTime > 7500L || deltaTime < 0L) + { + this._lastCleanTime = currentTime; + + synchronized (_lock) + { + for (int i = 0; i < this._blocks.size(); ++i) + { + BiomeCache.BiomeCacheBlock biomeCacheBlock = (BiomeCache.BiomeCacheBlock) this._blocks.get(i); + long var7 = currentTime - biomeCacheBlock.e; + if (var7 > 30000L || var7 < 0L) + { + this._blocks.remove(i--); + this._blockByCoord.remove(hash(biomeCacheBlock.c, biomeCacheBlock.d)); + } + } + } + } + } + + private long hash(int x, int z) + { + return (long) x & 4294967295L | ((long) z & 4294967295L) << 32; + } + }); + + ChunkProviderServer cps = worldServer.chunkProviderServer; + IChunkProvider icp = cps.chunkProvider; + System.out.println("Using chunk provider " + icp.getClass()); + + TimingManager.start("Map Generation"); + + long start = System.currentTimeMillis(); + long last = start; + + while (!_stopGen) + { + long now = System.currentTimeMillis(); + if ((now - last) >= 10 * 1000) + { + _game.Announce(C.cGreen + C.Bold + "Generating Map: " + C.cWhite + getMapLoadETA() + " Remaining...", false); + last = now; + } + + long hash = LongHash.toLong(_chunkX, _chunkZ); + + // This is just a shortcut to how the Minecraft server would have generated a chunk if it doesn't exist. + // This should always create a chunk because we're not loading any chunks beforehand... + // /me looks at new maintainer + net.minecraft.server.v1_8_R3.Chunk chunk = icp.getOrCreateChunk(_chunkX, _chunkZ); + + // Run the copypasted code for chunk saving. + cps.saveChunk(chunk); + cps.saveChunkNOP(chunk); + cps.unloadQueue.remove(_chunkX, _chunkZ); + cps.chunks.remove(hash); + + if (_chunkX < _currentBorder / 16) + { + _chunkX++; + } + else if (_chunkZ < _currentBorder / 16) + { + _chunkX = (int) -(_currentBorder / 16); + _chunkZ++; + } + else + { + _mapLoaded = true; + System.out.println("Map Loading Finished! Took " + TimeUnit.MILLISECONDS.toSeconds(now - start) + " seconds"); + break; + } + + _chunksLoaded++; + + _chunksPerTick = (int) (_chunksLoaded / ((now - start) / 50.0)); + } + + TimingManager.stop("Map Generation"); + + if (_stopGen) + { + return; + } + + TimingManager.start("Map Saving"); + + // Wait for all the chunks to save (but do we need this?) + while (!list.isEmpty()) + { + Thread.sleep(100); + } + + TimingManager.stop("Map Saving"); + + _game.getArcadeManager().runSync(_game::generateSpawns); + } + catch (Throwable t) + { + // todo proper exception handling + // maybe force shutdown? + t.printStackTrace(); + } + } + + public void flagStop() + { + this._stopGen = true; + } + + public String getMapLoadETA() + { + int chunksToGo = _chunkTotal - _chunksLoaded; + + return UtilTime.MakeStr((long) ((double) chunksToGo / (double) (_chunksPerTick * 20) * 1000d), 1); + } + + public boolean isMapLoaded() + { + return this._mapLoaded; + } + + public int getPercentageComplete() + { + return UtilMath.clamp((int) ((_chunksLoaded * 1.0 / _chunkTotal) * 100), 0, 100); + } + + public String getProgress() + { + return getPercentageComplete() + "%"; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/WitherGame.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/WitherGame.java index d85536b2a..20e743fc8 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/WitherGame.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/WitherGame.java @@ -633,7 +633,12 @@ public class WitherGame extends TeamGame implements IBlockRestorer { speed = 0.09 - (_yLimit - player.getLocation().getY()) * 0.006; } - + + if (speed < 0.01) //This is to stop players having negative speed when they go under the map + { + speed = 0.01; + } + player.setFlySpeed((float) Math.min(1, speed)); // Bump diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/Module.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/Module.java new file mode 100644 index 000000000..0279e0da6 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/Module.java @@ -0,0 +1,29 @@ +package nautilus.game.arcade.game.modules; + +import nautilus.game.arcade.game.Game; +import org.bukkit.event.Listener; + +public abstract class Module implements Listener +{ + // The game this module belongs to + private Game _game; + + public void initialize(Game game) + { + if (_game != null) + { + throw new IllegalArgumentException("Attempting to initialize module which has already been initialized for " + _game); + } + this._game = game; + } + + public void cleanup() + { + + } + + public Game getGame() + { + return this._game; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/TeamModule.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/TeamModule.java new file mode 100644 index 000000000..60fb19d7d --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/modules/TeamModule.java @@ -0,0 +1,164 @@ +package nautilus.game.arcade.game.modules; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.recharge.Recharge; +import nautilus.game.arcade.game.Game; +import nautilus.game.arcade.game.GameTeam; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.util.UUID; + +public class TeamModule extends Module +{ + private BiMap _teamReqs = HashBiMap.create(); + + @EventHandler(priority = EventPriority.HIGH) + public void teamSelectInteract(PlayerInteractEntityEvent event) + { + if (getGame().GetState() != Game.GameState.Recruit) + return; + + if (event.getRightClicked() == null) + return; + + if (!(event.getRightClicked() instanceof Player)) + return; + + Player player = event.getPlayer(); + + //Observer + if (getGame().getArcadeManager().IsObserver(player)) + { + UtilPlayer.message(player, F.main("Game", "Spectators cannot partake in games.")); + return; + } + + selectTeamMate(player, (Player) event.getRightClicked()); + } + + @EventHandler + public void teamSelectCommand(PlayerCommandPreprocessEvent event) + { + if (!event.getMessage().toLowerCase().startsWith("/team ")) + return; + + event.setCancelled(true); + + if (getGame().GetState() != Game.GameState.Recruit) + { + UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot send team requests while the game is live")); + return; + } + + //Observer + if (getGame().getArcadeManager().IsObserver(event.getPlayer())) + { + UtilPlayer.message(event.getPlayer(), F.main("Game", "Spectators cannot partake in games.")); + return; + } + + Player target = UtilPlayer.searchOnline(event.getPlayer(), event.getMessage().split(" ")[1], true); + + if (target == null) + { + UtilPlayer.message(event.getPlayer(), F.main("Game", "That player is not online")); + return; + } + + if (event.getPlayer().equals(target)) + { + UtilPlayer.message(event.getPlayer(), F.main("Game", "You can't team with yourself!")); + return; + } + + selectTeamMate(event.getPlayer(), target); + } + + private void selectTeamMate(Player player, Player ally) + { + //Accept Invite + if (_teamReqs.containsKey(ally.getUniqueId()) && _teamReqs.get(ally.getUniqueId()).equals(player.getUniqueId())) + { + //Remove Prefs + _teamReqs.remove(player.getUniqueId()); + _teamReqs.remove(ally.getUniqueId()); + + //Inform + UtilPlayer.message(player, F.main("Game", "You accepted " + ally.getName() + "'s Team Request!")); + UtilPlayer.message(ally, F.main("Game", player.getName() + " accepted your Team Request!")); + + //Leave Old Teams + if (getGame().GetTeam(player) != null) + getGame().GetTeam(player).DisbandTeam(); + + if (getGame().GetTeam(ally) != null) + getGame().GetTeam(ally).DisbandTeam(); + + //Get Team + GameTeam team = getEmptyTeam(); + if (team == null) + return; + + team.setDisplayName(player.getName() + " & " + ally.getName()); + + //Join Team + getGame().SetPlayerTeam(player, team, true); + getGame().SetPlayerTeam(ally, team, true); + } + //Send Invite + else + { + //Already on Team with Target + if (getGame().GetTeam(player) != null) + if (getGame().GetTeam(player).HasPlayer(ally)) + return; + + //Inform Player + UtilPlayer.message(player, F.main("Game", "You sent a Team Request to " + ally.getName() + "!")); + + //Inform Target + if (Recharge.Instance.use(player, "Team Req " + ally.getName(), 2000, false, false)) + { + UtilPlayer.message(ally, F.main("Game", player.getName() + " sent you a Team Request!")); + UtilPlayer.message(ally, F.main("Game", "Type " + F.elem("/team " + player.getName()) + " to accept!")); + } + + //Add Pref + _teamReqs.put(player.getUniqueId(), ally.getUniqueId()); + } + } + + @EventHandler + public void teamQuit(PlayerQuitEvent event) + { + if (getGame().GetState() != Game.GameState.Recruit) + return; + + Player player = event.getPlayer(); + + if (getGame().GetTeam(player) != null) + getGame().GetTeam(player).DisbandTeam(); + + _teamReqs.remove(player.getUniqueId()); + _teamReqs.inverse().remove(player.getUniqueId()); + } + + private GameTeam getEmptyTeam() + { + for (GameTeam team : getGame().GetTeamList()) + { + if (team.GetPlayers(false).isEmpty()) + return team; + } + + return null; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/PlayerPage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/PlayerPage.java index c2f6f2817..c6cf102d5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/PlayerPage.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/privateServer/page/PlayerPage.java @@ -44,7 +44,12 @@ public abstract class PlayerPage extends BasePage players = new ArrayList<>(); for (String s : _players) { - players.add(Bukkit.getPlayer(s)); + Player player = Bukkit.getPlayer(s); + + if (!_plugin.isVanished(player)) + { + players.add(player); + } } } else @@ -56,7 +61,7 @@ public abstract class PlayerPage extends BasePage int slot = 9; for (Player player : players) { - if (showPlayer(player)) + if (showPlayer(player) && !_plugin.isVanished(player)) { ItemStack head = getPlayerHead(player.getName(), C.cGreen + C.Bold + player.getName(), new String[]{ ChatColor.RESET + C.cGray + getDisplayString(player) }); addButton(slot, head, new Button(slot, player)); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/spectatorMenu/button/SpectatorButton.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/spectatorMenu/button/SpectatorButton.java index d2f170f5f..c1f189998 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/spectatorMenu/button/SpectatorButton.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/gui/spectatorMenu/button/SpectatorButton.java @@ -41,18 +41,7 @@ public class SpectatorButton implements IButton if(clickType == ClickType.RIGHT) { _player.closeInventory(); - _player.teleport(_target.getLocation().add(0, 1, 0)); - _arcadeManager.runSyncLater(new Runnable() - { - @Override - public void run() - { - _player.setGameMode(GameMode.SPECTATOR); - _player.setSpectatorTarget(_target); - UtilTextBottom.display(C.cYellow + "You are spectating " + F.game(_target.getName()), player); - UtilPlayer.message(_player, F.main("Game", "Sneak to stop spectating")); - } - }, 3); + _arcadeManager.getGameSpectatorManager().setSpectating(_player, _target); } else { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkBoneRush.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkBoneRush.java index 4a5790f73..bdef9e25b 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkBoneRush.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkBoneRush.java @@ -30,6 +30,7 @@ import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.game.games.smash.TeamSuperSmash; import nautilus.game.arcade.kit.SmashPerk; public class PerkBoneRush extends SmashPerk implements IThrown @@ -151,6 +152,18 @@ public class PerkBoneRush extends SmashPerk implements IThrown double damage = 0.7; String reason = GetName(); + if (Manager.GetGame() instanceof TeamSuperSmash && target instanceof Player && data.getThrower() instanceof Player) + { + TeamSuperSmash smash = (TeamSuperSmash) Manager.GetGame(); + Player targetPlayer = (Player) target; + Player throwerPlayer = (Player) data.getThrower(); + + if(smash.GetTeam(targetPlayer).equals(smash.GetTeam(throwerPlayer))) + { + return; + } + } + if (isSuperActive(damager)) { damage = 3; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkCreeperElectricity.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkCreeperElectricity.java index c9054de14..0b6ae7d62 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkCreeperElectricity.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkCreeperElectricity.java @@ -39,10 +39,7 @@ public class PerkCreeperElectricity extends Perk if (event.IsCancelled()) return; - if (event.GetCause() == DamageCause.ENTITY_ATTACK) - return; - - if (event.GetCause() == DamageCause.FIRE_TICK) + if (event.GetCause() == DamageCause.ENTITY_ATTACK || event.GetCause() == DamageCause.FIRE_TICK || event.GetCause() == DamageCause.STARVATION) return; Player damagee = event.GetDamageePlayer(); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkCreeperExplode.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkCreeperExplode.java index 5a97d8a8f..fee25dd52 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkCreeperExplode.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkCreeperExplode.java @@ -21,8 +21,10 @@ import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.kit.SmashPerk; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; @@ -165,6 +167,15 @@ public class PerkCreeperExplode extends SmashPerk if (UtilMath.offset(player.getLocation(), spawn) < 14) spawnIterator.remove(); } + + //If all spawns have been destroyed revert to using the spectator spawn + for (GameTeam team : Manager.GetGame().GetTeamList()) + { + if (team.GetSpawns().isEmpty()) + { + team.GetSpawns().add(Manager.GetGame().GetSpectatorLocation()); + } + } } //Damage diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkFirefly.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkFirefly.java index 5b8a4d23a..df7e17b2e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkFirefly.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkFirefly.java @@ -3,11 +3,8 @@ package nautilus.game.arcade.kit.perks; import java.util.HashSet; import java.util.Iterator; -import org.bukkit.Color; import org.bukkit.EntityEffect; -import org.bukkit.FireworkEffect; import org.bukkit.Sound; -import org.bukkit.FireworkEffect.Type; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; @@ -19,7 +16,6 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilFirework; import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilParticle.ViewDist; import mineplex.core.common.util.UtilServer; @@ -30,7 +26,6 @@ import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent; -import nautilus.game.arcade.kit.Perk; import nautilus.game.arcade.kit.SmashPerk; import nautilus.game.arcade.kit.perks.data.FireflyData; @@ -93,7 +88,7 @@ public class PerkFirefly extends SmashPerk if (event.getType() != UpdateType.TICK) return; - _tick = (_tick + 1)%1000; + _tick++; Iterator dataIterator = _data.iterator(); @@ -147,8 +142,8 @@ public class PerkFirefly extends SmashPerk continue; other.playEffect(EntityEffect.HURT); - - if (_tick == 0) + + if (_tick % 12 == 0) { if (Recharge.Instance.use(other, GetName() + " hit by " + data.Player.getName(), 2000, false, false)) { @@ -166,7 +161,7 @@ public class PerkFirefly extends SmashPerk { dataIterator.remove(); } - } + } } @EventHandler diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkInferno.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkInferno.java index ecf9b4bff..afba15ebd 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkInferno.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkInferno.java @@ -20,7 +20,8 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import nautilus.game.arcade.kit.Perk; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.game.games.smash.TeamSuperSmash; import nautilus.game.arcade.kit.SmashPerk; public class PerkInferno extends SmashPerk @@ -119,4 +120,23 @@ public class PerkInferno extends SmashPerk } } + @EventHandler + public void onCustomDamage(CustomDamageEvent event) + { + if (Manager.GetGame() instanceof TeamSuperSmash) + { + TeamSuperSmash smash = (TeamSuperSmash) Manager.GetGame(); + + if (event.GetDamagerPlayer(true) == null) + { + return; + } + + if (smash.GetTeam(event.GetDamagerPlayer(true)).equals(smash.GetTeam(event.GetDamageePlayer()))) + { + event.GetDamageeEntity().setFireTicks(0); + event.SetCancelled("Team Damage"); + } + } + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkLeap.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkLeap.java index 035ffe685..b34c6daa6 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkLeap.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkLeap.java @@ -14,6 +14,7 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.recharge.Recharge; @@ -74,7 +75,7 @@ public class PerkLeap extends Perk if (event.getPlayer().getItemInHand() == null) return; - if (!event.getPlayer().getItemInHand().getType().toString().contains("_AXE")) + if (!UtilItem.isAxe(event.getPlayer().getItemInHand())) return; Player player = event.getPlayer(); @@ -96,7 +97,7 @@ public class PerkLeap extends Perk } //Energy - if (!Recharge.Instance.use(player, _name, _recharge, true, true)) + if (!Recharge.Instance.use(player, _name, _recharge, false, true)) return; //Use Use diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkNightLivingDead.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkNightLivingDead.java index 64dcdc9b7..9f0bcc8c7 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkNightLivingDead.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkNightLivingDead.java @@ -13,8 +13,6 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Zombie; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityTargetEvent; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; import mineplex.core.common.util.UtilAlg; @@ -22,6 +20,7 @@ import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilTime; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.game.games.smash.TeamSuperSmash; import nautilus.game.arcade.kit.SmashPerk; import nautilus.game.arcade.kit.perks.data.NightLivingDeadData; @@ -126,6 +125,16 @@ public class PerkNightLivingDead extends SmashPerk { if (data.Zombies.contains(event.getEntity())) { + if (Manager.GetGame() instanceof TeamSuperSmash && event.getTarget() instanceof Player) + { + TeamSuperSmash smash = (TeamSuperSmash) Manager.GetGame(); + Player targetPlayer = (Player) event.getTarget(); + + if (smash.GetTeam(data.Player).equals(smash.GetTeam(targetPlayer))) + { + event.setCancelled(true); + } + } if (data.Player.equals(event.getTarget())) { event.setCancelled(true); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkPigBaconBounce.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkPigBaconBounce.java index b458b763d..195717459 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkPigBaconBounce.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkPigBaconBounce.java @@ -33,6 +33,7 @@ import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.projectile.IThrown; import mineplex.core.projectile.ProjectileUser; import mineplex.core.recharge.Recharge; +import nautilus.game.arcade.game.games.smash.TeamSuperSmash; import nautilus.game.arcade.kit.SmashPerk; public class PerkPigBaconBounce extends SmashPerk implements IThrown @@ -108,6 +109,18 @@ public class PerkPigBaconBounce extends SmashPerk implements IThrown if (target == null) return; + + if (Manager.GetGame() instanceof TeamSuperSmash && target instanceof Player && data.getThrower() instanceof Player) + { + TeamSuperSmash smash = (TeamSuperSmash) Manager.GetGame(); + Player targetPlayer = (Player) target; + Player throwerPlayer = (Player) data.getThrower(); + + if(smash.GetTeam(targetPlayer).equals(smash.GetTeam(throwerPlayer))) + { + return; + } + } //Damage Event Manager.GetDamage().NewDamageEvent(target, data.getThrower(), null, diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkSlimeRocket.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkSlimeRocket.java index 4a433a9d2..0bf4780f1 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkSlimeRocket.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkSlimeRocket.java @@ -33,6 +33,7 @@ import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.game.games.smash.TeamSuperSmash; import nautilus.game.arcade.kit.SmashPerk; public class PerkSlimeRocket extends SmashPerk implements IThrown @@ -208,6 +209,17 @@ public class PerkSlimeRocket extends SmashPerk implements IThrown if (!_owner.containsKey(event.getEntity())) return; + if (Manager.GetGame() instanceof TeamSuperSmash && event.getTarget() instanceof Player) + { + TeamSuperSmash smash = (TeamSuperSmash) Manager.GetGame(); + Player targetPlayer = (Player) event.getTarget(); + + if (smash.GetTeam(_owner.get(event.getEntity())).equals(smash.GetTeam(targetPlayer))) + { + event.setCancelled(true); + } + } + if (_owner.get(event.getEntity()).equals(event.getTarget())) { event.setCancelled(true); @@ -225,6 +237,18 @@ public class PerkSlimeRocket extends SmashPerk implements IThrown Slime slime = (Slime)data.getThrown(); + if (Manager.GetGame() instanceof TeamSuperSmash && target instanceof Player && data.getThrower() instanceof Player) + { + TeamSuperSmash smash = (TeamSuperSmash) Manager.GetGame(); + Player targetPlayer = (Player) target; + Player throwerPlayer = (Player) data.getThrower(); + + if(smash.GetTeam(targetPlayer).equals(smash.GetTeam(throwerPlayer))) + { + return; + } + } + //Damage Event Manager.GetDamage().NewDamageEvent(target, data.getThrower(), null, DamageCause.PROJECTILE, 3 + slime.getSize() * 3, true, true, false, @@ -275,6 +299,16 @@ public class PerkSlimeRocket extends SmashPerk implements IThrown //if (owner != null) // event.SetDamager(owner); This gives knockback from wrong direction :( + if (Manager.GetGame() instanceof TeamSuperSmash) + { + TeamSuperSmash smash = (TeamSuperSmash) Manager.GetGame(); + + if (smash.GetTeam(owner).equals(smash.GetTeam(event.GetDamageePlayer()))) + { + event.SetCancelled("Team Damage"); + return; + } + } if (owner != null && owner.equals(event.GetDamageeEntity())) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkWitherImage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkWitherImage.java index 5a7fccc01..28011f7ff 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkWitherImage.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkWitherImage.java @@ -2,6 +2,17 @@ package nautilus.game.arcade.kit.perks; import java.util.HashMap; import java.util.Iterator; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.recharge.Recharge; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import nautilus.game.arcade.game.games.smash.TeamSuperSmash; +import nautilus.game.arcade.kit.SmashPerk; import org.bukkit.Location; import org.bukkit.Material; @@ -17,20 +28,10 @@ import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerInteractEvent; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilAction; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.recharge.Recharge; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.minecraft.game.core.damage.CustomDamageEvent; -import nautilus.game.arcade.kit.SmashPerk; - public class PerkWitherImage extends SmashPerk { - private HashMap _images = new HashMap(); + private HashMap _ownerToSkeleton = new HashMap(); + private HashMap _skeletonToOwner = new HashMap(); public PerkWitherImage() { @@ -67,7 +68,7 @@ public class PerkWitherImage extends SmashPerk if (!Kit.HasKit(player)) return; - if (!_images.containsKey(player)) + if (!_ownerToSkeleton.containsKey(player)) { if (!Recharge.Instance.use(player, GetName(), 12000, true, true)) return; @@ -94,7 +95,8 @@ public class PerkWitherImage extends SmashPerk UtilAction.velocity(skel, player.getLocation().getDirection(), 1.6, false, 0, 0.2, 10, true); - _images.put(player, skel); + _ownerToSkeleton.put(player, skel); + _skeletonToOwner.put(skel, player); Recharge.Instance.use(player, "Wither Swap", 500, false, false); @@ -109,7 +111,7 @@ public class PerkWitherImage extends SmashPerk if (!Recharge.Instance.use(player, "Wither Swap", 2000, true, false)) return; - Skeleton skel = _images.get(player); + Skeleton skel = _ownerToSkeleton.get(player); Location loc = skel.getLocation(); skel.teleport(player.getLocation()); @@ -126,9 +128,23 @@ public class PerkWitherImage extends SmashPerk @EventHandler public void entityTarget(EntityTargetEvent event) { - if (_images.containsKey(event.getTarget())) - if (_images.get(event.getTarget()).equals(event.getEntity())) - event.setCancelled(true); + if (_skeletonToOwner.containsKey(event.getEntity())) + { + if (Manager.GetGame() instanceof TeamSuperSmash && event.getTarget() instanceof Player) + { + TeamSuperSmash smash = (TeamSuperSmash) Manager.GetGame(); + Player targetPlayer = (Player) event.getTarget(); + + if(smash.GetTeam(_skeletonToOwner.get(event.getEntity())).equals(smash.GetTeam(targetPlayer))) + { + event.setCancelled(true); + } + } + if (_ownerToSkeleton.get(event.getTarget()).equals(event.getEntity())) + { + event.setCancelled(true); + } + } } @EventHandler @@ -137,13 +153,13 @@ public class PerkWitherImage extends SmashPerk Player damagee = event.GetDamageePlayer(); if (damagee == null) return; - if (!_images.containsKey(damagee)) + if (!_ownerToSkeleton.containsKey(damagee.getUniqueId())) return; LivingEntity damager = event.GetDamagerEntity(false); if (damager == null) return; - if (_images.get(damagee).equals(damager)) + if (_ownerToSkeleton.get(damagee.getUniqueId()).equals(damager)) event.SetCancelled("Wither Image"); } @@ -153,12 +169,12 @@ public class PerkWitherImage extends SmashPerk LivingEntity damager = event.GetDamagerEntity(true); if (damager == null) return; - if (!_images.containsValue(damager)) + if (!_ownerToSkeleton.containsValue(damager)) return; - for (Player player : _images.keySet()) + for (Player player : _ownerToSkeleton.keySet()) { - if (_images.get(player).equals(damager)) + if (_ownerToSkeleton.get(player).equals(damager)) { event.SetDamager(player); event.setKnockbackOrigin(damager.getLocation()); @@ -173,12 +189,12 @@ public class PerkWitherImage extends SmashPerk if (event.getType() != UpdateType.FAST) return; - Iterator playerIterator = _images.keySet().iterator(); + Iterator playerIterator = _ownerToSkeleton.keySet().iterator(); while (playerIterator.hasNext()) { Player player = playerIterator.next(); - Skeleton skel = _images.get(player); + Skeleton skel = _ownerToSkeleton.get(player); if (!player.isValid() || !skel.isValid() || skel.getTicksLived() > 160) { @@ -195,7 +211,8 @@ public class PerkWitherImage extends SmashPerk @EventHandler(priority = EventPriority.LOWEST) public void clean(PlayerDeathEvent event) { - Skeleton skel = _images.remove(event.getEntity()); + Skeleton skel = _ownerToSkeleton.remove(event.getEntity()); + _skeletonToOwner.remove(skel); if (skel != null) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java index 2de25542c..8a80e2dcf 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameCreationManager.java @@ -105,6 +105,7 @@ public class GameCreationManager implements Listener { Game game = gameIterator.next(); + game.cleanupModules(); game.disable(); HandlerList.unregisterAll(game); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java index ae8e4157e..87c345881 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLobbyManager.java @@ -948,7 +948,8 @@ public class GameLobbyManager implements Listener public void Combust(EntityCombustEvent event) { for (LobbyEnt ent : _kits.values()) - if (event.getEntity().equals(ent.GetEnt())) + if (event.getEntity().getWorld().getUID().equals(ent.GetEnt().getWorld().getUID()) && + event.getEntity().equals(ent.GetEnt())) { event.setCancelled(true); return; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameSpectatorManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameSpectatorManager.java index b067a806d..defc9f325 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameSpectatorManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameSpectatorManager.java @@ -1,8 +1,22 @@ package nautilus.game.arcade.managers; +import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import java.util.UUID; +import mineplex.core.packethandler.IPacketHandler; +import mineplex.core.packethandler.PacketHandler; +import mineplex.core.packethandler.PacketInfo; +import net.minecraft.server.v1_8_R3.EntityPlayer; +import net.minecraft.server.v1_8_R3.NetworkManager; +import net.minecraft.server.v1_8_R3.PacketPlayOutCamera; +import net.minecraft.server.v1_8_R3.PacketPlayOutGameStateChange; +import net.minecraft.server.v1_8_R3.PacketPlayOutNamedEntitySpawn; +import net.minecraft.server.v1_8_R3.WorldSettings; import org.bukkit.GameMode; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -10,6 +24,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerGameModeChangeEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerToggleSneakEvent; @@ -26,8 +41,10 @@ import mineplex.core.updater.event.UpdateEvent; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.game.Game.GameState; -public class GameSpectatorManager implements Listener +public class GameSpectatorManager implements Listener, IPacketHandler { + private Set _pendingSpectate = Collections.synchronizedSet(new HashSet<>()); + ArcadeManager Manager; public GameSpectatorManager(ArcadeManager manager) @@ -35,11 +52,13 @@ public class GameSpectatorManager implements Listener Manager = manager; Manager.getPluginManager().registerEvents(this, Manager.getPlugin()); + + Manager.getPacketHandler().addPacketHandler(this, PacketHandler.ListenerPriority.HIGH, PacketPlayOutNamedEntitySpawn.class); } - + @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void interactCancel(PlayerInteractEvent event) - { + { if (Manager.GetGame() == null) return; @@ -47,30 +66,30 @@ public class GameSpectatorManager implements Listener if (!Manager.GetGame().IsAlive(player)) event.setCancelled(true); - + processClick(player, event.getAction()); } - + public void processClick(Player player, Action action) { if (Manager.GetGame() == null) return; - + if(!Manager.GetGame().AllowEntitySpectate) return; - + if(!Manager.GetGame().IsLive()) return; - + if(player.getGameMode() != GameMode.SPECTATOR) return; - + if(player.getSpectatorTarget() == null) return; - + if(!(player.getSpectatorTarget() instanceof Player)) return; - + List players = Manager.GetGame().GetPlayers(true); int currentPlayer = 0; for(Player otherPlayer : players) @@ -79,32 +98,32 @@ public class GameSpectatorManager implements Listener if(((Player) player.getSpectatorTarget()) == otherPlayer) break; } - + if(action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK) currentPlayer = currentPlayer - 2; else return; - + if(currentPlayer < 0) currentPlayer = players.size() - 1; - + if(currentPlayer >= players.size()) currentPlayer = 0; - + if(players.get(currentPlayer) == null) return; - + Player specPlayer = players.get(currentPlayer); - + setSpectating(player, specPlayer); } - + @EventHandler(priority = EventPriority.LOW) public void interactEntityCancel(PlayerInteractEntityEvent event) { if (Manager.GetGame() == null) return; - + Player player = event.getPlayer(); if (Manager.GetGame().GetState() == GameState.Recruit) @@ -114,7 +133,7 @@ public class GameSpectatorManager implements Listener return; } } - + if (!Manager.GetGame().IsAlive(player)) { event.setCancelled(true); @@ -127,7 +146,7 @@ public class GameSpectatorManager implements Listener } } } - + @EventHandler public void updateSpecEntitys(UpdateEvent event) { @@ -136,7 +155,7 @@ public class GameSpectatorManager implements Listener if(Manager.GetGame() == null) return; - + if(Manager.GetGame().IsLive() || Manager.GetGame().GetState() == GameState.End) { if(Manager.GetGame().AllowEntitySpectate) @@ -158,13 +177,13 @@ public class GameSpectatorManager implements Listener } } } - + @EventHandler(priority = EventPriority.LOW) public void spectatedEntityDeath(PlayerDeathEvent event) { if(Manager.GetGame() == null) return; - + if(Manager.GetGame().IsLive() || Manager.GetGame().GetState() == GameState.End) { if(Manager.GetGame().AllowEntitySpectate) @@ -191,13 +210,13 @@ public class GameSpectatorManager implements Listener } } } - + @EventHandler(priority = EventPriority.LOW) public void dismountEntity(PlayerToggleSneakEvent event) { if(Manager.GetGame() == null) return; - + if(Manager.GetGame().IsLive() || Manager.GetGame().GetState() == GameState.End) { if(Manager.GetGame().AllowEntitySpectate) @@ -213,41 +232,53 @@ public class GameSpectatorManager implements Listener } } } - - private void setSpectating(Player player, Entity target) - { - player.setGameMode(GameMode.SURVIVAL); - player.teleport(target.getLocation().add(0, 1, 0)); - player.getInventory().setHeldItemSlot(5); - Manager.runSyncLater(new Runnable() - { - @Override - public void run() - { - if (Manager.GetGame().IsAlive(player)) - return; - Player ptarget = null; - if (target instanceof Player) - ptarget = (Player) target; - - if (ptarget != null) - { - if (!Manager.GetGame().IsAlive(ptarget)) - return; - } - - player.setGameMode(GameMode.SPECTATOR); - player.setSpectatorTarget(target); - - if (ptarget != null) - UtilTextBottom.display(C.cGray + "You are spectating " + F.elem(Manager.GetGame().GetTeam(ptarget).GetColor() + ptarget.getName()) + ".", player); - - UtilPlayer.message(player, F.main("Game", "Sneak to stop spectating.")); + public void setSpectating(Player player, Entity target) + { + if (Manager.GetGame().IsAlive(player)) + { + return; + } + + Player playerTarget = null; + + if (target instanceof Player) + { + playerTarget = (Player) target; + if (!Manager.GetGame().IsAlive(playerTarget)) + { + return; } - }, 1); + } + + _pendingSpectate.add(target.getUniqueId()); + + player.teleport(target.getLocation().add(0, 1, 0)); + + // If the player already has the entity loaded, we have to set it now + + // todo + // In the future, we could do some really cool stuff where we listen to all incoming and outgoing + // spawn/destroy packets and track whether the client has loaded the entity in memory + // However, that approach has the risk of desynchronization at which point we're screwed + player.setGameMode(GameMode.SPECTATOR); + player.setSpectatorTarget(target); + + if (playerTarget != null) + UtilTextBottom.display(C.cGray + "You are spectating " + F.elem(Manager.GetGame().GetTeam(playerTarget).GetColor() + playerTarget.getName()) + ".", player); + + UtilPlayer.message(player, F.main("Game", "Sneak to stop spectating.")); + + // And if the player did have the entity loaded, we also need to clean up after ourselves + // 20 ticks should be more than enough time considering we're just waiting for the server to attempt to + // send the packet + // and even if the server was lagging, the scheduler should be lagging too + Manager.runSyncLater(() -> + { + _pendingSpectate.remove(target.getUniqueId()); + }, 20L); } - + @EventHandler(priority = EventPriority.LOW) public void vehicleDamage(VehicleDamageEvent event) { @@ -256,10 +287,57 @@ public class GameSpectatorManager implements Listener if (!(event.getAttacker() instanceof Player)) return; - + Player player = (Player)event.getAttacker(); if (!Manager.GetGame().IsAlive(player)) event.setCancelled(true); } + + @Override + public void handle(PacketInfo packetInfo) + { + if (packetInfo.getPacket() instanceof PacketPlayOutNamedEntitySpawn) + { + PacketPlayOutNamedEntitySpawn packet = (PacketPlayOutNamedEntitySpawn) packetInfo.getPacket(); + if (_pendingSpectate.remove(packet.b)) + { + // Handle Minestrike spam race condition + if (Manager.GetGame().IsAlive(packetInfo.getPlayer())) + { + return; + } + + packetInfo.setCancelled(true); + + EntityPlayer ep = ((CraftPlayer) packetInfo.getPlayer()).getHandle(); + NetworkManager manager = ep.playerConnection.networkManager; + + manager.a(packet, future -> + { + Manager.runSync(() -> + { + PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(packetInfo.getPlayer(), GameMode.SPECTATOR); + UtilServer.CallEvent(event); + if(event.isCancelled()) { + return; + } + + ep.playerInteractManager.setGameMode(WorldSettings.EnumGamemode.getById(GameMode.SPECTATOR.getValue())); + ep.fallDistance = 0.0F; + manager.a(new PacketPlayOutCamera(ep), future1 -> + { + manager.a(new PacketPlayOutGameStateChange(3, (float)GameMode.SPECTATOR.getValue()), future2 -> + { + PacketPlayOutCamera p1 = new PacketPlayOutCamera(); + p1.a = packet.a; + manager.handle(p1); + }); + + }); + }); + }); + } + } + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/wineffect/WinEffectManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/wineffect/WinEffectManager.java index 922a164d7..35362f78f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/wineffect/WinEffectManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/wineffect/WinEffectManager.java @@ -74,9 +74,15 @@ public class WinEffectManager public WinEffectGadget getWinEffect() { GadgetManager manager = _game.getArcadeManager().getCosmeticManager().getGadgetManager(); - Gadget gadget = manager.getActive(_winner, GadgetType.WIN_EFFECT); - if(gadget == null) gadget = manager.getGadget(WinEffectPodium.class); - return (WinEffectGadget) gadget; + Gadget winEffect = manager.getGadget(WinEffectPodium.class); + for (Gadget gadget : manager.getGadgets(GadgetType.WIN_EFFECT)) + { + if (gadget.isActive(_winner)) + { + winEffect = gadget; + } + } + return (WinEffectGadget) winEffect; } }