Question Is there a WorldEdit Factions integrated plugin?

Discussion in 'Bukkit Help' started by Rexcantor64, Mar 21, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Rexcantor64

    THIS IS NOT ABOUT WORLDEDIT CLAIM

    My problem is simple and fast. I have Factions and WorldEdit on the same server and I gave permissions to donators to use world edit. The problem is, they can use world edit on safezone, warzone and other factions territory. I just want them to use on their OWN territory (if they can build, because recruits can build) and on wilderness.

    WorldEdit version: 6.1;no_git_id
    Factions version: 2.8.2

    I already tried to make a plugin, but world edit doesn't have normal events.. ;(
    I tried EditSessionEvent but you can't cancel it, so it's useless...

    Here is what I had:

    WEListener (open)

    Code:
    import me.islandcraft.factions.managers.WEManager;
    
    import com.sk89q.worldedit.event.extent.EditSessionEvent;
    import com.sk89q.worldedit.extension.platform.Actor;
    import com.sk89q.worldedit.util.eventbus.Subscribe;
    public class WEListener {
        @Subscribe
        public void wrapForLogging(EditSessionEvent event) {
            Actor actor = event.getActor();
            if (actor != null && actor.isPlayer()) {
                WEManager wem = new WEManager(actor, event.getExtent());
                event.setExtent(wem);
                wem.setWorld(event.getWorld());
            }
        }
    }


    WEManager (open)

    Code:
    import me.islandcraft.factions.Main;
    import net.minecraft.server.v1_8_R3.NBTTagCompound;
    import net.minecraft.server.v1_8_R3.TileEntity;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    
    import com.massivecraft.factions.Rel;
    import com.massivecraft.factions.entity.BoardColl;
    import com.massivecraft.factions.entity.Faction;
    import com.massivecraft.factions.entity.MPlayer;
    import com.massivecraft.massivecore.ps.PS;
    import com.sk89q.worldedit.Vector;
    import com.sk89q.worldedit.blocks.BaseBlock;
    import com.sk89q.worldedit.extension.platform.Actor;
    import com.sk89q.worldedit.extent.Extent;
    import com.sk89q.worldedit.extent.logging.AbstractLoggingExtent;
    import com.sk89q.worldedit.world.World;
    
    public class WEManager extends AbstractLoggingExtent {
        private final Actor actor;
        private World world;
        private org.bukkit.World bWorld;
        private Player p = null;
    
        public WEManager(Actor actor, Extent extent) {
            super(extent);
            this.actor = actor;
            if (actor.isPlayer())
                this.p = Bukkit.getPlayer(this.actor.getUniqueId());
        }
    
        @Override
        protected void onBlockChange(Vector position, BaseBlock newBlock) {
            BaseBlock oldBlock = getBlock(position);
    
            System.out.println(actor.getName() + " set block @ " + position
                    + " from " + oldBlock + " to " + newBlock);
    
            Location location = new Location(this.bWorld, position.getBlockX(),
                    position.getBlockY(), position.getBlockZ());
    
            PS ps = PS.valueOf(location);
            Faction faction = BoardColl.get().getFactionAt(ps);
            MPlayer mplayer = MPlayer.get(p);
    
            if (mplayer.isUsingAdminMode())
                return;
    
            String tag = faction.getName(); //I know it should be inside "if(factions != null)", only testing the code.
    
            if (faction != null) { // Not really needed, but good for error checking
    
                if (tag.equalsIgnoreCase("wilderness"))
                    return;
    
                if (tag.equalsIgnoreCase("safezone")
                        || tag.equalsIgnoreCase("warzone")) {
                    keep(position, oldBlock);
                    return;
                }
    
                if (!faction.getOnlinePlayers().contains(p)) {
                    keep(position, oldBlock);
                    return;
                }
    
                if (mplayer.getRole() == Rel.RECRUIT) {
                    keep(position, oldBlock);
                    return;
                }
    
            }
        }
    
        public void setWorld(World w) {
            this.world = w;
            this.bWorld = Bukkit.getWorld(this.world.getName());
        }
    
        private void keep(final Vector position, final BaseBlock oldBlock) {
            Bukkit.getScheduler().runTaskLater(Main.get(), new Runnable() {
    
                @Override
                public void run() {
                    baseBlockToBlock(position, oldBlock);
                }
            }, 1L);
        }
    
        @SuppressWarnings("deprecation")
        private Block baseBlockToBlock(Vector p, BaseBlock bb) {
            Location loc = new Location(this.bWorld, p.getBlockX(), p.getBlockY(),
                    p.getBlockZ());
            Block b = this.bWorld.getBlockAt(loc);
            b.setTypeId(bb.getType());
            b.setData((byte) bb.getData());
            if (bb.hasNbtData()) { //Not finished yet
                TileEntity te = NBTManager.getGeneralTileEntity(loc);
                NBTTagCompound nbt = new NBTTagCompound();
                te.b(nbt);
                System.out.println("NBTTagCompound: " + nbt.toString());
                System.out.println("CompoundTag: " + bb.getNbtData().toString());
                System.out.println("NBTid: " + bb.getNbtId());
            }
            return b;
        }
    }


    The problem on the code above: The player still recives the block, the chests lose the items and the message saying the blocks changed number still have the blocks that didn't change.

    I hope there is a plugin for it somewhere... Thanks for your time!

    EDIT: I registered the event on onEnabled.
     
  2. Offline

    Rexcantor64

  3. Offline

    Rexcantor64

  4. Offline

    Rexcantor64

    Sadly, BUMP3
     
Thread Status:
Not open for further replies.

Share This Page