Revert change to non-deprecated function; fixes #4
Also some rebalancing changes
This commit is contained in:
parent
c4d8ad1441
commit
76bf3d93f9
|
@ -3,6 +3,7 @@ package ca.thetechrobo.smp;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -16,6 +17,7 @@ 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;
|
||||
|
@ -35,17 +37,15 @@ public class DeathListener implements Listener {
|
|||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
this.scores.addPlayerToScoreboard(e.getPlayer());
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler
|
||||
public void onPlayerUse(PlayerInteractEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
ItemStack i = p.getInventory().getItemInMainHand();
|
||||
if (!(i.hasItemMeta())) return;
|
||||
Life d = new Life();
|
||||
d.create();
|
||||
|
||||
Boolean rightclickair = (e.getAction() == Action.RIGHT_CLICK_AIR);
|
||||
if (!rightclickair) {
|
||||
Limbo.debug(p, this.scores);
|
||||
return;
|
||||
}
|
||||
Boolean heartblock = (i.getType() == Material.PLAYER_HEAD && rightclickair);
|
||||
|
@ -56,10 +56,27 @@ public class DeathListener implements Listener {
|
|||
p.getInventory().removeItem(newi);
|
||||
return;
|
||||
}
|
||||
if (!(i.hasDisplayName())) return;
|
||||
Boolean condition1a = (i.getItemMeta().displayName().equals(Component.text(d.dn)));
|
||||
if (!(i.getItemMeta().hasDisplayName())) {
|
||||
return;
|
||||
}
|
||||
// Gets at least up to here.
|
||||
Life d = new Life();
|
||||
d.create();
|
||||
Boolean condition1a = (i.getItemMeta().getDisplayName().equals(d.dn));
|
||||
// DO NOT CHANGE THIS TO
|
||||
// i.getItemMeta().displayName().equals(Component.text(d.dn))
|
||||
// IT DOES NOT WORK. I am sick of figuring out why.
|
||||
// It caused many minutes of frustration at the computer.
|
||||
// Just... don't.
|
||||
// Unless you're ready to deal with insanity.
|
||||
Boolean condition1b = (i.getType() == d.m);
|
||||
Boolean lifeblock = (condition1a && condition1b && rightclickair);
|
||||
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);
|
||||
|
@ -67,7 +84,8 @@ public class DeathListener implements Listener {
|
|||
}
|
||||
LifeExtractor f = new LifeExtractor();
|
||||
f.create();
|
||||
if ((i.getType() == f.m) && (i.getItemMeta().displayName().equals(Component.text(f.dn)))) {
|
||||
Bukkit.broadcast(Component.text((i.getType() == f.m) && (i.getItemMeta().displayName().equals(Component.text(f.dn)))));
|
||||
if ((i.getType() == f.m) && (i.getItemMeta().getDisplayName().equals(f.dn))) {
|
||||
if (p.getInventory().firstEmpty() == (-1)) {
|
||||
p.sendMessage("§4Not enough room in your inventory.");
|
||||
p.playSound(p, Sound.ENTITY_ENDERMAN_TELEPORT, 76, 0);
|
||||
|
|
|
@ -38,7 +38,7 @@ public class DeleteMyData implements CommandExecutor {
|
|||
}
|
||||
if (number) {
|
||||
Player sender = (Player) senderr;
|
||||
if (args[0].equals(String.valueOf(this.scores.load(sender, "delete", null)))) {
|
||||
if (args[0].equals(String.valueOf(this.scores.load(sender, "delete", null, false)))) {
|
||||
Bukkit.getBanList(Type.NAME).addBan(sender.getName(), "Deleted data.", null, null);
|
||||
Component kickmsg = Component.text("Your server data has been ")
|
||||
.append(Component.text("irrecoverably deleted.")
|
||||
|
|
|
@ -54,9 +54,6 @@ public class ScoreboardWrapper {
|
|||
}
|
||||
return def;
|
||||
}
|
||||
public int load(Player p, String keystr, Integer def) {
|
||||
return load(p, keystr, def, true);
|
||||
}
|
||||
public int load(Player p, String keystr, Integer def, Boolean checkLowerThanOne) {
|
||||
NamespacedKey key = new NamespacedKey(this.plugin, keystr);
|
||||
PersistentDataContainer c = p.getPersistentDataContainer();
|
||||
|
@ -96,7 +93,7 @@ public class ScoreboardWrapper {
|
|||
lives.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
Score score = lives.getScore(p.getName());
|
||||
this.boards.put(p.getName(), temp);
|
||||
score.setScore(load(p, "lives", 2));
|
||||
score.setScore(load(p, "lives", 2, true));
|
||||
p.setScoreboard(this.boards.get(p.getName()));
|
||||
}
|
||||
public double dieHearts(Player p, double dec) {
|
||||
|
@ -108,6 +105,10 @@ public class ScoreboardWrapper {
|
|||
neww = 4.0;
|
||||
die(p, 1);
|
||||
}
|
||||
return setHearts(p, neww);
|
||||
}
|
||||
public double setHearts(Player p, double neww) {
|
||||
AttributeInstance access = p.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||
access.setBaseValue(neww);
|
||||
return neww;
|
||||
}
|
||||
|
@ -124,6 +125,7 @@ public class ScoreboardWrapper {
|
|||
calendar.add(Calendar.DAY_OF_YEAR, 5);
|
||||
Date date = calendar.getTime();
|
||||
Bukkit.getBanList(Type.NAME).addBan(p.getName(), "Ran out of lives.", date, null);
|
||||
setHearts(p, 16.0);
|
||||
Component kickmsg = Component.text("Ran out of lives. Come back later.");
|
||||
p.kick(kickmsg);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue