Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
added highlight command
- Loading branch information
Showing
3 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
src/main/java/net/doubledoordev/d3commands/commands/CommandHighlight.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright (c) 2014-2016, Dries007 & 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. | ||
* | ||
* 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.CommandException; | ||
import net.minecraft.command.ICommandSender; | ||
import net.minecraft.command.PlayerNotFoundException; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.player.EntityPlayerMP; | ||
import net.minecraft.network.datasync.DataParameter; | ||
import net.minecraft.network.datasync.DataSerializers; | ||
import net.minecraft.network.datasync.EntityDataManager; | ||
import net.minecraft.network.play.server.SPacketEntityMetadata; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.text.TextComponentTranslation; | ||
import net.minecraftforge.common.util.FakePlayer; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.List; | ||
|
||
public class CommandHighlight extends CommandBase | ||
{ | ||
@Override | ||
public String getCommandName() | ||
{ | ||
return "highlight"; | ||
} | ||
|
||
@Override | ||
public String getCommandUsage(ICommandSender icommandsender) | ||
{ | ||
return "/highlight [target] [true|false]"; | ||
} | ||
|
||
@Override | ||
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException | ||
{ | ||
if (args.length == 0) | ||
{ | ||
getCommandSenderAsPlayer(sender).setGlowing(getCommandSenderAsPlayer(sender).isGlowing()); | ||
sender.addChatMessage(new TextComponentTranslation("d3.cmd.highlight.success", sender.getDisplayName())); | ||
return; | ||
} | ||
if (args.length == 1) | ||
{ | ||
try | ||
{ | ||
getCommandSenderAsPlayer(sender).setGlowing(parseBoolean(args[0])); | ||
sender.addChatMessage(new TextComponentTranslation("d3.cmd.highlight.success", sender.getDisplayName())); | ||
} | ||
catch (CommandException ignored) | ||
{ | ||
for (Entity e : getEntityList(server, sender, args[0])) | ||
{ | ||
e.setGlowing(!e.isGlowing()); | ||
} | ||
} | ||
return; | ||
} | ||
boolean b = parseBoolean(args[1]); | ||
for (Entity e : getEntityList(server, sender, args[0])) | ||
{ | ||
e.setGlowing(b); | ||
} | ||
// target.setGlowing(!target.isGlowing()); | ||
// | ||
// DataParameter<Byte> FLAGS = new DataParameter<>(0, DataSerializers.BYTE); | ||
// EntityDataManager dm = target.getDataManager(); | ||
// EntityDataManager fake = new EntityDataManager(target); | ||
// fake.register(FLAGS, (byte) (dm.get(FLAGS) & (1 << 6))); | ||
// | ||
// EntityPlayerMP senderMP = getCommandSenderAsPlayer(sender); | ||
// | ||
// SPacketEntityMetadata p = new SPacketEntityMetadata(target.getEntityId(), dm, false); | ||
// senderMP.connection.sendPacket(p); | ||
// | ||
// sender.addChatMessage(new TextComponentTranslation("d3.cmd.highlight.success", target.getDisplayName())); | ||
} | ||
|
||
@Override | ||
public int getRequiredPermissionLevel() | ||
{ | ||
return 2; | ||
} | ||
|
||
@Override | ||
public boolean isUsernameIndex(final String[] args, final int userIndex) | ||
{ | ||
return userIndex == 0; | ||
} | ||
|
||
@Override | ||
public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos pos) | ||
{ | ||
if (args.length == 1) return getListOfStringsMatchingLastWord(args, server.getAllUsernames()); | ||
if (args.length == 2) return getListOfStringsMatchingLastWord(args, "true", "false"); | ||
return super.getTabCompletionOptions(server, sender, args, pos); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters