Search in sources :

Example 31 with Location

use of org.bukkit.Location in project TotalFreedomMod by TotalFreedom.

the class ProtectArea method isInProtectedArea.

public boolean isInProtectedArea(final Vector min, final Vector max, final String worldName) {
    boolean doSave = false;
    boolean inProtectedArea = false;
    final Iterator<Map.Entry<String, SerializableProtectedRegion>> it = areas.entrySet().iterator();
    while (it.hasNext()) {
        final SerializableProtectedRegion region = it.next().getValue();
        Location regionCenter = null;
        try {
            regionCenter = region.getLocation();
        } catch (SerializableProtectedRegion.CantFindWorldException ex) {
            it.remove();
            doSave = true;
            continue;
        }
        if (regionCenter != null) {
            if (worldName.equals(regionCenter.getWorld().getName())) {
                if (cubeIntersectsSphere(min, max, regionCenter.toVector(), region.getRadius())) {
                    inProtectedArea = true;
                    break;
                }
            }
        }
    }
    if (doSave) {
        save();
    }
    return inProtectedArea;
}
Also used : ConfigEntry(me.totalfreedom.totalfreedommod.config.ConfigEntry) Location(org.bukkit.Location)

Example 32 with Location

use of org.bukkit.Location in project TotalFreedomMod by TotalFreedom.

the class ProtectArea method onBlockBreak.

