Merge pull request #255 from Focusvity/pr/modifyitem-fix

Fixed modifyitem command
This commit is contained in:
CoolJWB 2020-08-08 00:38:59 +02:00 committed by GitHub
commit b6746acb44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,12 +2,11 @@ package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.FUtil;
import net.minecraft.server.v1_16_R1.NBTTagCompound; import net.minecraft.server.v1_16_R1.NBTTagCompound;
import net.minecraft.server.v1_16_R1.NBTTagInt;
import net.minecraft.server.v1_16_R1.NBTTagList; import net.minecraft.server.v1_16_R1.NBTTagList;
import net.minecraft.server.v1_16_R1.NBTTagString;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -160,23 +159,34 @@ public class Command_modifyitem extends FreedomCommand
msg("Invalid attribute. Please run /attributelist for a list of valid attributes."); msg("Invalid attribute. Please run /attributelist for a list of valid attributes.");
return true; return true;
} }
cmpnd.set("AttributeName", NBTTagString.a(attribute.getAttribute())); cmpnd.setString("AttributeName", attribute.getAttribute());
cmpnd.set("Name", NBTTagString.a(attribute.getAttribute())); cmpnd.setString("Name", attribute.getAttribute());
int amount; double amount;
try try
{ {
amount = Integer.parseInt(args[2]); amount = Double.parseDouble(args[2]);
} }
catch (NumberFormatException ex) catch (NumberFormatException ex)
{ {
msg("The amount specified is not a valid integer."); msg("The amount specified is not a valid integer.");
return true; return true;
} }
cmpnd.set("Amount", NBTTagInt.a(amount)); if (Double.isNaN(amount))
cmpnd.set("Operation", NBTTagInt.a(0)); {
cmpnd.set("UUIDLeast", NBTTagInt.a(894654)); msg("The amount specified is illegal.");
cmpnd.set("UUIDMost", NBTTagInt.a(2872)); return true;
cmpnd.set("Slot", NBTTagString.a("mainhand")); }
cmpnd.setDouble("Amount", amount);
cmpnd.setInt("Operation", 0);
Random random = new Random();
cmpnd.setIntArray("UUID", new int[]
{
random.nextInt(),
random.nextInt(),
random.nextInt(),
random.nextInt()
});
cmpnd.setString("Slot", "mainhand");
modifiers.add(cmpnd); modifiers.add(cmpnd);
compound.set("AttributeModifiers", modifiers); compound.set("AttributeModifiers", modifiers);
nmsStack.setTag(compound); nmsStack.setTag(compound);