Skip to content
Permalink
Browse files

Added /fly command.

  • Loading branch information...
woutwoot committed Oct 25, 2014
1 parent 1707da9 commit 7c7a6f9de82aa5a71180063a6e9ae74a061e0d55
@@ -11,9 +11,9 @@ Commands currently included:
* /top
* /heal [target player]
* /feed [target player]
* /fly [target player]

Commands to be added soon:
* /fly
* /gm
* /tpa (Use json chat formatting to accept, no command)
* /back
@@ -46,6 +46,7 @@ public void syncConfig()
commands.add(new CommandEntry(new CommandHeal(), configuration.getBoolean("heal", MODID, true, "Heal yourself or other players.")));
commands.add(new CommandEntry(new CommandFeed(), configuration.getBoolean("feed", MODID, true, "Feed yourself or other players.")));
commands.add(new CommandEntry(new CommandGetUUID(), configuration.getBoolean("getuuid", MODID, true, "Allows easy UUID grabbing.")));
commands.add(new CommandEntry(new CommandFly(), configuration.getBoolean("fly", MODID, true, "Toggle fly mode.")));

if (configuration.hasChanged()) configuration.save();
}
@@ -0,0 +1,95 @@
/*
* Copyright (c) 2014, DoubleDoorDevelopment
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the project nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package net.doubledoordev.d3commands.commands;

import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;

import java.util.List;

public class CommandFly extends CommandBase
{
@Override
public String getCommandName() {
return "fly";
}

@Override
public String getCommandUsage(ICommandSender icommandsender)
{
return "/fly [target player]";
}

@Override
public void processCommand(final ICommandSender sender, final String[] args)
{
if (args.length == 1)
{
if (sender instanceof MinecraftServer || MinecraftServer.getServer().getConfigurationManager().func_152596_g(MinecraftServer.getServer().getConfigurationManager().func_152612_a(sender.getCommandSenderName()).getGameProfile()))
{
EntityPlayerMP playerFly = getPlayer(sender, args[0]);
doFly(playerFly);
//TODO: Add succes message, need to ask dries how to get stuff from the .lang files.
}
else sender.addChatMessage(new ChatComponentTranslation("commands.generic.permission"));
}
else
{
EntityPlayerMP playerFly = getCommandSenderAsPlayer(sender);
if (args.length == 0)
{
doFly(playerFly);
}
else
{
playerFly.addChatMessage(new ChatComponentText(getCommandUsage(sender)));
}
}
}

private void doFly(EntityPlayerMP playerFly) {
playerFly.capabilities.allowFlying = !playerFly.capabilities.isFlying;
if (!playerFly.capabilities.allowFlying)
playerFly.capabilities.isFlying = false;
playerFly.sendPlayerAbilities();
}

@Override
public List addTabCompletionOptions(final ICommandSender sender, final String[] args)
{
if (args.length == 1) return getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames());
return null;
}
}

0 comments on commit 7c7a6f9

Please sign in to comment.
You can’t perform that action at this time.