diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Pair.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Pair.java index 7ec401ed6..e89e491af 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Pair.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Pair.java @@ -45,21 +45,25 @@ public class Pair implements Serializable { return getLeft().toString() + ":" + getRight().toString(); } - @SuppressWarnings("rawtypes") + @Override - public boolean equals(Object obj) + public boolean equals(Object o) { - if (this == obj) - return true; - if (!(obj instanceof Pair)) - return false; + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; - Pair localPair = (Pair) obj; + Pair pair = (Pair) o; - if (getLeft() != null ? !getLeft().equals(localPair.getLeft()) : localPair.getLeft() != null) - return false; - if (getRight() != null ? !getRight().equals(localPair.getRight()) : localPair.getRight() != null) - return false; - return true; + if (left != null ? !left.equals(pair.left) : pair.left != null) return false; + return right != null ? right.equals(pair.right) : pair.right == null; + + } + + @Override + public int hashCode() + { + int result = left != null ? left.hashCode() : 0; + result = 31 * result + (right != null ? right.hashCode() : 0); + return result; } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilInv.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilInv.java index 4f8313b43..f7b6cbec7 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilInv.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilInv.java @@ -173,7 +173,17 @@ public class UtilInv return getItems(player, true, true, true); } + public static ArrayList getItemsUncloned(Player player) + { + return getItems(player, true, true, true, false); + } + public static ArrayList getItems(Player player, boolean getArmor, boolean getCursor, boolean getCrafting) + { + return getItems(player, getArmor, getCursor, getCrafting, true); + } + + public static ArrayList getItems(Player player, boolean getArmor, boolean getCursor, boolean getCrafting, boolean clone) { ArrayList items = new ArrayList(); PlayerInventory inv = player.getInventory(); @@ -182,7 +192,7 @@ public class UtilInv { if (item != null && item.getType() != Material.AIR) { - items.add(item.clone()); + items.add(clone ? item.clone() : item); } } @@ -192,7 +202,7 @@ public class UtilInv { if (item != null && item.getType() != Material.AIR) { - items.add(item.clone()); + items.add(clone ? item.clone() : item); } } } @@ -202,7 +212,7 @@ public class UtilInv ItemStack cursorItem = player.getItemOnCursor(); if (cursorItem != null && cursorItem.getType() != Material.AIR) - items.add(cursorItem.clone()); + items.add(clone ? cursorItem.clone() : cursorItem); } if (getCrafting) @@ -215,7 +225,7 @@ public class UtilInv { if (item != null && item.getType() != Material.AIR) { - items.add(item.clone()); + items.add(clone ? item.clone() : item); } } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java index f2c320b74..e025133f9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java @@ -57,7 +57,14 @@ public class CoreClientManager extends MiniPlugin private static AtomicInteger _clientsConnecting = new AtomicInteger(0); private static AtomicInteger _clientsProcessing = new AtomicInteger(0); + private final Rank WHITELIST_BYPASS; + public CoreClientManager(JavaPlugin plugin, String webServer) + { + this(plugin, webServer, Rank.MODERATOR); + } + + public CoreClientManager(JavaPlugin plugin, String webServer, Rank whitelistBypass) { super("Client Manager", plugin); @@ -65,6 +72,7 @@ public class CoreClientManager extends MiniPlugin _repository = new AccountRepository(plugin, webServer); _clientList = new NautHashMap(); _duplicateLoginGlitchPreventionList = new HashSet(); + WHITELIST_BYPASS = whitelistBypass; } public AccountRepository getRepository() @@ -195,7 +203,7 @@ public class CoreClientManager extends MiniPlugin _clientsProcessing.decrementAndGet(); } - if (Bukkit.hasWhitelist() && !Get(event.getName()).GetRank().has(Rank.MODERATOR)) + if (Bukkit.hasWhitelist() && !Get(event.getName()).GetRank().has(WHITELIST_BYPASS)) { for (OfflinePlayer player : Bukkit.getWhitelistedPlayers()) { 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 327bc3be5..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 @@ -89,11 +89,14 @@ import mineplex.minecraft.game.classcombat.shop.ClassCombatShop; import mineplex.minecraft.game.classcombat.shop.ClassShopManager; import mineplex.minecraft.game.core.IRelation; import mineplex.minecraft.game.core.combat.CombatManager; +import mineplex.minecraft.game.core.condition.Condition; import mineplex.minecraft.game.core.condition.ConditionManager; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; import mineplex.minecraft.game.core.damage.DamageManager; import mineplex.minecraft.game.core.fire.Fire; import mineplex.minecraft.game.core.mechanics.Weapon; import mineplex.serverdata.commands.ServerCommandManager; +import net.md_5.bungee.api.ChatColor; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -321,6 +324,19 @@ public class ClansManager extends MiniClientPluginimplements IRelati Material targetType = event.getTargetBlock().getType(); event.setCancelled(targetType == Material.POTATO || targetType == Material.CARROT); } + + @EventHandler + public void on(CustomDamageEvent event) + { + if (event.GetCause() == EntityDamageEvent.DamageCause.CUSTOM + && event.GetDamageInitial() == 0.1 + && event.GetDamageePlayer() != null) + { + Condition poisonShock = _condition.GetActiveCondition(event.GetDamageePlayer(), Condition.ConditionType.POISON_SHOCK); + if (poisonShock != null) + event.SetIgnoreArmor(true); + } + } }); _worldEvent.setFactory(skillManager); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/KillCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/KillCommand.java index 151567dbd..611838bd7 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/KillCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/KillCommand.java @@ -1,6 +1,7 @@ package mineplex.game.clans.clans.commands; import mineplex.game.clans.clans.ClansManager; +import mineplex.minecraft.game.classcombat.Skill.Global.Recharge; import org.bukkit.entity.Player; import mineplex.core.command.CommandBase; @@ -29,6 +30,11 @@ public class KillCommand extends CommandBase UtilPlayer.message(caller, F.main("Clans", "You cannot use this command whilst in the tutorial.")); return; } + if (mineplex.core.recharge.Recharge.Instance.use(caller, "Suicide", 5000, false, false)) + { + UtilPlayer.message(caller, F.main("Clans", "Please wait a bit before suiciding")); + return; + } UtilPlayer.message(caller, F.main("Clans", "You have imploded.")); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/page/ClanWhoPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/page/ClanWhoPage.java index 6fe27d3ad..5550d370a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/page/ClanWhoPage.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/page/ClanWhoPage.java @@ -62,7 +62,7 @@ public class ClanWhoPage extends ClanPageBase // Basic Clan Info lore.add(C.Reset + C.cYellow + "Founder " + C.cWhite + _lookupClan.getDesc()); - lore.add(C.Reset + C.cYellow + "Formed " + C.cWhite + UtilTime.convertString(System.currentTimeMillis() - _lookupClan.getDateCreated().getTime(), 1, UtilTime.TimeUnit.FIT)); + lore.add(C.Reset + C.cYellow + "Formed " + C.cWhite + UtilTime.convertString(System.currentTimeMillis() - _lookupClan.getDateCreated().getTime(), 1, UtilTime.TimeUnit.FIT) + " ago on " + UtilTime.when(_lookupClan.getDateCreated().getTime())); lore.add(C.Reset + C.cYellow + "Members " + C.cWhite + _lookupClan.getOnlinePlayerCount() + "/" + _lookupClan.getMembers().size()); lore.add(C.Reset + C.cYellow + "Territory " + C.cWhite + _lookupClan.getClaims() + "/" + _lookupClan.getClaimsMax()); lore.add(C.Reset + C.cYellow + "TNT Protection " + C.cWhite + _lookupClan.getProtected()); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java index 8d819ff9b..db6fa935f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java @@ -58,7 +58,10 @@ public class SafeLog extends MiniPlugin if (!isSafeLog) { - NPCManager.getInstance().spawnLogoutNpc(player); + if (!_clansManager.getIncognitoManager().Get(player).Status) + { + NPCManager.getInstance().spawnLogoutNpc(player); + } } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java index 116cb315c..a16b7529b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java @@ -6,6 +6,9 @@ import java.util.UUID; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftItem; +import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemFactory; +import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractEvent; @@ -105,7 +108,7 @@ public class CustomItem implements Listener public ItemStack toItemStack(int amount) { - ItemStack item = new ItemStack(_material, amount); + ItemStack item = CraftItemStack.asCraftMirror(CraftItemStack.asNMSCopy(new ItemStack(_material, amount))); update(item); if (_dullEnchantment) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java index 21befc0b9..43849130c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java @@ -2,6 +2,8 @@ package mineplex.game.clans.items; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; import java.util.Iterator; @@ -86,21 +88,6 @@ import net.minecraft.server.v1_8_R3.PacketPlayOutWindowItems; */ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable { - private static final Field UNHANDLED_TAGS_FIELD; - - static - { - try - { - UNHANDLED_TAGS_FIELD = Class.forName("org.bukkit.craftbukkit.v1_8_R3.inventory.CraftMetaItem").getDeclaredField("unhandledTags"); - UNHANDLED_TAGS_FIELD.setAccessible(true); - } - catch (Throwable t) - { - throw new RuntimeException("Error getting unhandledTags field", t); - } - } - private static final String ITEM_SERIALIZATION_TAG = "-JSON-"; private static final Gson GSON; @@ -626,7 +613,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable return null; } - CraftItemStack originalItem = CraftItemStack.asCraftMirror(item); + CraftItemStack originalItem = CraftItemStack.asCraftMirror(item.cloneItemStack()); ItemMeta originalMeta = originalItem.getItemMeta(); // No need to modify item packets with no lore @@ -680,7 +667,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable List cleansed = new ArrayList<>(); for (String s : input) { - if (!s.startsWith(ITEM_SERIALIZATION_TAG)) + if (s.startsWith(ITEM_SERIALIZATION_TAG)) { cleansed.add(s); } @@ -697,40 +684,35 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable // This will not be persistent if the ItemStack is a block and placed then picked up private static Map getUnhandledTags(ItemStack itemStack) { - ItemMeta itemMeta = itemStack.getItemMeta(); - if (itemMeta == null) + net.minecraft.server.v1_8_R3.ItemStack handle = ((CraftItemStack) itemStack).getHandle(); + if (handle == null) + return Collections.emptyMap(); + + NBTTagCompound tag = handle.getTag(); + + if (tag == null) + return Collections.emptyMap(); + + Map unhandled = new HashMap<>(); + for (String name : tag.c()) { - return null; + unhandled.put(name, tag.get(name)); } - try - { - return (Map) UNHANDLED_TAGS_FIELD.get(itemMeta); - } - catch (IllegalAccessException e) - { - System.out.println("Could not get unhandledTags"); - e.printStackTrace(); - } - return null; + return unhandled; } private static void saveUnhandledTags(ItemStack itemStack, Map map) { - ItemMeta itemMeta = itemStack.getItemMeta(); - if (itemMeta == null) + net.minecraft.server.v1_8_R3.ItemStack handle = ((CraftItemStack) itemStack).getHandle(); + NBTTagCompound tag = handle.getTag(); + + if (tag != null) { - return; + for (String name : map.keySet()) + { + tag.set(name, map.get(name)); + } } - try - { - UNHANDLED_TAGS_FIELD.set(itemMeta, map); - } - catch (IllegalAccessException e) - { - System.out.println("Could not get unhandledTags"); - e.printStackTrace(); - } - itemStack.setItemMeta(itemMeta); } public static void save(ItemStack itemStack, boolean remove) @@ -743,7 +725,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable saveUnhandledTags(itemStack, data); if (remove) { - _customItemCache.remove(item); + _customItemCache.remove(UUID.fromString(item._uuid)); } } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ItemListener.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ItemListener.java index c3bbbf9a8..02ff57e7e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ItemListener.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ItemListener.java @@ -16,6 +16,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerGameModeChangeEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemHeldEvent; @@ -44,7 +45,7 @@ public class ItemListener implements Listener, Runnable public ItemListener(JavaPlugin plugin) { _plugin = plugin; - _plugin.getServer().getScheduler().runTaskTimer(_plugin, this, 20 * 60 * 5, 0); + _plugin.getServer().getScheduler().runTaskTimer(_plugin, this, 0, 20 * 60 * 5); } @Override @@ -65,7 +66,7 @@ public class ItemListener implements Listener, Runnable private void save(Player player, boolean remove) { - for (ItemStack item : UtilInv.getItems(player)) + for (ItemStack item : UtilInv.getItemsUncloned(player)) { GearManager.save(item, remove); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/LegendaryItem.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/LegendaryItem.java index f01f68886..f27d909df 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/LegendaryItem.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/LegendaryItem.java @@ -13,7 +13,7 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent; public class LegendaryItem extends CustomItem { - private final long BLOCK_COOLDOWN = 200L; // Right clicking activates right click for 200ms + private static final long BLOCK_COOLDOWN = 200L; // Right clicking activates right click for 200ms protected long _lastBlock; // Timestamp of last block from wielder diff --git a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/condition/ConditionManager.java b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/condition/ConditionManager.java index dbac07668..54b6e7437 100644 --- a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/condition/ConditionManager.java +++ b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/condition/ConditionManager.java @@ -402,6 +402,18 @@ public class ConditionManager extends MiniPlugin return false; } + + public boolean HasCondition(LivingEntity target, ConditionType type) + { + if (!_conditions.containsKey(target)) + return false; + + for (Condition cond : _conditions.get(target)) + if (type == null || cond.GetType() == type) + return true; + + return false; + } public WeakHashMap> GetActiveConditions() { 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 daba8449a..f19f26b67 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 @@ -3,6 +3,9 @@ package mineplex.minecraft.game.core.damage; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.math.BigDecimal; +import java.util.Arrays; +import java.util.HashMap; import java.util.Map; import mineplex.core.MiniPlugin; @@ -57,6 +60,9 @@ public class DamageManager extends MiniPlugin public boolean DisableDamageChanges = false; private boolean _enabled = true; + + private final HashMap _protectionTypeModifiers = new HashMap(); + private final HashMap _protectionCauses = new HashMap(); public DamageManager(JavaPlugin plugin, CombatManager combatManager, NpcManager npcManager, DisguiseManager disguiseManager, ConditionManager conditionManager) { @@ -79,6 +85,102 @@ public class DamageManager extends MiniPlugin } registerEvents(new NpcProtectListener(npcManager)); + + _protectionTypeModifiers.put(Enchantment.PROTECTION_ENVIRONMENTAL.getName(), 1); + _protectionTypeModifiers.put(Enchantment.PROTECTION_FIRE.getName(), 2); + _protectionTypeModifiers.put(Enchantment.PROTECTION_EXPLOSIONS.getName(), 2); + _protectionTypeModifiers.put(Enchantment.PROTECTION_PROJECTILE.getName(), 2); + _protectionTypeModifiers.put(Enchantment.PROTECTION_FALL.getName(), 3); + + _protectionCauses.put(Enchantment.PROTECTION_ENVIRONMENTAL.getName(), new DamageCause[] {DamageCause.BLOCK_EXPLOSION, DamageCause.CONTACT, DamageCause.CUSTOM, DamageCause.DROWNING, DamageCause.ENTITY_ATTACK, DamageCause.ENTITY_EXPLOSION, DamageCause.FALL, DamageCause.FALLING_BLOCK, DamageCause.FIRE, DamageCause.FIRE_TICK, DamageCause.LAVA, DamageCause.LIGHTNING, DamageCause.PROJECTILE, DamageCause.SUFFOCATION, DamageCause.THORNS}); + _protectionCauses.put(Enchantment.PROTECTION_FIRE.getName(), new DamageCause[] {DamageCause.FIRE, DamageCause.FIRE_TICK, DamageCause.LAVA}); + _protectionCauses.put(Enchantment.PROTECTION_EXPLOSIONS.getName(), new DamageCause[] {DamageCause.BLOCK_EXPLOSION, DamageCause.ENTITY_EXPLOSION}); + _protectionCauses.put(Enchantment.PROTECTION_PROJECTILE.getName(), new DamageCause[] {DamageCause.PROJECTILE}); + _protectionCauses.put(Enchantment.PROTECTION_FALL.getName(), new DamageCause[] {DamageCause.FALL}); + } + + private int getHighestLevel(Enchantment ench, ItemStack[] items) + { + int level = 0; + + for (ItemStack item : items) + { + if (item == null && item.getType() == Material.AIR) + { + continue; + } + if (!item.containsEnchantment(ench)) + { + continue; + } + if (item.getEnchantmentLevel(ench) <= level) + { + continue; + } + level = item.getEnchantmentLevel(ench); + } + + return level; + } + + private int getTotalEPF(Enchantment ench, ItemStack[] items) + { + if (!_protectionTypeModifiers.containsKey(ench.getName())) + { + return 0; + } + if (!_protectionCauses.containsKey(ench.getName())) + { + return 0; + } + + int epf = 0; + + for (ItemStack item : items) + { + if (item == null || item.getType() == Material.AIR) + { + continue; + } + if (!item.containsEnchantment(ench)) + { + continue; + } + if (item.getEnchantmentLevel(ench) <= 0) + { + continue; + } + + epf += (item.getEnchantmentLevel(ench) * _protectionTypeModifiers.get(ench.getName())); + } + + return Math.min(20, epf); + } + + private double getTotalEnchantReduction(ItemStack[] armor, DamageCause cause) + { + int epf = 0; + + for (Enchantment ench : Enchantment.values()) + { + if (!_protectionTypeModifiers.containsKey(ench.getName())) + { + continue; + } + if (!_protectionCauses.containsKey(ench.getName())) + { + continue; + } + if (!Arrays.asList(_protectionCauses.get(ench.getName())).contains(cause)) + { + continue; + } + + epf += getTotalEPF(ench, armor); + } + + epf = Math.max(0, Math.min(20, epf)); + return new BigDecimal(1).subtract(new BigDecimal(epf).divide(new BigDecimal(25))).doubleValue(); } @EventHandler(priority = EventPriority.HIGHEST) @@ -273,35 +375,9 @@ public class DamageManager extends MiniPlugin Player damagee = event.GetDamageePlayer(); if (damagee != null) { - for (ItemStack stack : damagee.getInventory().getArmorContents()) + if (getTotalEnchantReduction(damagee.getInventory().getArmorContents(), event.GetCause()) > 0) { - if (stack == null) - continue; - - Map enchants = stack.getEnchantments(); - for (Enchantment e : enchants.keySet()) - { - if (e.equals(Enchantment.PROTECTION_ENVIRONMENTAL)) - event.AddMod("Ench Prot", damagee.getName(), 0.5 * (double)enchants.get(e), false); - - else if (e.equals(Enchantment.PROTECTION_FIRE) && - event.GetCause() == DamageCause.FIRE && - event.GetCause() == DamageCause.FIRE_TICK && - event.GetCause() == DamageCause.LAVA) - event.AddMod("Ench Prot", damagee.getName(), 0.5 * (double)enchants.get(e), false); - - else if (e.equals(Enchantment.PROTECTION_FALL) && - event.GetCause() == DamageCause.FALL) - event.AddMod("Ench Prot", damagee.getName(), 0.5 * (double)enchants.get(e), false); - - else if (e.equals(Enchantment.PROTECTION_EXPLOSIONS) && - event.GetCause() == DamageCause.ENTITY_EXPLOSION) - event.AddMod("Ench Prot", damagee.getName(), 0.5 * (double)enchants.get(e), false); - - else if (e.equals(Enchantment.PROTECTION_PROJECTILE) && - event.GetCause() == DamageCause.PROJECTILE) - event.AddMod("Ench Prot", damagee.getName(), 0.5 * (double)enchants.get(e), false); - } + event.AddMult("Ench Prot", damagee.getName(), getTotalEnchantReduction(damagee.getInventory().getArmorContents(), event.GetCause()), false); } } @@ -324,8 +400,15 @@ public class DamageManager extends MiniPlugin else if (e.equals(Enchantment.FIRE_ASPECT)) if (_conditionManager != null) + { + double reduce = 0; + if (damagee != null) + { + reduce = (15 * getHighestLevel(Enchantment.PROTECTION_FIRE, damagee.getInventory().getArmorContents())) * (4 * (double)enchants.get(e)); + } _conditionManager.Factory().Ignite("Ench Fire", event.GetDamageeEntity(), damager, - 4 * (double)enchants.get(e), false, false); + (4 * (double)enchants.get(e)) - reduce, false, false); + } } } diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java index 5a58758c7..282933d23 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/StaffServer.java @@ -7,6 +7,7 @@ import mineplex.core.achievement.AchievementManager; import mineplex.core.antihack.AntiHack; import mineplex.core.chat.Chat; import mineplex.core.command.CommandCenter; +import mineplex.core.common.Rank; import mineplex.core.creature.Creature; import mineplex.core.donation.DonationManager; import mineplex.core.elo.EloManager; @@ -48,7 +49,7 @@ public class StaffServer extends JavaPlugin //Static Modules CommandCenter.Initialize(this); - CoreClientManager clientManager = new CoreClientManager(this, webServerAddress); + CoreClientManager clientManager = new CoreClientManager(this, webServerAddress, Rank.DEVELOPER); CommandCenter.Instance.setClientManager(clientManager); Recharge.Initialize(this); @@ -83,15 +84,15 @@ public class StaffServer extends JavaPlugin ((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("cf1b629c-cc55-4eb4-be9e-3ca86dfc7b9d"), "mannalou")); ((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("04a484d0-93e0-4777-a70c-808046917e3a"), "EvilEsther")); ((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("adaa7613-6683-400f-baf8-7272c04b2cb4"), "Timmy48081_")); - ((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("57791647-93b1-4980-8835-7fddadd20eb8"), "xTheOnlyOreOx")); + ((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("231fb752-9556-489b-8428-f47c7598e061"), "Nuclear_Poptart")); ((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("efaf9a17-2304-4f42-8433-421523c308dc"), "B2_mp")); ((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("492ff708-fe76-4c5a-b9ed-a747b5fa20a0"), "Cherdy8s")); - ((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("cf85f470-5248-4978-8208-435736fa136e"), "RustyRoo")); + ((CraftServer)getServer()).getHandle().addWhitelist(new GameProfile(UUID.fromString("6edf17d5-6bb2-4ed9-92e9-bed8e96fff68"), "BlueBeetleHD")); ((CraftServer)getServer()).getHandle().addOp(new GameProfile(UUID.fromString("377bdea3-badc-448d-81c1-65db43b17ea4"), "Strutt20")); ((CraftServer)getServer()).getHandle().addOp(new GameProfile(UUID.fromString("efaf9a17-2304-4f42-8433-421523c308dc"), "B2_mp")); - ((CraftServer)getServer()).getHandle().addOp(new GameProfile(UUID.fromString("cf85f470-5248-4978-8208-435736fa136e"), "RustyRoo")); + ((CraftServer)getServer()).getHandle().addOp(new GameProfile(UUID.fromString("6edf17d5-6bb2-4ed9-92e9-bed8e96fff68"), "BlueBeetleHD")); new ProfileCacheManager(this); } diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/customerSupport/CustomerSupport.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/customerSupport/CustomerSupport.java index 1842ee5e4..c91f53c0e 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/customerSupport/CustomerSupport.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/customerSupport/CustomerSupport.java @@ -57,9 +57,9 @@ public class CustomerSupport extends MiniPlugin implements ResultSetCallable @EventHandler public void Join(PlayerJoinEvent event) { - if (!_clientManager.Get(event.getPlayer()).GetRank().has(Rank.MODERATOR)) + if (!_clientManager.Get(event.getPlayer()).GetRank().has(Rank.SUPPORT)) { - event.getPlayer().kickPlayer("Only for staff."); + event.getPlayer().kickPlayer("Only for support staff."); return; } @@ -119,7 +119,7 @@ public class CustomerSupport extends MiniPlugin implements ResultSetCallable caller.sendMessage(C.cDGreen + C.Strike + "============================================="); caller.sendMessage(C.cBlue + "Name: " + C.cYellow + playerName); caller.sendMessage(C.cBlue + "Rank: " + C.cYellow + (client.GetRank() == null ? C.cRed + "Error rank null!" : (client.GetRank().Name.isEmpty() ? "Regular" : client.GetRank().Name))); - caller.sendMessage(C.cBlue + "Coins: " + C.cYellow + donor.getCoins()); + caller.sendMessage(C.cBlue + "Shards: " + C.cYellow + donor.getCoins()); caller.sendMessage(C.cBlue + "Gems: " + C.cYellow + donor.GetGems()); int enjinCoinsReceived = 0; @@ -234,7 +234,7 @@ public class CustomerSupport extends MiniPlugin implements ResultSetCallable } // Strutt20 asked me to remove some stuff from the menu - caller.sendMessage(C.cBlue + "Enjin Coin Total Received: " + C.cYellow + enjinCoinsReceived); + caller.sendMessage(C.cBlue + "Enjin Shard Total Received: " + C.cYellow + enjinCoinsReceived); caller.sendMessage(C.cBlue + "Old Chests Received: " + C.cYellow + oldChestsReceived); caller.sendMessage(C.cBlue + "Ancient Chests Received: " + C.cYellow + ancientChestsReceived); caller.sendMessage(C.cBlue + "Mythical Chests Received: " + C.cYellow + mythicalChestsReceived); diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/SalesPackageManager.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/SalesPackageManager.java index 65f25a186..67dea4d96 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/SalesPackageManager.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/SalesPackageManager.java @@ -94,7 +94,7 @@ public class SalesPackageManager extends MiniPlugin public void displaySalesPackages(Player caller, String playerName) { - JsonMessage coinBuilder = new JsonMessage("Coins : ").color("blue"); + JsonMessage coinBuilder = new JsonMessage("Shards : ").color("blue"); JsonMessage packageBuilder = new JsonMessage("Rank Packages : ").color("blue"); JsonMessage chestBuilder = new JsonMessage("Chest Packages : ").color("blue"); @@ -104,7 +104,7 @@ public class SalesPackageManager extends MiniPlugin { coinBuilder = coinBuilder.extra("[").color("gray").extra(salesPackage.getName()).color("green").click("run_command", "/display " + playerName + " " + salesPackage.getName()).extra("] ").color("gray"); } - else if (salesPackage instanceof MythicalChest || salesPackage instanceof AncientChest || salesPackage instanceof OldChest || salesPackage instanceof IlluminatedChest) + else if (salesPackage instanceof MythicalChest || salesPackage instanceof AncientChest || salesPackage instanceof OldChest || salesPackage instanceof IlluminatedChest || salesPackage instanceof FreedomChest) { chestBuilder = chestBuilder.extra("[").color("gray").extra(salesPackage.getName()).color("green").click("run_command", "/display " + playerName + " " + salesPackage.getName()).extra("] ").color("gray"); } diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/CoinCommand.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/CoinCommand.java index 02dd85695..3ced1fbc3 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/CoinCommand.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/CoinCommand.java @@ -17,7 +17,7 @@ public class CoinCommand extends CommandBase { public CoinCommand(SalesPackageManager plugin) { - super(plugin, Rank.MODERATOR, "coin"); + super(plugin, Rank.MODERATOR, "coin", "shard", "shards"); } @Override @@ -43,11 +43,11 @@ public class CoinCommand extends CommandBase { if (completed) { - caller.sendMessage(F.main(Plugin.getName(), "Added " + amount + " coins to " + playerName + "'s account!")); + caller.sendMessage(F.main(Plugin.getName(), "Added " + amount + " shards to " + playerName + "'s account!")); } else { - UtilPlayer.message(caller, F.main(Plugin.getName(), "There was an error giving " + F.elem(amount + "Coins") + " to " + F.name(playerName) + ".")); + UtilPlayer.message(caller, F.main(Plugin.getName(), "There was an error giving " + F.elem(amount + "Shards") + " to " + F.name(playerName) + ".")); } } }, caller.getName(), playerName, client.getAccountId(), amount); diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/salespackages/Coins.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/salespackages/Coins.java index 1091a16fd..51c79115d 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/salespackages/Coins.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/salespackages/Coins.java @@ -10,13 +10,13 @@ public class Coins extends SalesPackageBase public Coins(SalesPackageManager manager, int amount) { - super(manager, amount + " Coins"); + super(manager, amount + " Shards"); _amount = amount; } public void displayToAgent(Player agent, String playerName) { - addButton(agent, "/sales coin " + playerName + " " + _amount, _amount + " Coins."); + addButton(agent, "/sales coin " + playerName + " " + _amount, _amount + " Shards."); agent.sendMessage(" "); addBackButton(agent, playerName); } diff --git a/Plugins/Nautilus.Game.Arcade/pom.xml b/Plugins/Nautilus.Game.Arcade/pom.xml index 6c69780d2..f23ada168 100644 --- a/Plugins/Nautilus.Game.Arcade/pom.xml +++ b/Plugins/Nautilus.Game.Arcade/pom.xml @@ -19,5 +19,9 @@ mineplex-minecraft-game-classcombat ${project.version} + + fr.neatmonster + nocheatplus + 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 531b5045f..74f0ee8af 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 @@ -917,7 +917,7 @@ public abstract class Game implements Listener if (GetKit(player) == null) return false; - return GetKit(player).equals(kit); + return GetKit(player).GetName().equals(kit.GetName()); } public boolean SetPlayerState(Player player, PlayerState state) 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 256771fdb..36bd685e2 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 @@ -268,11 +268,18 @@ public class GameTeam return GetColor() + "§l" + GetName(); } - public void SpawnTeleport(Player player) - { + public Location SpawnTeleport(Player player) + { + Location l = GetSpawn(); + player.teleport(l); + return l; + } + + public void SpawnTeleport(Player player, Location location) + { player.leaveVehicle(); player.eject(); - player.teleport(GetSpawn()); + player.teleport(location); } public void SpawnTeleport() diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/Build.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/Build.java index f737f6790..e5aab2079 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/Build.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/build/Build.java @@ -1505,6 +1505,11 @@ public class Build extends Game { Player player = ((Player) event.getWhoClicked()); + if (_buildGameState == 2 || _buildGameState == 3) + { + event.setCancelled(true); + } + if (IsLive() && IsAlive(player)) { BuildData buildData = _data.get(player); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/dragonescape/DragonEscape.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/dragonescape/DragonEscape.java index cc2f238b6..c6cead608 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/dragonescape/DragonEscape.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/dragonescape/DragonEscape.java @@ -632,8 +632,15 @@ public class DragonEscape extends SoloGame @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { + if (!IsLive()) + return; + + if (event.getClickedBlock() == null) + return; + if(event.getClickedBlock().getType() != Material.TRAP_DOOR) return; + // Stops players using trap doors in game. event.setCancelled(true); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/gladiators/hotbar/HotbarInventory.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/gladiators/hotbar/HotbarInventory.java index 9ffc569ae..61f38d12e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/gladiators/hotbar/HotbarInventory.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/gladiators/hotbar/HotbarInventory.java @@ -21,7 +21,7 @@ public class HotbarInventory { Inventory inv = UtilServer.getServer().createInventory(null, 36, "Hotbar Editor"); - for (int slot : Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 18, 19, 20, 21, 22, 23, 24, 25, 26)) + for (int slot : Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 33, 34, 35)) { inv.setItem(slot, getGlass(slot)); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/gladiators/hotbar/HotbarPageListener.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/gladiators/hotbar/HotbarPageListener.java index 736de92df..ead613383 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/gladiators/hotbar/HotbarPageListener.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/gladiators/hotbar/HotbarPageListener.java @@ -8,12 +8,21 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryDragEvent; +import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilItem; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; /** * Created by William (WilliamTiger). @@ -27,7 +36,7 @@ public class HotbarPageListener implements Listener { _editor = editor; } - + @EventHandler public void onClick(InventoryClickEvent e) { @@ -140,4 +149,51 @@ public class HotbarPageListener implements Listener i.remove(); } + + @EventHandler + public void updateInv(UpdateEvent event) + { + if (event.getType() != UpdateType.FASTER) + return; + + for (Player player : UtilServer.GetPlayers()) + { + if (player.getOpenInventory() == null) + continue; + + if (player.getOpenInventory().getTopInventory() == null) + continue; + + if (!player.getOpenInventory().getTopInventory().getName().equals("Hotbar Editor")) + continue; + + for (Material mat : new Material[]{Material.DIAMOND_SWORD, Material.BOW, Material.FISHING_ROD, Material.ARROW}) + { + boolean founditem = false; + for (ItemStack item : player.getOpenInventory().getTopInventory().getContents()) + { + if (item != null && item.getType() == mat) + { + founditem = true; + } + } + if (player.getItemOnCursor() != null) + { + if (player.getItemOnCursor().getType() == mat) + founditem = true; + } + + if (!founditem) + { + player.getOpenInventory().getTopInventory().addItem(new ItemStack(mat)); + } + + + if (UtilInv.contains(player, null, mat, (byte) 0, 1, false, true, false)) + { + UtilInv.removeAll(player, mat, (byte) 0); + } + } + } + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/lobbers/kits/perks/PerkWaller.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/lobbers/kits/perks/PerkWaller.java index 90550c8c4..89a415a4e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/lobbers/kits/perks/PerkWaller.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/lobbers/kits/perks/PerkWaller.java @@ -7,6 +7,7 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.recharge.Recharge; import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilInv; import nautilus.game.arcade.game.games.lobbers.events.TNTThrowEvent; @@ -76,6 +77,11 @@ public class PerkWaller extends Perk return; } + if (!Recharge.Instance.usable(event.getPlayer(), "Waller")) + return; + + Recharge.Instance.use(event.getPlayer(), "Waller", 100, false, false); + UtilInv.remove(event.getPlayer(), Material.STONE_SPADE, (byte) 0, 1); _wallBlocks.addAll(buildWall(event.getClickedBlock().getLocation(), event.getPlayer().getLocation().getYaw())); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/Gun.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/Gun.java index cabfdcf94..102f87e3d 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/Gun.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minestrike/items/guns/Gun.java @@ -331,7 +331,7 @@ public class Gun extends StrikeItem { new BukkitRunnable() { public void run() { - PlayerStats remoteStats = game.getArcadeManager().GetStatsManager().Get(player);; + PlayerStats remoteStats = game.getArcadeManager().GetStatsManager().Get(player); _kills = (int) remoteStats.getStat(game.GetName() + "." + getStatNameKills(true)); Player owner = UtilPlayer.searchExact(getOwnerName()); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/MonsterMaze.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/MonsterMaze.java index d52c5039b..dc3538511 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/MonsterMaze.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/MonsterMaze.java @@ -48,6 +48,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.scoreboard.Team; public class MonsterMaze extends SoloGame @@ -60,6 +62,9 @@ public class MonsterMaze extends SoloGame private Location _center; private HashMap _launched = new HashMap(); + + private static final int JUMP_POTION_AMPLIFIER = -10; + private int _potionMult = JUMP_POTION_AMPLIFIER; @SuppressWarnings("unchecked") public MonsterMaze(ArcadeManager manager) @@ -260,6 +265,36 @@ public class MonsterMaze extends SoloGame } } + @EventHandler + public void onDebug(PlayerCommandPreprocessEvent event) + { + if (!event.getPlayer().isOp()) + return; + + if (event.getMessage().toLowerCase().contains("/setmult ")) + { + event.setCancelled(true); + Integer mult = Integer.parseInt(event.getMessage().toLowerCase().replace("/setmult ", "")); + _potionMult = mult; + + for (Player pl : GetPlayers(true)) + { + Manager.GetCondition().Clean(pl); + } + } + } + + @EventHandler + public void onBreakJumper(InventoryClickEvent event) + { + if (!InProgress()) + return; + if (!IsAlive(event.getWhoClicked())) + return; + + event.setCancelled(true); + } + @EventHandler public void PotionEffects(UpdateEvent event) { @@ -276,7 +311,7 @@ public class MonsterMaze extends SoloGame else { if (!Manager.GetCondition().HasCondition(pl, ConditionType.JUMP, null)) - Manager.GetCondition().Factory().Jump("No jumping", pl, null, 9999999, 250, true, false, false); + Manager.GetCondition().Factory().Jump("No jumping", pl, null, 9999999, _potionMult, true, false, false); } // if (!Manager.GetCondition().HasCondition(pl, ConditionType.INVISIBILITY, null)) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/kits/KitJumper.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/kits/KitJumper.java index 22c4d31a7..32841361a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/kits/KitJumper.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/kits/KitJumper.java @@ -42,7 +42,7 @@ public class KitJumper extends ProgressingKit @Override public void GiveItems(Player player) { - player.getInventory().setItem(4, PLAYER_ITEMS[4]); - player.getInventory().setItem(8, PLAYER_ITEMS[8]); + player.getInventory().setItem(4, PLAYER_ITEMS[0]); + player.getInventory().setItem(8, PLAYER_ITEMS[1]); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/quiver/kits/KitEnchanter.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/quiver/kits/KitEnchanter.java index fcfce7584..1b38cfa92 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/quiver/kits/KitEnchanter.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/quiver/kits/KitEnchanter.java @@ -4,6 +4,7 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilServer; +import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemStackFactory; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.game.Game.GameState; @@ -11,6 +12,7 @@ import nautilus.game.arcade.kit.KitAvailability; import nautilus.game.arcade.kit.Perk; import nautilus.game.arcade.kit.ProgressingKit; import nautilus.game.arcade.kit.perks.PerkArrowRebound; + import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -31,7 +33,7 @@ public class KitEnchanter extends ProgressingKit private static final ItemStack IN_HAND = new ItemStack(Material.BOW); private static final ItemStack[] PLAYER_ITEMS = { - ItemStackFactory.Instance.CreateStack(Material.STONE_SWORD), + new ItemBuilder(Material.STONE_SWORD).setGlow(true).build(), ItemStackFactory.Instance.CreateStack(Material.BOW) }; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/quiver/kits/KitLeaper.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/quiver/kits/KitLeaper.java index c67f789fa..f12ed6a8d 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/quiver/kits/KitLeaper.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/quiver/kits/KitLeaper.java @@ -31,7 +31,7 @@ public class KitLeaper extends ProgressingKit private static final ItemStack IN_HAND = new ItemStack(Material.STONE_SWORD); private static final ItemStack[] PLAYER_ITEMS = { - ItemStackFactory.Instance.CreateStack(Material.IRON_AXE), + ItemStackFactory.Instance.CreateStack(Material.STONE_SWORD), ItemStackFactory.Instance.CreateStack(Material.BOW) }; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/Skywars.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/Skywars.java index 019d23f96..a99565c9a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/Skywars.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/Skywars.java @@ -674,8 +674,7 @@ public abstract class Skywars extends Game Player player = e.getPlayer(); if (is.getType() == Material.TNT) { - e.setCancelled(true); - _tntGen.pickup(player, e.getItem()); + e.setCancelled(_tntGen.pickup(player, e.getItem())); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/data/TNTGenerator.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/data/TNTGenerator.java index ebff5b18f..cd05c76e1 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/data/TNTGenerator.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/data/TNTGenerator.java @@ -76,23 +76,23 @@ public class TNTGenerator .trail(true).build()); } - public void pickup(Player player, Item item) + public boolean pickup(Player player, Item item) { if (_ent == null) - return; + return false; if (!_ent.equals(item)) - return; + return false; if (!Host.IsAlive(player)) - return; + return true; if (Host.Manager.isSpectator(player)) - return; + return true; GameTeam team = Host.GetTeam(player); if (team == null) - return; + return true; // Remove _ent.remove(); @@ -124,6 +124,7 @@ public class TNTGenerator player.playSound(player.getLocation(), Sound.ENDERDRAGON_HIT, 3F, 1F); Bukkit.getPluginManager().callEvent(new TNTPickupEvent(player)); + return true; } public String getScoreboardInfo() diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/SurvivalGames.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/SurvivalGames.java index b86b52cb3..f59a36d02 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/SurvivalGames.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/SurvivalGames.java @@ -37,6 +37,7 @@ import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.hanging.HangingBreakEvent; +import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.PrepareItemCraftEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; @@ -1936,6 +1937,15 @@ public abstract class SurvivalGames extends Game } } } + + @EventHandler + public void craftedItems(CraftItemEvent event) + { + if (UtilItem.isWeapon(event.getCurrentItem()) || UtilItem.isArmor(event.getCurrentItem())) + { + UtilItem.makeUnbreakable(event.getCurrentItem()); + } + } @EventHandler public void UpdateNametagVisibility(UpdateEvent event) 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 0999ecd4a..a6d564eea 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,14 +1,27 @@ package nautilus.game.arcade.game.games.uhc; import java.lang.reflect.Field; -import java.lang.reflect.Method; 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.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.NautHashMap; @@ -34,38 +47,35 @@ 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; import nautilus.game.arcade.events.GameStateChangeEvent; +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.Game.GameState; import nautilus.game.arcade.kit.Kit; import net.minecraft.server.v1_8_R3.BiomeCache; -import net.minecraft.server.v1_8_R3.ChunkCoordIntPair; import net.minecraft.server.v1_8_R3.ChunkProviderServer; -import net.minecraft.server.v1_8_R3.EmptyChunk; -import net.minecraft.server.v1_8_R3.ExceptionWorldConflict; +import net.minecraft.server.v1_8_R3.ChunkRegionLoader; import net.minecraft.server.v1_8_R3.FileIOThread; -import net.minecraft.server.v1_8_R3.IChunkLoader; import net.minecraft.server.v1_8_R3.IChunkProvider; -import net.minecraft.server.v1_8_R3.LongHashMap; import net.minecraft.server.v1_8_R3.MinecraftServer; import net.minecraft.server.v1_8_R3.NBTTagCompound; -import net.minecraft.server.v1_8_R3.World; import net.minecraft.server.v1_8_R3.WorldChunkManager; +import net.minecraft.server.v1_8_R3.WorldServer; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.Chunk; 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.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_8_R3.generator.NormalChunkGenerator; import org.bukkit.craftbukkit.v1_8_R3.util.LongHash; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Entity; @@ -74,24 +84,27 @@ 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.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.PlayerDeathEvent; import org.bukkit.event.inventory.PrepareItemCraftEvent; -import org.bukkit.event.player.PlayerChangedWorldEvent; +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.PlayerJoinEvent; 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; @@ -107,10 +120,16 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; -import org.spigotmc.WatchdogThread; +import org.spigotmc.AsyncCatcher; -public class UHC extends TeamGame +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; + + // The number of threads to use for reading chunks from disk + private static final int THREADS_FOR_CHUNK_LOADING = 4; + private NautHashMap _teamReqs = new NautHashMap(); private NautHashMap _deathTime = new NautHashMap(); @@ -145,6 +164,14 @@ public class UHC extends TeamGame 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); @@ -157,7 +184,7 @@ public class UHC extends TeamGame DamageDealt ); } - + public UHC(ArcadeManager manager, GameType type) { super(manager, type, @@ -213,8 +240,6 @@ public class UHC extends TeamGame this.WorldBoundaryKill = false; - this.TickPerTeleport = 3; - this.GemBoosterEnabled = false; this.GemDoubleEnabled = false; this.GemHunterEnabled = false; @@ -243,6 +268,8 @@ public class UHC extends TeamGame _createTime = System.currentTimeMillis(); _serverTime = Utility.currentTimeMillis(); + + NCPHookManager.addHook(CheckType.ALL, this); } @Override @@ -274,23 +301,6 @@ public class UHC extends TeamGame border.setWarningTime(-99); } - @EventHandler - public void onDamage(CustomDamageEvent event) - { - if (!IsLive()) - return; - - if (UtilTime.elapsed(getGameLiveTime(), 20000)) - return; - - if (!(event.GetDamageeEntity() instanceof Player)) - return; - - event.SetCancelled("Spawn Invincibility"); - event.GetDamageeEntity().setFireTicks(0); - - } - @EventHandler public void onSecond(UpdateEvent event) { @@ -479,6 +489,333 @@ public class UHC extends TeamGame } TimingManager.stop("UHC Spawn Generation"); + + Location spawn = GetRandomSpawn(WorldData.World.getSpawnLocation()); + WorldData.World.setSpawnLocation(spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ()); + + WorldServer worldServer = ((CraftWorld) WorldData.World).getHandle(); + + // Update view distance + worldServer.spigotConfig.viewDistance = VIEW_DISTANCE; + worldServer.getPlayerChunkMap().a(VIEW_DISTANCE); + + if (Runtime.getRuntime().maxMemory() / 1024 / 1024 < 2048) + { + Announce(C.cGreen + C.Bold + "Skipping spawn pregeneration", false); + 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(); } @EventHandler @@ -675,7 +1012,7 @@ public class UHC extends TeamGame while (!stopGen) { long now = System.currentTimeMillis(); - if ((now - last) >= 4000) + if ((now - last) >= 10 * 1000) { Announce(C.cGreen + C.Bold + "Generating Map: " + C.cWhite + getMapLoadETA() + " Remaining...", false); last = now; @@ -745,6 +1082,170 @@ public class UHC extends TeamGame }, "WorldGen Thread").start(); } + @EventHandler + public void on(ChunkUnloadEvent event) + { + if (IsLive()) + return; + event.setCancelled(true); + } + + private volatile boolean _isTeleporting = false; + + @EventHandler + public void on(ChunkPreLoadEvent event) + { + if (_isTeleporting) + { + System.out.println("WARNING: TRIED TO LOAD CHUNK WHILE TELEPORTING: " + event.getX() + " " + event.getZ()); + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void on(PlayerKickEvent event) + { + // Don't kick players while teleporting. Probably NCP trying to kick for fly or something + if (_isTeleporting) + { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.LOW) + public void PlayerPrepare(GameStateChangeEvent event) + { + final Game game = event.GetGame(); + + if (event.GetState() != GameState.Prepare) + return; + + _isTeleporting = true; + + List players = game.GetPlayers(true); + + Location zero = WorldData.World.getSpawnLocation(); + + for (Player player : players) + { + player.teleport(zero); + + // Heal + player.setHealth(player.getMaxHealth()); + // Resistance and regen + player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 30 * 20, 128), true); + 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); + + _totalPlayers = players.size(); + + Map teleportedLocations = new HashMap<>(); + + AtomicInteger id = new AtomicInteger(); + id.set(UtilServer.getServer().getScheduler().runTaskTimer(Manager.getPlugin(), () -> + { + _teleportedPlayers++; + if (_teleportedPlayers >= players.size()) + { + Manager.runSyncLater(() -> + { + try + { + for (Player player : players) + { + GameTeam team = game.GetTeam(player); + if (team != null) + { + if (teleportedLocations.get(player.getUniqueId()) != null) + { + team.SpawnTeleport(player, teleportedLocations.get(player.getUniqueId())); + } + } + + // Heal + player.setHealth(player.getMaxHealth()); + // Resistance and regen + player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 30 * 20, 128), true); + player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 30 * 20, 128), true); + } + } + finally + { + game.AnnounceGame(); + game.StartPrepareCountdown(); + + //Event + GamePrepareCountdownCommence gamePrepareCountdownCommence = new GamePrepareCountdownCommence(game); + UtilServer.getServer().getPluginManager().callEvent(gamePrepareCountdownCommence); + + _isTeleporting = false; + + Manager.runSyncLater(() -> + { + for (Player player : players) + { + 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; + }, 10 * 20L); + } + }, 3 * 20L); + Bukkit.getServer().getScheduler().cancelTask(id.get()); + return; + } + + Player player = players.get(_teleportedPlayers); + GameTeam team = game.GetTeam(player); + + // This could happen if the player left (and rejoined) while teleporting + // Team maps based on player as a key + if (team != null) + { + // Save where they teleported + teleportedLocations.put(player.getUniqueId(), team.SpawnTeleport(player)); + + // Update scoreboard + _scoreObj.getScore(player).setScore((int) player.getMaxHealth()); + + game.addPlayerInTime(player); + + Manager.Clear(player); + UtilInv.Clear(player); + + // Heal + player.setHealth(player.getMaxHealth()); + // Resistance and regen + player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 30 * 20, 128), true); + player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 30 * 20, 128), true); + + + game.ValidateKit(player, game.GetTeam(player)); + + if (game.GetKit(player) != null) + game.GetKit(player).ApplyKit(player); + + //Event + PlayerPrepareTeleportEvent playerStateEvent = new PlayerPrepareTeleportEvent(game, player); + UtilServer.getServer().getPluginManager().callEvent(playerStateEvent); + } + }, 4 * 20L, 4L).getTaskId()); + + //Spectators Move + for (Player player : UtilServer.getPlayers()) + { + if (Manager.GetGame().IsAlive(player)) + continue; + + Manager.addSpectator(player, true); + } + } + @EventHandler public void WorldBoundaryYLimit(BlockPlaceEvent event) { @@ -758,10 +1259,14 @@ public class UHC extends TeamGame public Location GetRandomSpawn(Location around) { + // Sometimes getting a random spawn at 0,0 hangs forever + int tries = 0; + Location loc = null; while (loc == null) { + tries++; Block block = null; // Get Team Location @@ -776,8 +1281,8 @@ public class UHC extends TeamGame // Get Radius Location else { - block = UtilBlock.getHighest(WorldData.World, around.getBlockX() - 4 + UtilMath.r(8), around.getBlockZ() - 4 - + UtilMath.r(8), null); + block = UtilBlock.getHighest(WorldData.World, around.getBlockX() - 4 + UtilMath.r(tries < 10 ? 8 : 30), around.getBlockZ() - 4 + + UtilMath.r(tries < 10 ? 8 : 30), null); } // Check Validity @@ -786,6 +1291,9 @@ public class UHC extends TeamGame if (block.getRelative(BlockFace.DOWN).isLiquid()) continue; + if (block.getRelative(BlockFace.DOWN).getType() == Material.AIR) + continue; + // Suffocated if (block.getType() != Material.AIR || block.getRelative(BlockFace.UP).getType() != Material.AIR) continue; @@ -1273,8 +1781,18 @@ public class UHC extends TeamGame } Scoreboard.WriteBlank(); - Scoreboard.Write(C.cYellow + C.Bold + "Time"); - Scoreboard.Write(UtilTime.MakeStr(System.currentTimeMillis() - GetStateTime())); + if (GetState() == GameState.Prepare) + { + Scoreboard.Write(C.cYellow + C.Bold + "Status"); + int players = _teleportedPlayers + 1; + if (players > _totalPlayers) players = _totalPlayers; + Scoreboard.Write("Teleporting Players (" + players + "/" + _totalPlayers + ")"); + } + else + { + Scoreboard.Write(C.cYellow + C.Bold + "Time"); + Scoreboard.Write(UtilTime.MakeStr(System.currentTimeMillis() - GetStateTime())); + } Scoreboard.WriteBlank(); Scoreboard.Write(C.cYellow + C.Bold + "Borders"); @@ -1584,8 +2102,8 @@ public class UHC extends TeamGame if (visible) break; } - - if(visible) + + if (visible) setOreType(vein); // Remove Vein @@ -1609,15 +2127,15 @@ public class UHC extends TeamGame } } } - + public void setOreType(ArrayList blocks) { - + } public boolean isMapLoaded() { - return _mapLoaded; + return _mapLoaded && areSpawnsGenerated(); } public String getMapLoadPercent() @@ -1625,6 +2143,23 @@ public class UHC extends TeamGame 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; @@ -1768,4 +2303,26 @@ public class UHC extends TeamGame 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/wizards/Wizards.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/Wizards.java index 9ab574b9b..6ab2f5018 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/Wizards.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/Wizards.java @@ -18,6 +18,7 @@ import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilParticle.ParticleType; @@ -955,7 +956,10 @@ public class Wizards extends SoloGame containsSpell = true; UtilInv.addDullEnchantment(item); } - + + if (UtilItem.isArmor(item)) + UtilItem.makeUnbreakable(item); + inv.setItem(UtilMath.r(inv.getSize()), item); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkBomber.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkBomber.java index 95ca01a94..98bb50f9d 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkBomber.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkBomber.java @@ -127,6 +127,15 @@ public class PerkBomber extends Perk UtilPlayer.message(event.getPlayer(), F.main(GetName(), "You cannot drop " + F.item("Throwing TNT") + ".")); } + @EventHandler (ignoreCancelled = true) + public void on(BlockPlaceEvent event) + { + if (!isThrowingTnt(event.getItemInHand())) + return; + event.setCancelled(true); + UtilPlayer.message(event.getPlayer(), F.main(GetName(), "You cannot place " + F.item("Throwing TNT") + ".")); + } + @EventHandler public void TNTDeathRemove(PlayerDeathEvent event) { @@ -139,6 +148,7 @@ public class PerkBomber extends Perk int oldAmount = _tntCount.get(event.getEntity()).get(); if (oldAmount < remove.size()) { + // fixme If you die with someone else's tnt, then this will occur System.out.println("Strange.... expected " + oldAmount + " of tnt for " + event.getEntity().getName() + " but removed " + remove.size() + " instead"); _tntCount.get(event.getEntity()).set(0); } 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 f971ae57a..035ffe685 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 @@ -6,6 +6,7 @@ import org.bukkit.entity.Horse; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; +import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerInteractEvent; import mineplex.core.common.util.C; @@ -18,6 +19,7 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.recharge.Recharge; import nautilus.game.arcade.kit.Perk; import nautilus.game.arcade.kit.perks.event.PerkLeapEvent; +import org.bukkit.event.player.PlayerQuitEvent; public class PerkLeap extends Perk { @@ -125,4 +127,22 @@ public class PerkLeap extends Perk PerkLeapEvent leapEvent = new PerkLeapEvent(player); UtilServer.getServer().getPluginManager().callEvent(leapEvent); } + + @EventHandler + public void removeDataOnQuit(PlayerQuitEvent event) + { + _uses.remove(event.getPlayer().getName()); + } + + @EventHandler + public void removeDataOnDeath(PlayerDeathEvent event) + { + _uses.remove(event.getEntity().getName()); + } + + @Override + public void unregisteredEvents() + { + _uses.clear(); + } } 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 220745fb7..ae8e4157e 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 @@ -1048,7 +1048,7 @@ public class GameLobbyManager implements Listener { if (Manager.GetGame() instanceof UHC && !((UHC)Manager.GetGame()).isMapLoaded()) { - objective.setDisplayName(((UHC)Manager.GetGame()).getMapLoadPercent() + " " + (_colorTick ? ChatColor.GREEN : ChatColor.YELLOW) + "§l" + "Generating Map"); + objective.setDisplayName(((UHC) Manager.GetGame()).getObjectiveName(_colorTick)); } else { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java index b57c40277..cc517cbf9 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameManager.java @@ -741,6 +741,10 @@ public class GameManager implements Listener if (event.GetState() != GameState.Prepare) return; + // Sir, I'll handle this. + if (game instanceof UHC) + return; + final ArrayList players = game.GetPlayers(true); //Prepare Players diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GamePlayerManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GamePlayerManager.java index 899786190..cef0c62ab 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GamePlayerManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GamePlayerManager.java @@ -1,12 +1,19 @@ package nautilus.game.arcade.managers; +import java.util.ArrayList; + import mineplex.core.common.Rank; import mineplex.core.common.util.C; import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilTabTitle; +import mineplex.core.common.util.UtilTime; import mineplex.core.recharge.Recharge; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; +import mineplex.minecraft.game.core.condition.Condition.ConditionType; import mineplex.minecraft.game.core.damage.CustomDamageEvent; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; @@ -16,6 +23,8 @@ import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.ProgressingKit; + +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.LivingEntity; @@ -32,11 +41,12 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.scheduler.BukkitRunnable; -import java.util.ArrayList; - public class GamePlayerManager implements Listener { ArcadeManager Manager; + private static final long PLAYER_VISIBILITY_REFRESH_RATE = 30000; + private static final int VIEW_DISTANCE_BLOCK_VALUE = 8; + private long _lastVisibilityRefresh = 0; public GamePlayerManager(ArcadeManager manager) { @@ -44,6 +54,34 @@ public class GamePlayerManager implements Listener Manager.getPluginManager().registerEvents(this, Manager.getPlugin()); } + + @EventHandler + public void onRefreshVisibility(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + return; + if (UtilTime.elapsed(_lastVisibilityRefresh, PLAYER_VISIBILITY_REFRESH_RATE)) + { + _lastVisibilityRefresh = System.currentTimeMillis(); + if (Manager.GetGame() == null) + { + return; + } + for (Player player : Manager.GetGame().GetPlayers(true)) + { + if (!Manager.GetCondition().HasCondition(player, ConditionType.INVISIBILITY) && Manager.GetGame().IsAlive(player) && !UtilPlayer.isSpectator(player)) + { + for (Player viewer : Bukkit.getOnlinePlayers()) + { + if (UtilMath.offset2d(viewer, player) <= (Bukkit.getViewDistance() * VIEW_DISTANCE_BLOCK_VALUE)) + { + viewer.showPlayer(player); + } + } + } + } + } + } @EventHandler(priority = EventPriority.HIGH) public void PlayerDeath(CombatDeathEvent event) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/scoreboard/GameScoreboard.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/scoreboard/GameScoreboard.java index ce8c403eb..6500f6308 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/scoreboard/GameScoreboard.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/scoreboard/GameScoreboard.java @@ -250,7 +250,7 @@ public class GameScoreboard if (i >= _chars.length) break; - String str = ChatColor.COLOR_CHAR + "" + _chars[i]; + String str = ChatColor.COLOR_CHAR + "" + _chars[i] + C.Reset; Score score = GetObjectiveSide().getScore(str);