Lots of changes, specifics:

Fixed clans having more than max energy.
Made /c home work from anywhere, 20 secs warmup, 30 secs in claimed territory.
/c <clan> now works with clans with 18+ players.
This commit is contained in:
NewGarbo 2015-12-18 11:13:38 +00:00
parent 4bf7e15055
commit 1840572c49
13 changed files with 313 additions and 45 deletions

View File

@ -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<DelayedTaskClient>
{
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<DelayedTaskClient> end, Callback<DelayedTaskClient> tick, Callback<DelayedTaskClient> 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));
}
}

View File

@ -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<String, Task> 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;
}
}

View File

@ -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<DelayedTaskClient> _end;
private Callback<DelayedTaskClient> _tick;
private Callback<DelayedTaskClient> _cancel;
private String _name;
private long _startTime;
private long _endTime;
private Location _startPos;
private boolean _allowMovement;
public Task(DelayedTaskClient client, String task, Callback<DelayedTaskClient> end, Callback<DelayedTaskClient> tick, Callback<DelayedTaskClient> 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<DelayedTaskClient> getEnd()
{
return _end;
}
public Callback<DelayedTaskClient> 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);
}
}
}

View File

@ -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<CoinTransactionToken> getCoinTransactions()

View File

@ -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);

View File

@ -507,6 +507,11 @@ public class ClanInfo
public int getEnergy()
{
if (_energy > getEnergyMax())
{
_energy = getEnergyMax();
}
return _energy;
}

View File

@ -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<ClansManager>
{
private ClansManager _manager;
public ClansCommand(ClansManager plugin)
{
super(plugin, Rank.ALL, "c", "clan", "clans", "factions");
@ -741,7 +741,7 @@ public class ClansCommand extends CommandBase<ClansManager>
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<ClansManager>
}
}
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<ClansManager>
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,15 +790,32 @@ public class ClansCommand extends CommandBase<ClansManager>
* }
*/
// 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;
}
DelayedTask.Instance.doDelay(caller, "Home Teleport", new Callback<DelayedTaskClient>() {
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<DelayedTaskClient>() {
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<DelayedTaskClient>() {
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<ClansManager>
}
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."));

View File

@ -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

View File

@ -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;

View File

@ -185,6 +185,14 @@ public class PvpTimer extends MiniClientPlugin<PvpTimerClient>
@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<Entity> iterator = event.GetTargets().iterator(); iterator.hasNext();)
{
Entity entity = iterator.next();

View File

@ -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);
}
}

View File

@ -89,7 +89,6 @@ public abstract class ClansShopPage<T extends ShopBase<ClansManager>> extends Sh
addShopItem(index, item, (byte) 0, displayName, 1);
}
public void addShopItem(int index, ClansShopItem item)
{
addShopItem(index, item, (byte) 0);