diff --git a/.gitignore b/.gitignore index 1f2440b8d..81e05ca00 100644 --- a/.gitignore +++ b/.gitignore @@ -60,4 +60,9 @@ target/ # IntelliJ IDEA Files *.iml -.idea/ \ No newline at end of file +.idea/ + +# Eclipse +.settings/ +.classpath +.project diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java index 7bda731aa..611170f37 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java @@ -464,6 +464,11 @@ public class UtilBlock return getHighest(world, x, z, null); } + public static Block getHighest(World world, Location location) + { + return getHighest(world, location.getBlockX(), location.getBlockZ(), null); + } + public static Block getHighest(World world, int x, int z, HashSet ignore) { Block block = world.getHighestBlockAt(x, z); diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilWorld.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilWorld.java index c2a3c40ab..321ba7ee9 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilWorld.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilWorld.java @@ -1,15 +1,19 @@ package mineplex.core.common.util; import java.util.Collection; - +import java.util.List; +import java.util.function.Predicate; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.util.Vector; +import com.google.common.collect.Lists; + public class UtilWorld { public static World getWorld(String world) @@ -194,4 +198,15 @@ public class UtilWorld return vec.toLocation(world); } + + private static List branch(Location origin) + { + return Lists.newArrayList(origin.getBlock(), + origin.getBlock().getRelative(BlockFace.DOWN), + origin.getBlock().getRelative(BlockFace.UP), + origin.getBlock().getRelative(BlockFace.NORTH), + origin.getBlock().getRelative(BlockFace.EAST), + origin.getBlock().getRelative(BlockFace.SOUTH), + origin.getBlock().getRelative(BlockFace.WEST)); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java index 47ae28025..4b53ed051 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java @@ -67,6 +67,7 @@ public class ClanInfo private HashMap _warOut = new HashMap(); // Temporary + private NautHashMap _recentlyLeft = new NautHashMap<>(); private NautHashMap _inviteeMap = new NautHashMap(); private NautHashMap _inviterMap = new NautHashMap(); private List _onlinePlayers = new ArrayList(); @@ -76,6 +77,7 @@ public class ClanInfo public ClansManager Clans; private BedStatus _bedStatus = null; + public ClanInfo(ClansManager clans, ClanToken token) { @@ -800,4 +802,9 @@ public class ClanInfo { return _bedStatus == BedStatus.DESTROYED ? C.cRed + "Destroyed" : (_bedStatus == BedStatus.DOESNT_EXIST ? C.cWhite + "None" : (_bedStatus == BedStatus.EXISTS_AND_OBSTRUCTED ? C.cRed + "Obstructed" : (_bedStatus == BedStatus.EXISTS_AND_UNOBSTRUCTED ? C.cGreen + UtilWorld.locToStrClean(_home) : "N/A"))); } + + public void left(String name) + { + _recentlyLeft.put(name, System.currentTimeMillis()); + } } 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 c3b073b66..e088c9185 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 @@ -39,7 +39,7 @@ import mineplex.core.account.CoreClientManager; import mineplex.core.achievement.AchievementManager; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.chat.Chat; -import mineplex.core.chat.MessageData; +import mineplex.core.common.Pair; import mineplex.core.common.Rank; import mineplex.core.common.util.C; import mineplex.core.common.util.F; @@ -75,7 +75,6 @@ import mineplex.game.clans.clans.commands.ClanManagementCommand; import mineplex.game.clans.clans.commands.ClansAllyChatCommand; import mineplex.game.clans.clans.commands.ClansChatCommand; import mineplex.game.clans.clans.commands.ClansCommand; -import mineplex.game.clans.clans.commands.ClansLoginManager; import mineplex.game.clans.clans.commands.KillCommand; import mineplex.game.clans.clans.commands.MapCommand; import mineplex.game.clans.clans.commands.RegionsCommand; @@ -97,6 +96,7 @@ import mineplex.game.clans.clans.stuck.StuckManager; import mineplex.game.clans.clans.supplyDrop.SupplyDropManager; import mineplex.game.clans.clans.tntGenerator.TntGeneratorManager; import mineplex.game.clans.clans.war.WarManager; +import mineplex.game.clans.clans.warpoints.WarPointEvasion; import mineplex.game.clans.clans.worldevent.WorldEventManager; import mineplex.game.clans.core.ClanDeleteCommand; import mineplex.game.clans.core.ClanLoadCommand; @@ -199,6 +199,7 @@ public class ClansManager extends MiniClientPluginimplements IRelati // private NautHashMap _clanMemberNameMap = new // NautHashMap(); private NautHashMap _clanMemberUuidMap = new NautHashMap(); + private NautHashMap> _clanMemberLeftMap = new NautHashMap<>(); private NautHashMap _claimMap = new NautHashMap(); private NautHashMap _unclaimMap = new NautHashMap(); @@ -257,6 +258,8 @@ public class ClansManager extends MiniClientPluginimplements IRelati _explosion = new Explosion(plugin, blockRestore); + new WarPointEvasion(plugin); + // new ClansLoginManager(getPlugin(), clientManager, _serverName); _clanShop = new ClanShop(this, clientManager, donationManager); @@ -584,6 +587,13 @@ public class ClansManager extends MiniClientPluginimplements IRelati { player.setOp(true); } + if(player.getInventory().getHelmet() != null) { //Reset helmet to fix 1 damage bug + ItemStack helmet = player.getInventory().getHelmet().clone(); + player.getInventory().setHelmet(null); + runSyncLater(() -> { + player.getInventory().setHelmet(helmet); + }, 5L); + } } @EventHandler @@ -1136,4 +1146,19 @@ public class ClansManager extends MiniClientPluginimplements IRelati ClansPlayerDeathEvent clansPlayerDeathEvent = new ClansPlayerDeathEvent(event, playerClan, killerClan); Bukkit.getServer().getPluginManager().callEvent(clansPlayerDeathEvent); } + + public void justLeft(UUID uniqueId, ClanInfo clan) + { + _clanMemberLeftMap.put(uniqueId, Pair.create(clan, System.currentTimeMillis())); + } + + public Pair leftRecently(UUID uniqueId, long time) + { + if (_clanMemberLeftMap.containsKey(uniqueId) && (System.currentTimeMillis() - _clanMemberLeftMap.get(uniqueId).getRight()) <= time) + { + return Pair.create(_clanMemberLeftMap.get(uniqueId).getLeft(), time - (System.currentTimeMillis() - _clanMemberLeftMap.get(uniqueId).getRight())); + } + + return null; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java index 6a1356d8c..4e466128c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java @@ -632,6 +632,8 @@ public class ClansUtility // Inform Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You left " + F.elem("Clan " + clan.getName()) + ".")); clan.inform(F.name(caller.getName()) + " has left your Clan.", null); + + clan.left(caller.getName()); } }); } @@ -677,8 +679,8 @@ public class ClansUtility if (!data) { Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "There was an error processing your request. Try again later")); - - }else + } + else { Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You disbanded your Clan.")); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java index cbc4c02dc..536c29993 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java @@ -1,10 +1,17 @@ package mineplex.game.clans.clans.commands; +import java.util.Collections; +import java.util.List; + import org.bukkit.Bukkit; +import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import com.google.common.collect.Lists; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; @@ -13,6 +20,7 @@ import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilInput; +import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; @@ -30,6 +38,7 @@ import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClientClan; import mineplex.game.clans.clans.event.ClanJoinEvent; import mineplex.game.clans.clans.event.ClansCommandExecutedEvent; +import mineplex.game.clans.core.repository.ClanTerritory; import net.minecraft.server.v1_8_R3.EnumDirection; public class ClansCommand extends CommandBase @@ -105,6 +114,8 @@ public class ClansCommand extends CommandBase else if (args[0].equalsIgnoreCase("sethome")) homeSet(caller); + else if (args[0].equalsIgnoreCase("stuck")) + stuck(caller); /* * else if (args[0].equalsIgnoreCase("enemy") || args[0].equals("e")) @@ -211,6 +222,8 @@ public class ClansCommand extends CommandBase _manager.getTutorials().sendTutorialMsg(caller, F.help("/c map ", "View Clan Map", Rank.ALL)); _manager.getTutorials().sendTutorialMsg(caller, F.help("/cc (Message)", "Clan Chat (Toggle)", Rank.ALL)); + _manager.getTutorials().sendTutorialMsg(caller, F.help("/c stuck", "Teleports you to the nearest Wilderness location", Rank.ALL)); + _manager.getTutorials().sendTutorialMsg(caller, F.help("/c promote ", "Promote Player in Clan", Rank.MODERATOR)); _manager.getTutorials().sendTutorialMsg(caller, F.help("/c demote ", "Demote Player in Clan", Rank.MODERATOR)); @@ -242,6 +255,12 @@ public class ClansCommand extends CommandBase return; } + if (Plugin.leftRecently(caller.getUniqueId(), 20 * 60 * 1000) != null) + { + _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot create a Clan for " + C.mTime + UtilTime.MakeStr(Plugin.leftRecently(caller.getUniqueId(), 20 * 60 * 1000).getRight()) + C.mBody + ".")); + return; + } + /* * TODO if (!client.canJoin()) { _manager.getTutorials().sendTutorialMsg(caller, * F.main("Clans", "You cannot join a Clan for " + C.mTime + @@ -344,6 +363,83 @@ public class ClansCommand extends CommandBase Plugin.getClanUtility().invite(caller, clan, target); } + public void stuck(final Player caller) + { + ClanTerritory territory = Plugin.getClanUtility().getClaim(caller.getLocation()); + + String clanName = Plugin.getClanUtility().getClanByPlayer(caller) == null ? null : Plugin.getClanUtility().getClanByPlayer(caller).getName(); + + if (territory == null || territory.Safe || territory.Owner.equals(clanName)) + { + _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must be in another Clan's territory to use this.")); + return; + } + + DelayedTask.Instance.doDelay(caller, "Wilderness Teleport", new Callback() { + public void run(DelayedTaskClient player) + { + // Do + + Location loc = getWildLoc(player.getPlayer().getLocation()); + + if (loc == null) + { + _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Error whilst finding location to teleport to.")); + return; + } + + player.getPlayer().teleport(loc); + + // Inform + _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You have been teleported to the Wilderness.")); + } + }, new Callback() { + public void run(DelayedTaskClient client) + { + UtilTextMiddle.display("", "Teleporting to Wilderness in " + F.elem(UtilTime.MakeStr(Math.max(0, client.getTimeLeft("Wilderness Teleport")))), 0, 5, 0, client.getPlayer()); + } + }, new Callback() { + public void run(DelayedTaskClient client) + { + UtilPlayer.message(client.getPlayer(), F.main("Clans", "Teleport has been cancelled due to movement.")); + } + }, 7 * 1000, false); + + } + + public Location getWildLoc(Location origin) + { + Chunk wildLoc = origin.getChunk(); + + List worldChunks = Lists.newArrayList(origin.getWorld().getLoadedChunks()); + + Collections.sort( + worldChunks, + (c1, c2) -> + (int) ((int) + origin.distance( + UtilBlock.getHighest(origin.getWorld(), + c1.getBlock(7, origin.getBlockY(), 7).getLocation() + ).getLocation()) + - + origin.distance( + UtilBlock.getHighest(origin.getWorld(), + c2.getBlock(7, origin.getBlockY(), 7).getLocation() + ).getLocation()) + ) + ); + + for (Chunk chunk : worldChunks) + { + if (Plugin.getClanUtility().getClaim(chunk) == null) + { + return chunk.getBlock(6, UtilBlock.getHighest(origin.getWorld(), chunk.getBlock(6, 0, 6).getLocation()).getY(), 6).getLocation(); + } + } + + return null; + } + public void join(final Player caller, String[] args) { if (Plugin.getClanMemberUuidMap().containsKey(caller.getUniqueId())) @@ -352,6 +448,12 @@ public class ClansCommand extends CommandBase return; } + if (Plugin.leftRecently(caller.getUniqueId(), 20 * 60 * 1000) != null) + { + _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot join a Clan for " + C.mTime + UtilTime.MakeStr(Plugin.leftRecently(caller.getUniqueId(), 20 * 60 * 1000).getRight()) + C.mBody + ".")); + return; + } + if (!Plugin.Get(caller).canJoin()) { _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot join a Clan for " + C.mTime + UtilTime.convertString(System.currentTimeMillis() - Plugin.Get(caller).getDelay(), 1, TimeUnit.FIT) + C.mBody + ".")); @@ -438,6 +540,8 @@ public class ClansCommand extends CommandBase // Inform _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You left " + F.elem("Clan " + clan.getName()) + ".")); clan.inform(F.name(caller.getName()) + " has left your Clan.", null); + + _manager.justLeft(caller.getUniqueId(), clan); } }); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarManager.java index 166693db2..39a1e2680 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/war/WarManager.java @@ -25,9 +25,9 @@ import mineplex.core.scoreboard.elements.ScoreboardElement; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; +import mineplex.game.clans.clans.ClanTips.TipType; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansUtility; -import mineplex.game.clans.clans.ClanTips.TipType; import mineplex.game.clans.clans.event.ClanDisbandedEvent; import mineplex.game.clans.clans.event.ClansPlayerDeathEvent; import mineplex.game.clans.clans.war.command.WarPointsCommand; @@ -38,7 +38,7 @@ import mineplex.game.clans.core.war.ClanWarData; public class WarManager extends MiniPlugin implements ScoreboardElement { public static final int WAR_START_POINTS = 0; - public static final int WAR_FINISH_POINTS = 20; + public static final int WAR_FINISH_POINTS = 25; public static final long INVADE_LENGTH = 60000L * 30; // 30 Minutes public static final long WAR_COOLDOWN = 60000L * 30; // 30 Minutes @@ -117,11 +117,18 @@ public class WarManager extends MiniPlugin implements ScoreboardElement @EventHandler public void handleDeath(final ClansPlayerDeathEvent event) { - if (event.getPlayer() != null && event.getPlayer().getClan() != null) + ClanInfo deathClan = event.getPlayer().getClan(); + + if (deathClan == null) + { + deathClan = _clansManager.leftRecently(event.getPlayer().getPlayer().getUniqueId(), 60000) == null ? deathClan : _clansManager.leftRecently(event.getPlayer().getPlayer().getUniqueId(), 60000).getLeft(); + } + + if (event.getPlayer() != null && deathClan != null) { if (event.getKiller() != null && event.getKiller().getClan() != null) { - final ClanInfo clan = event.getPlayer().getClan(); + final ClanInfo clan = deathClan; final ClanInfo killerClan = event.getKiller().getClan(); ClanWarData war = clan.getWarData(killerClan); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/warpoints/WarPointEvasion.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/warpoints/WarPointEvasion.java new file mode 100644 index 000000000..74f8aefba --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/warpoints/WarPointEvasion.java @@ -0,0 +1,52 @@ +package mineplex.game.clans.clans.warpoints; + +import com.google.common.collect.Maps; +import mineplex.core.MiniPlugin; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilTime; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.event.PlayerPreClaimTerritoryEvent; +import mineplex.game.clans.clans.event.PlayerUnClaimTerritoryEvent; +import org.bukkit.Chunk; +import org.bukkit.event.EventHandler; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.HashMap; + +public class WarPointEvasion extends MiniPlugin{ + private HashMap _cooldown; + private final long COOLDOWN_TIME = 1000 * 60 * 30; + + public WarPointEvasion(JavaPlugin plugin) { + super("WP Evasion", plugin); + _cooldown = Maps.newHashMap(); + } + + @EventHandler + public void updateCooldown(UpdateEvent event) { + if(!event.getType().equals(UpdateType.SEC)) return; + + _cooldown.keySet().stream().filter(chunk -> UtilTime.elapsed(_cooldown.get(chunk), COOLDOWN_TIME)).forEach(chunk -> _cooldown.remove(chunk)); + } + + @EventHandler + public void onClaim(PlayerPreClaimTerritoryEvent event) { + Chunk chunk = event.getClaimedChunk(); + if(_cooldown.containsKey(chunk)) { + event.setCancelled(true); + event.getClaimer().sendMessage(F.main("Clans", "You cannot claim this chunk for another " + UtilTime.convertString(System.currentTimeMillis() - _cooldown.get(chunk), 1, UtilTime.TimeUnit.MINUTES))); + } + } + + @EventHandler + public void onunClaim(PlayerUnClaimTerritoryEvent event) { + Chunk chunk = event.getUnClaimedChunk(); + if(_cooldown.containsKey(chunk)) { + // Error maybe? + _cooldown.remove(chunk); + } + _cooldown.put(chunk, System.currentTimeMillis()); + + } +} 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 b6505c23b..73242f881 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 @@ -130,7 +130,10 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable // TODO: Introduce configurable non-hardcoded values for generation // weights? _attributeWeights = new WeightSet(new Weight(3, 3), new Weight(20, 2), new Weight(77, 1)); - _typeWeights = new WeightSet(new Weight(10, ItemType.LEGENDARY), new Weight(45, ItemType.ARMOR), new Weight(23, ItemType.WEAPON), new Weight(22, ItemType.BOW)); + _typeWeights = new WeightSet(new Weight(6, ItemType.LEGENDARY), + new Weight(46, ItemType.ARMOR), + new Weight(25, ItemType.WEAPON), + new Weight(23, ItemType.BOW)); // Weapon-based attributes _weaponAttributes = new WeightSet>(FrostedAttribute.class, SharpAttribute.class, JaggedAttribute.class, HasteAttribute.class, FlamingAttribute.class, ConqueringAttribute.class); diff --git a/Plugins/plugin.xml b/Plugins/plugin.xml index 30937a766..c6ed635aa 100644 --- a/Plugins/plugin.xml +++ b/Plugins/plugin.xml @@ -44,7 +44,6 @@ - commons-codec:commons-codec com.google.code.gson:gson com.mineplex:spigot diff --git a/Plugins/pom.xml b/Plugins/pom.xml index 63426e9ae..49d4c7329 100644 --- a/Plugins/pom.xml +++ b/Plugins/pom.xml @@ -122,7 +122,7 @@ redis.clients jedis - 2.7.2 + 2.6.2 compile @@ -177,32 +177,28 @@ - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - net.md-5 - - scriptus - - - [0.3.1,) - - - describe - - - - - - - - - + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + net.md-5 + scriptus + [0.3.1,) + + describe + + + + + + + + +