Search in sources :

Example 81 with Region

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

the class RPBlockListener method onBlockGrow.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockGrow(ChangeBlockEvent.Grow e) {
    RedProtect.get().logger.debug("blocks", "RPBlockListener - Is ChangeBlockEvent.Grow event");
    BlockSnapshot b = e.getTransactions().get(0).getOriginal();
    Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get());
    if (r != null && !r.canGrow()) {
        e.setCancelled(true);
        RedProtect.get().logger.debug("blocks", "Cancel grow " + b.getState().getName());
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Listener(org.spongepowered.api.event.Listener)

Example 82 with Region

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

the class RPBlockListener method onFrameAndBoatBrake.

/*
    @Listener
    public void onEntityExplode(ExplosionEvent.Detonate e) {
    	RedProtect.get().logger.debug("Is BlockListener - ExplosionEvent.Detonate event");
    	
        for (Transaction<BlockSnapshot> bl:e.getTransactions()) {
        	BlockSnapshot b = bl.getOriginal();
        	RedProtect.get().logger.debug("Blocks: "+b.getState().getType().getName());
        	
        	Location<World> l = b.getLocation().get();
        	Region r = RedProtect.get().rm.getTopRegion(l);
        	if (!cont.canWorldBreak(b)){
        		RedProtect.get().logger.debug("canWorldBreak Called!");
        		bl.setValid(false);
        		//toRemove.add(bl);
        		continue;
        	}        	
        	if (r == null){
        		continue;
        	}
        	
        	if ((b.getState().getType().getName().contains("tnt") || e.getCause().first(Lightning.class).isPresent()) && !r.canFire()){
        		//toRemove.add(bl);
        		bl.setValid(false);
    			continue;
        	}  
        	
        	if (e.getCause().first(Living.class).isPresent() && !r.canMobLoot()){
        		//toRemove.add(bl);
        		bl.setValid(false);
        		continue;
        	}
        	
        }
        /*if (!toRemove.isEmpty()){
        	e.getTransactions().removeAll(toRemove);
        }
        
    }*/
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFrameAndBoatBrake(DamageEntityEvent e) {
    RedProtect.get().logger.debug("blocks", "Is BlockListener - DamageEntityEvent event");
    Entity ent = e.getTargetEntity();
    Location<World> l = e.getTargetEntity().getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l);
    if (ent instanceof Hanging && e.getCause().first(Monster.class).isPresent()) {
        if (r != null && !r.canFire()) {
            e.setCancelled(true);
            return;
        }
    }
    if (ent instanceof Boat && e.getCause().first(Player.class).isPresent()) {
        Player p = e.getCause().first(Player.class).get();
        if (!r.canMinecart(p)) {
            RPLang.sendMessage(p, "blocklistener.region.cantbreak");
            e.setCancelled(true);
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) Hanging(org.spongepowered.api.entity.hanging.Hanging) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) World(org.spongepowered.api.world.World) Boat(org.spongepowered.api.entity.vehicle.Boat) Listener(org.spongepowered.api.event.Listener)

Example 83 with Region

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

the class RPBlockListener method onSignPlace.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onSignPlace(ChangeSignEvent e, @First Player p) {
    RedProtect.get().logger.debug("blocks", "BlockListener - Is SignChangeEvent event! Cancelled? " + e.isCancelled());
    Sign s = e.getTargetTile();
    List<Text> lines = e.getText().asList();
    Location<World> loc = s.getLocation();
    World w = p.getWorld();
    BlockSnapshot b = w.createSnapshot(loc.getBlockPosition());
    if (b == null) {
        this.setErrorSign(e, p, RPLang.get("blocklistener.block.null"));
        return;
    }
    Region signr = RedProtect.get().rm.getTopRegion(loc);
    if (signr != null && !signr.canSign(p)) {
        RPLang.sendMessage(p, "playerlistener.region.cantinteract");
        e.setCancelled(true);
        return;
    }
    Text line1 = lines.get(0);
    if (lines.size() != 4) {
        this.setErrorSign(e, p, RPLang.get("blocklistener.sign.wronglines"));
        return;
    }
    if (RedProtect.get().cfgs.getBool("server-protection.sign-spy.enabled")) {
        Sponge.getServer().getConsole().sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.location").replace("{x}", "" + loc.getX()).replace("{y}", "" + loc.getY()).replace("{z}", "" + loc.getZ()).replace("{world}", w.getName())));
        Sponge.getServer().getConsole().sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.player").replace("{player}", p.getName())));
        Sponge.getServer().getConsole().sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.lines12").replace("{line1}", lines.get(0).toPlain()).replace("{line2}", lines.get(1).toPlain())));
        Sponge.getServer().getConsole().sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.lines34").replace("{line3}", lines.get(2).toPlain()).replace("{line4}", lines.get(3).toPlain())));
        if (!RedProtect.get().cfgs.getBool("server-protection.sign-spy.only-console")) {
            for (Player play : Sponge.getServer().getOnlinePlayers()) {
                if (RedProtect.get().ph.hasGenPerm(play, "redprotect.signspy")) /* && !play.equals(p)*/
                {
                    play.sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.location").replace("{x}", "" + loc.getX()).replace("{y}", "" + loc.getY()).replace("{z}", "" + loc.getZ()).replace("{world}", w.getName())));
                    play.sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.player").replace("{player}", p.getName())));
                    play.sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.lines12").replace("{line1}", lines.get(0).toPlain()).replace("{line2}", lines.get(1).toPlain())));
                    play.sendMessage(RPUtil.toText(RPLang.get("blocklistener.signspy.lines34").replace("{line3}", lines.get(2).toPlain()).replace("{line4}", lines.get(3).toPlain())));
                }
            }
        }
    }
    if ((RedProtect.get().cfgs.getBool("private.use") && s.getType().equals(TileEntityTypes.SIGN)) && (line1.toPlain().equalsIgnoreCase("private") || line1.toPlain().equalsIgnoreCase("[private]") || line1.toPlain().equalsIgnoreCase(RPLang.get("blocklistener.container.signline")) || line1.toPlain().equalsIgnoreCase("[" + RPLang.get("blocklistener.container.signline") + "]"))) {
        Region r = RedProtect.get().rm.getTopRegion(loc);
        Boolean out = RedProtect.get().cfgs.getBool("private.allow-outside");
        if (out || r != null) {
            if (cont.isContainer(b)) {
                int length = p.getName().length();
                if (length > 16) {
                    length = 16;
                }
                lines.set(1, RPUtil.toText(p.getName().substring(0, length)));
                e.getText().setElements(lines);
                RPLang.sendMessage(p, "blocklistener.container.protected");
                return;
            } else {
                RPLang.sendMessage(p, "blocklistener.container.notprotected");
                // w.digBlock(loc.getBlockPosition(), Cause.of(NamedCause.simulated(p)));
                return;
            }
        } else {
            RPLang.sendMessage(p, "blocklistener.container.notregion");
            // w.digBlock(loc.getBlockPosition(), Cause.of(NamedCause.simulated(p)));
            return;
        }
    }
    if (line1.toPlain().equalsIgnoreCase("[rp]")) {
        String claimmode = RedProtect.get().cfgs.getWorldClaimType(p.getWorld().getName());
        if ((!claimmode.equalsIgnoreCase("BLOCK") && !claimmode.equalsIgnoreCase("BOTH")) && !RedProtect.get().ph.hasPerm(p, "redprotect.admin.create")) {
            this.setErrorSign(e, p, RPLang.get("blocklistener.region.claimmode"));
            return;
        }
        RegionBuilder rb = new EncompassRegionBuilder(e);
        if (rb.ready()) {
            Region r = rb.build();
            lines.set(0, RPUtil.toText(RPLang.get("blocklistener.region.signcreated")));
            lines.set(1, RPUtil.toText(r.getName()));
            e.getText().setElements(lines);
            // RPLang.sendMessage(p, RPLang.get("blocklistener.region.created").replace("{region}",  r.getName()));
            RedProtect.get().rm.add(r, RedProtect.get().serv.getWorld(r.getWorld()).get());
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) EncompassRegionBuilder(br.net.fabiozumbi12.RedProtect.Sponge.actions.EncompassRegionBuilder) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Text(org.spongepowered.api.text.Text) World(org.spongepowered.api.world.World) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Sign(org.spongepowered.api.block.tileentity.Sign) RegionBuilder(br.net.fabiozumbi12.RedProtect.Sponge.RegionBuilder) EncompassRegionBuilder(br.net.fabiozumbi12.RedProtect.Sponge.actions.EncompassRegionBuilder) Listener(org.spongepowered.api.event.Listener)

Example 84 with Region

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

the class RPBlockListener method onDecay.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onDecay(ChangeBlockEvent.Decay e, @First BlockSnapshot source) {
    BlockSnapshot bfrom = e.getTransactions().get(0).getOriginal();
    RedProtect.get().logger.debug("blocks", "Is BlockFromToEvent.Decay event is to " + source.getState().getType().getName() + " from " + bfrom.getState().getType().getName());
    Region r = RedProtect.get().rm.getTopRegion(bfrom.getLocation().get());
    if (r != null && !r.leavesDecay() && source.getState().getType().getName().contains("leaves")) {
        e.setCancelled(true);
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Listener(org.spongepowered.api.event.Listener)

Example 85 with Region

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

the class RPBlockListener method onBlockPlaceGeneric.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockPlaceGeneric(ChangeBlockEvent.Place e) {
    if (e.getCause().root().toString().contains("minecraft:fire")) {
        Region r = RedProtect.get().rm.getTopRegion(e.getTransactions().get(0).getOriginal().getLocation().get());
        if (r != null && !r.canFire()) {
            e.setCancelled(true);
            RedProtect.get().logger.debug("blocks", "Tryed to PLACE FIRE!");
        }
    }
}
Also used : Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Listener(org.spongepowered.api.event.Listener)

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