Shematica on right click

Discussion in 'Spigot Plugin Development' started by Nighterance, May 21, 2017.

  1. Hello! So I am either searching for if exists or trying to create a plugin.

    Idea:
    When you right click paper with custom name, there will be generated schematic in your location, I think how to make it.

    Event that checks for right click, if clicked item has meta displayname && is not null, then execute command. But how could I add schematica to specific player location? By getting x = player.getlocation x ect and then executing it as world edit command from console?
     
  2. Just google it, there are loads of threads created already about this. Just google it.
     
  3. Could you give me a link maybe?
    Thanks!
     
  4. Well, since I'm lazy. I'll just spoonfeed you:
    Code (Text):
        private void pasteSchematica(Player p, Location focus){
            File file;
            Integer files = SkyBlock.schematica.listFiles().length;
            Integer random = r.nextInt(files+1);
            if (random == 0 || random > files+1){
                random = 1;
            }
            file = new File(SkyBlock.schematica + "/SB" + random + ".schematic");
           
            if (file.exists() && !file.isDirectory()) {
                /* Paste schematic */
                SchematicFormat format = SchematicFormat.getFormat(file);
                CuboidClipboard WEclipboard = null;
                try {
                    WEclipboard = format.load(file);
                }catch (DataException | IOException e1) {
                    e1.printStackTrace();
                }
                if (WEclipboard != null) {
                    BukkitServerInterface WEinterface = new BukkitServerInterface((WorldEditPlugin)Bukkit
                            .getPluginManager().getPlugin("WorldEdit"), Bukkit.getServer());
                    EditSession WEsessionEdit = null;
                    for (LocalWorld WEworld : WEinterface.getWorlds()) {
                        if (WEworld.getName().equalsIgnoreCase(focus.getWorld().getName())) {
                            WEsessionEdit = new EditSession(WEworld, -1);
                            break;
                        }
                    }
                    Vector WEvector = new Vector(focus.getX(), focus.getY(), focus.getZ());
                    try {
                        WEclipboard.paste(WEsessionEdit, WEvector, false);
                    } catch (MaxChangedBlocksException e) {
                        e.printStackTrace();
                    }
                 }
             }  
        }
    Replace some code since this is optimized for my plugin with multiple schematica's to choose from...