#Plugin drops unwanted item
1 messages · Page 1 of 1 (latest)
so it drops both heads?
steve head and player one
is this multiversion or something, i dont get the point of the 2 playerHead ='s
I don't remember why there are two of them
remove the try catch and change ItemStack playerHead to ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD, 1);
Now it gives 2 playerheads
You know what may be causing the 2nd one to drop?
I tried removing the bottom itemstack but it still dropped 2
send the updated code
public class Getkilled implements Listener {
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
Player getKilled = event.getEntity();
String killerName = getKilled.getKiller().getName();
if (event.getEntity().getKiller() == null) return;
ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD, 1);
SkullMeta meta = (SkullMeta) playerHead.getItemMeta();
meta.setOwner(getKilled.getName());
meta.setLore(Arrays.asList("Killed by " + killerName)
playerHead.setItemMeta(meta);
getKilled.getWorld().dropItemNaturally(getKilled.getLocation(), playerHead);
}
}
np
How can I make a second lore line?
meta.setLore(Arrays.asList("Killed by " + killerName, "Lore Line 2"))
oh it goes in the same bracket
just a comma between differnet lines
yea, tried to put the other text in extra brackets after comma before
ah lol
How can I change color and make text for example bold in the item lore?
meta.setLore(Arrays.asList(ChatColor.GREEN.toString() + ChatColor.BOLD + "Killed by " + killerName, "Lore Line 2"))
okay, thank you
Hello once again, how can I make so the color1 and format1 can be controlled from config?
code: https://hastebin.com/uwazenunop.swift
config: https://hastebin.com/odihamuyed.apache
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Create a file called config.yml in the resources folder and add the default there then you can use that instead of copying defaults another way
The second one is my config file that I created
config:
Color1: "WHITE"
Format1: "ITALIC"
Color2: "WHITE"
Format2: "ITALIC"
Drop Chance: 1.0
# Color1 Is color of the killer name and Format1 is format aka bold, italic and so one, for kill date is color2 and format2
# Write exactly as in the link, https://hub.spigotmc.org/javadocs/spigot/org/bukkit/ChatColor.html
# It must be in " "
# Drop chance: 1.0
# 1.0 = 100%, 0.1 = 10%, 0 = 0%, 0 = disabled
Code:
https://paste.md-5.net/usigitalak.java
project formatting:
Does the drop chance code work with any percentage or only with 100% and 10%?
only 1.0 and 0.1 because thats what the comments on config said
its not hard to make it work with 100.0 and between 1.0
Probally the most stupid question yet, but how do I change so when I build the plugin jar version wont always be 1.0-snapshot?
maven or gradle
maven
<version>1.0-SNAPSHOT</version> im guessing
Do I need to write some code more for the plugin to actually create config file when in server?
just needs the config in resources and it should do it automatically from the saveDefaultConfig(); on onEnable
btw is the chance thing correct?
the code that should be used is on https://paste.md-5.net/usigitalak.java
just copy that
just change the package name up top and class name
isn't the percentage for 100 or 10% only?
do you want Drop Chance in config to be a 100 to 1 percent
so Drop Chance: 95 has a 95% chance of dropping
yes
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
int chance = getConfig().getInt("Drop Chance");
// Config
String color1 = getConfig().getString("Color1");
String format1 = getConfig().getString("Format1");
String color2 = getConfig().getString("Color2");
String format2 = getConfig().getString("Format2");
Player getKilled = event.getEntity();
String killerName = getKilled.getKiller().getName();
// LocalDate date = LocalDate.now();
Date date = Calendar.getInstance().getTime();
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String today = formatter.format(date);
if (event.getEntity().getKiller() == null) return;
ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD, 1);
SkullMeta meta = (SkullMeta) playerHead.getItemMeta();
meta.setOwner(getKilled.getName());
Bukkit.getLogger().info(getConfig().getString("drop chance" + "is my name"));
meta.setLore(Arrays.asList(ChatColor.of(color1).toString() + ChatColor.of(format1) + "Killed by " + killerName, ChatColor.of(color2).toString() + ChatColor.of(format2) + "Killed on "+ today ));
playerHead.setItemMeta(meta);
Double randomChance = ThreadLocalRandom.current().nextInt(0, 100);
if (chance > randomChance) getKilled.getWorld().dropItemNaturally(getKilled.getLocation(), playerHead);
}
What does it want to int?
for some reason it didn't make a config file in server nor drops a head
do you have the onEnable code
yes
is the default config in the resources folder
i know the problem
Is main or getkilled your main class
if there isnt anything in main, delete it
there's this stuff but idk if it's needed
remove the extends JavaPlugin and onEnable from getKilled
ill get the code for di
Main should have ```
@Override
public void onEnable() {
// Plugin startup logic
saveDefaultConfig();
getServer().getPluginManager().registerEvents(new GetKilled(this), this);
}
oh wait forgot something
And getKilled should look like
public class GetKilled implements Listener {
private final MainClassName plugin;
public CurrentClassName(MainClassName plugin) {
this.plugin = plugin;
}
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
int chance = plugin.getConfig().getDouble("Drop Chance");
// Config
String color1 = plugin.getConfig().getString("Color1");
String format1 = plugin.getConfig().getString("Format1");
String color2 = plugin.getConfig().getString("Color2");
String format2 = plugin.getConfig().getString("Format2");
Player getKilled = event.getEntity();
String killerName = getKilled.getKiller().getName();
// LocalDate date = LocalDate.now();
Date date = Calendar.getInstance().getTime();
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String today = formatter.format(date);
if (event.getEntity().getKiller() == null) return;
ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD, 1);
SkullMeta meta = (SkullMeta) playerHead.getItemMeta();
meta.setOwner(getKilled.getName());
Bukkit.getLogger().info(plugin.getConfig().getString("drop chance" + "is my name"));
meta.setLore(Arrays.asList(ChatColor.of(color1).toString() + ChatColor.of(format1) + "Killed by " + killerName, ChatColor.of(color2).toString() + ChatColor.of(format2) + "Killed on "+ today ));
playerHead.setItemMeta(meta);
int randomChance = ThreadLocalRandom.current().nextDouble(0.0, 100.0);
if (percentage > randomChance) getKilled.getWorld().dropItemNaturally(getKilled.getLocation(), playerHead);
}
}
theres some errors now
chance the top to the correct stuff, its just placeholders
private final MainClassName plugin;
public CurrentClassName(MainClassName plugin) {
this.plugin = plugin;
}
oh ok
MainClassName = Main
CurrentClassName = Getkilled
this.plugin too?
this.plugin is fine to stay
and what about all these cannot resolve method "getConfig()"
should fix itself after getting the correct class names
it says it needs int but there is int
change nextDouble to nextInt
numbers to 0 and 100
int randomChance = ThreadLocalRandom.current().nextInt(0, 100);
hmm
class name is wrong
Getkilled not GetKilled
forgot to change the int and chance stuff
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
int chance = plugin.getConfig().getDouble("Drop Chance");
``` should be the top of the event sorry
it gives me error that it should be int not double so getDouble to getInt?
correct
I meant about this one
np lol
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
int chance = plugin.getConfig().getInt("Drop Chance");
// Config
String color1 = plugin.getConfig().getString("Color1");
String format1 = plugin.getConfig().getString("Format1");
String color2 = plugin.getConfig().getString("Color2");
String format2 = plugin.getConfig().getString("Format2");
Player getKilled = event.getEntity();
String killerName = getKilled.getKiller().getName();
// LocalDate date = LocalDate.now();
Date date = Calendar.getInstance().getTime();
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String today = formatter.format(date);
if (event.getEntity().getKiller() == null) return;
ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD, 1);
SkullMeta meta = (SkullMeta) playerHead.getItemMeta();
meta.setOwner(getKilled.getName());
Bukkit.getLogger().info(plugin.getConfig().getString("drop chance" + "is my name"));
meta.setLore(Arrays.asList(ChatColor.of(color1).toString() + ChatColor.of(format1) + "Killed by " + killerName, ChatColor.of(color2).toString() + ChatColor.of(format2) + "Killed on "+ today ));
playerHead.setItemMeta(meta);
int randomChance = ThreadLocalRandom.current().nextInt(0, 100);
if (chance >= randomChance) getKilled.getWorld().dropItemNaturally(getKilled.getLocation(), playerHead);
}
``` should be the 100% correct code lol
Welp I forgot yesterday but I hope it wouldn't be too hard to be able to separately disable line 1 of lore and line 2 from config, that would be the final thing that I would need to add to the plugin.
Thats not hard to do, ill get it when im on my pc
I am in school rn so you don't have to hurry
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
ArrayList lore = new ArrayList();
int chance = plugin.getConfig().getInt("Drop Chance");
Player getKilled = event.getEntity();
String killerName = getKilled.getKiller().getName();
// Date
Date date = Calendar.getInstance().getTime();
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String today = formatter.format(date);
// Config
String color1 = plugin.getConfig().getString("Color1");
String format1 = plugin.getConfig().getString("Format1");
String color2 = plugin.getConfig().getString("Color2");
String format2 = plugin.getConfig().getString("Format2");
String line1Enabled = plugin.getConfig().getString("Line1");
String line1 = ChatColor.of(color1).toString() + ChatColor.of(format1) + "Killed by " + killerName;
String line2Enabled = plugin.getConfig().getString("Line2");
String line2 = ChatColor.of(color2).toString() + ChatColor.of(format2) + "Killed on " + today;
if (line1Enabled.equals("enabled")) lore.add(line1);
if (line2Enabled.equals("enabled")) lore.add(line2);
if (event.getEntity().getKiller() == null) return;
ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD, 1);
SkullMeta meta = (SkullMeta) playerHead.getItemMeta();
meta.setOwner(getKilled.getName());
Bukkit.getLogger().info(plugin.getConfig().getString("drop chance" + "is my name"));
meta.setLore(lore);
playerHead.setItemMeta(meta);
int randomChance = ThreadLocalRandom.current().nextInt(0, 100);
if (chance >= randomChance) getKilled.getWorld().dropItemNaturally(getKilled.getLocation(), playerHead);
}
for some reason it doesn't seem to want to drop the head
whats drop chance in config
100
add a System.out.println for chance and random chance to check its not doing the math correctly
and where do I see when it prints them?
console
found a thing
oh add
Line1: enabled
Line2: enabled
``` to config.yml on server and resource