Add FlySpeedCommand to replace EventModule's
This commit is contained in:
parent
740c547914
commit
bda5813c9c
@ -0,0 +1,43 @@
|
||||
package mineplex.mapparser.command;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.mapparser.MapParser;
|
||||
|
||||
public class FlySpeedCommand extends BaseCommand
|
||||
{
|
||||
private final static float BASE_SPEED = 0.1F;
|
||||
|
||||
public FlySpeedCommand(MapParser plugin)
|
||||
{
|
||||
super(plugin, "speed", "flyspeed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, String alias, String[] args)
|
||||
{
|
||||
float newSpeed = BASE_SPEED;
|
||||
|
||||
if (args.length > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
newSpeed = Float.parseFloat(args[0]);
|
||||
|
||||
if (newSpeed > 10 || newSpeed < 0)
|
||||
{
|
||||
throw new NumberFormatException("Speed must be between 0 and 10.");
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
message(player, "Please enter a valid speed value from " + C.cYellow + "0" + C.mBody + " to " + C.cYellow + "10");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
player.setFlySpeed(newSpeed / 10);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -227,59 +227,6 @@ public class EventModule extends Module
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void commandCancel(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
if (event.getMessage().startsWith("/tp") ||
|
||||
event.getMessage().startsWith("/hub") ||
|
||||
event.getMessage().startsWith("/list") ||
|
||||
event.getMessage().startsWith("/map") ||
|
||||
event.getMessage().startsWith("/create") ||
|
||||
event.getMessage().startsWith("/copy") ||
|
||||
event.getMessage().startsWith("/delete"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Permission
|
||||
if (!getPlugin().getData(event.getPlayer().getWorld().getName()).HasAccess(event.getPlayer()))
|
||||
{
|
||||
UtilPlayerBase.message(event.getPlayer(), F.main("Parser", "You do not have Build-Access for this Map."));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void FlySpeed(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
if (!event.getMessage().toLowerCase().startsWith("/speed"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
String[] tokens = event.getMessage().split(" ");
|
||||
|
||||
if (tokens.length != 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
try
|
||||
{
|
||||
float speed = Float.parseFloat(tokens[1]);
|
||||
|
||||
player.setFlySpeed(speed);
|
||||
|
||||
UtilPlayerBase.message(player, F.main("Game", "Fly Speed set to " + F.elem("" + speed) + "."));
|
||||
} catch (Exception e)
|
||||
{
|
||||
UtilPlayerBase.message(player, F.main("Game", "Invalid Speed Input."));
|
||||
}
|
||||
}
|
||||
|
||||
//#################################################################################################
|
||||
//# #
|
||||
|
Loading…
Reference in New Issue
Block a user