**Major Security Fix:** Fix item duping when banned

This commit is contained in:
TheTechRobo 2022-04-08 17:30:02 -04:00
parent b757b8ebf5
commit deb8542abe
4 changed files with 17 additions and 13 deletions

View File

@ -16,8 +16,6 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import net.kyori.adventure.text.Component;
public class DeathListener implements Listener {
public ScoreboardWrapper scores;
private ArrayList<String> skulllore;
@ -39,6 +37,14 @@ public class DeathListener implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
this.scores.addPlayerToScoreboard(e.getPlayer());
// v ITEM DUPING PREVENTION
Boolean banned = (this.scores.load(e.getPlayer(), "bannedByLSPLUGIN", 0, false) == 1);
if (banned) {
e.getPlayer().getInventory().clear();
Bukkit.getLogger().info("Player was UNBANNED after being BANNED.");
this.scores.save(e.getPlayer(), 0, "bannedByLSPLUGIN");
}
// ^ ITEM DUPING PREVENTION
}
@SuppressWarnings("deprecation")
@EventHandler
@ -62,7 +68,6 @@ public class DeathListener implements Listener {
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));
@ -81,7 +86,6 @@ public class DeathListener implements Listener {
}
LifeExtractor f = new LifeExtractor();
f.create();
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.");

View File

@ -21,7 +21,6 @@ public class LifestealPlugin extends JavaPlugin {
Life life = new Life();
life.create();
//life.changeTo3(); // removed for balancing
item = life.item;
key = new NamespacedKey(this, "life");
recipe = new ShapedRecipe(key, item);

View File

@ -26,12 +26,12 @@ public class Limbo {
p.sendMessage(Component.text("You are in Limbo for the next 5 days. A peaceful place, with no one to hear you ")
.append(Component.text(" scream...").color(TextColor.color(255, 0, 0))));
}
public static void debug(Player p, ScoreboardWrapper sw) {
long currentTS = Instant.now().getEpochSecond();
long expiry = sw.loadLong(p, "banExpires", 0L);
Boolean hi = (expiry < currentTS);
sw.load(p, "prebanX", 0, false);
sw.load(p, "prebanY", 0, false);
sw.load(p, "prebanZ", 0, false);
}
//public static void debug(Player p, ScoreboardWrapper sw) {
// long currentTS = Instant.now().getEpochSecond();
// long expiry = sw.loadLong(p, "banExpires", 0L);
// Boolean hi = (expiry < currentTS);
// sw.load(p, "prebanX", 0, false);
// sw.load(p, "prebanY", 0, false);
// sw.load(p, "prebanZ", 0, false);
//}
}

View File

@ -126,6 +126,7 @@ public class ScoreboardWrapper {
Date date = calendar.getTime();
Bukkit.getBanList(Type.NAME).addBan(p.getName(), "Ran out of lives.", date, null);
setHearts(p, 16.0);
save(p, 1, "bannedByLSPLUGIN");
Component kickmsg = Component.text("Ran out of lives. Come back later.");
p.kick(kickmsg);
}