Initial 1.11.2 update
This commit is contained in:
@@ -32,165 +32,177 @@ import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
public class CommandCastSpell extends CommandBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName(){
|
||||
public String getName(){
|
||||
return Wizardry.settings.castCommandName;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getRequiredPermissionLevel(){
|
||||
// I *think* it's something like 0 = everyone, 1 = moderator, 2 = op/admin, 3 = op/console...
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender p_71518_1_){
|
||||
public String getUsage(ICommandSender sender){
|
||||
// Not ideal, but the way this is implemented means I have no choice. Only used in the help command, so in there
|
||||
// the custom command name will not display.
|
||||
return "commands.wizardry:cast.usage";
|
||||
//return I18n.format("commands.wizardry:cast.usage", Wizardry.settings.castCommandName);
|
||||
// return I18n.format("commands.wizardry:cast.usage", Wizardry.settings.castCommandName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] arguments, BlockPos pos) {
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] arguments,
|
||||
BlockPos pos){
|
||||
switch(arguments.length){
|
||||
case 1: return getListOfStringsMatchingLastWord(arguments, Spell.getSpellNames());
|
||||
case 2: return getListOfStringsMatchingLastWord(arguments, server.getAllUsernames());
|
||||
case 1:
|
||||
return getListOfStringsMatchingLastWord(arguments, Spell.getSpellNames());
|
||||
case 2:
|
||||
return getListOfStringsMatchingLastWord(arguments, server.getOnlinePlayerNames());
|
||||
}
|
||||
return super.getTabCompletionOptions(server, sender, arguments, pos);
|
||||
return super.getTabCompletions(server, sender, arguments, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] arguments) throws CommandException {
|
||||
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] arguments) throws CommandException{
|
||||
|
||||
if(arguments.length < 1){
|
||||
throw new WrongUsageException("commands.wizardry:cast.usage", Wizardry.settings.castCommandName);
|
||||
}else{
|
||||
|
||||
// ===== Parameter retrieval =====
|
||||
|
||||
int i=0;
|
||||
|
||||
EntityPlayerMP caster = null;
|
||||
|
||||
try{
|
||||
caster = getCommandSenderAsPlayer(sender);
|
||||
}catch(PlayerNotFoundException exception){
|
||||
// Nothing here since the player specifying is done later, I just don't want it to throw an exception here.
|
||||
}
|
||||
|
||||
Spell spell = Spell.get(arguments[i++]);
|
||||
|
||||
if(spell == null){
|
||||
throw new NumberInvalidException("commands.wizardry:cast.not_found", new Object[]{arguments[i-1]});
|
||||
}
|
||||
|
||||
boolean castAsOtherPlayer = false;
|
||||
|
||||
if(i < arguments.length){
|
||||
try{
|
||||
// If the second argument is a player and is not the player that gave the command, the spell is cast
|
||||
// as the given player rather than the command sender, and there is a different chat readout.
|
||||
EntityPlayerMP entityplayermp = getPlayer(server, sender, arguments[i++]);
|
||||
if(caster != entityplayermp){
|
||||
castAsOtherPlayer = true;
|
||||
caster = entityplayermp;
|
||||
}
|
||||
}catch(PlayerNotFoundException exception){
|
||||
// If no player was found, rather than give an error it simply assumes the player was unspecified.
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
// If, after this point, the player is still null, the sender must be a command block or the console and the
|
||||
// player must not have been specified, meaning an exception should be thrown.
|
||||
if(caster == null) throw new PlayerNotFoundException("You must specify which player you wish to perform this action on.");
|
||||
|
||||
SpellModifiers modifiers = new SpellModifiers();
|
||||
|
||||
if(i < arguments.length){
|
||||
|
||||
// Copied from CommandGive. Why it doesn't just use arguments[i] itself I don't know.
|
||||
String nbt = getChatComponentFromNthArg(sender, arguments, i++).getUnformattedText();
|
||||
throw new WrongUsageException("commands.wizardry:cast.usage", Wizardry.settings.castCommandName);
|
||||
}else{
|
||||
|
||||
try{
|
||||
modifiers = SpellModifiers.fromNBT(JsonToNBT.getTagFromJson(nbt));
|
||||
}catch(NBTException nbtexception){
|
||||
throw new CommandException("commands.wizardry:cast.tag_error", nbtexception.getMessage());
|
||||
}
|
||||
|
||||
for(float multiplier : modifiers.getModifiers().values()){
|
||||
if(multiplier < 0){
|
||||
throw new NumberInvalidException("commands.generic.double.tooSmall", multiplier, 0);
|
||||
}else if(multiplier > Wizardry.settings.maxSpellCommandMultiplier){
|
||||
throw new NumberInvalidException("commands.generic.double.tooBig", multiplier, Wizardry.settings.maxSpellCommandMultiplier);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ===== Spell casting =====
|
||||
|
||||
// If anything stops the spell working at this point, nothing else happens.
|
||||
if(MinecraftForge.EVENT_BUS.post(new SpellCastEvent.Pre(caster, spell, modifiers, Source.COMMAND))){
|
||||
displayFailMessage(sender, spell);
|
||||
return;
|
||||
}
|
||||
|
||||
WizardData data = WizardData.get((EntityPlayer)caster);
|
||||
|
||||
if(spell.isContinuous){
|
||||
|
||||
// Events for continuous spell casting via commands are dealt with in WizardData.
|
||||
|
||||
if(data != null){
|
||||
if(data.isCasting()){
|
||||
data.stopCastingContinuousSpell();
|
||||
}else{
|
||||
|
||||
data.startCastingContinuousSpell(spell, modifiers);
|
||||
|
||||
if(castAsOtherPlayer){
|
||||
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:cast.success_remote_continuous", spell.getNameForTranslationFormatted(), caster.getName()));
|
||||
}else{
|
||||
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:cast.success_continuous", spell.getNameForTranslationFormatted()));
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}else{
|
||||
// ===== Parameter retrieval =====
|
||||
|
||||
if(spell.cast(caster.worldObj, caster, EnumHand.MAIN_HAND, 0, modifiers)){
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(new SpellCastEvent.Post(caster, spell, modifiers, Source.COMMAND));
|
||||
|
||||
if(spell.doesSpellRequirePacket()){
|
||||
int i = 0;
|
||||
|
||||
EntityPlayerMP caster = null;
|
||||
|
||||
try{
|
||||
caster = getCommandSenderAsPlayer(sender);
|
||||
}catch (PlayerNotFoundException exception){
|
||||
// Nothing here since the player specifying is done later, I just don't want it to throw an exception
|
||||
// here.
|
||||
}
|
||||
|
||||
Spell spell = Spell.get(arguments[i++]);
|
||||
|
||||
if(spell == null){
|
||||
throw new NumberInvalidException("commands.wizardry:cast.not_found", new Object[]{arguments[i - 1]});
|
||||
}
|
||||
|
||||
boolean castAsOtherPlayer = false;
|
||||
|
||||
if(i < arguments.length){
|
||||
try{
|
||||
// If the second argument is a player and is not the player that gave the command, the spell is cast
|
||||
// as the given player rather than the command sender, and there is a different chat readout.
|
||||
EntityPlayerMP entityplayermp = getPlayer(server, sender, arguments[i++]);
|
||||
if(caster != entityplayermp){
|
||||
castAsOtherPlayer = true;
|
||||
caster = entityplayermp;
|
||||
}
|
||||
}catch (PlayerNotFoundException exception){
|
||||
// If no player was found, rather than give an error it simply assumes the player was unspecified.
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
// If, after this point, the player is still null, the sender must be a command block or the console and the
|
||||
// player must not have been specified, meaning an exception should be thrown.
|
||||
if(caster == null)
|
||||
throw new PlayerNotFoundException("You must specify which player you wish to perform this action on.");
|
||||
|
||||
SpellModifiers modifiers = new SpellModifiers();
|
||||
|
||||
if(i < arguments.length){
|
||||
|
||||
// Copied from CommandGive. Why it doesn't just use arguments[i] itself I don't know.
|
||||
String nbt = getChatComponentFromNthArg(sender, arguments, i++).getUnformattedText();
|
||||
|
||||
try{
|
||||
modifiers = SpellModifiers.fromNBT(JsonToNBT.getTagFromJson(nbt));
|
||||
}catch (NBTException nbtexception){
|
||||
throw new CommandException("commands.wizardry:cast.tag_error", nbtexception.getMessage());
|
||||
}
|
||||
|
||||
for(float multiplier : modifiers.getModifiers().values()){
|
||||
if(multiplier < 0){
|
||||
throw new NumberInvalidException("commands.generic.double.tooSmall", multiplier, 0);
|
||||
}else if(multiplier > Wizardry.settings.maxSpellCommandMultiplier){
|
||||
throw new NumberInvalidException("commands.generic.double.tooBig", multiplier,
|
||||
Wizardry.settings.maxSpellCommandMultiplier);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ===== Spell casting =====
|
||||
|
||||
// If anything stops the spell working at this point, nothing else happens.
|
||||
if(MinecraftForge.EVENT_BUS.post(new SpellCastEvent.Pre(caster, spell, modifiers, Source.COMMAND))){
|
||||
displayFailMessage(sender, spell);
|
||||
return;
|
||||
}
|
||||
|
||||
WizardData data = WizardData.get((EntityPlayer)caster);
|
||||
|
||||
if(spell.isContinuous){
|
||||
|
||||
// Events for continuous spell casting via commands are dealt with in WizardData.
|
||||
|
||||
if(data != null){
|
||||
if(data.isCasting()){
|
||||
data.stopCastingContinuousSpell();
|
||||
}else{
|
||||
|
||||
data.startCastingContinuousSpell(spell, modifiers);
|
||||
|
||||
if(castAsOtherPlayer){
|
||||
sender.sendMessage(
|
||||
new TextComponentTranslation("commands.wizardry:cast.success_remote_continuous",
|
||||
spell.getNameForTranslationFormatted(), caster.getName()));
|
||||
}else{
|
||||
sender.sendMessage(new TextComponentTranslation("commands.wizardry:cast.success_continuous",
|
||||
spell.getNameForTranslationFormatted()));
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
if(spell.cast(caster.world, caster, EnumHand.MAIN_HAND, 0, modifiers)){
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(new SpellCastEvent.Post(caster, spell, modifiers, Source.COMMAND));
|
||||
|
||||
if(spell.doesSpellRequirePacket()){
|
||||
// Sends a packet to all players in dimension to tell them to spawn particles.
|
||||
// Only sent if the spell succeeded, because if the spell failed, you wouldn't
|
||||
// need to spawn any particles!
|
||||
IMessage msg = new PacketCastSpell.Message(caster.getEntityId(), null, spell.id(), modifiers);
|
||||
WizardryPacketHandler.net.sendToDimension(msg, caster.worldObj.provider.getDimension());
|
||||
WizardryPacketHandler.net.sendToDimension(msg, caster.world.provider.getDimension());
|
||||
}
|
||||
|
||||
if(castAsOtherPlayer){
|
||||
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:cast.success_remote", spell.getNameForTranslationFormatted(), caster.getName()));
|
||||
}else{
|
||||
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:cast.success", spell.getNameForTranslationFormatted()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
displayFailMessage(sender, spell);
|
||||
}
|
||||
|
||||
if(castAsOtherPlayer){
|
||||
sender.sendMessage(new TextComponentTranslation("commands.wizardry:cast.success_remote",
|
||||
spell.getNameForTranslationFormatted(), caster.getName()));
|
||||
}else{
|
||||
sender.sendMessage(new TextComponentTranslation("commands.wizardry:cast.success",
|
||||
spell.getNameForTranslationFormatted()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
displayFailMessage(sender, spell);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Displays the "Unable to cast [spell]" message in the chat. */
|
||||
private void displayFailMessage(ICommandSender sender, Spell spell){
|
||||
ITextComponent message = new TextComponentTranslation("commands.wizardry:cast.fail", spell.getNameForTranslationFormatted());
|
||||
message.getStyle().setColor(TextFormatting.RED);
|
||||
sender.addChatMessage(message);
|
||||
ITextComponent message = new TextComponentTranslation("commands.wizardry:cast.fail",
|
||||
spell.getNameForTranslationFormatted());
|
||||
message.getStyle().setColor(TextFormatting.RED);
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
public class CommandDiscoverSpell extends CommandBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName(){
|
||||
public String getName(){
|
||||
return Wizardry.settings.discoverspellCommandName;
|
||||
}
|
||||
|
||||
@@ -32,39 +32,40 @@ public class CommandDiscoverSpell extends CommandBase {
|
||||
return 2;
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public boolean checkPermission(MinecraftServer server, ICommandSender sender){
|
||||
// Only ops (multiplayer) or players with cheats enabled (singleplayer/LAN) can use /discoverspell.
|
||||
return !(sender instanceof EntityPlayer) || server.getServer().getConfigurationManager().func_152596_g(((EntityPlayer)sender).getGameProfile());
|
||||
}
|
||||
*/
|
||||
/* @Override public boolean checkPermission(MinecraftServer server, ICommandSender sender){ // Only ops
|
||||
* (multiplayer) or players with cheats enabled (singleplayer/LAN) can use /discoverspell. return !(sender
|
||||
* instanceof EntityPlayer) ||
|
||||
* server.getServer().getConfigurationManager().func_152596_g(((EntityPlayer)sender).getGameProfile()); } */
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender p_71518_1_){
|
||||
public String getUsage(ICommandSender sender){
|
||||
// Not ideal, but the way this is implemented means I have no choice. Only used in the help command, so in there
|
||||
// the custom command name will not display.
|
||||
return "commands.wizardry:discoverspell.usage";
|
||||
//return I18n.format("commands.wizardry:discoverspell.usage", Wizardry.settings.discoverspellCommandName);
|
||||
// return I18n.format("commands.wizardry:discoverspell.usage", Wizardry.settings.discoverspellCommandName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] arguments, BlockPos pos) {
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] arguments,
|
||||
BlockPos pos){
|
||||
switch(arguments.length){
|
||||
case 1: return getListOfStringsMatchingLastWord(arguments, Spell.getSpellNames());
|
||||
case 2: return getListOfStringsMatchingLastWord(arguments, server.getAllUsernames());
|
||||
case 1:
|
||||
return getListOfStringsMatchingLastWord(arguments, Spell.getSpellNames());
|
||||
case 2:
|
||||
return getListOfStringsMatchingLastWord(arguments, server.getOnlinePlayerNames());
|
||||
}
|
||||
return super.getTabCompletionOptions(server, sender, arguments, pos);
|
||||
return super.getTabCompletions(server, sender, arguments, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] arguments) throws CommandException {
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] arguments) throws CommandException{
|
||||
|
||||
if(arguments.length < 1){
|
||||
throw new WrongUsageException("commands.wizardry:discoverspell.usage", Wizardry.settings.discoverspellCommandName);
|
||||
throw new WrongUsageException("commands.wizardry:discoverspell.usage",
|
||||
Wizardry.settings.discoverspellCommandName);
|
||||
}else{
|
||||
|
||||
int i=0;
|
||||
int i = 0;
|
||||
boolean clear = false;
|
||||
boolean all = false;
|
||||
|
||||
@@ -72,8 +73,9 @@ public class CommandDiscoverSpell extends CommandBase {
|
||||
|
||||
try{
|
||||
player = getCommandSenderAsPlayer(sender);
|
||||
}catch(PlayerNotFoundException exception){
|
||||
// Nothing here since the player specifying is done later, I just don't want it to throw an exception here.
|
||||
}catch (PlayerNotFoundException exception){
|
||||
// Nothing here since the player specifying is done later, I just don't want it to throw an exception
|
||||
// here.
|
||||
}
|
||||
|
||||
Spell spell = Spells.none;
|
||||
@@ -89,7 +91,8 @@ public class CommandDiscoverSpell extends CommandBase {
|
||||
spell = Spell.get(arguments[i++]);
|
||||
|
||||
if(spell == null){
|
||||
throw new NumberInvalidException("commands.wizardry:discoverspell.not_found", new Object[]{arguments[i-1]});
|
||||
throw new NumberInvalidException("commands.wizardry:discoverspell.not_found",
|
||||
new Object[]{arguments[i - 1]});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,25 +107,31 @@ public class CommandDiscoverSpell extends CommandBase {
|
||||
|
||||
// If, after this point, the player is still null, the sender must be a command block or the console and the
|
||||
// player must not have been specified, meaning an exception should be thrown.
|
||||
if(player == null) throw new PlayerNotFoundException("You must specify which player you wish to perform this action on.");
|
||||
if(player == null)
|
||||
throw new PlayerNotFoundException("You must specify which player you wish to perform this action on.");
|
||||
|
||||
WizardData properties = WizardData.get(player);
|
||||
|
||||
if(properties != null){
|
||||
if(clear){
|
||||
properties.spellsDiscovered.clear();
|
||||
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:discoverspell.clear", player.getName()));
|
||||
sender.sendMessage(
|
||||
new TextComponentTranslation("commands.wizardry:discoverspell.clear", player.getName()));
|
||||
}else if(all){
|
||||
properties.spellsDiscovered.addAll(Spell.getSpells(Spell.allSpells));
|
||||
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:discoverspell.all", player.getName()));
|
||||
sender.sendMessage(
|
||||
new TextComponentTranslation("commands.wizardry:discoverspell.all", player.getName()));
|
||||
}else{
|
||||
if(properties.hasSpellBeenDiscovered(spell)){
|
||||
properties.spellsDiscovered.remove(spell);
|
||||
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:discoverspell.removespell", spell.getNameForTranslationFormatted(), player.getName()));
|
||||
sender.sendMessage(new TextComponentTranslation("commands.wizardry:discoverspell.removespell",
|
||||
spell.getNameForTranslationFormatted(), player.getName()));
|
||||
}else{
|
||||
if(!MinecraftForge.EVENT_BUS.post(new DiscoverSpellEvent(player, spell, DiscoverSpellEvent.Source.COMMAND))){
|
||||
if(!MinecraftForge.EVENT_BUS
|
||||
.post(new DiscoverSpellEvent(player, spell, DiscoverSpellEvent.Source.COMMAND))){
|
||||
properties.discoverSpell(spell);
|
||||
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:discoverspell.addspell", spell.getNameForTranslationFormatted(), player.getName()));
|
||||
sender.sendMessage(new TextComponentTranslation("commands.wizardry:discoverspell.addspell",
|
||||
spell.getNameForTranslationFormatted(), player.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import net.minecraft.util.text.TextFormatting;
|
||||
public class CommandSetAlly extends CommandBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName(){
|
||||
public String getName(){
|
||||
return Wizardry.settings.allyCommandName;
|
||||
}
|
||||
|
||||
@@ -32,30 +32,32 @@ public class CommandSetAlly extends CommandBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkPermission(MinecraftServer server, ICommandSender p_71519_1_)
|
||||
{
|
||||
public boolean checkPermission(MinecraftServer server, ICommandSender p_71519_1_){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender p_71518_1_){
|
||||
public String getUsage(ICommandSender p_71518_1_){
|
||||
// Not ideal, but the way this is implemented means I have no choice. Only used in the help command, so in there
|
||||
// the custom command name will not display.
|
||||
return "commands.wizardry:ally.usage";
|
||||
//return I18n.format("commands.wizardry:ally.usage", Wizardry.settings.allyCommandName);
|
||||
// return I18n.format("commands.wizardry:ally.usage", Wizardry.settings.allyCommandName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] arguments, BlockPos pos) {
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] arguments,
|
||||
BlockPos pos){
|
||||
switch(arguments.length){
|
||||
case 1: return getListOfStringsMatchingLastWord(arguments, server.getAllUsernames());
|
||||
case 2: return getListOfStringsMatchingLastWord(arguments, server.getAllUsernames());
|
||||
case 1:
|
||||
return getListOfStringsMatchingLastWord(arguments, server.getOnlinePlayerNames());
|
||||
case 2:
|
||||
return getListOfStringsMatchingLastWord(arguments, server.getOnlinePlayerNames());
|
||||
}
|
||||
return super.getTabCompletionOptions(server, sender, arguments, pos);
|
||||
return super.getTabCompletions(server, sender, arguments, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] arguments) throws CommandException {
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] arguments) throws CommandException{
|
||||
|
||||
if(arguments.length < 1){
|
||||
throw new WrongUsageException("commands.wizardry:ally.usage", Wizardry.settings.allyCommandName);
|
||||
@@ -65,8 +67,9 @@ public class CommandSetAlly extends CommandBase {
|
||||
|
||||
try{
|
||||
allyOf = getCommandSenderAsPlayer(sender);
|
||||
}catch(PlayerNotFoundException exception){
|
||||
// Nothing here since the player specifying is done later, I just don't want it to throw an exception here.
|
||||
}catch (PlayerNotFoundException exception){
|
||||
// Nothing here since the player specifying is done later, I just don't want it to throw an exception
|
||||
// here.
|
||||
}
|
||||
|
||||
boolean executeAsOtherPlayer = false;
|
||||
@@ -79,11 +82,13 @@ public class CommandSetAlly extends CommandBase {
|
||||
allyOf = getPlayer(server, sender, arguments[1]);
|
||||
// Don't want to catch the exception here either, because there can be no other second argument.
|
||||
|
||||
if(allyOf != sender && sender instanceof EntityPlayer && !WizardryUtilities.isPlayerOp((EntityPlayer)sender, server)){
|
||||
if(allyOf != sender && sender instanceof EntityPlayer
|
||||
&& !WizardryUtilities.isPlayerOp((EntityPlayer)sender, server)){
|
||||
// Displays a chat message if a non-op tries to modify another player's allies.
|
||||
TextComponentTranslation TextComponentTranslation2 = new TextComponentTranslation("commands.wizardry:ally.permission");
|
||||
TextComponentTranslation TextComponentTranslation2 = new TextComponentTranslation(
|
||||
"commands.wizardry:ally.permission");
|
||||
TextComponentTranslation2.getStyle().setColor(TextFormatting.RED);
|
||||
allyOf.addChatMessage(TextComponentTranslation2);
|
||||
allyOf.sendMessage(TextComponentTranslation2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -92,18 +97,20 @@ public class CommandSetAlly extends CommandBase {
|
||||
|
||||
// If, after this point, allyOf is still null, the sender must be a command block or the console and two
|
||||
// players must not have been specified, meaning an exception should be thrown.
|
||||
if(allyOf == null) throw new PlayerNotFoundException("You must specify which player you wish to perform this action on.");
|
||||
if(allyOf == null)
|
||||
throw new PlayerNotFoundException("You must specify which player you wish to perform this action on.");
|
||||
|
||||
if(allyOf == ally) throw new NumberInvalidException("commands.wizardry:ally.self");
|
||||
|
||||
if(WizardData.get(allyOf) != null){
|
||||
String string = WizardData.get(allyOf).toggleAlly(ally) ? "add" : "remove";
|
||||
if(executeAsOtherPlayer){
|
||||
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:ally." + string + "ally", ally.getName(), allyOf.getName()));
|
||||
sender.sendMessage(new TextComponentTranslation("commands.wizardry:ally." + string + "ally",
|
||||
ally.getName(), allyOf.getName()));
|
||||
// In this case, the player whose allies have been modified is also notified.
|
||||
allyOf.addChatMessage(new TextComponentTranslation("item.wand." + string + "ally", ally.getName()));
|
||||
allyOf.sendMessage(new TextComponentTranslation("item.wand." + string + "ally", ally.getName()));
|
||||
}else{
|
||||
sender.addChatMessage(new TextComponentTranslation("item.wand." + string + "ally", ally.getName()));
|
||||
sender.sendMessage(new TextComponentTranslation("item.wand." + string + "ally", ally.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import net.minecraft.util.text.TextFormatting;
|
||||
public class CommandViewAllies extends CommandBase {
|
||||
|
||||
@Override
|
||||
public String getCommandName(){
|
||||
public String getName(){
|
||||
return Wizardry.settings.alliesCommandName;
|
||||
}
|
||||
|
||||
@@ -30,37 +30,38 @@ public class CommandViewAllies extends CommandBase {
|
||||
// I *think* it's something like 0 = everyone, 1 = moderator, 2 = op/admin, 3 = op/console...
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkPermission(MinecraftServer server, ICommandSender p_71519_1_)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandUsage(ICommandSender p_71518_1_){
|
||||
public boolean checkPermission(MinecraftServer server, ICommandSender p_71519_1_){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage(ICommandSender p_71518_1_){
|
||||
// Not ideal, but the way this is implemented means I have no choice. Only used in the help command, so in there
|
||||
// the custom command name will not display.
|
||||
return "commands.wizardry:allies.usage";
|
||||
//return I18n.format("commands.wizardry:allies.usage", Wizardry.settings.alliesCommandName);
|
||||
// return I18n.format("commands.wizardry:allies.usage", Wizardry.settings.alliesCommandName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] arguments, BlockPos pos) {
|
||||
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] arguments,
|
||||
BlockPos pos){
|
||||
switch(arguments.length){
|
||||
case 1: return getListOfStringsMatchingLastWord(arguments, server.getAllUsernames());
|
||||
case 1:
|
||||
return getListOfStringsMatchingLastWord(arguments, server.getOnlinePlayerNames());
|
||||
}
|
||||
return super.getTabCompletionOptions(server, sender, arguments, pos);
|
||||
return super.getTabCompletions(server, sender, arguments, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] arguments) throws CommandException {
|
||||
public void execute(MinecraftServer server, ICommandSender sender, String[] arguments) throws CommandException{
|
||||
|
||||
EntityPlayerMP player = null;
|
||||
|
||||
try{
|
||||
player = getCommandSenderAsPlayer(sender);
|
||||
}catch(PlayerNotFoundException exception){
|
||||
}catch (PlayerNotFoundException exception){
|
||||
// Nothing here since the player specifying is done later, I just don't want it to throw an exception here.
|
||||
}
|
||||
|
||||
@@ -70,12 +71,14 @@ public class CommandViewAllies extends CommandBase {
|
||||
|
||||
player = getPlayer(server, sender, arguments[0]);
|
||||
// Don't want to catch the exception here either, because there can be no other first argument.
|
||||
|
||||
if(player != sender && sender instanceof EntityPlayer && !WizardryUtilities.isPlayerOp((EntityPlayer)sender, server)){
|
||||
// Displays a chat message if a non-op tries to view another player's allies.
|
||||
TextComponentTranslation TextComponentTranslation2 = new TextComponentTranslation("commands.wizardry:allies.permission");
|
||||
|
||||
if(player != sender && sender instanceof EntityPlayer
|
||||
&& !WizardryUtilities.isPlayerOp((EntityPlayer)sender, server)){
|
||||
// Displays a chat message if a non-op tries to view another player's allies.
|
||||
TextComponentTranslation TextComponentTranslation2 = new TextComponentTranslation(
|
||||
"commands.wizardry:allies.permission");
|
||||
TextComponentTranslation2.getStyle().setColor(TextFormatting.RED);
|
||||
player.addChatMessage(TextComponentTranslation2);
|
||||
player.sendMessage(TextComponentTranslation2);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -84,7 +87,8 @@ public class CommandViewAllies extends CommandBase {
|
||||
|
||||
// If, after this point, player is still null, the sender must be a command block or the console and the
|
||||
// player must not have been specified, meaning an exception should be thrown.
|
||||
if(player == null) throw new PlayerNotFoundException("You must specify which player you wish to perform this action on.");
|
||||
if(player == null)
|
||||
throw new PlayerNotFoundException("You must specify which player you wish to perform this action on.");
|
||||
|
||||
if(WizardData.get(player) != null){
|
||||
|
||||
@@ -102,9 +106,10 @@ public class CommandViewAllies extends CommandBase {
|
||||
}
|
||||
|
||||
if(executeAsOtherPlayer){
|
||||
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:allies.list_other", player.getName(), string));
|
||||
sender.sendMessage(
|
||||
new TextComponentTranslation("commands.wizardry:allies.list_other", player.getName(), string));
|
||||
}else{
|
||||
sender.addChatMessage(new TextComponentTranslation("commands.wizardry:allies.list", string));
|
||||
sender.sendMessage(new TextComponentTranslation("commands.wizardry:allies.list", string));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user