Add heartextractor; small refactorings

This commit is contained in:
TheTechRobo 2022-04-07 18:21:36 -04:00
parent 4ea21a8d75
commit b757b8ebf5
5 changed files with 54 additions and 12 deletions

6
config.yml Normal file
View File

@ -0,0 +1,6 @@
healthAfterUnban: 16.0 # 8 hearts
banDuration: 5 # days
onDeathRemove: 4.0 # 2 hearts
headsGive: 4.0 # 2 hearts
lifextractorEnabled: true
startingLives: 2 # different than hearts

View File

@ -17,7 +17,6 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
public class DeathListener implements Listener {
public ScoreboardWrapper scores;
@ -25,13 +24,17 @@ public class DeathListener implements Listener {
@EventHandler
public void onDeath(PlayerDeathEvent e) {
this.scores.dieHearts(e.getEntity(), 4);
ItemStack skull = rethead(e.getEntity());
e.getEntity().getWorld().dropItemNaturally(e.getEntity().getLocation(), skull);
}
public ItemStack rethead(Player p) {
ItemStack skull = new ItemStack(Material.PLAYER_HEAD);
SkullMeta meta = (SkullMeta) skull.getItemMeta();
meta.setOwningPlayer(e.getEntity());
meta.setOwningPlayer(p);
meta.setLore(this.skulllore);
ItemMeta newmeta = this.scores.save(meta, 69, "IsDroppedSkull");
skull.setItemMeta(newmeta);
e.getEntity().getWorld().dropItemNaturally(e.getEntity().getLocation(), skull);
return skull;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
@ -71,12 +74,6 @@ public class DeathListener implements Listener {
// Unless you're ready to deal with insanity.
Boolean condition1b = (i.getType() == d.m);
Boolean lifeblock = (condition1a && condition1b);
Bukkit.broadcast(
Component.text(condition1a).color(TextColor.color(255, 0, 0))
.append(Component.text(condition1b).color(TextColor.color(0, 255, 0)))
);
Bukkit.broadcast(i.getItemMeta().displayName());
Bukkit.broadcast(Component.text(d.dn));
if (lifeblock) {
this.scores.die(p, -1);
p.getInventory().removeItem(d.item);
@ -99,6 +96,22 @@ public class DeathListener implements Listener {
this.scores.die(p, 1);
d.add(p);
}
HeartExtratrator he = new HeartExtratrator();
he.create();
if ((i.getType() == he.m) && (i.getItemMeta().getDisplayName().equals(he.dn))) {
if (p.getInventory().firstEmpty() == (-1)) {
p.sendMessage("§4Not enough room in your inventory.");
p.playSound(p, Sound.ENTITY_ENDERMAN_TELEPORT, 76, 0);
return;
}
if (this.scores.dieHearts(p, 0) <= 8.0) {
p.sendMessage("§4Performing this operation will cause you to lose a life. Cancelled.");
p.playSound(p, Sound.ENTITY_ENDERMAN_TELEPORT, 69, 0);
return;
}
this.scores.dieHearts(p, 8);
p.getInventory().addItem(rethead(p));
}
}
public void initialise(LifestealPlugin pl) {
this.scores = new ScoreboardWrapper();

View File

@ -0,0 +1,16 @@
package ca.thetechrobo.smp;
import java.util.ArrayList;
import org.bukkit.Material;
public class HeartExtratrator extends SuperLife {
public void create() {
this.lore = new ArrayList<String>();
this.lore.add("Right-click to convert FOUR of your hearts");
this.lore.add("into a single head...");
this.m = Material.STONE_HOE;
this.dn = "§3Extractor⭐§dDeHeart";
supercreate();
}
}

View File

@ -36,6 +36,16 @@ public class LifestealPlugin extends JavaPlugin {
recipe.shape("NN ", "NN ", " ");
recipe.setIngredient('N', Material.NETHERITE_BLOCK);
Bukkit.addRecipe(recipe);
HeartExtratrator heartdeheart = new HeartExtratrator();
heartdeheart.create();
item = heartdeheart.item;
key = new NamespacedKey(this, "MasqueDeMasque");
recipe = new ShapedRecipe(key, item);
recipe.shape("BS ", "BS ", " S ");
recipe.setIngredient('B', Material.BUCKET);
recipe.setIngredient('S', Material.STICK);
Bukkit.addRecipe(recipe);
}
@Override
public void onEnable() {

View File

@ -23,7 +23,4 @@ public class SuperLife {
public void add(Player p) {
p.getInventory().addItem(this.item);
}
public void changeTo3() {
this.item.setAmount(3);
}
}