@EventHandler(priority = EventPriority.NORMAL)
public void onBlockBreak(BlockBreakEvent event) {
    if (!ConfigEntry.PROTECTAREA_ENABLED.getBoolean()) {
        return;
    }
    final Player player = event.getPlayer();
    if (plugin.al.isAdmin(player)) {
        return;
    }
    final Location location = event.getBlock().getLocation();
    if (isInProtectedArea(location)) {
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 33 with Location

use of org.bukkit.Location in project TotalFreedomMod by TotalFreedom.

the class AntiNuke method onBlockPlace.

@EventHandler(priority = EventPriority.HIGH)
public void onBlockPlace(BlockPlaceEvent event) {
    if (!ConfigEntry.NUKE_MONITOR_ENABLED.getBoolean()) {
        return;
    }
    Player player = event.getPlayer();
    Location blockLocation = event.getBlock().getLocation();
    FPlayer fPlayer = plugin.pl.getPlayer(player);
    Location playerLocation = player.getLocation();
    double nukeMonitorRange = ConfigEntry.NUKE_MONITOR_RANGE.getDouble();
    boolean outOfRange = false;
    if (!playerLocation.getWorld().equals(blockLocation.getWorld())) {
        outOfRange = true;
    } else if (playerLocation.distanceSquared(blockLocation) > (nukeMonitorRange * nukeMonitorRange)) {
        outOfRange = true;
    }
    if (outOfRange) {
        if (fPlayer.incrementAndGetFreecamPlaceCount() > ConfigEntry.FREECAM_TRIGGER_COUNT.getInteger()) {
            FUtil.bcastMsg(player.getName() + " has been flagged for possible freecam building.", ChatColor.RED);
            plugin.ae.autoEject(player, "Freecam (extended range) block building is not permitted on this server.");
            fPlayer.resetFreecamPlaceCount();
            event.setCancelled(true);
            return;
        }
    }
    if (fPlayer.incrementAndGetBlockPlaceCount() > ConfigEntry.NUKE_MONITOR_COUNT_PLACE.getInteger()) {
        FUtil.bcastMsg(player.getName() + " is placing blocks too fast!", ChatColor.RED);
        plugin.ae.autoEject(player, "You are placing blocks too fast.");
        fPlayer.resetBlockPlaceCount();
        event.setCancelled(true);
    }
}
Also used : FPlayer(me.totalfreedom.totalfreedommod.player.FPlayer) FPlayer(me.totalfreedom.totalfreedommod.player.FPlayer) Player(org.bukkit.entity.Player) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 34 with Location

use of org.bukkit.Location in project TotalFreedomMod by TotalFreedom.

the class Command_dispfill method run.

@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
    if (args.length == 2) {
        int radius;
        try {
            radius = Math.max(5, Math.min(25, Integer.parseInt(args[0])));
        } catch (NumberFormatException ex) {
            sender.sendMessage("Invalid radius.");
            return true;
        }
        final List<ItemStack> items = new ArrayList<>();
        final String[] itemsRaw = StringUtils.split(args[1], ",");
        for (final String searchItem : itemsRaw) {
            Material material = Material.matchMaterial(searchItem);
            if (material == null) {
                try {
                    material = DepreciationAggregator.getMaterial(Integer.parseInt(searchItem));
                } catch (NumberFormatException ex) {
                }
            }
            if (material != null) {
                items.add(new ItemStack(material, 64));
            } else {
                sender.sendMessage("Skipping invalid item: " + searchItem);
            }
        }
        final ItemStack[] itemsArray = items.toArray(new ItemStack[items.size()]);
        int affected = 0;
        final Location centerLocation = playerSender.getLocation();
        final Block centerBlock = centerLocation.getBlock();
        for (int xOffset = -radius; xOffset <= radius; xOffset++) {
            for (int yOffset = -radius; yOffset <= radius; yOffset++) {
                for (int zOffset = -radius; zOffset <= radius; zOffset++) {
                    final Block targetBlock = centerBlock.getRelative(xOffset, yOffset, zOffset);
                    if (targetBlock.getLocation().distanceSquared(centerLocation) < (radius * radius)) {
                        if (targetBlock.getType().equals(Material.DISPENSER)) {
                            sender.sendMessage("Filling dispenser @ " + FUtil.formatLocation(targetBlock.getLocation()));
                            setDispenserContents(targetBlock, itemsArray);
                            affected++;
                        }
                    }
                }
            }
        }
        sender.sendMessage("Done. " + affected + " dispenser(s) filled.");
    } else {
        return false;
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location)

Example 35 with Location

use of org.bukkit.Location in project TotalFreedomMod by TotalFreedom.

the class Command_gtfo method run.

@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
    if (args.length == 0) {
        return false;
    }
    final Player player = getPlayer(args[0]);
    if (player == null) {
        msg(FreedomCommand.PLAYER_NOT_FOUND, ChatColor.RED);
        return true;
    }
    String reason = null;
    if (args.length >= 2) {
        reason = StringUtils.join(ArrayUtils.subarray(args, 1, args.length), " ");
    }
    FUtil.bcastMsg(player.getName() + " has been a VERY naughty, naughty boy.", ChatColor.RED);
    // Undo WorldEdits
    try {
        plugin.web.undo(player, 15);
    } catch (NoClassDefFoundError ex) {
    }
    // Rollback
    plugin.rb.rollback(player.getName());
    // Deop
    player.setOp(false);
    // Gamemode suvival
    player.setGameMode(GameMode.SURVIVAL);
    // Clear inventory
    player.getInventory().clear();
    // Strike with lightning
    final Location targetPos = player.getLocation();
    for (int x = -1; x <= 1; x++) {
        for (int z = -1; z <= 1; z++) {
            final Location strike_pos = new Location(targetPos.getWorld(), targetPos.getBlockX() + x, targetPos.getBlockY(), targetPos.getBlockZ() + z);
            targetPos.getWorld().strikeLightning(strike_pos);
        }
    }
    String ip = FUtil.getFuzzyIp(Ips.getIp(player));
    // Broadcast
    final StringBuilder bcast = new StringBuilder().append(ChatColor.RED).append("Banning: ").append(player.getName()).append(", IP: ").append(ip);
    if (reason != null) {
        bcast.append(" - Reason: ").append(ChatColor.YELLOW).append(reason);
    }
    FUtil.bcastMsg(bcast.toString());
    // Ban player
    plugin.bm.addBan(Ban.forPlayerFuzzy(player, sender, null, reason));
    // Kick player
    player.kickPlayer(ChatColor.RED + "GTFO");
    return true;
}
Also used : Player(org.bukkit.entity.Player) Location(org.bukkit.Location)

Aggregations

Location (org.bukkit.Location)470 Player (org.bukkit.entity.Player)120 World (org.bukkit.World)63 EventHandler (org.bukkit.event.EventHandler)54 Vector (org.bukkit.util.Vector)45 Test (org.junit.Test)43 ArrayList (java.util.ArrayList)36 Block (org.bukkit.block.Block)31 Entity (org.bukkit.entity.Entity)28 UUID (java.util.UUID)27 ItemStack (org.bukkit.inventory.ItemStack)22 LivingEntity (org.bukkit.entity.LivingEntity)20 PotionEffect (org.bukkit.potion.PotionEffect)17 User (com.earth2me.essentials.User)16 List (java.util.List)16 IOException (java.io.IOException)15 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)14 LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)14 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)14 Island (com.wasteofplastic.acidisland.Island)12