Solved Using the worldedit api to store a region and actually use the region

Discussion in 'Plugin Development' started by gogobebe2, Dec 27, 2014.

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

    gogobebe2

    Hi, I found a post somewhere giving out this snippet of code:
    Code:
                            WorldEditPlugin worldEditPlugin = null;
                            worldEditPlugin = (WorldEditPlugin) Bukkit.getServer()
                                    .getPluginManager().getPlugin("WorldEdit");
                            Selection sel = worldEditPlugin.getSelection(player);
    
                            if (sel instanceof Polygonal2DSelection) {
                                Polygonal2DSelection polySel = (Polygonal2DSelection) sel;
                                int minY = polySel.getNativeMinimumPoint()
                                        .getBlockY();
                                int maxY = polySel.getNativeMaximumPoint()
                                        .getBlockY();
                            } else if (sel instanceof CuboidSelection) {
                                BlockVector min = sel.getNativeMinimumPoint()
                                        .toBlockVector();
                                BlockVector max = sel.getNativeMaximumPoint()
                                        .toBlockVector();
                            }
                            //Now what?
    I'm trying to do this plugin: http://bukkit.org/threads/item-limit-via-regions.330626/#post-2951274
    So what it does, is it's kinda like worldguard except it doesn't let a specific item in and takes it from the player if it walks into the region. Is there also a way to create a flag for worldguard instead?
    Anyway this is what I've got so far and I have no idea how I'm actually supposed to use the top piece of code in my code:
    Code:
    package com.gmail.gogobebe2.rbrestricteditems;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    import com.sk89q.worldedit.BlockVector;
    import com.sk89q.worldedit.bukkit.WorldEditPlugin;
    import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
    import com.sk89q.worldedit.bukkit.selections.Polygonal2DSelection;
    import com.sk89q.worldedit.bukkit.selections.Selection;
    
    public class RBRestrictedItems extends JavaPlugin implements Listener {
    
        public void onEnable() {
            this.saveDefaultConfig();
            this.getConfig().options().copyDefaults(true);
            this.saveConfig();
        }
    
        public void onDisable() {
            this.saveConfig();
        }
    
        public boolean onCommand(CommandSender sender, Command command,
                String commandLabel, String[] args) {
            if (commandLabel.equalsIgnoreCase("ir")) {
    
                if (args.length == 0) {
                    sender.sendMessage(ChatColor.DARK_AQUA + "[the"
                            + ChatColor.BLUE + " /ir " + ChatColor.DARK_AQUA
                            + "help menu]");
                    sender.sendMessage(ChatColor.BLACK + "- " + ChatColor.GREEN
                            + "/ir " + ChatColor.BLUE + "create <name>" + " - "
                            + ChatColor.ITALIC + "creates a region.");
                    sender.sendMessage(ChatColor.BLACK + "- " + ChatColor.GREEN
                            + "/ir " + ChatColor.BLUE + "set <name> <item(s)>"
                            + " - " + ChatColor.ITALIC
                            + "sets the item not allowed in a region.");
                    sender.sendMessage(ChatColor.BLACK + "- " + ChatColor.GREEN
                            + "/ir " + ChatColor.BLUE + "delete <name>" + " - "
                            + ChatColor.ITALIC + "deletes the region.");
                    sender.sendMessage(ChatColor.BLACK + "- " + ChatColor.GREEN
                            + "/ir " + ChatColor.BLUE + "see" + " - "
                            + ChatColor.ITALIC
                            + "checks what regions the player is in.");
                    sender.sendMessage(ChatColor.BLACK + "- " + ChatColor.GREEN
                            + "/ir " + ChatColor.BLUE + "list" + " - "
                            + ChatColor.ITALIC + "lists the regions in the world.");
                    sender.sendMessage(ChatColor.BLACK
                            + "- "
                            + ChatColor.GREEN
                            + "/ir "
                            + ChatColor.BLUE
                            + "info"
                            + " - "
                            + ChatColor.ITALIC
                            + "displays the items not allowed in the area and it's location.");
                    sender.sendMessage(ChatColor.BLACK + "- " + ChatColor.GREEN
                            + "/ir " + ChatColor.BLUE + "reload" + " - "
                            + ChatColor.ITALIC + "reloads the config.yml");
                } else {
                    // *************** CREATE ***************
    
                    if (args[0].equalsIgnoreCase("create")) {
                        if (sender instanceof Player) {
                            Player player = (Player) sender;
                            WorldEditPlugin worldEditPlugin = null;
                            worldEditPlugin = (WorldEditPlugin) Bukkit.getServer()
                                    .getPluginManager().getPlugin("WorldEdit");
                            Selection sel = worldEditPlugin.getSelection(player);
    
                            if (sel instanceof Polygonal2DSelection) {
                                Polygonal2DSelection polySel = (Polygonal2DSelection) sel;
                                int minY = polySel.getNativeMinimumPoint()
                                        .getBlockY();
                                int maxY = polySel.getNativeMaximumPoint()
                                        .getBlockY();
                            } else if (sel instanceof CuboidSelection) {
                                BlockVector min = sel.getNativeMinimumPoint()
                                        .toBlockVector();
                                BlockVector max = sel.getNativeMaximumPoint()
                                        .toBlockVector();
                            }
                            //Now what?
    
                        } else {
                            sender.sendMessage(ChatColor.RED
                                    + "This command can only be used aby a player!");
                        }
                    }
    
                    // *************** RELOAD ***************
                    if (args[0].equalsIgnoreCase("reload")) {
                        this.reloadConfig();
                        this.saveConfig();
                        if (sender instanceof Player) {
                            sender.sendMessage(ChatColor.GOLD + "Plugin reloaded!");
                            Bukkit.getConsoleSender()
                                    .sendMessage(
                                            ChatColor.GOLD
                                                    + "RB Restricted Items plugin reloaded!");
                        } else {
                            Bukkit.getConsoleSender()
                                    .sendMessage(
                                            ChatColor.GOLD
                                                    + "RB Restricted Items plugin reloaded!");
                        }
                    }
    
                    // **************************************
                }
            }
            return true;
        }
    
    }
    
    and my plugin.yml:
    Code:
    name: RBRestrictedItems
    version: 1.0
    main: com.gmail.gogobebe2.rbrestricteditems.RBRestrictedItems
    description: Restrict items in a specified region.
    
    commands:
        ir:
            usage: /<command>
            description: Create region based item restrictions
     
  2. Offline

    mythbusterma

    @gogobebe2

    Forgive me, but this isn't what WorldEdit is used for at all, and WorldEdit doesn't depend on WorldGuard, nor vice-versa. Why are you using WorldEdit, just use WorldGuard.
     
Thread Status:
Not open for further replies.

Share This Page