forked from stefatorus/LagAssist
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
2.5 KiB
110 lines
2.5 KiB
3 years ago
|
package com.entryrise.lagassist;
|
||
4 years ago
|
|
||
|
import java.util.SplittableRandom;
|
||
|
|
||
|
import org.bukkit.Bukkit;
|
||
|
import org.bukkit.Material;
|
||
|
import org.bukkit.block.Block;
|
||
|
import org.bukkit.event.EventHandler;
|
||
|
import org.bukkit.event.Listener;
|
||
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
||
|
import org.bukkit.event.block.BlockRedstoneEvent;
|
||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||
|
import org.bukkit.scheduler.BukkitTask;
|
||
|
|
||
3 years ago
|
import com.entryrise.lagassist.utils.V1_11;
|
||
|
import com.entryrise.lagassist.utils.WorldMgr;
|
||
4 years ago
|
|
||
|
public class Redstone implements Listener {
|
||
|
|
||
|
SplittableRandom sr = new SplittableRandom();
|
||
|
|
||
|
public static boolean redstoneculler;
|
||
|
|
||
|
private static boolean destructives;
|
||
|
private static int chance;
|
||
|
private static int ticks;
|
||
|
|
||
|
private static BukkitTask br;
|
||
|
|
||
|
public static void Enabler(boolean reload) {
|
||
|
redstoneculler = false;
|
||
|
destructives = Main.config.getBoolean("redstone-culler.destructive.enabled");
|
||
|
chance = Main.config.getInt("redstone-culler.chance");
|
||
|
ticks = Main.config.getInt("redstone-culler.ticks");
|
||
|
|
||
|
if (!reload) {
|
||
|
Main.p.getServer().getPluginManager().registerEvents(new Redstone(), Main.p);
|
||
|
}
|
||
|
|
||
|
Bukkit.getLogger().info(" §e[§a✔§e] §fRedstone Culler.");
|
||
|
}
|
||
|
|
||
|
public static void CullRedstone() {
|
||
|
if (!redstoneculler) {
|
||
|
redstoneculler = true;
|
||
|
setTimer();
|
||
|
} else if (Bukkit.getScheduler().isCurrentlyRunning(br.getTaskId())) {
|
||
|
br.cancel();
|
||
|
setTimer();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static void setTimer() {
|
||
|
br = new BukkitRunnable() {
|
||
|
@Override
|
||
|
public void run() {
|
||
|
redstoneculler = false;
|
||
4 years ago
|
V1_11.observerBreaker();
|
||
4 years ago
|
}
|
||
|
|
||
|
}.runTaskLater(Main.p, ticks);
|
||
|
}
|
||
|
|
||
|
@EventHandler
|
||
4 years ago
|
public void redstoneCuller(BlockRedstoneEvent e) {
|
||
4 years ago
|
if (!redstoneculler) {
|
||
|
return;
|
||
|
}
|
||
|
if (WorldMgr.isBlacklisted(e.getBlock().getWorld())) {
|
||
|
return;
|
||
|
}
|
||
|
e.setNewCurrent(0);
|
||
|
|
||
|
if (chance < 0) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
Block b = e.getBlock();
|
||
|
|
||
|
if (!Main.config.getStringList("redstone-culler.affected-materials").contains(b.getType().toString().toUpperCase())) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
int rand = sr.nextInt(100);
|
||
|
if (rand > chance) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
b.setType(Material.AIR);
|
||
|
}
|
||
|
|
||
|
@EventHandler
|
||
|
public void ObserverCuller(BlockPhysicsEvent e) {
|
||
|
if (redstoneculler) {
|
||
|
if (WorldMgr.isBlacklisted(e.getBlock().getWorld())) {
|
||
|
return;
|
||
|
}
|
||
4 years ago
|
// if (VersionMgr.isNewMaterials()) {
|
||
4 years ago
|
if (destructives) {
|
||
|
V1_11.ObserverAdd(e.getBlock());
|
||
|
}
|
||
|
if (V1_11.isObserver(e.getBlock())) {
|
||
|
e.setCancelled(true);
|
||
|
}
|
||
4 years ago
|
// }
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
|
}
|