use of org.bukkit.event.EventHandler in project TotalFreedomMod by TotalFreedom.
the class RollbackManager method onPlayerInteract.
@EventHandler(ignoreCancelled = false)
public void onPlayerInteract(PlayerInteractEvent event) {
final Player player = event.getPlayer();
if (!event.hasItem() || event.getItem().getType() != Material.STICK || !plugin.al.isAdmin(player)) {
return;
}
event.setCancelled(true);
final Location location = DepreciationAggregator.getTargetBlock(player, null, 5).getLocation();
final List<RollbackEntry> entries = plugin.rb.getEntriesAtLocation(location);
if (entries.isEmpty()) {
FUtil.playerMsg(player, "No block edits at that location.");
return;
}
FUtil.playerMsg(player, "Block edits at (" + ChatColor.WHITE + "x" + location.getBlockX() + ", y" + location.getBlockY() + ", z" + location.getBlockZ() + ChatColor.BLUE + ")" + ChatColor.WHITE + ":", ChatColor.BLUE);
for (RollbackEntry entry : entries) {
FUtil.playerMsg(player, " - " + ChatColor.BLUE + entry.author + " " + entry.getType() + " " + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase()) + (entry.data == 0 ? "" : ":" + entry.data));
}
}
use of org.bukkit.event.EventHandler in project GameCore by Warvale.
the class Preferences method onPlayerInteract.
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Action a = event.getAction();
ItemStack is = event.getItem();
if (a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
return;
if (is.getType() == Material.REDSTONE_COMPARATOR)
tsGUI(event.getPlayer());
if (Main.getTeams().getSpectatorTeam().getEntries().contains(event.getPlayer().getName())) {
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.BLOCK_ENDERCHEST_OPEN, 1, 1);
}
}
use of org.bukkit.event.EventHandler in project GameCore by Warvale.
the class TeamSelect method onMove.
@EventHandler(priority = EventPriority.HIGHEST)
public void onMove(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
if (!event.getInventory().equals(inv)) {
if (Main.getTeams().getSpectatorTeam().getEntries().contains(event.getWhoClicked().getName())) {
event.setCancelled(true);
return;
}
}
switch(event.getSlot()) {
case // Join red
3:
if (event.getInventory().equals(inv)) {
Main.getTeams().getRedTeam().addEntry(event.getWhoClicked().getName());
event.getWhoClicked().sendMessage(ChatColor.GRAY + "You joined team " + ChatColor.RED + "red");
for (PotionEffect effect : event.getWhoClicked().getActivePotionEffects()) event.getWhoClicked().removePotionEffect(effect.getType());
player.playSound(player.getLocation(), Sound.BLOCK_ENDERCHEST_OPEN, 1, 1);
if (GameStart.initActive) {
player.sendMessage(org.bukkit.ChatColor.RED.toString() + org.bukkit.ChatColor.BOLD + "/vote #" + org.bukkit.ChatColor.BLUE.toString() + org.bukkit.ChatColor.BOLD + " to vote for a map!" + org.bukkit.ChatColor.DARK_BLUE + "\n1: Redwood Forest" + "\n2: Volcano Island" + "\n3: Pagoda Everglade" + "\n4: Extraterrestrial");
}
if (Main.getTeams().getRedTeam().getSize() >= 1 && Main.getTeams().getBlueTeam().getSize() >= 1 && !GameStart.initActive) {
GameStart.startCountdown();
}
event.setCancelled(true);
player.closeInventory();
}
break;
case // Close menu
4:
if (event.getInventory().equals(inv)) {
event.setCancelled(true);
player.playSound(player.getLocation(), Sound.BLOCK_ENDERCHEST_CLOSE, 1, 1);
player.closeInventory();
}
break;
case // Join blue
5:
if (event.getInventory().equals(inv)) {
Main.getTeams().getBlueTeam().addEntry(event.getWhoClicked().getName());
event.getWhoClicked().sendMessage(ChatColor.GRAY + "You joined team " + ChatColor.DARK_AQUA + "blue");
for (PotionEffect effect : event.getWhoClicked().getActivePotionEffects()) event.getWhoClicked().removePotionEffect(effect.getType());
player.playSound(player.getLocation(), Sound.BLOCK_ENDERCHEST_OPEN, 1, 1);
if (GameStart.initActive) {
player.sendMessage(org.bukkit.ChatColor.RED.toString() + org.bukkit.ChatColor.BOLD + "/vote #" + org.bukkit.ChatColor.BLUE.toString() + org.bukkit.ChatColor.BOLD + " to vote for a map!" + org.bukkit.ChatColor.DARK_BLUE + "\n1: Redwood Forest" + "\n2: Volcano Island" + "\n3: Pagoda Everglade" + "\n4: Extraterrestrial");
}
if (Main.getTeams().getRedTeam().getSize() >= 1 && Main.getTeams().getBlueTeam().getSize() >= 1 && !GameStart.initActive) {
GameStart.startCountdown();
}
event.setCancelled(true);
player.closeInventory();
}
break;
default:
if (Main.getTeams().getSpectatorTeam().getEntries().contains(event.getWhoClicked().getName())) {
event.setCancelled(true);
break;
}
}
}
use of org.bukkit.event.EventHandler in project GameCore by Warvale.
the class TeamSelect method onPlayerInteract.
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Action a = event.getAction();
ItemStack is = event.getItem();
if (a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
return;
if (is.getType() == Material.ENCHANTED_BOOK)
tsGUI(event.getPlayer());
if (Main.getTeams().getSpectatorTeam().getEntries().contains(event.getPlayer().getName())) {
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.BLOCK_ENDERCHEST_OPEN, 1, 1);
}
}
use of org.bukkit.event.EventHandler in project GameCore by Warvale.
the class GlobalEvent method onBlockBreak.
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
if (event.getBlock().getType().equals(Material.IRON_ORE)) {
event.getPlayer().giveExp(10);
for (int i = 0; i < NumberUtils.random(3, 1); i++) {
event.getPlayer().getInventory().addItem(new ItemStack(Material.IRON_INGOT));
}
event.setCancelled(true);
Location blockLoc = event.getBlock().getLocation();
event.getBlock().setType(Material.STONE);
List<Entity> entityList = new ArrayList<>();
for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
ItemStack stack = new ItemStack(Material.IRON_NUGGET);
stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
}
new BukkitRunnable() {
@Override
public void run() {
entityList.forEach(Entity::remove);
}
}.runTaskLater(Main.get(), 60L);
new BukkitRunnable() {
@Override
public void run() {
event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.IRON_ORE);
event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 5, 1);
}
}.runTaskLater(Main.get(), 400L);
}
if (event.getBlock().getType().equals(Material.GOLD_ORE)) {
event.getPlayer().giveExp(30);
for (int i = 0; i < NumberUtils.random(2, 0); i++) {
event.getPlayer().getInventory().addItem(new ItemStack(Material.GOLD_INGOT));
}
event.setCancelled(true);
Location blockLoc = event.getBlock().getLocation();
event.getBlock().setType(Material.STONE);
List<Entity> entityList = new ArrayList<>();
for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
ItemStack stack = new ItemStack(Material.GOLD_NUGGET);
stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
}
new BukkitRunnable() {
@Override
public void run() {
entityList.stream().forEach(entity -> entity.remove());
}
}.runTaskLater(Main.get(), 60L);
new BukkitRunnable() {
@Override
public void run() {
event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.GOLD_ORE);
event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 10, 1);
}
}.runTaskLater(Main.get(), 400L);
}
if (event.getBlock().getType().equals(Material.DIAMOND_ORE)) {
event.getPlayer().giveExp(50);
for (int i = 0; i < NumberUtils.random(1, 0); i++) {
event.getPlayer().getInventory().addItem(new ItemStack(Material.DIAMOND));
}
event.setCancelled(true);
Location blockLoc = event.getBlock().getLocation();
event.getBlock().setType(Material.STONE);
List<Entity> entityList = new ArrayList<>();
for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
ItemStack stack = new ItemStack(Material.PRISMARINE_CRYSTALS);
stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
}
new BukkitRunnable() {
@Override
public void run() {
entityList.stream().forEach(entity -> entity.remove());
}
}.runTaskLater(Main.get(), 60L);
new BukkitRunnable() {
@Override
public void run() {
event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.DIAMOND_ORE);
event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 25, 1);
}
}.runTaskLater(Main.get(), 400L);
}
if (event.getBlock().getType().equals(Material.LAPIS_ORE)) {
event.getPlayer().giveExp(50);
for (int i = 0; i < NumberUtils.random(1, 0); i++) {
event.getPlayer().getInventory().addItem(new ItemStack(Material.LAPIS_BLOCK));
}
event.setCancelled(true);
Location blockLoc = event.getBlock().getLocation();
event.getBlock().setType(Material.STONE);
List<Entity> entityList = new ArrayList<>();
for (int i = 0; i < NumberUtils.random(5, 2) + 1; i++) {
ItemStack stack = new ItemStack(Material.EYE_OF_ENDER);
stack.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, NumberUtils.random(100, 1));
entityList.add(event.getPlayer().getWorld().dropItemNaturally(event.getBlock().getLocation().setDirection(Vector.getRandom()).add(Vector.getRandom()), stack));
}
new BukkitRunnable() {
@Override
public void run() {
entityList.stream().forEach(entity -> entity.remove());
}
}.runTaskLater(Main.get(), 60L);
new BukkitRunnable() {
@Override
public void run() {
event.getPlayer().getWorld().getBlockAt(blockLoc).setType(Material.LAPIS_ORE);
event.getPlayer().getWorld().playSound(blockLoc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 15, 1);
}
}.runTaskLater(Main.get(), 400L);
}
}
Aggregations