parent
fa9eb9a1d2
commit
d070f47d2d
|
@ -5,7 +5,9 @@ import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
@ -25,6 +27,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
public class BlockBreakListener implements Listener {
|
public class BlockBreakListener implements Listener {
|
||||||
|
|
||||||
private final MineAlert plugin;
|
private final MineAlert plugin;
|
||||||
|
private final HashSet<Location> cache = new HashSet<>();
|
||||||
private final Map<Player, List<BlockEvent>> map = new HashMap<>();
|
private final Map<Player, List<BlockEvent>> map = new HashMap<>();
|
||||||
private final Queue<BlockEvent> queue = new ConcurrentLinkedQueue<>();
|
private final Queue<BlockEvent> queue = new ConcurrentLinkedQueue<>();
|
||||||
|
|
||||||
|
@ -38,14 +41,16 @@ public class BlockBreakListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
queue.add(new BlockEvent(event.getPlayer(), event.getBlock().getType(), true));
|
if (cache.contains(event.getBlock().getLocation())) return;
|
||||||
|
queue.add(new BlockEvent(event.getPlayer(), event.getBlock().getType(), event.getBlock().getLocation(), true));
|
||||||
|
|
||||||
int radius = this.plugin.getConfig().getInt("ore.radius", 3);
|
int radius = this.plugin.getConfig().getInt("ore.radius", 3);
|
||||||
for (int x = -radius; x < radius; x++) {
|
for (int x = -radius; x < radius; x++) {
|
||||||
for (int y = -radius; y < radius; y++) {
|
for (int y = -radius; y < radius; y++) {
|
||||||
for (int z = -radius; z < radius; z++) {
|
for (int z = -radius; z < radius; z++) {
|
||||||
if (x == 0 && y == 0 && z == 0) continue;
|
if (x == 0 && y == 0 && z == 0) continue;
|
||||||
queue.add(new BlockEvent(event.getPlayer(), event.getBlock().getRelative(x, y, z).getType(), false));
|
Block block = event.getBlock().getRelative(x, y, z);
|
||||||
|
queue.add(new BlockEvent(event.getPlayer(), block.getType(), block.getLocation(), false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +60,8 @@ public class BlockBreakListener implements Listener {
|
||||||
while (this.plugin.isEnabled()) {
|
while (this.plugin.isEnabled()) {
|
||||||
BlockEvent event = this.queue.poll();
|
BlockEvent event = this.queue.poll();
|
||||||
if (event != null) {
|
if (event != null) {
|
||||||
|
if (cache.contains(event.getLocation())) continue;
|
||||||
|
cache.add(event.getLocation());
|
||||||
for (String s: this.plugin.getConfig().getConfigurationSection("ore.blocks").getKeys(false)) {
|
for (String s: this.plugin.getConfig().getConfigurationSection("ore.blocks").getKeys(false)) {
|
||||||
if (Lang.getMaterialKey(event.getMaterial()).equals(s)) {
|
if (Lang.getMaterialKey(event.getMaterial()).equals(s)) {
|
||||||
addStrike(event);
|
addStrike(event);
|
||||||
|
@ -132,6 +139,7 @@ public class BlockBreakListener implements Listener {
|
||||||
"ore.purge"
|
"ore.purge"
|
||||||
);
|
);
|
||||||
if (new Date(e.getTime().getTime() + purge).before(now)) {
|
if (new Date(e.getTime().getTime() + purge).before(now)) {
|
||||||
|
cache.remove(e.getLocation());
|
||||||
events.remove();
|
events.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,12 +202,14 @@ public class BlockBreakListener implements Listener {
|
||||||
class BlockEvent {
|
class BlockEvent {
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final Material material;
|
private final Material material;
|
||||||
|
private final Location location;
|
||||||
private final Boolean parent;
|
private final Boolean parent;
|
||||||
private final Date time;
|
private final Date time;
|
||||||
|
|
||||||
BlockEvent(Player player, Material material, Boolean parent) {
|
BlockEvent(Player player, Material material, Location location, Boolean parent) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.material = material;
|
this.material = material;
|
||||||
|
this.location = location;
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.time = Calendar.getInstance().getTime();
|
this.time = Calendar.getInstance().getTime();
|
||||||
}
|
}
|
||||||
|
@ -212,6 +222,10 @@ class BlockEvent {
|
||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
public Boolean isParent() {
|
public Boolean isParent() {
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue