mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-26 07:54:41 +02:00
Try to be a little more sensible with stored cooldowns.
This commit is contained in:
@@ -7,7 +7,6 @@ import com.earth2me.essentials.api.IUser;
|
||||
import com.earth2me.essentials.commands.NoChargeException;
|
||||
import com.earth2me.essentials.settings.Kit;
|
||||
import com.earth2me.essentials.storage.AsyncStorageObjectHolder;
|
||||
import com.earth2me.essentials.user.UserData;
|
||||
import com.earth2me.essentials.user.UserData.TimestampType;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import java.io.File;
|
||||
@@ -18,8 +17,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class Kits extends AsyncStorageObjectHolder<com.earth2me.essentials.settings.Kits> implements IKits
|
||||
{
|
||||
|
||||
|
||||
public Kits(final IEssentials ess)
|
||||
{
|
||||
super(ess, com.earth2me.essentials.settings.Kits.class);
|
||||
@@ -66,8 +63,8 @@ public class Kits extends AsyncStorageObjectHolder<com.earth2me.essentials.setti
|
||||
@Override
|
||||
public void sendKit(IUser user, Kit kit) throws Exception
|
||||
{
|
||||
final List<ItemStack> itemList = kit.getItems();
|
||||
user.giveItems(itemList, true);
|
||||
final List<ItemStack> itemList = kit.getItems();
|
||||
user.giveItems(itemList, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,42 +90,49 @@ public class Kits extends AsyncStorageObjectHolder<com.earth2me.essentials.setti
|
||||
{
|
||||
return getData().getKits().isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void finishRead()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishWrite()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void checkTime(final IUser user, Kit kit) throws NoChargeException
|
||||
{
|
||||
final Calendar time = new GregorianCalendar();
|
||||
// Take the current time, and remove the delay from it.
|
||||
final double delay = kit.getDelay();
|
||||
final Calendar c = new GregorianCalendar();
|
||||
c.add(Calendar.SECOND, -(int)delay);
|
||||
c.add(Calendar.MILLISECOND, -(int)((delay * 1000.0) % 1000.0));
|
||||
final Calendar earliestTime = new GregorianCalendar();
|
||||
earliestTime.add(Calendar.SECOND, -(int)delay);
|
||||
earliestTime.add(Calendar.MILLISECOND, -(int)((delay * 1000.0) % 1000.0));
|
||||
|
||||
final long mintime = c.getTimeInMillis();
|
||||
// This value contains the most recent time a kit could have been used that would allow another use.
|
||||
|
||||
//todo multiple kit times
|
||||
final long earliestLong = earliestTime.getTimeInMillis();
|
||||
|
||||
// When was the last kit used?
|
||||
final Long lastTime = user.getTimestamp(TimestampType.KIT);
|
||||
if (lastTime == null || lastTime < mintime)
|
||||
if (lastTime == null || lastTime < earliestLong)
|
||||
{
|
||||
final Calendar now = new GregorianCalendar();
|
||||
user.setTimestamp(TimestampType.KIT, now.getTimeInMillis());
|
||||
user.setTimestamp(TimestampType.KIT, time.getTimeInMillis());
|
||||
}
|
||||
else if (lastTime > time.getTimeInMillis())
|
||||
{
|
||||
// This is to make sure time didn't get messed up on last kit use.
|
||||
// If this happens, let's give the user the benifit of the doubt.
|
||||
user.setTimestamp(TimestampType.KIT, time.getTimeInMillis());
|
||||
}
|
||||
else
|
||||
{
|
||||
final Calendar future = new GregorianCalendar();
|
||||
future.setTimeInMillis(lastTime);
|
||||
future.add(Calendar.SECOND, (int)delay);
|
||||
future.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0));
|
||||
user.sendMessage(_("kitTimed", DateUtil.formatDateDiff(future.getTimeInMillis())));
|
||||
time.setTimeInMillis(lastTime);
|
||||
time.add(Calendar.SECOND, (int)delay);
|
||||
time.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0));
|
||||
user.sendMessage(_("kitTimed", DateUtil.formatDateDiff(time.getTimeInMillis())));
|
||||
throw new NoChargeException();
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,10 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.economy.Trade;
|
||||
import com.earth2me.essentials.utils.Util;
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.api.IEssentials;
|
||||
import com.earth2me.essentials.api.ITeleport;
|
||||
import com.earth2me.essentials.api.IUser;
|
||||
import com.earth2me.essentials.economy.Trade;
|
||||
import com.earth2me.essentials.permissions.Permissions;
|
||||
import com.earth2me.essentials.user.CooldownException;
|
||||
import com.earth2me.essentials.user.UserData.TimestampType;
|
||||
@@ -137,6 +136,7 @@ public class Teleport implements Runnable, ITeleport
|
||||
this.ess = ess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void respawn(final Trade chargeFor, TeleportCause cause) throws Exception
|
||||
{
|
||||
final Player player = user.getBase();
|
||||
@@ -146,6 +146,7 @@ public class Teleport implements Runnable, ITeleport
|
||||
teleport(new Target(pre.getRespawnLocation()), chargeFor, cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warp(String warp, Trade chargeFor, TeleportCause cause) throws Exception
|
||||
{
|
||||
final Location loc = ess.getWarps().getWarp(warp);
|
||||
@@ -196,11 +197,13 @@ public class Teleport implements Runnable, ITeleport
|
||||
teleport(new Target(loc), chargeFor, TeleportCause.PLUGIN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(Location loc, Trade chargeFor, TeleportCause cause) throws Exception
|
||||
{
|
||||
teleport(new Target(loc), chargeFor, cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport(Entity entity, Trade chargeFor, TeleportCause cause) throws Exception
|
||||
{
|
||||
teleport(new Target(entity), chargeFor, cause);
|
||||
@@ -208,14 +211,14 @@ public class Teleport implements Runnable, ITeleport
|
||||
|
||||
private void teleport(Target target, Trade chargeFor, TeleportCause cause) throws Exception
|
||||
{
|
||||
double delay = ess.getRanks().getTeleportDelay(user);
|
||||
double tDelay = ess.getRanks().getTeleportDelay(user);
|
||||
|
||||
if (chargeFor != null)
|
||||
{
|
||||
chargeFor.isAffordableFor(user);
|
||||
}
|
||||
cooldown(true);
|
||||
if (delay <= 0 || Permissions.TELEPORT_TIMER_BYPASS.isAuthorized(user))
|
||||
if (tDelay <= 0 || Permissions.TELEPORT_TIMER_BYPASS.isAuthorized(user))
|
||||
{
|
||||
cooldown(false);
|
||||
now(target, cause);
|
||||
@@ -228,10 +231,10 @@ public class Teleport implements Runnable, ITeleport
|
||||
|
||||
cancel();
|
||||
Calendar c = new GregorianCalendar();
|
||||
c.add(Calendar.SECOND, (int)delay);
|
||||
c.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0));
|
||||
c.add(Calendar.SECOND, (int)tDelay);
|
||||
c.add(Calendar.MILLISECOND, (int)((tDelay * 1000.0) % 1000.0));
|
||||
user.sendMessage(_("dontMoveMessage", DateUtil.formatDateDiff(c.getTimeInMillis())));
|
||||
initTimer((long)(delay * 1000.0), target, chargeFor, cause);
|
||||
initTimer((long)(tDelay * 1000.0), target, chargeFor, cause);
|
||||
|
||||
teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10);
|
||||
}
|
||||
@@ -243,6 +246,7 @@ public class Teleport implements Runnable, ITeleport
|
||||
user.getBase().teleport(LocationUtil.getSafeDestination(target.getLocation()), cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void now(Location loc, boolean cooldown, TeleportCause cause) throws Exception
|
||||
{
|
||||
if (cooldown)
|
||||
@@ -259,6 +263,7 @@ public class Teleport implements Runnable, ITeleport
|
||||
now(new Target(loc), cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void now(Entity entity, boolean cooldown, TeleportCause cause) throws Exception
|
||||
{
|
||||
if (cooldown)
|
||||
@@ -268,6 +273,7 @@ public class Teleport implements Runnable, ITeleport
|
||||
now(new Target(entity), cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void back(Trade chargeFor) throws Exception
|
||||
{
|
||||
user.acquireReadLock();
|
||||
@@ -281,6 +287,7 @@ public class Teleport implements Runnable, ITeleport
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void back() throws Exception
|
||||
{
|
||||
user.acquireReadLock();
|
||||
@@ -294,6 +301,7 @@ public class Teleport implements Runnable, ITeleport
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void home(Location loc, Trade chargeFor) throws Exception
|
||||
{
|
||||
teleport(new Target(loc), chargeFor, TeleportCause.COMMAND);
|
||||
|
Reference in New Issue
Block a user