diff --git a/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTask.java b/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTask.java new file mode 100644 index 000000000..bd02855fe --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTask.java @@ -0,0 +1,65 @@ +package mineplex.core.delayedtask; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniClientPlugin; +import mineplex.core.common.util.Callback; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class DelayedTask extends MiniClientPlugin +{ + public static DelayedTask Instance; + + public DelayedTask(JavaPlugin plugin) + { + super("Delayed Task", plugin); + } + + public static void Initialize(JavaPlugin plugin) + { + Instance = new DelayedTask(plugin); + } + + public void doDelay(Player player, String task, Callback end, Callback tick, Callback cancel, long wait, boolean allowMovement) + { + Get(player).insert(new Task(Get(player), task, end, tick, cancel, wait, allowMovement)); + } + + @EventHandler + public void onUpdate(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + for (Player player : Bukkit.getOnlinePlayers()) + { + Get(player).tick(); + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) + { + Get(event.getPlayer()).cleanup(); + } + + @EventHandler + public void onPlayerKick(PlayerKickEvent event) + { + Get(event.getPlayer()).cleanup(); + } + + @Override + protected DelayedTaskClient AddPlayer(String player) + { + return new DelayedTaskClient(Bukkit.getPlayer(player)); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTaskClient.java b/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTaskClient.java new file mode 100644 index 000000000..636b48294 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTaskClient.java @@ -0,0 +1,82 @@ +package mineplex.core.delayedtask; + +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.entity.Player; + +public class DelayedTaskClient +{ + public Map Tasks = new HashMap<>(); + + private Player _player; + + public DelayedTaskClient(Player player) + { + _player = player; + } + + public void insert(Task task) + { + Tasks.put(task.getName(), task); + } + + public long getTimeLeft(String task) + { + if (!Tasks.containsKey(task)) return -1; + + return getEndTime(task) - System.currentTimeMillis(); + } + + public long getEndTime(String task) + { + if (!Tasks.containsKey(task)) return -1; + + return Tasks.get(task).getEndTime(); + } + + public long getStartTime(String task) + { + if (!Tasks.containsKey(task)) return -1; + + return Tasks.get(task).getStartTime(); + } + + public void cleanup() + { + if (Tasks == null) + { + Tasks = new HashMap<>(); + } + + Tasks.clear(); + Tasks = null; + } + + public void cleanup(String task) + { + Tasks.remove(task); + } + + public void tick() + { + if (Tasks == null) + { + Tasks = new HashMap<>(); + } + + for (Task task : Tasks.values()) + { + if (task.getTick() != null) + { + task.tick(); + } + } + } + + public Player getPlayer() + { + return _player; + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/Task.java b/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/Task.java new file mode 100644 index 000000000..37a1204cd --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/Task.java @@ -0,0 +1,95 @@ +package mineplex.core.delayedtask; + +import org.bukkit.Location; + +import mineplex.core.common.util.Callback; + +public class Task +{ + private DelayedTaskClient _client; + + private Callback _end; + private Callback _tick; + private Callback _cancel; + + private String _name; + + private long _startTime; + private long _endTime; + + private Location _startPos; + private boolean _allowMovement; + + public Task(DelayedTaskClient client, String task, Callback end, Callback tick, Callback cancel, long taskLength, boolean allowMovement) + { + _client = client; + + _name = task; + _end = end; + _tick = tick; + _cancel = cancel; + + _startPos = client.getPlayer().getLocation(); + + _allowMovement = allowMovement; + + _startTime = System.currentTimeMillis(); + _endTime = _startTime + taskLength; + } + + public String getName() + { + return _name; + } + + public Callback getEnd() + { + return _end; + } + + public Callback getTick() + { + return _tick; + } + + public long getEndTime() + { + return _endTime; + } + + public long getStartTime() + { + return _startTime; + } + + public void tick() + { + _tick.run(_client); + + if (!_allowMovement && _startPos.distance(_client.getPlayer().getLocation()) > 0.3) + { + if (_cancel != null) + { + _cancel.run(_client); + } + + if (_end != null) + { + _end.run(_client); + } + + _client.cleanup(_name); + return; + } + + if (System.currentTimeMillis() >= _endTime) + { + if (_end != null) + { + _end.run(_client); + } + + _client.cleanup(_name); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/Donor.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/Donor.java index 7145b3dab..c6e583835 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/Donor.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/Donor.java @@ -152,7 +152,11 @@ public class Donor public void addGold(int amount) { _gold = Math.max(0, _gold + amount); - + } + + public void setGold(int amount) + { + _gold = Math.max(0, amount); } public List getCoinTransactions() diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index d27dab663..92ae49d6c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -13,6 +13,7 @@ import mineplex.core.antihack.AntiHack; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.chat.Chat; import mineplex.core.command.CommandCenter; +import mineplex.core.delayedtask.DelayedTask; import mineplex.core.donation.DonationManager; import mineplex.core.explosion.Explosion; import mineplex.core.friend.FriendManager; @@ -76,6 +77,8 @@ public class Clans extends JavaPlugin ItemStackFactory.Initialize(this, false); + DelayedTask.Initialize(this); + Recharge.Initialize(this); VisibilityManager.Initialize(this); // new ProfileCacheManager(this); 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 5e82714fe..4a511c5f7 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 @@ -507,6 +507,11 @@ public class ClanInfo public int getEnergy() { + if (_energy > getEnergyMax()) + { + _energy = getEnergyMax(); + } + return _energy; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansPlayer.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansPlayer.java index 5b3e166ac..b18b93eff 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansPlayer.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansPlayer.java @@ -8,7 +8,7 @@ public class ClansPlayer private UUID _uuid; private ClanRole _role; private boolean _online; - + public ClansPlayer(String playerName, UUID uuid, ClanRole role) { _playerName = playerName; 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 3fda15789..0265b77d5 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 @@ -15,9 +15,12 @@ import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilInput; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.common.util.UtilWorld; +import mineplex.core.delayedtask.DelayedTask; +import mineplex.core.delayedtask.DelayedTaskClient; import mineplex.core.recharge.Recharge; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClanRole; @@ -27,14 +30,11 @@ 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.tutorials.Tutorial; -import mineplex.game.clans.tutorials.TutorialManager; import net.minecraft.server.v1_8_R3.EnumDirection; public class ClansCommand extends CommandBase { private ClansManager _manager; - public ClansCommand(ClansManager plugin) { super(plugin, Rank.ALL, "c", "clan", "clans", "factions"); @@ -741,7 +741,7 @@ public class ClansCommand extends CommandBase Plugin.getItemMapManager().setMap(caller); } - public void home(Player caller, String[] args) + public void home(final Player caller, String[] args) { if (args.length > 1) { @@ -752,7 +752,7 @@ public class ClansCommand extends CommandBase } } - ClanInfo clan = Plugin.getClanUtility().getClanByPlayer(caller); + final ClanInfo clan = Plugin.getClanUtility().getClanByPlayer(caller); if (clan == null) { @@ -772,18 +772,6 @@ public class ClansCommand extends CommandBase return; } - if (!Plugin.getClanUtility().isSafe(caller.getLocation())) - { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You can only use Clan Home from Spawn.")); - return; - } - - if (!Plugin.getClanUtility().isSpecial(caller.getLocation(), "Spawn")) - { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You can only use Clan Home from Spawn.")); - return; - } - Location home = clan.getHome(); if (!(home.getBlock().getType().equals(Material.BED_BLOCK) && home.add(0, 1, 0).getBlock().getType().equals(Material.AIR)) && home.add(0, 2, 0).getBlock().getType().equals(Material.AIR)) @@ -802,14 +790,31 @@ public class ClansCommand extends CommandBase * } */ - // if (!Recharge.Instance.use(caller, "Clans Teleport", "Clans - // Teleport", 300000, true, false, false, false)) return; + if (!Recharge.Instance.use(caller, "Home Teleport", 5 * 60 * 1000, true, false)) + { + return; + } - // Do - Plugin.getTeleport().TP(caller, clan.getHome().add(0, 1, 0)); - - // Inform - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You teleported to your Clan Home " + UtilWorld.locToStrClean(caller.getLocation()) + ".")); + DelayedTask.Instance.doDelay(caller, "Home Teleport", new Callback() { + public void run(DelayedTaskClient player) + { + // Do + Plugin.getTeleport().TP(caller, clan.getHome().add(0, 1, 0)); + + // Inform + _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You teleported to your Clan Home " + UtilWorld.locToStrClean(caller.getLocation()) + ".")); + } + }, new Callback() { + public void run(DelayedTaskClient client) + { + UtilTextMiddle.display("", "Teleporting to Clan Home in " + F.elem(UtilTime.MakeStr(Math.max(0, client.getTimeLeft("Home Teleport")))), 0, 5, 0); + } + }, new Callback() { + public void run(DelayedTaskClient client) + { + UtilPlayer.message(client.getPlayer(), F.main("Clans", "Teleport has been cancelled due to movement.")); + } + }, (Plugin.getClanUtility().getClaim(caller.getLocation()) != null ? 30 : 20) * 1000, false); } public void homeSet(Player caller) @@ -881,7 +886,9 @@ public class ClansCommand extends CommandBase } public void infoClan(Player caller, String search) - {System.out.println(search); + { + System.out.println(search); + if (search == null) { _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a search parameter.")); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansLoginManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansLoginManager.java index 1267209fb..1b8575083 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansLoginManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansLoginManager.java @@ -41,8 +41,8 @@ public class ClansLoginManager extends MiniPlugin implements ILoginProcessor { if (_queue.contains(event.getPlayer().getName()) && !event.getPlayer().isOp()) { - event.setKickMessage("This is not your Clans home server"); - event.setResult(PlayerLoginEvent.Result.KICK_OTHER); +// event.setKickMessage("This is not your Clans home server"); +// event.setResult(PlayerLoginEvent.Result.KICK_OTHER); } _queue.remove(event.getPlayer().getName()); @@ -50,18 +50,18 @@ public class ClansLoginManager extends MiniPlugin implements ILoginProcessor private void kickPlayer(final String playerName, final String homeServer) { - runSyncLater(new Runnable() - { - @Override - public void run() - { - Player player = UtilPlayer.searchExact(playerName); - if (player != null && player.isOnline() && !player.isOp()) - { - player.kickPlayer("This is not your home server. To play clans, connect to " + homeServer); - } - } - }, 20); +// runSyncLater(new Runnable() +// { +// @Override +// public void run() +// { +// Player player = UtilPlayer.searchExact(playerName); +// if (player != null && player.isOnline() && !player.isOp()) +// { +// player.kickPlayer("This is not your home server. To play clans, connect to " + homeServer); +// } +// } +// }, 20); } @Override 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 bc6240df7..dd417956c 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 @@ -31,7 +31,7 @@ public class ClanWhoPage extends ClanPageBase public ClanWhoPage(ClansManager plugin, ClanShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player, ClanInfo lookupClan, boolean showBackButton) { - super(plugin, shop, clientManager, donationManager, lookupClan.getName(), player, 36); + super(plugin, shop, clientManager, donationManager, lookupClan.getName(), player, 45); _lookupClan = lookupClan; _showBackButton = showBackButton; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/PvpTimer.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/PvpTimer.java index b9e38b20b..c44481841 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/PvpTimer.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/PvpTimer.java @@ -185,6 +185,14 @@ public class PvpTimer extends MiniClientPlugin @EventHandler public void onSkill(SkillTriggerEvent event) { + if (event.GetTargets() != null + && event.GetTargets().size() == 1 + && event.GetTargets().get(0) instanceof Player + && hasTimer((Player) event.GetTargets().get(0))) + { + event.SetCancelled(true); + } + for (Iterator iterator = event.GetTargets().iterator(); iterator.hasNext();) { Entity entity = iterator.next(); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/GiantsBroadsword.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/GiantsBroadsword.java index d28524af0..256bae574 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/GiantsBroadsword.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/GiantsBroadsword.java @@ -62,7 +62,7 @@ public class GiantsBroadsword extends LegendaryItem private void buffPlayer(Player player) { - grantPotionEffect(player, PotionEffectType.SLOW, 20, 10); - grantPotionEffect(player, PotionEffectType.REGENERATION, 1, 10); + grantPotionEffect(player, PotionEffectType.SLOW, 40, 10); + grantPotionEffect(player, PotionEffectType.REGENERATION, 40, 10); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ClansShopPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ClansShopPage.java index 78169ea47..459a18701 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ClansShopPage.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ClansShopPage.java @@ -89,7 +89,6 @@ public abstract class ClansShopPage> extends Sh addShopItem(index, item, (byte) 0, displayName, 1); } - public void addShopItem(int index, ClansShopItem item) { addShopItem(index, item, (byte) 0);