Search in sources :

Example 86 with Region

use of br.net.fabiozumbi12.RedProtect.Sponge.Region in project RedProtect by FabioZumbi12.

the class RPBlockListener method onPistonEvent.

// TODO Test events
/*
    @Listener
    public void onListenEvent(TargetLivingEvent event) {    	
    	RedProtect.get().logger.severe("Event: "+ event.toString());
    }
    
    */
/*
	@Listener
	public void onVehicleBreak(DamageEntityEvent e){
		if (e.isCancelled()){
    		return;
    	}
		if (!(e.getAttacker() instanceof Player)){
			return;
		}
		Vehicle cart = e.getVehicle();
		Player p = (Player) e.getAttacker();
		Region r = RedProtect.get().rm.getTopRegion(cart.getLocation());
		if (r == null){
			return;
		}
		
		if (!r.canMinecart(p)){
			RPLang.sendMessage(p, "blocklistener.region.cantbreak");
			e.setCancelled(true);
			return;
		}
	}
	*/
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPistonEvent(ChangeBlockEvent.Pre e) {
    Location<World> piston = null;
    Location<World> block = null;
    boolean antih = RedProtect.get().cfgs.getBool("region-settings.anti-hopper");
    if (RedProtect.get().getPVHelper().checkCause(e.getCause(), "PISTON_EXTEND")) {
        if (RedProtect.get().cfgs.getBool("performance.disable-PistonEvent-handler")) {
            return;
        }
        List<Location<World>> locs = e.getLocations();
        for (Location<World> loc : locs) {
            if (piston == null) {
                piston = loc;
                continue;
            }
            block = loc;
        }
    }
    if (RedProtect.get().getPVHelper().checkCause(e.getCause(), "PISTON_RETRACT")) {
        if (RedProtect.get().cfgs.getBool("performance.disable-PistonEvent-handler")) {
            return;
        }
        List<Location<World>> locs = e.getLocations();
        for (Location<World> loc : locs) {
            if (piston == null) {
                piston = loc;
                continue;
            }
            block = loc;
        }
    }
    // process
    if (piston != null && block != null) {
        Region rPi = RedProtect.get().rm.getTopRegion(piston);
        Region rB = RedProtect.get().rm.getTopRegion(block);
        if (rPi == null && rB != null || (rPi != null && rB != null && rPi != rB && !rPi.sameLeaders(rB))) {
            e.setCancelled(true);
            return;
        }
        if (antih) {
            BlockSnapshot ib = block.add(0, 1, 0).createSnapshot();
            if (!cont.canWorldBreak(ib) || !cont.canWorldBreak(block.createSnapshot())) {
                e.setCancelled(true);
            }
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 87 with Region

use of br.net.fabiozumbi12.RedProtect.Sponge.Region in project RedProtect by FabioZumbi12.

the class RPBlockListener method onFlow.

/*
    @Listener
    public void onBlockBurn(NotifyNeighborBlockEvent e, @First BlockSnapshot source){
    	
    	RedProtect.get().logger.debug("Is ChangeBlockEvent.Modify event");
    	Map<Direction, BlockState> dirs = e.getNeighbors();
    	    	
    	for (Direction dir:dirs.keySet()){
    		BlockSnapshot b = source.getLocation().get().getRelative(dir).createSnapshot();
    		BlockState bstate = source.getState();
        	Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get());        	
        	
        	if ((bstate.getType().equals(BlockTypes.FIRE) || bstate.getType().getName().contains("LAVA")) && r != null && !r.canFire()){
    			e.setCancelled(true);
    			return;
    		}
        	
        	if (!cont.canWorldBreak(b)){
        		e.setCancelled(true);
        		return;
        	}
    	}
    	return;
    }
    */
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFlow(ChangeBlockEvent.Place e, @First BlockSnapshot source) {
    BlockSnapshot bto = e.getTransactions().get(0).getOriginal();
    RedProtect.get().logger.debug("blocks", "Is BlockFromToEvent.Place event is to " + source.getState().getType().getName() + " from " + bto.getState().getType().getName());
    Region rto = RedProtect.get().rm.getTopRegion(bto.getLocation().get());
    if (rto != null && (source.getState().getType().equals(BlockTypes.WATER) || source.getState().getType().equals(BlockTypes.LAVA) || source.getState().getType().equals(BlockTypes.FLOWING_LAVA) || source.getState().getType().equals(BlockTypes.FLOWING_WATER))) {
        if (!rto.canFlow()) {
            e.setCancelled(true);
            return;
        }
        String bfType = bto.getState().getType().getName();
        if (!rto.FlowDamage() && !bto.getState().getType().equals(BlockTypes.AIR) && !bfType.contains("water") && !bfType.contains("lava")) {
            e.setCancelled(true);
            return;
        }
    }
    for (Direction dir : Arrays.asList(Direction.EAST, Direction.NORTH, Direction.SOUTH, Direction.WEST)) {
        Location<World> locFrom = bto.getLocation().get().getBlockRelative(dir);
        Region rfrom = RedProtect.get().rm.getTopRegion(locFrom);
        if (rfrom != null && !rfrom.canFlow()) {
            e.setCancelled(true);
            return;
        }
        if (rfrom != null && rto != null && rfrom != rto && !rfrom.sameLeaders(rto)) {
            e.setCancelled(true);
            return;
        }
        if (rfrom == null && rto != null) {
            e.setCancelled(true);
            return;
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) World(org.spongepowered.api.world.World) Direction(org.spongepowered.api.util.Direction) Listener(org.spongepowered.api.event.Listener)

Example 88 with Region

use of br.net.fabiozumbi12.RedProtect.Sponge.Region in project RedProtect by FabioZumbi12.

the class RPCommands method handleDeleteName.

private static void handleDeleteName(Player p, String rname, String world) {
    Region r = RedProtect.get().rm.getRegion(rname, p.getWorld());
    if (!world.equals("")) {
        if (Sponge.getServer().getWorld(world).isPresent()) {
            r = RedProtect.get().rm.getRegion(rname, Sponge.getServer().getWorld(world).get());
        } else {
            RPLang.sendMessage(p, "cmdmanager.region.invalidworld");
            return;
        }
    }
    if (RedProtect.get().ph.hasRegionPermLeader(p, "delete", r)) {
        if (r == null) {
            RPLang.sendMessage(p, RPLang.get("cmdmanager.region.doesntexist") + ": " + rname);
            return;
        }
        String puuid = RPUtil.PlayerToUUID(p.getName());
        if (r.isRentFor(puuid)) {
            RPLang.sendMessage(p, "cmdmanager.rent.cantdothisrent");
            return;
        }
        int claims = RedProtect.get().cfgs.getInt("region-settings.first-home.can-delete-after-claims");
        if (!r.canDelete() && (claims == -1 || RedProtect.get().rm.getPlayerRegions(p.getName(), p.getWorld()) < claims) && !p.hasPermission("redprotect.bypass")) {
            if (claims != -1) {
                RPLang.sendMessage(p, RPLang.get("cmdmanager.region.cantdeletefirst-claims").replace("{claims}", "" + claims));
            } else {
                RPLang.sendMessage(p, RPLang.get("cmdmanager.region.cantdeletefirst"));
            }
            return;
        }
        DeleteRegionEvent event = new DeleteRegionEvent(r, p);
        if (Sponge.getEventManager().post(event)) {
            return;
        }
        RedProtect.get().rm.remove(r, RedProtect.get().serv.getWorld(r.getWorld()).get());
        RPLang.sendMessage(p, RPLang.get("cmdmanager.region.deleted") + " " + rname);
        RedProtect.get().logger.addLog("(World " + world + ") Player " + p.getName() + " REMOVED region " + rname);
    } else {
        sendNoPermissionMessage(p);
    }
}
Also used : DeleteRegionEvent(br.net.fabiozumbi12.RedProtect.Sponge.events.DeleteRegionEvent)

Example 89 with Region

use of br.net.fabiozumbi12.RedProtect.Sponge.Region in project RedProtect by FabioZumbi12.

the class RPCommands method handleDelete.

private static void handleDelete(Player p) {
    Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
    if (RedProtect.get().ph.hasRegionPermLeader(p, "delete", r)) {
        if (r == null) {
            sendNotInRegionMessage(p);
            return;
        }
        String puuid = RPUtil.PlayerToUUID(p.getName());
        if (r.isRentFor(puuid)) {
            RPLang.sendMessage(p, "cmdmanager.rent.cantdothisrent");
            return;
        }
        int claims = RedProtect.get().cfgs.getInt("region-settings.first-home.can-delete-after-claims");
        if (!r.canDelete() && (claims == -1 || RedProtect.get().rm.getPlayerRegions(p.getName(), p.getWorld()) < claims) && !p.hasPermission("redprotect.bypass")) {
            if (claims != -1) {
                RPLang.sendMessage(p, RPLang.get("cmdmanager.region.cantdeletefirst-claims").replace("{claims}", "" + claims));
            } else {
                RPLang.sendMessage(p, RPLang.get("cmdmanager.region.cantdeletefirst"));
            }
            return;
        }
        DeleteRegionEvent event = new DeleteRegionEvent(r, p);
        if (Sponge.getEventManager().post(event)) {
            return;
        }
        String rname = r.getName();
        String w = r.getWorld();
        RedProtect.get().rm.remove(r, RedProtect.get().serv.getWorld(w).get());
        RPLang.sendMessage(p, RPLang.get("cmdmanager.region.deleted") + " " + rname);
        RedProtect.get().logger.addLog("(World " + w + ") Player " + p.getName() + " REMOVED region " + rname);
    } else {
        sendNoPermissionMessage(p);
    }
}
Also used : DeleteRegionEvent(br.net.fabiozumbi12.RedProtect.Sponge.events.DeleteRegionEvent)

Example 90 with Region

use of br.net.fabiozumbi12.RedProtect.Sponge.Region in project RedProtect by FabioZumbi12.

the class RPEntityListener method onCreatureSpawn.

@Listener(order = Order.FIRST, beforeModifications = true)
@IsCancelled(Tristate.FALSE)
public void onCreatureSpawn(SpawnEntityEvent event) {
    for (Entity e : event.getEntities()) {
        if (e == null || e.getType() == null) {
            continue;
        }
        if (!(e instanceof Living)) {
            continue;
        }
        Optional<SpawnTypes> cause = event.getCause().first(SpawnTypes.class);
        RedProtect.get().logger.debug("entity", "SpawnCause: " + (cause.map(Object::toString).orElse(" null")));
        if (e instanceof Wither && cause.isPresent() && cause.get().equals(SpawnTypes.PLACEMENT)) {
            Region r = RedProtect.get().rm.getTopRegion(e.getLocation());
            if (r != null && !r.canSpawnWhiter()) {
                event.isCancelled();
                return;
            }
        }
        if (e instanceof Monster) {
            Location<World> l = e.getLocation();
            Region r = RedProtect.get().rm.getTopRegion(l);
            if (r != null && !r.canSpawnMonsters()) {
                RedProtect.get().logger.debug("entity", "Cancelled spawn of monster " + e.getType().getName());
                event.setCancelled(true);
                return;
            }
        }
        if (e instanceof Animal || e instanceof Golem || e instanceof Ambient || e instanceof Aquatic) {
            Location<World> l = e.getLocation();
            Region r = RedProtect.get().rm.getTopRegion(l);
            if (r != null && !r.canSpawnPassives()) {
                RedProtect.get().logger.debug("entity", "Cancelled spawn of animal " + e.getType().getName());
                event.setCancelled(true);
                return;
            }
        }
        RedProtect.get().logger.debug("entity", "RPEntityListener - Spawn mob " + e.getType().getName());
    }
}
Also used : Wither(org.spongepowered.api.entity.living.monster.Wither) Entity(org.spongepowered.api.entity.Entity) Living(org.spongepowered.api.entity.living.Living) World(org.spongepowered.api.world.World) Golem(org.spongepowered.api.entity.living.golem.Golem) Ambient(org.spongepowered.api.entity.living.Ambient) Aquatic(org.spongepowered.api.entity.living.Aquatic) Animal(org.spongepowered.api.entity.living.animal.Animal) Monster(org.spongepowered.api.entity.living.monster.Monster) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) Listener(org.spongepowered.api.event.Listener) IsCancelled(org.spongepowered.api.event.filter.IsCancelled)

Aggregations

Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)113 EventHandler (org.bukkit.event.EventHandler)92 Player (org.bukkit.entity.Player)69 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)47 Listener (org.spongepowered.api.event.Listener)46 Location (org.bukkit.Location)43 World (org.spongepowered.api.world.World)30 Block (org.bukkit.block.Block)26 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)20 PvPlayer (me.NoChance.PvPManager.PvPlayer)20 Entity (org.bukkit.entity.Entity)20 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)19 Entity (org.spongepowered.api.entity.Entity)19 LivingEntity (org.bukkit.entity.LivingEntity)16 Player (org.spongepowered.api.entity.living.player.Player)16 World (org.bukkit.World)10 Monster (org.bukkit.entity.Monster)10 Material (org.bukkit.Material)9 ClanPlayer (net.sacredlabyrinth.phaed.simpleclans.ClanPlayer)8 OfflinePlayer (org.bukkit.OfflinePlayer)8