mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 11:45:51 +00:00
Fix Altar Item Swap Exploit
This commit is contained in:
parent
bf61b4a42f
commit
1f3f2c635d
@ -1,13 +1,19 @@
|
|||||||
package me.mrCookieSlime.Slimefun.AncientAltar;
|
package me.mrCookieSlime.Slimefun.AncientAltar;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import me.mrCookieSlime.Slimefun.SlimefunStartup;
|
import me.mrCookieSlime.Slimefun.SlimefunStartup;
|
||||||
import me.mrCookieSlime.Slimefun.listeners.AncientAltarListener;
|
import me.mrCookieSlime.Slimefun.listeners.AncientAltarListener;
|
||||||
import me.mrCookieSlime.Slimefun.Variables;
|
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.block.Block;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -23,6 +29,7 @@ public class RitualAnimation implements Runnable {
|
|||||||
List<ItemStack> items;
|
List<ItemStack> items;
|
||||||
|
|
||||||
List<Location> particles;
|
List<Location> particles;
|
||||||
|
Map<Item,Location> itemLock = new HashMap<>();
|
||||||
|
|
||||||
boolean running;
|
boolean running;
|
||||||
int stage;
|
int stage;
|
||||||
@ -38,11 +45,17 @@ public class RitualAnimation implements Runnable {
|
|||||||
|
|
||||||
this.running = true;
|
this.running = true;
|
||||||
this.stage = 0;
|
this.stage = 0;
|
||||||
|
for(Block ped:this.pedestals) {
|
||||||
|
Item itm = AncientAltarListener.findItem(ped);
|
||||||
|
this.itemLock.put(itm, itm.getLocation().clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
idle();
|
idle();
|
||||||
|
if(!checkLockedItems())
|
||||||
|
abort();
|
||||||
if(this.stage == 36) {
|
if(this.stage == 36) {
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
@ -54,6 +67,15 @@ public class RitualAnimation implements Runnable {
|
|||||||
SlimefunStartup.instance.getServer().getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, this, 8);
|
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() {
|
private void idle() {
|
||||||
try {
|
try {
|
||||||
l.getWorld().spawnParticle(Particle.SPELL_WITCH, l,16, 1.2F, 0F, 1.2F);
|
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) {
|
private void checkPedestal(Block pedestal) {
|
||||||
Item item = AncientAltarListener.findItem(pedestal);
|
Item item = AncientAltarListener.findItem(pedestal);
|
||||||
if (item == null) abort();
|
|
||||||
|
|
||||||
|
if(item == null || itemLock.remove(item) == null) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
particles.add(pedestal.getLocation().add(0.5, 1.5, 0.5));
|
particles.add(pedestal.getLocation().add(0.5, 1.5, 0.5));
|
||||||
items.add(AncientAltarListener.fixItemStack(item.getItemStack(), item.getCustomName()));
|
items.add(AncientAltarListener.fixItemStack(item.getItemStack(), item.getCustomName()));
|
||||||
@ -82,7 +109,9 @@ public class RitualAnimation implements Runnable {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itemLock.remove(item);
|
||||||
item.remove();
|
item.remove();
|
||||||
|
|
||||||
pedestal.removeMetadata("item_placed", SlimefunStartup.instance);
|
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.
|
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);
|
l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 5F, 1F);
|
||||||
|
itemLock.clear();
|
||||||
altars.remove(altar);
|
altars.remove(altar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user