1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Fix Altar Item Swap Exploit

This commit is contained in:
dNiym 2019-08-03 12:54:45 -04:00
parent bf61b4a42f
commit 1f3f2c635d

View File

@ -1,13 +1,19 @@
package me.mrCookieSlime.Slimefun.AncientAltar;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import me.mrCookieSlime.Slimefun.SlimefunStartup;
import me.mrCookieSlime.Slimefun.listeners.AncientAltarListener;
import me.mrCookieSlime.Slimefun.Variables;
import org.bukkit.*;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;
@ -23,6 +29,7 @@ public class RitualAnimation implements Runnable {
List<ItemStack> items;
List<Location> particles;
Map<Item,Location> itemLock = new HashMap<>();
boolean running;
int stage;
@ -38,11 +45,17 @@ public class RitualAnimation implements Runnable {
this.running = true;
this.stage = 0;
for(Block ped:this.pedestals) {
Item itm = AncientAltarListener.findItem(ped);
this.itemLock.put(itm, itm.getLocation().clone());
}
}
@Override
public void run() {
idle();
if(!checkLockedItems())
abort();
if(this.stage == 36) {
finish();
return;
@ -54,6 +67,15 @@ public class RitualAnimation implements Runnable {
SlimefunStartup.instance.getServer().getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, this, 8);
}
private boolean checkLockedItems() {
for(Item itm:this.itemLock.keySet())
if(itm.getLocation().distance(this.itemLock.get(itm)) > 0.3)
return false;
return true;
}
private void idle() {
try {
l.getWorld().spawnParticle(Particle.SPELL_WITCH, l,16, 1.2F, 0F, 1.2F);
@ -69,7 +91,12 @@ public class RitualAnimation implements Runnable {
private void checkPedestal(Block pedestal) {
Item item = AncientAltarListener.findItem(pedestal);
if (item == null) abort();
if(item == null || itemLock.remove(item) == null) {
abort();
}
else {
particles.add(pedestal.getLocation().add(0.5, 1.5, 0.5));
items.add(AncientAltarListener.fixItemStack(item.getItemStack(), item.getCustomName()));
@ -82,7 +109,9 @@ public class RitualAnimation implements Runnable {
e.printStackTrace();
}
itemLock.remove(item);
item.remove();
pedestal.removeMetadata("item_placed", SlimefunStartup.instance);
}
}
@ -96,6 +125,7 @@ public class RitualAnimation implements Runnable {
Variables.altarinuse.remove(altar.getLocation()); // should re-enable altar blocks on craft failure.
l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 5F, 1F);
itemLock.clear();
altars.remove(altar);
}