Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better way to handle registering commands and config, added heal and …
…feed command. Messages still have to be added.
- Loading branch information
Showing
4 changed files
with
274 additions
and
15 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/main/java/net/doubledoordev/d3commands/CommandEntry.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,81 @@ | ||
/* | ||
* 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; | ||
|
||
import net.minecraft.command.CommandBase; | ||
|
||
/** | ||
* Created by Wout on 25/10/2014. | ||
*/ | ||
public class CommandEntry { | ||
|
||
private CommandBase command; | ||
private boolean enabled; | ||
private String permission; | ||
|
||
public CommandEntry(CommandBase command, boolean enabled, String permission) { | ||
this.command = command; | ||
this.enabled = enabled; | ||
this.permission = permission; | ||
} | ||
|
||
public CommandEntry(CommandBase command, boolean enabled) { | ||
this.command = command; | ||
this.enabled = enabled; | ||
} | ||
|
||
public CommandBase getCommand() { | ||
return command; | ||
} | ||
|
||
public void setCommand(CommandBase command) { | ||
this.command = command; | ||
} | ||
|
||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
public void setEnabled(boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
public String getPermission() { | ||
if(permission == null){ | ||
return "d3.commands." + this.getCommand().getCommandName().toLowerCase(); | ||
} | ||
return permission; | ||
} | ||
|
||
public void setPermission(String permission) { | ||
this.permission = permission; | ||
} | ||
} |
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
88 changes: 88 additions & 0 deletions
88
src/main/java/net/doubledoordev/d3commands/commands/CommandFeed.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,88 @@ | ||
/* | ||
* 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 CommandFeed extends CommandBase | ||
{ | ||
@Override | ||
public String getCommandName() { | ||
return "feed"; | ||
} | ||
|
||
@Override | ||
public String getCommandUsage(ICommandSender icommandsender) | ||
{ | ||
return "/feed [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 playerFeed = getPlayer(sender, args[0]); | ||
playerFeed.getFoodStats().setFoodLevel(20); | ||
//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 playerFeed = getCommandSenderAsPlayer(sender); | ||
if (args.length == 0) | ||
{ | ||
playerFeed.getFoodStats().setFoodLevel(20); | ||
} | ||
else | ||
{ | ||
playerFeed.addChatMessage(new ChatComponentText(getCommandUsage(sender))); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public List addTabCompletionOptions(final ICommandSender sender, final String[] args) | ||
{ | ||
if (args.length == 1) return getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames()); | ||
return null; | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
src/main/java/net/doubledoordev/d3commands/commands/CommandHeal.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,90 @@ | ||
/* | ||
* 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 CommandHeal extends CommandBase | ||
{ | ||
@Override | ||
public String getCommandName() { | ||
return "heal"; | ||
} | ||
|
||
@Override | ||
public String getCommandUsage(ICommandSender icommandsender) | ||
{ | ||
return "/heal [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 playerHeal = getPlayer(sender, args[0]); | ||
playerHeal.setHealth(20); | ||
playerHeal.getFoodStats().setFoodLevel(20); | ||
//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 playerHeal = getCommandSenderAsPlayer(sender); | ||
if (args.length == 0) | ||
{ | ||
playerHeal.setHealth(20); | ||
playerHeal.getFoodStats().setFoodLevel(20); | ||
} | ||
else | ||
{ | ||
playerHeal.addChatMessage(new ChatComponentText(getCommandUsage(sender))); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public List addTabCompletionOptions(final ICommandSender sender, final String[] args) | ||
{ | ||
if (args.length == 1) return getListOfStringsMatchingLastWord(args, MinecraftServer.getServer().getAllUsernames()); | ||
return null; | ||
} | ||
} |