Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gamebuster19901.test;
- import java.util.HashSet;
- import org.bukkit.block.Block;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.BlockRedstoneEvent;
- import org.bukkit.plugin.java.JavaPlugin;
- import net.md_5.bungee.api.ChatColor;
- public final class TestPlugin extends JavaPlugin implements Listener{
- private boolean isOff = false;
- private int pauseTime = 0;
- private HashSet<Block> stoppedRedstones = new HashSet<Block>();
- private final short max_redstones = 20;
- public final void onEnable(){
- getServer().getPluginManager().registerEvents(this, this);
- getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
- public void run() {
- if (!isOff){
- if(pauseTime != 0){
- pauseTime--;
- getLogger().info(pauseTime + "");
- }
- if (stoppedRedstones.size() != 0 && stoppedRedstones.size() - max_redstones > 0){
- getLogger().info("Stopped " + stoppedRedstones.size() + "redstone events");
- }
- reset();
- }
- }
- },1,1);
- getLogger().info("Test plugin has been enabled");
- }
- public final void onDisable() {
- isOff = true;
- }
- @EventHandler
- public void onRedstone(BlockRedstoneEvent event){
- stoppedRedstones.add(event.getBlock()); //hashsets only allow one instance of an object in them, don't need to worry about duplicates!
- getLogger().info(stoppedRedstones.size() + " redstone events fired this tick so far");
- if (stoppedRedstones.size() > max_redstones && pauseTime == 0){
- event.setNewCurrent(0);
- pause(400);
- }
- else if (pauseTime != 0){
- event.setNewCurrent(0);
- }
- }
- public void reset(){
- stoppedRedstones.clear();
- }
- public void pause(int ticks){
- getLogger().info("Stopping all redstone for " + ticks + " ticks");
- pauseTime = ticks;
- for (Player p : getServer().getOnlinePlayers()){
- //if player can build in the house{
- p.sendMessage(ChatColor.RED + "Oh no, your house has Overheated! Redstone in your house has been disabled for " + ChatColor.BOLD + ChatColor.RED + ticks / 20 + ChatColor.RESET + ChatColor.RED + " seconds.");
- p.sendMessage(ChatColor.RED + "To prevent this from happening again, make sure less than " + max_redstones + " redstone blocks change per tick!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement