Created
May 29, 2014 22:16
-
-
Save tobyp/96b59d6560b5ed3ebbbd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.tobyp.bukkit.annoyance; | |
import org.bukkit.ChatColor; | |
import org.bukkit.entity.Creeper; | |
import org.bukkit.entity.Entity; | |
import org.bukkit.entity.EntityType; | |
import org.bukkit.entity.Player; | |
import org.bukkit.event.EventHandler; | |
import org.bukkit.event.Listener; | |
import org.bukkit.event.entity.*; | |
import org.bukkit.event.player.AsyncPlayerChatEvent; | |
import org.bukkit.inventory.ItemStack; | |
import org.bukkit.plugin.java.JavaPlugin; | |
import org.bukkit.potion.PotionEffect; | |
import org.bukkit.potion.PotionEffectType; | |
import java.util.Random; | |
public class AnnoyancePlugin extends JavaPlugin implements Listener { | |
private static final Random rnd = new Random(); | |
int creeper_task; | |
int nausea_task; | |
int turnaround_task; | |
int hotbarscramble_task; | |
double creeper_chance = 0.1; | |
int creeper_period = 20*20; | |
double nausea_chance = 0.1; | |
int nausea_period = 4*20; | |
int nausea_duration = 2*20; | |
double chat_reverse_chance = 0.2; | |
int chat_nausea_limit = 20; | |
int chat_nausea_second_per = 20; | |
double turnaround_chance = 0.01; | |
int turnaround_period = 1*20; | |
double hotbarscramble_chance = 0.01; | |
int hotbarscramble_period = 1*20; | |
@Override | |
public void onEnable() { | |
getServer().getPluginManager().registerEvents(this, this); | |
creeper_task = getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { | |
@Override | |
public void run() { | |
for (Player p : getServer().getOnlinePlayers()) { | |
if (p.hasPermission("annoyance.creeper") && rnd.nextDouble() < creeper_chance) { | |
p.getWorld().spawnEntity(p.getLocation(), EntityType.CREEPER); | |
} | |
} | |
} | |
}, 0, creeper_period); | |
nausea_task = getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { | |
@Override | |
public void run() { | |
for (Player p : getServer().getOnlinePlayers()) { | |
if (p.hasPermission("annoyance.nausea") && rnd.nextDouble() < nausea_chance) { | |
p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, nausea_duration, 0)); | |
} | |
} | |
} | |
}, 0, nausea_period); | |
turnaround_task = getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { | |
@Override | |
public void run() { | |
for (Player p : getServer().getOnlinePlayers()) { | |
if (p.hasPermission("annoyance.turnaround") && rnd.nextDouble() < turnaround_chance) { | |
p.getLocation().setYaw((float)Math.PI - p.getLocation().getYaw()); | |
} | |
} | |
} | |
}, 0, turnaround_period); | |
hotbarscramble_task = getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { | |
@Override | |
public void run() { | |
for (Player p : getServer().getOnlinePlayers()) { | |
if (p.hasPermission("annoyance.hotbarscramble") && rnd.nextDouble() < hotbarscramble_chance) { | |
ItemStack is = p.getInventory().getItem(0); | |
for (int i=1; i<=8; i++) { | |
p.getInventory().setItem(i-1, p.getInventory().getItem(i)); | |
} | |
p.getInventory().setItem(8, is); | |
} | |
} | |
} | |
}, 0, hotbarscramble_period); | |
} | |
@Override | |
public void onDisable() { | |
getServer().getScheduler().cancelTask(creeper_task); | |
getServer().getScheduler().cancelTask(nausea_task); | |
getServer().getScheduler().cancelTask(turnaround_task); | |
} | |
@EventHandler | |
public void onChat(AsyncPlayerChatEvent e) { | |
if (e.getPlayer().hasPermission("annoyance.chat_reverse") && rnd.nextDouble() < chat_reverse_chance) { | |
e.setMessage(new StringBuilder(e.getMessage()).reverse().toString()); | |
if (e.getPlayer().hasPermission("annoyance.chat_nausea") && e.getMessage().length() > chat_nausea_limit) { | |
e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20*(e.getMessage().length()-chat_nausea_limit)/chat_nausea_second_per, 0)); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Annoyance | |
author: tobyp | |
main: net.tobyp.bukkit.annoyance.AnnoyancePlugin | |
version: 1.0.0 | |
permissions: | |
annoyance.creeper: | |
default: false | |
annoyance.nausea: | |
default: false | |
annoyance.turnaround: | |
default: false | |
annoyance.hotbarscramble: | |
default: false | |
annoyance.chat_reverse: | |
default: false | |
annoyance.chat_nausea: | |
default: false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment