/** * Create a default configuration file from the .jar. * * @param name the filename */ protected void createDefaultConfiguration(String name) { File actual = new File(getDataFolder(), name); if (!actual.exists()) { try (JarFile file = new JarFile(getFile())) { ZipEntry copy = file.getEntry("defaults/" + name); if (copy == null) throw new FileNotFoundException(); copyDefaultConfig(file.getInputStream(copy), actual, name); } catch (IOException e) { getLogger().severe("Unable to read default configuration: " + name); } } }
@Override public String getVersion() { return plugin.getDescription().getVersion(); }
@Override public void onPluginMessageReceived(String channel, Player player, byte[] message) { LocalSession session = plugin.getSession(player); String text = new String(message, UTF_8_CHARSET); session.handleCUIInitializationMessage(text); session.describeCUI(plugin.wrapPlayer(player)); }
/** * Create a WorldEdit Player from a Bukkit Player. * * @param player The Bukkit player * @return The WorldEdit player */ public static BukkitPlayer adapt(Player player) { return WorldEditPlugin.getInstance().wrapPlayer(player); }
@Nullable @Override public Map<String, ? extends Property<?>> getProperties(BlockType blockType) { if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) { return WorldEditPlugin.getInstance().getBukkitImplAdapter().getProperties(blockType); } return super.getProperties(blockType); }
/** * Called on plugin enable. */ @SuppressWarnings("AccessStaticViaInstance") @Override public void onEnable() { this.INSTANCE = this; //noinspection ResultOfMethodCallIgnored getDataFolder().mkdirs(); WorldEdit worldEdit = WorldEdit.getInstance(); // Setup platform server = new BukkitServerInterface(this, getServer()); worldEdit.getPlatformManager().register(server); loadAdapter(); // Need an adapter to work with special blocks with NBT data worldEdit.loadMappings(); loadConfig(); // Load configuration PermissionsResolverManager.initialize(this); // Setup permission resolver // Register CUI getServer().getMessenger().registerIncomingPluginChannel(this, CUI_PLUGIN_CHANNEL, new CUIChannelListener(this)); getServer().getMessenger().registerOutgoingPluginChannel(this, CUI_PLUGIN_CHANNEL); // Now we can register events getServer().getPluginManager().registerEvents(new WorldEditListener(this), this); // If we are on MCPC+/Cauldron, then Forge will have already loaded // Forge WorldEdit and there's (probably) not going to be any other // platforms to be worried about... at the current time of writing WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent()); // Enable metrics new Metrics(this); }
@Override public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { // Add the command to the array because the underlying command handling // code of WorldEdit expects it String[] split = new String[args.length + 1]; System.arraycopy(args, 0, split, 1, args.length); split[0] = cmd.getName(); CommandEvent event = new CommandEvent(wrapCommandSender(sender), Joiner.on(" ").join(split)); getWorldEdit().getEventBus().post(event); return true; }
if (!plugin.getInternalPlatform().isHookingEvents()) { return; final Player player = plugin.wrapPlayer(event.getPlayer()); final World world = player.getWorld(); final WorldEdit we = plugin.getWorldEdit();
public Actor wrapCommandSender(CommandSender sender) { if (sender instanceof Player) { return wrapPlayer((Player) sender); } return new BukkitCommandSender(this, sender); }
private void loadConfig() { createDefaultConfiguration("config.yml"); // Create the default configuration file config = new BukkitConfiguration(new YAMLProcessor(new File(getDataFolder(), "config.yml"), true), this); config.load(); }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onGamemode(PlayerGameModeChangeEvent event) { if (!plugin.getInternalPlatform().isHookingEvents()) { return; } // this will automatically refresh their session, we don't have to do anything WorldEdit.getInstance().getSessionManager().get(plugin.wrapPlayer(event.getPlayer())); }
/** * Called when a player attempts to use a command * * @param event Relevant event details */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { String[] split = event.getMessage().split(" "); if (split.length > 0) { split[0] = split[0].substring(1); split = plugin.getWorldEdit().getPlatformManager().getCommandManager().commandDetection(split); } final String newMessage = "/" + StringUtil.joinString(split, " "); if (!newMessage.equals(event.getMessage())) { event.setMessage(newMessage); plugin.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { if (!event.getMessage().isEmpty()) { plugin.getServer().dispatchCommand(event.getPlayer(), event.getMessage().substring(1)); } event.setCancelled(true); } } }
@Override public File getWorkingDirectory() { return plugin.getDataFolder(); } }
/** * Convert any WorldEdit world into an equivalent wrapped Bukkit world. * * <p>If a matching world cannot be found, a {@link RuntimeException} * will be thrown.</p> * * @param world the world * @return a wrapped Bukkit world */ public static BukkitWorld asBukkitWorld(World world) { if (world instanceof BukkitWorld) { return (BukkitWorld) world; } else { BukkitWorld bukkitWorld = WorldEditPlugin.getInstance().getInternalPlatform().matchWorld(world); if (bukkitWorld == null) { throw new RuntimeException("World '" + world.getName() + "' has no matching version in Bukkit"); } return bukkitWorld; } }
private LocalSession getPlayerSession(Player player) { final WorldEditPlugin wep = getWorldEditPlugin(); if (wep == null) { return null; } try { return wep.getSession(player); } catch (Exception ex) { FLog.severe(ex); return null; } }
@Override public void run(String playerID) throws QuestRuntimeException { try { Location location = loc.getLocation(playerID); SchematicFormat schematic = SchematicFormat.getFormat(file); CuboidClipboard clipboard = schematic.load(file); BukkitWorld world = new BukkitWorld(location.getWorld()); EditSession editSession = we.getWorldEdit().getEditSessionFactory().getEditSession(world, 64*64*64); Vector newOrigin = BukkitUtil.toVector(location); clipboard.paste(editSession, newOrigin, noAir); } catch (DataException | IOException | MaxChangedBlocksException e) { Debug.error("Error while pasting a schematic: " + e.getMessage()); } }
private void loadAdapter() { WorldEdit worldEdit = WorldEdit.getInstance(); // Attempt to load a Bukkit adapter BukkitImplLoader adapterLoader = new BukkitImplLoader(); try { adapterLoader.addFromPath(getClass().getClassLoader()); } catch (IOException e) { log.log(Level.WARNING, "Failed to search path for Bukkit adapters"); } try { adapterLoader.addFromJar(getFile()); } catch (IOException e) { log.log(Level.WARNING, "Failed to search " + getFile() + " for Bukkit adapters", e); } try { bukkitAdapter = adapterLoader.loadAdapter(); log.log(Level.INFO, "Using " + bukkitAdapter.getClass().getCanonicalName() + " as the Bukkit adapter"); } catch (AdapterLoadException e) { Platform platform = worldEdit.getPlatformManager().queryCapability(Capability.WORLD_EDITING); if (platform instanceof BukkitServerInterface) { log.log(Level.WARNING, e.getMessage()); } else { log.log(Level.INFO, "WorldEdit could not find a Bukkit adapter for this MC version, " + "but it seems that you have another implementation of WorldEdit installed (" + platform.getPlatformName() + ") " + "that handles the world editing."); } } }
@Override public BaseEntity getState() { org.bukkit.entity.Entity entity = entityRef.get(); if (entity != null) { if (entity instanceof Player) { return null; } BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { return adapter.getEntity(entity); } else { return null; } } else { return null; } }
@Override public List<String> onTabComplete(CommandSender sender, Command cmd, String commandLabel, String[] args) { // Add the command to the array because the underlying command handling // code of WorldEdit expects it String[] split = new String[args.length + 1]; System.arraycopy(args, 0, split, 1, args.length); split[0] = cmd.getName(); CommandSuggestionEvent event = new CommandSuggestionEvent(wrapCommandSender(sender), Joiner.on(" ").join(split)); getWorldEdit().getEventBus().post(event); return event.getSuggestions(); }
/** * Gets the session for the player. * * @param player a player * @return a session */ public LocalSession getSession(Player player) { return WorldEdit.getInstance().getSessionManager().get(wrapPlayer(player)); }