├── .gitignore ├── .gitmodules ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── pom.xml └── src └── main ├── java └── net │ └── glowstone │ └── bukkit2sponge │ ├── Bukkit2Sponge.java │ ├── ShinyGame.java │ ├── ShinyGameRegistry.java │ ├── ShinyServer.java │ ├── block │ ├── ShinyBlockSnapshot.java │ ├── ShinyBlockState.java │ └── ShinyBlockType.java │ ├── bukkit │ └── BukkitListener.java │ ├── command │ ├── BukkitCommand.java │ └── ShinyConsoleSource.java │ ├── event │ ├── BaseEvent.java │ ├── EventRegistration.java │ └── ShinyEventManager.java │ ├── guice │ ├── ConfigDirAnnotation.java │ ├── ConfigFileAnnotation.java │ ├── ShinyGuiceModule.java │ └── ShinyPluginGuiceModule.java │ ├── inventory │ └── ShinyItemStack.java │ ├── item │ ├── ShinyItemType.java │ └── ShinyItemTypes.java │ ├── permission │ └── ShinySubject.java │ ├── plugin │ ├── DefaultShader.java │ ├── GlowstoneConnector.java │ ├── PluginLoader.java │ ├── ShinyClassLoader.java │ ├── ShinyPluginContainer.java │ └── ShinyPluginManager.java │ ├── text │ └── ShinyTranslation.java │ ├── util │ └── Unsupported.java │ └── world │ └── ShinyWorld.java └── resources └── plugin.yml /.gitignore: -------------------------------------------------------------------------------- 1 | /.classpath 2 | /.project 3 | /.settings 4 | /nbproject 5 | /target 6 | /bin 7 | /dist 8 | /.idea 9 | .*.sw[a-p] 10 | *.iml 11 | /dependency-reduced-pom.xml 12 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "SpongeAPI"] 2 | path = SpongeAPI 3 | url = https://github.com/SpongePowered/SpongeAPI 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Bukkit2Sponge an OPEN Open Source Project 2 | 3 | ----------------------------------------- 4 | 5 | ## What? 6 | 7 | Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project. 8 | 9 | ## Rules 10 | 11 | There are a few basic ground-rules for contributors: 12 | 13 | 1. **No `--force` pushes** or modifying the Git history in any way. 14 | 1. **Non-master branches** ought to be used for ongoing work. 15 | 1. **External API changes and significant modifications** ought to be subject to an **internal pull-request** to solicit feedback from other contributors. 16 | 1. Internal pull-requests to solicit feedback are *encouraged* for any other non-trivial contribution but left to the discretion of the contributor. 17 | 1. Contributors should attempt to adhere to the prevailing code-style. 18 | 19 | ## Releases 20 | 21 | Declaring formal releases remains the prerogative of the project maintainer. 22 | 23 | ## Changes to this arrangement 24 | 25 | This is an experiment and feedback is welcome! This document may also be subject to pull-requests or changes by contributors where you believe you have something valuable to add or change. 26 | 27 | ----------------------------------------- 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Bukkit2Sponge Copyright (C) 2016-2017 The Glowstone Project 2 | Bukkit2Sponge Copyright (C) 2015 deathcap 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Bukkit2Sponge 2 | ============= 3 | 4 | An implementation of [SpongeAPI](https://github.com/SpongePowered/SpongeAPI) as a Bukkit plugin. 5 | 6 | Bukkit2Sponge allows loading SpongeAPI plugins on Bukkit servers. 7 | 8 | * [Bukkit2Sponge thread on Sponge Forums](https://forums.spongepowered.org/t/bukkit2sponge-an-implementation-of-spongeapi-for-bukkit-servers/6747) 9 | * [Bukkit2Sponge resource on SpigotMC](http://www.spigotmc.org/resources/bukkit2sponge.6368/) 10 | 11 | Warning: very incomplete (bug reports and pull requests appreciated, see [issues](https://github.com/GlowstonePlusPlus/Bukkit2Sponge/issues)) 12 | 13 | Usage 14 | ----- 15 | 16 | Copy the plugin jar to the `plugins` directory of your Bukkit server. 17 | 18 | Run your server, the first time it will create a `plugins/Bukkit2Sponge/plugins` directory. 19 | You can place your SpongeAPI plugins here. 20 | 21 | If using the [Glowstone](https://github.com/GlowstoneMC/Glowstone) 22 | server, you can alternatively place the SpongeAPI plugins in the top-level `plugins/` directory 23 | and they will be loaded by Bukkit2Sponge as well. 24 | 25 | When starting the server, if configured correctly Bukkit2Sponge should log the SpongeAPI plugins it finds: 26 | 27 | ``` 28 | 12:00:00 [INFO] [Bukkit2Sponge] Loading plugins... 29 | 12:00:00 [INFO] [Bukkit2Sponge] Initializing 1 SpongeAPI plugins... 30 | ``` 31 | 32 | Downloads 33 | --------- 34 | 35 | Latest builds are available from: 36 | https://bamboo.gserv.me/browse/GSPP-B2S/latestSuccessful/artifact/shared/Plugin-JAR/bukkit2sponge-0.1.0-SNAPSHOT.jar 37 | 38 | 39 | Building from source 40 | -------------------- 41 | 42 | 1. After installing the 43 | [Java Development Kit](http://oracle.com/technetwork/java/javase/downloads) and 44 | [Maven](https://maven.apache.org), checkout the source: 45 | 46 | ``` 47 | git clone https://github.com/GlowstoneMC/Bukkit2Sponge 48 | cd Bukkit2Sponge 49 | ``` 50 | 51 | 2. Build the plugin: 52 | 53 | ``` 54 | mvn package 55 | ``` 56 | 57 | The plugin jar will be placed in `target/`. 58 | 59 | 60 | See also 61 | -------- 62 | 63 | * [SpongeForge](https://github.com/SpongePowered/SpongeForge): SpongeAPI implementation on Minecraft Forge 64 | * [SpongeVanilla](https://github.com/SpongePowered/SpongeVanilla): SpongeAPI implementation on Minecraft 65 | * [Pore](https://github.com/LapisBlue/Pore): a SpongeAPI plugin to load Bukkit plugins (the opposite of Bukkit2Sponge) 66 | 67 | License 68 | ------- 69 | 70 | Bukkit2Sponge is open-source software released under the MIT license. Please see 71 | the `LICENSE` file for details. 72 | 73 | Bukkit is open-source software released under the GPL license. Please see 74 | the `LICENSE.txt` file in the Bukkit repository for details. 75 | 76 | Sponge is open-source software released under the MIT license. Please see 77 | the `LICENSE.txt` file in the Sponge repository for details. 78 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | net.glowstone 5 | bukkit2sponge 6 | jar 7 | 0.1.0-SNAPSHOT 8 | Bukkit2Sponge 9 | https://github.com/GlowstoneMC/Bukkit2Sponge 10 | 11 | 12 | UTF-8 13 | 1.12-pre5-SNAPSHOT 14 | 6.0.0 15 | yyyyMMdd-HHmm 16 | 1.8 17 | 1.8 18 | 19 | 20 | 21 | org.sonatype.oss 22 | oss-parent 23 | 9 24 | 25 | 26 | 27 | 28 | 29 | glowstone-repo 30 | https://repo.glowstone.net/repository/internal/ 31 | 32 | 33 | sponge-repo 34 | https://repo.spongepowered.org/maven 35 | 36 | 37 | 38 | 39 | 40 | glowstone-upstream 41 | https://repo.glowstone.net/content/repositories/releases/ 42 | 43 | 44 | glowstone-upstream 45 | https://repo.glowstone.net/content/repositories/snapshots/ 46 | 47 | 48 | 49 | 50 | 51 | org.projectlombok 52 | lombok 53 | 1.14.8 54 | provided 55 | 56 | 57 | net.glowstone 58 | glowkit 59 | ${bukkit.version} 60 | jar 61 | provided 62 | 63 | 64 | org.spongepowered 65 | spongeapi 66 | ${sponge.version} 67 | jar 68 | 69 | 70 | com.google.inject 71 | guice 72 | 4.0 73 | 74 | 75 | ninja.leaping.configurate 76 | configurate-hocon 77 | 3.3 78 | 79 | 80 | org.ow2.asm 81 | asm 82 | 5.0.3 83 | 84 | 85 | org.ow2.asm 86 | asm-commons 87 | 5.0.3 88 | 89 | 90 | 91 | 92 | 93 | 94 | src/main/resources 95 | true 96 | 97 | 98 | 99 | 100 | org.apache.maven.plugins 101 | maven-shade-plugin 102 | 3.0.0 103 | 104 | 105 | package 106 | 107 | shade 108 | 109 | 110 | 111 | 112 | junit:junit 113 | 114 | 115 | 116 | 117 | 118 | com.google.common 119 | net.glowstone.bukkit2sponge.libs.guava17.com.google.common 120 | 121 | 122 | 123 | org.objectweb.asm 124 | net.glowstone.bukkit2sponge.libs.asm5.org.objectweb.asm 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | org.apache.maven.plugins 134 | maven-jar-plugin 135 | 3.0.2 136 | 137 | 138 | 139 | ${project.name} 140 | ${project.version} 141 | ${sponge.version} 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/Bukkit2Sponge.java: -------------------------------------------------------------------------------- 1 | 2 | package net.glowstone.bukkit2sponge; 3 | 4 | import com.google.common.io.PatternFilenameFilter; 5 | import com.google.inject.Guice; 6 | import com.google.inject.Injector; 7 | import net.glowstone.bukkit2sponge.bukkit.BukkitListener; 8 | import net.glowstone.bukkit2sponge.guice.ShinyGuiceModule; 9 | import net.glowstone.bukkit2sponge.plugin.GlowstoneConnector; 10 | import org.bukkit.plugin.java.JavaPlugin; 11 | import org.spongepowered.api.Platform; 12 | import org.spongepowered.api.event.game.state.GameConstructionEvent; 13 | import org.spongepowered.api.event.game.state.GamePreInitializationEvent; 14 | import org.spongepowered.api.event.game.state.GameStateEvent; 15 | 16 | import java.io.File; 17 | import java.io.IOException; 18 | import java.net.MalformedURLException; 19 | import java.net.URL; 20 | import java.util.ArrayList; 21 | import java.util.Collection; 22 | import java.util.List; 23 | 24 | public class Bukkit2Sponge extends JavaPlugin { 25 | 26 | public static Bukkit2Sponge instance = null; 27 | private final BukkitListener bukkitListener = new BukkitListener(); 28 | 29 | public Injector getInjector() { 30 | return injector; 31 | } 32 | 33 | private Injector injector; 34 | 35 | private ShinyGame game; 36 | 37 | @Override 38 | public void onDisable() { 39 | getLogger().info("Goodbye world!"); 40 | } 41 | 42 | @Override 43 | public void onEnable() { 44 | Bukkit2Sponge.instance = this; 45 | getLogger().info( getDescription().getName() + " v" + getDescription().getVersion() + " is loading..."); 46 | load(); 47 | } 48 | 49 | private List getPluginURLs() { 50 | // Our own personal plugins directory 51 | File directory = getPluginsDirectory(); 52 | 53 | if (!directory.exists()) { 54 | directory.mkdirs(); 55 | } 56 | 57 | File[] files = directory.listFiles(new PatternFilenameFilter(".+\\.jar")); 58 | 59 | List urls = new ArrayList<>(files.length); 60 | for (File jar : files) { 61 | try { 62 | urls.add(jar.toURI().toURL()); 63 | } catch (MalformedURLException e) { 64 | Bukkit2Sponge.instance.getLogger().warning("Malformed URL: " + jar + e); 65 | } 66 | } 67 | 68 | List gs = GlowstoneConnector.getSpongePlugins(getServer()); 69 | if (gs != null) { 70 | Bukkit2Sponge.instance.getLogger().info("Glowstone integration enabled (" + gs.size() + " plugins)"); 71 | urls.addAll(gs); 72 | } 73 | 74 | return urls; 75 | } 76 | 77 | private void load() { 78 | Collection loadedPluginURLs; 79 | List urls = getPluginURLs(); 80 | 81 | try { 82 | injector = Guice.createInjector(new ShinyGuiceModule()); 83 | 84 | /* 85 | CONSTRUCTION, 86 | LOAD_COMPLETE, 87 | PRE_INITIALIZATION, 88 | INITIALIZATION, 89 | POST_INITIALIZATION, 90 | SERVER_ABOUT_TO_START, 91 | SERVER_STARTING, 92 | SERVER_STARTED, 93 | SERVER_STOPPING, 94 | SERVER_STOPPED 95 | */ 96 | 97 | 98 | game = injector.getInstance(ShinyGame.class); 99 | 100 | getServer().getPluginManager().registerEvents(bukkitListener, this); 101 | 102 | getLogger().info("SpongeAPI version: " + game.getPlatform().getContainer(Platform.Component.API).getVersion().get()); 103 | 104 | getLogger().info("Loading SpongeAPI plugins..."); 105 | loadedPluginURLs = game.getPluginManager().loadPlugins(urls); 106 | postState(GameConstructionEvent.class); 107 | getLogger().info("Initializing " + loadedPluginURLs.size() + " SpongeAPI plugins..."); 108 | postState(GamePreInitializationEvent.class); 109 | } catch (IOException e) { 110 | throw new RuntimeException(e); 111 | } 112 | } 113 | 114 | public ShinyGame getGame() { 115 | return this.game; 116 | } 117 | 118 | public void postState(Class type) { 119 | 120 | } 121 | 122 | // Sponge directories relative to our own Bukkit plugin data folder 123 | 124 | public File getPluginsDirectory() { 125 | return new File(this.getDataFolder(), "plugins"); 126 | } 127 | 128 | public File getConfigDirectory() { 129 | return new File(this.getDataFolder(), "config"); 130 | } 131 | } -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/ShinyGame.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge; 2 | 3 | import com.google.inject.Inject; 4 | import com.google.inject.Singleton; 5 | import net.glowstone.bukkit2sponge.plugin.ShinyPluginManager; 6 | import org.bukkit.Bukkit; 7 | import org.spongepowered.api.*; 8 | import org.spongepowered.api.plugin.PluginContainer; 9 | import org.spongepowered.api.service.ServiceManager; 10 | import org.spongepowered.api.service.SimpleServiceManager; 11 | import org.spongepowered.api.world.TeleportHelper; 12 | 13 | import java.nio.file.Path; 14 | import java.util.Map; 15 | import java.util.Optional; 16 | 17 | /** 18 | * Implementation of {@link Game}. 19 | */ 20 | 21 | @Singleton 22 | public class ShinyGame implements Game { 23 | 24 | private final ShinyPluginManager pluginManager = new ShinyPluginManager(this); 25 | private final ShinyGameRegistry registry = new ShinyGameRegistry(); 26 | private final SimpleServiceManager services = new SimpleServiceManager(pluginManager); 27 | private final ShinyServer server = new ShinyServer(Bukkit.getServer()); 28 | 29 | private static final String API_VERSION; 30 | private static final String IMPL_VERSION; 31 | 32 | static { 33 | Package pkg = ShinyGame.class.getPackage(); 34 | String apiVersion = pkg.getSpecificationVersion(); 35 | API_VERSION = (apiVersion == null) ? "unknown" : apiVersion; 36 | String implVersion = pkg.getImplementationVersion(); 37 | IMPL_VERSION = (implVersion == null) ? "unknown" : implVersion; 38 | } 39 | 40 | @Inject 41 | public ShinyGame() { 42 | 43 | } 44 | 45 | // platform information 46 | 47 | @Override 48 | public Platform getPlatform() { 49 | return new Platform() { 50 | @Override 51 | public Type getType() { 52 | return Type.SERVER; 53 | } 54 | 55 | @Override 56 | public Type getExecutionType() { 57 | return Type.SERVER; 58 | } 59 | 60 | @Override 61 | public PluginContainer getContainer(Component component) { 62 | return new PluginContainer() { 63 | @Override 64 | public String getId() { 65 | return "SpongeAPI"; 66 | } 67 | 68 | @Override 69 | public Optional getVersion() { 70 | return Optional.ofNullable(ShinyGame.this.getClass().getPackage().getSpecificationVersion()); 71 | } 72 | }; 73 | } 74 | 75 | @Override 76 | public MinecraftVersion getMinecraftVersion() { 77 | return null; 78 | } 79 | 80 | @Override 81 | public Map asMap() { 82 | return null; 83 | } 84 | }; 85 | } 86 | 87 | private GameState state; 88 | 89 | @Override 90 | public GameState getState() { 91 | return state; 92 | } 93 | 94 | public void setState(GameState state) { 95 | this.state = state; 96 | } 97 | 98 | @Override 99 | public Path getGameDirectory() { 100 | return null; 101 | } 102 | 103 | @Override 104 | public Path getSavesDirectory() { 105 | return null; 106 | } 107 | 108 | @Override 109 | public boolean isServerAvailable() { 110 | return false; 111 | } 112 | 113 | @Override 114 | public Server getServer() { 115 | return server; 116 | } 117 | 118 | @Override 119 | public GameDictionary getGameDictionary() { 120 | return null; 121 | } 122 | 123 | @Override 124 | public TeleportHelper getTeleportHelper() { 125 | return null; //To change body of implemented methods use File | Settings | File Templates. 126 | } 127 | 128 | // service access 129 | 130 | @Override 131 | public ShinyPluginManager getPluginManager() { 132 | return pluginManager; 133 | } 134 | 135 | @Override 136 | public GameRegistry getRegistry() { 137 | return registry; 138 | } 139 | 140 | @Override 141 | public ServiceManager getServiceManager() { 142 | return services; 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/ShinyGameRegistry.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge; 2 | 3 | import org.spongepowered.api.CatalogType; 4 | import org.spongepowered.api.GameRegistry; 5 | import org.spongepowered.api.block.BlockType; 6 | import org.spongepowered.api.data.type.Art; 7 | import org.spongepowered.api.data.value.ValueFactory; 8 | import org.spongepowered.api.entity.EntityType; 9 | import org.spongepowered.api.entity.ai.task.AITaskType; 10 | import org.spongepowered.api.entity.ai.task.AbstractAITask; 11 | import org.spongepowered.api.entity.living.Agent; 12 | import org.spongepowered.api.item.ItemType; 13 | import org.spongepowered.api.item.merchant.VillagerRegistry; 14 | import org.spongepowered.api.item.recipe.RecipeRegistry; 15 | import org.spongepowered.api.network.status.Favicon; 16 | import org.spongepowered.api.registry.CatalogRegistryModule; 17 | import org.spongepowered.api.registry.CatalogTypeAlreadyRegisteredException; 18 | import org.spongepowered.api.registry.RegistryModule; 19 | import org.spongepowered.api.registry.RegistryModuleAlreadyRegisteredException; 20 | import org.spongepowered.api.resourcepack.ResourcePack; 21 | import org.spongepowered.api.scoreboard.displayslot.DisplaySlot; 22 | import org.spongepowered.api.statistic.BlockStatistic; 23 | import org.spongepowered.api.statistic.EntityStatistic; 24 | import org.spongepowered.api.statistic.ItemStatistic; 25 | import org.spongepowered.api.statistic.StatisticType; 26 | import org.spongepowered.api.text.format.TextColor; 27 | import org.spongepowered.api.text.selector.SelectorFactory; 28 | import org.spongepowered.api.text.serializer.TextSerializerFactory; 29 | import org.spongepowered.api.text.translation.Translation; 30 | import org.spongepowered.api.util.ResettableBuilder; 31 | import org.spongepowered.api.util.rotation.Rotation; 32 | import org.spongepowered.api.world.extent.ExtentBufferFactory; 33 | 34 | import java.awt.image.BufferedImage; 35 | import java.io.IOException; 36 | import java.io.InputStream; 37 | import java.net.URL; 38 | import java.nio.file.Path; 39 | import java.util.*; 40 | import java.util.function.Supplier; 41 | 42 | /** 43 | * Implementation of {@link GameRegistry}. 44 | */ 45 | public class ShinyGameRegistry implements GameRegistry { 46 | 47 | private final Map blocks = new HashMap<>(); 48 | private final Map items = new HashMap<>(); 49 | private final Map arts = new HashMap<>(); 50 | private final Map rotations = new HashMap<>(); 51 | private final Map idMap = new IdentityHashMap<>(); 52 | 53 | private void register(BlockType block) { 54 | blocks.put(block.getId(), block); 55 | idMap.put(block, block.getId()); 56 | } 57 | 58 | private void register(ItemType item) { 59 | items.put(item.getId(), item); 60 | idMap.put(item, item.getId()); 61 | } 62 | 63 | 64 | @Override 65 | public Optional getType(Class tClass, String s) { 66 | return null; //To change body of implemented methods use File | Settings | File Templates. 67 | } 68 | 69 | @Override 70 | public Collection getAllOf(Class tClass) { 71 | return null; //To change body of implemented methods use File | Settings | File Templates. 72 | } 73 | 74 | @Override 75 | public Collection getAllFor(String pluginId, Class typeClass) { 76 | return null; 77 | } 78 | 79 | @Override 80 | public GameRegistry registerModule(Class catalogClass, CatalogRegistryModule registryModule) throws IllegalArgumentException, RegistryModuleAlreadyRegisteredException { 81 | return null; 82 | } 83 | 84 | @Override 85 | public GameRegistry registerModule(RegistryModule module) throws RegistryModuleAlreadyRegisteredException { 86 | return null; 87 | } 88 | 89 | @Override 90 | public GameRegistry registerBuilderSupplier(Class builderClass, Supplier supplier) { 91 | return null; 92 | } 93 | 94 | @Override 95 | public > T createBuilder(Class builderClass) throws IllegalArgumentException { 96 | return null; 97 | } 98 | 99 | @Override 100 | public T register(Class type, T obj) throws IllegalArgumentException, CatalogTypeAlreadyRegisteredException { 101 | return null; 102 | } 103 | 104 | @Override 105 | public Optional getRotationFromDegree(int degrees) { 106 | return Optional.ofNullable(rotations.get(degrees)); // TODO: int -> Rotation 107 | } 108 | 109 | @Override 110 | public Favicon loadFavicon(String raw) throws IOException { 111 | return null; 112 | } 113 | 114 | @Override 115 | public Favicon loadFavicon(Path path) throws IOException { 116 | return null; 117 | } 118 | 119 | @Override 120 | public Collection getDefaultGameRules() { 121 | return null; //To change body of implemented methods use File | Settings | File Templates. 122 | } 123 | 124 | @Override 125 | public Optional getEntityStatistic(StatisticType statType, EntityType entityType) { 126 | return null; 127 | } 128 | 129 | @Override 130 | public Optional getItemStatistic(StatisticType statType, ItemType itemType) { 131 | return null; 132 | } 133 | 134 | @Override 135 | public Optional getBlockStatistic(StatisticType statType, BlockType blockType) { 136 | return null; 137 | } 138 | 139 | @Override 140 | public Favicon loadFavicon(URL url) throws IOException { 141 | return null; //To change body of implemented methods use File | Settings | File Templates. 142 | } 143 | 144 | @Override 145 | public Favicon loadFavicon(InputStream in) throws IOException { 146 | return null; //To change body of implemented methods use File | Settings | File Templates. 147 | } 148 | 149 | @Override 150 | public Favicon loadFavicon(BufferedImage image) throws IOException { 151 | return null; //To change body of implemented methods use File | Settings | File Templates. 152 | } 153 | 154 | @Override 155 | public RecipeRegistry getRecipeRegistry() { 156 | return null; //To change body of implemented methods use File | Settings | File Templates. 157 | } 158 | 159 | @Override 160 | public Optional getResourcePackById(String id) { 161 | return null; 162 | } 163 | 164 | @Override 165 | public Optional getDisplaySlotForColor(TextColor color) { 166 | return null; //To change body of implemented methods use File | Settings | File Templates. 167 | } 168 | 169 | @Override 170 | public AITaskType registerAITaskType(Object plugin, String id, String name, Class> aiClass) { 171 | return null; 172 | } 173 | 174 | @Override 175 | public ExtentBufferFactory getExtentBufferFactory() { 176 | return null; 177 | } 178 | 179 | @Override 180 | public ValueFactory getValueFactory() { 181 | return null; 182 | } 183 | 184 | @Override 185 | public VillagerRegistry getVillagerRegistry() { 186 | return null; 187 | } 188 | 189 | @Override 190 | public TextSerializerFactory getTextSerializerFactory() { 191 | return null; 192 | } 193 | 194 | @Override 195 | public SelectorFactory getSelectorFactory() { 196 | return null; 197 | } 198 | 199 | @Override 200 | public Locale getLocale(String locale) { 201 | return null; 202 | } 203 | 204 | @Override 205 | public Optional getTranslationById(String s) { 206 | return null; //To change body of implemented methods use File | Settings | File Templates. 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/ShinyServer.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge; 2 | 3 | import net.glowstone.bukkit2sponge.command.ShinyConsoleSource; 4 | import org.spongepowered.api.Server; 5 | import org.spongepowered.api.command.source.ConsoleSource; 6 | import org.spongepowered.api.entity.living.player.Player; 7 | import org.spongepowered.api.profile.GameProfileManager; 8 | import org.spongepowered.api.resourcepack.ResourcePack; 9 | import org.spongepowered.api.scoreboard.Scoreboard; 10 | import org.spongepowered.api.text.Text; 11 | import org.spongepowered.api.text.channel.MessageChannel; 12 | import org.spongepowered.api.world.ChunkTicketManager; 13 | import org.spongepowered.api.world.World; 14 | import org.spongepowered.api.world.WorldArchetype; 15 | import org.spongepowered.api.world.storage.ChunkLayout; 16 | import org.spongepowered.api.world.storage.WorldProperties; 17 | 18 | import java.io.IOException; 19 | import java.net.InetSocketAddress; 20 | import java.util.Collection; 21 | import java.util.Optional; 22 | import java.util.UUID; 23 | import java.util.concurrent.CompletableFuture; 24 | 25 | public class ShinyServer implements Server { 26 | 27 | private org.bukkit.Server handle; 28 | private ShinyConsoleSource consoleSource = new ShinyConsoleSource("console"); 29 | 30 | public ShinyServer(org.bukkit.Server handle) { 31 | this.handle = handle; 32 | } 33 | 34 | @Override 35 | public Collection getOnlinePlayers() { 36 | return null; //To change body of implemented methods use File | Settings | File Templates. 37 | } 38 | 39 | @Override 40 | public int getMaxPlayers() { 41 | return handle.getMaxPlayers(); 42 | } 43 | 44 | @Override 45 | public Optional getPlayer(UUID uniqueId) { 46 | return Optional.empty(); //To change body of implemented methods use File | Settings | File Templates. 47 | } 48 | 49 | @Override 50 | public Optional getPlayer(String name) { 51 | return Optional.empty(); //To change body of implemented methods use File | Settings | File Templates. 52 | } 53 | 54 | @Override 55 | public Collection getWorlds() { 56 | return null; //To change body of implemented methods use File | Settings | File Templates. 57 | } 58 | 59 | @Override 60 | public Collection getUnloadedWorlds() { 61 | return null; //To change body of implemented methods use File | Settings | File Templates. 62 | } 63 | 64 | @Override 65 | public Collection getAllWorldProperties() { 66 | return null; //To change body of implemented methods use File | Settings | File Templates. 67 | } 68 | 69 | @Override 70 | public Optional getWorld(UUID uniqueId) { 71 | return null; //To change body of implemented methods use File | Settings | File Templates. 72 | } 73 | 74 | @Override 75 | public Optional getWorld(String worldName) { 76 | return null; //To change body of implemented methods use File | Settings | File Templates. 77 | } 78 | 79 | @Override 80 | public java.util.Optional getDefaultWorld() { 81 | return null; 82 | } 83 | 84 | @Override 85 | public String getDefaultWorldName() { 86 | return null; 87 | } 88 | 89 | @Override 90 | public Optional loadWorld(String worldName) { 91 | return null; //To change body of implemented methods use File | Settings | File Templates. 92 | } 93 | 94 | @Override 95 | public Optional loadWorld(UUID uniqueId) { 96 | return null; //To change body of implemented methods use File | Settings | File Templates. 97 | } 98 | 99 | @Override 100 | public Optional loadWorld(WorldProperties properties) { 101 | return null; //To change body of implemented methods use File | Settings | File Templates. 102 | } 103 | 104 | @Override 105 | public Optional getWorldProperties(String worldName) { 106 | return null; //To change body of implemented methods use File | Settings | File Templates. 107 | } 108 | 109 | @Override 110 | public Optional getWorldProperties(UUID uniqueId) { 111 | return null; //To change body of implemented methods use File | Settings | File Templates. 112 | } 113 | 114 | @Override 115 | public boolean unloadWorld(World world) { 116 | return false; //To change body of implemented methods use File | Settings | File Templates. 117 | } 118 | 119 | @Override 120 | public WorldProperties createWorldProperties(String folderName, WorldArchetype archetype) throws IOException { 121 | return null; 122 | } 123 | 124 | @Override 125 | public CompletableFuture> copyWorld(WorldProperties worldProperties, String copyName) { 126 | return null; 127 | } 128 | 129 | @Override 130 | public java.util.Optional renameWorld(WorldProperties worldProperties, String newName) { 131 | return null; 132 | } 133 | 134 | @Override 135 | public CompletableFuture deleteWorld(WorldProperties worldProperties) { 136 | return null; 137 | } 138 | 139 | @Override 140 | public boolean saveWorldProperties(WorldProperties properties) { 141 | return false; //To change body of implemented methods use File | Settings | File Templates. 142 | } 143 | 144 | @Override 145 | public java.util.Optional getServerScoreboard() { 146 | return null; 147 | } 148 | 149 | @Override 150 | public ChunkLayout getChunkLayout() { 151 | return null; //To change body of implemented methods use File | Settings | File Templates. 152 | } 153 | 154 | @Override 155 | public int getRunningTimeTicks() { 156 | return 0; //To change body of implemented methods use File | Settings | File Templates. 157 | } 158 | 159 | @Override 160 | public MessageChannel getBroadcastChannel() { 161 | return null; 162 | } 163 | 164 | @Override 165 | public void setBroadcastChannel(MessageChannel channel) { 166 | 167 | } 168 | 169 | @Override 170 | public Optional getBoundAddress() { 171 | return null; //To change body of implemented methods use File | Settings | File Templates. 172 | } 173 | 174 | @Override 175 | public boolean hasWhitelist() { 176 | return handle.hasWhitelist(); 177 | } 178 | 179 | @Override 180 | public void setHasWhitelist(boolean enabled) { 181 | handle.setWhitelist(enabled); 182 | } 183 | 184 | @Override 185 | public boolean getOnlineMode() { 186 | return handle.getOnlineMode(); 187 | } 188 | 189 | @Override 190 | public Text getMotd() { 191 | return Text.of(handle.getMotd()); 192 | } 193 | 194 | @Override 195 | public void shutdown() { 196 | 197 | } 198 | 199 | @Override 200 | public void shutdown(Text kickMessage) { 201 | //TODO handle.getShutdownMessage() 202 | handle.shutdown(); 203 | } 204 | 205 | @Override 206 | public ConsoleSource getConsole() { 207 | return consoleSource; 208 | } 209 | 210 | @Override 211 | public ChunkTicketManager getChunkTicketManager() { 212 | return null; 213 | } 214 | 215 | @Override 216 | public GameProfileManager getGameProfileManager() { 217 | return null; 218 | } 219 | 220 | @Override 221 | public double getTicksPerSecond() { 222 | return 0; 223 | } 224 | 225 | @Override 226 | public java.util.Optional getDefaultResourcePack() { 227 | return null; 228 | } 229 | 230 | @Override 231 | public int getPlayerIdleTimeout() { 232 | return 0; 233 | } 234 | 235 | @Override 236 | public void setPlayerIdleTimeout(int timeout) { 237 | 238 | } 239 | 240 | @Override 241 | public boolean isMainThread() { 242 | return false; 243 | } 244 | } 245 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/block/ShinyBlockSnapshot.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.block; 2 | 3 | import com.flowpowered.math.vector.Vector3i; 4 | import net.glowstone.bukkit2sponge.util.Unsupported; 5 | import org.spongepowered.api.block.BlockSnapshot; 6 | import org.spongepowered.api.block.BlockState; 7 | import org.spongepowered.api.block.tileentity.TileEntityArchetype; 8 | import org.spongepowered.api.data.DataContainer; 9 | import org.spongepowered.api.data.Property; 10 | import org.spongepowered.api.data.key.Key; 11 | import org.spongepowered.api.data.manipulator.ImmutableDataManipulator; 12 | import org.spongepowered.api.data.merge.MergeFunction; 13 | import org.spongepowered.api.data.value.BaseValue; 14 | import org.spongepowered.api.data.value.immutable.ImmutableValue; 15 | import org.spongepowered.api.world.BlockChangeFlag; 16 | import org.spongepowered.api.world.Location; 17 | import org.spongepowered.api.world.World; 18 | 19 | import java.util.*; 20 | import java.util.function.Function; 21 | 22 | public class ShinyBlockSnapshot implements BlockSnapshot { 23 | 24 | private final BlockState state; 25 | 26 | public ShinyBlockSnapshot(BlockState state) { 27 | this.state = state; 28 | } 29 | 30 | public ShinyBlockSnapshot(org.bukkit.block.BlockState bukkitState) { 31 | ShinyBlockType type = new ShinyBlockType(bukkitState.getBlock().getType()); 32 | ShinyBlockState state = new ShinyBlockState(type); 33 | this.state = state; 34 | } 35 | 36 | @Override 37 | public BlockState getState() { 38 | return state; 39 | } 40 | 41 | @Override 42 | public BlockState getExtendedState() { 43 | return null; 44 | } 45 | 46 | @Override 47 | public BlockSnapshot withState(BlockState blockState) { 48 | return null; 49 | } 50 | 51 | @Override 52 | public BlockSnapshot withContainer(DataContainer container) { 53 | return null; 54 | } 55 | 56 | @Override 57 | public boolean restore(boolean force, BlockChangeFlag flag) { 58 | return false; 59 | } 60 | 61 | @Override 62 | public Optional getCreator() { 63 | return null; 64 | } 65 | 66 | @Override 67 | public Optional getNotifier() { 68 | return null; 69 | } 70 | 71 | @Override 72 | public Optional createArchetype() { 73 | return null; 74 | } 75 | 76 | @Override 77 | public UUID getWorldUniqueId() { 78 | return null; 79 | } 80 | 81 | @Override 82 | public Vector3i getPosition() { 83 | return null; 84 | } 85 | 86 | @Override 87 | public Optional> getLocation() { 88 | return null; 89 | } 90 | 91 | @Override 92 | public BlockSnapshot withLocation(Location location) { 93 | return null; 94 | } 95 | 96 | @Override 97 | public List> getManipulators() { 98 | return null; 99 | } 100 | 101 | @Override 102 | public int getContentVersion() { 103 | return 0; 104 | } 105 | 106 | @Override 107 | public DataContainer toContainer() { 108 | return null; 109 | } 110 | 111 | @Override 112 | public > Optional getProperty(Class propertyClass) { 113 | return null; 114 | } 115 | 116 | @Override 117 | public Collection> getApplicableProperties() { 118 | throw Unsupported.missing(); 119 | } 120 | 121 | @Override 122 | public > Optional get(Class containerClass) { 123 | return null; 124 | } 125 | 126 | @Override 127 | public > Optional getOrCreate(Class containerClass) { 128 | return get(containerClass); 129 | } 130 | 131 | @Override 132 | public boolean supports(Class> containerClass) { 133 | return false; 134 | } 135 | 136 | @Override 137 | public Optional transform(Key> key, Function function) { 138 | return null; 139 | } 140 | 141 | @Override 142 | public Optional with(Key> key, E value) { 143 | return null; 144 | } 145 | 146 | @Override 147 | public Optional with(BaseValue value) { 148 | return null; 149 | } 150 | 151 | @Override 152 | public Optional with(ImmutableDataManipulator valueContainer) { 153 | return null; 154 | } 155 | 156 | @Override 157 | public Optional with(Iterable> valueContainers) { 158 | return null; 159 | } 160 | 161 | @Override 162 | public Optional without(Class> containerClass) { 163 | return null; 164 | } 165 | 166 | @Override 167 | public BlockSnapshot merge(BlockSnapshot that) { 168 | return null; 169 | } 170 | 171 | @Override 172 | public BlockSnapshot merge(BlockSnapshot that, MergeFunction function) { 173 | return null; 174 | } 175 | 176 | @Override 177 | public List> getContainers() { 178 | return null; 179 | } 180 | 181 | @Override 182 | public Optional get(Key> key) { 183 | return null; 184 | } 185 | 186 | @Override 187 | public > Optional getValue(Key key) { 188 | return null; 189 | } 190 | 191 | @Override 192 | public boolean supports(Key key) { 193 | return false; 194 | } 195 | 196 | @Override 197 | public BlockSnapshot copy() { 198 | return null; 199 | } 200 | 201 | @Override 202 | public Set> getKeys() { 203 | return null; 204 | } 205 | 206 | @Override 207 | public Set> getValues() { 208 | return null; 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/block/ShinyBlockState.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.block; 2 | 3 | import org.spongepowered.api.block.BlockSnapshot; 4 | import org.spongepowered.api.block.BlockState; 5 | import org.spongepowered.api.block.BlockType; 6 | import org.spongepowered.api.block.trait.BlockTrait; 7 | import org.spongepowered.api.data.DataContainer; 8 | import org.spongepowered.api.data.Property; 9 | import org.spongepowered.api.data.key.Key; 10 | import org.spongepowered.api.data.manipulator.ImmutableDataManipulator; 11 | import org.spongepowered.api.data.merge.MergeFunction; 12 | import org.spongepowered.api.data.value.BaseValue; 13 | import org.spongepowered.api.data.value.immutable.ImmutableValue; 14 | import org.spongepowered.api.util.Cycleable; 15 | import org.spongepowered.api.util.Direction; 16 | import org.spongepowered.api.world.Location; 17 | import org.spongepowered.api.world.World; 18 | 19 | import java.util.*; 20 | import java.util.function.Function; 21 | 22 | public class ShinyBlockState implements BlockState { 23 | 24 | private final BlockType type; 25 | 26 | public ShinyBlockState(BlockType type) { 27 | this.type = type; 28 | } 29 | 30 | @Override 31 | public BlockType getType() { 32 | return this.type; 33 | } 34 | 35 | @Override 36 | public BlockState withExtendedProperties(Location location) { 37 | return null; 38 | } 39 | 40 | @Override 41 | public BlockState cycleValue(Key>> key) { 42 | return null; 43 | } 44 | 45 | @Override 46 | public BlockSnapshot snapshotFor(Location location) { 47 | return null; 48 | } 49 | 50 | @Override 51 | public > Optional getTraitValue(BlockTrait blockTrait) { 52 | return null; 53 | } 54 | 55 | @Override 56 | public Optional> getTrait(String blockTrait) { 57 | return null; 58 | } 59 | 60 | @Override 61 | public Optional withTrait(BlockTrait trait, Object value) { 62 | return null; 63 | } 64 | 65 | @Override 66 | public Collection> getTraits() { 67 | return null; 68 | } 69 | 70 | @Override 71 | public Collection getTraitValues() { 72 | return null; 73 | } 74 | 75 | @Override 76 | public Map, ?> getTraitMap() { 77 | return null; 78 | } 79 | 80 | @Override 81 | public String getId() { 82 | return null; 83 | } 84 | 85 | @Override 86 | public String getName() { 87 | return null; 88 | } 89 | 90 | @Override 91 | public List> getManipulators() { 92 | return null; 93 | } 94 | 95 | @Override 96 | public int getContentVersion() { 97 | return 0; 98 | } 99 | 100 | @Override 101 | public DataContainer toContainer() { 102 | return null; 103 | } 104 | 105 | @Override 106 | public > Optional getProperty(Direction direction, Class clazz) { 107 | return null; 108 | } 109 | 110 | @Override 111 | public > Optional getProperty(Class propertyClass) { 112 | return null; 113 | } 114 | 115 | @Override 116 | public Collection> getApplicableProperties() { 117 | return null; 118 | } 119 | 120 | @Override 121 | public > Optional get(Class containerClass) { 122 | return null; 123 | } 124 | 125 | @Override 126 | public > Optional getOrCreate(Class containerClass) { 127 | return get(containerClass); 128 | } 129 | 130 | @Override 131 | public boolean supports(Class> containerClass) { 132 | return false; 133 | } 134 | 135 | @Override 136 | public Optional transform(Key> key, Function function) { 137 | return null; 138 | } 139 | 140 | @Override 141 | public Optional with(Key> key, E value) { 142 | return null; 143 | } 144 | 145 | @Override 146 | public Optional with(BaseValue value) { 147 | return null; 148 | } 149 | 150 | @Override 151 | public Optional with(ImmutableDataManipulator valueContainer) { 152 | return null; 153 | } 154 | 155 | @Override 156 | public Optional with(Iterable> valueContainers) { 157 | return null; 158 | } 159 | 160 | @Override 161 | public Optional without(Class> containerClass) { 162 | return null; 163 | } 164 | 165 | @Override 166 | public BlockState merge(BlockState that) { 167 | return null; 168 | } 169 | 170 | @Override 171 | public BlockState merge(BlockState that, MergeFunction function) { 172 | return null; 173 | } 174 | 175 | @Override 176 | public List> getContainers() { 177 | return null; 178 | } 179 | 180 | @Override 181 | public Optional get(Key> key) { 182 | return null; 183 | } 184 | 185 | @Override 186 | public > Optional getValue(Key key) { 187 | return null; 188 | } 189 | 190 | @Override 191 | public boolean supports(Key key) { 192 | return false; 193 | } 194 | 195 | @Override 196 | public BlockState copy() { 197 | return null; 198 | } 199 | 200 | @Override 201 | public Set> getKeys() { 202 | return null; 203 | } 204 | 205 | @Override 206 | public Set> getValues() { 207 | return null; 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/block/ShinyBlockType.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.block; 2 | 3 | import org.bukkit.Material; 4 | import org.spongepowered.api.block.BlockSoundGroup; 5 | import org.spongepowered.api.block.BlockState; 6 | import org.spongepowered.api.block.BlockType; 7 | import org.spongepowered.api.block.trait.BlockTrait; 8 | import org.spongepowered.api.data.Property; 9 | import org.spongepowered.api.item.ItemType; 10 | import org.spongepowered.api.text.translation.Translation; 11 | 12 | import java.util.Collection; 13 | import java.util.Optional; 14 | 15 | public class ShinyBlockType implements BlockType { 16 | 17 | private final String name; 18 | private final Material material; 19 | 20 | public ShinyBlockType(Material material) { 21 | this.material = material; 22 | this.name = material.toString(); 23 | } 24 | 25 | @Override 26 | public String getId() { 27 | return null; //To change body of implemented methods use File | Settings | File Templates. 28 | } 29 | 30 | @Override 31 | public String getName() { 32 | return this.name; 33 | } 34 | 35 | @Override 36 | public BlockState getDefaultState() { 37 | return null; //To change body of implemented methods use File | Settings | File Templates. 38 | } 39 | 40 | @Override 41 | public Collection getAllBlockStates() { 42 | return null; 43 | } 44 | 45 | @Override 46 | public Optional getItem() { 47 | return null; 48 | } 49 | 50 | @Override 51 | public boolean getTickRandomly() { 52 | return false; //To change body of implemented methods use File | Settings | File Templates. 53 | } 54 | 55 | @Override 56 | public void setTickRandomly(boolean tickRandomly) { 57 | //To change body of implemented methods use File | Settings | File Templates. 58 | } 59 | 60 | @Override 61 | public Collection> getTraits() { 62 | return null; 63 | } 64 | 65 | @Override 66 | public Optional> getTrait(String blockTrait) { 67 | return null; 68 | } 69 | 70 | @Override 71 | public BlockSoundGroup getSoundGroup() { 72 | return null; 73 | } 74 | 75 | @Override 76 | public Translation getTranslation() { 77 | return null; //To change body of implemented methods use File | Settings | File Templates. 78 | } 79 | 80 | @Override 81 | public > Optional getProperty(Class propertyClass) { 82 | return null; 83 | } 84 | 85 | @Override 86 | public Collection> getApplicableProperties() { 87 | return null; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/bukkit/BukkitListener.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.bukkit; 2 | 3 | import org.bukkit.event.Listener; 4 | 5 | public class BukkitListener implements Listener { 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/command/BukkitCommand.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.command; 2 | 3 | import com.google.common.base.Joiner; 4 | import net.glowstone.bukkit2sponge.Bukkit2Sponge; 5 | import org.bukkit.command.Command; 6 | import org.bukkit.command.CommandSender; 7 | import org.bukkit.command.ConsoleCommandSender; 8 | import org.spongepowered.api.command.CommandException; 9 | import org.spongepowered.api.command.CommandMapping; 10 | import org.spongepowered.api.command.CommandResult; 11 | import org.spongepowered.api.command.CommandSource; 12 | import org.spongepowered.api.text.Text; 13 | import org.spongepowered.api.text.serializer.TextSerializers; 14 | 15 | import java.util.ArrayList; 16 | import java.util.Optional; 17 | 18 | public class BukkitCommand extends Command { 19 | 20 | private CommandMapping commandMapping; 21 | 22 | public BukkitCommand(CommandMapping commandMapping) { 23 | super(commandMapping.getPrimaryAlias(), 24 | getDescription(commandMapping), 25 | getUsage(commandMapping), 26 | new ArrayList<>(commandMapping.getAllAliases())); // TODO: remove primary alias? 27 | 28 | this.commandMapping = commandMapping; 29 | } 30 | 31 | private static String getDescription(CommandMapping commandMapping) { 32 | Optional textOptional = commandMapping.getCallable().getShortDescription(Bukkit2Sponge.instance.getGame().getServer().getConsole()); 33 | return textOptional.map(TextSerializers.PLAIN::serialize).orElseGet(commandMapping::getPrimaryAlias); 34 | } 35 | 36 | private static String getUsage(CommandMapping commandMapping) { 37 | Text text = commandMapping.getCallable().getUsage(Bukkit2Sponge.instance.getGame().getServer().getConsole()); 38 | 39 | return TextSerializers.PLAIN.serialize(text); 40 | } 41 | 42 | @Override 43 | public boolean execute(CommandSender commandSender, String s, String[] strings) { 44 | CommandSource commandSource; 45 | 46 | if (commandSender instanceof ConsoleCommandSender) { 47 | commandSource = Bukkit2Sponge.instance.getGame().getServer().getConsole(); 48 | } else { 49 | commandSource = null; // TODO: players, etc. 50 | } 51 | 52 | String arguments = Joiner.on(' ').join(strings); // TODO: ? 53 | 54 | try { 55 | CommandResult commandResult = commandMapping.getCallable().process(commandSource, arguments); 56 | 57 | return commandResult != null; // TODO 58 | } catch (CommandException ex) { 59 | ex.printStackTrace(); 60 | return false; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/command/ShinyConsoleSource.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.command; 2 | 3 | import net.glowstone.bukkit2sponge.permission.ShinySubject; 4 | import org.spongepowered.api.command.source.ConsoleSource; 5 | import org.spongepowered.api.text.Text; 6 | import org.spongepowered.api.text.channel.MessageChannel; 7 | 8 | public class ShinyConsoleSource extends ShinySubject implements ConsoleSource { 9 | public ShinyConsoleSource(String identifier) { 10 | super(identifier); 11 | } 12 | 13 | @Override 14 | public String getName() { 15 | return this.getIdentifier(); 16 | } 17 | 18 | // org.spongepowered.api.service.permission.Subject 19 | @Override 20 | public boolean hasPermission(String permission) { 21 | return true; // console has all permissions 22 | } 23 | 24 | @Override 25 | public void sendMessage(Text message) { 26 | 27 | } 28 | 29 | @Override 30 | public MessageChannel getMessageChannel() { 31 | return null; 32 | } 33 | 34 | @Override 35 | public void setMessageChannel(MessageChannel channel) { 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/event/BaseEvent.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.event; 2 | 3 | import org.spongepowered.api.event.Event; 4 | import org.spongepowered.api.event.cause.Cause; 5 | 6 | /** 7 | * A base class for defining events. 8 | */ 9 | public class BaseEvent implements Event { 10 | public BaseEvent() { 11 | } 12 | 13 | @Override 14 | public Cause getCause() { 15 | return null; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/event/EventRegistration.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.event; 2 | 3 | import net.glowstone.bukkit2sponge.Bukkit2Sponge; 4 | import org.spongepowered.api.event.Cancellable; 5 | import org.spongepowered.api.event.Event; 6 | 7 | import java.lang.reflect.InvocationTargetException; 8 | import java.lang.reflect.Method; 9 | import java.util.logging.Level; 10 | 11 | /** 12 | * Container for a single object listening for some event. 13 | */ 14 | public final class EventRegistration { 15 | 16 | private final Object object; 17 | private final Method method; 18 | private final boolean ignoreCancelled; 19 | private final Class clazz; 20 | 21 | public EventRegistration(Object object, Method method, boolean ignoreCancelled) { 22 | this.object = object; 23 | this.method = method; 24 | this.ignoreCancelled = ignoreCancelled; 25 | clazz = method.getParameterTypes()[0]; 26 | } 27 | 28 | public Object getObject() { 29 | return object; 30 | } 31 | 32 | public void call(Event event) { 33 | if (ignoreCancelled && (event instanceof Cancellable) && ((Cancellable) event).isCancelled()) { 34 | return; 35 | } 36 | 37 | if (clazz.isAssignableFrom(event.getClass())) { 38 | try { 39 | method.invoke(object, event); 40 | } catch (InvocationTargetException e) { 41 | Bukkit2Sponge.instance.getLogger().log(Level.WARNING, "Event error", e.getTargetException()); 42 | } catch (IllegalAccessException e) { 43 | Bukkit2Sponge.instance.getLogger().log(Level.WARNING, "Event error", e); 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/event/ShinyEventManager.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.event; 2 | 3 | import org.spongepowered.api.event.*; 4 | 5 | import java.util.EnumMap; 6 | import java.util.LinkedList; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | /** 11 | * Implementation of {@link EventManager}. 12 | */ 13 | public class ShinyEventManager implements EventManager { 14 | 15 | private final Map> registrations = new EnumMap<>(Order.class); 16 | 17 | public ShinyEventManager() { 18 | for (Order order : Order.values()) { 19 | registrations.put(order, new LinkedList()); 20 | } 21 | } 22 | 23 | @Override 24 | public void registerListeners(Object plugin, Object obj) { 25 | 26 | } 27 | 28 | @Override 29 | public void registerListener(Object plugin, Class eventClass, EventListener listener) { 30 | 31 | } 32 | 33 | @Override 34 | public void registerListener(Object plugin, Class eventClass, Order order, EventListener listener) { 35 | 36 | } 37 | 38 | @Override 39 | public void registerListener(Object plugin, Class eventClass, Order order, boolean beforeModifications, EventListener listener) { 40 | 41 | } 42 | 43 | @Override 44 | public void unregisterListeners(Object obj) { 45 | 46 | } 47 | 48 | @Override 49 | public void unregisterPluginListeners(Object plugin) { 50 | 51 | } 52 | 53 | @Override 54 | public boolean post(Event event) { 55 | for (List list : registrations.values()) { 56 | for (EventRegistration reg : list) { 57 | reg.call(event); 58 | } 59 | } 60 | return !(event instanceof Cancellable) || ((Cancellable) event).isCancelled(); 61 | } 62 | 63 | public void callSpecial(Object target, Event event) { 64 | for (List list : registrations.values()) { 65 | for (EventRegistration reg : list) { 66 | if (reg.getObject() == target) { 67 | reg.call(event); 68 | } 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/guice/ConfigDirAnnotation.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.guice; 2 | 3 | // based on https://github.com/SpongePowered/Sponge/blob/master/src/main/java/org/spongepowered/mod/guice/ConfigDirAnnotation.java 4 | 5 | /* 6 | * This file is part of Sponge, licensed under the MIT License (MIT). 7 | * 8 | * Copyright (c) SpongePowered 9 | * Copyright (c) contributors 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | * THE SOFTWARE. 28 | */ 29 | 30 | import org.spongepowered.api.config.ConfigDir; 31 | 32 | import java.lang.annotation.Annotation; 33 | 34 | // This is strange, but required for Guice and annotations with values. 35 | class ConfigDirAnnotation implements ConfigDir { 36 | 37 | boolean shared; 38 | 39 | ConfigDirAnnotation(boolean isShared) { 40 | this.shared = isShared; 41 | } 42 | 43 | @Override 44 | public boolean sharedRoot() { 45 | return this.shared; 46 | } 47 | 48 | @Override 49 | public Class annotationType() { 50 | return ConfigDir.class; 51 | } 52 | 53 | // See Javadocs for java.lang.annotation.Annotation for specification of equals, hashCode, toString 54 | @Override 55 | public boolean equals(Object o) { 56 | if (this == o) { 57 | return true; 58 | } 59 | if (o == null || !(o instanceof ConfigDir)) { 60 | return false; 61 | } 62 | 63 | ConfigDir that = (ConfigDir) o; 64 | 65 | return sharedRoot() == that.sharedRoot(); 66 | } 67 | 68 | @Override 69 | public int hashCode() { 70 | return (127 * "sharedRoot".hashCode()) ^ Boolean.valueOf(sharedRoot()).hashCode(); 71 | } 72 | 73 | @Override 74 | public String toString() { 75 | return "@org.spongepowered.api.service.config.ConfigDir(" 76 | + "sharedRoot=" + this.shared 77 | + ')'; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/guice/ConfigFileAnnotation.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.guice; 2 | 3 | // based on https://github.com/SpongePowered/SpongeVanilla/blob/master/src/main/java/org/spongepowered/granite/guice/ConfigFileAnnotation.java 4 | 5 | /* 6 | * This file is part of Granite, licensed under the MIT License (MIT). 7 | * 8 | * Copyright (c) SpongePowered 9 | * Copyright (c) contributors 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | * THE SOFTWARE. 28 | */ 29 | 30 | import org.spongepowered.api.config.DefaultConfig; 31 | 32 | import java.lang.annotation.Annotation; 33 | 34 | class ConfigFileAnnotation implements DefaultConfig { 35 | 36 | private final boolean shared; 37 | 38 | ConfigFileAnnotation(boolean shared) { 39 | this.shared = shared; 40 | } 41 | 42 | @Override 43 | public boolean sharedRoot() { 44 | return this.shared; 45 | } 46 | 47 | @Override 48 | public Class annotationType() { 49 | return DefaultConfig.class; 50 | } 51 | 52 | @Override 53 | public boolean equals(Object o) { 54 | if (this == o) { 55 | return true; 56 | } 57 | if (!(o instanceof DefaultConfig)) { 58 | return false; 59 | } 60 | 61 | DefaultConfig that = (DefaultConfig) o; 62 | return sharedRoot() == that.sharedRoot(); 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | return (127 * "sharedRoot".hashCode()) ^ Boolean.valueOf(sharedRoot()).hashCode(); 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return '@' + getClass().getName() + "{" + 73 | "shared: " + this.shared + "}"; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/guice/ShinyGuiceModule.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.guice; 2 | 3 | import com.google.inject.AbstractModule; 4 | import com.google.inject.Scopes; 5 | import net.glowstone.bukkit2sponge.Bukkit2Sponge; 6 | import net.glowstone.bukkit2sponge.ShinyGame; 7 | import net.glowstone.bukkit2sponge.ShinyGameRegistry; 8 | import net.glowstone.bukkit2sponge.plugin.ShinyPluginManager; 9 | import org.spongepowered.api.Game; 10 | import org.spongepowered.api.GameRegistry; 11 | import org.spongepowered.api.plugin.PluginManager; 12 | 13 | import java.io.File; 14 | 15 | public class ShinyGuiceModule extends AbstractModule { 16 | @Override 17 | protected void configure() { 18 | bind(Bukkit2Sponge.class).toInstance(Bukkit2Sponge.instance); 19 | bind(Game.class).to(ShinyGame.class).in(Scopes.SINGLETON); 20 | bind(PluginManager.class).to(ShinyPluginManager.class).in(Scopes.SINGLETON); 21 | bind(GameRegistry.class).to(ShinyGameRegistry.class).in(Scopes.SINGLETON); 22 | bind(File.class).annotatedWith(new ConfigDirAnnotation(true)).toInstance(Bukkit2Sponge.instance.getConfigDirectory()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/guice/ShinyPluginGuiceModule.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.guice; 2 | 3 | // based on https://github.com/SpongePowered/SpongeVanilla/blob/master/src/main/java/org/spongepowered/granite/guice/GranitePluginGuiceModule.java 4 | 5 | /* 6 | * This file is part of Granite, licensed under the MIT License (MIT). 7 | * 8 | * Copyright (c) SpongePowered 9 | * Copyright (c) contributors 10 | * 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy 12 | * of this software and associated documentation files (the "Software"), to deal 13 | * in the Software without restriction, including without limitation the rights 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | * copies of the Software, and to permit persons to whom the Software is 16 | * furnished to do so, subject to the following conditions: 17 | * 18 | * The above copyright notice and this permission notice shall be included in 19 | * all copies or substantial portions of the Software. 20 | * 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | * THE SOFTWARE. 28 | */ 29 | 30 | import com.google.inject.AbstractModule; 31 | import com.google.inject.Provider; 32 | import com.google.inject.TypeLiteral; 33 | import net.glowstone.bukkit2sponge.plugin.ShinyPluginContainer; 34 | import ninja.leaping.configurate.commented.CommentedConfigurationNode; 35 | import ninja.leaping.configurate.hocon.HoconConfigurationLoader; 36 | import ninja.leaping.configurate.loader.ConfigurationLoader; 37 | import org.slf4j.Logger; 38 | import org.slf4j.LoggerFactory; 39 | import org.spongepowered.api.config.ConfigDir; 40 | import org.spongepowered.api.config.DefaultConfig; 41 | import org.spongepowered.api.plugin.PluginContainer; 42 | 43 | import javax.inject.Inject; 44 | import java.io.File; 45 | 46 | public class ShinyPluginGuiceModule extends AbstractModule { 47 | 48 | private final ShinyPluginContainer container; 49 | 50 | public ShinyPluginGuiceModule(ShinyPluginContainer container) { 51 | this.container = container; 52 | } 53 | 54 | @Override 55 | protected void configure() { 56 | DefaultConfig pluginConfigPrivate = new ConfigFileAnnotation(false); 57 | DefaultConfig pluginConfigShared = new ConfigFileAnnotation(true); 58 | ConfigDir pluginDirPrivate = new ConfigDirAnnotation(false); 59 | 60 | bind(PluginContainer.class).toInstance(this.container); 61 | bind(Logger.class).toInstance(LoggerFactory.getLogger(this.container.getId())); 62 | bind(File.class).annotatedWith(pluginDirPrivate) 63 | .toProvider(PluginConfigDirProvider.class); // plugin-private config directory (shared dir is in the global guice module) 64 | bind(File.class).annotatedWith(pluginConfigShared).toProvider(PluginSharedConfigFileProvider.class); // shared-directory config file 65 | bind(File.class).annotatedWith(pluginConfigPrivate).toProvider(PluginPrivateConfigFileProvider.class); // plugin-private directory config file 66 | bind(new TypeLiteral>() { 67 | }).annotatedWith(pluginConfigShared) 68 | .toProvider(PluginSharedHoconConfigProvider.class); // loader for shared-directory config file 69 | bind(new TypeLiteral>() { 70 | }).annotatedWith(pluginConfigPrivate) 71 | .toProvider(PluginPrivateHoconConfigProvider.class); // loader for plugin-private directory config file 72 | } 73 | 74 | private static class PluginSharedConfigFileProvider implements Provider { 75 | 76 | private final PluginContainer container; 77 | private final File root; 78 | 79 | @Inject 80 | private PluginSharedConfigFileProvider(PluginContainer container, @ConfigDir(sharedRoot = true) File sharedConfigDir) { 81 | this.container = container; 82 | this.root = sharedConfigDir; 83 | } 84 | 85 | @Override 86 | public File get() { 87 | return new File(this.root, this.container.getId() + ".conf"); 88 | } 89 | } 90 | 91 | private static class PluginPrivateConfigFileProvider implements Provider { 92 | 93 | private final PluginContainer container; 94 | private final File root; 95 | 96 | @Inject 97 | private PluginPrivateConfigFileProvider(PluginContainer container, @ConfigDir(sharedRoot = false) File sharedConfigDir) { 98 | this.container = container; 99 | this.root = sharedConfigDir; 100 | } 101 | 102 | @Override 103 | public File get() { 104 | return new File(this.root, this.container.getId() + ".conf"); 105 | } 106 | } 107 | 108 | private static class PluginSharedHoconConfigProvider implements Provider> { 109 | 110 | private final File configFile; 111 | 112 | @Inject 113 | private PluginSharedHoconConfigProvider(@DefaultConfig(sharedRoot = true) File configFile) { 114 | this.configFile = configFile; 115 | } 116 | 117 | @Override 118 | public ConfigurationLoader get() { 119 | return HoconConfigurationLoader.builder().setFile(this.configFile).build(); 120 | } 121 | } 122 | 123 | private static class PluginPrivateHoconConfigProvider implements Provider> { 124 | 125 | private final File configFile; 126 | 127 | @Inject 128 | private PluginPrivateHoconConfigProvider(@DefaultConfig(sharedRoot = false) File configFile) { 129 | this.configFile = configFile; 130 | } 131 | 132 | @Override 133 | public ConfigurationLoader get() { 134 | return HoconConfigurationLoader.builder().setFile(this.configFile).build(); 135 | } 136 | } 137 | 138 | private static class PluginConfigDirProvider implements Provider { 139 | 140 | private final PluginContainer container; 141 | private final File sharedConfigDir; 142 | 143 | @Inject 144 | private PluginConfigDirProvider(PluginContainer container, @ConfigDir(sharedRoot = true) File sharedConfigDir) { 145 | this.container = container; 146 | this.sharedConfigDir = sharedConfigDir; 147 | } 148 | 149 | @Override 150 | public File get() { 151 | return new File(this.sharedConfigDir, this.container.getId() + "/"); 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/inventory/ShinyItemStack.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.inventory; 2 | 3 | import org.spongepowered.api.data.*; 4 | import org.spongepowered.api.data.key.Key; 5 | import org.spongepowered.api.data.manipulator.DataManipulator; 6 | import org.spongepowered.api.data.merge.MergeFunction; 7 | import org.spongepowered.api.data.persistence.InvalidDataException; 8 | import org.spongepowered.api.data.value.BaseValue; 9 | import org.spongepowered.api.data.value.immutable.ImmutableValue; 10 | import org.spongepowered.api.event.cause.Cause; 11 | import org.spongepowered.api.item.ItemType; 12 | import org.spongepowered.api.item.inventory.ItemStack; 13 | import org.spongepowered.api.item.inventory.ItemStackSnapshot; 14 | import org.spongepowered.api.text.translation.Translation; 15 | 16 | import java.util.Collection; 17 | import java.util.Set; 18 | 19 | /** 20 | * Implementation of {@link ItemStack}. 21 | */ 22 | public class ShinyItemStack implements ItemStack { 23 | 24 | private final ItemType item; 25 | private int quantity; 26 | private short damage; 27 | 28 | private int maxQuantity; 29 | 30 | public ShinyItemStack(ItemType item) { 31 | this(item, 1, (short) 0); 32 | } 33 | 34 | public ShinyItemStack(ItemType item, int quantity) { 35 | this(item, quantity, (short) 0); 36 | } 37 | 38 | public ShinyItemStack(ItemType item, int quantity, short damage) { 39 | this.item = item; 40 | this.quantity = quantity; 41 | this.damage = damage; 42 | maxQuantity = item.getMaxStackQuantity(); 43 | } 44 | 45 | @Override 46 | public ItemType getItem() { 47 | return item; 48 | } 49 | 50 | @Override 51 | public int getQuantity() { 52 | return quantity; 53 | } 54 | 55 | @Override 56 | public void setQuantity(int quantity) throws IllegalArgumentException { 57 | if (quantity > maxQuantity) { 58 | throw new IllegalArgumentException("Quantity exceeds max: " + quantity + " > " + maxQuantity); 59 | } 60 | this.quantity = quantity; 61 | } 62 | 63 | @Override 64 | public int getMaxStackQuantity() { 65 | return maxQuantity; 66 | } 67 | 68 | @Override 69 | public ItemStackSnapshot createSnapshot() { 70 | return null; 71 | } 72 | 73 | @Override 74 | public boolean equalTo(ItemStack that) { 75 | return false; 76 | } 77 | 78 | @Override 79 | public boolean isEmpty() { 80 | return false; 81 | } 82 | 83 | @Override 84 | public java.util.Optional get(Key> key) { 85 | return null; 86 | } 87 | 88 | @Override 89 | public > java.util.Optional getValue(Key key) { 90 | return null; 91 | } 92 | 93 | @Override 94 | public boolean supports(Key key) { 95 | return false; 96 | } 97 | 98 | @Override 99 | public ItemStack copy() { 100 | return null; 101 | } 102 | 103 | @Override 104 | public Set> getKeys() { 105 | return null; 106 | } 107 | 108 | @Override 109 | public Set> getValues() { 110 | return null; 111 | } 112 | 113 | @Override 114 | public boolean validateRawData(DataView container) { 115 | return false; 116 | } 117 | 118 | @Override 119 | public void setRawData(DataView container) throws InvalidDataException { 120 | 121 | } 122 | 123 | @Override 124 | public int getContentVersion() { 125 | return 0; 126 | } 127 | 128 | @Override 129 | public DataContainer toContainer() { 130 | return null; 131 | } 132 | 133 | @Override 134 | public > java.util.Optional getProperty(Class propertyClass) { 135 | return null; 136 | } 137 | 138 | @Override 139 | public Collection> getApplicableProperties() { 140 | return null; 141 | } 142 | 143 | @Override 144 | public > java.util.Optional get(Class containerClass) { 145 | return null; 146 | } 147 | 148 | @Override 149 | public > java.util.Optional getOrCreate(Class containerClass) { 150 | return null; 151 | } 152 | 153 | @Override 154 | public boolean supports(Class> holderClass) { 155 | return false; 156 | } 157 | 158 | @Override 159 | public DataTransactionResult offer(Key> key, E value) { 160 | return null; 161 | } 162 | 163 | @Override 164 | public DataTransactionResult offer(Key> key, E value, Cause cause) { 165 | return null; 166 | } 167 | 168 | @Override 169 | public DataTransactionResult offer(DataManipulator valueContainer, MergeFunction function) { 170 | return null; 171 | } 172 | 173 | @Override 174 | public DataTransactionResult offer(DataManipulator valueContainer, MergeFunction function, Cause cause) { 175 | return null; 176 | } 177 | 178 | @Override 179 | public DataTransactionResult remove(Class> containerClass) { 180 | return null; 181 | } 182 | 183 | @Override 184 | public DataTransactionResult remove(Key key) { 185 | return null; 186 | } 187 | 188 | @Override 189 | public DataTransactionResult undo(DataTransactionResult result) { 190 | return null; 191 | } 192 | 193 | @Override 194 | public DataTransactionResult copyFrom(DataHolder that, MergeFunction function) { 195 | return null; 196 | } 197 | 198 | @Override 199 | public Collection> getContainers() { 200 | return null; 201 | } 202 | 203 | @Override 204 | public Translation getTranslation() { 205 | return null; 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/item/ShinyItemType.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.item; 2 | 3 | import org.spongepowered.api.block.BlockType; 4 | import org.spongepowered.api.data.Property; 5 | import org.spongepowered.api.item.ItemType; 6 | import org.spongepowered.api.text.translation.Translation; 7 | 8 | import java.util.Optional; 9 | 10 | /** 11 | * Todo: Javadoc for ShinyItemType. 12 | */ 13 | public class ShinyItemType implements ItemType { 14 | 15 | private final String id; 16 | 17 | public ShinyItemType(String id) { 18 | this.id = id; 19 | } 20 | 21 | @Override 22 | public String getId() { 23 | return id; 24 | } 25 | 26 | @Override 27 | public Optional getBlock() { 28 | return null; 29 | } 30 | 31 | @Override 32 | public String getName() { 33 | return toString(); 34 | } 35 | 36 | @Override 37 | public int getMaxStackQuantity() { 38 | return 64; 39 | } 40 | 41 | @Override 42 | public > Optional getDefaultProperty(Class propertyClass) { 43 | return null; //To change body of implemented methods use File | Settings | File Templates. 44 | } 45 | 46 | @Override 47 | public Translation getTranslation() { 48 | return null; //Text.of("item." + id + ".name").get(); // TODO 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return getTranslation().getId(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/item/ShinyItemTypes.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.item; 2 | 3 | import org.spongepowered.api.item.ItemType; 4 | 5 | /** 6 | * Todo: Javadoc for ShinyItemTypes. 7 | */ 8 | public final class ShinyItemTypes { 9 | 10 | private ShinyItemTypes() { 11 | } 12 | 13 | public static final ItemType IRON_SHOVEL = new ShinyItemType("iron_shovel"); 14 | public static final ItemType IRON_PICKAXE = new ShinyItemType("iron_pickaxe"); 15 | public static final ItemType IRON_AXE = new ShinyItemType("iron_axe"); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/permission/ShinySubject.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.permission; 2 | 3 | import org.spongepowered.api.command.CommandSource; 4 | import org.spongepowered.api.service.context.Context; 5 | import org.spongepowered.api.service.permission.Subject; 6 | import org.spongepowered.api.service.permission.SubjectCollection; 7 | import org.spongepowered.api.service.permission.SubjectData; 8 | import org.spongepowered.api.util.Tristate; 9 | 10 | import java.util.List; 11 | import java.util.Optional; 12 | import java.util.Set; 13 | 14 | public class ShinySubject implements Subject { 15 | private String identifier; 16 | 17 | public ShinySubject(String identifier) 18 | { 19 | this.identifier = identifier; 20 | } 21 | 22 | @Override 23 | public String getIdentifier() { 24 | return this.identifier; 25 | } 26 | 27 | @Override 28 | public Optional getCommandSource() { 29 | return null; //To change body of implemented methods use File | Settings | File Templates. 30 | } 31 | 32 | @Override 33 | public SubjectCollection getContainingCollection() { 34 | return null; //To change body of implemented methods use File | Settings | File Templates. 35 | } 36 | 37 | @Override 38 | public SubjectData getSubjectData() { 39 | return null; 40 | } 41 | 42 | @Override 43 | public SubjectData getTransientSubjectData() { 44 | return null; 45 | } 46 | 47 | @Override 48 | public boolean hasPermission(Set contexts, String permission) { 49 | return false; //To change body of implemented methods use File | Settings | File Templates. 50 | } 51 | 52 | @Override 53 | public boolean hasPermission(String permission) { 54 | return false; //To change body of implemented methods use File | Settings | File Templates. 55 | } 56 | 57 | @Override 58 | public Tristate getPermissionValue(Set contexts, String permission) { 59 | return null; 60 | } 61 | 62 | @Override 63 | public boolean isChildOf(Subject parent) { 64 | return false; //To change body of implemented methods use File | Settings | File Templates. 65 | } 66 | 67 | @Override 68 | public boolean isChildOf(Set contexts, Subject parent) { 69 | return false; //To change body of implemented methods use File | Settings | File Templates. 70 | } 71 | 72 | @Override 73 | public List getParents() { 74 | return null; //To change body of implemented methods use File | Settings | File Templates. 75 | } 76 | 77 | @Override 78 | public List getParents(Set contexts) { 79 | return null; //To change body of implemented methods use File | Settings | File Templates. 80 | } 81 | 82 | @Override 83 | public Optional getOption(Set contexts, String key) { 84 | return null; 85 | } 86 | 87 | @Override 88 | public Set getActiveContexts() { 89 | return null; //To change body of implemented methods use File | Settings | File Templates. 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/plugin/DefaultShader.java: -------------------------------------------------------------------------------- 1 | 2 | // based on http://svn.apache.org/viewvc/maven/plugins/tags/maven-shade-plugin-2.3/src/main/java/org/apache/maven/plugins/shade/DefaultShader.java?revision=1590870&view=markup 3 | // and http://svn.apache.org/viewvc/maven/plugins/tags/maven-shade-plugin-2.3/src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java?revision=1590870&view=co 4 | 5 | package net.glowstone.bukkit2sponge.plugin; 6 | 7 | 8 | /* 9 | * Licensed to the Apache Software Foundation (ASF) under one 10 | * or more contributor license agreements. See the NOTICE file 11 | * distributed with this work for additional information 12 | * regarding copyright ownership. The ASF licenses this file 13 | * to you under the Apache License, Version 2.0 (the 14 | * "License"); you may not use this file except in compliance 15 | * with the License. You may obtain a copy of the License at 16 | * 17 | * http://www.apache.org/licenses/LICENSE-2.0 18 | * 19 | * Unless required by applicable law or agreed to in writing, 20 | * software distributed under the License is distributed on an 21 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 22 | * KIND, either express or implied. See the License for the 23 | * specific language governing permissions and limitations 24 | * under the License. 25 | */ 26 | 27 | 28 | import java.io.IOException; 29 | import java.util.Iterator; 30 | import java.util.Map; 31 | import java.util.regex.Matcher; 32 | import java.util.regex.Pattern; 33 | 34 | import org.objectweb.asm.ClassReader; 35 | import org.objectweb.asm.ClassVisitor; 36 | import org.objectweb.asm.ClassWriter; 37 | import org.objectweb.asm.commons.Remapper; 38 | import org.objectweb.asm.commons.RemappingClassAdapter; 39 | 40 | 41 | public class DefaultShader 42 | { 43 | private RelocatorRemapper remapper; 44 | 45 | 46 | public DefaultShader( Map replacements) throws IOException 47 | { 48 | this.remapper = new RelocatorRemapper(replacements); 49 | 50 | } 51 | 52 | public byte[] getRemappedClass( byte[] is) 53 | throws IOException 54 | { 55 | 56 | ClassReader cr = new ClassReader( is ); 57 | ClassWriter cw = new ClassWriter( cr, 0 ); 58 | 59 | ClassVisitor cv = new RemappingClassAdapter( cw, remapper ) 60 | { 61 | /* 62 | @Override 63 | public void visitSource( final String source, final String debug ) 64 | { 65 | if ( source == null ) 66 | { 67 | super.visitSource( source, debug ); 68 | } 69 | else 70 | { 71 | final String fqSource = pkg + source; 72 | final String mappedSource = remapper.map( fqSource ); 73 | final String filename = mappedSource.substring( mappedSource.lastIndexOf( '/' ) + 1 ); 74 | super.visitSource( filename, debug ); 75 | } 76 | } 77 | */ 78 | }; 79 | 80 | try 81 | { 82 | cr.accept( cv, ClassReader.EXPAND_FRAMES ); 83 | } 84 | catch ( Throwable ise ) 85 | { 86 | throw new RuntimeException( ise ) ; 87 | } 88 | 89 | byte[] renamedClass = cw.toByteArray(); 90 | 91 | return renamedClass; 92 | } 93 | 94 | /** 95 | * @author Jason van Zyl 96 | */ 97 | 98 | public class RelocatorRemapper 99 | extends Remapper 100 | { 101 | 102 | private final Pattern classPattern = Pattern.compile( "(\\[*)?L(.+);" ); 103 | private final Map replacements; 104 | 105 | public RelocatorRemapper(Map replacements) 106 | { 107 | this.replacements = replacements; 108 | } 109 | 110 | @Override 111 | public Object mapValue( Object object ) 112 | { 113 | if ( object instanceof String ) 114 | { 115 | String name = (String) object; 116 | String value = name; 117 | 118 | String prefix = ""; 119 | String suffix = ""; 120 | 121 | Matcher m = classPattern.matcher( name ); 122 | if ( m.matches() ) 123 | { 124 | prefix = m.group( 1 ) + "L"; 125 | suffix = ";"; 126 | name = m.group( 2 ); 127 | } 128 | 129 | value = map( name ); 130 | 131 | return value; 132 | } 133 | 134 | return super.mapValue( object ); 135 | } 136 | 137 | @Override 138 | public String map( String name ) 139 | { 140 | Iterator it = replacements.entrySet().iterator(); 141 | while (it.hasNext()) { 142 | Map.Entry pair = (Map.Entry) it.next(); 143 | String inPrefix = (String) pair.getKey(); 144 | String outPrefix = (String) pair.getValue(); 145 | 146 | if (name.startsWith(inPrefix)) { 147 | return outPrefix + name; 148 | } 149 | } 150 | return name; 151 | } 152 | 153 | } 154 | 155 | } 156 | 157 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/plugin/GlowstoneConnector.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.plugin; 2 | 3 | import net.glowstone.bukkit2sponge.Bukkit2Sponge; 4 | import org.bukkit.Server; 5 | 6 | import java.io.File; 7 | import java.lang.reflect.Method; 8 | import java.net.MalformedURLException; 9 | import java.net.URL; 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | public class GlowstoneConnector { 14 | 15 | @SuppressWarnings("unchecked") 16 | public static List getSpongePlugins(Server server) { 17 | List files; 18 | 19 | try { 20 | Method method = server.getClass().getMethod("getSpongePlugins"); 21 | 22 | files = (List) method.invoke(server); 23 | } catch (Exception ex) { 24 | //ex.printStackTrace(); // may be an unsupported platform - ignore 25 | return null; 26 | } 27 | 28 | List urls = new ArrayList<>(files.size()); 29 | for (File file : files) { 30 | Bukkit2Sponge.instance.getLogger().info("SpongeAPI plugin from Glowstone: " + file.getPath()); 31 | try { 32 | urls.add(file.toURI().toURL()); 33 | } catch (MalformedURLException ex) { 34 | ex.printStackTrace(); 35 | } 36 | } 37 | 38 | return urls; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/plugin/PluginLoader.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.plugin; 2 | 3 | import net.glowstone.bukkit2sponge.Bukkit2Sponge; 4 | import net.glowstone.bukkit2sponge.ShinyGame; 5 | import org.spongepowered.api.plugin.Plugin; 6 | import org.spongepowered.api.plugin.PluginContainer; 7 | 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | import java.net.URL; 11 | import java.net.URLClassLoader; 12 | import java.util.ArrayList; 13 | import java.util.Iterator; 14 | import java.util.List; 15 | import java.util.logging.Level; 16 | import java.util.zip.ZipEntry; 17 | import java.util.zip.ZipInputStream; 18 | 19 | /** 20 | * Simple plugin loader for sets of jars. 21 | */ 22 | final class PluginLoader { 23 | 24 | private final ShinyGame game; 25 | 26 | public PluginLoader(ShinyGame game) { 27 | this.game = game; 28 | } 29 | 30 | /** 31 | * Load a list of SpongeAPI plugins 32 | * 33 | * @param urls URLs of potential plugins jars to load. This list is mutated, on return it will only 34 | * contain recognized SpongeAPI plugins. 35 | * @return Loaded plugin containers 36 | */ 37 | public List loadPlugins(List urls) { 38 | URLClassLoader root = new URLClassLoader(urls.toArray(new URL[urls.size()]), PluginLoader.class.getClassLoader()); 39 | List result = new ArrayList<>(urls.size()); 40 | 41 | Iterator iterator = urls.iterator(); 42 | while (iterator.hasNext()) { 43 | URL url = iterator.next(); 44 | 45 | if (!loadJar(result, root, url)) 46 | iterator.remove(); 47 | } 48 | 49 | return result; 50 | } 51 | 52 | private boolean loadJar(List result, URLClassLoader root, URL url) { 53 | boolean hasPlugin = false; 54 | 55 | try (ShinyClassLoader classLoader = new ShinyClassLoader(new URL[]{url}, root); 56 | InputStream fileIn = url.openStream(); 57 | ZipInputStream zipIn = new ZipInputStream(fileIn) 58 | ) { 59 | ZipEntry entryIn; 60 | while ((entryIn = zipIn.getNextEntry()) != null) { 61 | String name = entryIn.getName(); 62 | if (name.endsWith(".class") && !entryIn.isDirectory()) { 63 | name = name.substring(0, name.length() - 6).replace("/", "."); 64 | 65 | Class clazz; 66 | try { 67 | clazz = classLoader.findClass(name); 68 | } catch (Throwable t) { 69 | Bukkit2Sponge.instance.getLogger().log(Level.WARNING, "Error loading " + url.getFile() + "/" + name, t); 70 | continue; 71 | } 72 | 73 | PluginContainer container = fromClass(clazz); 74 | 75 | if (container != null) { 76 | result.add(container); 77 | hasPlugin = true; 78 | } 79 | } 80 | } 81 | } catch (IOException ex) { 82 | Bukkit2Sponge.instance.getLogger().warning("Error reading " + url + ex); 83 | } 84 | 85 | return hasPlugin; 86 | } 87 | 88 | private PluginContainer fromClass(Class clazz) { 89 | Plugin annotation = clazz.getAnnotation(Plugin.class); 90 | if (annotation != null) { 91 | try { 92 | ShinyPluginContainer container = new ShinyPluginContainer(clazz); 93 | return container; 94 | } catch (Throwable t) { 95 | Bukkit2Sponge.instance.getLogger().log(Level.WARNING, "Error initializing " + annotation.id() + " (" + clazz + ")", t); 96 | } 97 | } 98 | return null; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/plugin/ShinyClassLoader.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.plugin; 2 | 3 | import com.google.common.io.ByteStreams; 4 | 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.net.JarURLConnection; 8 | import java.net.URL; 9 | import java.net.URLClassLoader; 10 | import java.security.CodeSigner; 11 | import java.security.CodeSource; 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | 15 | public class ShinyClassLoader extends URLClassLoader { 16 | 17 | private static DefaultShader shader = null; 18 | 19 | private final static String com_google_common = new String(new char[] {'c','o','m','/','g','o','o','g','l','e','/','c','o','m','m','o','n'}); 20 | private final static String org_objectweb_asm = new String(new char[] {'o','r','g','/','o','b','j','e','c','t','w','e','b','/','a','s','m'}); 21 | 22 | static { 23 | try { 24 | Map replacements = new HashMap<>(); 25 | 26 | // SpongeAPI library relocations - note: must match pom.xml relocations 27 | replacements.put(com_google_common, "net/glowstone/bukkit2sponge/libs/guava17/"); 28 | replacements.put(org_objectweb_asm, "net/glowstone/bukkit2sponge/libs/asm5/"); 29 | 30 | shader = new DefaultShader(replacements); 31 | } catch (IOException ex) { 32 | ex.printStackTrace(); 33 | } 34 | } 35 | 36 | public ShinyClassLoader(URL[] urls, ClassLoader parent) throws IOException { 37 | super(urls, parent); 38 | } 39 | 40 | private byte[] relocateBytecode(byte[] bytes) throws IOException { 41 | return shader.getRemappedClass(bytes); 42 | } 43 | 44 | @Override 45 | protected Class findClass(String name) throws ClassNotFoundException { 46 | String path = name.replace('.', '/').concat(".class"); 47 | URL url = this.findResource(path); 48 | if (url == null) { 49 | throw new ClassNotFoundException("Unable to find class resource " + name + " at " + path); 50 | } 51 | 52 | InputStream stream = null; 53 | byte[] bytecode = null; 54 | try { 55 | stream = url.openStream(); 56 | bytecode = ByteStreams.toByteArray(stream); 57 | } catch (IOException ex) { 58 | ex.printStackTrace(); 59 | throw new ClassNotFoundException("Unable to open or read stream for class " + name + ": " + ex.getLocalizedMessage()); 60 | } 61 | 62 | CodeSource codeSource = null; 63 | try { 64 | JarURLConnection jarURLConnection = (JarURLConnection) url.openConnection(); 65 | URL jarURL = jarURLConnection.getJarFileURL(); 66 | codeSource = new CodeSource(jarURL, new CodeSigner[0]); 67 | } catch (IOException ex) { 68 | ex.printStackTrace(); 69 | throw new ClassNotFoundException("Unable to read code source for class " + name + ": " + ex.getLocalizedMessage()); 70 | } 71 | 72 | byte[] remappedBytecode; 73 | try { 74 | remappedBytecode = relocateBytecode(bytecode); 75 | } catch (IOException ex) { 76 | ex.printStackTrace(); 77 | //throw new ClassNotFoundException("Unable to relocate class " + name + ": " + ex.getLocalizedMessage()); 78 | remappedBytecode = bytecode; 79 | } 80 | 81 | Class result = this.defineClass(name, remappedBytecode, 0, remappedBytecode.length, codeSource); 82 | if (result != null) { 83 | this.resolveClass(result); 84 | } 85 | 86 | return result; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/plugin/ShinyPluginContainer.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.plugin; 2 | 3 | import com.google.inject.Injector; 4 | import net.glowstone.bukkit2sponge.Bukkit2Sponge; 5 | import net.glowstone.bukkit2sponge.guice.ShinyPluginGuiceModule; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.spongepowered.api.plugin.Plugin; 9 | import org.spongepowered.api.plugin.PluginContainer; 10 | 11 | import java.util.Optional; 12 | 13 | /** 14 | * Implementation of {@link PluginContainer}. 15 | */ 16 | public final class ShinyPluginContainer implements PluginContainer { 17 | 18 | private final String id; 19 | private final String name; 20 | private final String version; 21 | private final Logger logger; 22 | private final Object instance; 23 | 24 | public ShinyPluginContainer(Class pluginClass) { 25 | Plugin info = pluginClass.getAnnotation(Plugin.class); 26 | this.id = info.id(); 27 | this.name = info.name(); 28 | this.version = info.version(); 29 | this.logger = LoggerFactory.getLogger(this.id); 30 | 31 | Injector injector = Bukkit2Sponge.instance.getInjector().createChildInjector(new ShinyPluginGuiceModule(this)); 32 | this.instance = injector.getInstance(pluginClass); 33 | } 34 | 35 | @Override 36 | public String getId() { 37 | return this.id; 38 | } 39 | 40 | @Override 41 | public String getName() { 42 | return this.name; 43 | } 44 | 45 | @Override 46 | public Optional getVersion() { 47 | return Optional.of(this.version); 48 | } 49 | 50 | @Override 51 | public Optional getInstance() { 52 | return Optional.of(this.instance); 53 | } 54 | 55 | public Logger getLogger() { 56 | return this.logger; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/plugin/ShinyPluginManager.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.plugin; 2 | 3 | import com.google.inject.Inject; 4 | import com.google.inject.Singleton; 5 | import net.glowstone.bukkit2sponge.Bukkit2Sponge; 6 | import net.glowstone.bukkit2sponge.ShinyGame; 7 | import org.spongepowered.api.plugin.PluginContainer; 8 | import org.spongepowered.api.plugin.PluginManager; 9 | 10 | import java.io.IOException; 11 | import java.net.URL; 12 | import java.util.*; 13 | 14 | /** 15 | * Implementation of {@link PluginManager}. 16 | */ 17 | 18 | @Singleton 19 | public class ShinyPluginManager implements PluginManager { 20 | 21 | private final ShinyGame game; 22 | private final PluginLoader loader; 23 | 24 | private final Map plugins = new HashMap<>(); 25 | private final Map instanceMap = new IdentityHashMap<>(); 26 | 27 | @Inject 28 | public ShinyPluginManager(ShinyGame game) { 29 | this.game = game; 30 | loader = new PluginLoader(game); 31 | } 32 | 33 | @Override 34 | public Optional fromInstance(Object instance) { 35 | return Optional.ofNullable(instanceMap.get(instance)); 36 | } 37 | 38 | @Override 39 | public Optional getPlugin(String id) { 40 | return Optional.ofNullable(plugins.get(id)); 41 | } 42 | 43 | @Override 44 | public Collection getPlugins() { 45 | return plugins.values(); 46 | } 47 | 48 | @Override 49 | public boolean isLoaded(String id) { 50 | return plugins.containsKey(id); 51 | } 52 | 53 | /** 54 | * Load a directory full of plugins 55 | * 56 | * @return List of recognized SpongeAPI plugin URLs 57 | * @throws IOException 58 | */ 59 | public Collection loadPlugins(List urls) throws IOException { 60 | Collection containers = loader.loadPlugins(urls); 61 | for (PluginContainer container : containers) { 62 | if (plugins.containsKey(container.getId())) { 63 | Bukkit2Sponge.instance.getLogger().warning("Skipped loading duplicate of \"" + container.getId() + "\""); 64 | continue; 65 | } 66 | Bukkit2Sponge.instance.getLogger().info("SpongeAPI plugin found: "+container.getName()+" v"+container.getVersion()); 67 | plugins.put(container.getId(), container); 68 | instanceMap.put(container.getInstance(), container); 69 | game.getEventManager().registerListeners(container.getInstance(), container.getInstance()); 70 | } 71 | 72 | return urls; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/text/ShinyTranslation.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.text; 2 | 3 | import org.spongepowered.api.text.translation.Translation; 4 | 5 | import java.util.Locale; 6 | 7 | /** 8 | * Todo: Javadoc for ShinyTranslation. 9 | */ 10 | public class ShinyTranslation implements Translation { 11 | private final String id; 12 | 13 | public ShinyTranslation(String id) { 14 | this.id = id; 15 | } 16 | 17 | @Override 18 | public String getId() { 19 | return id; 20 | } 21 | 22 | @Override 23 | public String get(Locale locale) { 24 | return id; 25 | } 26 | 27 | @Override 28 | public String get(Locale locale, Object... args) { 29 | return id; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "Translation(" + id + ")"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/util/Unsupported.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.util; 2 | 3 | /** 4 | * Utilities for throwing UnsupportedOperationExceptions. 5 | */ 6 | public final class Unsupported { 7 | 8 | private Unsupported() { 9 | } 10 | 11 | public static UnsupportedOperationException missing() { 12 | return new UnsupportedOperationException("This method is not yet supported."); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/net/glowstone/bukkit2sponge/world/ShinyWorld.java: -------------------------------------------------------------------------------- 1 | package net.glowstone.bukkit2sponge.world; 2 | 3 | import com.flowpowered.math.vector.Vector3d; 4 | import com.flowpowered.math.vector.Vector3i; 5 | import org.spongepowered.api.block.BlockSnapshot; 6 | import org.spongepowered.api.block.BlockState; 7 | import org.spongepowered.api.block.BlockType; 8 | import org.spongepowered.api.block.ScheduledBlockUpdate; 9 | import org.spongepowered.api.block.tileentity.TileEntity; 10 | import org.spongepowered.api.data.*; 11 | import org.spongepowered.api.data.key.Key; 12 | import org.spongepowered.api.data.manipulator.DataManipulator; 13 | import org.spongepowered.api.data.merge.MergeFunction; 14 | import org.spongepowered.api.data.persistence.InvalidDataException; 15 | import org.spongepowered.api.data.value.BaseValue; 16 | import org.spongepowered.api.data.value.immutable.ImmutableValue; 17 | import org.spongepowered.api.effect.particle.ParticleEffect; 18 | import org.spongepowered.api.effect.sound.SoundCategory; 19 | import org.spongepowered.api.effect.sound.SoundType; 20 | import org.spongepowered.api.entity.Entity; 21 | import org.spongepowered.api.entity.EntitySnapshot; 22 | import org.spongepowered.api.entity.EntityType; 23 | import org.spongepowered.api.entity.living.player.Player; 24 | import org.spongepowered.api.event.cause.Cause; 25 | import org.spongepowered.api.item.inventory.ItemStack; 26 | import org.spongepowered.api.service.context.Context; 27 | import org.spongepowered.api.text.BookView; 28 | import org.spongepowered.api.text.Text; 29 | import org.spongepowered.api.text.channel.MessageChannel; 30 | import org.spongepowered.api.text.chat.ChatType; 31 | import org.spongepowered.api.text.title.Title; 32 | import org.spongepowered.api.util.AABB; 33 | import org.spongepowered.api.util.Direction; 34 | import org.spongepowered.api.util.DiscreteTransform3; 35 | import org.spongepowered.api.world.*; 36 | import org.spongepowered.api.world.biome.BiomeType; 37 | import org.spongepowered.api.world.difficulty.Difficulties; 38 | import org.spongepowered.api.world.difficulty.Difficulty; 39 | import org.spongepowered.api.world.explosion.Explosion; 40 | import org.spongepowered.api.world.extent.*; 41 | import org.spongepowered.api.world.extent.worker.MutableBiomeVolumeWorker; 42 | import org.spongepowered.api.world.extent.worker.MutableBlockVolumeWorker; 43 | import org.spongepowered.api.world.gen.WorldGenerator; 44 | import org.spongepowered.api.world.storage.WorldProperties; 45 | import org.spongepowered.api.world.storage.WorldStorage; 46 | import org.spongepowered.api.world.weather.Weather; 47 | import org.spongepowered.api.world.weather.Weathers; 48 | 49 | import javax.annotation.Nullable; 50 | import java.io.IOException; 51 | import java.nio.file.Path; 52 | import java.util.Collection; 53 | import java.util.Optional; 54 | import java.util.Set; 55 | import java.util.UUID; 56 | import java.util.function.Predicate; 57 | 58 | public class ShinyWorld implements World { 59 | private org.bukkit.World handle; 60 | 61 | public ShinyWorld(org.bukkit.World handle) { 62 | this.handle = handle; 63 | } 64 | 65 | public org.bukkit.World getHandle() { 66 | return this.handle; 67 | } 68 | 69 | @Override 70 | public Difficulty getDifficulty() { 71 | switch (this.handle.getDifficulty()) { 72 | case EASY: return Difficulties.EASY; 73 | case HARD: return Difficulties.HARD; 74 | case NORMAL: return Difficulties.NORMAL; 75 | case PEACEFUL: return Difficulties.PEACEFUL; 76 | default: return Difficulties.NORMAL; 77 | } 78 | } 79 | 80 | @Override 81 | public Optional getGameRule(String gameRule) { 82 | return Optional.of(this.handle.getGameRuleValue(gameRule)); 83 | } 84 | 85 | @Override 86 | public boolean doesKeepSpawnLoaded() { 87 | return this.handle.getKeepSpawnInMemory(); 88 | } 89 | 90 | @Override 91 | public void setKeepSpawnLoaded(boolean keepLoaded) { 92 | this.handle.setKeepSpawnInMemory(keepLoaded); 93 | } 94 | 95 | @Override 96 | public WorldStorage getWorldStorage() { 97 | return null; 98 | } 99 | 100 | @Override 101 | public void triggerExplosion(Explosion explosion, Cause cause) { 102 | 103 | } 104 | 105 | @Override 106 | public PortalAgent getPortalAgent() { 107 | return null; 108 | } 109 | 110 | @Override 111 | public int getHighestYAt(int x, int z) { 112 | return 0; 113 | } 114 | 115 | @Override 116 | public boolean setBlock(int x, int y, int z, BlockState blockState, BlockChangeFlag flag, Cause cause) { 117 | return false; 118 | } 119 | 120 | @Override 121 | public BlockSnapshot createSnapshot(int x, int y, int z) { 122 | return null; 123 | } 124 | 125 | @Override 126 | public boolean restoreSnapshot(BlockSnapshot snapshot, boolean force, BlockChangeFlag flag, Cause cause) { 127 | return false; 128 | } 129 | 130 | @Override 131 | public boolean restoreSnapshot(int x, int y, int z, BlockSnapshot snapshot, boolean force, BlockChangeFlag flag, Cause cause) { 132 | return false; 133 | } 134 | 135 | @Override 136 | public Collection getScheduledUpdates(int x, int y, int z) { 137 | return null; 138 | } 139 | 140 | @Override 141 | public ScheduledBlockUpdate addScheduledUpdate(int x, int y, int z, int priority, int ticks) { 142 | return null; 143 | } 144 | 145 | @Override 146 | public void removeScheduledUpdate(int x, int y, int z, ScheduledBlockUpdate update) { 147 | 148 | } 149 | 150 | @Override 151 | public boolean isLoaded() { 152 | return false; 153 | } 154 | 155 | @Override 156 | public Extent getExtentView(Vector3i newMin, Vector3i newMax) { 157 | return null; 158 | } 159 | 160 | @Override 161 | public Vector3i getBiomeMin() { 162 | return null; 163 | } 164 | 165 | @Override 166 | public Vector3i getBiomeMax() { 167 | return null; 168 | } 169 | 170 | @Override 171 | public Vector3i getBiomeSize() { 172 | return null; 173 | } 174 | 175 | @Override 176 | public boolean containsBiome(int x, int y, int z) { 177 | return false; 178 | } 179 | 180 | @Override 181 | public BiomeType getBiome(int x, int y, int z) { 182 | return null; 183 | } 184 | 185 | @Override 186 | public UnmodifiableBiomeVolume getUnmodifiableBiomeView() { 187 | return null; 188 | } 189 | 190 | @Override 191 | public MutableBiomeVolume getBiomeCopy(StorageType type) { 192 | return null; 193 | } 194 | 195 | @Override 196 | public ImmutableBiomeVolume getImmutableBiomeCopy() { 197 | return null; 198 | } 199 | 200 | @Override 201 | public void setBiome(int x, int y, int z, BiomeType biome) { 202 | 203 | } 204 | 205 | @Override 206 | public MutableBiomeVolume getBiomeView(Vector3i newMin, Vector3i newMax) { 207 | return null; 208 | } 209 | 210 | @Override 211 | public MutableBiomeVolume getBiomeView(DiscreteTransform3 transform) { 212 | return null; 213 | } 214 | 215 | @Override 216 | public MutableBiomeVolumeWorker getBiomeWorker() { 217 | return null; 218 | } 219 | 220 | @Override 221 | public boolean hitBlock(int x, int y, int z, Direction side, Cause cause) { 222 | return false; 223 | } 224 | 225 | @Override 226 | public boolean interactBlock(int x, int y, int z, Direction side, Cause cause) { 227 | return false; 228 | } 229 | 230 | @Override 231 | public boolean interactBlockWith(int x, int y, int z, ItemStack itemStack, Direction side, Cause cause) { 232 | return false; 233 | } 234 | 235 | @Override 236 | public boolean placeBlock(int x, int y, int z, BlockState block, Direction side, Cause cause) { 237 | return false; 238 | } 239 | 240 | @Override 241 | public boolean digBlock(int x, int y, int z, Cause cause) { 242 | return false; 243 | } 244 | 245 | @Override 246 | public boolean digBlockWith(int x, int y, int z, ItemStack itemStack, Cause cause) { 247 | return false; 248 | } 249 | 250 | @Override 251 | public int getBlockDigTimeWith(int x, int y, int z, ItemStack itemStack, Cause cause) { 252 | return 0; 253 | } 254 | 255 | @Override 256 | public Vector3i getBlockMin() { 257 | return null; 258 | } 259 | 260 | @Override 261 | public Vector3i getBlockMax() { 262 | return null; 263 | } 264 | 265 | @Override 266 | public Vector3i getBlockSize() { 267 | return null; 268 | } 269 | 270 | @Override 271 | public boolean containsBlock(int x, int y, int z) { 272 | return false; 273 | } 274 | 275 | @Override 276 | public BlockState getBlock(int x, int y, int z) { 277 | return null; 278 | } 279 | 280 | @Override 281 | public BlockType getBlockType(int x, int y, int z) { 282 | return null; 283 | } 284 | 285 | @Override 286 | public UnmodifiableBlockVolume getUnmodifiableBlockView() { 287 | return null; 288 | } 289 | 290 | @Override 291 | public MutableBlockVolume getBlockCopy(StorageType type) { 292 | return null; 293 | } 294 | 295 | @Override 296 | public ImmutableBlockVolume getImmutableBlockCopy() { 297 | return null; 298 | } 299 | 300 | @Override 301 | public Collection getTileEntities() { 302 | return null; 303 | } 304 | 305 | @Override 306 | public Collection getTileEntities(Predicate filter) { 307 | return null; 308 | } 309 | 310 | @Override 311 | public Optional getTileEntity(int x, int y, int z) { 312 | return null; 313 | } 314 | 315 | @Override 316 | public boolean setBlock(int x, int y, int z, BlockState block, Cause cause) { 317 | return false; 318 | } 319 | 320 | @Override 321 | public MutableBlockVolume getBlockView(Vector3i newMin, Vector3i newMax) { 322 | return null; 323 | } 324 | 325 | @Override 326 | public MutableBlockVolume getBlockView(DiscreteTransform3 transform) { 327 | return null; 328 | } 329 | 330 | @Override 331 | public MutableBlockVolumeWorker getBlockWorker(Cause cause) { 332 | return null; 333 | } 334 | 335 | @Override 336 | public Optional getCreator(int x, int y, int z) { 337 | return null; 338 | } 339 | 340 | @Override 341 | public Optional getNotifier(int x, int y, int z) { 342 | return null; 343 | } 344 | 345 | @Override 346 | public void setCreator(int x, int y, int z, @Nullable UUID uuid) { 347 | 348 | } 349 | 350 | @Override 351 | public void setNotifier(int x, int y, int z, @Nullable UUID uuid) { 352 | 353 | } 354 | 355 | @Override 356 | public Optional getBlockSelectionBox(int x, int y, int z) { 357 | return null; 358 | } 359 | 360 | @Override 361 | public Set getIntersectingBlockCollisionBoxes(AABB box) { 362 | return null; 363 | } 364 | 365 | @Override 366 | public Set getIntersectingCollisionBoxes(Entity owner, AABB box) { 367 | return null; 368 | } 369 | 370 | @Override 371 | public ArchetypeVolume createArchetypeVolume(Vector3i min, Vector3i max, Vector3i origin) { 372 | return null; 373 | } 374 | 375 | @Override 376 | public boolean save() throws IOException { 377 | return false; 378 | } 379 | 380 | @Override 381 | public Collection getPlayers() { 382 | return null; 383 | } 384 | 385 | @Override 386 | public Optional getChunk(int cx, int cy, int cz) { 387 | return null; 388 | } 389 | 390 | @Override 391 | public Optional loadChunk(int cx, int cy, int cz, boolean shouldGenerate) { 392 | return null; 393 | } 394 | 395 | @Override 396 | public boolean unloadChunk(Chunk chunk) { 397 | return false; 398 | } 399 | 400 | @Override 401 | public Iterable getLoadedChunks() { 402 | return null; 403 | } 404 | 405 | @Override 406 | public Optional getEntity(UUID uuid) { 407 | return null; 408 | } 409 | 410 | @Override 411 | public Collection getEntities() { 412 | return null; 413 | } 414 | 415 | @Override 416 | public Collection getEntities(Predicate filter) { 417 | return null; 418 | } 419 | 420 | @Override 421 | public Entity createEntity(EntityType type, Vector3d position) throws IllegalArgumentException, IllegalStateException { 422 | return null; 423 | } 424 | 425 | @Override 426 | public Optional createEntity(DataContainer entityContainer) { 427 | return null; 428 | } 429 | 430 | @Override 431 | public Optional createEntity(DataContainer entityContainer, Vector3d position) { 432 | return null; 433 | } 434 | 435 | @Override 436 | public Entity createEntityNaturally(EntityType type, Vector3d position) throws IllegalArgumentException, IllegalStateException { 437 | return null; 438 | } 439 | 440 | @Override 441 | public Optional restoreSnapshot(EntitySnapshot snapshot, Vector3d position) { 442 | return null; 443 | } 444 | 445 | @Override 446 | public boolean spawnEntity(Entity entity, Cause cause) { 447 | return false; 448 | } 449 | 450 | @Override 451 | public boolean spawnEntities(Iterable entities, Cause cause) { 452 | return false; 453 | } 454 | 455 | @Override 456 | public Set getIntersectingEntities(AABB box, Predicate filter) { 457 | return null; 458 | } 459 | 460 | @Override 461 | public Set getIntersectingEntities(Vector3d start, Vector3d end, Predicate filter) { 462 | return null; 463 | } 464 | 465 | @Override 466 | public Set getIntersectingEntities(Vector3d start, Vector3d direction, double distance, Predicate filter) { 467 | return null; 468 | } 469 | 470 | @Override 471 | public WorldBorder getWorldBorder() { 472 | return null; 473 | } 474 | 475 | @Override 476 | public ChunkPreGenerate.Builder newChunkPreGenerate(Vector3d center, double diameter) { 477 | return null; 478 | } 479 | 480 | @Override 481 | public Dimension getDimension() { 482 | return null; 483 | } 484 | 485 | @Override 486 | public WorldGenerator getWorldGenerator() { 487 | return null; 488 | } 489 | 490 | @Override 491 | public WorldProperties getProperties() { 492 | return null; 493 | } 494 | 495 | @Override 496 | public Path getDirectory() { 497 | return null; 498 | } 499 | 500 | @Override 501 | public UUID getUniqueId() { 502 | return this.handle.getUID(); 503 | } 504 | 505 | @Override 506 | public Weather getWeather() { 507 | if (this.handle.hasStorm()) { 508 | return Weathers.RAIN; 509 | } else if (this.handle.isThundering()) { 510 | return Weathers.THUNDER_STORM; 511 | } else { 512 | return Weathers.CLEAR; 513 | } 514 | } 515 | 516 | @Override 517 | public long getRemainingDuration() { 518 | return this.handle.getWeatherDuration() != 0 ? this.handle.getWeatherDuration() : this.handle.getThunderDuration(); 519 | } 520 | 521 | @Override 522 | public long getRunningDuration() { 523 | // TODO: doesn't appear the Bukkit API exposes running weather duration? 524 | return 0; //To change body of implemented methods use File | Settings | File Templates. 525 | } 526 | 527 | @Override 528 | public void setWeather(Weather weather) { 529 | 530 | } 531 | 532 | @Override 533 | public void setWeather(Weather weather, long duration) { 534 | 535 | } 536 | 537 | @Override 538 | public > Optional getProperty(int x, int y, int z, Class propertyClass) { 539 | return null; 540 | } 541 | 542 | @Override 543 | public > Optional getProperty(int x, int y, int z, Direction direction, Class propertyClass) { 544 | return null; 545 | } 546 | 547 | @Override 548 | public Collection> getProperties(int x, int y, int z) { 549 | return null; 550 | } 551 | 552 | @Override 553 | public Collection getFacesWithProperty(int x, int y, int z, Class> propertyClass) { 554 | return null; 555 | } 556 | 557 | @Override 558 | public void spawnParticles(ParticleEffect particleEffect, Vector3d position) { 559 | 560 | } 561 | 562 | @Override 563 | public void spawnParticles(ParticleEffect particleEffect, Vector3d position, int radius) { 564 | 565 | } 566 | 567 | @Override 568 | public void playSound(SoundType sound, SoundCategory category, Vector3d position, double volume) { 569 | 570 | } 571 | 572 | @Override 573 | public void playSound(SoundType sound, SoundCategory category, Vector3d position, double volume, double pitch) { 574 | 575 | } 576 | 577 | @Override 578 | public void playSound(SoundType sound, SoundCategory category, Vector3d position, double volume, double pitch, double minVolume) { 579 | 580 | } 581 | 582 | @Override 583 | public void sendTitle(Title title) { 584 | 585 | } 586 | 587 | @Override 588 | public void sendBookView(BookView bookView) { 589 | 590 | } 591 | 592 | @Override 593 | public void sendBlockChange(int x, int y, int z, BlockState state) { 594 | 595 | } 596 | 597 | @Override 598 | public void resetBlockChange(int x, int y, int z) { 599 | 600 | } 601 | 602 | @Override 603 | public Context getContext() { 604 | return null; 605 | } 606 | 607 | @Override 608 | public void sendMessage(ChatType type, Text message) { 609 | 610 | } 611 | 612 | @Override 613 | public void sendMessage(Text message) { 614 | 615 | } 616 | 617 | @Override 618 | public MessageChannel getMessageChannel() { 619 | return null; 620 | } 621 | 622 | @Override 623 | public void setMessageChannel(MessageChannel channel) { 624 | 625 | } 626 | 627 | @Override 628 | public Optional get(int x, int y, int z, Key> key) { 629 | return null; 630 | } 631 | 632 | @Override 633 | public > Optional get(int x, int y, int z, Class manipulatorClass) { 634 | return null; 635 | } 636 | 637 | @Override 638 | public > Optional getOrCreate(int x, int y, int z, Class manipulatorClass) { 639 | return null; 640 | } 641 | 642 | @Override 643 | public > Optional getValue(int x, int y, int z, Key key) { 644 | return null; 645 | } 646 | 647 | @Override 648 | public boolean supports(int x, int y, int z, Key key) { 649 | return false; 650 | } 651 | 652 | @Override 653 | public boolean supports(int x, int y, int z, Class> manipulatorClass) { 654 | return false; 655 | } 656 | 657 | @Override 658 | public Set> getKeys(int x, int y, int z) { 659 | return null; 660 | } 661 | 662 | @Override 663 | public Set> getValues(int x, int y, int z) { 664 | return null; 665 | } 666 | 667 | @Override 668 | public DataTransactionResult offer(int x, int y, int z, Key> key, E value) { 669 | return null; 670 | } 671 | 672 | @Override 673 | public DataTransactionResult offer(int x, int y, int z, Key> key, E value, Cause cause) { 674 | return null; 675 | } 676 | 677 | @Override 678 | public DataTransactionResult offer(int x, int y, int z, DataManipulator manipulator, MergeFunction function) { 679 | return null; 680 | } 681 | 682 | @Override 683 | public DataTransactionResult offer(int x, int y, int z, DataManipulator manipulator, MergeFunction function, Cause cause) { 684 | return null; 685 | } 686 | 687 | @Override 688 | public DataTransactionResult remove(int x, int y, int z, Class> manipulatorClass) { 689 | return null; 690 | } 691 | 692 | @Override 693 | public DataTransactionResult remove(int x, int y, int z, Key key) { 694 | return null; 695 | } 696 | 697 | @Override 698 | public DataTransactionResult undo(int x, int y, int z, DataTransactionResult result) { 699 | return null; 700 | } 701 | 702 | @Override 703 | public DataTransactionResult copyFrom(int xTo, int yTo, int zTo, DataHolder from) { 704 | return null; 705 | } 706 | 707 | @Override 708 | public DataTransactionResult copyFrom(int xTo, int yTo, int zTo, DataHolder from, MergeFunction function) { 709 | return null; 710 | } 711 | 712 | @Override 713 | public DataTransactionResult copyFrom(int xTo, int yTo, int zTo, int xFrom, int yFrom, int zFrom, MergeFunction function) { 714 | return null; 715 | } 716 | 717 | @Override 718 | public Collection> getManipulators(int x, int y, int z) { 719 | return null; 720 | } 721 | 722 | @Override 723 | public boolean validateRawData(int x, int y, int z, DataView container) { 724 | return false; 725 | } 726 | 727 | @Override 728 | public void setRawData(int x, int y, int z, DataView container) throws InvalidDataException { 729 | 730 | } 731 | } 732 | -------------------------------------------------------------------------------- /src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | name: Bukkit2Sponge 2 | main: net.glowstone.bukkit2sponge.Bukkit2Sponge 3 | version: ${version} 4 | --------------------------------------------------------------------------------