use of org.bukkit.Location 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.Location 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);
}
}
use of org.bukkit.Location in project GameCore by Warvale.
the class AbilityManager method onMove.
@EventHandler
public void onMove(PlayerMoveEvent e) {
if (!freeze.contains(e.getPlayer()))
return;
if (!electroCooldown.contains(e.getPlayer()))
return;
Location from = e.getFrom();
Location to = e.getTo();
double x = Math.floor(from.getX());
double z = Math.floor(from.getZ());
if (Math.floor(to.getX()) != x || Math.floor(to.getZ()) != z) {
x += .5;
z += .5;
e.getPlayer().teleport(new Location(from.getWorld(), x, from.getY(), z, from.getYaw(), from.getPitch()));
}
}
use of org.bukkit.Location in project Minigames by AddstarMC.
the class CTFFlag method spawnFlag.
public Location spawnFlag(Location location) {
Location blockBelow = location.clone();
Location newLocation = location.clone();
blockBelow.setY(blockBelow.getBlockY() - 1);
if (blockBelow.getBlock().getType() == Material.AIR) {
while (blockBelow.getBlock().getType() == Material.AIR) {
if (blockBelow.getY() > 1) {
blockBelow.setY(blockBelow.getY() - 1);
} else {
return null;
}
}
} else if (blockBelow.getBlock().getType() != Material.AIR) {
while (blockBelow.getBlock().getType() != Material.AIR) {
if (blockBelow.getY() < 255) {
blockBelow.setY(blockBelow.getY() + 1);
} else {
return null;
}
}
blockBelow.setY(blockBelow.getY() - 1);
}
if (blockBelow.getBlock().getType() == Material.FURNACE || blockBelow.getBlock().getType() == Material.DISPENSER || blockBelow.getBlock().getType() == Material.CHEST || blockBelow.getBlock().getType() == Material.BREWING_STAND || blockBelow.getBlock().getType() == Material.SIGN_POST || blockBelow.getBlock().getType() == Material.WALL_SIGN) {
blockBelow.setY(blockBelow.getY() + 1);
}
newLocation = blockBelow.clone();
newLocation.setY(newLocation.getY() + 1);
newLocation.getBlock().setType(Material.SIGN_POST);
Sign sign = (Sign) newLocation.getBlock().getState();
sign.setData(data);
originalBlock = blockBelow.getBlock().getState();
blockBelow.getBlock().setType(Material.BEDROCK);
if (newLocation != null) {
atHome = false;
for (int i = 0; i < 4; i++) {
sign.setLine(i, signText[i]);
}
sign.update();
currentLocation = newLocation.clone();
}
return newLocation;
}
use of org.bukkit.Location in project Minigames by AddstarMC.
the class RewardSign method signUse.
@Override
public boolean signUse(Sign sign, MinigamePlayer player) {
Location loc = sign.getLocation();
if (!MinigameUtils.isMinigameTool(player.getPlayer().getInventory().getItemInMainHand())) {
String label = sign.getLine(2).toLowerCase();
if (player.isInMinigame()) {
if (!player.hasTempClaimedReward(label)) {
if (mdata.hasRewardSign(loc)) {
Rewards rew = mdata.getRewardSign(loc);
for (RewardType r : rew.getReward()) {
r.giveReward(player);
}
}
player.addTempClaimedReward(label);
}
} else {
if (!player.hasClaimedReward(label)) {
if (mdata.hasRewardSign(loc)) {
Rewards rew = mdata.getRewardSign(loc);
for (RewardType r : rew.getReward()) {
r.giveReward(player);
}
player.updateInventory();
}
player.addClaimedReward(label);
}
}
} else if (player.getPlayer().hasPermission("minigame.tool")) {
Rewards rew = null;
if (!mdata.hasRewardSign(loc)) {
mdata.addRewardSign(loc);
}
rew = mdata.getRewardSign(loc);
Menu rewardMenu = new Menu(5, getName(), player);
rewardMenu.addItem(new MenuItemRewardGroupAdd("Add Group", Material.ITEM_FRAME, rew), 42);
rewardMenu.addItem(new MenuItemRewardAdd("Add Item", Material.ITEM_FRAME, rew), 43);
final MenuItemCustom mic = new MenuItemCustom("Save Rewards", Material.REDSTONE_TORCH_ON);
final Location floc = loc;
mic.setClick(new InteractionInterface() {
@Override
public Object interact(Object object) {
mdata.saveRewardSign(MinigameUtils.createLocationID(floc), true);
mic.getContainer().getViewer().sendMessage("Saved rewards for this sign.", null);
mic.getContainer().getViewer().getPlayer().closeInventory();
return null;
}
});
rewardMenu.addItem(mic, 44);
List<String> list = new ArrayList<String>();
for (RewardRarity r : RewardRarity.values()) {
list.add(r.toString());
}
List<MenuItem> mi = new ArrayList<MenuItem>();
for (RewardType item : rew.getRewards()) {
mi.add(item.getMenuItem());
}
List<String> des = new ArrayList<String>();
des.add("Double Click to edit");
for (RewardGroup group : rew.getGroups()) {
MenuItemRewardGroup rwg = new MenuItemRewardGroup(group.getName() + " Group", des, Material.CHEST, group, rew);
mi.add(rwg);
}
rewardMenu.addItems(mi);
rewardMenu.displayMenu(player);
}
return true;
}
Aggregations