I've tried everything, but with this code, the items I get for killing a player will have their base Minecraft name, why? I've tried everything. Could another plugin be blocking it? What could be the problem?
Java, intellijidea, 1.8 Code:
public class killitem implements Listener {
private random plugin = random.getPlugin(random.class);
#EventHandler
public void onPlayerDeath(PlayerDeathEvent e) {
Player player = e.getEntity();
Player killer = player.getKiller();
//Enderpearl
ItemStack is = new ItemStack(Material.ENDER_PEARL);
ItemMeta meta = is.getItemMeta();
meta.setDisplayName("" + ChatColor.GOLD + ChatColor.YELLOW + ChatColor.BOLD + "Véggyöngy");
ArrayList<String> lore = new ArrayList();
//Blaze rod
ItemStack is2 = new ItemStack(Material.BLAZE_ROD);
ItemMeta meta2 = is2.getItemMeta();
meta.setDisplayName("" + ChatColor.GOLD + ChatColor.DARK_RED + ChatColor.BOLD + "Mentőrúd");
ArrayList<String> lore2 = new ArrayList();
lore.add("|" + ChatColor.RED + "Jobb klikk: |" + ChatColor.DARK_GRAY + " ▪ " + ChatColor.GRAY + "Feltölti " + ChatColor.RED + "teljesen " + ChatColor.GRAY + "az életedet!");
meta.setLore(lore2);
is2.setItemMeta(meta2);
//Csillag
ItemStack is3 = new ItemStack(Material.NETHER_STAR);
ItemMeta meta3 = is3.getItemMeta();
meta.setDisplayName("" + ChatColor.DARK_GREEN + ChatColor.BOLD + "Második Esély");
ArrayList<String> lore3 = new ArrayList();
lore.add("|" + ChatColor.GREEN + "Jobb klikk: |" + ChatColor.DARK_GRAY + " ▪ " + ChatColor.GRAY + "Feldob " + ChatColor.RED + "60 " + ChatColor.GRAY + "blokk magasra!");
meta.setLore(lore3);
//Toll
ItemStack is4 = new ItemStack(Material.FEATHER);
ItemMeta meta4 = is4.getItemMeta();
meta.setDisplayName("" + ChatColor.AQUA + ChatColor.BOLD + "Speed");
ArrayList<String> lore4 = new ArrayList();
lore.add("|" + ChatColor.AQUA + "Jobb klikk: |" + ChatColor.DARK_GRAY + " ▪ " + ChatColor.GRAY + "Speed 4-et kapsz " + ChatColor.AQUA + "10 " + ChatColor.GRAY + "másodpercre!");
meta.setLore(lore4);
//Quartz
ItemStack is5 = new ItemStack(Material.QUARTZ);
ItemMeta meta5 = is5.getItemMeta();
meta.setDisplayName("" + ChatColor.RED + ChatColor.BOLD + "Instant Health");
ArrayList<String> lore5 = new ArrayList();
lore.add("|" + ChatColor.RED + "Jobb klikk: |" + ChatColor.DARK_GRAY + " ▪ " + ChatColor.GRAY + "Feltölti " + ChatColor.RED + "teljesen " + ChatColor.GRAY + "az életed!");
meta.setLore(lore5);
//Aranyalma
ItemStack is6 = new ItemStack(Material.GOLDEN_APPLE);
ItemMeta meta6 = is6.getItemMeta();
meta.setDisplayName("" + ChatColor.YELLOW + "Aranyalma");
ArrayList<String> lore6 = new ArrayList();
int upper = 5;
Random random = new Random();
random.nextInt(5 + (upper));
if (player.isDead()) {
player.getKiller();
if (player.getKiller() instanceof Player) {
random.nextInt(5 + (upper));
if (random.nextInt(5 + (upper)) == 6) {
killer.getInventory().addItem(is2);
is2.setItemMeta(meta2);
} else if (random.nextInt(5 + (upper)) == 7) {
killer.getInventory().addItem(is3);
is3.setItemMeta(meta3);
} else if (random.nextInt(5 + (upper)) == 8) {
killer.getInventory().addItem(is4);
is4.setItemMeta(meta4);
} else if (random.nextInt(5 + (upper)) == 9) {
killer.getInventory().addItem(is);
killer.getInventory().addItem(is6);
is6.setItemMeta(meta6);
is.setItemMeta(meta);
}
} else if (random.nextInt(5 + (upper)) == 10) {
}
}
}
}
okay try to first setItemMeta and then give it
if (random.nextInt(5 + (upper)) == 6) {
is2.setItemMeta(meta2);//like this
killer.getInventory().addItem(is2);
Try using this:
public class killitem implements Listener {
private random plugin = random.getPlugin(random.class);
#EventHandler
public void onPlayerDeath(PlayerDeathEvent e) {
bukkit.getscheduler().runTask(plugin, ()->giveItemForKiller(e));
}
private void giveItemForKiller(PlayerDeathEvent e) {
Player player = e.getEntity();
Player killer = player.getKiller();
//Enderpearl
ItemStack is = new ItemStack(Material.ENDER_PEARL);
ItemMeta meta = is.getItemMeta();
meta.setDisplayName("" + ChatColor.GOLD + ChatColor.YELLOW + ChatColor.BOLD + "Véggyöngy");
ArrayList<String> lore = new ArrayList();
//Blaze rod
ItemStack is2 = new ItemStack(Material.BLAZE_ROD);
ItemMeta meta2 = is2.getItemMeta();
meta.setDisplayName("" + ChatColor.GOLD + ChatColor.DARK_RED + ChatColor.BOLD + "Mentőrúd");
ArrayList<String> lore2 = new ArrayList();
lore.add("|" + ChatColor.RED + "Jobb klikk: |" + ChatColor.DARK_GRAY + " ▪ " + ChatColor.GRAY + "Feltölti " + ChatColor.RED + "teljesen " + ChatColor.GRAY + "az életedet!");
meta.setLore(lore2);
is2.setItemMeta(meta2);
//Csillag
ItemStack is3 = new ItemStack(Material.NETHER_STAR);
ItemMeta meta3 = is3.getItemMeta();
meta.setDisplayName("" + ChatColor.DARK_GREEN + ChatColor.BOLD + "Második Esély");
ArrayList<String> lore3 = new ArrayList();
lore.add("|" + ChatColor.GREEN + "Jobb klikk: |" + ChatColor.DARK_GRAY + " ▪ " + ChatColor.GRAY + "Feldob " + ChatColor.RED + "60 " + ChatColor.GRAY + "blokk magasra!");
meta.setLore(lore3);
//Toll
ItemStack is4 = new ItemStack(Material.FEATHER);
ItemMeta meta4 = is4.getItemMeta();
meta.setDisplayName("" + ChatColor.AQUA + ChatColor.BOLD + "Speed");
ArrayList<String> lore4 = new ArrayList();
lore.add("|" + ChatColor.AQUA + "Jobb klikk: |" + ChatColor.DARK_GRAY + " ▪ " + ChatColor.GRAY + "Speed 4-et kapsz " + ChatColor.AQUA + "10 " + ChatColor.GRAY + "másodpercre!");
meta.setLore(lore4);
//Quartz
ItemStack is5 = new ItemStack(Material.QUARTZ);
ItemMeta meta5 = is5.getItemMeta();
meta.setDisplayName("" + ChatColor.RED + ChatColor.BOLD + "Instant Health");
ArrayList<String> lore5 = new ArrayList();
lore.add("|" + ChatColor.RED + "Jobb klikk: |" + ChatColor.DARK_GRAY + " ▪ " + ChatColor.GRAY + "Feltölti " + ChatColor.RED + "teljesen " + ChatColor.GRAY + "az életed!");
meta.setLore(lore5);
//Aranyalma
ItemStack is6 = new ItemStack(Material.GOLDEN_APPLE);
ItemMeta meta6 = is6.getItemMeta();
meta.setDisplayName("" + ChatColor.YELLOW + "Aranyalma");
ArrayList<String> lore6 = new ArrayList();
int upper = 5;
Random random = new Random();
random.nextInt(5 + (upper));
if (player.isDead()) {
player.getKiller();
if (player.getKiller() instanceof Player) {
random.nextInt(5 + (upper));
if (random.nextInt(5 + (upper)) == 6) {
killer.getInventory().addItem(is2);
is2.setItemMeta(meta2);
} else if (random.nextInt(5 + (upper)) == 7) {
killer.getInventory().addItem(is3);
is3.setItemMeta(meta3);
} else if (random.nextInt(5 + (upper)) == 8) {
killer.getInventory().addItem(is4);
is4.setItemMeta(meta4);
} else if (random.nextInt(5 + (upper)) == 9) {
killer.getInventory().addItem(is);
killer.getInventory().addItem(is6);
is6.setItemMeta(meta6);
is.setItemMeta(meta);
}
} else if (random.nextInt(5 + (upper)) == 10) {
}
}
}
}
Related
I am using the following to download assetbundle and it works in first scene. But when in second scene, the same code doesn't work - the uwr.downloadedbytes return 0. If I restart the app and go straight to the second scene, it works. Strange things is when I go back to the first scene from second scene, the code works as well. I want to know what is going wrong, is it something to do with unload(false) in the first scene?
private IEnumerator DownloadBundles()
{
AssetBundleList = new List<string>();
m_AssetBundle = new List<AssetBundle>();
m_InstantiatedModels = new List<GameObject>();
yield return StartCoroutine(DownloadBundle(1));
}
private IEnumerator DownloadBundle(int i)
{
string platform = "Android";
string bundleURL = data.url + data.id + "/" + platform + "/" + data.id + "assetbundles" + i.ToString();
using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(bundleURL, (uint)data.assetBundleVersion, 0))
{
AsyncOperation asyncOp = uwr.SendWebRequest();
while (!asyncOp.isDone)
{
if (m_ProgressText.gameObject.activeSelf)
{
m_ProgressText.text = "Loading " + (i == 1 ? "" : "More ") + "Models... " + ((int)(asyncOp.progress * 100)).ToString() + "%";
}
yield return null;
}
if (uwr.error != null)
{
throw new UnityException("AssetBundle DownloadHandler had an error: " + uwr.error);
}
else
{
Debug.Log(uwr.downloadedBytes.ToString());
AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr);
string[] assetBundleList1 = bundle.GetAllAssetNames();
assetBundleDownloaded.Add(i);
object[] golist = bundle.LoadAllAssets();
for (int k = 0; k < golist.Length; k++)
{
GameObject go = Instantiate(golist[k] as GameObject, Vector3.zero, Quaternion.identity);
go.SetActive(false);
m_InstantiatedModels.Add(go);
}
m_AssetBundle.Add(bundle);
yield return null;
}
}
}
Code:
IEnumerator PickImage (int maxSize)
{
Texture2D texture = null;
NativeGallery.Permission permission = NativeGallery.GetImageFromGallery (( path) => {
Debug.Log ("Image path: " + path);
if (path != null) {
// Create Texture from selected image
texture = NativeGallery.LoadImageAtPath (path, maxSize);
if (texture == null) {
Debug.Log ("Couldn't load texture from " + path);
return;
}
profileImage.sprite = Sprite.Create (texture, new Rect (0f, 0f, texture.width, texture.height), new Vector2 (0.5f, 0.5f), 100f);
}
}, "Select an image", "image/*", maxSize);
if (texture != null) {
// make texture read and write able
Texture2D readableTexture = DuplicateTexture(texture);
Debug.Log ("readable texture width: " + readableTexture.width + " height: " + readableTexture.height);
WWWForm form = new WWWForm ();
Debug.Log ("player id: " + DataCollection.localPlayer.PlayerId);
form.AddField (GameConstants.ARG_UPLOAD_PHOTO_PLAYER_ID, DataCollection.localPlayer.PlayerId);
form.AddBinaryData (GameConstants.ARG_UPLOAD_PHOTO, readableTexture.GetRawTextureData (), "profilepic.jpg", "image/*");
Dictionary<string,string> headerDisc = form.headers;
WWW www = new WWW (GameConstants.API_UPLOAD_PHOTO, form.data, headerDisc);
yield return www;
if (www.error == null) {
Debug.Log ("Data: " + www.text);
profileImage.sprite = Sprite.Create (texture, new Rect (0f, 0f, texture.width, texture.height), new Vector2 (0.5f, 0.5f), 100f);
} else {
Debug.Log ("Error: " + www.error);
}
}
Debug.Log ("Permission result: " + permission);
}
I don't know what my error is I am not understanding classes
I have read a java book but its not helpful
classes codes and methods confuse me and though you figuring out my code i will have a better understanding of what those things actually do
public double intoxicated(double weight)
{
double numDrinks;
numDrinks = (0.08 + 0.015) * weight /
(12 * 7.5 * alcohol);
return numDrinks;
}
public class Beer
{
private String name;
private double alcohol;
public String getName(){
return name;
}
public void setName(String n)
{
this.name= name;
}
public double getAlcohol()
{
return Alcohol;
}
public void setAlcohol(double a)
{
this.age = age;
}
public double intoxicated(double weight)
{
double numDrinks;
numDrinks = (0.08 + 0.015) * weight /
(12 * 7.5 * alcohol);
return numDrinks;
}
public static void main(String[] args)
{
Beer beer1 = new Beer();
Beer beer2 = new Beer();
beer1.setName("Cors Light");
beer1.setAlcohol(0.042);
beer2.setName("Heinaken");
beer2.setAlcohol(0.042);
double lightWeight = 100.0;
double heavyWeight = 250.0;
double lightDrinks1 = beer1.intoxicated(lightWeight);
System.out.println("The number of " + beer1.getName() +
" drinks needed to make\na person weighing " +
lightWeight + " pounds intoxicated is " + lightDrinks1);
System.out.println();
double heavyDrinks1 = beer1.intoxicated(heavyWeight);
System.out.println("The number of " + beer1.getName() +
" drinks needed to make\na person weighing " +
heavyWeight + " pounds intoxicated is " + heavyDrinks1);
System.out.println();
double lightDrinks2 = beer2.intoxicated(lightWeight);
System.out.println("The number of " + beer2.getName() +
" drinks needed to make\na person weighing " +
lightWeight + " pounds intoxicated is " + lightDrinks2);
System.out.println();
double heavyDrinks2 = beer2.intoxicated(heavyWeight);
System.out.println("The number of " + beer2.getName() +
" drinks needed to make\na person weighing " +
heavyWeight + " pounds intoxicated is " + heavyDrinks2);
System.out.println();
Beer beer3 = new Beer();
beer3.setName("Miller Genuine Draft Light");
beer3.setAlcohol(0.042); // 4.2% alcohol
lightWeight = 100.0;
heavyWeight = 250.0;
double lightDrinks3 = beer3.intoxicated(lightWeight);
System.out.println("The number of " + beer3.getName() +
" drinks needed to make\na person weighing " +
lightWeight + " pounds intoxicated is " + lightDrinks3);
System.out.println();
double heavyDrinks3 = beer3.intoxicated(heavyWeight);
System.out.println("The number of " + beer3.getName() +
" drinks needed to make\na person weighing " +
heavyWeight + " pounds intoxicated is " + heavyDrinks3);
System.out.println();
}
}
I have first listed my class code, then my tester/driver code and have put my questions at the bottom. My code for my class is as follows :
class Complex {
//data values
private double real;
private double imag;
//constructors
public Complex () {
real = 0;
imag = 0;
}
public Complex (double realInput) {
real = realInput;
imag = 0;
}
public Complex (double realInput, double imagInput) {
real = realInput;
imag = imagInput;
}
//accessors
public double getReal () {
return real;
}
public double getImag () {
return imag;
}
//modifiers
public void setReal (double inputReal) {
real = inputReal;
}
public void setImag (double inputImag) {
imag = inputImag;
}
//toString method
public String toString() {
return real + " + " + imag + "i";
}
//instance methods
//addition methods
public Complex add (double realInput) {
real = real + realInput;
Complex newComplex = new Complex(real, imag);
return newComplex;
}
public Complex add (Complex complex) {
double firstReal = complex.getReal();
double firstImag = complex.getImag();
double secondReal = this.getReal();
double secondImag = this.getImag();
real = firstReal + secondReal;
imag = firstImag + secondImag;
Complex newComplex = new Complex(real, imag);
return newComplex;
}
//subtraction methods
public Complex subtract (double realInput) {
real = real - realInput;
Complex newComplex = new Complex(real, imag);
return newComplex;
}
public Complex subtract (Complex complex) {
double newReal = complex.getReal();
double newImag = complex.getImag();
real = this.getReal() - newReal;
imag = this.getImag() - newImag;
Complex newComplex = new Complex(real, imag);
return newComplex;
}
//multiplication methods
public Complex multiply (double realInput) {
real = real * realInput;
imag = imag * realInput;
Complex newComplex = new Complex(real, imag);
return newComplex;
}
//****problem code****
public Complex multiply (Complex complex) {
double newReal = complex.getReal();
double newImag = complex.getImag();
real = ((real * newReal) - (imag * newImag));
imag = ((real * newImag) + (imag * newReal));
Complex newComplex = new Complex(real, imag);
return newComplex;
}
//division methods
public Complex divide (double realInput) {
real = real / realInput;
imag = imag / realInput;
Complex newComplex = new Complex(real, imag);
return newComplex;
}
//****problem code****
public Complex divide (Complex complex) {
double newReal = complex.getReal();
double newImag = complex.getImag();
real = this.getReal();
imag = this.getImag();
double newRealNumerator = (real * newReal) + (imag * newImag);
double newRealDenominator = (Math.pow(newReal, 2) + Math.pow(newImag, 2));
real = newRealNumerator / newRealDenominator;
double newImagNumerator = (imag * newReal) - (real * newImag);
double newImagDenominator = newRealDenominator;
imag = newImagNumerator / newImagDenominator;
Complex newComplex = new Complex(real, imag);
return newComplex;
}
//equals method
public boolean equals (Complex complex) {
double firstReal = complex.getReal();
double firstImag = complex.getImag();
double secondReal = this.getReal();
double secondImag = this.getImag();
boolean testEquals = false;
if (firstReal == secondReal && firstImag == secondImag) {
testEquals = true;
}
return testEquals;
}
}//end class
My code for my tester/driver is as follows:
class ComplexTester {
public static void main(String[] args ) {
//declaring Complex objects
Complex one = new Complex ();
Complex two = new Complex (3);
Complex three = new Complex (1, 4);
Complex four = new Complex (2, 3);
//testing addition methods
System.out.println("Testing addition methods...");
System.out.println("(" + three.toString() + ") + (" + 3.0 + ") = " + three.add(3.0));
three.setReal(1);
three.setImag(4);
System.out.println("(" + three.toString() + ") + (" + four.toString() + ") = " + three.add(four));
three.setReal(1);
three.setImag(4);
//testing subtraction methods
System.out.println();
System.out.println("Testing subtraction methods...");
System.out.println("(" + three.toString() + ") - (" + 3.0 + ") = " + three.subtract(3.0));
three.setReal(1);
three.setImag(4);
System.out.println("(" + three.toString() + ") - (" + four.toString() + ") = " + three.subtract(four));
three.setReal(1);
three.setImag(4);
//testing multiplication methods
System.out.println();
System.out.println("Testing multiplication methods...");
System.out.println("(" + three.toString() + ") * (" + 3.0 + ") = " + three.multiply(3.0));
three.setReal(1);
three.setImag(4);
System.out.println("(" + three.toString() + ") * (" + four.toString() + ") = " + three.multiply(four));
three.setReal(6);
three.setImag(3);
//testing division method
System.out.println();
System.out.println("Testing division methods...");
System.out.println("(" + three.toString() + ") / (" + 3.0 + ") = " + three.divide(3.0));
three.setReal(4);
three.setImag(2);
Complex testDiv = new Complex(3, -1);
System.out.println("(" + three.toString() + ") / (" + testDiv.toString() + ") = " + three.divide(testDiv));
three.setReal(1);
three.setImag(4);
//testing equals method
System.out.println();
System.out.println("Testing equals method...");
if (three.equals(four) == true) {
System.out.println(three.toString() + " is equal to " + four.toString());
}
else {
System.out.println(three.toString() + " is not equal to " + four.toString());
}
Complex testEquals = new Complex(2, 3);
if (four.equals(testEquals) == true) {
System.out.println(four.toString() + " is equal to " + testEquals.toString());
}
else {
System.out.println(four.toString() + " is not equal to " + testEquals.toString());
}
}// end main method
}// end class
My first problem is that if I would call my add method on the three object [such as three.add(four) ] it completely changes the three object to the answer of three.add(four). What I did to get around that (and I'm assuming it's bad programming) is call the set methods to assign the three object back to what I needed.
My second problem is that the multiply and divide methods (that I have commented above with "****problem code****") are not reporting the correct complex number. The multiply problem code should show (-10.0 + 11.0i) in the tester but instead it shows (-10.0 + -22.0i) upon running. The divide problem code should show (1.0 + 1.0i) but instead it shows (1.0 + 0.7i) upon running.
To multiply a complex number by another complex number the formula is: (A + Bi) times (C + Di) = (AC - BD) + (AD + BC)i
To divide a complex number by another complex number the formula is: (A + Bi) divided by (C + Di) = (AC+BD)/(C2 + D2) + (BC-AD)/(C2 + D2)i
My key to convert from the letters of the formulas listed (A, B, C, D) and my own self-named variables is: A = real, B = imag, C = newReal, and D = newImag
real = ((real * newReal) - (imag * newImag));
imag = ((real * newImag) + (imag * newReal));
This updates your instance variable real and you are using this updated real variable in the calculation of imaginary part of the complex variable which is obviously wrong.
Your code should be like this.
public Complex multiply (Complex complex) {
double newReal = complex.getReal();
double newImag = complex.getImag();
double real = ((this.real * newReal) - (this.imag * newImag));
double imag = ((this.real * newImag) + (this.imag * newReal));
Complex newComplex = new Complex(real, imag);
return newComplex;
}
The below throws an error for in public static void DemoMethod(). Why?
package demoblock;
/**
*
* #author coleen
*/
public class DemoBlock {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Demontrating block scope");
int x = 1111;
System.out.print("in first block x is" + x);
{
int y = 2222;
System.out.println(" In second block x is " + x);
System.out.println(" In seond block y is " + y);
}
{
int y = 3333;
System.out.println(" In third block x is " + x);
System.out.println(" In third block y is " + y);
DemoMethod();
System.out.println(" After method x is " + x);
System.out.println(" After method block y is " + y);
System.out.println(" At the end x is " + x);
public static void DemoMethod()
{
int x = 8888;
int y = 9999;
System.out.println(" In demoMethod x is " + x);
System.out.println(" In DemoMethod block y is " + y);
}
}
/** * * #author coleen */
public class DemoBlock
{
/**
* #param args
* the command line arguments
*/
public static void main( String[] args )
{
System.out.println( "Demontrating block scope" );
int x = 1111;
System.out.print( "in first block x is" + x );
{
int y = 2222;
System.out.println( " In second block x is " + x );
System.out.println( " In seond block y is " + y );
}
{
int y = 3333;
System.out.println( " In third block x is " + x );
System.out.println( " In third block y is " + y );
DemoMethod();
System.out.println( " After method x is " + x );
System.out.println( " After method block y is " + y );
System.out.println( " At the end x is " + x );
}
}
public static void DemoMethod()
{
int x = 8888;
int y = 9999;
System.out.println( " In demoMethod x is " + x );
System.out.println( " In DemoMethod block y is " + y );
}
}