Merge 8d372cd768
into cde7184da3
This commit is contained in:
commit
95ccd027ef
|
@ -52,7 +52,8 @@ public class AsyncTeleport implements IAsyncTeleport {
|
|||
final Calendar time = new GregorianCalendar();
|
||||
if (teleportOwner.getLastTeleportTimestamp() > 0) {
|
||||
// Take the current time, and remove the delay from it.
|
||||
final double cooldown = ess.getSettings().getTeleportCooldown();
|
||||
final String group = teleportOwner.getGroup();
|
||||
final double cooldown = ess.getSettings().getTeleportCooldown(group);
|
||||
final Calendar earliestTime = new GregorianCalendar();
|
||||
earliestTime.add(Calendar.SECOND, -(int) cooldown);
|
||||
earliestTime.add(Calendar.MILLISECOND, -(int) ((cooldown * 1000.0) % 1000.0));
|
||||
|
|
|
@ -128,7 +128,7 @@ public interface ISettings extends IConf {
|
|||
|
||||
boolean isForcePassengerTeleport();
|
||||
|
||||
double getTeleportCooldown();
|
||||
double getTeleportCooldown(String group);
|
||||
|
||||
double getTeleportDelay();
|
||||
|
||||
|
|
|
@ -487,8 +487,8 @@ public class Settings implements net.ess3.api.ISettings {
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getTeleportCooldown() {
|
||||
return config.getDouble("teleport-cooldown", 0);
|
||||
public double getTeleportCooldown(String group) {
|
||||
return config.getDouble("group-teleport-cooldowns." + (group == null ? "Default" : group),0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -43,7 +43,8 @@ public class Teleport implements ITeleport {
|
|||
final Calendar time = new GregorianCalendar();
|
||||
if (teleportOwner.getLastTeleportTimestamp() > 0) {
|
||||
// Take the current time, and remove the delay from it.
|
||||
final double cooldown = ess.getSettings().getTeleportCooldown();
|
||||
final String group = teleportOwner.getGroup();
|
||||
final double cooldown = ess.getSettings().getTeleportCooldown(group);
|
||||
final Calendar earliestTime = new GregorianCalendar();
|
||||
earliestTime.add(Calendar.SECOND, -(int) cooldown);
|
||||
earliestTime.add(Calendar.MILLISECOND, -(int) ((cooldown * 1000.0) % 1000.0));
|
||||
|
|
|
@ -92,10 +92,9 @@ force-safe-teleport-location: false
|
|||
teleport-passenger-dismount: true
|
||||
|
||||
# The delay, in seconds, required between /home, /tp, etc.
|
||||
teleport-cooldown: 0
|
||||
|
||||
# The delay, in seconds, before a user actually teleports. If the user moves or gets attacked in this timeframe, the teleport is cancelled.
|
||||
teleport-delay: 0
|
||||
group-teleport-cooldowns:
|
||||
default: 0
|
||||
# admins: 3
|
||||
|
||||
# The delay, in seconds, a player can't be attacked by other players after they have been teleported by a command.
|
||||
# This will also prevent the player attacking other players.
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.commands.IEssentialsCommand;
|
||||
import com.earth2me.essentials.commands.NoChargeException;
|
||||
import org.bukkit.plugin.InvalidDescriptionException;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class TeleportationTest {
|
||||
|
||||
private final OfflinePlayer base1;
|
||||
private final Essentials ess;
|
||||
private final FakeServer server;
|
||||
|
||||
public TeleportationTest() {
|
||||
server = FakeServer.getServer();
|
||||
ess = new Essentials(server);
|
||||
try {
|
||||
ess.setupForTesting(server);
|
||||
} catch (final InvalidDescriptionException ex) {
|
||||
fail("InvalidDescriptionException");
|
||||
} catch (final IOException ex) {
|
||||
fail("IOException");
|
||||
}
|
||||
base1 = server.createPlayer("testPlayer1");
|
||||
server.addPlayer(base1);
|
||||
ess.getUser(base1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTeleportationCooldownConfig() {
|
||||
final User user1 = ess.getUser(base1);
|
||||
|
||||
final double defaultTeleportCooldown = ess.getSettings().getTeleportCooldown("default");
|
||||
assertEquals(defaultTeleportCooldown, 0, 0.01);
|
||||
|
||||
boolean fail = false;
|
||||
try {
|
||||
// Test two home commands in quick succession; will work as long as config is properly set
|
||||
runCommand("home", user1, "a");
|
||||
runCommand("home", user1, "a");
|
||||
} catch (Exception e) {
|
||||
fail = true;
|
||||
} finally {
|
||||
assertEquals(fail, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void runCommand(final String command, final User user, final String args) throws Exception {
|
||||
runCommand(command, user, args.split("\\s+"));
|
||||
}
|
||||
|
||||
private void runCommand(final String command, final User user, final String[] args) throws Exception {
|
||||
final IEssentialsCommand cmd;
|
||||
|
||||
try {
|
||||
cmd = (IEssentialsCommand) Essentials.class.getClassLoader()
|
||||
.loadClass("com.earth2me.essentials.commands.Command" + command).newInstance();
|
||||
cmd.setEssentials(ess);
|
||||
cmd.run(server, user, command, null, args);
|
||||
} catch (final NoChargeException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue