summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIaccidentally <coryhuckaby@gmail.com>2012-08-26 20:02:01 -0400
committerIaccidentally <coryhuckaby@gmail.com>2012-08-26 20:02:01 -0400
commitd8c6b921f0c1b5216e8854b4952d275d5b7458c0 (patch)
tree049376437430e32f96a7fe64e00998c4503c9f24
parent7aff52cceccacec09de357037e7a48ea84d9ecfd (diff)
downloadEssentials-d8c6b921f0c1b5216e8854b4952d275d5b7458c0.tar
Essentials-d8c6b921f0c1b5216e8854b4952d275d5b7458c0.tar.gz
Essentials-d8c6b921f0c1b5216e8854b4952d275d5b7458c0.tar.lz
Essentials-d8c6b921f0c1b5216e8854b4952d275d5b7458c0.tar.xz
Essentials-d8c6b921f0c1b5216e8854b4952d275d5b7458c0.zip
add Commandspeed to 3.x
-rw-r--r--Essentials/src/net/ess3/commands/Commandspeed.java148
1 files changed, 148 insertions, 0 deletions
diff --git a/Essentials/src/net/ess3/commands/Commandspeed.java b/Essentials/src/net/ess3/commands/Commandspeed.java
new file mode 100644
index 000000000..e724580da
--- /dev/null
+++ b/Essentials/src/net/ess3/commands/Commandspeed.java
@@ -0,0 +1,148 @@
+package net.ess3.commands;
+
+import net.ess3.user.User;
+import org.bukkit.Server;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+
+public class Commandspeed extends EssentialsCommand
+{
+
+ @Override
+ protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
+ {
+ if (args.length < 2)
+ {
+ throw new NotEnoughArgumentsException();
+ }
+ final boolean isFly = isFlyMode(args[0]);
+ final float speed = getMoveSpeed(args[1]);
+ speedOtherPlayers(server, sender, isFly, true, speed, args[2]);
+ }
+
+ @Override
+ protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
+ {
+ if (args.length < 1)
+ {
+ throw new NotEnoughArgumentsException();
+ }
+
+ boolean isFly;
+ float speed;
+ boolean isBypass = user.isAuthorized("essentials.speed.bypass");
+ if (args.length == 1)
+ {
+ //isFly = user.isFlying();
+ isFly = true;
+ speed = getMoveSpeed(args[0]);
+ }
+ else
+ {
+ //isFly = isFlyMode(args[0]);
+ //speed = getMoveSpeed(args[1]);
+ //if (args.length > 2 && user.isAuthorized("essentials.speed.others"))
+ //{
+ // speedOtherPlayers(server, user, isFly, isBypass, speed, args[2]);
+ // return;
+ //}
+ isFly = true;
+ speed = getMoveSpeed(args[0]);
+ if (user.isAuthorized("essentials.speed.others"))
+ {
+ speedOtherPlayers(server, user, isFly, isBypass, speed, args[1]);
+ return;
+ }
+ }
+
+ //if (isFly)
+ //{
+ user.setFlySpeed(getRealMoveSpeed(speed, isFly, isBypass));
+ user.sendMessage(_("moveSpeed", _("flying"), speed, user.getDisplayName()));
+ //}
+ //else
+ //{
+ // user.setWalkSpeed(getRealMoveSpeed(speed, isFly, isBypass));
+ // user.sendMessage(_("moveSpeed", _("walking"), speed, user.getDisplayName()));
+ //}
+ }
+
+ private void speedOtherPlayers(final Server server, final CommandSender sender, final boolean isFly, final boolean isBypass, final float speed, final String target)
+ {
+ for (Player matchPlayer : server.matchPlayer(target))
+ {
+ if (isFly)
+ {
+ matchPlayer.setFlySpeed(getRealMoveSpeed(speed, isFly, isBypass));
+ sender.sendMessage(_("moveSpeed", _("flying"), speed, matchPlayer.getDisplayName()));
+ }
+ else
+ {
+ matchPlayer.setWalkSpeed(getRealMoveSpeed(speed, isFly, isBypass));
+ sender.sendMessage(_("moveSpeed", _("walking"), speed, matchPlayer.getDisplayName()));
+ }
+ }
+ }
+
+ private boolean isFlyMode(final String modeString) throws NotEnoughArgumentsException
+ {
+ boolean isFlyMode;
+ if (modeString.contains("fly") || modeString.equalsIgnoreCase("f"))
+ {
+ isFlyMode = true;
+ }
+ else if (modeString.contains("walk") || modeString.contains("run")
+ || modeString.equalsIgnoreCase("w") || modeString.equalsIgnoreCase("r"))
+ {
+ isFlyMode = false;
+ }
+ else
+ {
+ throw new NotEnoughArgumentsException();
+ }
+ return isFlyMode;
+ }
+
+ private float getMoveSpeed(final String moveSpeed) throws NotEnoughArgumentsException
+ {
+ float userSpeed;
+ try
+ {
+ userSpeed = Float.parseFloat(moveSpeed);
+ if (userSpeed > 10f)
+ {
+ userSpeed = 10f;
+ }
+ else if (userSpeed < 0f)
+ {
+ userSpeed = 0f;
+ }
+ }
+ catch (NumberFormatException e)
+ {
+ throw new NotEnoughArgumentsException();
+ }
+ return userSpeed;
+ }
+
+ private float getRealMoveSpeed(final float userSpeed, final boolean isFly, final boolean isBypass)
+ {
+ final float defaultSpeed = isFly ? 0.1f : 0.2f;
+ float maxSpeed = 1f;
+ if (!isBypass)
+ {
+ maxSpeed = (float)(isFly ? ess.getSettings().getMaxFlySpeed() : ess.getSettings().getMaxWalkSpeed());
+ }
+
+ if (userSpeed < 1f)
+ {
+ return defaultSpeed * userSpeed;
+ }
+ else
+ {
+ float ratio = ((userSpeed - 1) / 9) * (maxSpeed - defaultSpeed);
+ return ratio + defaultSpeed;
+ }
+ }
+}