Skip to content

Commit

Permalink
Added an array of blood items and set item meta once
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuarezl committed Aug 18, 2024
1 parent 7eb6e66 commit b356b73
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/cl/mastercode/DamageIndicator/DIMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Iterator;
import java.util.Map;

Expand Down Expand Up @@ -197,7 +196,7 @@ public void reloadMessages() {
messages = YamlConfiguration.loadConfiguration(getDataFolder().toPath().resolve("messages.yml").toFile());
}

public @NonNull BukkitAudiences adventure() {
public BukkitAudiences adventure() {
if (this.adventure == null) {
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
}
Expand Down
14 changes: 10 additions & 4 deletions src/cl/mastercode/DamageIndicator/listener/BloodListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.bukkit.util.Vector;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
Expand All @@ -56,6 +57,7 @@ public class BloodListener implements Listener {

private static final String BLOOD_NAME = "di-blood";
private static final String DISABLED_BLOOD = "DI-DISABLED-BLOOD";
private static final ItemStack[] BLOOD_ITEMS = new ItemStack[]{new ItemStack(Material.CRIMSON_ROOTS), new ItemStack(Material.FIRE_CORAL_FAN), new ItemStack(Material.RED_DYE)};
private final DIMain plugin;
private final Map<Item, Long> bloodItems = new LinkedHashMap<>();
private final Set<EntityType> disabledEntities = new HashSet<>();
Expand Down Expand Up @@ -165,11 +167,15 @@ public void onPlayerDeath(PlayerDeathEvent e) {
return;
}
for (int i = 0; i < 14; i++) {
ItemStack is = new ItemStack(new ItemStack(Material.RED_DYE));
ItemStack is = BLOOD_ITEMS[i % 3];
ItemMeta meta = is.getItemMeta();
meta.setDisplayName(BLOOD_NAME);
is.setItemMeta(meta);
Item item = e.getEntity().getWorld().dropItemNaturally(e.getEntity().getLocation(), is);
// check if meta was already set for item on the array
if (!meta.hasDisplayName()) {
meta.setDisplayName(BLOOD_NAME);
meta.setLore(List.of(String.valueOf(i)));
is.setItemMeta(meta);
}
Item item = e.getEntity().getWorld().dropItemNaturally(e.getEntity().getEyeLocation(), is);
item.setPickupDelay(Integer.MAX_VALUE);
item.setVelocity(new Vector(random.nextDouble() * 0.1, 0.4, random.nextDouble() * 0.1));
bloodItems.put(item, System.currentTimeMillis());
Expand Down

0 comments on commit b356b73

Please sign in to comment.